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>
115 lines
3.6 KiB
Swift
115 lines
3.6 KiB
Swift
// DelayPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Delay pedal: feedback delay line.
|
||
///
|
||
/// Signal chain (inside `effect(_:)`):
|
||
/// ```
|
||
/// dry → DelayLineFeedback(delay: time, decayTime: feedback) → mono wet out
|
||
/// ```
|
||
///
|
||
/// `effect` returns the pure wet delay signal. The base `Pedal` class handles
|
||
/// wet/dry blending via `mix`, so do not pre-blend inside `effect`.
|
||
///
|
||
/// ## Parameters
|
||
///
|
||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||
///
|
||
/// - Parameters:
|
||
/// - time: Delay time in seconds. Range `[0.01, 5.0]`. Defaults to `0.25`.
|
||
/// - feedback: Feedback amount expressed as decay time in seconds — the time
|
||
/// for echoes to fall to `targetAmp` (−60 dB). Longer values produce more
|
||
/// repeats. Range `[0.05, 6.0]` seconds. Defaults to `1.0`.
|
||
public final class DelayPedal: Pedal {
|
||
|
||
/// One-line description shown in the picker and info panel.
|
||
public override var summary: String {
|
||
"Echo delay with adjustable time and decay, from slapback to long repeats."
|
||
}
|
||
|
||
// MARK: - Parameters
|
||
|
||
/// Delay time in seconds. Range [0.01, 5.0].
|
||
@UIParam public var time: Double = 0.25
|
||
|
||
/// Feedback decay time in seconds (time to reach −60 dB amplitude).
|
||
@UIParam public var feedback: Double = 1.0
|
||
|
||
// MARK: - Constants
|
||
|
||
/// Maximum supported delay time in seconds. Sizes the delay line buffer at init.
|
||
private let maxDelayTime: Double = 5.0
|
||
|
||
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
||
private let targetAmp: Double = 0.001
|
||
|
||
/// Default wet/dry blend — a partial mix so dry signal and echoes coexist.
|
||
private static let defaultMix: Double = 0.35
|
||
|
||
// MARK: - UI knobs
|
||
|
||
/// Delay-time knob range in seconds.
|
||
private let timeRange: ClosedRange<Double> = 0.01 ... 5.0
|
||
|
||
/// Feedback (decay-time) knob range in seconds.
|
||
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
||
|
||
// MARK: - Init
|
||
|
||
/// Creates a delay 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: "Delay",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: DelayPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
|
||
]
|
||
}
|
||
|
||
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||
[
|
||
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
/// Applies a feedback delay line. Returns the pure wet (delayed) signal.
|
||
///
|
||
/// The base class `Pedal` mixes this with the dry signal via the `mix` parameter.
|
||
///
|
||
/// - Parameter dry: Dry mono input signal.
|
||
/// - Returns: Pure wet mono delayed output.
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
DelayLineFeedback(
|
||
input: dry,
|
||
maxDelay: maxDelayTime,
|
||
delay: $time,
|
||
decayTime: $feedback,
|
||
targetAmp: targetAmp,
|
||
sampleRate: sampleRate,
|
||
interpolation: .linear
|
||
)
|
||
}
|
||
}
|