Looper: MIDI-mappable Sync, cycling through the switch options

Add a looperSyncToggle PedalActionKind (dispatched to LooperPedal.cycleSyncMode)
and a Sync row in the MIDI mapping sheet. A mapped switch/Program Change
oscillates the control through its positions on each press, via a reusable
PedalSwitch.nextValue(after:) that advances to the next option and wraps — so
this generalises to any multi-position switch, not just the two-state Sync.

Tests: cycleSyncModeOscillatesThroughOptions, pedalActionCyclesLooperSync.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 17:24:50 -07:00
parent 5dafc00d98
commit 3ef39a7a0d
7 changed files with 52 additions and 0 deletions
@@ -530,6 +530,15 @@ struct LooperPedalTests {
} }
}
@Test func cycleSyncModeOscillatesThroughOptions() throws {
let pedal: LooperPedal = LooperPedal()
#expect(pedal.syncToBeat == 1.0) // Sync by default
pedal.cycleSyncMode()
#expect(pedal.syncToBeat == 0.0, "cycle → Free")
pedal.cycleSyncMode()
#expect(pedal.syncToBeat == 1.0, "cycle wraps back → Sync")
}
@Test func stopResumeAndCueStop() throws {
let (engine, clock, pedal): (SynthesisEngine, LyrebirdClock, LooperPedal) =
try makeQuantizedFixture(bpm: 120.0, sampleRate: 44100.0)
@@ -286,4 +286,24 @@ struct MIDIControllerPCTests {
#expect(looper.reverse == 1.0, "mapped Program Change should flip the looper's reverse")
}
}
@Test func pedalActionCyclesLooperSync() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
let sg: ShoeGaze = ShoeGaze(engine: engine)
let board: PedalBoard = try sg.addBoard()
let looper: LooperPedal = LooperPedal()
try board.add(looper)
try sg.finalizeBoard(board)
let controller: MIDIController = MIDIController(engine: engine, shoeGaze: sg)
defer { try? FileManager.default.removeItem(at: url) }
withExtendedLifetime(sg) {
controller.armSwitchLearn(.pedalAction(pedalID: looper.id, kind: .looperSyncToggle))
controller.ingestForTesting(.programChange(channel: 0, program: 21)) // learn only
#expect(looper.syncToBeat == 1.0)
controller.ingestForTesting(.programChange(channel: 0, program: 21)) // fire → cycle
#expect(looper.syncToBeat == 0.0, "mapped Program Change should oscillate Sync through its options")
}
}
}