Logic Pro X: HandleMIDI function

HandleMIDI function

The HandleMIDI() function lets you process MIDI events that the plug-in receives. HandleMIDI is called each time a MIDI event is received by the plug-in and is required in order to process incoming MIDI events. If you don’t implement the HandleMIDI function, events pass through the plug-in unaffected.

HandleMIDI is called with one argument, which is a JavaScript object that represents the incoming MIDI event. HandleMIDI and JavaScript Event object use is shown in the examples.

Load the corresponding Tutorial setting to view the script in the Script Editor. This will help you to understand the syntax structure and layout of code and comments. See Use the Script Editor.

Tutorial script 1: Simple Pass Through

Pass MIDI events through the plug-in.

function HandleMIDI(event) { event.send(); }

Tutorial script 2: Trace Events

Log events to the plug-in console and don’t send them anywhere.

function HandleMIDI(event) { event.trace(); }

Tutorial script 3: Transpose and Delay

Repeat notes up one octave with 100ms delay and pass all other events through.

Text following /* shows comments that explain the JavaScript code.

function HandleMIDI(event) { event.send(); /* send original event */ if (event instanceof Note) { /* if it is a note */ event.pitch += 12; /* transpose up one octave */ event.sendAfterMilliseconds(100); /* send after delay */ } }
Published Date: Aug 9, 2019
Helpful?