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
@@ -140,4 +140,20 @@ public struct ShoeGazeState: Codable, Equatable {
self.numOutputChannels = try container.decodeIfPresent(Int.self, forKey: .numOutputChannels)
self.routers = try container.decodeIfPresent([ChainRouterState].self, forKey: .routers)
}
/// Whether two snapshots describe the same **rig** — its boards, routers, MIDI map, and tempo —
/// ignoring live session settings that are not part of the recalled rig: the input source and the
/// engine's channel counts.
///
/// Use this for unsaved-changes detection. Those session fields are deliberately not applied when
/// switching rigs (see ``ShoeGaze/loadRig(from:keepingCurrentInput:)``), so a plain `==` would
/// report a freshly-loaded rig as "changed" merely because the player's current input differs from
/// the input the rig was saved with — producing a spurious "save changes?" prompt.
public func hasSameRigContent(as other: ShoeGazeState) -> Bool {
boards == other.boards
&& routers == other.routers
&& midiMap == other.midiMap
&& bpm == other.bpm
&& tempoEnabled == other.tempoEnabled
}
}
@@ -1677,12 +1677,16 @@ public struct ShoeGazeBuilderView: View {
/// Whether the working rig differs from the library entry it was loaded from. A working rig with
/// no backing entry counts as dirty when it has any boards.
///
/// Compares rig content only (boards, routers, MIDI, tempo) — not the live input source or engine
/// channel counts, which are intentionally kept across a rig switch and so must not register as
/// unsaved changes (otherwise switching between rigs always prompts to save).
private func isCurrentRigDirty() -> Bool {
guard let id: UUID = currentRigID,
let entry: RigEntry = library.entries.first(where: { $0.id == id }) else {
return !shoeGaze.boards.isEmpty
}
return shoeGaze.captureState() != entry.state
return !shoeGaze.captureState().hasSameRigContent(as: entry.state)
}
/// Saves the current session over the loaded library entry, or prompts for a name when no entry