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:
2026-08-02 20:27:39 -07:00
parent 59370ee5dd
commit 3fe6b8a50a
6 changed files with 106 additions and 14 deletions
@@ -275,6 +275,60 @@ struct PresetTests {
#expect(section.route == .stereo, "Route should be recalled")
}
@Test func applyStateRebuildsBoardWhenCabinetVoiceChanges() throws {
// A cabinet voice is a `rebuildsOnChange` selector: only the selected voice's convolver is
// built, so a lightweight recall that changes it must rebuild the board (a plain node write
// would leave audio on the previously-built convolver).
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, numAudioBuses: 128)
defer { try? FileManager.default.removeItem(at: url) }
let sg: ShoeGaze = ShoeGaze(engine: engine)
let board: PedalBoard = try sg.addBoard()
try board.add(CabinetPedal())
try sg.finalizeBoard(board)
guard let original: CabinetPedal = board.pedals.first as? CabinetPedal else {
Issue.record("No CabinetPedal in board")
return
}
// Snapshot at voice 3, then move the live pedal to voice 0 and recall the snapshot.
original.cabinet = 3.0
let snapshot: ShoeGazeState = sg.captureState()
original.cabinet = 0.0
sg.applyState(snapshot)
// The rebuild replaces the instance — the recalled voice must be reflected on the new one.
guard let rebuilt: CabinetPedal = sg.boards[0].pedals.first as? CabinetPedal else {
Issue.record("No CabinetPedal after recall")
return
}
#expect(rebuilt !== original, "board should rebuild when the cabinet voice changes")
#expect(rebuilt.cabinet == 3.0, "recalled cabinet voice should be applied")
}
@Test func applyStateDoesNotRebuildWhenCabinetVoiceUnchanged() throws {
// Recall with the same cabinet voice must NOT rebuild — the lightweight path stays cheap.
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.1, numAudioBuses: 128)
defer { try? FileManager.default.removeItem(at: url) }
let sg: ShoeGaze = ShoeGaze(engine: engine)
let board: PedalBoard = try sg.addBoard()
try board.add(CabinetPedal())
try sg.finalizeBoard(board)
guard let original: CabinetPedal = board.pedals.first as? CabinetPedal else {
Issue.record("No CabinetPedal in board")
return
}
original.cabinet = 2.0
let snapshot: ShoeGazeState = sg.captureState()
sg.applyState(snapshot)
#expect(sg.boards[0].pedals.first === original, "unchanged cabinet voice should not rebuild")
}
// MARK: - In-memory round-trip
@Test func captureStateRoundTripEquality() throws {