Add signal-flow pedalboard builder UI
Interactive builder views in LyrebirdShoeGazeUI: - PedalPaletteView: vertical sidebar listing every pedal (tap to append to the main chain, drag "add:<type>" onto a lane) plus routing actions (Stereo Split / Parallel Split / Merge to Mono). - BoardFlowView: left-to-right signal-flow board driven by board.orderedSegments. Pedal cards joined by pink connector lines (double for stereo width); split regions render as two stacked L/R (A/B) lanes you fill independently by dropping pedals; per-card trash, drag-to-reorder within a lane, region route/mode controls, and a region trash. Reads shoeGaze.boards[index] fresh each body (index is the stable anchor across rebuilds). - ShoeGazeBuilderView: sidebar + vertically-centered flow board, with transport, input picker, board picker, and JSON save/load (NSSavePanel / NSOpenPanel on macOS, fileExporter/Importer on iOS via RigFileDocument). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,184 @@
|
||||
// PedalPaletteView.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
import LyrebirdShoeGaze
|
||||
|
||||
/// A vertical catalog of every available pedal plus a reference list of the routing/branching
|
||||
/// options, sized to sit in a narrow left sidebar.
|
||||
///
|
||||
/// The pedal rows are tappable: selecting one invokes `onAdd(type)` with the pedal's
|
||||
/// `displayName`, which the host wires to `ShoeGaze.appendPedal(type:to:)`. The routing cards
|
||||
/// (Parallel split, Stereo split, Chain router, Merge to mono) are informational only — they
|
||||
/// describe the topologies the engine supports, which are built programmatically rather than via
|
||||
/// linear add (see ``BoardBuilderView`` for the read-only display of existing branches).
|
||||
///
|
||||
/// ## Usage
|
||||
///
|
||||
/// ```swift
|
||||
/// PedalPaletteView { type in
|
||||
/// try? shoeGaze.appendPedal(type: type, to: board)
|
||||
/// }
|
||||
/// ```
|
||||
public struct PedalPaletteView: View {
|
||||
|
||||
// MARK: - Layout constants
|
||||
|
||||
private static let sectionSpacing: CGFloat = 14
|
||||
private static let rowSpacing: CGFloat = 6
|
||||
private static let titleFontSize: CGFloat = 12
|
||||
private static let titleOpacity: Double = 0.7
|
||||
private static let cardCornerRadius: CGFloat = 7
|
||||
private static let cardPaddingH: CGFloat = 10
|
||||
private static let cardPaddingV: CGFloat = 7
|
||||
private static let cardBorderOpacity: Double = 0.4
|
||||
private static let cardBorderWidth: CGFloat = 1
|
||||
private static let pedalCardBrightness: Double = 0.18
|
||||
private static let routingCardBrightness: Double = 0.1
|
||||
private static let routingCaptionOpacity: Double = 0.5
|
||||
private static let routingCaptionFontSize: CGFloat = 10
|
||||
private static let addGlyphOpacity: Double = 0.4
|
||||
|
||||
/// Preferred display order for the built-in pedals. Any registered pedal not listed here is
|
||||
/// appended afterwards (sorted) so the palette never silently drops a newly added pedal.
|
||||
private static let preferredOrder: [String] = [
|
||||
"Overdrive", "Compressor", "Fuzz", "Tremolo", "Phaser", "Modulation",
|
||||
"Auto-Wah", "Mu-Tron", "Bass Octaver", "Octave Splitter",
|
||||
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb",
|
||||
]
|
||||
|
||||
/// Routing/branching topologies the user can insert into the board.
|
||||
private static let routingOptions: [(title: String, caption: String, action: RoutingAction)] = [
|
||||
("Stereo Split", "L/R independent lanes", .stereoSplit),
|
||||
("Parallel Split", "A/B branches, mixed", .parallelSplit),
|
||||
("Merge to Mono", "Collapse stereo → mono", .mergeToMono),
|
||||
]
|
||||
|
||||
/// Routing actions a host can perform from the palette.
|
||||
public enum RoutingAction: Equatable, Sendable {
|
||||
case stereoSplit
|
||||
case parallelSplit
|
||||
case mergeToMono
|
||||
case chainRouter
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let onAdd: (String) -> Void
|
||||
private let onRouting: (RoutingAction) -> Void
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a pedal palette.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
||||
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
||||
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
||||
public init(
|
||||
onAdd: @escaping (String) -> Void,
|
||||
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
||||
) {
|
||||
self.onAdd = onAdd
|
||||
self.onRouting = onRouting
|
||||
}
|
||||
|
||||
/// Registered pedal names in preferred order, with any unlisted registered pedals appended.
|
||||
private var orderedPedalNames: [String] {
|
||||
let registered: Set<String> = Set(PedalRegistry.builtIn.keys)
|
||||
let ordered: [String] = PedalPaletteView.preferredOrder.filter { registered.contains($0) }
|
||||
let extras: [String] = registered
|
||||
.subtracting(ordered)
|
||||
.sorted()
|
||||
return ordered + extras
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
public var body: some View {
|
||||
VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) {
|
||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||
sectionTitle("PEDALS")
|
||||
ForEach(orderedPedalNames, id: \.self) { name in
|
||||
pedalRow(name)
|
||||
}
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||
sectionTitle("ROUTING")
|
||||
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
|
||||
routingCard(title: option.title, caption: option.caption, action: option.action)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
private func sectionTitle(_ text: String) -> some View {
|
||||
Text(text)
|
||||
.font(.system(size: PedalPaletteView.titleFontSize, weight: .semibold))
|
||||
.foregroundStyle(Color.white.opacity(PedalPaletteView.titleOpacity))
|
||||
}
|
||||
|
||||
/// A full-width pedal row: tap appends to the main chain; drag carries `"add:<name>"` so it can
|
||||
/// be dropped onto a stereo/parallel lane.
|
||||
private func pedalRow(_ name: String) -> some View {
|
||||
Button {
|
||||
onAdd(name)
|
||||
} label: {
|
||||
HStack(spacing: 4) {
|
||||
Text(name)
|
||||
.font(.callout)
|
||||
.foregroundStyle(Color.white)
|
||||
.lineLimit(1)
|
||||
Spacer(minLength: 0)
|
||||
Image(systemName: "plus")
|
||||
.font(.caption2)
|
||||
.foregroundStyle(Color.white.opacity(PedalPaletteView.addGlyphOpacity))
|
||||
}
|
||||
.padding(.horizontal, PedalPaletteView.cardPaddingH)
|
||||
.padding(.vertical, PedalPaletteView.cardPaddingV)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(cardBackground(brightness: PedalPaletteView.pedalCardBrightness))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.draggable("add:\(name)")
|
||||
}
|
||||
|
||||
/// A tappable routing row that inserts a region/node into the board.
|
||||
private func routingCard(title: String, caption: String, action: RoutingAction) -> some View {
|
||||
Button {
|
||||
onRouting(action)
|
||||
} label: {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(title)
|
||||
.font(.callout)
|
||||
.foregroundStyle(Color.white)
|
||||
Text(caption)
|
||||
.font(.system(size: PedalPaletteView.routingCaptionFontSize))
|
||||
.foregroundStyle(Color.white.opacity(PedalPaletteView.routingCaptionOpacity))
|
||||
}
|
||||
.padding(.horizontal, PedalPaletteView.cardPaddingH)
|
||||
.padding(.vertical, PedalPaletteView.cardPaddingV)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(cardBackground(brightness: PedalPaletteView.routingCardBrightness))
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
}
|
||||
|
||||
private func cardBackground(brightness: Double) -> some View {
|
||||
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
|
||||
.fill(Color(white: brightness))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
|
||||
.stroke(
|
||||
Color.white.opacity(PedalPaletteView.cardBorderOpacity),
|
||||
lineWidth: PedalPaletteView.cardBorderWidth
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user