From 48ac573489aff4238640293b1f3e7824037ad6bd Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Wed, 1 Jul 2026 13:45:13 -0700 Subject: [PATCH] Let one footswitch drive multiple toggles (scenes) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit captureSwitch stole a Program Change from any prior action, so one footswitch could only drive one toggle. applyProgram already fires every matching binding, so this just drops the steal-by-program: one binding per action (re-learning an action replaces it), and a single PC may drive MANY actions — a "scene" (e.g. bypass two pedals, or solo a board and bypass another, from one press). Mirrors the CC multi-target change. Tests: one PC drives two actions and toggles both; re-learning an action replaces its program. 323 green; both app targets build. Co-Authored-By: Claude Opus 4.8 --- .../MIDI/MIDIController.swift | 6 ++-- .../MIDIControllerPCTests.swift | 34 ++++++++++++++++--- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift index 0624ce0..6dd14d4 100644 --- a/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift +++ b/Sources/LyrebirdShoeGaze/MIDI/MIDIController.swift @@ -309,8 +309,10 @@ public final class MIDIController { displayNameHint: hint(for: action) ) var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty - // One action → one program, and reassigning a program steals it from any other action. - map.switches.removeAll { $0.action == action || $0.program == program } + // One binding per action — re-learning an action replaces its binding. A single footswitch + // (program) may drive MULTIPLE actions on purpose (a "scene": e.g. bypass two pedals, or + // solo a board and bypass another, from one press), so we do NOT steal by program number. + map.switches.removeAll { $0.action == action } map.switches.append(binding) shoeGaze.midiMap = map onMapChanged?() diff --git a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift index c7ce353..d543a6c 100644 --- a/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift +++ b/Tests/LyrebirdShoeGazeTests/MIDIControllerPCTests.swift @@ -153,18 +153,42 @@ struct MIDIControllerPCTests { } } - @Test func reassigningProgramStealsFromPriorAction() throws { + @Test func oneProgramCanDriveMultipleActions() throws { + // A single footswitch (PC) may drive several toggles at once — a "scene". + let (controller, sg, boards, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = + try makeRig() + defer { try? FileManager.default.removeItem(at: url) } + + withExtendedLifetime(sg) { + controller.armSwitchLearn(.rigBypass) + controller.ingestForTesting(.programChange(channel: 0, program: 8)) + controller.armSwitchLearn(.pedalBypass(boardIndex: 0, pedalIndex: 0)) + controller.ingestForTesting(.programChange(channel: 0, program: 8)) // same PC, kept + + // Both bindings survive — one PC drives two actions. + #expect(controller.switchBinding(for: .rigBypass)?.program == 8) + #expect(controller.switchBinding(for: .pedalBypass(boardIndex: 0, pedalIndex: 0))?.program == 8) + #expect(sg.midiMap?.switches.count == 2) + + // Firing the PC toggles both at once. + let pedalBypass: UIParamNode = boards[0].pedals[0].$bypass + controller.ingestForTesting(.programChange(channel: 0, program: 8)) + #expect(sg.rigBypassed == true) + #expect(abs(pedalBypass.value - 1.0) < 1e-9) + } + } + + @Test func reLearningAnActionReplacesItsProgram() throws { let (controller, sg, _, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig() defer { try? FileManager.default.removeItem(at: url) } withExtendedLifetime(sg) { controller.armSwitchLearn(.rigBypass) controller.ingestForTesting(.programChange(channel: 0, program: 8)) - controller.armSwitchLearn(.boardBypass(boardIndex: 0)) - controller.ingestForTesting(.programChange(channel: 0, program: 8)) // same PC steals it + controller.armSwitchLearn(.rigBypass) + controller.ingestForTesting(.programChange(channel: 0, program: 9)) // same action, new PC - #expect(controller.switchBinding(for: .rigBypass) == nil, "prior action loses the PC") - #expect(controller.switchBinding(for: .boardBypass(boardIndex: 0))?.program == 8) + #expect(controller.switchBinding(for: .rigBypass)?.program == 9, "re-learn replaces") #expect(sg.midiMap?.switches.count == 1) } }