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>
128 lines
4.3 KiB
Swift
128 lines
4.3 KiB
Swift
// MultiTapDelayPedal.swift
|
||
// Lyrebird
|
||
//
|
||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||
// SPDX-License-Identifier: MIT
|
||
|
||
import LyrebirdSynth
|
||
import LyrebirdUI
|
||
|
||
/// Three-tap delay pedal with no feedback and an independent volume per tap.
|
||
///
|
||
/// The dry signal is split into three non-regenerating delay lines at independent times;
|
||
/// each tap's level is set by its own volume knob, and the three taps are summed into the
|
||
/// wet output. Because no tap feeds back, the result is a fixed three-echo pattern rather
|
||
/// than a decaying repeat train — useful for rhythmic slap-back groups and chords of echoes.
|
||
///
|
||
/// Signal chain (inside `effect(_:)`):
|
||
/// ```
|
||
/// dry ─┬─ DelayLine(time1) × vol1 ─┐
|
||
/// ├─ DelayLine(time2) × vol2 ─┼─ Σ → wet
|
||
/// └─ DelayLine(time3) × vol3 ─┘
|
||
/// ```
|
||
///
|
||
/// `effect` returns the summed wet signal — the base `Pedal` blends it via `mix`.
|
||
///
|
||
/// ## Knobs (two rows of three)
|
||
/// - `time1`, `time2`, `time3`: Delay time of each tap, in seconds.
|
||
/// - `vol1`, `vol2`, `vol3`: Linear output level of each tap in `[0, 1]`.
|
||
public final class MultiTapDelayPedal: Pedal {
|
||
|
||
/// One-line description shown in the picker and info panel.
|
||
public override var summary: String {
|
||
"Multi-tap delay producing rhythmic patterns of echoes."
|
||
}
|
||
|
||
// MARK: - Tap times
|
||
|
||
/// Tap 1 delay time, in seconds.
|
||
@UIParam public var time1: Double = 0.12
|
||
|
||
/// Tap 2 delay time, in seconds.
|
||
@UIParam public var time2: Double = 0.24
|
||
|
||
/// Tap 3 delay time, in seconds.
|
||
@UIParam public var time3: Double = 0.36
|
||
|
||
// MARK: - Tap volumes
|
||
|
||
/// Tap 1 linear level in [0, 1].
|
||
@UIParam public var vol1: Double = 0.8
|
||
|
||
/// Tap 2 linear level in [0, 1].
|
||
@UIParam public var vol2: Double = 0.5
|
||
|
||
/// Tap 3 linear level in [0, 1].
|
||
@UIParam public var vol3: Double = 0.3
|
||
|
||
// MARK: - Constants
|
||
|
||
/// Maximum supported per-tap delay time in seconds. Sizes each delay-line buffer at init.
|
||
private let maxDelayTime: Double = 5.0
|
||
|
||
/// Partial wet/dry blend so the dry note and its taps coexist.
|
||
private static let defaultMix: Double = 0.4
|
||
|
||
// MARK: - Ranges
|
||
|
||
private let timeRange: ClosedRange<Double> = 0.01 ... 5.0
|
||
private let volRange: ClosedRange<Double> = 0.0 ... 1.0
|
||
|
||
// MARK: - Knobs
|
||
|
||
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||
[
|
||
TempoSyncableParam(key: "time1", label: "Time 1", node: $time1, kind: .time, range: timeRange),
|
||
TempoSyncableParam(key: "time2", label: "Time 2", node: $time2, kind: .time, range: timeRange),
|
||
TempoSyncableParam(key: "time3", label: "Time 3", node: $time3, kind: .time, range: timeRange),
|
||
]
|
||
}
|
||
|
||
/// Two rows of three: the three tap times, then the three tap volumes.
|
||
public override var effectKnobs: [PedalKnob] {
|
||
[
|
||
PedalKnob(label: "Time 1", node: $time1, range: timeRange),
|
||
PedalKnob(label: "Time 2", node: $time2, range: timeRange),
|
||
PedalKnob(label: "Time 3", node: $time3, range: timeRange),
|
||
PedalKnob(label: "Vol 1", node: $vol1, range: volRange),
|
||
PedalKnob(label: "Vol 2", node: $vol2, range: volRange),
|
||
PedalKnob(label: "Vol 3", node: $vol3, range: volRange),
|
||
]
|
||
}
|
||
|
||
// MARK: - Init
|
||
|
||
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||
super.init(
|
||
name: "Multi-Tap Delay",
|
||
inputBus: inputBus,
|
||
outputBus: outputBus,
|
||
initialMix: MultiTapDelayPedal.defaultMix
|
||
)
|
||
}
|
||
|
||
// MARK: - Effect
|
||
|
||
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||
let tap1: DelayLine = makeTap(dry, delay: $time1, volume: $vol1)
|
||
let tap2: DelayLine = makeTap(dry, delay: $time2, volume: $vol2)
|
||
let tap3: DelayLine = makeTap(dry, delay: $time3, volume: $vol3)
|
||
return tap1 + tap2 + tap3
|
||
}
|
||
|
||
private func makeTap(
|
||
_ dry: any ValidGeneratorInput,
|
||
delay: any ValidGeneratorInput,
|
||
volume: any ValidGeneratorInput
|
||
) -> DelayLine {
|
||
DelayLine(
|
||
input: dry,
|
||
maxDelay: maxDelayTime,
|
||
delay: delay,
|
||
sampleRate: sampleRate,
|
||
interpolation: .linear,
|
||
mul: volume
|
||
)
|
||
}
|
||
}
|