69f50b2037
Three new pedals: - LimiterPedal: linear boost gain stage into a LookAheadLimiter brick-wall ceiling. Reads engine sampleRate injected by PedalBoard.add at build time. - NoiseGatePedal: AmplitudeFollower -> hysteretic Schmidt gate -> LinLin floor map -> Lag smoothing. Tuneable residual floor when the gate is closed. - GraphicEQPedal: five cascaded RBJ filters (low/high shelf + three peaking mids) with per-band dB gains and a linear master output gain. New UI control: - PedalSlider descriptor and Pedal.effectSliders hook, alongside effectKnobs and effectSwitches. - VerticalParameterSlider: a vertical fader bound to a UIParamNode. - PedalView renders the fader bank and widens the enclosure to fit it. Persistence/registry: - PedalState.sliderValues (decodeIfPresent for backward compatibility); capture and apply in Pedal+Preset. - Registry entries and palette ordering for all three pedals. Tests: non-silent builds, limiter ceiling enforcement, gate open/closed/unity floor power ratios, EQ flat output, global-gain scaling, and 6-slider preset round-trip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
186 lines
7.3 KiB
Swift
186 lines
7.3 KiB
Swift
// 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", "Limiter", "Noise Gate", "Fuzz",
|
|
"Graphic EQ", "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
|
|
)
|
|
)
|
|
}
|
|
}
|