Add Limiter, Noise Gate, and Graphic EQ pedals + vertical-fader UI control
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>
This commit is contained in:
@@ -45,7 +45,8 @@ public struct PedalPaletteView: View {
|
||||
/// 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",
|
||||
"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",
|
||||
]
|
||||
|
||||
@@ -28,6 +28,9 @@ private func enclosureColor(for displayName: String) -> Color {
|
||||
case "Auto-Wah": return Color(red: 0.80, green: 0.62, blue: 0.10) // gold
|
||||
case "Feedback Delay": return Color(red: 0.48, green: 0.30, blue: 0.14) // tape sepia
|
||||
case "Multi-Tap Delay": return Color(red: 0.08, green: 0.48, blue: 0.68) // cyan
|
||||
case "Limiter": return Color(red: 0.62, green: 0.16, blue: 0.20) // brick red
|
||||
case "Noise Gate": return Color(red: 0.24, green: 0.26, blue: 0.30) // gunmetal
|
||||
case "Graphic EQ": return Color(red: 0.14, green: 0.40, blue: 0.50) // deep teal
|
||||
default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray
|
||||
}
|
||||
}
|
||||
@@ -184,6 +187,11 @@ public struct PedalView: View {
|
||||
private static let screwInset: CGFloat = 6
|
||||
private static let knobColumnCount: Int = 3
|
||||
private static let knobSpacing: CGFloat = 10
|
||||
/// Horizontal gap between adjacent vertical faders in the slider bank.
|
||||
private static let sliderBankSpacing: CGFloat = 4
|
||||
/// Approximate per-fader footprint (matches `VerticalParameterSlider.controlWidth`),
|
||||
/// used to widen the enclosure so a wide bank (e.g. a 6-band EQ) is never clipped.
|
||||
private static let sliderBankItemWidth: CGFloat = 28
|
||||
/// Horizontal gap between the Level knob and the bypass control in the bottom row.
|
||||
private static let bottomControlsSpacing: CGFloat = 18
|
||||
private static let sectionSpacing: CGFloat = 14
|
||||
@@ -224,6 +232,9 @@ public struct PedalView: View {
|
||||
public var body: some View {
|
||||
let accent: Color = enclosureColor(for: pedal.displayName)
|
||||
let darkAccent: Color = accent.opacity(PedalView.enclosureGradientDarkFraction)
|
||||
// Evaluate the (computed) slider descriptors once per render — both the bank and
|
||||
// the enclosure-width calculation consume the same array.
|
||||
let sliders: [PedalSlider] = pedal.effectSliders
|
||||
|
||||
ZStack(alignment: .topLeading) {
|
||||
// Enclosure fill with top-to-bottom gradient
|
||||
@@ -252,6 +263,7 @@ public struct PedalView: View {
|
||||
namePlate
|
||||
knobGrid
|
||||
switchRow
|
||||
sliderBank(sliders)
|
||||
Spacer(minLength: 0)
|
||||
bottomControls
|
||||
}
|
||||
@@ -260,7 +272,7 @@ public struct PedalView: View {
|
||||
// Corner screws — overlaid at the four corners
|
||||
screwCorners
|
||||
}
|
||||
.frame(width: PedalView.enclosureWidth)
|
||||
.frame(width: enclosureWidth(for: sliders))
|
||||
.shadow(
|
||||
color: Color.black.opacity(PedalView.shadowOpacity),
|
||||
radius: PedalView.shadowRadius,
|
||||
@@ -332,6 +344,32 @@ public struct PedalView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// Row of vertical faders drawn from `pedal.effectSliders`, beneath the switch row.
|
||||
/// Renders nothing when the pedal publishes no sliders.
|
||||
@ViewBuilder
|
||||
private func sliderBank(_ sliders: [PedalSlider]) -> some View {
|
||||
if !sliders.isEmpty {
|
||||
HStack(alignment: .top, spacing: PedalView.sliderBankSpacing) {
|
||||
ForEach(Array(sliders.enumerated()), id: \.offset) { pair in
|
||||
let slider: PedalSlider = pair.element
|
||||
VerticalParameterSlider(slider.label, node: slider.node, range: slider.range)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Enclosure width — the base stompbox width, widened to fit a wide vertical-fader bank
|
||||
/// (e.g. a multi-band graphic EQ) so its faders are never clipped.
|
||||
private func enclosureWidth(for sliders: [PedalSlider]) -> CGFloat {
|
||||
let sliderCount: Int = sliders.count
|
||||
guard sliderCount > 0 else { return PedalView.enclosureWidth }
|
||||
let bankContentWidth: CGFloat =
|
||||
CGFloat(sliderCount) * PedalView.sliderBankItemWidth
|
||||
+ CGFloat(max(0, sliderCount - 1)) * PedalView.sliderBankSpacing
|
||||
let needed: CGFloat = bankContentWidth + 2 * PedalView.enclosurePadding
|
||||
return max(PedalView.enclosureWidth, needed)
|
||||
}
|
||||
|
||||
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
|
||||
/// side-by-side and centred — a symmetric knob-switch-knob footer shared by all pedals.
|
||||
private var bottomControls: some View {
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
// VerticalParameterSlider.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import SwiftUI
|
||||
import LyrebirdUI
|
||||
|
||||
/// A vertical fader bound to a single ``UIParamNode``.
|
||||
///
|
||||
/// Drag anywhere on the track to set the value: dragging to the top maps to
|
||||
/// `range.upperBound`, dragging to the bottom maps to `range.lowerBound`. A filled bar
|
||||
/// grows up from the bottom to show the current position and a thin thumb marks the value.
|
||||
/// The control reads `node.value` (so it re-renders when the parameter changes elsewhere)
|
||||
/// and writes back via `node.update(_:)`.
|
||||
///
|
||||
/// `PedalView` renders a row of these for the graphic-EQ-style fader bank a pedal
|
||||
/// publishes through `Pedal.effectSliders`.
|
||||
struct VerticalParameterSlider: View {
|
||||
|
||||
// MARK: - Layout constants
|
||||
|
||||
private static let trackWidth: CGFloat = 10
|
||||
private static let trackCornerRadius: CGFloat = 5
|
||||
private static let thumbHeight: CGFloat = 4
|
||||
private static let thumbWidth: CGFloat = 20
|
||||
private static let thumbCornerRadius: CGFloat = 2
|
||||
private static let controlWidth: CGFloat = 28
|
||||
private static let trackHeight: CGFloat = 110
|
||||
private static let labelSpacing: CGFloat = 4
|
||||
private static let valueSpacing: CGFloat = 4
|
||||
private static let fontSizeLabel: CGFloat = 9
|
||||
private static let fontSizeValue: CGFloat = 9
|
||||
private static let trackBackgroundOpacity: Double = 0.30
|
||||
private static let fillTopOpacity: Double = 0.95
|
||||
private static let fillBottomOpacity: Double = 0.55
|
||||
private static let thumbOpacity: Double = 0.95
|
||||
private static let labelOpacity: Double = 0.85
|
||||
private static let valueOpacity: Double = 0.70
|
||||
/// Range span at or above which the value is shown as a whole number (dB bands) rather
|
||||
/// than with two decimals (narrow linear ranges like the master gain).
|
||||
private static let wideSpanThreshold: Double = 5.0
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private let label: String
|
||||
private let node: UIParamNode
|
||||
private let range: ClosedRange<Double>
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
/// Creates a vertical fader.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - label: Short caption shown beneath the fader.
|
||||
/// - node: The `UIParamNode` the fader reads and writes.
|
||||
/// - range: Inclusive value range the fader spans, in the parameter's units.
|
||||
init(
|
||||
_ label: String,
|
||||
node: UIParamNode,
|
||||
range: ClosedRange<Double>
|
||||
) {
|
||||
self.label = label
|
||||
self.node = node
|
||||
self.range = range
|
||||
}
|
||||
|
||||
// MARK: - Value mapping
|
||||
|
||||
/// Current value clamped into `range`.
|
||||
private var clampedValue: Double {
|
||||
min(max(node.value, range.lowerBound), range.upperBound)
|
||||
}
|
||||
|
||||
/// Current value as a `[0, 1]` fraction of the range (0 = bottom, 1 = top).
|
||||
private var fraction: CGFloat {
|
||||
let span: Double = range.upperBound - range.lowerBound
|
||||
guard span > 0 else { return 0 }
|
||||
return CGFloat((clampedValue - range.lowerBound) / span)
|
||||
}
|
||||
|
||||
// MARK: - Body
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: VerticalParameterSlider.labelSpacing) {
|
||||
track
|
||||
Text(label)
|
||||
.font(.system(size: VerticalParameterSlider.fontSizeLabel, weight: .semibold))
|
||||
.foregroundStyle(Color.white.opacity(VerticalParameterSlider.labelOpacity))
|
||||
.lineLimit(1)
|
||||
Text(valueText)
|
||||
.font(.system(size: VerticalParameterSlider.fontSizeValue, design: .monospaced))
|
||||
.foregroundStyle(Color.white.opacity(VerticalParameterSlider.valueOpacity))
|
||||
.lineLimit(1)
|
||||
}
|
||||
.frame(width: VerticalParameterSlider.controlWidth)
|
||||
}
|
||||
|
||||
/// The draggable track with background, value fill, and thumb.
|
||||
private var track: some View {
|
||||
GeometryReader { geometry in
|
||||
let height: CGFloat = geometry.size.height
|
||||
let fillHeight: CGFloat = height * fraction
|
||||
|
||||
ZStack(alignment: .bottom) {
|
||||
// Background track
|
||||
RoundedRectangle(cornerRadius: VerticalParameterSlider.trackCornerRadius)
|
||||
.fill(Color.black.opacity(VerticalParameterSlider.trackBackgroundOpacity))
|
||||
.frame(width: VerticalParameterSlider.trackWidth)
|
||||
|
||||
// Value fill growing up from the bottom
|
||||
RoundedRectangle(cornerRadius: VerticalParameterSlider.trackCornerRadius)
|
||||
.fill(
|
||||
LinearGradient(
|
||||
colors: [
|
||||
Color.white.opacity(VerticalParameterSlider.fillTopOpacity),
|
||||
Color.white.opacity(VerticalParameterSlider.fillBottomOpacity),
|
||||
],
|
||||
startPoint: .top,
|
||||
endPoint: .bottom
|
||||
)
|
||||
)
|
||||
.frame(width: VerticalParameterSlider.trackWidth, height: fillHeight)
|
||||
|
||||
// Thumb marking the current value. Clamp its centre into the track so it
|
||||
// never overhangs the ends at the value extremes.
|
||||
let halfThumb: CGFloat = VerticalParameterSlider.thumbHeight / 2
|
||||
let thumbCentre: CGFloat = min(max(fillHeight, halfThumb), height - halfThumb)
|
||||
RoundedRectangle(cornerRadius: VerticalParameterSlider.thumbCornerRadius)
|
||||
.fill(Color.white.opacity(VerticalParameterSlider.thumbOpacity))
|
||||
.frame(
|
||||
width: VerticalParameterSlider.thumbWidth,
|
||||
height: VerticalParameterSlider.thumbHeight
|
||||
)
|
||||
.offset(y: -(thumbCentre - halfThumb))
|
||||
}
|
||||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||
.contentShape(Rectangle())
|
||||
.gesture(
|
||||
DragGesture(minimumDistance: 0)
|
||||
.onChanged { drag in
|
||||
updateValue(forY: drag.location.y, height: height)
|
||||
}
|
||||
)
|
||||
}
|
||||
.frame(width: VerticalParameterSlider.controlWidth, height: VerticalParameterSlider.trackHeight)
|
||||
}
|
||||
|
||||
/// Formats the current value: integers when the span is wide (dB bands), two decimals otherwise.
|
||||
private var valueText: String {
|
||||
let span: Double = range.upperBound - range.lowerBound
|
||||
if span >= VerticalParameterSlider.wideSpanThreshold {
|
||||
return String(format: "%.0f", clampedValue)
|
||||
}
|
||||
return String(format: "%.2f", clampedValue)
|
||||
}
|
||||
|
||||
// MARK: - Drag handling
|
||||
|
||||
/// Converts a vertical drag position into a parameter value and writes it to the node.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - y: Drag Y position in the track's coordinate space (0 = top).
|
||||
/// - height: Track height in points.
|
||||
private func updateValue(forY y: CGFloat, height: CGFloat) {
|
||||
guard height > 0 else { return }
|
||||
// Invert: top of the track (y = 0) is the maximum, bottom is the minimum.
|
||||
let clampedY: CGFloat = min(max(y, 0), height)
|
||||
let frac: Double = Double(1 - clampedY / height)
|
||||
let span: Double = range.upperBound - range.lowerBound
|
||||
node.update(range.lowerBound + frac * span)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user