musicScoreOf function

double musicScoreOf(
  1. MusicSummary s,
  2. double speed
)

A dificuldade da música na escala do sightDifficulty, ao andamento speed (fração do escrito).

Implementation

double musicScoreOf(MusicSummary s, double speed) {
  final melody = s.lines.where((l) => l.staff == 1);
  final span = melody.isEmpty
      ? 0
      : melody.map((l) => l.highMidi - l.lowMidi).reduce(max);
  final altered = s.demands
      .where((d) => d.kind == MusicDemandKind.alteredNote)
      .fold<int>(0, (n, d) => n + d.measures.length);
  final figures = s.demands
      .where((d) => d.kind == MusicDemandKind.figure)
      .length;
  final bars = max(1, s.measures);
  return (s.notesPerSecond ?? 0) * speed * sightWeights.notesPerSecond +
      musicKeyAccidentals(s.tonicPc, minor: s.minor) *
          sightWeights.keyAccidentals +
      span * sightWeights.maxSpan +
      altered / bars * sightWeights.accidentalsPerBar +
      figures * sightWeights.rhythmKinds;
}