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:
2026-07-01 13:42:16 -07:00
parent 4d8464282e
commit e25b75a880
4 changed files with 51 additions and 21 deletions
@@ -216,11 +216,10 @@ public final class MIDIController {
target: resolved.hinted
)
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
// One control → one CC, and reassigning a CC (same controller + channel) steals it from any
// other control so a given expression pedal drives exactly one thing.
map.ccs.removeAll {
$0.target.addresses(resolved.hinted) || ($0.controller == controller && $0.channel == channel)
}
// One binding per control — re-learning a control replaces its binding. A single CC may
// drive MULTIPLE controls on purpose (e.g. map one expression pedal to two board levels and
// invert one for a crossfade), so we deliberately do NOT steal by controller number.
map.ccs.removeAll { $0.target.addresses(resolved.hinted) }
map.ccs.append(binding)
shoeGaze.midiMap = map
onMapChanged?()
@@ -254,9 +253,10 @@ public final class MIDIController {
private func resolveCC(_ target: MIDIMap.CCTarget) -> ResolvedCC? {
switch target {
case let .pedalControl(boardIndex, pedalIndex, controlIndex, nameHint, labelHint):
guard let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex),
controlIndex >= 0, controlIndex < pedal.ccMappableControls.count else { return nil }
let control: PedalControl = pedal.ccMappableControls[controlIndex]
guard let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex) else { return nil }
let controls: [PedalControl] = pedal.ccMappableControls
guard controlIndex >= 0, controlIndex < controls.count else { return nil }
let control: PedalControl = controls[controlIndex]
if let nameHint: String = nameHint, nameHint != pedal.displayName { return nil }
if let labelHint: String = labelHint, labelHint != control.label { return nil }
let hinted: MIDIMap.CCTarget = .pedalControl(