Looper: add Sync / Free transport mode toggle
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user