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
@@ -101,7 +101,7 @@ public struct MIDIMappingSheet: View {
SwitchRowModel(id: "sw-rig", action: .rigBypass, label: "Rig Bypass"),
SwitchRowModel(id: "sw-all", action: .allBoards, label: "All Boards On"),
]
for boardPair in shoeGaze.boards.enumerated() {
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
let boardIndex: Int = boardPair.offset
let board: PedalBoard = boardPair.element
rows.append(SwitchRowModel(id: "sw-solo-\(boardIndex)",
@@ -113,7 +113,7 @@ public struct MIDIMappingSheet: View {
rows.append(SwitchRowModel(id: "sw-byp-\(boardIndex)",
action: .boardBypass(boardIndex: boardIndex),
label: "\(board.label) · Bypass"))
for pedalPair in board.pedals.enumerated() {
for pedalPair: (offset: Int, element: Pedal) in board.pedals.enumerated() {
rows.append(SwitchRowModel(
id: "sw-pb-\(boardIndex)-\(pedalPair.offset)",
action: .pedalBypass(boardIndex: boardIndex, pedalIndex: pedalPair.offset),
@@ -125,7 +125,7 @@ public struct MIDIMappingSheet: View {
private var ccRowModels: [CCRowModel] {
var rows: [CCRowModel] = []
for boardPair in shoeGaze.boards.enumerated() {
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
let boardIndex: Int = boardPair.offset
let board: PedalBoard = boardPair.element
// Board master level (the board fader).
@@ -133,10 +133,10 @@ public struct MIDIMappingSheet: View {
id: "cc-blvl-\(boardIndex)",
target: .boardLevel(boardIndex: boardIndex, boardLabelHint: nil),
label: "\(board.label) · Level"))
for pedalPair in board.pedals.enumerated() {
for pedalPair: (offset: Int, element: Pedal) in board.pedals.enumerated() {
let pedalIndex: Int = pedalPair.offset
let pedal: Pedal = pedalPair.element
for controlPair in pedal.ccMappableControls.enumerated() {
for controlPair: (offset: Int, element: PedalControl) in pedal.ccMappableControls.enumerated() {
rows.append(CCRowModel(
id: "cc-\(boardIndex)-\(pedalIndex)-\(controlPair.offset)",
target: .pedalControl(