Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/MutantPedal.swift
T
josh f29ab609bd Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order,
summary, and tests):
- Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct
  from the mono-summed Modulation chorus.
- Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via
  LinLin) + tone low-pass.
- Ring Modulator: dry × tunable sine carrier.

Pedal-info UI:
- Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward).
- PedalRegistry.summary(for:) for the picker.
- PedalPaletteView rows show the summary as a subtitle.
- PedalView gains an ⓘ button → PedalInfoView sheet showing the description and
  the effect controls (knobs/sliders/switches) with ranges/options — excludes
  the common Mix/Level/bypass.

Tests: per-pedal build/param-change/knob-list; every built-in pedal has a
non-empty summary; info excludes common controls. 183 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:05:30 -07:00

171 lines
6.1 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// MutantPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Envelope-following auto-wah / funk-filter pedal.
///
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
/// fixes both its filter `mode` and sweep `direction` at `init`, six instances (three
/// filter modes × two sweep directions) run in parallel on the shared dry signal and a
/// nested `Select` picks the active one from the `mode` and `direction` switches — this
/// keeps every filter state warmed so switch changes are click-free (SuperCollider
/// `Select` semantics: every input advances each block).
///
/// ## Knobs
/// - `sensitivity`: Drive into the envelope follower; higher values open the filter on quieter notes.
/// - `resonance`: Filter peak emphasis at the swept cutoff.
///
/// ## Switches
/// - `direction` (two-state): `0` = Down (louder closes the filter), `1` = Up (louder opens it).
/// - `mode` (three-state): `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass.
public final class MutantPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Envelope-following auto-wah / funk filter that opens with your picking."
}
// MARK: - Parameters
/// Filter response selector. `0` = lowpass, `1` = bandpass, `2` = highpass. Driven by a three-state switch.
@UIParam public var mode: Double = 1.0
/// Sweep direction selector. `0` = down (louder closes), `1` = up (louder opens). Driven by a two-state switch.
@UIParam public var direction: Double = 1.0
/// Envelope-follower drive. Higher values make the filter respond to quieter input.
@UIParam public var sensitivity: Double = 1.5
/// Filter resonance (Chamberlin SVF peak emphasis). Clamped to `≥ 1.0` internally.
@UIParam public var resonance: Double = 4.0
// MARK: - Constants
private static let defaultMix: Double = 1.0
/// Cutoff at zero envelope, in Hz.
private let freqLo: Double = 80.0
/// Cutoff at maximum envelope, in Hz (≈40× sweep over `freqLo`).
private let freqHi: Double = 3200.0
/// Envelope attack/release times, in seconds.
private let attackTime: Double = 0.005
private let releaseTime: Double = 0.15
/// Half-step bias added before each `Select`'s truncate-toward-zero index, turning a
/// switch parameter into a round-to-nearest position selector.
private let selectRoundingBias: Double = 0.5
/// Switch position values.
private let modeLowpassValue: Double = 0.0
private let modeBandpassValue: Double = 1.0
private let modeHighpassValue: Double = 2.0
private let directionDownValue: Double = 0.0
private let directionUpValue: Double = 1.0
// MARK: - Ranges
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
private let resonanceRange: ClosedRange<Double> = 1.0 ... 12.0
// MARK: - Knobs
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Sensitivity", node: $sensitivity, range: sensitivityRange),
PedalKnob(label: "Resonance", node: $resonance, range: resonanceRange),
]
}
// MARK: - Switches
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Sweep",
node: $direction,
options: [
PedalSwitch.Option(title: "Down", value: directionDownValue),
PedalSwitch.Option(title: "Up", value: directionUpValue),
]
),
PedalSwitch(
label: "Mode",
node: $mode,
options: [
PedalSwitch.Option(title: "LP", value: modeLowpassValue),
PedalSwitch.Option(title: "BP", value: modeBandpassValue),
PedalSwitch.Option(title: "HP", value: modeHighpassValue),
]
),
]
}
// MARK: - Init
public init(inputBus: Int = 0, outputBus: Int = 0) {
super.init(
name: "Mutant",
inputBus: inputBus,
outputBus: outputBus,
initialMix: MutantPedal.defaultMix
)
}
// MARK: - Effect
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// Inner mode selectors per sweep direction. `Select` rounds the [0, 2] mode switch
// to the nearest position and advances all three filters each block (warmed state).
let modeWhich: any ValidGeneratorInput = $mode + selectRoundingBias
let downModes: Select.Audio = Select.Audio(
which: modeWhich,
inputs: [
makeFilter(dry, mode: .lowpass, direction: .down),
makeFilter(dry, mode: .bandpass, direction: .down),
makeFilter(dry, mode: .highpass, direction: .down),
]
)
let upModes: Select.Audio = Select.Audio(
which: modeWhich,
inputs: [
makeFilter(dry, mode: .lowpass, direction: .up),
makeFilter(dry, mode: .bandpass, direction: .up),
makeFilter(dry, mode: .highpass, direction: .up),
]
)
// Outer selector picks the sweep direction (Down = 0, Up = 1).
let directionWhich: any ValidGeneratorInput = $direction + selectRoundingBias
return Select.Audio(
which: directionWhich,
inputs: [downModes, upModes]
)
}
private func makeFilter(
_ dry: any ValidGeneratorInput,
mode: MuTronIIIMode,
direction: MuTronIIISweep
) -> MuTronIII.Audio {
MuTronIII.Audio(
input: dry,
mode: mode,
direction: direction,
sensitivity: $sensitivity,
peak: $resonance,
freqLo: freqLo,
freqHi: freqHi,
attackTime: attackTime,
releaseTime: releaseTime
)
}
}