2772abdc56
Tempo sync - Lock a delay time or modulation LFO rate to a note division (whole..sixteenth, dotted, triplet) of the shared clock. Value is derived from the tempo and follows tap tempo, the stepper, the editable BPM field, and MIDI. - Delay time: Delay, FeedbackDelay, PingPong, ReverseDelay, MultiTap (per tap). LFO rate (inverse mapping): Tremolo, Vibrato, Chorus, Flanger, Phaser, Modulation. - Core types NoteDivision / TempoSync / TempoSyncableParam; Pedal.tempoSyncableParams / tempoSync / applyTempoSync / setSync; ShoeGaze.setBpm broadcast recomputes all pedals; tempoSync persisted in PedalState (lenient decode) and recomputed on load + recall. - Observable TempoSyncRevision so the sync badge refreshes on any state-change path. UI - Division picker with drawn music-notation glyphs (NoteGlyphView + rasterized cache): noteheads, stems, flags, augmentation dot, bracketed 3 for triplets. Presented as a height-capped popover so it stays on-screen on iOS. - Editable BPM text field: integer-only, live-filtered, clamped 30-300, commit on return / Done / blur. - Divisions that clamp at the current tempo are disabled in the picker; an active clamped sync shows a warning marker. - In-context control mapping badges (PC / CC / KEY) per pedal control, with a legend. Delays - Maximum delay time raised to 5 s across the delay pedals (was 1-2 s). Docs: CHANGELOG.md, RELEASES.md, docs/plans/2.2-tempo-synced-parameters.md. All 454 tests pass; passed lyrebird_external_review (RT-safe, main-thread param writes). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
122 lines
4.1 KiB
Swift
122 lines
4.1 KiB
Swift
// TremoloPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Tremolo pedal: amplitude modulation via a unipolar sine LFO.
|
||
///
|
||
/// Signal chain (inside `effect(_:)`):
|
||
/// ```
|
||
/// dry × OscSin(freq: rate, mul: depth×0.5, add: 1−depth×0.5) → mono out
|
||
/// ```
|
||
///
|
||
/// The LFO oscillates between `[1 − depth, 1]` so full depth produces silence-to-unity
|
||
/// swells while zero depth leaves the signal unmodified. The result is a gain effect —
|
||
/// `defaultMix` is `1.0` (fully wet) so the base `Pedal` passes the tremolo signal through
|
||
/// unchanged; the `mix` knob can soften the wobble effect.
|
||
///
|
||
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
||
///
|
||
/// ## Parameters
|
||
///
|
||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||
///
|
||
/// - Parameters:
|
||
/// - rate: LFO modulation rate in Hz. Range `[0.5, 12]`. Defaults to `4.0`.
|
||
/// - depth: Modulation depth in `[0, 1]`. `0` = no modulation, `1` = full tremolo.
|
||
/// Defaults to `0.7`.
|
||
public final class TremoloPedal: Pedal {
|
||
|
||
/// One-line description shown in the picker and info panel.
|
||
public override var summary: String {
|
||
"Rhythmic volume modulation, from a gentle throb to choppy stutter."
|
||
}
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// LFO rate in Hz. Range [0.5, 12].
|
||
@UIParam public var rate: Double = 4.0
|
||
|
||
/// Modulation depth in [0, 1].
|
||
@UIParam public var depth: Double = 0.7
|
||
|
||
// MARK: - Constants
|
||
|
||
/// Default wet/dry blend — fully wet; tremolo is a gain effect so dry/wet
|
||
/// blending does not apply in the same way as a parallel effect.
|
||
private static let defaultMix: Double = 1.0
|
||
|
||
/// Scale factor applied to `depth` to compute the LFO half-amplitude swing.
|
||
/// At full depth the LFO oscillates over half the normalised range, so the
|
||
/// peak gain is 1.0 and the trough is `1 − depth`.
|
||
private let lfoDepthScale: Double = 0.5
|
||
|
||
// MARK: - UI knobs
|
||
|
||
/// Rate knob range in Hz (LFO frequency).
|
||
private let rateRange: ClosedRange<Double> = 0.5 ... 12.0
|
||
|
||
/// Depth knob range (modulation fraction).
|
||
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
|
||
|
||
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||
[
|
||
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||
]
|
||
}
|
||
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||
PedalKnob(label: "Depth", node: $depth, range: depthRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a tremolo 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: "Tremolo",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: TremoloPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
/// Multiplies the dry signal by a unipolar sine LFO.
|
||
///
|
||
/// The LFO range is `[1 − depth, 1]`. At `depth = 0` the multiplier is constant 1.0;
|
||
/// at `depth = 1` it swings between `0.0` and `1.0`.
|
||
///
|
||
/// Output is mono.
|
||
///
|
||
/// - Parameter dry: Dry mono input signal.
|
||
/// - Returns: Amplitude-modulated mono output.
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
// lfoScale = depth × lfoDepthScale → LFO swing half-amplitude
|
||
// lfoOffset = 1 − depth × lfoDepthScale → LFO centre, so peak = 1.0, trough = 1 − depth
|
||
let lfoScale: any ValidGeneratorInput = $depth * lfoDepthScale
|
||
let lfoOffset: any ValidGeneratorInput = 1.0 - ($depth * lfoDepthScale)
|
||
let lfo: OscSin.Audio = OscSin.Audio(
|
||
freq: $rate,
|
||
mul: lfoScale,
|
||
add: lfoOffset
|
||
)
|
||
return dry * lfo
|
||
}
|
||
}
|