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:
@@ -27,6 +27,9 @@ public enum BoardSegmentState: Codable, Equatable {
|
||||
/// A stereo split region (`splitStereo()`/`collectStereo()`). Wire discriminator: `"stereoSplit"`.
|
||||
case stereoSplit(StereoSplitState)
|
||||
|
||||
/// A stereo unzip region (`unzipStereo()`/`collectStereo()`). Wire discriminator: `"stereoUnzip"`.
|
||||
case stereoUnzip(StereoUnzipState)
|
||||
|
||||
/// A `mergeToMono()` collapse (no payload). Wire discriminator: `"mergeToMono"`.
|
||||
case mergeToMono
|
||||
}
|
||||
|
||||
@@ -34,6 +34,13 @@ extension PedalBoard {
|
||||
route: section.route
|
||||
))
|
||||
|
||||
case .stereoUnzip(let section):
|
||||
return BoardSegmentState.stereoUnzip(StereoUnzipState(
|
||||
left: section.left.pedals.map { $0.captureState() },
|
||||
right: section.right.pedals.map { $0.captureState() },
|
||||
route: section.route
|
||||
))
|
||||
|
||||
case .mergeToMono:
|
||||
return BoardSegmentState.mergeToMono
|
||||
}
|
||||
|
||||
@@ -133,6 +133,43 @@ extension ShoeGaze {
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Inserts an empty stereo-unzip region immediately after the segment at `topLevelIndex`,
|
||||
/// splitting the stereo signal at that point into two independently editable L/R lanes.
|
||||
///
|
||||
/// Used by the per-pedal "Split L/R" toggle: pass the stereo pedal's segment index. No board-
|
||||
/// level width guard is needed — `rebuildSegments` replays segments in order, so
|
||||
/// `unzipStereo()`'s own `width == 2` check validates the *local* width at the insertion point;
|
||||
/// an invalid insert throws and the atomic `rebuildBoard` leaves the existing board intact.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - topLevelIndex: Segment index (in `captureState().segments`) after which to insert.
|
||||
/// - board: The board to edit.
|
||||
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange` for a bad index;
|
||||
/// `ShoeGazeError.cannotUnzipMonoChain` if the signal at that point is mono; any rebuild error.
|
||||
@discardableResult
|
||||
public func insertStereoUnzip(afterSegment topLevelIndex: Int, in board: PedalBoard) throws -> PedalBoard {
|
||||
var segments: [BoardSegmentState] = board.captureState().segments
|
||||
guard topLevelIndex >= 0 && topLevelIndex < segments.count else {
|
||||
throw ShoeGazeError.pedalIndexOutOfRange(index: topLevelIndex, count: segments.count)
|
||||
}
|
||||
segments.insert(
|
||||
.stereoUnzip(StereoUnzipState(left: [], right: [], route: .stereo)),
|
||||
at: topLevelIndex + 1
|
||||
)
|
||||
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
|
||||
}
|
||||
|
||||
/// Returns `true` when the segment immediately after `topLevelIndex` is a stereo-unzip region —
|
||||
/// i.e. the "Split L/R" toggle for the pedal at `topLevelIndex` is on.
|
||||
public func isStereoUnzip(afterSegment topLevelIndex: Int, in board: PedalBoard) -> Bool {
|
||||
let segments: [BoardSegmentState] = board.captureState().segments
|
||||
let next: Int = topLevelIndex + 1
|
||||
guard next >= 0 && next < segments.count else { return false }
|
||||
if case .stereoUnzip = segments[next] { return true }
|
||||
return false
|
||||
}
|
||||
|
||||
/// Appends an empty parallel section (two A/B branches summed back to one signal) to the board.
|
||||
///
|
||||
/// - Returns: The rebuilt board occupying the same slot in `boards`.
|
||||
@@ -231,6 +268,11 @@ extension ShoeGaze {
|
||||
var right: [PedalState] = state.right
|
||||
if isLeft { try transform(&left) } else { try transform(&right) }
|
||||
segments[region] = .stereoSplit(StereoSplitState(left: left, right: right, route: state.route))
|
||||
case .stereoUnzip(let state):
|
||||
var left: [PedalState] = state.left
|
||||
var right: [PedalState] = state.right
|
||||
if isLeft { try transform(&left) } else { try transform(&right) }
|
||||
segments[region] = .stereoUnzip(StereoUnzipState(left: left, right: right, route: state.route))
|
||||
case .parallel(let state):
|
||||
var branchA: [PedalState] = state.branchA
|
||||
var branchB: [PedalState] = state.branchB
|
||||
|
||||
@@ -150,6 +150,13 @@ extension ShoeGaze {
|
||||
try board.collectStereo(section)
|
||||
section.route = stereoState.route
|
||||
|
||||
case .stereoUnzip(let unzipState):
|
||||
let section: StereoSplitSection = try board.unzipStereo()
|
||||
try addPedals(unzipState.left, to: section.left)
|
||||
try addPedals(unzipState.right, to: section.right)
|
||||
try board.collectStereo(section)
|
||||
section.route = unzipState.route
|
||||
|
||||
case .mergeToMono:
|
||||
try board.mergeToMono()
|
||||
}
|
||||
@@ -289,6 +296,11 @@ extension ShoeGaze {
|
||||
applyBranchParams(stereoState.right, to: section.right.pedals)
|
||||
section.route = stereoState.route
|
||||
|
||||
case let (.stereoUnzip(section), .stereoUnzip(unzipState)):
|
||||
applyBranchParams(unzipState.left, to: section.left.pedals)
|
||||
applyBranchParams(unzipState.right, to: section.right.pedals)
|
||||
section.route = unzipState.route
|
||||
|
||||
default:
|
||||
// Topology mismatch at this position — skip.
|
||||
continue
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// StereoUnzipState.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/// Serialisable snapshot of a stereo unzip region (`unzipStereo()` → two branches →
|
||||
/// `collectStereo()`).
|
||||
///
|
||||
/// Captures the left and right branch pedal chains in signal-flow order plus the active
|
||||
/// ``StereoRoute``. Reconstructed by `loadRig`/`rebuildBoard` via `board.unzipStereo()`, adding the
|
||||
/// branch pedals, `board.collectStereo(_:)`, then restoring `route`. Structurally identical to
|
||||
/// ``StereoSplitState`` — the distinct type keeps the unzip vs split distinction in presets so the
|
||||
/// correct splitter (stereo-deinterleave vs mono-duplicate) is rebuilt.
|
||||
public struct StereoUnzipState: Codable, Equatable {
|
||||
|
||||
/// Left-channel branch pedal snapshots in signal-flow order.
|
||||
public let left: [PedalState]
|
||||
|
||||
/// Right-channel branch pedal snapshots in signal-flow order.
|
||||
public let right: [PedalState]
|
||||
|
||||
/// The output route mode (`.stereo` / `.leftOnly` / `.rightOnly` / `.bypass`).
|
||||
public let route: StereoRoute
|
||||
|
||||
/// Creates a stereo unzip snapshot.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - left: Left-branch pedal snapshots in order.
|
||||
/// - right: Right-branch pedal snapshots in order.
|
||||
/// - route: The output route mode.
|
||||
public init(
|
||||
left: [PedalState],
|
||||
right: [PedalState],
|
||||
route: StereoRoute
|
||||
) {
|
||||
self.left = left
|
||||
self.right = right
|
||||
self.route = route
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user