Add segmented pedal switch control; Mu-Tron sweep + mode switches
Introduces a discrete multi-position switch control alongside the rotary knobs, and uses it to expose the Mu-Tron's sweep direction and filter mode. - PedalSwitch: UI-agnostic descriptor (label, node, ordered options of caption + value), parallel to PedalKnob. Two options make a two-state switch, three a three-state switch. - PedalSwitchView: segmented SwiftUI control bound to a UIParamNode. Lit segment is the option nearest the node's value; tapping writes that option's value. Serves both two- and three-state switches. - Pedal gains an effectSwitches hook; PedalView renders a switch row between the knob grid and the footswitch. - MuTronPedal: sweep direction is now a two-state switch (Down/Up) and filter mode a three-state switch (LP/BP/HP). The effect builds six MuTronIII instances (three modes x two directions) selected by a nested Select so every filter state stays warmed for click-free switching. - Presets: PedalState gains a backward-compatible switchValues array (decodes to empty for older presets); captureState/applyState persist and restore switch positions. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -11,22 +11,29 @@ import LyrebirdUI
|
||||
///
|
||||
/// Wraps the Lyrebird `MuTronIII` generator. The input amplitude drives an exponential
|
||||
/// cutoff sweep through a resonant Chamberlin state-variable filter. Because `MuTronIII`
|
||||
/// fixes its filter `mode` at `init`, three instances (lowpass, bandpass, highpass) run
|
||||
/// in parallel on the shared dry signal and a `Select` switch picks the active one from
|
||||
/// the `mode` knob — this keeps all three filter states warmed so mode changes are
|
||||
/// click-free (SuperCollider `Select` semantics: every input advances each block).
|
||||
/// 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
|
||||
/// - `mode`: Filter response. `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass.
|
||||
/// - `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 MuTronPedal: Pedal {
|
||||
|
||||
// MARK: - Parameters
|
||||
|
||||
/// Filter response selector. `0` = lowpass, `1` = bandpass, `2` = highpass.
|
||||
/// 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
|
||||
|
||||
@@ -37,9 +44,6 @@ public final class MuTronPedal: Pedal {
|
||||
|
||||
private static let defaultMix: Double = 1.0
|
||||
|
||||
/// Sweep direction is fixed to the classic "louder opens the filter" response.
|
||||
private let sweepDirection: MuTronIIISweep = .up
|
||||
|
||||
/// Cutoff at zero envelope, in Hz.
|
||||
private let freqLo: Double = 80.0
|
||||
|
||||
@@ -50,13 +54,19 @@ public final class MuTronPedal: Pedal {
|
||||
private let attackTime: Double = 0.005
|
||||
private let releaseTime: Double = 0.15
|
||||
|
||||
/// Half-step bias added before `Select`'s truncate-toward-zero index, turning the
|
||||
/// `mode` knob into a round-to-nearest 3-position switch over `[0, 2]`.
|
||||
private let modeRoundingBias: Double = 0.5
|
||||
/// 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 modeRange: ClosedRange<Double> = 0.0 ... 2.0
|
||||
private let sensitivityRange: ClosedRange<Double> = 0.0 ... 4.0
|
||||
private let resonanceRange: ClosedRange<Double> = 1.0 ... 12.0
|
||||
|
||||
@@ -64,12 +74,35 @@ public final class MuTronPedal: Pedal {
|
||||
|
||||
public override var effectKnobs: [PedalKnob] {
|
||||
[
|
||||
PedalKnob(label: "Mode", node: $mode, range: modeRange),
|
||||
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) {
|
||||
@@ -84,26 +117,43 @@ public final class MuTronPedal: Pedal {
|
||||
// MARK: - Effect
|
||||
|
||||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||
let lowpass: MuTronIII.Audio = makeFilter(dry, mode: .lowpass)
|
||||
let bandpass: MuTronIII.Audio = makeFilter(dry, mode: .bandpass)
|
||||
let highpass: MuTronIII.Audio = makeFilter(dry, mode: .highpass)
|
||||
// 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),
|
||||
]
|
||||
)
|
||||
|
||||
// Round the [0, 2] knob to the nearest integer index, then switch.
|
||||
let which: any ValidGeneratorInput = $mode + modeRoundingBias
|
||||
// Outer selector picks the sweep direction (Down = 0, Up = 1).
|
||||
let directionWhich: any ValidGeneratorInput = $direction + selectRoundingBias
|
||||
return Select.Audio(
|
||||
which: which,
|
||||
inputs: [lowpass, bandpass, highpass]
|
||||
which: directionWhich,
|
||||
inputs: [downModes, upModes]
|
||||
)
|
||||
}
|
||||
|
||||
private func makeFilter(
|
||||
_ dry: any ValidGeneratorInput,
|
||||
mode: MuTronIIIMode
|
||||
mode: MuTronIIIMode,
|
||||
direction: MuTronIIISweep
|
||||
) -> MuTronIII.Audio {
|
||||
MuTronIII.Audio(
|
||||
input: dry,
|
||||
mode: mode,
|
||||
direction: sweepDirection,
|
||||
direction: direction,
|
||||
sensitivity: $sensitivity,
|
||||
peak: $resonance,
|
||||
freqLo: freqLo,
|
||||
|
||||
Reference in New Issue
Block a user