sightDifficulty function
Implementation
SightDifficulty sightDifficulty(SightExercise ex) {
final step = ex.step;
final events = sightSoundingEvents(ex);
final seconds =
ex.measures * ex.ticksPerMeasure * 60 / step.bpm / sightTicksPerQuarter;
// Começos: um por (pauta, voz, instante); o acorde conta uma vez.
final onsets = {for (final e in events) (e.staff, e.voice, e.start)};
final chords = _chordsOf(events);
final notation = _notationOf(ex);
return SightDifficulty(
notesPerSecond: onsets.length / seconds,
maxPolyphony: chords.polyphony,
density: chords.starts == 0 ? 1 : chords.sounding / chords.starts,
maxSpan: chords.span,
leapRate: _leapRate(events, step.bpm),
accidentalsPerBar: notation.accidentals / ex.measures,
keyAccidentals: [
for (final k in [ex.tonic, ...ex.keyChanges.values])
KeySignature.parse(k).fifths.abs(),
].reduce(max),
maxLedgerLines: notation.ledger,
rhythmKinds: notation.kinds.length,
independence: _independence(events),
voices: notation.voices,
parts: notation.parts,
);
}