MultiVoiceMeasure class

Measure with multiple independent voices.

Used for polyphonic notation where multiple melodic lines appear on the same staff simultaneously.

This is a specialization of Measure: instead of keeping its notes in the inherited Measure.elements list, it stores them inside Voice objects. Measure.elements is therefore normally limited to the shared attributes of the bar (clef, time signature, key signature, barlines).

Because of that, allElements is the correct way to iterate a measure — it is overridden here to yield the shared elements followed by the elements of every voice in voice order. Reading elements directly on a MultiVoiceMeasure silently skips all the music.

The inherited capacity API (currentMusicalValue, musicalValueOfVoice, isValidlyFilled, canAddDuration, remainingValue) is voice-aware here as well: it is all derived from musicalValueByVoice, which this class overrides to account for the voices. Without that override a polyphonic measure reported a rhythmic value of ~0 and was rejected by every measure validator.

Example:

final measure = MultiVoiceMeasure();

// Voice 1 (melody, stems up)
final voice1 = Voice.voice1();
voice1.add(Note(pitch: Pitch(step: 'E', octave: 5), duration: ..., voice: 1));
measure.addVoice(voice1);

// Voice 2 (accompaniment, stems down)
final voice2 = Voice.voice2();
voice2.add(Note(pitch: Pitch(step: 'C', octave: 4), duration: ..., voice: 2));
measure.addVoice(voice2);
Inheritance

Constructors

MultiVoiceMeasure()
MultiVoiceMeasure.threeVoices({required List<MusicalElement> voice1Elements, required List<MusicalElement> voice2Elements, required List<MusicalElement> voice3Elements})
Factory: Create measure with 3 voices
factory
MultiVoiceMeasure.twoVoices({required List<MusicalElement> voice1Elements, required List<MusicalElement> voice2Elements})
Factory: Create measure with 2 voices
factory

Properties

allElements Iterable<MusicalElement>
Shared elements of the bar followed by the elements of every voice, voices taken in ascending voice-number order.
no setteroverride
autoBeaming bool
Controls whether notes should be automatically grouped with beams. true = auto-beaming active (default) false = use individual flags
getter/setter pairinherited
beamingMode BeamingMode
Specific beaming strategy for special cases.
getter/setter pairinherited
currentMusicalValue double
The current rhythmic value of the measure.
no setterinherited
elements List<MusicalElement>
All musical elements in this measure, in order.
finalinherited
hashCode int
The hash code for this object.
no setterinherited
inheritedTimeSignature TimeSignature?
A meter this bar inherits from an earlier one, so that add can enforce capacity on a bar that declares no TimeSignature of its own.
getter/setter pairinherited
isPolyphonic bool
Check if measure has multiple voices (is polyphonic)
no setter
isValidlyFilled bool
Returns true if the measure is correctly filled.
no setterinherited
manualBeamGroups List<List<int>>
Manual beam groups — list of note index groups to be beamed together. Example: [0, 1, 2, 3, 4] groups notes 0,1,2 into one beam and 3,4 into another.
getter/setter pairinherited
musicalValueByVoice Map<int, double>
Rhythmic value per voice, counting both the inherited Measure.elements list and the elements held by each Voice.
no setteroverride
number int?
Measure number, corresponding to the MEI <measure @n> attribute. null = automatic numbering by the layout engine.
getter/setter pairinherited
remainingValue double
Returns how much rhythmic time remains in the measure.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sortedVoices List<Voice>
Get all voices sorted by voice number
no setter
timeSignature TimeSignature?
Returns the active time signature for this measure.
no setterinherited
voice1 Voice?
Get voice 1 (top voice)
no setter
voice2 Voice?
Get voice 2 (bottom voice)
no setter
voiceCount int
Get number of voices in this measure
no setter
voiceNumbers List<int>
Get list of voice numbers (sorted)
no setter
voices Iterable<Voice>
Collection of voices (order not guaranteed).
no setter

Methods

add(MusicalElement element) → void
Adds a musical element to the measure.
inherited
addVoice(Voice voice) → void
Add a voice to this measure
canAddDuration(Duration duration, {int voice = defaultVoice}) bool
Returns true if there is room to add duration to voice.
inherited
getVoice(int number) Voice?
Get voice by number
musicalValueOfVoice(int voice) double
Rhythmic value already written in voice (0.0 when the voice is empty).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited