7dccf596f4
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>
60 lines
2.2 KiB
Swift
60 lines
2.2 KiB
Swift
// ChainRouterState.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/// Serialisable snapshot of one ``ChainRouter`` — its two linear board chains and its blend state.
|
|
///
|
|
/// A router splits one input to two independent boards and blends their outputs. Its branches are
|
|
/// built linearly (via ``ChainRouter/addToA(_:)`` / ``ChainRouter/addToB(_:)``), so each is captured
|
|
/// as a flat list of ``PedalState``. The splitter's two branch-enable levels capture the A / B / both
|
|
/// selection (and any continuous blend between them); the merger's two levels capture the output mix.
|
|
///
|
|
/// Persisted as part of ``ShoeGazeState/routers`` so a routed multi-board rig survives save / load.
|
|
public struct ChainRouterState: Codable, Equatable {
|
|
|
|
/// Pedals on board A (the first branch), in chain order.
|
|
public let boardA: [PedalState]
|
|
|
|
/// Pedals on board B (the second branch), in chain order.
|
|
public let boardB: [PedalState]
|
|
|
|
/// Splitter branch-A enable level in `[0, 1]`. `1` = A audible, `0` = A muted.
|
|
public let branchA: Double
|
|
|
|
/// Splitter branch-B enable level in `[0, 1]`. `1` = B audible, `0` = B muted.
|
|
public let branchB: Double
|
|
|
|
/// Merger board-A output level in `[0, 1]`.
|
|
public let mergerLevelA: Double
|
|
|
|
/// Merger board-B output level in `[0, 1]`.
|
|
public let mergerLevelB: Double
|
|
|
|
/// Creates a router snapshot.
|
|
///
|
|
/// - Parameters:
|
|
/// - boardA: Board A's pedals in chain order.
|
|
/// - boardB: Board B's pedals in chain order.
|
|
/// - branchA: Splitter branch-A enable level `[0, 1]`.
|
|
/// - branchB: Splitter branch-B enable level `[0, 1]`.
|
|
/// - mergerLevelA: Merger board-A output level `[0, 1]`.
|
|
/// - mergerLevelB: Merger board-B output level `[0, 1]`.
|
|
public init(
|
|
boardA: [PedalState],
|
|
boardB: [PedalState],
|
|
branchA: Double,
|
|
branchB: Double,
|
|
mergerLevelA: Double,
|
|
mergerLevelB: Double
|
|
) {
|
|
self.boardA = boardA
|
|
self.boardB = boardB
|
|
self.branchA = branchA
|
|
self.branchB = branchB
|
|
self.mergerLevelA = mergerLevelA
|
|
self.mergerLevelB = mergerLevelB
|
|
}
|
|
}
|