Files
ShoeGaze/Sources/LyrebirdShoeGaze/Presets/Pedal+Preset.swift
T
josh 69f50b2037 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>
2026-06-23 12:36:42 -07:00

57 lines
2.4 KiB
Swift

// Pedal+Preset.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
extension Pedal {
/// Captures the current parameter values of this pedal as a `PedalState`.
///
/// The returned snapshot includes:
/// - `type`: the pedal's `displayName` (used as a factory key on load).
/// - `knobValues`: one `Double` per entry in `knobs`, in order
/// (effect-specific knobs first, then Mix, then Level).
/// - `bypass`: the current bypass parameter value.
///
/// - Returns: A `PedalState` reflecting the pedal's current parameter values.
public func captureState() -> PedalState {
let values: [Double] = knobs.map { $0.node.value }
let switchValues: [Double] = effectSwitches.map { $0.node.value }
let sliderValues: [Double] = effectSliders.map { $0.node.value }
return PedalState(
type: displayName,
knobValues: values,
switchValues: switchValues,
sliderValues: sliderValues,
bypass: bypass
)
}
/// Applies a previously captured `PedalState` to this pedal's parameters.
///
/// For each (knob, value) pair in `zip(knobs, state.knobValues)`, the knob's
/// `UIParamNode` is updated via `node.update(_:)`; switch positions are restored the
/// same way from `zip(effectSwitches, state.switchValues)`. If either array has fewer
/// entries than its controls, the trailing controls retain their current values; extra
/// values are ignored. The `bypass` parameter is always applied regardless of any
/// count mismatch. Presets saved before switches existed carry an empty
/// `switchValues`, leaving switch positions at their defaults.
///
/// - Parameter state: The state to restore. The `state.type` is not validated
/// against `displayName` — the caller is responsible for matching types before
/// calling this method.
public func applyState(_ state: PedalState) {
for (knob, value) in zip(knobs, state.knobValues) {
knob.node.update(value)
}
for (pedalSwitch, value) in zip(effectSwitches, state.switchValues) {
pedalSwitch.node.update(value)
}
for (slider, value) in zip(effectSliders, state.sliderValues) {
slider.node.update(value)
}
bypass = state.bypass
}
}