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:
2026-08-09 13:19:42 -07:00
parent 75b99a547b
commit 7dccf596f4
8 changed files with 348 additions and 18 deletions
@@ -35,6 +35,28 @@ extension PedalBoard {
}
}
extension ChainRouter {
/// Constructs a concrete pedal, applies `configure`, and appends it to board A of the router.
///
/// The concrete-type `configure` closure keeps every parameter compile-checked, exactly like
/// ``PedalBoard/append(_:configure:)``. Uses ``addToA(_:)`` so ``finalize()`` ordering stays correct.
@discardableResult
func appendToA<P: Pedal>(_ pedal: P, configure: (P) -> Void) throws -> P {
configure(pedal)
try addToA(pedal)
return pedal
}
/// Constructs a concrete pedal, applies `configure`, and appends it to board B of the router.
@discardableResult
func appendToB<P: Pedal>(_ pedal: P, configure: (P) -> Void) throws -> P {
configure(pedal)
try addToB(pedal)
return pedal
}
}
// MARK: - Factory rig catalog
/// The built-in starter rigs shipped with the app and seeded into an empty rig library on first
@@ -82,6 +104,7 @@ public enum FactoryRigLibrary {
psychVibeLead,
comfortablyNumbLead,
doomRiffWall,
garciaOBELSplit,
]
// MARK: Shoegaze walls
@@ -600,6 +623,69 @@ public enum FactoryRigLibrary {
}
}
// MARK: Two-board split
/// A two-board split — a full effects chain vs a clean direct path — selectable like an on-board
/// effects loop. Showcases the multi-board router.
static let garciaOBELSplit: FactoryRig = FactoryRig(
id: stableID("Garcia OBEL Split"),
name: "Garcia OBEL Clean/Effects Split",
blurb: "Two boards, one footswitch: an effects/lead chain (octave, envelope filter, "
+ "overdrive, phaser, delay) versus a clean direct path — switch between them like an "
+ "on-board effects loop. In the spirit of a certain improvising guitarist's late-'80s "
+ "rig. Flip the router to A for effects, B for clean.",
category: .classic,
sessionBuild: { session in
let router: ChainRouter = try session.makeChainRouter()
// Board A — the effects / lead chain (effects loop engaged).
try router.appendToA(BassOctaverPedal()) { p in
p.oct1 = 0.5
p.direct = 1.0
p.mode = 1.0
}
try router.appendToA(MutantPedal()) { p in
p.sensitivity = 2.5
p.resonance = 5.0
}
try router.appendToA(OverdrivePedal()) { p in
p.drive = 5.0
p.tone = 4200.0
}
try router.appendToA(PhaserPedal()) { p in
p.rate = 0.4
p.feedback = 0.4
}
try router.appendToA(DelayPedal()) { p in
p.time = 0.35
p.feedback = 1.8
}
try router.appendToA(CaliforniaAmpPedal()) { p in
p.gain = 5.0
p.bass = 0.55
p.mid = 0.6
p.treble = 0.6
}
// Board B — the clean / direct path (effects loop bypassed).
try router.appendToB(CompressorPedal()) { p in
p.inputGain = 2.0
p.threshold = -16.0
p.ratio = 3.0
}
try router.appendToB(CaliforniaAmpPedal()) { p in
p.gain = 3.5
p.bass = 0.5
p.mid = 0.55
p.treble = 0.6
}
// Default to the effects board; the router's A/B control switches paths.
router.mode = .a
try router.finalize()
}
)
// MARK: - Seeding
/// Builds every factory rig into a ``RigEntry`` snapshot suitable for the rig library.
@@ -620,12 +706,19 @@ public enum FactoryRigLibrary {
entries.reserveCapacity(all.count)
for rig: FactoryRig in all {
let session: ShoeGaze = try makeSession()
// Tear down on every exit from this iteration, including a throw from `build` /
// `finalizeBoard`, so a failing rig never leaks its throwaway engine's buses/nodes.
// Tear down on every exit from this iteration, including a throw from a builder, so a
// failing rig never leaks its throwaway engine's buses/nodes.
defer { session.teardown() }
let board: PedalBoard = try session.addBoard()
try rig.build(session, board)
try session.finalizeBoard(board)
switch rig.build {
case .singleBoard(let build):
let board: PedalBoard = try session.addBoard()
try build(session, board)
try session.finalizeBoard(board)
case .session(let build):
// The builder owns its own board/router lifecycle (addBoard/finalizeBoard,
// makeChainRouter/finalize).
try build(session)
}
entries.append(session.captureEntry(name: rig.name, id: rig.id))
}
return entries