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
@@ -67,6 +67,11 @@ public struct ShoeGazeState: Codable, Equatable {
/// decoded with `decodeIfPresent`, so older rigs decode cleanly to `nil` without a format bump.
public let preChain: [PedalState]?
/// The rig's post-board chain — pedals that process the summed board mix, after the split, before
/// the hardware output (global reverb, bus limiter, …) — or `nil` for a rig saved before the
/// post-board stage existed. Additive: decoded with `decodeIfPresent`.
public let postChain: [PedalState]?
/// Creates a rig state snapshot.
///
/// - Parameters:
@@ -89,7 +94,8 @@ public struct ShoeGazeState: Codable, Equatable {
numInputChannels: Int? = nil,
numOutputChannels: Int? = nil,
routers: [ChainRouterState]? = nil,
preChain: [PedalState]? = nil
preChain: [PedalState]? = nil,
postChain: [PedalState]? = nil
) {
self.version = version
self.boards = boards
@@ -101,6 +107,7 @@ public struct ShoeGazeState: Codable, Equatable {
self.numOutputChannels = numOutputChannels
self.routers = routers
self.preChain = preChain
self.postChain = postChain
}
private enum CodingKeys: String, CodingKey {
@@ -114,6 +121,7 @@ public struct ShoeGazeState: Codable, Equatable {
case numOutputChannels
case routers
case preChain
case postChain
}
/// Decodes a rig snapshot, tolerating an absent, malformed, OR legacy-format `midiMap`.
@@ -148,6 +156,7 @@ public struct ShoeGazeState: Codable, Equatable {
self.numOutputChannels = try container.decodeIfPresent(Int.self, forKey: .numOutputChannels)
self.routers = try container.decodeIfPresent([ChainRouterState].self, forKey: .routers)
self.preChain = try container.decodeIfPresent([PedalState].self, forKey: .preChain)
self.postChain = try container.decodeIfPresent([PedalState].self, forKey: .postChain)
}
/// Whether two snapshots describe the same **rig** — its boards, routers, MIDI map, and tempo —
@@ -165,6 +174,7 @@ public struct ShoeGazeState: Codable, Equatable {
&& bpm == other.bpm
&& tempoEnabled == other.tempoEnabled
&& preChain == other.preChain
&& postChain == other.postChain
}
/// Returns a copy of this snapshot with its `preChain` replaced. Used by the pre-board edit path
@@ -173,7 +183,16 @@ public struct ShoeGazeState: Codable, Equatable {
ShoeGazeState(
version: version, boards: boards, midiMap: midiMap, bpm: bpm, tempoEnabled: tempoEnabled,
inputSource: inputSource, numInputChannels: numInputChannels,
numOutputChannels: numOutputChannels, routers: routers, preChain: preChain
numOutputChannels: numOutputChannels, routers: routers, preChain: preChain, postChain: postChain
)
}
/// Returns a copy with its `postChain` replaced. Post-board edit counterpart of ``withPreChain(_:)``.
public func withPostChain(_ postChain: [PedalState]?) -> ShoeGazeState {
ShoeGazeState(
version: version, boards: boards, midiMap: midiMap, bpm: bpm, tempoEnabled: tempoEnabled,
inputSource: inputSource, numInputChannels: numInputChannels,
numOutputChannels: numOutputChannels, routers: routers, preChain: preChain, postChain: postChain
)
}
}