sightCrossings function

List<int> sightCrossings(
  1. SightExercise ex
)

Os instantes em que a direita está abaixo da esquerda: o compasso (base 0) de cada um.

Implementation

List<int> sightCrossings(SightExercise ex) {
  final events = sightSoundingEvents(ex);
  final out = <int>[];
  final starts = {for (final e in events) e.start}.toList()..sort();
  for (final at in starts) {
    final right = sightSoundingAt(events, 1, at);
    final left = sightSoundingAt(events, 2, at);
    if (right.isEmpty || left.isEmpty) continue;
    final low = right.map((e) => e.midi).reduce((a, b) => a < b ? a : b);
    final high = left.map((e) => e.midi).reduce((a, b) => a > b ? a : b);
    if (low < high) out.add(at ~/ ex.ticksPerMeasure);
  }
  return out;
}