Voice class
Represents a voice in polyphonic notation
In polyphonic music, multiple independent melodic lines (voices) are notated on the same staff. Each voice is typically distinguished by:
- Stem direction (voice 1: up, voice 2: down)
- Horizontal offset (voice 2 shifted right)
- Different beaming groups
Examples:
- Bach fugues (3-4 voices on one staff)
- Piano music (2 voices per hand)
- Guitar fingerstyle (melody + accompaniment)
- Counterpoint exercises
Convention:
- Voice 1 (top voice): Stems up, no offset
- Voice 2 (bottom voice): Stems down, shifted right
- Voice 3+: Additional voices as needed
Constructors
-
Voice({required int number, List<
MusicalElement> ? elements, String? name, StemDirection? forcedStemDirection, double? horizontalOffset, String? color}) -
Voice.voice1({List<
MusicalElement> ? elements, String? name}) -
Factory: Create voice 1 (top voice, stems up)
factory
-
Voice.voice2({List<
MusicalElement> ? elements, String? name}) -
Factory: Create voice 2 (bottom voice, stems down, offset right)
factory
Properties
-
chords
→ List<
Chord> -
Get all chords in this voice
no setter
- color → String?
-
Color for this voice (optional, for visual distinction)
final
-
elements
→ List<
MusicalElement> -
Musical elements in this voice (notes, rests, chords)
final
- forcedStemDirection → StemDirection?
-
Preferred stem direction for this voice
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasNotes → bool
-
Check if this voice contains any notes (not just rests)
no setter
- horizontalOffset → double?
-
Horizontal offset for collision avoidance (in staff spaces)
final
- name → String?
-
Optional name for the voice (e.g., "Soprano", "Melody")
final
-
notes
→ List<
Note> -
Get all notes in this voice
no setter
- number → int
-
Voice number (1-based)
final
-
rests
→ List<
Rest> -
Get all rests in this voice
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
add(
MusicalElement element) → void - Add element to this voice
-
getHorizontalOffset(
double staffSpace) → double - Get horizontal offset for this voice
-
getStemDirection(
) → StemDirection - Get stem direction for this voice
-
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