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:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user