generate method

  1. @override
Future<TimedRound> generate(
  1. PlayLeadSheetSpec 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<TimedRound> generate(
  PlayLeadSheetSpec spec,
  CourseFiles files,
  Random rng, {
  RoundTurn? turn,
}) async {
  final bytes = await files.read(spec.file);
  final melody = readMelodyXml(utf8.decode(bytes));
  if (melody == null) {
    throw StateError('${spec.file} não é uma melodia lida');
  }
  final time = _timeOf(melody);
  final problems = <String>[];
  final chords = leadSheetChords(melody, error: problems.add);
  if (chords == null) throw StateError(problems.first);

  final slots = _slotsOf(chords);
  final swing = spec.swing ?? 50;
  final total = melody.measures.last.start + melody.measures.last.beats;
  final free = spec.melody == LeadMelody.free;
  final targets = _targetsOf(melody, slots);
  final attacks = _attacksOf(spec, melody, slots, swing);
  final changes = free
      ? const <UnderChange>[]
      : _underOf(spec, targets, slots);
  return TimedRound(
    bpm: spec.bpm,
    time: time,
    totalBeats: total,
    swing: swing,
    metronome: true,
    split: spec.split.midi,
    scoreBytes: bytes,
    fileName: spec.file.split('/').last,
    showsFeedback: true,
    scoreCursor: true,
    judge: () => LeadSheetJudge(
      slots: slots,
      chords: ChartSession(
        slots: slots,
        attacks: attacks,
        bpm: spec.bpm,
        chorusBeats: total,
        split: spec.split.midi,
        strict: true,
        omit5: true,
        swing: swing,
        pass: spec.pass,
      ),
      melody: free ? null : MelodyJudge(targets: targets, bpm: spec.bpm),
      split: spec.split.midi,
      bpm: spec.bpm,
      changes: changes,
    ),
  );
}