sightRhythmXml function
- SightExercise ex, {
- required int staff,
A partitura só com o ritmo de ex (E09, answer: dictation), na pauta
staff (1 = sol, 2 = fá): uma pauta, com a clave, a armadura e a fórmula
do passo, e só a voz 0. Sem andamento: a frase pode soar em outro andamento
que o do passo (sightListenBpm). Cada nota fica na linha do meio, com
cabeça em barra, menos a primeira, que vem escrita na altura de verdade. Os
ids são os de sightNoteId.
Implementation
String sightRhythmXml(SightExercise ex, {required int staff}) {
final measures = (staff == 1 ? ex.right : ex.left).first;
final octave = staff == 1 ? _rightOctave : _leftOctave;
final middleLetter = staff == 1 ? 'B' : 'D';
final key = KeySignature.parse(ex.tonic);
final accidentals = _Accidentals(key);
final scale = sightDivisionScale(ex);
final out = _partwiseStart();
var first = true;
var tiedIn = false;
for (var m = 0; m < measures.length; m++) {
final notes = measures[m];
out.writeln(' <measure number="${m + 1}">');
if (ex.systemBreaks.contains(m)) {
out.writeln(' <print new-system="yes"/>');
}
accidentals.newMeasure();
if (m == 0) _writeHeader(out, ex, only: staff);
final beams = _beams(notes, sightStartsOf(notes), ex.beatTicks);
for (var i = 0; i < notes.length; i++) {
final note = notes[i];
// A primeira nota vem na altura de verdade; as outras, na linha do meio.
final real = !note.isRest && first;
if (!note.isRest) first = false;
final _Pitch? pitch = note.isRest
? null
: real
? _pitchOf(ex.tonic, note.tones.first, octave)
: (
letter: _letters.indexOf(middleLetter),
octave: octave,
alter: key.alterOf(middleLetter),
);
_writeNote(
out,
_Lane(1, 1, scale),
note,
_NoteMark(
pitch: pitch,
id: note.isRest ? null : sightNoteId(staff, m, i),
accidental: real ? accidentals.write(pitch!) : null,
tieStop: tiedIn && !note.isRest,
slash: !note.isRest && !real,
beams: beams[i],
notations: _notations(note, tieStop: tiedIn),
),
);
tiedIn = note.tie && !note.isRest;
}
out.writeln(' </measure>');
}
return _partwiseEnd(out);
}