Add iCloud-synced rig library
Replace the single hand-saved rig file with a managed library of named rigs persisted in app storage and synced across devices and both builder apps via a shared iCloud container (iCloud.net.realizedsound.ShoeGazeData), falling back to local storage when iCloud is unavailable. Core (LyrebirdShoeGaze/Presets): - RigEntry: named, timestamped ShoeGazeState (a whole multi-board rig). - RigArchive: portable multi-rig JSON bundle for backup/transfer; legacy single-rig files import as a one-rig archive. - RigLibraryStore (@MainActor @Observable): one JSON file per rig, with NSFileCoordinator writes and NSMetadataQuery live remote-change watching. - RigLibraryLocation: iCloud-or-local directory resolver (skips the slow ubiquity lookup when no iCloud account is signed in). - ShoeGaze.loadRig(from: ShoeGazeState) + captureEntry; shared filename sanitizer factored out of BoardVersionStore. UI (LyrebirdShoeGazeUI): - RigLibrarySidebarView: persistent left listing with new/save/save-as/ duplicate/rename/delete/erase-all and archive import/export. - RigNamePrompt; RigLibraryBootstrap one-call shell setup. - ShoeGazeBuilderView: sidebar wired in; selecting a rig replaces the session; File menu / sidebar do whole-library archive import/export. Shells/entitlements: both builder targets own+start the store and carry the iCloud Documents entitlement; NSUbiquitousContainers exposes the rigs in the Files app. (macOS pbxproj also carries a pre-existing 1.0->1.1.1 version bump.) Tests: RigEntry/RigArchive round-trip + RigLibraryStore CRUD/import/export (15 new; full suite 206 passing). Provisioning (manual, not done here): enable the iCloud container on both App IDs and select it in Signing & Capabilities for both targets. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -55,11 +55,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
private let shoeGaze: ShoeGaze
|
||||
private let window: LyrebirdWindow
|
||||
|
||||
/// The rig library and the entry to highlight at launch; built in `init`.
|
||||
private let library: RigLibraryStore
|
||||
private let initialRigID: UUID?
|
||||
|
||||
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
|
||||
private var recordMenuItem: NSMenuItem?
|
||||
|
||||
/// Default file name offered by the Save panel.
|
||||
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||
/// Default file name offered by the archive Export panel.
|
||||
private static let defaultArchiveFileName: String = "ShoeGaze Library"
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -73,24 +77,31 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
numAudioBuses: AppDelegate.numAudioBuses,
|
||||
driver: coreDriver
|
||||
)
|
||||
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
|
||||
self.coreDriver = coreDriver
|
||||
self.engine = engine
|
||||
self.shoeGaze = ShoeGaze(engine: engine)
|
||||
self.shoeGaze = shoeGaze
|
||||
self.window = LyrebirdWindow(
|
||||
title: "ShoeGaze Builder — Lyrebird Pedalboard",
|
||||
width: AppDelegate.windowWidth,
|
||||
height: AppDelegate.windowHeight
|
||||
)
|
||||
super.init()
|
||||
|
||||
// Restore the autosaved rig if there is one; otherwise seed a default board.
|
||||
// Stored `let`s must be set before `super.init()`. Restore the autosaved working rig (or
|
||||
// seed a board), then bootstrap the rig library from it — all operating on `shoeGaze`, not
|
||||
// on `self` methods (which aren't available pre-`super.init`).
|
||||
if !RigStore.restore(into: shoeGaze) {
|
||||
seedInitialBoard()
|
||||
AppDelegate.seedInitialBoard(into: shoeGaze)
|
||||
}
|
||||
let bootstrap: RigLibraryBootstrap.Result = RigLibraryBootstrap.make(for: shoeGaze)
|
||||
self.library = bootstrap.store
|
||||
self.initialRigID = bootstrap.initialRigID
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
/// Seeds one board with a single pedal so the builder opens with an audible starting point.
|
||||
private func seedInitialBoard() {
|
||||
private static func seedInitialBoard(into shoeGaze: ShoeGaze) {
|
||||
var created: PedalBoard?
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
@@ -108,8 +119,15 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
installMainMenu()
|
||||
let session: ShoeGaze = shoeGaze
|
||||
let driver: CoreAudioDriver = coreDriver
|
||||
let rigLibrary: RigLibraryStore = library
|
||||
let startupRigID: UUID? = initialRigID
|
||||
window.open {
|
||||
ShoeGazeBuilderView(shoeGaze: session, hardwareSampleRate: { driver.deviceSampleRate })
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: session,
|
||||
library: rigLibrary,
|
||||
initialRigID: startupRigID,
|
||||
hardwareSampleRate: { driver.deviceSampleRate }
|
||||
)
|
||||
}
|
||||
anchorWindowLeft()
|
||||
}
|
||||
@@ -180,8 +198,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
mainMenu.addItem(fileMenuItem)
|
||||
let fileMenu: NSMenu = NSMenu(title: "File")
|
||||
fileMenuItem.submenu = fileMenu
|
||||
addItem(to: fileMenu, title: "Save Rig…", action: #selector(saveRigAction(_:)), key: "s")
|
||||
addItem(to: fileMenu, title: "Load Rig…", action: #selector(loadRigAction(_:)), key: "o")
|
||||
// The rig library (saved rigs) lives in the in-window sidebar; the File menu handles the
|
||||
// whole-library archive: a single file holding every rig, for backup or transfer.
|
||||
addItem(to: fileMenu, title: "Export Archive…", action: #selector(exportArchiveAction(_:)), key: "e")
|
||||
addItem(to: fileMenu, title: "Import Archive…", action: #selector(importArchiveAction(_:)), key: "i")
|
||||
|
||||
// Board menu — add board + transport.
|
||||
let boardMenuItem: NSMenuItem = NSMenuItem()
|
||||
@@ -230,34 +250,33 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
|
||||
// MARK: - Menu actions
|
||||
|
||||
@objc private func saveRigAction(_ sender: Any?) {
|
||||
@objc private func exportArchiveAction(_ sender: Any?) {
|
||||
let panel: NSSavePanel = NSSavePanel()
|
||||
panel.allowedContentTypes = [.json]
|
||||
panel.nameFieldStringValue = "\(AppDelegate.defaultRigFileName).json"
|
||||
panel.nameFieldStringValue = "\(AppDelegate.defaultArchiveFileName).json"
|
||||
panel.canCreateDirectories = true
|
||||
let session: ShoeGaze = shoeGaze
|
||||
let rigLibrary: RigLibraryStore = library
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url: URL = panel.url else { return }
|
||||
do { try session.saveRig(to: url) }
|
||||
catch { print("[ShoeGazeBuilder] saveRig failed: \(error)") }
|
||||
do { try rigLibrary.exportArchiveData().write(to: url, options: .atomic) }
|
||||
catch { print("[ShoeGazeBuilder] export archive failed: \(error)") }
|
||||
}
|
||||
}
|
||||
|
||||
@objc private func loadRigAction(_ sender: Any?) {
|
||||
@objc private func importArchiveAction(_ sender: Any?) {
|
||||
let panel: NSOpenPanel = NSOpenPanel()
|
||||
panel.allowedContentTypes = [.json]
|
||||
panel.canChooseDirectories = false
|
||||
panel.allowsMultipleSelection = false
|
||||
let session: ShoeGaze = shoeGaze
|
||||
let activeEngine: SynthesisEngine = engine
|
||||
let rigLibrary: RigLibraryStore = library
|
||||
panel.begin { response in
|
||||
guard response == .OK, let url: URL = panel.url else { return }
|
||||
// loadRig rebuilds the graph; stop the engine around it and restart if it was running.
|
||||
let wasRunning: Bool = activeEngine.isRunning
|
||||
if wasRunning { activeEngine.stop() }
|
||||
do { try session.loadRig(from: url) }
|
||||
catch { print("[ShoeGazeBuilder] loadRig failed: \(error)") }
|
||||
if wasRunning { try? activeEngine.start() }
|
||||
do {
|
||||
let data: Data = try Data(contentsOf: url)
|
||||
_ = try rigLibrary.importArchive(from: data)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilder] import archive failed: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user