feat(postboard): shared post-board chain after the board mix

Add a dedicated linear stereo post-board chain that processes the summed
board mix once, after the board split, before the hardware output — for
global reverb, a bus limiter, a final EQ, and the like.

Routing: when a post-chain exists, every BoardOutputMaster writes a shared
stereo mix bus (parameterized output bus indices) instead of hardware; the
post-chain (PostChain + PostChainOutput) reads that mix, runs its pedals in
order, and copies the tail to the hardware outputs. Always stereo-headed
(dual-mono for a mono rig) so mono pedals auto-stereoize per channel.

The chain's head node is inserted at .tail(of: mainGroup), so it evaluates
after every board master regardless of board add order — no re-order on
board add, and no board dropped from the mix. buildPostChain tracks the
chain before wiring it so a mid-build throw stays reclaimable by teardown.

State: additive ShoeGazeState.postChain (nil-when-empty, decodeIfPresent,
byte-identical old-rig round-trip). Edit API (append/insert/remove/move)
mirrors the pre-board chain: capture-from-live, stop/teardown/rebuild. Undo
treats a post-topology change as a full rebuild via id-sequence compare.
UI: a hide-when-empty post-board strip below the boards, symmetric to the
pre-board strip, with palette routing and per-pedal remove through undo.

Bumps the iOS demo's Lyrebird pin to 2.3.0 (onEditingEnded).

Tests: PostBoardChainTests (render, closed-volume silences output,
post-chain-after-every-master ordering, board-add ordering, insert/move/
remove, save/load round-trip with knob, old-rig decode) + post-pedal undo.
855 tests pass. Reviewed (RT-safety + line sweep); the ordering bug both
reviewers caught is fixed at the root and covered by a deterministic test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 00:22:39 -08:00
parent 10a6e122bf
commit 52c676605f
13 changed files with 709 additions and 23 deletions
@@ -41,7 +41,9 @@ extension ShoeGaze {
routers: routerStates.isEmpty ? nil : routerStates,
// Captured from the LIVE pre-pedals (so knob tweaks are saved); `nil` rather than `[]`
// when empty, so a rig without a pre-board chain stays byte-identical to the old format.
preChain: { let s: [PedalState] = capturePreBoardStates(); return s.isEmpty ? nil : s }()
preChain: { let s: [PedalState] = capturePreBoardStates(); return s.isEmpty ? nil : s }(),
// Likewise for the post-board chain, captured from the live post-pedals.
postChain: { let s: [PedalState] = capturePostBoardStates(); return s.isEmpty ? nil : s }()
)
}
@@ -181,9 +183,11 @@ extension ShoeGaze {
/// - Throws: `BusAllocatorError`, `EngineAddError`, or `ShoeGazeError` from board construction.
func rebuildAllBoards(from snapshot: ShoeGazeState) throws {
do {
// Set the pre-board chain before building any board: the first board's input tap wires
// through the feed bus, which `ensureFeed()` builds from `preBoardStates`.
// Set the pre- and post-board chains before building any board: a board's input tap wires
// through the feed bus (`ensureFeed()` from `preBoardStates`), and its master targets the
// mix bus (`ensurePostMix()` from `postBoardStates`), both decided per board.
preBoardStates = snapshot.preChain ?? []
postBoardStates = snapshot.postChain ?? []
for boardState: BoardState in snapshot.boards {
let board: PedalBoard = try addBoard()
board.id = boardState.id
@@ -199,6 +203,9 @@ extension ShoeGaze {
if boards.isEmpty && !preBoardStates.isEmpty {
_ = try ensureFeed()
}
// Build the post-board chain after every board master exists (it reads the mix those
// masters write and must evaluate after them).
try buildPostChain()
} catch {
// Leave no partial rig behind: tear down whatever was built, then rethrow.
teardown()