Files
ShoeGaze/Sources/LyrebirdShoeGaze/Input/FeedPassThrough.swift
T
josh 9dfadb129d feat(preboard): shared pre-board chain feeding every board
Add a pre-board stage: one linear pedal chain that processes the input once,
before the board split, and feeds every board — for front-of-chain gates /
drive / EQ, and multi-board "voice spray" rigs (one source → N panned boards →
Blend).

Routing: a stable mono feed bus every board taps. `FeedPassThrough` copies the
input source — or, when a pre-chain exists, that chain's mono output — onto the
feed bus (`ensureFeed`/`buildFeed`/`tearDownFeed`). The pre-chain is modeled as
an unfinalized `PedalBoard` fed from the source; a stereo tail folds to mono
(board heads are mono). Empty pre-chain = passthrough, byte-for-byte
behavior-preserving. addBoard taps the feed bus; teardown releases it
remove-before-release.

State: additive `ShoeGazeState.preChain` (`decodeIfPresent` → nil for old rigs,
no format bump; `hasSameRigContent` includes it). `captureState` reads the LIVE
pre-pedals so knob tweaks are saved; `rebuildAllBoards` sets the pre-chain
before building boards.

Edit API: appendPrePedal / insertPrePedal / removePrePedal / movePrePedal —
each folds in live knob values, then a full ordering-safe rig rebuild
(`setPreBoardChain`, mirrors setInputSource; rolls back on failure). Undo: a
pre-chain topology change (compared by id sequence, so knob-only edits stay on
the surgical path) rebuilds from the snapshot, stopping/starting the engine.
`allPedals()` now includes the pre-chain so pre-pedal knob undo resolves.

UI: an inline pre-board strip above the boards — hidden to a "+ Pre" button when
empty; otherwise the pre-pedals (keyed by stable id) with a per-pedal remove and
a "feeds all boards" divider. Palette adds route to the pre-board via a flag
(reset on any dismissal). Add / remove go through the undo wrapper.

Known scope: a pre-board edit resets transient/looper state (full rebuild, like
input-switch — setup-time); chain-router branches read the input directly and
are not fed by the pre-board. Both documented.

Tests: PreBoardChainTests (feeds boards, closed pre-Volume silences every board,
remove restores direct feed, save/load incl. a knob tweak, prior pre-pedal's
knob survives adding another, old-rig decode) + a pre-board undo test. Full
suite 844 green; both demos build. External review + caveman sweep: one blocking
(live knob sync) fixed + regression-tested, all non-blocking addressed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-25 19:18:04 -08:00

45 lines
1.8 KiB
Swift

// FeedPassThrough.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
/// Internal synthesizer that copies one mono bus straight to another — the writer of the shared
/// **feed bus** that every board taps.
///
/// The feed bus sits between the input source and the boards: a `FeedPassThrough` copies either the
/// raw input source (when there is no pre-board chain) or the pre-board chain's mono output onto a
/// single stable feed bus, and every board's input tap reads that feed bus. Keeping the feed bus
/// stable means a pre-board edit only rebuilds the pre-chain + this one node, never the boards.
///
/// Unlike ``TestLoopTap`` / ``HardwareInputPassThrough`` it carries no input-mute gain: the input
/// mute lives on the per-board taps (downstream of the feed), so a tail-producing pedal in the
/// pre-board chain is unaffected by it.
///
/// - Note: Must be removed from the engine before the feed bus it writes is released.
final class FeedPassThrough: SynthesizerBase {
/// Index of the bus to read from — the input source bus, or the pre-board chain's mono output.
private let inputBusIndex: Int
/// Index of the shared feed bus to write to.
private let outputBusIndex: Int
/// Creates a pass-through that copies `inputBusIndex` to `outputBusIndex`.
///
/// - Parameters:
/// - inputBusIndex: Bus to read from (input source, or pre-board chain output).
/// - outputBusIndex: The shared feed bus to write to.
init(inputBusIndex: Int, outputBusIndex: Int) {
self.inputBusIndex = inputBusIndex
self.outputBusIndex = outputBusIndex
super.init()
}
override func build() {
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
}
}