From ae067ac6d76ba94a3bd20557ae56989f88fce701 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Fri, 3 Jul 2026 16:58:18 -0700 Subject: [PATCH] Looper: regression coverage for record-after-reset (both paths) Add quantizedRecordsAgainAfterReset, driving the beat-quantized applyQuantizedTransport generation-guard path across a reset, plus the immediate-path recordsAgainAfterReset. Both confirm the transport state machine re-enters recording/playing correctly after a reset. Expose applyQuantizedTransport / QuantizedAction as internal for the test seam. Co-Authored-By: Claude Opus 4.8 --- .../LyrebirdShoeGaze/Pedals/LooperPedal.swift | 4 +-- .../LooperPedalTests.swift | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift index 7fffc7f..e2e4f52 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift @@ -594,7 +594,7 @@ public final class LooperPedal: Pedal { startPlayback(overdubTrack: nil, at: hostEngine?.currentTime ?? 0) } - private enum QuantizedAction: Sendable { + enum QuantizedAction: Sendable { case beginMaster case closeMaster } @@ -628,7 +628,7 @@ public final class LooperPedal: Pedal { routine.start(engine: engine) } - private func applyQuantizedTransport(_ action: QuantizedAction, generation: Int, at beatSample: SampleTime?) { + func applyQuantizedTransport(_ action: QuantizedAction, generation: Int, at beatSample: SampleTime?) { guard generation == transportGeneration else { return } switch action { case .beginMaster: beginMasterRecording(at: beatSample) diff --git a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift index e195f5f..9ac4e57 100644 --- a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift @@ -464,6 +464,34 @@ struct LooperPedalTests { } } } + @Test func quantizedRecordsAgainAfterReset() throws { + let sampleRate: Double = 44100.0 + let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) = + try makeQuantizedFixture(bpm: 120.0, sampleRate: sampleRate) + withExtendedLifetime(engine) { withExtendedLifetime(clock) { + // Mimic the real (beat-quantized) app path: pressLoop arms + starts a routine that + // fires applyQuantizedTransport with the generation captured at arm time. + // Session 1 + pedal.pressLoop() + pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate * 0.5)) + #expect(pedal.transportState == .recordingMaster) + pedal.pressLoop() + pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate * 2.5)) + #expect(pedal.transportState == .playing) + + // Reset, then session 2 — the quantized callbacks must still land. + pedal.resetLoop() + #expect(pedal.transportState == .clear) + pedal.pressLoop() + pedal.applyQuantizedTransport(.beginMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate * 4.5)) + #expect(pedal.transportState == .recordingMaster, "quantized record after reset must reach recording") + pedal.pressLoop() + pedal.applyQuantizedTransport(.closeMaster, generation: pedal.transportGeneration, at: SampleTime(sampleRate * 6.5)) + #expect(pedal.transportState == .playing) + #expect(pedal.overdubbingTrackIndex == 0) + } } + } + @Test func stopResumeAndCueStop() throws { let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) = try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)