Skip to main content

Region Object

The region object is accessed via the .region property on a note. It provides note insertion and iteration over all notes within the part. For the track-level arrangement surface, see Event Object — Instrument Part Events.

Only available on selected Instrument Part or the Note Editor from the MusicEdit subCategory.

Properties

PropertyTypeWritableExampleDescription
namestringNo"Track 1"Track name containing this part.
startnumberNo0Start position in beats.
lengthnumberNo52Duration in beats.
offsetnumberNo48Region offset.
parentobjectNoParent track (region-like surface). See sub-object below.
startTimeobject - Time ObjectNoStart position as time object.
endTimeobject - Time ObjectNoEnd position as time object.
lengthTimeobject - Time ObjectNoLength as time object.

Methods

MethodReturnsParametersDescription
getRoot()objectnoneReturns the root region. See sub-object below.
getTrack()objectnoneReturns the containing track (region-like surface).
getStartTime()objectnoneStart time of the part.
getEndTime()objectnoneEnd time of the part.
createSequenceIterator()objectnoneCreates an iterator over all notes in the region.
getSoundVariationForNote(note)numbernote — note eventLook up sound variation for a note (-1 if none, 0+ for assigned variation).
getLyricsForNote(note)object - Lyrics Objectnote — note eventLook up lyrics for a note.

Root

Returned by getRoot(). Returns a region-like object. Not the same region as region itself.

PropertyTypeWritableExampleDescription
namestringNo""Name (empty string for root).
startnumberNo0Start position in beats.
lengthnumberNo300Duration in beats.
offsetnumberNo48Offset.
parentobjectNoParent object.
startTimeobject - Time ObjectNoStart time object.
endTimeobject - Time ObjectNoEnd time object.
lengthTimeobject - Time ObjectNoLength time object.
MethodReturnsParametersDescription
getRoot()objectnoneReturns itself.
getTrack()objectnoneReturns the containing track.
getStartTime()objectnoneStart time.
getEndTime()objectnoneEnd time.

Parent Track

Returned by getTrack() and parent. Both return the same region-like object. getTrack() returns itself.

PropertyTypeWritableExampleDescription
namestringNo"Track 1"Track name.
startnumberNo0Start position in beats.
lengthnumberNo600Track length in beats.
offsetnumberNo48Offset.
parentobjectNoParent object.
startTimeobject - Time ObjectNoStart time object.
endTimeobject - Time ObjectNoEnd time object.
lengthTimeobject - Time ObjectNoLength time object.
MethodReturnsParametersDescription
getRoot()objectnoneReturns the root region.
getTrack()objectnoneReturns itself.
getStartTime()objectnoneStart time.
getEndTime()objectnoneEnd time.

Note Creation (Workaround)

Since the API does not provide a direct note-creation function on context.functions, note creation is done by cloning an existing note and inserting into a region.

var fn = context.functions;

function newNote(start, length, pitch, velocity, sourceEvent) {
var note = sourceEvent.clone();
var region = sourceEvent.region;

fn.insertEvent(region, note);
fn.moveEvent(note, start);
fn.resizeEvent(note, length);
fn.modifyPitch(note, pitch);
fn.modifyVelocity(note, velocity / 127.0);
fn.muteEvent(note, false);
return note;
}

Iterating All Notes in a Region

This pattern works in the Note Editor in a MusicEdit context where context.iterator returns individual notes. In the arrangement view, context.iterator returns Instrument Part Events — this pattern does not apply there.

// sourceNote — selected MIDI note from context.iterator
var region = sourceNote.region;

var it = region.createSequenceIterator();
while (!it.done()) {
var note = it.next();
}

See Iterator for the iterator interface reference.

Sound Variation Lookup

Retrieve assigned sound variation (keyswitch/articulation) index for each note in the region:

// region — from note.region or sourceEvent.region
var it = region.createSequenceIterator();
while (!it.done()) {
var note = it.next();
var variation = region.getSoundVariationForNote(note);
// variation: -1 if none, 0+ for assigned variation
}