Files
ShoeGaze/Sources/LyrebirdShoeGaze/Pedals/MultiTapDelayPedal.swift
T
josh f29ab609bd Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI
Pedals (each registered, with PedalType static, enclosure color, palette order,
summary, and tests):
- Chorus: true-stereo widener (two anti-phase modulated delay lines), distinct
  from the mono-summed Modulation chorus.
- Sustainer: one-knob compressor (sustain drives threshold/ratio/makeup via
  LinLin) + tone low-pass.
- Ring Modulator: dry × tunable sine carrier.

Pedal-info UI:
- Pedal.summary (open var, overridden by all 21 pedals; mandatory going forward).
- PedalRegistry.summary(for:) for the picker.
- PedalPaletteView rows show the summary as a subtitle.
- PedalView gains an ⓘ button → PedalInfoView sheet showing the description and
  the effect controls (knobs/sliders/switches) with ranges/options — excludes
  the common Mix/Level/bypass.

Tests: per-pedal build/param-change/knob-list; every built-in pedal has a
non-empty summary; info excludes common controls. 183 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-26 18:05:30 -07:00

120 lines
3.9 KiB
Swift
Raw 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.
// 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 = 1.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 ... 1.0
private let volRange: ClosedRange<Double> = 0.0 ... 1.0
// MARK: - Knobs
/// 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
)
}
}