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:
@@ -163,7 +163,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
@@ -176,7 +176,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 1.0;
|
||||
MARKETING_VERSION = 1.1.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@@ -194,7 +194,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 3;
|
||||
CURRENT_PROJECT_VERSION = 4;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@@ -206,7 +206,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||
MARKETING_VERSION = 1.0;
|
||||
MARKETING_VERSION = 1.1.1;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
|
||||
@@ -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)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,5 +28,17 @@
|
||||
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||
<key>NSPrincipalClass</key>
|
||||
<string>NSApplication</string>
|
||||
<key>NSUbiquitousContainers</key>
|
||||
<dict>
|
||||
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
||||
<dict>
|
||||
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
||||
<true/>
|
||||
<key>NSUbiquitousContainerName</key>
|
||||
<string>ShoeGaze</string>
|
||||
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
||||
<string>Any</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -4,5 +4,17 @@
|
||||
<dict>
|
||||
<key>com.apple.security.device.audio-input</key>
|
||||
<true/>
|
||||
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.net.realizedsound.ShoeGazeData</string>
|
||||
</array>
|
||||
<key>com.apple.developer.icloud-services</key>
|
||||
<array>
|
||||
<string>CloudDocuments</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.net.realizedsound.ShoeGazeData</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -169,6 +169,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = iphoneos;
|
||||
@@ -194,6 +195,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = iphoneos;
|
||||
|
||||
@@ -41,5 +41,17 @@
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>NSUbiquitousContainers</key>
|
||||
<dict>
|
||||
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
||||
<dict>
|
||||
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
||||
<true/>
|
||||
<key>NSUbiquitousContainerName</key>
|
||||
<string>ShoeGaze</string>
|
||||
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
||||
<string>Any</string>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.developer.icloud-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.net.realizedsound.ShoeGazeData</string>
|
||||
</array>
|
||||
<key>com.apple.developer.icloud-services</key>
|
||||
<array>
|
||||
<string>CloudDocuments</string>
|
||||
</array>
|
||||
<key>com.apple.developer.ubiquity-container-identifiers</key>
|
||||
<array>
|
||||
<string>iCloud.net.realizedsound.ShoeGazeData</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -26,6 +26,8 @@ struct ShoeGazeBuilderiOSApp: App {
|
||||
NavigationStack {
|
||||
ShoeGazeBuilderView(
|
||||
shoeGaze: model.shoeGaze,
|
||||
library: model.library,
|
||||
initialRigID: model.initialRigID,
|
||||
hardwareSampleRate: { model.hardwareSampleRate },
|
||||
onEnableLiveInput: { model.enableLiveInput() }
|
||||
)
|
||||
|
||||
@@ -8,6 +8,7 @@ import AVFoundation
|
||||
import Observation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdShoeGaze
|
||||
import LyrebirdShoeGazeUI
|
||||
|
||||
/// Observable model owning the `SynthesisEngine` and `ShoeGaze` session for the iOS builder.
|
||||
///
|
||||
@@ -48,23 +49,43 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
private var engine: SynthesisEngine
|
||||
private var iosDriver: iOSAudioDriver
|
||||
|
||||
/// The shared rig library (iCloud-or-local). Independent of the engine, so it survives the
|
||||
/// live-input engine rebuild.
|
||||
private(set) var library: RigLibraryStore
|
||||
|
||||
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
||||
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
||||
|
||||
/// The library entry to highlight as current on this launch (and after an engine rebuild),
|
||||
/// resolved live from the persisted id so a mid-session selection survives a rebuild.
|
||||
var initialRigID: UUID? {
|
||||
guard let stored: String = UserDefaults.standard.string(
|
||||
forKey: ShoeGazeBuilderView.currentRigDefaultsKey),
|
||||
let id: UUID = UUID(uuidString: stored),
|
||||
library.entries.contains(where: { $0.id == id }) else { return nil }
|
||||
return id
|
||||
}
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
init() {
|
||||
ShoeGazeBuilderiOSAppModel.configureAudioSession()
|
||||
let built: (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) =
|
||||
ShoeGazeBuilderiOSAppModel.buildEngine(inputChannels: ShoeGazeBuilderiOSAppModel.inputChannels)
|
||||
let shoeGaze: ShoeGaze = built.shoeGaze
|
||||
self.engine = built.engine
|
||||
self.iosDriver = built.driver
|
||||
self.shoeGaze = built.shoeGaze
|
||||
self.shoeGaze = shoeGaze
|
||||
|
||||
// Restore the autosaved rig if there is one; otherwise seed a default board.
|
||||
// Restore the autosaved working rig if there is one; otherwise seed a default board. Operate
|
||||
// on the local `shoeGaze`, not `self.shoeGaze`: self may not be touched until every stored
|
||||
// property (including `library`) is initialized.
|
||||
if !RigStore.restore(into: shoeGaze) {
|
||||
seedFallbackBoard()
|
||||
ShoeGazeBuilderiOSAppModel.seedFallbackBoard(into: shoeGaze)
|
||||
}
|
||||
|
||||
// Bootstrap the rig library (iCloud-or-local), seeding it from the working rig on first run.
|
||||
self.library = RigLibraryBootstrap.make(for: shoeGaze).store
|
||||
}
|
||||
|
||||
/// Persists the current rig. Call when the app moves to the background.
|
||||
@@ -158,7 +179,7 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
try shoeGaze.loadRig(from: snapshot)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderiOS] rig restore after rebuild failed: \(error)")
|
||||
seedFallbackBoard()
|
||||
ShoeGazeBuilderiOSAppModel.seedFallbackBoard(into: shoeGaze)
|
||||
}
|
||||
|
||||
selectLiveInputAndPersist()
|
||||
@@ -180,7 +201,7 @@ final class ShoeGazeBuilderiOSAppModel {
|
||||
}
|
||||
|
||||
/// Seeds a single default board so the rig is never empty after a failed restore.
|
||||
private func seedFallbackBoard() {
|
||||
private static func seedFallbackBoard(into shoeGaze: ShoeGaze) {
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
board.label = "Board 1"
|
||||
|
||||
Reference in New Issue
Block a user