fix(amps): recall rebuilds on a rebuildsOnChange switch (channel)

Review blocker: lightweight recall (ShoeGaze.applyState) detected topology change
only via Pedal.rebuildSelectorValues (effectSelectors), so a channel switch —
the first rebuildsOnChange *switch* — flipped during a scene recall wrote the
node value but never rebuilt, leaving the stale channel topology (wrong preamp).

- Rename/extend to Pedal.rebuildTopologyValues: folds in effectSwitches flagged
  rebuildsOnChange alongside the selectors (both NaN-sanitized). Recall call sites
  in ShoeGaze+Preset updated.
- FullertonDrive: rename channel constants to generic switchOff/On (used by the
  Bright switch too).
- Test: applyStateRebuildsBoardWhenChannelSwitchChanges — recall flipping the
  channel rebuilds the board and applies the recalled channel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-03 13:10:23 -07:00
parent da4d5e23ea
commit e88db04686
4 changed files with 51 additions and 16 deletions
@@ -329,6 +329,36 @@ struct PresetTests {
#expect(sg.boards[0].pedals.first === original, "unchanged cabinet voice should not rebuild")
}
@Test func applyStateRebuildsBoardWhenChannelSwitchChanges() throws {
// A rebuildsOnChange *switch* (an amp's Clean/Drive channel) changes graph topology, so a
// lightweight recall that flips it must rebuild the board — not just the cab selector case.
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(FullertonDriveAmpPedal())
try sg.finalizeBoard(board)
guard let original: FullertonDriveAmpPedal = board.pedals.first as? FullertonDriveAmpPedal else {
Issue.record("No FullertonDriveAmpPedal in board")
return
}
// Snapshot on the Drive channel, move the live pedal back to Clean, then recall.
original.channel = 1.0
let snapshot: ShoeGazeState = sg.captureState()
original.channel = 0.0
sg.applyState(snapshot)
guard let rebuilt: FullertonDriveAmpPedal = sg.boards[0].pedals.first as? FullertonDriveAmpPedal else {
Issue.record("No FullertonDriveAmpPedal after recall")
return
}
#expect(rebuilt !== original, "board should rebuild when the channel switch changes")
#expect(rebuilt.channel == 1.0, "recalled channel should be applied")
}
// MARK: - In-memory round-trip
@Test func captureStateRoundTripEquality() throws {