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:
@@ -874,17 +874,21 @@ public struct ShoeGazeBuilderView: View {
|
||||
|
||||
// MARK: - Rig library
|
||||
|
||||
/// Highlights the persisted current rig once the library has loaded. Runs once; only sets the
|
||||
/// highlight when nothing is selected yet and the saved id still exists in the library.
|
||||
/// Highlights the library entry that matches the restored working rig, once the library has
|
||||
/// loaded. Runs once.
|
||||
///
|
||||
/// The working graph is restored from the autosave file independently of any persisted
|
||||
/// selection, so the highlight is derived from the *actual* loaded graph rather than a separate
|
||||
/// stored id (which could point at a different rig and mislabel what's shown). If the working
|
||||
/// graph is an unsaved/edited session that matches no saved entry, nothing is highlighted.
|
||||
private func restoreCurrentRig() {
|
||||
guard !didRestoreRig, library.isLoaded else { return }
|
||||
didRestoreRig = true
|
||||
guard currentRigID == nil,
|
||||
let stored: String = UserDefaults.standard.string(
|
||||
forKey: ShoeGazeBuilderView.currentRigDefaultsKey),
|
||||
let id: UUID = UUID(uuidString: stored),
|
||||
library.entries.contains(where: { $0.id == id }) else { return }
|
||||
currentRigID = id
|
||||
guard currentRigID == nil else { return }
|
||||
let working: ShoeGazeState = shoeGaze.captureState()
|
||||
if let match: RigEntry = library.entries.first(where: { $0.state == working }) {
|
||||
currentRigID = match.id
|
||||
}
|
||||
}
|
||||
|
||||
/// Persists `currentRigID` so the same rig is highlighted on the next launch.
|
||||
|
||||
Reference in New Issue
Block a user