Add mono→stereo routing to PedalBoard
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>
This commit is contained in:
@@ -64,12 +64,32 @@ open class Pedal: SynthesizerBase {
|
||||
/// Human-readable name for the pedal (e.g. "Overdrive", "Delay").
|
||||
public let displayName: String
|
||||
|
||||
/// Index of the audio bus from which this pedal reads its dry input.
|
||||
/// Index of the audio bus from which this pedal reads its dry input (channel 0 /
|
||||
/// left / mono).
|
||||
public internal(set) var inputBus: Int
|
||||
|
||||
/// Index of the audio bus to which this pedal writes its output.
|
||||
/// Index of the audio bus to which this pedal writes its output (channel 0 /
|
||||
/// left / mono).
|
||||
public internal(set) var outputBus: Int
|
||||
|
||||
/// Right-channel input bus index, or `nil` for a mono input. When the board places
|
||||
/// this pedal in a stereo (width-2) region it sets this to the right tail bus. A
|
||||
/// `stereoNative` pedal entering a mono region leaves this `nil` and broadcasts the
|
||||
/// mono input to both channels.
|
||||
public internal(set) var inputBusRight: Int?
|
||||
|
||||
/// Right-channel output bus index, or `nil` for a mono output. Non-nil exactly when
|
||||
/// the pedal is part of a stereo region; `build()` emits a second channel only when
|
||||
/// this is set.
|
||||
public internal(set) var outputBusRight: Int?
|
||||
|
||||
/// Declares this pedal's channel topology. Defaults to ``PedalChannelKind/mono``.
|
||||
/// Override in a widener or stereo-native subclass.
|
||||
open var channelKind: PedalChannelKind { .mono }
|
||||
|
||||
/// `true` when the board has placed this pedal in a stereo (width-2) region.
|
||||
public var isStereo: Bool { outputBusRight != nil }
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
/// Lag time constant in seconds (60 dB convergence) for the bypass crossfade.
|
||||
@@ -150,13 +170,53 @@ open class Pedal: SynthesizerBase {
|
||||
dry
|
||||
}
|
||||
|
||||
/// Returns the two distinct wet outputs for a ``PedalChannelKind/widener`` pedal.
|
||||
///
|
||||
/// Called once with the mono dry input; the returned pair becomes the left and right
|
||||
/// wet signals of the now-stereo region. The default applies `effect(_:)` to both,
|
||||
/// which is rarely useful — widener subclasses override this to produce genuinely
|
||||
/// different channels (e.g. dry left, octave-up right).
|
||||
///
|
||||
/// - Parameter dry: The dry mono signal read from `inputBus`.
|
||||
/// - Returns: The left and right wet signals.
|
||||
open func wideEffect(_ dry: any ValidGeneratorInput)
|
||||
-> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
|
||||
(effect(dry), effect(dry))
|
||||
}
|
||||
|
||||
/// Returns the coupled stereo wet outputs for a ``PedalChannelKind/stereoNative`` pedal.
|
||||
///
|
||||
/// Called with both dry channels; the returned pair becomes the wet left and right
|
||||
/// signals. The default applies `effect(_:)` per channel independently — stereo-native
|
||||
/// subclasses override this to introduce cross-channel coupling (e.g. ping-pong feedback).
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - left: The left dry channel.
|
||||
/// - right: The right dry channel (equals `left` when the pedal entered a mono region).
|
||||
/// - Returns: The left and right wet signals.
|
||||
open func stereoEffect(
|
||||
left: any ValidGeneratorInput,
|
||||
right: any ValidGeneratorInput
|
||||
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
|
||||
(effect(left), effect(right))
|
||||
}
|
||||
|
||||
// MARK: - Build
|
||||
|
||||
/// Builds the signal graph: dry → effect → wet/dry blend → bypass switch → output.
|
||||
public override func build() {
|
||||
let dry: In.Audio = input(bus: inputBus)
|
||||
let wet: any ValidGeneratorInput = effect(dry)
|
||||
|
||||
/// Builds the signal graph for one channel: dry → wet/dry blend → bypass switch → × level.
|
||||
///
|
||||
/// Returns the final post-`level` source for the channel. The `mix`, `bypass`, and `level`
|
||||
/// `@UIParam` nodes are shared across channels; each channel gets its own `Lag.Control`
|
||||
/// for the bypass crossfade so smoothing is per-channel state driven by the same target.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - dry: The dry signal for this channel.
|
||||
/// - wet: The processed signal for this channel.
|
||||
/// - Returns: The channel's output source (post mix/bypass/level).
|
||||
private func applyChain(
|
||||
dry: any ValidGeneratorInput,
|
||||
wet: any ValidGeneratorInput
|
||||
) -> any ValidGeneratorInput {
|
||||
// Map mix [0, 1] → pan [-1, +1] for CrossFade (−1 = full inA/dry, +1 = full inB/wet).
|
||||
let mixPan: any ValidGeneratorInput = ($mix * bipolarSpan) - bipolarOffset
|
||||
|
||||
@@ -183,6 +243,40 @@ open class Pedal: SynthesizerBase {
|
||||
pan: bypassPan
|
||||
)
|
||||
|
||||
output(bus: outputBus, source: switched * $level)
|
||||
return switched * $level
|
||||
}
|
||||
|
||||
/// Builds the pedal's signal graph, dispatching on ``channelKind`` and emitting a second
|
||||
/// channel only when `outputBusRight` is set (a stereo region).
|
||||
public override func build() {
|
||||
switch channelKind {
|
||||
case .mono:
|
||||
// One independent `effect(_:)` graph per output channel; shared knobs.
|
||||
let dryLeft: In.Audio = input(bus: inputBus)
|
||||
output(bus: outputBus, source: applyChain(dry: dryLeft, wet: effect(dryLeft)))
|
||||
if let rightOut: Int = outputBusRight {
|
||||
// Broadcast the mono input to the right channel when no right input exists.
|
||||
let dryRight: In.Audio = input(bus: inputBusRight ?? inputBus)
|
||||
output(bus: rightOut, source: applyChain(dry: dryRight, wet: effect(dryRight)))
|
||||
}
|
||||
|
||||
case .widener:
|
||||
let dry: In.Audio = input(bus: inputBus)
|
||||
let wet: (left: any ValidGeneratorInput, right: any ValidGeneratorInput) = wideEffect(dry)
|
||||
output(bus: outputBus, source: applyChain(dry: dry, wet: wet.left))
|
||||
if let rightOut: Int = outputBusRight {
|
||||
output(bus: rightOut, source: applyChain(dry: dry, wet: wet.right))
|
||||
}
|
||||
|
||||
case .stereoNative:
|
||||
let dryLeft: In.Audio = input(bus: inputBus)
|
||||
let dryRight: In.Audio = input(bus: inputBusRight ?? inputBus)
|
||||
let wet: (left: any ValidGeneratorInput, right: any ValidGeneratorInput) =
|
||||
stereoEffect(left: dryLeft, right: dryRight)
|
||||
output(bus: outputBus, source: applyChain(dry: dryLeft, wet: wet.left))
|
||||
if let rightOut: Int = outputBusRight {
|
||||
output(bus: rightOut, source: applyChain(dry: dryRight, wet: wet.right))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user