Latch Note On/Off Script for Mainstage with Debugging
ok here's the script with debug statements. You need to make sure your key or drumpad is triggering the specific channel and note the script is looking for. You CAN create a channel strip that does not take input from any source and still trigger the note!
// Scripter - Latch Note On/Off with Debugging
var isLatched = false; // Tracks the latch state
var triggerNote = 36; // MIDI note of the drum pad (C1 by default)
var inputChannel = 1; // Channel the drum pad is sending on (1-16)
var targetNote = 83; // MIDI note to trigger (This one is set to B4)
var outputChannel = 1; // MIDI channel for the specific channel strip (1-16)
function HandleMIDI(event) {
// Debug: Log all incoming events
Trace("Incoming Event: " + event.toString());
if (event instanceof NoteOn) {
// Debug: Log details of NoteOn events
Trace("NoteOn - Pitch: " + event.pitch + ", Channel: " + (event.channel + 1));
if (event.channel === inputChannel && event.pitch === triggerNote) {
// Debug: Log when the trigger note is detected
Trace("Trigger Note Detected!");
isLatched = !isLatched; // Toggle the latch state
Trace("Latch State Changed: " + isLatched);
if (isLatched) {
// Send Note On for the target note
var noteOn = new NoteOn();
noteOn.pitch = targetNote;
noteOn.velocity = event.velocity; // Use the velocity of the pad press
Trace("Sending Note On: Pitch " + noteOn.pitch + " on Channel " + (noteOn.channel + 1));
noteOn.send();
} else {
// Send Note Off for the target note
var noteOff = new NoteOff();
noteOff.pitch = targetNote;
Trace("Sending Note Off: Pitch " + noteOff.pitch + " on Channel " + (noteOff.channel + 1));
noteOff.send();
}
}
}
}
[Re-Titled by Moderator]