onStep method

void onStep(
  1. PracticeStep? step, {
  2. required double nowMs,
  3. required bool animate,
})

O passo step mudou (aperto, fim do passo ou nota seguinte). nowMs é a posição do agendador agora, e animate diz se as partículas e o esvaziar valem (sem animações, a cápsula só some).

Implementation

void onStep(
  PracticeStep? step, {
  required double nowMs,
  required bool animate,
}) {
  final next = holdMarkOf(step);
  final prev = state.shape.hold;
  if (next == prev) return;

  // O passo fechou (o aluno segurou até o fim): as notas dele soltam as
  // partículas. Um passo que volta (o trecho que recomeça) só some.
  var bursts = state.shape.bursts;
  if (prev != null && animate && (step == null || step.index > prev.index)) {
    bursts = [...bursts, HoldBurstMark(serial: _nextSerial(), ids: prev.ids)];
  }
  // Um aperto novo substitui a cápsula que ainda esvazia.
  final emptying = next != null ? null : state.shape.emptying;
  emit(
    HoldCapsuleState(
      shape: HoldShape(hold: next, emptying: emptying, bursts: bursts),
      fill: next == null ? 0 : holdFractionAt(next, nowMs),
      emptyingFill: state.emptyingFill,
    ),
  );
}