pump method

void pump()

Agenda o que cai até lookaheadSeconds à frente, e leva o juiz até o agora. Com autoTick, o Timer chama isto; os testes chamam direto.

Implementation

void pump() {
  final round = _round;
  final clock = _clock;
  final judge = _judge;
  final done = _done;
  if (round == null || clock == null || judge == null || done == null) {
    return;
  }
  if (done.isCompleted || _paused) return;

  final now = engine.nowSeconds;
  final earliest = engine.earliestScheduleSeconds;
  final batch = <ScheduledMidi>[];
  while (_next < _events.length) {
    final event = _events[_next];
    final seconds = clock.secondsAt(event.beat);
    if (seconds > now + lookaheadSeconds) break;
    batch.add(
      ScheduledMidi(
        seconds < earliest ? earliest : seconds,
        event.status,
        event.d1,
        _velocityOf(event),
      ),
    );
    _next++;
  }
  if (batch.isNotEmpty) engine.schedule(batch);

  final beat = clock.beatAt(now);
  judge.tick(beat);
  _emitir(_positionAt(round, clock.gridAt(now)));
  final end = clock.secondsAt(round.totalBeats) + tailSeconds;
  if (now >= end || judge.done) _finish();
}