voiceNumberOf static method
Returns the voice number element belongs to.
Note.voice / Chord.voice are honoured; null and elements without a
voice field (rests, tuplets, clefs, ...) fall back to defaultVoice.
For a tuplet the voice of its first voiced child is used, so that a
triplet written in voice 2 is not accounted against voice 1.
Implementation
static int voiceNumberOf(MusicalElement element) {
if (element is Note) {
return element.voice ?? defaultVoice;
} else if (element is Chord) {
return element.voice ?? defaultVoice;
} else if (element is Tuplet) {
for (final tupletElement in element.elements) {
final voice = voiceNumberOf(tupletElement);
if (voice != defaultVoice) return voice;
}
return defaultVoice;
}
return defaultVoice;
}