Skip to content

Instantly share code, notes, and snippets.

@edrd-f
Created June 4, 2018 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edrd-f/f61f701cd3fdbd7e60cd8a0c9912a8a0 to your computer and use it in GitHub Desktop.
Save edrd-f/f61f701cd3fdbd7e60cd8a0c9912a8a0 to your computer and use it in GitHub Desktop.
Apple Logic MIDI script to toggle notes
var notesOn = [];
function isNotePlaying(event) {
for (var i = 0; i < notesOn.length; i++) {
if (notesOn[i] && notesOn[i].pitch == event.pitch) {
return i;
}
}
return false;
}
function sendNoteOff(event) {
var noteOffEvent = new NoteOff();
noteOffEvent.pitch = event.pitch;
noteOffEvent.channel = event.channel;
noteOffEvent.velocity = 0;
noteOffEvent.send();
}
function HandleMIDI(event)
{
//event.trace();
if (event instanceof NoteOn) {
var noteIndex = isNotePlaying(event)
if (typeof noteIndex == 'number') {
delete notesOn[noteIndex];
sendNoteOff(event);
} else {
notesOn.push(event);
event.send();
}
return;
}
if (event instanceof NoteOff) {
return;
}
event.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment