Mainstage Script: Latch Notes

In several live music sets I needed to have a drone-note (a long sustaining low note, most of the time the root of the scale). One solution is to press a key on your synth and keep your sustain pedal pressed. Really simple, but having two sustain pedals connected to two different keyboards, I always end up confused.

There are several scripts which turn up when you do a search. One by someone called Caveman, does exactly that: basically you press a key, and out comes a NoteOn-message. When you press the key again, it sends a NoteOff. This works polyphonical.

However, this did not fully fit my needs. So I got to work:

This simple script basically works like this:

  1. Press note(s) you want to play. NoteOn(s) are being send. Press sustain-pedal. Release keys. Release Sustain-pedal. Notes are being held.
  2. Press Sustain-pedal and NoteOff(s) are being send.

That is it. Later I added the option to add notes after the sustain-pedal has been pressed/released.

/ Sustain Pedal: momentary to toggle
// Pressing the sustain pedal sustains all played notes
// notes can be added
// lifting the pedal has no effect
// pressing the pedal again stops the notes (similar to lifting your foot when sustainpedal is in regular mode.
// Albert Sikkema, October 2019

var sustain = 0


function HandleMIDI(event){
	var addnotes = GetParameter("Add Notes");
  // filter out sustain pedal for this channel to not affect the sustained chord
  if ((event instanceof ControlChange) && (event.number == 64) && (event.value == 127)){
  		if (sustain == 127) {
  		event.value = 0
  		event.send();
  		sustain = 0;
  		}
  		else if (sustain == 0){
  		event.send();
  		sustain = 127;
  		}
  	}	
  else if ((event instanceof ControlChange) && (event.number == 64) && (event.value == 0)) {
  		}
  else if ((event instanceof NoteOn) && (sustain == 127) && (addnotes == 1)) {
  		}
  else {
   event.send();
   }
}

var PluginParameters = [{
		name: "Add Notes", 
		type:"menu", 
		valueStrings:["On","Off"],  
		numberOfSteps:2, 
		defaultValue:0
}];

Leave a Reply