apply method

List<PlannedNote> apply(
  1. List<PlannedNote> notes
)

Põe o tempo humano em notes e devolve as notas na mesma ordem, com o ataque, o fim e a velocity deslocados. O Perfeito devolve as mesmas notas.

Implementation

List<PlannedNote> apply(List<PlannedNote> notes) {
  if (_identity || notes.isEmpty) return notes;
  final order = List<int>.generate(notes.length, (i) => i)
    ..sort((a, b) {
      final byOn = notes[a].onMs.compareTo(notes[b].onMs);
      return byOn != 0 ? byOn : a.compareTo(b);
    });
  final sorted = [for (final i in order) notes[i]];
  final attacks = _attacksOf(sorted);
  // O sorteio do trecho inteiro: ligado ou destacado (AV04, "por trecho").
  final legato = _rng.nextDouble() < gains.legatoShare;
  final onMs = List<double>.filled(sorted.length, 0);
  final velocity = List<int>.filled(sorted.length, 0);
  _timeAttacks(sorted, attacks, onMs, velocity);
  final offMs = _releases(sorted, attacks, onMs, legato);
  final out = List<PlannedNote>.of(notes);
  for (var k = 0; k < sorted.length; k++) {
    out[order[k]] = sorted[k].copyWith(
      onMs: onMs[k],
      offMs: offMs[k],
      velocity: velocity[k],
    );
  }
  _started = true;
  return out;
}