fix(rigs): don't flag a rig dirty over input/channel differences

Switching between starter rigs prompted "save changes?" even when nothing
was edited. The unsaved-changes check compared full ShoeGazeState snapshots
(`captureState() != entry.state`), which include the live input source and
engine channel counts — and those legitimately differ from a factory rig's
saved values now that a rig switch preserves the player's current input
instead of adopting the rig's saved one.

Add ShoeGazeState.hasSameRigContent(as:) comparing only rig content (boards,
routers, MIDI map, tempo) and use it for the dirty check, so session/engine
settings no longer register as unsaved changes. Test added.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-10 16:40:35 -07:00
parent 5decdd8693
commit 44e6c35550
3 changed files with 44 additions and 1 deletions
@@ -427,6 +427,29 @@ struct PresetTests {
#expect(sg.inputSource == .testLoop, "load leaves the current input source unchanged")
}
@Test func rigContentComparisonIgnoresInputAndChannels() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05, numInputChannels: 1, numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let sg: ShoeGaze = ShoeGaze(engine: engine, inputSource: .testLoop)
let board: PedalBoard = try sg.addBoard()
try board.add(FuzzPedal())
try sg.finalizeBoard(board)
let saved: ShoeGazeState = sg.captureState()
// Changing only the live input source must NOT read as a rig change (the source of the
// spurious "save changes?" prompt when switching starter rigs).
sg.inputSource = .liveInput(channel: 0)
let afterInputChange: ShoeGazeState = sg.captureState()
#expect(afterInputChange.hasSameRigContent(as: saved), "input change must not be a rig change")
#expect(afterInputChange != saved, "but the raw snapshots still differ on the input field")
// A genuine graph difference IS a content change.
let emptyRig: ShoeGazeState = ShoeGazeState(boards: [])
#expect(!saved.hasSameRigContent(as: emptyRig), "different boards must count as a rig change")
}
@Test func loadPreservesCurrentInputSourceNotTheSavedOne() throws {
// A rig captured with live input still RECORDS its source in the snapshot...
let (engineIn, urlIn): (SynthesisEngine, URL) = makeNRTEngine(