hanonTimedNotes function
- HanonPiece piece,
- int bpm
As notas de piece com o tempo em segundos, no andamento bpm (semínimas
por minuto): cada pauta anda no próprio tempo.
Implementation
List<TimedNote> hanonTimedNotes(HanonPiece piece, int bpm) {
final perUnit = 60 / bpm / piece.unitsPerQuarter;
// A 2.ª voz tocada (`inner`, o nº 58) corre junto da 1.ª, com o tempo dela.
final cursor = {1: 0, 2: 0, 3: 0, 4: 0};
final last = {1: 0, 2: 0, 3: 0, 4: 0};
final out = <TimedNote>[];
for (final note in piece.timeline) {
final voice = note.inner ? note.staff + 2 : note.staff;
// O acorde soa junto com a nota de antes da mesma voz.
final start = note.chord ? last[voice]! : cursor[voice]!;
if (!note.chord) {
last[voice] = start;
cursor[voice] = start + note.ticks;
}
if (note.rest) continue;
out.add(TimedNote(note.pitch.midi, start * perUnit, note.ticks * perUnit));
}
return out;
}