top of page

Nick

Beyer

Midi Note Latch

To sustain a note, I wrote some Javascript code within Logic’s midi scripter plugin.

Midi Note latch script for Logic/Mainstage midi scripter plugin

Occasionally when playing live I have the need to sustain a drone sound or keep a sample looping while playing other parts that may need the sustain pedal. Mainstage doesn’t have a great way to simply hold a note (that I know of), and I have had to figure out some odd workarounds in gigs past. Logic/Mainstage has a built in midi scripter plugin that can be used for custom midi effects, so I created a simple program that latches each key press in the on position until the key is pressed again. You can build chords note by note, or press them all at once and the key will act as if it were still pressed down. There is a toggle to turn off all notes if the sustain pedal is pressed.

Javascript Code:

// get parameter function to handle menu change for sustain pedal option

var EXT = {

     data: [],

     SetParameter: function(id, val) {

         if(typeof id != "string") id = PluginParameters[id].name;

         this.data[id] = val;

     },

     GetParameter: function(id) {

         if(typeof id != "string") id = PluginParameters[id].name;

         if(this.data[id] == undefined) {

             this.data[id] = GetParameter(id);

         }

         return this.data[id];

     }

};

function ParameterChanged(id, val) {

     EXT.SetParameter(id, val);

}

​

var Pedalnum = 64;   // Standard midi number for the pedal

var Threshold = 64;  // interpretation of pedal down/up value

var cc = new ControlChange; //implement cc to turn all notes off

cc.number = 120; 

cc.value = 1;

//This creates a menu button for sustain to turn off notes.

var PluginParameters = [];

PluginParameters.push({

     name: "Sustain pedal stop all notes",

     type: "menu",

     valueStrings: ["On","Off"],

     defaultValue: 0

});

 

isNoteOn = []; // create array to store whether note is on or off

for ( n = 0; n<128; ++n ) isNoteOn[n] = false;

 

function HandleMIDI(event)

{

event.trace();

//filter midi events to pass through other midi data other than noteon/off

if (event instanceof NoteOn || event instanceof NoteOff) {  

     if (isNoteOn[event.pitch] == false && event instanceof NoteOn) {

          isNoteOn[event.pitch]=true;

          event.trace();

          event.send();

     }

     else if (isNoteOn[event.pitch] == true && event instanceof NoteOn ) {

          event.velocity = 0; //noteOff signal

          event.send();

          isNoteOn[event.pitch]=false;

     }

}

else{

     event.send(); //send modulation, pitch bend, etc.

     }

 

if ( EXT.GetParameter("Sustain pedal stop all notes") == 0 ){

//on pedal press, turn off all  notes

     if (event instanceof ControlChange && event.number==Pedalnum) {

     cc.send();

     for ( n = 0; n<128; ++n ) isNoteOn[n] = false;

     }

}

}

© 2024 by Nick Beyer. Powered and secured by Wix

bottom of page