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
@@ -57,6 +57,11 @@ public struct ShoeGazeState: Codable, Equatable {
/// persistence. Reapplied on load under the same conditions as ``numInputChannels``.
public let numOutputChannels: Int?
/// The rig's chain routers (two-board split/blend units), or `nil` for a rig saved before router
/// persistence existed. Additive: decoded with `decodeIfPresent`, so older rigs — which never had
/// routers — decode cleanly to `nil` without a format-version bump.
public let routers: [ChainRouterState]?
/// Creates a rig state snapshot.
///
/// - Parameters:
@@ -68,6 +73,7 @@ public struct ShoeGazeState: Codable, Equatable {
/// - inputSource: The rig's input selection, or `nil` to not persist one. Defaults to `nil`.
/// - numInputChannels: The engine input-channel count, or `nil`. Defaults to `nil`.
/// - numOutputChannels: The engine output-channel count, or `nil`. Defaults to `nil`.
/// - routers: The rig's chain routers, or `nil` when there are none. Defaults to `nil`.
public init(
version: Int = presetFormatVersion,
boards: [BoardState],
@@ -76,7 +82,8 @@ public struct ShoeGazeState: Codable, Equatable {
tempoEnabled: Bool? = nil,
inputSource: InputSource? = nil,
numInputChannels: Int? = nil,
numOutputChannels: Int? = nil
numOutputChannels: Int? = nil,
routers: [ChainRouterState]? = nil
) {
self.version = version
self.boards = boards
@@ -86,6 +93,7 @@ public struct ShoeGazeState: Codable, Equatable {
self.inputSource = inputSource
self.numInputChannels = numInputChannels
self.numOutputChannels = numOutputChannels
self.routers = routers
}
private enum CodingKeys: String, CodingKey {
@@ -97,6 +105,7 @@ public struct ShoeGazeState: Codable, Equatable {
case inputSource
case numInputChannels
case numOutputChannels
case routers
}
/// Decodes a rig snapshot, tolerating an absent, malformed, OR legacy-format `midiMap`.
@@ -129,5 +138,6 @@ public struct ShoeGazeState: Codable, Equatable {
self.inputSource = try container.decodeIfPresent(InputSource.self, forKey: .inputSource)
self.numInputChannels = try container.decodeIfPresent(Int.self, forKey: .numInputChannels)
self.numOutputChannels = try container.decodeIfPresent(Int.self, forKey: .numOutputChannels)
self.routers = try container.decodeIfPresent([ChainRouterState].self, forKey: .routers)
}
}