X

Table Of Contents
Chapter 9 MIDI plug-ins 18 8
Code example 3
Repeat notes up one octave with 100ms delay and pass all other events through.
Text following “//” are comments.
function HandleMIDI(event) {
event.send(); // send original event
if (event instanceof Note) { // if it's a note
event.pitch += 12; // transpose up one octave
event.sendAfterMilliseconds(100); // send after delay
}
}
ProcessMIDI function
The ProcessMIDI() function lets you perform periodic (generally timing-related) tasks. This
can be used when scripting a sequencer, an arpeggiator, or another tempo-driven MIDI eect.
ProcessMIDI is generally not required for applications that do not make use of musical timing
information from the host. ProcessMIDI is called once per process block,” which is determined by
the host’s audio settings (sample rate and buer size).
This function is often used in combination with the "JavaScript TimingInfo object" to make use of
timing information from the host application. The use of ProcessMIDI and the TimingInfo object
is shown in the example. Also see Use the JavaScript TimingInfo object.
Note: To enable the GetTimingInfo feature, you need to add NeedsTimingInfo = true; at the
global script level (outside of any functions).
Code example
// Define NeedsTimingInfo as true at the global scope to enable GetHostInfo()
NeedsTimingInfo = true;
function ProcessMIDI() {
var info = GetTimingInfo(); // get a TimingInfo object from the host
if (info.playing) { // if the transport is running
Trace(info.tempo); // print the tempo in the plugin console
}
}