Online Sequencer Forums

Full Version: #midiflip code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Here's another one that flips the song between major/minor. Make sure you have the right key selected first since auto-detect will always detect major.

Code:
if (keySelect.selectedIndex == 0) {
   message('Select a key first');
} else {
   var inverseKeyIndex = (keySelect.selectedIndex + 12) % 24;
   var inverseKey = settings.scales[inverseKeyIndex];
   for (i = 0; i < song.notes.length; i++) {
      var note = song.notes[i];
      var octave = note.type.substring(note.type.length-1);
      var noteInverseKeyIndex = scale.indexOf(note.type.substring(0, note.type.length-1));
      if (noteInverseKeyIndex != -1) {
          song.moveNote(note, note.instrument, note.instrument, note.time, note.time, note.type, inverseKey[noteInverseKeyIndex] + octave);
          song.update(note);
      }
   }
   keySelect.selectedIndex = inverseKeyIndex;
   keySelect.onchange();
}
Added both to the tools menu.
(03-10-2018, 11:43 AM)Jacob_ Wrote: [ -> ]Here's another one that flips the song between major/minor. Make sure you have the right key selected first since auto-detect will always detect major.

Code:
if (keySelect.selectedIndex == 0) {
   message('Select a key first');
} else {
   var inverseKeyIndex = (keySelect.selectedIndex + 12) % 24;
   var inverseKey = settings.scales[inverseKeyIndex];
   for (i = 0; i < song.notes.length; i++) {
      var note = song.notes[i];
      var octave = note.type.substring(note.type.length-1);
      var noteInverseKeyIndex = scale.indexOf(note.type.substring(0, note.type.length-1));
      if (noteInverseKeyIndex != -1) {
          song.moveNote(note, note.instrument, note.instrument, note.time, note.time, note.type, inverseKey[noteInverseKeyIndex] + octave);
          song.update(note);
      }
   }
   keySelect.selectedIndex = inverseKeyIndex;
   keySelect.onchange();
}
Do you think you could make this so it doesn't affect percussion?
Also I want to note, if you attempt to make the inverse go from major to minor (or minor to major) in will re-invert the music.
Found a bug with the major to minor and vice versa code.
If it attempts to turn a C into a B one note lower, it will instead keep it in the same octave.
(C6--->B6 instead of C6--->B5)
B major to B minor breaks the conversion tool.
Used same fundamental code to make an "autotuner":
Use this code on the modifier:
var a=Array(0);for(i=0;i<selectedNotes.length;i++){a.push(selectedNotes[i].type)}
Then use this code on the song you want to remix:
for(i=0;i<selectedNotes.length;i++){n=selectedNotes[i];song.moveNote(n,n.instrument,n.instrument,n.time,n.time,n.type,a[i%16].slice(0,-1)+n.type.slice(-1))}
Pages: 1 2