f89229282f
Introduce chain width propagation (mono=1 / stereo=2, capped at 2), represented as a pair of mono buses to reuse existing infrastructure. - Pedal: width-parameterized build() with channelKind (mono / widener / stereoNative); effect() runs per channel for auto-stereoize, shared knobs. - PedalBoard: width tracking, add() dispatch, mergeToMono(), splitStereo()/ collectStereo() with four route modes (stereo / leftOnly / rightOnly / bypass), centered solo, click-free lagged gains. - BoardOutputMaster: width-aware (Pan2 mono, direct L/R stereo). - New routing nodes: StereoSplitter, StereoRouteCollector, StereoSplitSection. - Reference pedals: OctaveUpSplitterPedal (widener), PingPongDelayPedal (stereo-native). - 12 stereo-routing tests; full suite 108/108. Design: docs/stereo-routing-design.md Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
101 lines
3.5 KiB
Swift
101 lines
3.5 KiB
Swift
// StereoSplitSection.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// A stereo split region inside a ``PedalBoard``.
|
|
///
|
|
/// Created by ``PedalBoard/splitStereo()``. Holds the ``StereoSplitter`` that fans the mono
|
|
/// tail out, the two independently authored branch sub-chains that *become* the stereo
|
|
/// channels, and (after ``PedalBoard/collectStereo(_:)``) the ``StereoRouteCollector`` that
|
|
/// resolves the output ``route``.
|
|
///
|
|
/// Unlike a ``ParallelSection`` (whose branches are summed back to mono by a ``Merger``), the
|
|
/// two branches here map directly to the left and right output channels — the board's width
|
|
/// becomes 2 after `collectStereo(_:)`.
|
|
///
|
|
/// ## Typical usage
|
|
///
|
|
/// ```swift
|
|
/// let s = try board.splitStereo()
|
|
/// try s.left.add(DelayPedal())
|
|
/// try s.right.add(DelayPedal())
|
|
/// try board.collectStereo(s)
|
|
/// s.route = .leftOnly // centered solo of the left chain
|
|
/// ```
|
|
@MainActor
|
|
public final class StereoSplitSection {
|
|
|
|
// MARK: - Nodes and chains
|
|
|
|
/// The splitter that fans the pre-split mono signal into both branches plus the dry tap.
|
|
public let splitter: StereoSplitter
|
|
|
|
/// The left branch sub-chain. Its tail becomes the left output channel.
|
|
public let left: BranchChain
|
|
|
|
/// The right branch sub-chain. Its tail becomes the right output channel.
|
|
public let right: BranchChain
|
|
|
|
/// Shared tail pointer updated by both branch chains; used by ``PedalBoard/collectStereo(_:)``
|
|
/// to place the collector after the last pedal added across either branch.
|
|
internal let sharedTail: SharedTail
|
|
|
|
/// The clean pre-split tap bus carried to the collector for the `bypass` route.
|
|
internal let dryTapBus: AudioBus
|
|
|
|
/// The route collector, set by ``PedalBoard/collectStereo(_:)``. `nil` until then.
|
|
internal var collector: StereoRouteCollector?
|
|
|
|
/// Route requested before the collector exists; applied when `collectStereo(_:)` wires it.
|
|
private var pendingRoute: StereoRoute = .stereo
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a stereo split section. Called internally by ``PedalBoard/splitStereo()``.
|
|
///
|
|
/// - Parameters:
|
|
/// - splitter: The ``StereoSplitter`` feeding the two branches and the dry tap.
|
|
/// - left: The left branch sub-chain.
|
|
/// - right: The right branch sub-chain.
|
|
/// - sharedTail: The shared tail tracking pointer used by both branch chains.
|
|
/// - dryTapBus: The clean pre-split tap bus.
|
|
init(
|
|
splitter: StereoSplitter,
|
|
left: BranchChain,
|
|
right: BranchChain,
|
|
sharedTail: SharedTail,
|
|
dryTapBus: AudioBus
|
|
) {
|
|
self.splitter = splitter
|
|
self.left = left
|
|
self.right = right
|
|
self.sharedTail = sharedTail
|
|
self.dryTapBus = dryTapBus
|
|
}
|
|
|
|
// MARK: - Route
|
|
|
|
/// The output routing mode for this region. Settable from code or UI at any time; the
|
|
/// transition is click-free. Before ``PedalBoard/collectStereo(_:)`` wires the collector
|
|
/// the value is held and applied on wiring.
|
|
public var route: StereoRoute {
|
|
get { collector?.route ?? pendingRoute }
|
|
set {
|
|
pendingRoute = newValue
|
|
collector?.route = newValue
|
|
}
|
|
}
|
|
|
|
/// Applies the pending route to the freshly wired collector. Called by
|
|
/// ``PedalBoard/collectStereo(_:)``.
|
|
internal func bind(collector: StereoRouteCollector) {
|
|
self.collector = collector
|
|
collector.route = pendingRoute
|
|
}
|
|
}
|