You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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:

  1. I press my sustain pedal to play the last note
  2. I press another key while holding the sustain pedal
  3. 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();
	}
}

Posted on Dec 20, 2023 6:33 AM

Reply
1 reply

Using Scripter to make sustain pedal play the last note

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.