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:
@@ -47,6 +47,8 @@ public struct BoardFlowView: View {
|
||||
private static let badgeFontSize: CGFloat = 11
|
||||
private static let badgeOpacity: Double = 0.6
|
||||
private static let dropHighlightWidth: CGFloat = 2
|
||||
private static let splitToggleSpacing: CGFloat = 6
|
||||
private static let splitToggleWidth: CGFloat = 200
|
||||
private static let emptyLaneOpacity: Double = 0.4
|
||||
|
||||
/// Signal-path accent (the pink/magenta connector colour).
|
||||
@@ -121,6 +123,8 @@ public struct BoardFlowView: View {
|
||||
if pedal.channelKind != .mono { stereo = true }
|
||||
case .stereoSplit:
|
||||
stereo = true
|
||||
case .stereoUnzip:
|
||||
stereo = true
|
||||
case .parallel:
|
||||
break
|
||||
case .mergeToMono:
|
||||
@@ -145,7 +149,7 @@ public struct BoardFlowView: View {
|
||||
private func stageView(_ stage: StageModel) -> some View {
|
||||
switch stage.segment {
|
||||
case .pedal(let pedal):
|
||||
mainPedalCard(pedal: pedal, linearIndex: stage.linearIndex ?? 0)
|
||||
mainPedalCard(pedal: pedal, linearIndex: stage.linearIndex ?? 0, segmentIndex: stage.segmentIndex)
|
||||
case .stereoSplit(let section):
|
||||
regionNode(
|
||||
title: "STEREO SPLIT",
|
||||
@@ -156,6 +160,16 @@ public struct BoardFlowView: View {
|
||||
rightPedals: section.right.pedals,
|
||||
control: AnyView(StereoRouteControlView(section: section))
|
||||
)
|
||||
case .stereoUnzip(let section):
|
||||
regionNode(
|
||||
title: "STEREO UNZIP",
|
||||
segmentIndex: stage.segmentIndex,
|
||||
leftLabel: "L",
|
||||
rightLabel: "R",
|
||||
leftPedals: section.left.pedals,
|
||||
rightPedals: section.right.pedals,
|
||||
control: AnyView(StereoRouteControlView(section: section))
|
||||
)
|
||||
case .parallel(let section):
|
||||
regionNode(
|
||||
title: "PARALLEL",
|
||||
@@ -201,9 +215,9 @@ public struct BoardFlowView: View {
|
||||
|
||||
// MARK: - Main pedal card
|
||||
|
||||
private func mainPedalCard(pedal: Pedal, linearIndex: Int) -> some View {
|
||||
private func mainPedalCard(pedal: Pedal, linearIndex: Int, segmentIndex: Int) -> some View {
|
||||
let payload: String = "movemain:\(linearIndex)"
|
||||
return PedalView(pedal: pedal)
|
||||
let card: some View = PedalView(pedal: pedal)
|
||||
.overlay(alignment: .topTrailing) { trashButton { deleteSegment(forLinear: linearIndex) } }
|
||||
.overlay { dropOutline(active: dropTarget == payload) }
|
||||
.draggable(payload)
|
||||
@@ -212,6 +226,48 @@ public struct BoardFlowView: View {
|
||||
} isTargeted: { hovering in
|
||||
dropTarget = hovering ? payload : (dropTarget == payload ? nil : dropTarget)
|
||||
}
|
||||
return VStack(spacing: BoardFlowView.splitToggleSpacing) {
|
||||
card
|
||||
// Stereo-producing pedals (Ping-Pong, Octave Splitter) offer a choice: keep one stereo
|
||||
// flow downstream, or split the L/R channels into independent lanes (a stereo unzip).
|
||||
if pedal.channelKind != .mono {
|
||||
splitToggle(segmentIndex: segmentIndex)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A "Stereo flow / Split L/R" segmented control for a stereo-producing pedal. "Split L/R"
|
||||
/// inserts a stereo-unzip region right after the pedal; "Stereo flow" removes it.
|
||||
private func splitToggle(segmentIndex: Int) -> some View {
|
||||
let binding: Binding<Bool> = Binding(
|
||||
get: {
|
||||
guard let board: PedalBoard = board else { return false }
|
||||
return shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board)
|
||||
},
|
||||
set: { split in
|
||||
guard let board: PedalBoard = board else { return }
|
||||
do {
|
||||
if split {
|
||||
guard !shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board) else { return }
|
||||
_ = try shoeGaze.insertStereoUnzip(afterSegment: segmentIndex, in: board)
|
||||
} else {
|
||||
// Only remove the next segment if it is in fact this pedal's unzip region —
|
||||
// it may have been removed via the region's own trash button.
|
||||
guard shoeGaze.isStereoUnzip(afterSegment: segmentIndex, in: board) else { return }
|
||||
_ = try shoeGaze.removeSegment(at: segmentIndex + 1, from: board)
|
||||
}
|
||||
} catch {
|
||||
print("[BoardFlowView] split toggle failed: \(error)")
|
||||
}
|
||||
}
|
||||
)
|
||||
return Picker("", selection: binding) {
|
||||
Text("Stereo flow").tag(false)
|
||||
Text("Split L/R").tag(true)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
.labelsHidden()
|
||||
.frame(maxWidth: BoardFlowView.splitToggleWidth)
|
||||
}
|
||||
|
||||
// MARK: - Region node (stereo split / parallel)
|
||||
|
||||
Reference in New Issue
Block a user