Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/MagnaVibratoAmpPedal.swift
T
josh 292261a088 refactor(ui): make widthUnits mean "base width in columns" + tidy overrides
Follow-up cleanup now that card width is content-derived. Redefine widthUnits
as the card's base width in knob columns (1 = 3-wide, 2 = 4-wide) — both the
knob-grid column count and the card's minimum width — with selector/switch rows
able to push wider. Values above 2 no longer do anything.

- Delete the now-misleading widthUnits 3/4 overrides on 11 amps; they inherit
  AmpVoicePedal's 2 (all full-surface amps → the same tight 4-wide card).
- Remove Mutant's redundant override (2 knobs + 2 switches → 3-wide either way).
- Cabinet: keep widthUnits 2 so it's 4-wide like the amps — its Cab/Mic/Mic B
  selector captions (voice names) need the room to stay readable (per request).
- Looper keeps widthUnits 3 (the one pedal still using the flat multiple for its
  bespoke timeline/knobs/transport layout).
- Refresh the widthUnits docs (base + AmpVoicePedal + Cabinet); update the amp
  tests' widthUnits assertions (3/4 → 2; Looper stays 3).

675 tests pass; no visual change to the amps, Cabinet now matches their width.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 09:05:40 -07:00

86 lines
3.6 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.
// MagnaVibratoAmpPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// American clean combo with **true pitch vibrato** — the Magnatone voice: a genuine
/// frequency-modulation warble (a swept delay line), not the amplitude-modulation "vibrato" other
/// amps label as such.
///
/// A ``AmpVoicePedal`` (`.fender`) whose onboard effect is a delay line whose read position is swept
/// by an LFO — modulating pitch. `Depth` scales the sweep, `Speed` its rate, and a Vibrato
/// footswitch bypasses it (a fixed short delay, no warble).
public final class MagnaVibratoAmpPedal: AmpVoicePedal {
/// Vibrato LFO rate in Hz. Range [0.5, 12].
@UIParam public var speed: Double = 5.0
/// Vibrato depth in [0, 1] → 0…±`maxSweepSeconds` of delay-time sweep around the base delay
/// (the LFO is bipolar, so the delay swings both above and below `baseDelaySeconds`).
@UIParam public var depth: Double = 0.3
/// Vibrato footswitch: `1` = engaged, `0` = bypassed (`Speed`/`Depth` preserved).
@UIParam public var vibratoEnabled: Double = 1.0
/// Base delay time (the centre the LFO sweeps around), in seconds.
private let baseDelaySeconds: Double = 0.005
/// Maximum ± sweep at full depth, in seconds.
private let maxSweepSeconds: Double = 0.002
/// Delay-line capacity — must exceed base + max sweep.
private let maxDelaySeconds: Double = 0.010
private let speedRange: ClosedRange<Double> = 0.5 ... 12.0
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
public override var toneStackModel: ToneStackModel { .fender }
public override var summaryText: String {
"American clean combo with true pitch vibrato (a swept delay, not tremolo)."
}
public override var signatureKnobs: [PedalKnob] {
[
PedalKnob(label: "Speed", node: $speed, range: speedRange),
PedalKnob(label: "Depth", node: $depth, range: depthRange),
]
}
public override var effectSwitches: [PedalSwitch] {
[
PedalSwitch(
label: "Vibrato",
node: $vibratoEnabled,
options: [
PedalSwitch.Option(title: "Off", value: switchOffValue),
PedalSwitch.Option(title: "On", value: switchOnValue),
]
),
]
}
/// Creates a Magna Vibrato amp.
///
/// - 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: "Magna Vibrato", inputBus: inputBus, outputBus: outputBus)
gain = 5.08 // clean platform for the vibrato
cab = 0.0 // American 1×12
}
/// True pitch vibrato: a delay line whose delay time is swept by a sine LFO. The footswitch
/// gates the sweep to zero (a fixed base delay, no warble) while keeping Speed/Depth.
public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput {
let sweepSeconds: any ValidGeneratorInput = ($depth * $vibratoEnabled) * maxSweepSeconds
let delayTime: OscSin.Audio = OscSin.Audio(
freq: $speed, mul: sweepSeconds, add: baseDelaySeconds)
return DelayLine(
input: signal,
maxDelay: maxDelaySeconds,
delay: delayTime,
sampleRate: sampleRate,
interpolation: .linear
)
}
}