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

148 lines
5.3 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.
// PingPongDelayPedal.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Stereo-native ping-pong delay: echoes bounce left → right across the stereo field.
///
/// A ``PedalChannelKind/stereoNative`` pedal — a single instance reads both input channels,
/// couples them, and writes both outputs (it cannot be expressed as two independent mono
/// pedals). When placed in a mono region the mono input broadcasts to both channels and the
/// chain widens to stereo; in a stereo region it sums the two inputs as the delay feed.
///
/// ## Signal chain (inside `stereoEffect(left:right:)`)
///
/// ```
/// feed = (left + right) · 0.5
/// leftWet = DelayLineFeedback(feed, delay: time, decayTime: feedback) // echoes at t, 2t, 3t …
/// rightWet = DelayLine(leftWet, delay: time) // L delayed one tap → t later
/// ```
///
/// The right channel is the left channel's echo train delayed by one further tap, so each
/// repeat lands first on the left, then on the right — the characteristic ping-pong bounce.
/// The cross-channel dependency (right derived from the processed left) is what makes this
/// stereo-native rather than two independent delays.
///
/// ## Parameters
///
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
///
/// - Parameters:
/// - time: Delay time per tap in seconds. Range `[0.05, 5.0]`. Defaults to `0.3`.
/// - feedback: Feedback as decay time in seconds (time for echoes to fall to −60 dB).
/// Range `[0.05, 6.0]`. Defaults to `1.2`.
public final class PingPongDelayPedal: Pedal {
/// One-line description shown in the picker and info panel.
public override var summary: String {
"Stereo ping-pong delay bouncing echoes between left and right."
}
// MARK: - Parameters
/// Delay time per tap in seconds. Range [0.05, 5.0].
@UIParam public var time: Double = 0.3
/// Feedback decay time in seconds (time to reach −60 dB amplitude). Range [0.05, 6.0].
@UIParam public var feedback: Double = 1.2
// MARK: - Constants
/// Maximum supported delay time in seconds. Sizes both delay lines at init.
private let maxDelayTime: Double = 5.0
/// Amplitude target for the `decayTime` calculation (−60 dB).
private let targetAmp: Double = 0.001
/// Gain applied when summing the two input channels into the mono delay feed.
private let feedGain: Double = 0.5
/// Default wet/dry blend — partial so dry and echoes coexist.
private static let defaultMix: Double = 0.4
// MARK: - UI knobs
/// Delay-time knob range in seconds.
private let timeRange: ClosedRange<Double> = 0.05 ... 5.0
/// Feedback (decay-time) knob range in seconds.
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
// MARK: - Channel kind
/// This pedal is stereo-native (cross-channel coupling).
public override var channelKind: PedalChannelKind { .stereoNative }
// MARK: - Init
/// Creates a ping-pong delay pedal.
///
/// - Parameters:
/// - inputBus: Audio bus index to read the left/mono input from. Defaults to `0`.
/// - outputBus: Audio bus index to write the left output to. Defaults to `0`.
public init(
inputBus: Int = 0,
outputBus: Int = 0
) {
super.init(
name: "Ping-Pong",
inputBus: inputBus,
outputBus: outputBus,
initialMix: PingPongDelayPedal.defaultMix
)
}
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),
]
}
// MARK: - Effect
/// Builds the cross-coupled ping-pong delay. The right channel is the left echo train
/// delayed by one further tap, producing the left → right bounce.
///
/// - Parameters:
/// - left: Left dry channel.
/// - right: Right dry channel (equals `left` when entering a mono region).
/// - Returns: `(left: feedback echoes, right: echoes delayed one tap)`.
public override func stereoEffect(
left: any ValidGeneratorInput,
right: any ValidGeneratorInput
) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) {
// Sum both inputs to a mono feed; a mono region passes left == right (no change).
let feed: any ValidGeneratorInput = (left + right) * feedGain
let leftWet: DelayLineFeedback = DelayLineFeedback(
input: feed,
maxDelay: maxDelayTime,
delay: $time,
decayTime: $feedback,
targetAmp: targetAmp,
sampleRate: sampleRate,
interpolation: .linear
)
// Right is the left echo train delayed one more tap → the L → R bounce.
let rightWet: DelayLine = DelayLine(
input: leftWet,
maxDelay: maxDelayTime,
delay: $time,
sampleRate: sampleRate,
interpolation: .linear
)
return (left: leftWet, right: rightWet)
}
}