generate method

  1. @override
Future<QuestionRound> generate(
  1. ListenNoteSpec 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<QuestionRound> generate(
  ListenNoteSpec spec,
  CourseFiles files,
  Random rng, {
  RoundTurn? turn,
}) async {
  final buttons = spec.input == AnswerInput.buttons;
  final notes = notesOf(spec.notes, rng, key: buttons ? null : spec.key);
  final reference = spec.reference;
  List<SoundCue> soundOf(Pitch pitch) => [
    if (reference != null) SoundCue([reference.midi]),
    SoundCue([pitch.midi]),
  ];
  return QuestionRound([
    for (final pitch in notes)
      buttons
          ? Question(
              answers: spec.choices,
              correct: spec.choices.indexOf(pitch.step),
              sound: soundOf(pitch),
            )
          : Question(
              expectedPitch: pitch.midi,
              anyOctave: spec.octave == OctaveRule.any,
              sound: soundOf(pitch),
            ),
  ]);
}