generate method

  1. @override
Future<QuestionRound> generate(
  1. ListenIntervalSpec 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(
  ListenIntervalSpec spec,
  CourseFiles files,
  Random rng, {
  RoundTurn? turn,
}) async {
  final roots = notesOf(spec.notes, rng);
  final labels = [for (final i in spec.intervals) kIntervalLabels[i]!];
  return QuestionRound([
    for (final root in roots)
      () {
        final index = rng.nextInt(spec.intervals.length);
        final down = switch (spec.direction) {
          IntervalDirection.up => false,
          IntervalDirection.down => true,
          IntervalDirection.both => rng.nextBool(),
        };
        final semitones = spec.intervals[index].semitones;
        final other = (root.midi + (down ? -semitones : semitones)).clamp(
          kLowestPianoMidi,
          kHighestPianoMidi,
        );
        return Question(
          answers: labels,
          correct: index,
          sound: spec.play == IntervalPlay.harmonic
              ? [
                  SoundCue([root.midi, other], seconds: 1.5),
                ]
              : [
                  SoundCue([root.midi]),
                  SoundCue([other]),
                ],
        );
      }(),
  ]);
}