generate method
override
Assíncrono porque alguns tipos leem um file: da pasta do curso. turn
é a rodada na sessão (EX05: o play-score com keys: e cycle: escolhe
o tom por ela); quem não usa, ignora.
Implementation
@override
Future<ScoreRound> generate(
PlayPatternSpec spec,
CourseFiles files,
Random rng, {
RoundTurn? turn,
}) async {
final round = turn ?? RoundTurn();
final target = _targetOf(spec, round, rng);
final key = KeySpec.parse(target.name)!;
// `hand: sequence` (EX22): o passo do turno escolhe a mão desta rodada.
final step = spec.handSequence
? clampStep(round.step, kHandSequence.length)
: 0;
final stage = kHandSequence[step];
final hand = spec.handSequence ? _patternHandOf(stage.hand) : spec.hand;
final notes = patternNotesOf(spec, key, hand: hand);
final source = fromMusicXml(
patternScore(notes, clef: patternClefOf(hand), key: target.name),
);
return ScoreRound(
bytes: source.bytes,
fileName: source.fileName,
mode: spec.mode,
hand: spec.handSequence ? stage.hand : _handOf(spec.hand),
bpm: round.bpm ?? spec.bpm,
pitches: [for (final note in notes) note.pitch.midi],
noteIds: [for (var i = 0; i < notes.length; i++) roundNoteId(i)],
marks: patternMarksOf(notes),
keyLabel: target.label,
chainLength: spec.handSequence ? kHandSequence.length : 1,
step: step,
speedFactor: spec.handSequence ? stage.speed : 1.0,
);
}