
Use MIDI event beatPos property in MainStage
Every MIDI event in Scripter has a property called “beatPos” that carries the exact beat position of the event. This makes more exact event timing possible and also handles loops correctly. This property can be used in place of timingInfo.blockStartBeat
. See Use the JavaScript TimingInfo object.
Note: This property only works if "var NeedsTimingInfo = true"
, otherwise it will have a value of 0, and will print a warning if modified.
In MainStage, type either of the following lines in the Script Editor window (both achieve the same result):
event.send()
event.sendAtBeat(event.beatPos)
Alternatively, you can use either of the following lines in the Script Editor window (both achieve the same result):
event.beatpos += 1; event.send()
event.sendAtBeat(event.beatPos + 1)
Usage example for the beatPos property
You can use the beatPos property to send a MIDI event at a specific beat position. In the following example, a note off event is sent a beat later than the beat position of the corresponding note on event.
Note: You can also use the event.sendAtBeat(pos) method to send an event at a specific beat position. The advantage of using the beatPos property is that you don’t actually have to send an event; you can simply use the property to retrieve the exact beat position of an event.
Text following /* shows comments that explain the JavaScript code.
var NeedsTimingInfo = true; /* needed to make beatPos work */
function HandleMIDI(event) {
var on = new NoteOn; /* make a new note on */
on.pitch = 60; /* set its pitch to C3 */
on.beatPos = event.beatPos; /* copy beat position from incoming event */
on.send(); /* send the note on */
var off = new NoteOff(on); /* make a note off using the note on to initialize its pitch value to C3 */
/* note that the beatPos does not get copied here */
off.beatPos = on.BeatPos+1; /* set the beat position of the note off event */
off.send(); /* send the note off event */
}