Let one footswitch drive multiple toggles (scenes)
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 <noreply@anthropic.com>
This commit is contained in:
@@ -309,8 +309,10 @@ public final class MIDIController {
|
|||||||
displayNameHint: hint(for: action)
|
displayNameHint: hint(for: action)
|
||||||
)
|
)
|
||||||
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
|
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
|
||||||
// One action → one program, and reassigning a program steals it from any other action.
|
// One binding per action — re-learning an action replaces its binding. A single footswitch
|
||||||
map.switches.removeAll { $0.action == action || $0.program == program }
|
// (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)
|
map.switches.append(binding)
|
||||||
shoeGaze.midiMap = map
|
shoeGaze.midiMap = map
|
||||||
onMapChanged?()
|
onMapChanged?()
|
||||||
|
|||||||
@@ -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()
|
let (controller, sg, _, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||||
defer { try? FileManager.default.removeItem(at: url) }
|
defer { try? FileManager.default.removeItem(at: url) }
|
||||||
|
|
||||||
withExtendedLifetime(sg) {
|
withExtendedLifetime(sg) {
|
||||||
controller.armSwitchLearn(.rigBypass)
|
controller.armSwitchLearn(.rigBypass)
|
||||||
controller.ingestForTesting(.programChange(channel: 0, program: 8))
|
controller.ingestForTesting(.programChange(channel: 0, program: 8))
|
||||||
controller.armSwitchLearn(.boardBypass(boardIndex: 0))
|
controller.armSwitchLearn(.rigBypass)
|
||||||
controller.ingestForTesting(.programChange(channel: 0, program: 8)) // same PC steals it
|
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: .rigBypass)?.program == 9, "re-learn replaces")
|
||||||
#expect(controller.switchBinding(for: .boardBypass(boardIndex: 0))?.program == 8)
|
|
||||||
#expect(sg.midiMap?.switches.count == 1)
|
#expect(sg.midiMap?.switches.count == 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user