romanAnalysisCard function
- TheoryDraw draw
"Em Dó maior: «0» – «1» – …. Qual é a análise em algarismos romanos?": o trecho de 3 ou 4 acordes, e a análise. Os erros são análises do mesmo trecho com um grau trocado, que dão outros acordes (uma análise que dá os mesmos acordes não é um erro, e fica de fora).
Implementation
TheoryCard romanAnalysisCard(TheoryDraw draw) {
final tonic = draw.tonic;
// Só entram os trechos que se escrevem com um acidente por nota no tom (o
// bII7 de Ré♭ seria Mi𝄫7).
final fits = [
for (final t in _romanTemplates)
if (_singleChords([for (final d in t.$1) degreeChord(d, tonic)])) t,
];
final template = fits[draw.rng.nextInt(fits.length)];
final degrees = template.$1;
final chords = [for (final d in degrees) degreeChord(d, tonic)];
final right = degrees.join(' – ');
final sound = _chordsId(chords);
final pool = {for (final t in _romanTemplates) ...t.$1}.toList();
final errors = <String>{};
for (var i = 0; i < degrees.length; i++) {
for (final d in pool) {
final candidate = [...degrees]..[i] = d;
final candidateChords = [
for (final c in candidate) degreeChord(c, tonic),
];
if (_chordsId(candidateChords) != sound &&
_singleChords(candidateChords)) {
errors.add(candidate.join(' – '));
}
}
}
final sorted = errors.toList()..shuffle(draw.rng);
final choice = choices(
textOption(right, right),
[for (final text in sorted) textOption(text, text)],
const [],
draw.rng,
);
final marks = [for (var i = 0; i < chords.length; i++) '«$i»'].join(' – ');
return TheoryCard(
prompt:
'Em ${tonicName(tonic)}: $marks. Qual é a análise em algarismos '
'romanos?',
explanation: template.$2,
chords: chords,
options: choice.options,
correct: choice.correct,
);
}