check method

ChordCheck check(
  1. Iterable<int> held, {
  2. NoteNaming naming = NoteNaming.latin,
  3. bool byEar = false,
})

Confere as notas MIDI que estão apertadas agora. Com byEar (os "Acordes de ouvido"), o aviso de erro não diz a cifra nem o baixo: o aluno os acha de ouvido.

Implementation

ChordCheck check(
  Iterable<int> held, {
  NoteNaming naming = NoteNaming.latin,
  bool byEar = false,
}) {
  final notes = held.toList()..sort();
  if (notes.isEmpty) return const ChordCheck(ChordVerdict.incomplete);
  final pcs = {for (final n in notes) n % 12};
  for (final pc in pcs) {
    if (!allowed.contains(pc)) {
      return ChordCheck(
        ChordVerdict.wrong,
        byEar
            ? '${pcLabel(pc, naming)} não é do acorde que soou.'
            : '${pcLabel(pc, naming)} não é do ${symbol.label}.',
      );
    }
  }
  if (!pcs.containsAll(required)) {
    return const ChordCheck(ChordVerdict.incomplete);
  }
  final lowest = notes.first % 12;
  final wantedBass = bass;
  if (wantedBass != null && lowest != wantedBass) {
    if (byEar) {
      return ChordCheck(
        ChordVerdict.wrong,
        'A nota mais grave (${pcLabel(lowest, naming)}) não é o baixo que '
        'soou.',
      );
    }
    return ChordCheck(
      ChordVerdict.wrong,
      'O baixo é ${pcLabel(wantedBass, naming)}; '
      'a nota mais grave é ${pcLabel(lowest, naming)}.',
    );
  }
  if (hands == ChordHands.both) {
    if (notes.first >= kMiddleC) {
      return const ChordCheck(
        ChordVerdict.wrong,
        'Toque o baixo com a mão esquerda, abaixo do dó central.',
      );
    }
    if (notes.where((n) => n >= kMiddleC).length < 2) {
      return const ChordCheck(
        ChordVerdict.wrong,
        'O acorde vai na mão direita, do dó central para cima.',
      );
    }
  }
  return const ChordCheck(ChordVerdict.right);
}