generate method

  1. @override
Future<ScoreRound> generate(
  1. PlayScoreSpec spec,
  2. CourseFiles files,
  3. Random rng, {
  4. RoundTurn? turn,
})
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(
  PlayScoreSpec spec,
  CourseFiles files,
  Random rng, {
  RoundTurn? turn,
}) async {
  final round = turn ?? RoundTurn();

  final score = await _scoreOf(spec.source, files);
  if (spec.keys == null && spec.cycle == null) {
    return _round(spec, score, round);
  }
  final written = await _writtenKeyOf(score, round);
  if (written == null) {
    throw StateError(
      '`keys` e `cycle` pedem a armadura escrita, e a partitura não a tem '
      '(um K: que não é tom).',
    );
  }
  final target = playScoreKeyFor(spec, written, round, rng);
  if (target == null) {
    return _round(spec, score, round);
  }
  return _round(
    spec,
    score,
    round,
    tone: (
      transpose: Transposition.toFifths(
        written.fifths,
        target.fifths,
        range: (lowest: written.lowest, highest: written.highest),
      )?.interval,
      keyLabel: target.label,
    ),
  );
}