Add Stereo Unzip: process a stereo signal's L/R independently
A stereo-output pedal (Ping-Pong, Octave Splitter) now shows a "Stereo flow / Split L/R" toggle on its card: - Stereo flow (default): unchanged broadcast behavior — following pedals process both channels as one stereo flow. - Split L/R: inserts a Stereo Unzip region right after the pedal, routing the L channel into one lane and R into the other for independent processing, then recombining to stereo with the same route/solo/bypass control as the stereo split. Engine/core: - StereoUnzipSplitter: 2-in -> 3-out node (L->lane L, R->lane R, and a centered 0.5*L+0.5*R dry tap for the bypass route). - PedalBoard.unzipStereo() mirrors splitStereo() but reads both tails and requires width 2; reuses collectStereo / StereoSplitSection / StereoRouteCollector. New stereoUnzipSections (cleared on teardown). - BoardSegment/.stereoUnzip + StereoUnzipState round-trip via preset capture/rebuild/applyState. - ShoeGaze.insertStereoUnzip(afterSegment:)/isStereoUnzip(afterSegment:) drive the toggle; invalid insert (mono tail) throws cannotUnzipMonoChain and the atomic rebuild keeps the board intact. - StereoSplitSection.splitter relaxed to `any Synthesizer` (stored only) so it can hold either splitter type. UI: per-pedal toggle + STEREO UNZIP region rendering in BoardFlowView. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,10 @@ public final class PedalBoard {
|
||||
/// All stereo split sections created via `splitStereo()` (for inspection / UI binding).
|
||||
public private(set) var stereoSplitSections: [StereoSplitSection] = []
|
||||
|
||||
/// All stereo unzip sections created via ``unzipStereo()``. Same `StereoSplitSection` type as
|
||||
/// ``stereoSplitSections``; tracked separately so a UI can distinguish the two region kinds.
|
||||
public private(set) var stereoUnzipSections: [StereoSplitSection] = []
|
||||
|
||||
/// The node that writes the head bus (e.g. a `TestLoopSource` or input pass-through).
|
||||
/// Set by `ShoeGaze` after adding the input source. When non-nil, the first `add(_:)`
|
||||
/// call chains the first pedal after this node automatically (no `after:` arg needed).
|
||||
@@ -367,6 +371,78 @@ public final class PedalBoard {
|
||||
return section
|
||||
}
|
||||
|
||||
/// Splits the current **stereo** tail into two independently authored branch chains — left
|
||||
/// channel into one, right channel into the other — so the channels can be processed
|
||||
/// separately, then recombined to stereo by ``collectStereo(_:)``.
|
||||
///
|
||||
/// The stereo counterpart of ``splitStereo()``: it requires a width-2 tail and uses a
|
||||
/// ``StereoUnzipSplitter`` (which reads both channels) instead of a mono-duplicating
|
||||
/// ``StereoSplitter``. Everything downstream (branch chains, route collector, route control)
|
||||
/// is identical, so it returns the same ``StereoSplitSection`` type.
|
||||
///
|
||||
/// Route semantics for the reused ``StereoRouteCollector`` differ from a mono split, because
|
||||
/// each lane here carries one *original* channel rather than a duplicated mono signal:
|
||||
/// `.stereo` = L lane → left, R lane → right; `.leftOnly` / `.rightOnly` = center the chosen
|
||||
/// lane (so you hear only that original channel, processed, in both speakers); `.bypass` =
|
||||
/// the centered mono sum (`0.5·L + 0.5·R`) of the pre-unzip signal in both speakers.
|
||||
///
|
||||
/// - Returns: A ``StereoSplitSection`` with two empty branch chains; call `collectStereo(_:)`
|
||||
/// after adding branch pedals.
|
||||
/// - Throws:
|
||||
/// - `ShoeGazeError.cannotUnzipMonoChain` if the tail is mono (width 1).
|
||||
/// - `BusAllocatorError.noFreeBus` if no mono audio bus is available.
|
||||
/// - `EngineAddError` if the engine rejects the splitter add.
|
||||
public func unzipStereo() throws -> StereoSplitSection {
|
||||
guard width == 2, let rightTail: AudioBus = outputBusRight else {
|
||||
throw ShoeGazeError.cannotUnzipMonoChain
|
||||
}
|
||||
let preLeft: AudioBus = outputBus
|
||||
let preRight: AudioBus = rightTail
|
||||
|
||||
// Branch input buses are branch-owned (mirroring `splitStereo`); the dry tap is board-owned.
|
||||
let leftInBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let rightInBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||
let dryTapBus: AudioBus = try allocateInterNodeBus()
|
||||
|
||||
let splitter: StereoUnzipSplitter = StereoUnzipSplitter(
|
||||
inputLeft: preLeft.index,
|
||||
inputRight: preRight.index,
|
||||
outputBusLeft: leftInBus.index,
|
||||
outputBusRight: rightInBus.index,
|
||||
dryTapBus: dryTapBus.index
|
||||
)
|
||||
|
||||
let tail: SharedTail = SharedTail(node: splitter)
|
||||
let leftChain: BranchChain = BranchChain(
|
||||
engine: engine,
|
||||
inputBus: leftInBus,
|
||||
sampleRate: engine.sampleRate,
|
||||
sharedTail: tail
|
||||
)
|
||||
let rightChain: BranchChain = BranchChain(
|
||||
engine: engine,
|
||||
inputBus: rightInBus,
|
||||
sampleRate: engine.sampleRate,
|
||||
sharedTail: tail
|
||||
)
|
||||
branchChains.append(leftChain)
|
||||
branchChains.append(rightChain)
|
||||
|
||||
try insertNode(splitter, after: nil)
|
||||
routingNodes.append(splitter)
|
||||
|
||||
let section: StereoSplitSection = StereoSplitSection(
|
||||
splitter: splitter,
|
||||
left: leftChain,
|
||||
right: rightChain,
|
||||
sharedTail: tail,
|
||||
dryTapBus: dryTapBus
|
||||
)
|
||||
stereoUnzipSections.append(section)
|
||||
orderedSegments.append(.stereoUnzip(section))
|
||||
return section
|
||||
}
|
||||
|
||||
/// Inserts the route collector for a stereo split section and advances the board to width 2.
|
||||
///
|
||||
/// The collector reads both branch tails and the dry tap, and writes the board's new left and
|
||||
@@ -565,6 +641,7 @@ public final class PedalBoard {
|
||||
lastNode = nil
|
||||
orderedSegments.removeAll()
|
||||
stereoSplitSections.removeAll()
|
||||
stereoUnzipSections.removeAll()
|
||||
|
||||
// Step 4: Release board-owned buses (head bus and main-chain inter-node buses).
|
||||
for bus: AudioBus in allocatedBuses {
|
||||
|
||||
Reference in New Issue
Block a user