feat(rigs): ship built-in factory starter rigs
Add a factory rig library: 8 curated starter pedalboard rigs seeded into an empty rig library on first launch. Rigs are compile-checked builders (construct concrete pedals, set typed @UIParam values, board.add) rather than hand-written JSON, so a renamed pedal control is a build error, not a silently corrupted preset. Seeding builds each rig in a throwaway offline (never-started) engine, captures a RigEntry with a stable per-rig UUID (idempotent re-seed), and saves to the store. Bootstrap rolls back this run's saves if any store.save fails, so a partial library can't freeze future seeding (gated on isEmpty). Rigs are named/described by sound, not trademarked products or artists; a test guards against brand names leaking into names/blurbs. Full ship-path test loads and renders every rig to non-silent output. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -39,15 +39,65 @@ public enum RigLibraryBootstrap {
|
||||
|
||||
// Seed only after the (possibly iCloud) library has loaded: an empty library here means a
|
||||
// genuine first run, not a not-yet-synced one.
|
||||
guard store.entries.isEmpty, !shoeGaze.boards.isEmpty else { return }
|
||||
guard store.entries.isEmpty else { return }
|
||||
|
||||
// First run: populate the library with the shipped starter rigs. These are built in
|
||||
// throwaway offline sessions, so they are independent of the current working graph. The
|
||||
// working session is intentionally left as-is (no `currentRigID`) — the user picks a starter
|
||||
// rig from the sidebar to load it, rather than the highlight pointing at a rig the working
|
||||
// graph has not actually loaded.
|
||||
let entries: [RigEntry]
|
||||
do {
|
||||
entries = try FactoryRigLibrary.makeEntries()
|
||||
} catch {
|
||||
// Building the shipped rigs is deterministic and should never fail at runtime; if it
|
||||
// somehow does, fall back to seeding the working rig so the library is not left empty.
|
||||
print("[RigLibraryBootstrap] building factory rigs failed: \(error)")
|
||||
seedWorkingRig(store, seedFrom: shoeGaze, seedName: seedName)
|
||||
return
|
||||
}
|
||||
|
||||
// Save sequentially, rolling back on failure. Seeding is gated on `store.entries.isEmpty`,
|
||||
// so a partially-saved library would be frozen forever (never retried, never completed). If
|
||||
// any save fails, delete the entries saved this run so the library returns to empty and a
|
||||
// later launch retries the full seed. (This is best-effort, not truly atomic: if a rollback
|
||||
// `delete` itself fails, a partial set can still be left behind and frozen — the residual
|
||||
// hole a non-transactional store cannot fully close.)
|
||||
var savedThisRun: [RigEntry] = []
|
||||
do {
|
||||
for entry: RigEntry in entries {
|
||||
try store.save(entry)
|
||||
savedThisRun.append(entry)
|
||||
}
|
||||
} catch {
|
||||
print("[RigLibraryBootstrap] seeding factory rigs failed after "
|
||||
+ "\(savedThisRun.count)/\(entries.count); rolling back: \(error)")
|
||||
for entry: RigEntry in savedThisRun {
|
||||
do {
|
||||
try store.delete(entry)
|
||||
} catch {
|
||||
print("[RigLibraryBootstrap] rollback of '\(entry.name)' failed: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Seeds the working session's current rig as a single named library entry.
|
||||
///
|
||||
/// Last-resort fallback used only when the factory rigs could not be built; keeps the library
|
||||
/// from being left empty on first run.
|
||||
private static func seedWorkingRig(
|
||||
_ store: RigLibraryStore,
|
||||
seedFrom shoeGaze: ShoeGaze,
|
||||
seedName: String
|
||||
) {
|
||||
guard !shoeGaze.boards.isEmpty else { return }
|
||||
let entry: RigEntry = shoeGaze.captureEntry(name: seedName)
|
||||
do {
|
||||
try store.save(entry)
|
||||
// The seeded entry was captured from the working graph, so it is the session's source
|
||||
// rig — record it so the sidebar highlights it and the autosave envelope carries it.
|
||||
shoeGaze.currentRigID = entry.id
|
||||
} catch {
|
||||
print("[RigLibraryBootstrap] seeding library failed: \(error)")
|
||||
print("[RigLibraryBootstrap] fallback seeding failed: \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user