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)