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>
136 lines
4.2 KiB
Swift
136 lines
4.2 KiB
Swift
// ChorusPedal.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// True-stereo chorus pedal.
|
|
///
|
|
/// Two modulated delay lines, fed the same dry signal but driven by sine LFOs 180° apart,
|
|
/// produce a wide left/right shimmer. Unlike `ModulationPedal` (which sums Lyrebird's
|
|
/// `Chorus` to mono), this pedal is a ``PedalChannelKind/widener`` — it keeps the two voices
|
|
/// on separate channels for genuine stereo width.
|
|
///
|
|
/// Signal path (per channel, inside `wideEffect(_:)`):
|
|
/// ```
|
|
/// dry → DelayLine(delay: base ± depth·sin(rate)) → wet L / wet R
|
|
/// ```
|
|
///
|
|
/// The wet/dry blend and bypass are handled by the `Pedal` base class.
|
|
///
|
|
/// ## Parameters
|
|
///
|
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
|
///
|
|
/// - Parameters:
|
|
/// - rate: LFO rate in Hz. Range `[0.05, 6]`. Defaults to `0.8`.
|
|
/// - depth: Delay-sweep depth in seconds (half-swing around the base delay). Range
|
|
/// `[0.0005, 0.008]`. Defaults to `0.003`.
|
|
public final class ChorusPedal: Pedal {
|
|
|
|
// MARK: - Parameters
|
|
|
|
/// LFO rate in Hz. Range [0.05, 6].
|
|
@UIParam public var rate: Double = 0.8
|
|
|
|
/// Delay-sweep depth in seconds. Range [0.0005, 0.008].
|
|
@UIParam public var depth: Double = 0.003
|
|
|
|
// MARK: - Constants
|
|
|
|
/// Default wet/dry blend — chorus sits under the dry signal.
|
|
private static let defaultMix: Double = 0.5
|
|
|
|
/// Base delay around which the LFO sweeps, in seconds.
|
|
private let baseDelayTime: Double = 0.012
|
|
|
|
/// Maximum delay the lines are allocated for, in seconds. Covers `baseDelayTime + max depth`.
|
|
private let maxDelayTime: Double = 0.03
|
|
|
|
/// LFO phase for the left voice, in cycles.
|
|
private let leftPhase: Double = 0.0
|
|
|
|
/// LFO phase for the right voice, in cycles — a half cycle (180°) opposite the left.
|
|
private let rightPhase: Double = 0.5
|
|
|
|
// MARK: - UI knobs
|
|
|
|
private let rateRange: ClosedRange<Double> = 0.05 ... 6.0
|
|
private let depthRange: ClosedRange<Double> = 0.0005 ... 0.008
|
|
|
|
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: - Channel topology
|
|
|
|
public override var channelKind: PedalChannelKind { .widener }
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a stereo chorus 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: "Chorus",
|
|
inputBus: inputBus,
|
|
outputBus: outputBus,
|
|
initialMix: ChorusPedal.defaultMix
|
|
)
|
|
}
|
|
|
|
public override var summary: String {
|
|
"Lush stereo chorus: two detuned voices panned wide for shimmer and depth."
|
|
}
|
|
|
|
// MARK: - Effect
|
|
|
|
/// Builds one modulated delay line per channel, with the two LFOs in anti-phase.
|
|
///
|
|
/// - Parameter dry: Dry mono input signal.
|
|
/// - Returns: The left and right wet voices.
|
|
public override func wideEffect(
|
|
_ dry: any ValidGeneratorInput
|
|
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
|
|
(voice(dry, phase: leftPhase), voice(dry, phase: rightPhase))
|
|
}
|
|
|
|
/// One chorus voice: a delay line whose time is swept by a sine LFO around `baseDelayTime`.
|
|
private func voice(
|
|
_ dry: any ValidGeneratorInput,
|
|
phase: Double
|
|
) -> any ValidGeneratorInput {
|
|
let sweep: OscSin.Audio = OscSin.Audio(
|
|
freq: $rate,
|
|
phase: phase,
|
|
mul: $depth,
|
|
add: baseDelayTime
|
|
)
|
|
return DelayLine(
|
|
input: dry,
|
|
maxDelay: maxDelayTime,
|
|
delay: sweep,
|
|
sampleRate: sampleRate,
|
|
interpolation: .linear
|
|
)
|
|
}
|
|
}
|