Files
ShoeGaze/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift
T
josh 75b99a547b feat(pedals): add Sustain Fuzz pedal + Gilmour/doom rigs
New "Sustain Fuzz": a mid-scooped, high-sustain fuzz distinct from the
single-stage Fuzz. Two cascaded soft-clip (softClipNormalized) stages
compress and stack harmonics for smooth violin-like sustain; a fixed
midrange scoop (RBJPeakingEQ cut at 750 Hz) hollows the mids; a tone
low-pass sets the top end. Sustain/Tone/Scoop knobs. Composed in effect(),
no new RT generator.

Registered in PedalType/PedalRegistry, enclosure colour, palette order.
Tests cover build+non-silent, each knob changing output, knob listing,
preset round-trip.

Adds two factory rigs: Comfortably Numb Lead and Doom Riff Wall.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-09 13:10:16 -07:00

399 lines
18 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 wraps in a `PedalType` for `ShoeGaze.appendPedal(_: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(PedalType(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
/// Category-colour fill / border opacity for the colour-coded pedal cards.
private static let categoryFillOpacity: Double = 0.22
private static let categoryBorderOpacity: Double = 0.65
private static let routingCaptionOpacity: Double = 0.5
private static let routingCaptionFontSize: CGFloat = 10
private static let addGlyphOpacity: Double = 0.4
/// Vertical gap between a pedal row's name and its description subtitle.
private static let rowSubtitleSpacing: CGFloat = 2
/// Opacity of the pedal-row description subtitle.
private static let summaryOpacity: Double = 0.55
/// Fixed card width when laid out horizontally (the vertical layout stretches to fill instead).
private static let horizontalCardWidth: CGFloat = 150
/// 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] = [
"California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "British Master", "British Dual", "Boutique Lead", "Boutique OD", "Cali Hi-Gain", "Command", "Citrus", "Sixties Combo", "Magna Vibrato", "Anaheim", "Modern High-Gain", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Ivy League", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "Cabinet", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", "Sustain Fuzz",
"Volume",
"Graphic EQ", "Tremolo", "Phaser", "Vibe", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary",
"Auto-Wah", "Wah", "Mutant", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator",
"Auto Granulator", "Bass Octaver", "Octave Splitter", "Harmonizer",
"Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverse Delay", "Reverb",
"Shimmer Reverb", "Plate Reverb", "Room Reverb", "Spring 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
private let axis: Axis
private let showsFilterMenu: Bool
/// Active type filter when the palette owns it; `nil` shows all pedals. Ignored when an
/// `externalFilter` binding is supplied (the host hoists the filter into its own header).
@State private var internalFilter: PedalCategory?
private let externalFilter: Binding<PedalCategory?>?
/// The live filter, from the host binding if provided, else the palette's own state.
private var activeFilter: PedalCategory? {
externalFilter?.wrappedValue ?? internalFilter
}
private func setFilter(_ category: PedalCategory?) {
if let externalFilter: Binding<PedalCategory?> = externalFilter {
externalFilter.wrappedValue = category
} else {
internalFilter = category
}
}
// MARK: - Init
/// Creates a pedal palette.
///
/// - Parameters:
/// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar;
/// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host
/// wraps the view in a `ScrollView` of the matching axis.
/// - filter: Optional external binding for the type filter, so a host (e.g. a sheet) can put
/// the filter control in its own fixed header. When `nil` the palette manages its own filter.
/// - showsFilterMenu: Whether to draw the built-in filter menu inline. Pass `false` when the
/// host renders its own filter control. Defaults to `true`.
/// - 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(
axis: Axis = .vertical,
filter: Binding<PedalCategory?>? = nil,
showsFilterMenu: Bool = true,
onAdd: @escaping (String) -> Void,
onRouting: @escaping (RoutingAction) -> Void = { _ in }
) {
self.axis = axis
self.externalFilter = filter
self.showsFilterMenu = showsFilterMenu
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
}
/// Pedal names after applying the active type filter.
private var visiblePedalNames: [String] {
guard let filter: PedalCategory = activeFilter else { return orderedPedalNames }
return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter }
}
/// Visible pedals bucketed by category, in the same order the filter menu lists them
/// (`PedalCategory.allCases`). Within a bucket the preferred order is preserved; empty
/// buckets are dropped so the picker shows only categories that have visible pedals.
private var groupedVisiblePedals: [(category: PedalCategory, names: [String])] {
let visible: [String] = visiblePedalNames
return PedalCategory.allCases.compactMap { category in
let names: [String] = visible.filter { PedalCategory.category(for: $0) == category }
return names.isEmpty ? nil : (category, names)
}
}
/// The `.amp` bucket on its own, or `nil` when no amp models are visible. Split out so the
/// horizontal picker can drop the (large) amp list into the second row (with Routing and the
/// Cabinet) instead of letting it stretch the head of the effects row.
private var ampGroup: (category: PedalCategory, names: [String])? {
groupedVisiblePedals.first { $0.category == .amp }
}
/// The `.cabinet` bucket on its own, or `nil` when no cabinet is visible. Sits on the second row
/// between Routing and the amp models (rig-structure controls grouped together).
private var cabinetGroup: (category: PedalCategory, names: [String])? {
groupedVisiblePedals.first { $0.category == .cabinet }
}
/// Visible pedal groups excluding the amp models and the cabinet — the actual effects row (row 1).
private var effectGroups: [(category: PedalCategory, names: [String])] {
groupedVisiblePedals.filter { $0.category != .amp && $0.category != .cabinet }
}
// MARK: - Body
public var body: some View {
switch axis {
case .horizontal: horizontalBody
default: verticalBody
}
}
/// Full-width column for a left sidebar.
private var verticalBody: some View {
VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) {
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)
}
}
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
HStack {
sectionTitle("PEDALS")
Spacer(minLength: 0)
if showsFilterMenu { filterMenu }
}
ForEach(visiblePedalNames, id: \.self) { name in
pedalRow(name)
}
}
}
}
/// Horizontal scroller: a PEDALS row (leading filter + colour-coded effect cards) with a second
/// row that carries the amp models alongside the ROUTING cards. Amps live with routing rather
/// than at the head of the effects row so the effects row stays short.
private var horizontalBody: some View {
VStack(alignment: .leading, spacing: PedalPaletteView.sectionSpacing) {
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("PEDALS")
if showsFilterMenu { filterMenu }
}
ForEach(effectGroups, id: \.category) { group in
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
categoryLabel(group.category)
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(group.names, id: \.self) { name in
pedalRow(name)
}
}
}
}
}
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
sectionTitle("ROUTING")
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(PedalPaletteView.routingOptions, id: \.title) { option in
routingCard(title: option.title, caption: option.caption, action: option.action)
}
}
}
if let cabinet: (category: PedalCategory, names: [String]) = cabinetGroup {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
categoryLabel(cabinet.category)
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(cabinet.names, id: \.self) { name in
pedalRow(name)
}
}
}
}
if let amps: (category: PedalCategory, names: [String]) = ampGroup {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
categoryLabel(amps.category)
HStack(alignment: .top, spacing: PedalPaletteView.rowSpacing) {
ForEach(amps.names, id: \.self) { name in
pedalRow(name)
}
}
}
}
}
}
}
// 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 per-group header in the horizontal picker — the category name tinted in its accent colour.
private func categoryLabel(_ category: PedalCategory) -> some View {
Text(category.rawValue.uppercased())
.font(.system(size: PedalPaletteView.titleFontSize, weight: .semibold))
.foregroundStyle(category.color.opacity(0.9))
.lineLimit(1)
}
/// "Filter by type" menu — defaults to **All** (no filtering).
private var filterMenu: some View {
Menu {
Button("All Types") { setFilter(nil) }
Divider()
ForEach(PedalCategory.allCases) { category in
Button(category.rawValue) { setFilter(category) }
}
} label: {
HStack(spacing: 3) {
Image(systemName: "line.3.horizontal.decrease.circle")
Text(activeFilter?.rawValue ?? "All").lineLimit(1)
}
.font(.system(size: PedalPaletteView.titleFontSize))
.foregroundStyle((activeFilter?.color ?? Color.white).opacity(0.9))
}
#if os(macOS)
.menuStyle(.borderlessButton)
.fixedSize()
#endif
}
/// 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 {
let summary: String = PedalRegistry.summary(for: name)
return Button {
onAdd(name)
} label: {
VStack(alignment: .leading, spacing: PedalPaletteView.rowSubtitleSpacing) {
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))
}
if !summary.isEmpty {
Text(summary)
.font(.caption2)
.foregroundStyle(Color.white.opacity(PedalPaletteView.summaryOpacity))
.lineLimit(2)
.multilineTextAlignment(.leading)
.fixedSize(horizontal: false, vertical: true)
}
}
.padding(.horizontal, PedalPaletteView.cardPaddingH)
.padding(.vertical, PedalPaletteView.cardPaddingV)
.modifier(CardFrame(axis: axis, width: PedalPaletteView.horizontalCardWidth))
.background(categoryCardBackground(PedalCategory.category(for: name).color))
}
.buttonStyle(.plain)
.draggable("add:\(name)")
}
/// Category-tinted card background — a low-opacity fill plus a stronger border in the category
/// colour, so palette blocks are colour-coded by type.
private func categoryCardBackground(_ color: Color) -> some View {
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
.fill(color.opacity(PedalPaletteView.categoryFillOpacity))
.overlay(
RoundedRectangle(cornerRadius: PedalPaletteView.cardCornerRadius)
.stroke(color.opacity(PedalPaletteView.categoryBorderOpacity),
lineWidth: PedalPaletteView.cardBorderWidth)
)
}
/// 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)
.modifier(CardFrame(axis: axis, width: PedalPaletteView.horizontalCardWidth))
.background(cardBackground(brightness: PedalPaletteView.routingCardBrightness))
}
.buttonStyle(.plain)
}
/// Stretches a card to fill width in a vertical column, or pins it to a fixed width in a
/// horizontal row.
private struct CardFrame: ViewModifier {
let axis: Axis
let width: CGFloat
func body(content: Content) -> some View {
switch axis {
case .horizontal:
content.frame(width: width, alignment: .leading)
default:
content.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
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
)
)
}
}