Fix CC crossfade steal + rig highlight/graph mismatch; review nits
Bug: assigning a CC to a second control invalidated the first. captureCC stole any binding sharing the CC number, which directly defeats the crossfade use case. Now one binding per CONTROL (re-learning a control replaces it), and a single CC may drive MANY controls — map two board levels to one CC, invert one, for a crossfade. Bug: at launch the sidebar could highlight a different rig than the loaded graph. restoreCurrentRig() highlighted a rig from a separate UserDefault that drifts from the autosave working graph (restored independently). It now derives the highlight from the actual working graph — matching the library entry whose state equals it — so the highlight can never disagree with what's shown; an edited/unsaved session highlights nothing. Review nits: cache ccMappableControls in resolveCC (one array build per CC instead of two); explicit type annotations on the mapping-sheet for-loops. Test: one CC drives two controls with one inverted (crossfade). 322 green; both app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -139,6 +139,32 @@ struct MIDIControllerCCTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func oneCCDrivesMultipleControlsForCrossfade() throws {
|
||||
// Assigning a second control to a CC must NOT steal it from the first — a single expression
|
||||
// pedal can crossfade by driving two controls (one inverted).
|
||||
let (controller, sg, board, url): (MIDIController, ShoeGaze, PedalBoard, URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
// Control 0 = Position, control 1 = Mix on a Volume pedal.
|
||||
controller.armCCLearn(pedalControl(0, 0, 0))
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 20, value: 0))
|
||||
controller.armCCLearn(pedalControl(0, 0, 1))
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 20, value: 0))
|
||||
controller.setCCInverted(for: pedalControl(0, 0, 1), true)
|
||||
|
||||
// Both bindings survive — the same CC drives both controls.
|
||||
#expect(sg.midiMap?.ccs.count == 2, "assigning a 2nd control must not steal the 1st")
|
||||
#expect(controller.ccBinding(for: pedalControl(0, 0, 0)) != nil)
|
||||
|
||||
let position: UIParamNode = board.pedals[0].ccMappableControls[0].node
|
||||
let mix: UIParamNode = board.pedals[0].ccMappableControls[1].node
|
||||
controller.ingestForTesting(.controlChange(channel: 0, controller: 20, value: 127))
|
||||
#expect(abs(position.value - 1.0) < 1e-9, "position sweeps up")
|
||||
#expect(abs(mix.value - 0.0) < 1e-9, "inverted mix sweeps down — a crossfade")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func unboundCCIsIgnored() throws {
|
||||
let (controller, sg, board, url): (MIDIController, ShoeGaze, PedalBoard, URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
Reference in New Issue
Block a user