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 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 16:58:18 -07:00
parent 6f651b6e17
commit ae067ac6d7
2 changed files with 30 additions and 2 deletions
@@ -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)
@@ -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)