feat(rigs): persist chain routers + add Garcia two-board split rig
Add ChainRouter persistence so routed multi-board rigs survive save/load —
previously captureState/loadRig only handled plain boards, so any A/B router
rig was silently lost on save (a latent gap this fixes for user rigs too).
- New ChainRouterState (Codable): each router's two linear branches as
[PedalState] plus splitter branch levels and merger output levels.
- ShoeGazeState gains an additive `routers` field decoded with
decodeIfPresent (nil for old rigs) — no format-version bump; routerless
rigs stay byte-identical (nil, not []).
- captureState snapshots routers; rebuildAllBoards reconstructs each via
makeChainRouter/addTo{A,B}/finalize and restores the blend.
FactoryRig gains a session-scoped builder variant (FactoryRigBuild enum) so
a rig can create its own boards/routers; makeEntries branches on it.
Ships the Garcia OBEL Clean/Effects Split: an effects/lead board (octave,
envelope filter, overdrive, phaser, delay, amp) vs a clean direct board,
selectable via the router — showcasing the multi-board capability.
Tests: full router capture -> JSON -> load round-trip with structure and
branch-level assertions plus a render check, backward-compat (no routers
key when routerless), and the Garcia rig via the factory load+render suite.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -40,13 +40,14 @@ public struct FactoryRig: Identifiable, Sendable {
|
||||
/// Sonic family this rig belongs to, for grouping in a picker. Presentational only.
|
||||
public let category: FactoryRigCategory
|
||||
|
||||
/// Builds the rig's pedal chain into `board`, an empty board freshly returned by
|
||||
/// `session.addBoard()`. Set pedal parameters via the typed `configure` closures of
|
||||
/// ``FactoryRigLibrary``'s helpers. Do **not** call `finalizeBoard` / `captureEntry` here — the
|
||||
/// seeding driver owns that lifecycle.
|
||||
public let build: @MainActor (_ session: ShoeGaze, _ board: PedalBoard) throws -> Void
|
||||
/// How this rig builds its graph at seed time.
|
||||
public let build: FactoryRigBuild
|
||||
|
||||
/// Creates a factory rig descriptor.
|
||||
/// Creates a single-board factory rig.
|
||||
///
|
||||
/// The `build` closure receives a fresh, empty ``PedalBoard`` (already returned by
|
||||
/// `session.addBoard()`) and appends pedals to it. Do **not** call `finalizeBoard` /
|
||||
/// `captureEntry` here — the seeding driver owns that lifecycle.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - id: Stable identifier (a fixed literal per rig — see ``id``).
|
||||
@@ -65,6 +66,46 @@ public struct FactoryRig: Identifiable, Sendable {
|
||||
self.name = name
|
||||
self.blurb = blurb
|
||||
self.category = category
|
||||
self.build = build
|
||||
self.build = .singleBoard(build)
|
||||
}
|
||||
|
||||
/// Creates a session-scoped factory rig that builds its own boards and/or routers.
|
||||
///
|
||||
/// Use this for rigs the single-board form can't express — e.g. a two-board signal split via
|
||||
/// ``ShoeGaze/makeChainRouter()``. The `sessionBuild` closure gets the whole session and owns the
|
||||
/// full lifecycle for what it creates: it must call `addBoard`/`finalizeBoard` (for plain boards)
|
||||
/// and/or `makeChainRouter`/`addToA`/`addToB`/`finalize` (for routers) itself. Do **not** call
|
||||
/// `captureEntry` here — the seeding driver owns that.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - id: Stable identifier (a fixed literal per rig — see ``id``).
|
||||
/// - name: Rig name (picker title + saved entry name).
|
||||
/// - blurb: User-facing description of the sound.
|
||||
/// - category: Sonic family for picker grouping.
|
||||
/// - sessionBuild: Graph-building closure run against the session at seed time.
|
||||
public init(
|
||||
id: UUID,
|
||||
name: String,
|
||||
blurb: String,
|
||||
category: FactoryRigCategory,
|
||||
sessionBuild: @escaping @MainActor (_ session: ShoeGaze) throws -> Void
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.blurb = blurb
|
||||
self.category = category
|
||||
self.build = .session(sessionBuild)
|
||||
}
|
||||
}
|
||||
|
||||
/// How a ``FactoryRig`` builds its graph at seed time.
|
||||
public enum FactoryRigBuild: Sendable {
|
||||
|
||||
/// Appends pedals to a single pre-made, empty board; the seeding driver calls `addBoard` before
|
||||
/// and `finalizeBoard` after.
|
||||
case singleBoard(@MainActor (_ session: ShoeGaze, _ board: PedalBoard) throws -> Void)
|
||||
|
||||
/// Builds the whole graph against the session (boards and/or routers), owning its own
|
||||
/// `addBoard`/`finalizeBoard` and `makeChainRouter`/`finalize` lifecycle.
|
||||
case session(@MainActor (_ session: ShoeGaze) throws -> Void)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user