From 10a6e122bf52dc1813debddbc3500c46e139b34a Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Wed, 25 Nov 2026 20:11:07 -0800 Subject: [PATCH] feat(midi): MIDI-mappable primary transport footswitch (Capture / Freeze) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Expose a pedal's primary transport footswitch — TunedVerb's Capture, FreezVerb's Freeze — as a MIDI-mappable action, so a footswitch (Program Change) can trigger it. Previously only per-pedal Bypass and the looper's transport were mappable. - New `MIDITransportPedal` protocol (@MainActor): `midiTransportName` + a `toggleMIDITransport()` that presses the pedal's primary footswitch. TunedVerb (Capture) and FreezVerb (Freeze) conform. - `MIDIMap.PedalActionKind.pedalPrimaryTransport`, dispatched by MIDIController to `toggleMIDITransport()`. Learn / persist / resolve-by-id ride the existing pedalAction path (same as the looper actions). - The mapping sheet lists the action for any `MIDITransportPedal` ("Board 2 · TunedVerb · Capture"); the per-pedal control-mapping strip shows a badge for it. A future press-to-trigger pedal just conforms and appears. Tests: conformance + a Program-Change round-trip toggling Capture on/off. Full suite 846 green; both demos build. Co-Authored-By: Claude Opus 4.8 --- .../MIDI/MIDIController.swift | 2 ++ Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift | 4 +++ .../MIDI/MIDITransportPedal.swift | 25 +++++++++++++++++ .../Pedals/FreezVerbPedal.swift | 9 +++++++ .../Pedals/TunedVerbPedal.swift | 9 +++++++ .../ControlMappingStrip.swift | 11 ++++++++ .../LyrebirdShoeGazeUI/MIDIMappingSheet.swift | 8 ++++++ .../MIDIControllerPCTests.swift | 27 +++++++++++++++++++ 8 files changed, 95 insertions(+) create mode 100644 Sources/LyrebirdShoeGaze/MIDI/MIDITransportPedal.swift diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift index e7744a2..a5e4e88 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift @@ -417,6 +417,8 @@ public final class MIDIController { (pedal as? LooperPedal)?.cycleSyncMode() case .looperTrack(let index): (pedal as? LooperPedal)?.tapTrack(index) + case .pedalPrimaryTransport: + (pedal as? MIDITransportPedal)?.toggleMIDITransport() } } diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift index 741eee2..c77fefd 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIMap.swift @@ -114,6 +114,10 @@ public struct MIDIMap: Codable, Equatable, Sendable { /// 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) + + /// Toggles a pedal's primary transport footswitch — any ``MIDITransportPedal`` (e.g. + /// TunedVerb's Capture, FreezVerb's Freeze). Dispatched to `toggleMIDITransport()`. + case pedalPrimaryTransport } // MARK: - Switch binding diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDITransportPedal.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDITransportPedal.swift new file mode 100644 index 0000000..ce92f49 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDITransportPedal.swift @@ -0,0 +1,25 @@ +// MIDITransportPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +/// A pedal with a primary **transport footswitch** — a momentary, latching action beyond generic +/// bypass (e.g. TunedVerb's *Capture*, FreezVerb's *Freeze*) — that can be driven by a MIDI +/// footswitch. +/// +/// Conforming makes the action appear in the MIDI mapping sheet automatically and lets a mapped +/// Program Change fire it: the sheet lists `midiTransportName`, and `MIDIController` calls +/// ``toggleMIDITransport()`` for a `PedalActionKind/pedalPrimaryTransport` binding. A pedal with a +/// richer transport surface (the looper) is handled by its own dedicated action kinds instead. +@MainActor +public protocol MIDITransportPedal: AnyObject { + + /// Short display name of the primary transport footswitch (e.g. `"Capture"`, `"Freeze"`), shown + /// in the MIDI mapping sheet after the pedal name. + var midiTransportName: String { get } + + /// Toggles the primary transport footswitch — called when a mapped MIDI footswitch fires. Same + /// effect as pressing the pedal's on-screen footswitch. + func toggleMIDITransport() +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/FreezVerbPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/FreezVerbPedal.swift index 211b587..3d58533 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/FreezVerbPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/FreezVerbPedal.swift @@ -243,3 +243,12 @@ public final class FreezVerbPedal: Pedal { frozen = 0.0 } } + +// MARK: - MIDI transport + +extension FreezVerbPedal: MIDITransportPedal { + /// The Freeze footswitch is the mappable transport action. + public var midiTransportName: String { "Freeze" } + + public func toggleMIDITransport() { toggleFreeze() } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift index b7a80c2..569a448 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/TunedVerbPedal.swift @@ -242,3 +242,12 @@ public final class TunedVerbPedal: Pedal { captured = 0.0 } } + +// MARK: - MIDI transport + +extension TunedVerbPedal: MIDITransportPedal { + /// The Capture footswitch is the mappable transport action. + public var midiTransportName: String { "Capture" } + + public func toggleMIDITransport() { toggleCapture() } +} diff --git a/Sources/LyrebirdShoeGazeUI/ControlMappingStrip.swift b/Sources/LyrebirdShoeGazeUI/ControlMappingStrip.swift index 2d300d1..6c9fb76 100644 --- a/Sources/LyrebirdShoeGazeUI/ControlMappingStrip.swift +++ b/Sources/LyrebirdShoeGazeUI/ControlMappingStrip.swift @@ -191,6 +191,15 @@ struct PedalMappingStrip: View { rows.append(PedalMappingRow(id: "bypass", label: "Bypass", badges: bypassBadges)) } + // Primary transport footswitch (TunedVerb Capture, FreezVerb Freeze). + if let transport: MIDITransportPedal = pedal as? MIDITransportPedal { + let action: MIDIMap.Action = .pedalAction(pedalID: pedalID, kind: .pedalPrimaryTransport) + let transportBadges: [PedalMappingBadge] = badges(for: action, in: map) + if transportBadges.isEmpty == false { + rows.append(PedalMappingRow(id: "transport", label: transport.midiTransportName, badges: transportBadges)) + } + } + // Looper transport actions. if pedal is LooperPedal { for kind: MIDIMap.PedalActionKind in loopedActionOrder { @@ -248,6 +257,8 @@ struct PedalMappingStrip: View { case .looperSyncToggle: return "Sync" case .looperReset: return "Reset" case .looperTrack(let index): return "Track \(LooperPedal.trackLabel(index))" + // Not a looper action; only looper kinds reach this helper, so a plain fallback suffices. + case .pedalPrimaryTransport: return "Transport" } } } diff --git a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift index cdae79b..4264760 100644 --- a/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift +++ b/Sources/LyrebirdShoeGazeUI/MIDIMappingSheet.swift @@ -120,6 +120,14 @@ public struct MIDIMappingSheet: View { id: "sw-pb-\(pedal.id)", action: .pedalBypass(pedalID: pedal.id), label: "\(board.label) · \(pedal.displayName) · Bypass")) + // A pedal with a primary transport footswitch (TunedVerb Capture, FreezVerb Freeze) + // exposes it as a mappable action. + if let transport: MIDITransportPedal = pedal as? MIDITransportPedal { + rows.append(SwitchRowModel( + id: "sw-pt-\(pedal.id)", + action: .pedalAction(pedalID: pedal.id, kind: .pedalPrimaryTransport), + label: "\(board.label) · \(pedal.displayName) · \(transport.midiTransportName)")) + } // Loopers expose their transport footswitches as mappable switch actions. if pedal is LooperPedal { var looperActions: [(String, String, MIDIMap.PedalActionKind)] = [ diff --git a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift index ac5d55c..8908bd0 100644 --- a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift +++ b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift @@ -353,4 +353,31 @@ struct MIDIControllerPCTests { #expect(looper.isTrackMuted(0), "mapped Program Change should tap (mute) the selected recorded track") } } + + @Test func tunedVerbAndFreezVerbExposeAPrimaryTransport() { + #expect((TunedVerbPedal() as? MIDITransportPedal)?.midiTransportName == "Capture") + #expect((FreezVerbPedal() as? MIDITransportPedal)?.midiTransportName == "Freeze") + } + + @Test func mappedProgramChangeTogglesTunedVerbCapture() throws { + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256) + defer { try? FileManager.default.removeItem(at: url) } + let sg: ShoeGaze = ShoeGaze(engine: engine) + let board: PedalBoard = try sg.addBoard() + let tuned: TunedVerbPedal = TunedVerbPedal() + try board.add(tuned) + try sg.finalizeBoard(board) + let controller: MIDIController = MIDIController(engine: engine, shoeGaze: sg) + + withExtendedLifetime(sg) { + controller.armSwitchLearn(.pedalAction(pedalID: tuned.id, kind: .pedalPrimaryTransport)) + controller.ingestForTesting(.programChange(channel: 0, program: 3)) // learn only + #expect(tuned.captured < 0.5, "learn must not toggle Capture") + + controller.ingestForTesting(.programChange(channel: 0, program: 3)) // fire + #expect(tuned.captured > 0.5, "a mapped Program Change toggles Capture on") + controller.ingestForTesting(.programChange(channel: 0, program: 3)) // fire again + #expect(tuned.captured < 0.5, "a second press toggles Capture off") + } + } }