diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift index 5cb6c3f..9088a94 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift @@ -403,6 +403,8 @@ public final class MIDIController { (pedal as? LooperPedal)?.toggleReverse() case .looperSyncToggle: (pedal as? LooperPedal)?.cycleSyncMode() + case .looperTrack(let index): + (pedal as? LooperPedal)?.tapTrack(index) } } diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift index 691b8a7..d6d388a 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift @@ -85,6 +85,9 @@ public struct MIDIMap: Codable, Equatable, Sendable { case looperReverse /// Looper: cycles the Sync/Free transport mode (`LooperPedal.cycleSyncMode()`). case looperSyncToggle + /// Looper: taps track `index` (0 = A) — selects it, or mutes it if already selected and + /// recorded (`LooperPedal.tapTrack(_:)`), matching the A/B/C/D dots. + case looperTrack(index: Int) } // MARK: - Switch binding diff --git a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift index 83a451a..e678219 100644 --- a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift +++ b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift @@ -120,7 +120,7 @@ public struct MIDIMappingSheet: View { label: "\(board.label) · \(pedal.displayName) · Bypass")) // Loopers expose their transport footswitches as mappable switch actions. if pedal is LooperPedal { - let looperActions: [(String, String, MIDIMap.PedalActionKind)] = [ + var looperActions: [(String, String, MIDIMap.PedalActionKind)] = [ ("rec", "Record", .looperRecordStop), ("stop", "Stop", .looperStop), ("cue", "Cue Stop", .looperCueStop), @@ -128,6 +128,11 @@ public struct MIDIMappingSheet: View { ("sync", "Sync", .looperSyncToggle), ("reset", "Reset", .looperReset), ] + // A/B/C/D track taps (select / mute), matching the timeline dots. + for i: Int in 0 ..< LooperPedal.trackCount { + let letter: String = LooperPedal.trackLabel(i) + looperActions.append(("track\(letter)", "Track \(letter)", .looperTrack(index: i))) + } for (slug, name, kind): (String, String, MIDIMap.PedalActionKind) in looperActions { rows.append(SwitchRowModel( id: "sw-la-\(slug)-\(pedal.id)", diff --git a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift index 9ee025a..e5cce24 100644 --- a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift +++ b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift @@ -306,4 +306,31 @@ struct MIDIControllerPCTests { #expect(looper.syncToBeat == 0.0, "mapped Program Change should oscillate Sync through its options") } } + + @Test func pedalActionTapsLooperTrack() 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) { + // Get a recorded, selected track A (immediate transport). + looper.clock = nil + looper.pressLoop() + looper.pressLoop() + #expect(looper.trackHasContent(0)) + #expect(!looper.isTrackMuted(0)) + + controller.armSwitchLearn(.pedalAction(pedalID: looper.id, kind: .looperTrack(index: 0))) + controller.ingestForTesting(.programChange(channel: 0, program: 22)) // learn only + #expect(!looper.isTrackMuted(0)) + + controller.ingestForTesting(.programChange(channel: 0, program: 22)) // fire → tapTrack(0) → mute A + #expect(looper.isTrackMuted(0), "mapped Program Change should tap (mute) the selected recorded track") + } + } }