Files
ShoeGaze/Sources/LyrebirdShoeGaze/PostChainOutput.swift
T
josh 52c676605f 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>
2026-11-26 00:22:39 -08:00

44 lines
1.7 KiB
Swift

// PostChainOutput.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
/// Internal synthesizer that copies the post-board chain's stereo tail onto the hardware output
/// buses — the final node of the ``PostChain``.
///
/// The board masters write the shared mix bus, the post-chain's pedals process it, and this node
/// copies the processed tail (left / right) to the hardware outputs. It carries no gain: the
/// rig-wide volume / mute live on the board masters, upstream of the post-chain.
///
/// - Note: Must be removed from the engine before the tail / hardware buses it reads are released.
final class PostChainOutput: SynthesizerBase {
private let leftInputBus: Int
private let rightInputBus: Int
private let leftOutputBus: Int
private let rightOutputBus: Int
/// Creates a stereo copy from the chain tail to the hardware outputs.
///
/// - Parameters:
/// - leftInputBus: Chain-tail left bus to read.
/// - rightInputBus: Chain-tail right bus to read.
/// - leftOutputBus: Hardware output for the left channel (default `0`).
/// - rightOutputBus: Hardware output for the right channel (default `1`).
init(leftInputBus: Int, rightInputBus: Int, leftOutputBus: Int = 0, rightOutputBus: Int = 1) {
self.leftInputBus = leftInputBus
self.rightInputBus = rightInputBus
self.leftOutputBus = leftOutputBus
self.rightOutputBus = rightOutputBus
super.init()
}
override func build() {
output(bus: leftOutputBus, source: input(bus: leftInputBus))
output(bus: rightOutputBus, source: input(bus: rightInputBus))
}
}