From 5dafc00d98ef131f142d2245d1bd9fcd7c0f4f53 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Fri, 3 Jul 2026 17:16:13 -0700 Subject: [PATCH] Looper: add Sync / Free transport mode toggle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New syncToBeat switch (Free / Sync, default Sync) rendered as a segmented control below the knobs and persisted with the rig. When off, runQuantized applies transport immediately (freeform — loop length is whatever you play, not beat-measured) even with a clock present; when on, record start / loop close arm to the next beat as before. Not reset by resetLoop / resetForRebuild so the mode sticks. Covered by freeformModeRecordsImmediatelyDespiteClock. Co-Authored-By: Claude Opus 4.8 --- .../LyrebirdShoeGaze/Pedals/LooperPedal.swift | 22 ++++++++++++++++++- .../LooperPedalTests.swift | 22 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift index 16a664f..0148e7d 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/LooperPedal.swift @@ -70,6 +70,11 @@ public final class LooperPedal: Pedal { /// Playback direction. `0` = forward, `1` = reverse. Read as `1 − 2·reverse`. @UIParam public var reverse: Double = 0.0 + /// Transport sync mode. `1` = beat-quantized (record start / loop close snap to the next + /// beat via the shared clock); `0` = freeform (immediate, loop length is whatever you play). + /// Persisted with the rig. Default `1`. + @UIParam public var syncToBeat: Double = 1.0 + // MARK: - Internal live state (read by the audio graph / UI LEDs) /// `1` while the loop bank is playing, else `0`. Gates the whole player sum and the overdub @@ -189,6 +194,20 @@ public final class LooperPedal: Pedal { ] } + /// Beat-sync vs freeform transport mode, as a two-position segmented switch below the knobs. + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Sync", + node: $syncToBeat, + options: [ + PedalSwitch.Option(title: "Free", value: 0.0), + PedalSwitch.Option(title: "Sync", value: 1.0), + ] + ), + ] + } + /// Transport row: the smart Loop footswitch, the two stops, direction, and reset. public override var effectTransportButtons: [PedalButton] { [ @@ -657,7 +676,8 @@ public final class LooperPedal: Pedal { private func runQuantized(_ action: QuantizedAction) { transportGeneration += 1 let generation: Int = transportGeneration - guard let clock: LyrebirdClock = clock, let engine: SynthesisEngine = hostEngine else { + // Freeform (Sync off) or no clock/engine → apply immediately, un-quantized. + guard syncToBeat >= 0.5, let clock: LyrebirdClock = clock, let engine: SynthesisEngine = hostEngine else { applyQuantizedTransport(action, generation: generation, at: nil) return } diff --git a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift index ee47d17..46aabae 100644 --- a/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/LooperPedalTests.swift @@ -163,7 +163,7 @@ struct LooperPedalTests { @Test func exposesLooperControls() throws { let pedal: LooperPedal = LooperPedal() #expect(pedal.effectKnobs.map { $0.label } == ["Crossfade", "Playback", "Overdub", "Feedback"]) - #expect(pedal.effectSwitches.isEmpty) + #expect(pedal.effectSwitches.map { $0.label } == ["Sync"]) #expect(pedal.effectButtons.isEmpty) #expect(pedal.effectTransportButtons.map { $0.label } == ["Loop", "Stop", "Cue Stop", "Reverse", "Reset"]) } @@ -510,6 +510,26 @@ struct LooperPedalTests { } } } + @Test func freeformModeRecordsImmediatelyDespiteClock() throws { + let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) = + try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0) + withExtendedLifetime(engine) { withExtendedLifetime(clock) { + // Sync off: even with a clock present, transport is immediate — no armed/waiting state. + pedal.syncToBeat = 0.0 + pedal.pressLoop() + #expect(pedal.transportState == .recordingMaster, "freeform record starts immediately") + pedal.pressLoop() + #expect(pedal.transportState == .playing) + #expect(pedal.loopLengthBeats == 0.0, "freeform loops aren't beat-measured") + + // Flip to Sync: the next take arms for the beat instead. + pedal.resetLoop() + pedal.syncToBeat = 1.0 + pedal.pressLoop() + #expect(pedal.transportState == .armedRecord, "sync record arms for the next beat") + } } + } + @Test func stopResumeAndCueStop() throws { let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) = try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)