Files
josh 2772abdc56 Release 2.1.0: tempo-synced pedal parameters, editable BPM, control mapping badges
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>
2026-07-10 08:47:22 -07:00

111 lines
3.6 KiB
Swift
Raw Permalink 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.
// FeedbackDelayPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Feedback (tape-style) delay pedal with multiple regenerating repeats.
///
/// Signal chain (inside `effect(_:)`):
/// ```
/// dry → DelayLineFeedback(delay: time, decayTime: feedback) → RBJLowPass(tone) → wet
/// ```
///
/// The feedback path regenerates the echo so a single note produces a train of repeats
/// that decays over `feedback` seconds. A `Tone` lowpass darkens the wet signal for the
/// warm, rolled-off character of a tape echo (cubic interpolation adds the same smear).
/// `effect` returns the pure wet signal — the base `Pedal` blends it via `mix`.
///
/// ## Knobs
/// - `time`: Delay time between repeats, in seconds.
/// - `feedback`: Repeat decay time in seconds — how long the echoes regenerate before
/// falling to −60 dB. Longer values produce more audible repeats.
/// - `tone`: Lowpass cutoff in Hz applied to the wet signal; lower darkens the echoes.
public final class FeedbackDelayPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Feedback delay with a tone-shaped repeat for dub-style echoes."
}
// MARK: - Parameters
/// Delay time between repeats, in seconds.
@UIParam public var time: Double = 0.3
/// Repeat decay time in seconds (time for echoes to reach −60 dB). Longer = more repeats.
@UIParam public var feedback: Double = 2.5
/// Tone (lowpass) cutoff in Hz applied to the wet echoes.
@UIParam public var tone: Double = 4000.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
/// Butterworth Q for the tone lowpass (no resonant peak).
private let toneQ: Double = 0.707
/// Partial wet/dry blend so the dry note and its echoes coexist.
private static let defaultMix: Double = 0.35
// MARK: - Ranges
private let timeRange: ClosedRange<Double> = 0.02 ... 5.0
private let feedbackRange: ClosedRange<Double> = 0.1 ... 8.0
private let toneRange: ClosedRange<Double> = 500.0 ... 8000.0
// MARK: - Knobs
public override var tempoSyncableParams: [TempoSyncableParam] {
[
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
]
}
public override var effectKnobs: [PedalKnob] {
[
PedalKnob(label: "Time", node: $time, range: timeRange),
PedalKnob(label: "Decay Time", node: $feedback, range: feedbackRange),
PedalKnob(label: "Tone", node: $tone, range: toneRange),
]
}
// MARK: - Init
public init(inputBus: Int = 0, outputBus: Int = 0) {
super.init(
name: "Feedback Delay",
inputBus: inputBus,
outputBus: outputBus,
initialMix: FeedbackDelayPedal.defaultMix
)
}
// MARK: - Effect
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
let echoes: DelayLineFeedback = DelayLineFeedback(
input: dry,
maxDelay: maxDelayTime,
delay: $time,
decayTime: $feedback,
targetAmp: targetAmp,
sampleRate: sampleRate,
interpolation: .cubic
)
return RBJLowPass.Audio(
input: echoes,
freq: $tone,
q: toneQ
)
}
}