f29ab609bd
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>
145 lines
4.8 KiB
Swift
145 lines
4.8 KiB
Swift
// SustainerPedal.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// Sustainer pedal: a one-knob compressor tuned for long, even sustain.
|
|
///
|
|
/// A single `sustain` control drives a feed-forward compressor harder as it climbs — lowering
|
|
/// the threshold, raising the ratio, and adding makeup gain together — so notes bloom and hold
|
|
/// without the user juggling threshold/ratio (that's what the `Compressor` pedal is for). A
|
|
/// `tone` low-pass rounds off the squashed top end.
|
|
///
|
|
/// Signal path (inside `effect(_:)`):
|
|
/// ```
|
|
/// dry → Compressor(threshold↓, ratio↑, makeup↑ with sustain) → RBJLowPass(tone) → wet
|
|
/// ```
|
|
///
|
|
/// The wet/dry blend and bypass are handled by the `Pedal` base class.
|
|
///
|
|
/// ## Parameters
|
|
///
|
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
|
///
|
|
/// - Parameters:
|
|
/// - sustain: Amount of sustain/compression. `0` = gentle, `10` = maximum squash and hold.
|
|
/// Range `[0, 10]`. Defaults to `5.0`.
|
|
/// - tone: Output low-pass cutoff in Hz. Range `[800, 8000]`. Defaults to `6000.0`.
|
|
public final class SustainerPedal: Pedal {
|
|
|
|
// MARK: - Parameters
|
|
|
|
/// Sustain amount in [0, 10]. Higher = more compression, makeup, and hold.
|
|
@UIParam public var sustain: Double = 5.0
|
|
|
|
/// Output low-pass cutoff in Hz. Range [800, 8000].
|
|
@UIParam public var tone: Double = 6000.0
|
|
|
|
// MARK: - Constants
|
|
|
|
private static let defaultMix: Double = 1.0
|
|
|
|
/// Compressor envelope times, in seconds — fast attack to catch picks, slow release to hold.
|
|
private let attackTime: Double = 0.005
|
|
private let releaseTime: Double = 0.4
|
|
|
|
/// Hard knee for a defined, punchy sustain.
|
|
private let kneeWidth: Double = 0.0
|
|
|
|
/// Butterworth tone low-pass (no resonant peak).
|
|
private let toneQ: Double = 0.707
|
|
|
|
/// `sustain` knob span, mapped to the compressor settings below.
|
|
private let sustainMin: Double = 0.0
|
|
private let sustainMax: Double = 10.0
|
|
|
|
/// Threshold in dB at min / max sustain (lower threshold = more of the signal compressed).
|
|
private let thresholdAtMin: Double = -6.0
|
|
private let thresholdAtMax: Double = -36.0
|
|
|
|
/// Compression ratio at min / max sustain.
|
|
private let ratioAtMin: Double = 2.0
|
|
private let ratioAtMax: Double = 10.0
|
|
|
|
/// Makeup gain in dB at min / max sustain (compensates for the added gain reduction).
|
|
private let makeupAtMin: Double = 0.0
|
|
private let makeupAtMax: Double = 18.0
|
|
|
|
// MARK: - UI knobs
|
|
|
|
private let sustainRange: ClosedRange<Double> = 0.0 ... 10.0
|
|
private let toneRange: ClosedRange<Double> = 800.0 ... 8000.0
|
|
|
|
public override var effectKnobs: [PedalKnob] {
|
|
[
|
|
PedalKnob(label: "Sustain", node: $sustain, range: sustainRange),
|
|
PedalKnob(label: "Tone", node: $tone, range: toneRange),
|
|
]
|
|
}
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a sustainer pedal.
|
|
///
|
|
/// - Parameters:
|
|
/// - inputBus: Audio bus index to read the dry input from. Defaults to `0`.
|
|
/// - outputBus: Audio bus index to write the processed output to. Defaults to `0`.
|
|
public init(
|
|
inputBus: Int = 0,
|
|
outputBus: Int = 0
|
|
) {
|
|
super.init(
|
|
name: "Sustainer",
|
|
inputBus: inputBus,
|
|
outputBus: outputBus,
|
|
initialMix: SustainerPedal.defaultMix
|
|
)
|
|
}
|
|
|
|
public override var summary: String {
|
|
"Compressor tuned for long, even sustain — one knob to make notes bloom and hold."
|
|
}
|
|
|
|
// MARK: - Effect
|
|
|
|
/// Drives a compressor from the single `sustain` knob, then rolls off the top with `tone`.
|
|
///
|
|
/// - Parameter dry: Dry mono input signal.
|
|
/// - Returns: The sustained, tone-shaped wet signal.
|
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
|
let threshold: LinLin.Audio = mapSustain(to: thresholdAtMin, thresholdAtMax)
|
|
let ratio: LinLin.Audio = mapSustain(to: ratioAtMin, ratioAtMax)
|
|
let makeup: LinLin.Audio = mapSustain(to: makeupAtMin, makeupAtMax)
|
|
|
|
let compressed: Compressor.Audio = Compressor.Audio(
|
|
in: dry,
|
|
threshold: threshold,
|
|
ratio: ratio,
|
|
attack: attackTime,
|
|
release: releaseTime,
|
|
kneeWidth: kneeWidth,
|
|
makeupGain: makeup
|
|
)
|
|
return RBJLowPass.Audio(
|
|
input: compressed,
|
|
freq: $tone,
|
|
q: toneQ
|
|
)
|
|
}
|
|
|
|
/// Maps the `sustain` knob `[sustainMin, sustainMax]` to `[outLo, outHi]`.
|
|
private func mapSustain(to outLo: Double, _ outHi: Double) -> LinLin.Audio {
|
|
LinLin.Audio(
|
|
$sustain,
|
|
inLo: sustainMin,
|
|
inHi: sustainMax,
|
|
outLo: outLo,
|
|
outHi: outHi
|
|
)
|
|
}
|
|
}
|