
ProcessMIDI function in Scripter MIDI plug-in in MainStage
The ProcessMIDI() function lets you perform periodic (generally timing-related) tasks. The function can be used when scripting a sequencer, an arpeggiator, or another tempo-driven MIDI effect. ProcessMIDI is generally not required for applications that don’t make use of musical timing information from the host. ProcessMIDI is called once per “process block,” which is determined by the host audio settings (sample rate and buffer size).
This function is often used in combination with the TimingInfo object to make use of timing information from MainStage. The use of ProcessMIDI and the TimingInfo object is shown in the example. Also see Use the JavaScript TimingInfo object.
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.
Important: To enable the GetTimingInfo feature, you need to add var NeedsTimingInfo = true; at the global script level (outside of any functions).
Tutorial script 5: Process MIDI Callback
Text following /* shows comments that explain the JavaScript code.
/* Define NeedsTimingInfo as true at the global level to enable GetHostInfo() */
var NeedsTimingInfo = true;
function ProcessMIDI() {
var info = GetTimingInfo(); /* get a TimingInfo object from the host
if the transport is running */
if (info.playing) {
Trace(info.tempo); /* print the tempo in the plug-in console */
}
}