feat(mutant): add Range switch, Sweep, and Attack/Release controls

The envelope filter's cutoff sweep was fixed (80 Hz -> 3200 Hz, 5 ms / 150 ms),
so it read as either muted (resting too low) or extreme (40x span). The
underlying MuTronIII generator already takes freqLo/freqHi/attack/release as
live params, so expose them:

- Range switch (Lo/Hi) on the face — shifts the whole sweep window low
  (rhythm/bass) or high (harmonics/solos), matching the original Mu-Tron III.
- Sweep, Attack, Release in the advanced pop-over — Sweep sets how far input
  amplitude drives the cutoff (peak = resting x sweep); Attack/Release shape
  the envelope response.
- Tamer defaults: resting 80 -> 120 Hz, span 40x -> 20x.

Serialization-safe: new continuous params live in advancedValues and Range is
a trailing switch, so a rig saved with the old 2-switch / no-advanced layout
loads unchanged with the new controls at their defaults (test covers it).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-13 09:42:52 -07:00
parent 850b86209a
commit 4a9bf0fb30
2 changed files with 161 additions and 26 deletions
@@ -17,6 +17,13 @@ import LyrebirdUI
/// keeps every filter state warmed so switch changes are click-free (SuperCollider
/// `Select` semantics: every input advances each block).
///
/// The cutoff sweeps exponentially from a resting frequency (`freqLo`) up to a peak
/// (`freqHi`) as the envelope opens: `cutoff = freqLo·(freqHi/freqLo)^envelope`. The
/// **Range** switch shifts that whole window low (rhythm / bass) or high (harmonics /
/// solos), matching the original pedal; the **Sweep** knob sets how far above the resting
/// frequency the envelope drives the cutoff (its "openness"), and **Attack** / **Release**
/// shape how quickly the filter follows the input dynamics.
///
/// ## Knobs
/// - `sensitivity`: Drive into the envelope follower; higher values open the filter on quieter notes.
/// - `resonance`: Filter peak emphasis at the swept cutoff.
@@ -24,6 +31,12 @@ import LyrebirdUI
/// ## 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.
/// - `range` (two-state): `0` = Low band (rhythm / bass), `1` = High band (harmonics / solos).
///
/// ## Advanced
/// - `sweep`: How far the envelope drives the cutoff above its resting frequency (peak = resting × sweep).
/// - `attack`: Envelope attack time in seconds — how fast the filter opens on a transient.
/// - `release`: Envelope release time in seconds — how fast it closes after a note.
public final class MutantPedal: Pedal {
/// One-line description shown in the picker and info panel.
@@ -45,19 +58,29 @@ public final class MutantPedal: Pedal {
/// Filter resonance (Chamberlin SVF peak emphasis). Clamped to `≥ 1.0` internally.
@UIParam public var resonance: Double = 4.0
/// Frequency-band selector. `0` = Low band, `1` = High band. Shifts the resting cutoff (and with
/// it the whole sweep window) up or down. Driven by a two-state switch.
@UIParam public var range: Double = 0.0
/// Sweep amount: the peak cutoff is `restingCutoff × sweep`, so higher values open the filter
/// further as the input drives it. Advanced knob.
@UIParam public var sweep: Double = 20.0
/// Envelope attack time in seconds — how fast the filter opens on a transient. Advanced knob.
@UIParam public var attack: Double = 0.008
/// Envelope release time in seconds — how fast the filter closes after a note. Advanced knob.
@UIParam public var release: Double = 0.14
// MARK: - Constants
private static let defaultMix: Double = 1.0
/// Cutoff at zero envelope, in Hz.
private let freqLo: Double = 80.0
/// Resting cutoff (in Hz) at `range == Low`.
private let rangeLowBaseFreq: Double = 120.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
/// Resting cutoff (in Hz) at `range == High`.
private let rangeHighBaseFreq: Double = 380.0
/// Half-step bias added before each `Select`'s truncate-toward-zero index, turning a
/// switch parameter into a round-to-nearest position selector.
@@ -69,11 +92,17 @@ public final class MutantPedal: Pedal {
private let modeHighpassValue: Double = 2.0
private let directionDownValue: Double = 0.0
private let directionUpValue: Double = 1.0
private let rangeLowValue: Double = 0.0
private let rangeHighValue: Double = 1.0
// MARK: - Ranges
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
private let resonanceRange: ClosedRange<Double> = 1.0 ... 12.0
/// Sweep multiplier: peak cutoff = resting × sweep. `1` = no sweep; `50` ≈ 5.6 octaves.
private let sweepRange: ClosedRange<Double> = 1.0 ... 50.0
private let attackRange: ClosedRange<Double> = 0.001 ... 0.08
private let releaseRange: ClosedRange<Double> = 0.02 ... 0.6
// MARK: - Knobs
@@ -84,12 +113,20 @@ public final class MutantPedal: Pedal {
]
}
public override var advancedKnobs: [PedalKnob] {
[
PedalKnob(label: "Sweep", node: $sweep, range: sweepRange),
PedalKnob(label: "Attack", node: $attack, range: attackRange),
PedalKnob(label: "Release", node: $release, range: releaseRange),
]
}
// MARK: - Switches
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Sweep",
label: "Direction",
node: $direction,
options: [
PedalSwitch.Option(title: "Down", value: directionDownValue),
@@ -105,6 +142,14 @@ public final class MutantPedal: Pedal {
PedalSwitch.Option(title: "HP", value: modeHighpassValue),
]
),
PedalSwitch(
label: "Range",
node: $range,
options: [
PedalSwitch.Option(title: "Lo", value: rangeLowValue),
PedalSwitch.Option(title: "Hi", value: rangeHighValue),
]
),
]
}
@@ -122,23 +167,29 @@ public final class MutantPedal: Pedal {
// MARK: - Effect
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
// Resting cutoff shifts with the Range switch (Low band vs High band); the peak the envelope
// reaches is `restingCutoff × sweep`. Both feed all six warmed filters (fan-out).
let restingFreq: any ValidGeneratorInput =
$range * (rangeHighBaseFreq - rangeLowBaseFreq) + rangeLowBaseFreq
let peakFreq: any ValidGeneratorInput = restingFreq * $sweep
// 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),
makeFilter(dry, mode: .lowpass, direction: .down, freqLo: restingFreq, freqHi: peakFreq),
makeFilter(dry, mode: .bandpass, direction: .down, freqLo: restingFreq, freqHi: peakFreq),
makeFilter(dry, mode: .highpass, direction: .down, freqLo: restingFreq, freqHi: peakFreq),
]
)
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),
makeFilter(dry, mode: .lowpass, direction: .up, freqLo: restingFreq, freqHi: peakFreq),
makeFilter(dry, mode: .bandpass, direction: .up, freqLo: restingFreq, freqHi: peakFreq),
makeFilter(dry, mode: .highpass, direction: .up, freqLo: restingFreq, freqHi: peakFreq),
]
)
@@ -153,7 +204,9 @@ public final class MutantPedal: Pedal {
private func makeFilter(
_ dry: any ValidGeneratorInput,
mode: MuTronIIIMode,
direction: MuTronIIISweep
direction: MuTronIIISweep,
freqLo: any ValidGeneratorInput,
freqHi: any ValidGeneratorInput
) -> MuTronIII.Audio {
MuTronIII.Audio(
input: dry,
@@ -163,8 +216,8 @@ public final class MutantPedal: Pedal {
peak: $resonance,
freqLo: freqLo,
freqHi: freqHi,
attackTime: attackTime,
releaseTime: releaseTime
attackTime: $attack,
releaseTime: $release
)
}
}