generate method

  1. @override
Future<QuestionRound> generate(
  1. PlayChordSpec 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(
  PlayChordSpec spec,
  CourseFiles files,
  Random rng, {
  RoundTurn? turn,
}) async {
  final shape = spec.voicing == null ? null : kVoicingShapes[spec.voicing];
  final region = _region(spec);
  final questions = <Question>[];
  List<int>? near;
  for (final (i, pick) in _picks(spec.chords, rng).indexed) {
    final choice = spec.inversions[i % spec.inversions.length];
    final inversion = _inversionOf(choice, pick.chord, rng);
    final reference = _voicing(pick.chord, spec, inversion, near);
    if (reference.isNotEmpty) near = reference;
    final needed = _needed(pick.chord, reference, shape != null, spec.omit5);
    final chord = PlayChord(
      symbol: pick.chord,
      needed: needed,
      // O que o molde pede também é permitido: o `rootless-a` num maj7 pede a
      // 9ª, que a cifra não tem. Sem isto, a referência reprovaria a si mesma.
      allowed: {...pick.chord.pitchClasses, ...needed},
      inversion: inversion,
      voicing: spec.voicing,
      shape: shape,
      strict: spec.strict,
      hand: spec.hand,
      split: spec.split.midi,
      lowest: region.low,
      highest: region.high,
      voiceLeadingMax: spec.voiceLeading,
      reference: reference,
      prompt: spec.prompt,
      degree: pick.degree,
      keyName: pick.keyName,
    );
    // O texto de fábrica (cifra americana); a tela escreve na grafia do app
    // ou do curso, pela mesma função (`playChordPrompt`).
    questions.add(
      Question(
        prompt: playChordPrompt(chord, ChordNotation.american),
        playChord: chord,
      ),
    );
  }
  return QuestionRound(questions, timeLimit: spec.pass.timeLimit);
}