0d17ed260b
Persistence (macOS + iOS): - RigStore autosaves the rig (rigData JSON) to Application Support and restores it on launch. App models restore-or-seed at init; macOS saves on terminate + resignActive, iOS saves on scenePhase leaving .active. The builder also autosaves after structural edits (add board/pedal, load, clear). Clear (both platforms): - A Clear button in the builder opens a confirmation dialog: Save & Clear / Clear Without Saving / Cancel. Clear removes all boards and seeds one fresh empty board, then autosaves. Save & Clear triggers the save mechanism and only clears once the save completes (cancelling the save leaves the rig intact). - The rig-save exporter is now cross-platform (was iOS-only) so Save and the Save & Clear flow work on macOS too; macOS keeps its File-menu Load. Tests: RigStore save/restore round-trip across instances; restore is a no-op with no autosave. 186 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
53 lines
1.9 KiB
Swift
53 lines
1.9 KiB
Swift
// RigStoreTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
@testable import LyrebirdShoeGaze
|
|
|
|
@MainActor
|
|
@Suite("RigStore")
|
|
struct RigStoreTests {
|
|
|
|
@Test func savesAndRestoresAcrossInstances() throws {
|
|
RigStore.clear()
|
|
defer { RigStore.clear() }
|
|
|
|
// Build a rig and autosave it.
|
|
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
|
defer { try? FileManager.default.removeItem(at: urlA) }
|
|
let a: ShoeGaze = ShoeGaze(engine: engineA)
|
|
let lead: PedalBoard = try a.addBoard()
|
|
lead.label = "Lead"
|
|
try a.appendPedal(.overdrive, to: lead)
|
|
try a.finalizeBoard(lead)
|
|
let clean: PedalBoard = try a.addBoard()
|
|
clean.label = "Clean"
|
|
try a.appendPedal(.graphicEQ, to: clean)
|
|
try a.finalizeBoard(clean)
|
|
#expect(RigStore.save(a))
|
|
|
|
// A fresh, boardless instance restores the autosaved rig.
|
|
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
|
defer { try? FileManager.default.removeItem(at: urlB) }
|
|
let b: ShoeGaze = ShoeGaze(engine: engineB)
|
|
#expect(RigStore.restore(into: b))
|
|
#expect(b.boards.count == 2)
|
|
#expect(b.boards.first?.label == "Lead")
|
|
#expect(b.boards.last?.label == "Clean")
|
|
}
|
|
|
|
@Test func restoreReturnsFalseWhenNoAutosave() throws {
|
|
RigStore.clear()
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 64)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
|
#expect(!RigStore.restore(into: sg), "restore should report nothing to load after clear()")
|
|
}
|
|
}
|