Last active
November 7, 2024 22:45
-
-
Save kristopherjohnson/190d2b86a1dab613ffd5909c562b97e5 to your computer and use it in GitHub Desktop.
Logic Pro Scripter script for a latched MIDI keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Plays note with infinite sustain when pressed. | |
// Unlatches note when it is pressed again. | |
// Initialize an empty set to store latched notes | |
var latchedNotes = new Set(); | |
function HandleMIDI(event) { | |
// Check if the event is a note on or note off | |
if (event instanceof NoteOn) { | |
if (latchedNotes.has(event.pitch)) { | |
// If the note is already latched, release it | |
var noteOff = new NoteOff(event); | |
noteOff.send(); | |
latchedNotes.delete(event.pitch); // Remove note from the set | |
} else { | |
// If the note is not latched, latch it | |
event.send(); // Send the note-on message | |
latchedNotes.add(event.pitch); // Add note to the set | |
} | |
} else if (event instanceof NoteOff) { | |
// Block the original note-off if the note is latched | |
if (latchedNotes.has(event.pitch)) { | |
// Do nothing; keep the note latched | |
} else { | |
// If not latched, pass the note-off through | |
event.send(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment