10.6

Table Of Contents
215Logic Pro Effects
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 */
}
Use the JavaScript MIDI object
The MIDI object contains a number of convenient and easy to use functions that can be
used when writing your scripts.
Note: The MIDI object is a property of the global object, which means that you do not
instantiate it but access its functions much like you would the JavaScript Math object.
An example is calling MIDI.allNotesOff() directly.
MIDI object properties
Use the following method names and arguments to perform these functions:
noteNumber(string name): Returns the MIDI note number for a given note name.
For example: C3 or B#2.
Note: You cannot use flats in your argument. Use A#3, not Bb3.
noteName(number pitch): Returns the name (string) for a given MIDI note number.
ccName(number controller): Returns the controller name (string) for a given controller
number.
allNotesOff(): Sends the all notes off message on all MIDI channels.
normalizeStatus(number status): Normalizes a value to the safe range of MIDI status
bytes (128–239).