fix(cab): rebuild board on lightweight recall of a topology selector
Review follow-up to the single-convolver cab change. Now that only the selected cabinet voice's convolver is built, any path that changes the selector value without rebuilding leaves audio on the stale convolver. The UI drag already rebuilds; the gap was ShoeGaze.applyState (lightweight scene recall), which applies param snapshots to live pedals without a rebuild. - Pedal.rebuildSelectorValues: values of effectSelectors flagged rebuildsOnChange. - applyState/applySegmentParams/applyBranchParams: detect when a rebuildsOnChange selector value actually changes during recall and rebuild only those boards; boards without such a selector keep the cheap live-apply path. - CabinetVoice.voice(atSelectorValue:): guard non-finite and clamp in Double space so Int() can never trap on a corrupt preset value. - Doc fixes: CabinetPedal.cabinet and AmpVoicePedal chain diagram no longer claim a live Select. MIDI CC is unaffected: selectors are not in ccMappableControls (knobs + sliders only). Tests: recall changing the cab voice rebuilds and applies; recall with an unchanged voice does not rebuild. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -350,7 +350,17 @@ extension ShoeGaze {
|
||||
/// - Parameter state: The `ShoeGazeState` whose parameter values should be applied.
|
||||
public func applyState(_ state: ShoeGazeState) {
|
||||
for (board, boardState) in zip(boards, state.boards) {
|
||||
applySegmentParams(boardState.segments, to: board.orderedSegments)
|
||||
let topologyChanged: Bool = applySegmentParams(boardState.segments, to: board.orderedSegments)
|
||||
// A `rebuildsOnChange` selector (e.g. a cabinet voice) picks which nodes exist in the
|
||||
// graph, so a plain node write during recall is invisible until the board is rebuilt.
|
||||
// Rebuild only the boards where such a selector actually changed value.
|
||||
if topologyChanged {
|
||||
do {
|
||||
_ = try rebuildBoard(board, from: board.captureState())
|
||||
} catch {
|
||||
print("[ShoeGaze] board rebuild after recall failed: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
// A recall restores each pedal's tempo-sync state but not its derived values (no clock is
|
||||
// consulted in `Pedal.applyState`), so recompute them against the rig's current tempo —
|
||||
@@ -363,30 +373,39 @@ extension ShoeGaze {
|
||||
/// Positionally applies segment parameter snapshots to live board segments, including
|
||||
/// branch pedals and split routing modes. Type or topology mismatches at any position are
|
||||
/// skipped silently (lightweight recall is for topologically identical rigs).
|
||||
/// - Returns: `true` if any pedal's `rebuildsOnChange` selector value changed, meaning the board
|
||||
/// must be rebuilt for the new selection to take effect.
|
||||
@discardableResult
|
||||
private func applySegmentParams(
|
||||
_ states: [BoardSegmentState],
|
||||
to segments: [BoardSegment]
|
||||
) {
|
||||
) -> Bool {
|
||||
var topologyChanged: Bool = false
|
||||
for (segment, segmentState) in zip(segments, states) {
|
||||
switch (segment, segmentState) {
|
||||
case let (.pedal(pedal), .pedal(pedalState)):
|
||||
if pedal.displayName == pedalState.type {
|
||||
let before: [Double] = pedal.rebuildSelectorValues
|
||||
pedal.applyState(pedalState)
|
||||
if pedal.rebuildSelectorValues != before { topologyChanged = true }
|
||||
}
|
||||
|
||||
case let (.parallel(section), .parallel(parallelState)):
|
||||
applyBranchParams(parallelState.branchA, to: section.branchA.pedals)
|
||||
applyBranchParams(parallelState.branchB, to: section.branchB.pedals)
|
||||
let a: Bool = applyBranchParams(parallelState.branchA, to: section.branchA.pedals)
|
||||
let b: Bool = applyBranchParams(parallelState.branchB, to: section.branchB.pedals)
|
||||
if a || b { topologyChanged = true }
|
||||
section.splitter.mode = parallelState.mode
|
||||
|
||||
case let (.stereoSplit(section), .stereoSplit(stereoState)):
|
||||
applyBranchParams(stereoState.left, to: section.left.pedals)
|
||||
applyBranchParams(stereoState.right, to: section.right.pedals)
|
||||
let l: Bool = applyBranchParams(stereoState.left, to: section.left.pedals)
|
||||
let r: Bool = applyBranchParams(stereoState.right, to: section.right.pedals)
|
||||
if l || r { topologyChanged = true }
|
||||
section.route = stereoState.route
|
||||
|
||||
case let (.stereoUnzip(section), .stereoUnzip(unzipState)):
|
||||
applyBranchParams(unzipState.left, to: section.left.pedals)
|
||||
applyBranchParams(unzipState.right, to: section.right.pedals)
|
||||
let l: Bool = applyBranchParams(unzipState.left, to: section.left.pedals)
|
||||
let r: Bool = applyBranchParams(unzipState.right, to: section.right.pedals)
|
||||
if l || r { topologyChanged = true }
|
||||
section.route = unzipState.route
|
||||
|
||||
default:
|
||||
@@ -394,12 +413,20 @@ extension ShoeGaze {
|
||||
continue
|
||||
}
|
||||
}
|
||||
return topologyChanged
|
||||
}
|
||||
|
||||
/// Positionally applies branch pedal snapshots to live branch pedals, matching by type.
|
||||
private func applyBranchParams(_ states: [PedalState], to pedals: [Pedal]) {
|
||||
///
|
||||
/// - Returns: `true` if any branch pedal's `rebuildsOnChange` selector value changed.
|
||||
@discardableResult
|
||||
private func applyBranchParams(_ states: [PedalState], to pedals: [Pedal]) -> Bool {
|
||||
var topologyChanged: Bool = false
|
||||
for (pedal, pedalState) in zip(pedals, states) where pedal.displayName == pedalState.type {
|
||||
let before: [Double] = pedal.rebuildSelectorValues
|
||||
pedal.applyState(pedalState)
|
||||
if pedal.rebuildSelectorValues != before { topologyChanged = true }
|
||||
}
|
||||
return topologyChanged
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user