Using Scripter to make sustain pedal play the last note
I am trying to get my sustain pedal to play the last note. My script seems to work but where it fails is:
- I press my sustain pedal to play the last note
- I press another key while holding the sustain pedal
- the note pressed from step 1 won't release until I turn off the input in the channel.
Any suggestions are appreciated! Below is my code:
// Define a variable to store the last played note
var lastNote = null;
function HandleMIDI(event)
{
var note = new NoteOn;
if (event instanceof NoteOn) {
// Store the note in the variable
lastNote = event.pitch;
}
if (event instanceof ControlChange && event.number==64) {
// we received a sustain pedal message, convert it to a note
note.channel=1; // channel 1
note.pitch=lastNote; // kick drum
if (event.value>0) note.velocity=100; else note.velocity=0; // lock velocity at 100
note.send(); // send it
} else {
// send all other MIDI messages through untouched
event.trace();
event.send();
}
}