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>
125 lines
3.9 KiB
Swift
125 lines
3.9 KiB
Swift
// PhaserPedal.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
|
|
/// Phaser pedal: cascaded all-pass filter swept by a sine LFO.
|
|
///
|
|
/// Signal chain (inside `effect(_:)`):
|
|
/// ```
|
|
/// dry → Phaser.Audio(rate:, feedback:, mix: 1.0) → mono out
|
|
/// ```
|
|
///
|
|
/// `Phaser.Audio` is mono-in / mono-out. Its internal `mix` is set to `1.0` (fully
|
|
/// wet) so the base `Pedal` class handles the dry/wet blend uniformly via its own
|
|
/// `mix` parameter.
|
|
///
|
|
/// The wet/dry mix and bypass switching are handled by the `Pedal` base class.
|
|
///
|
|
/// ## Parameters
|
|
///
|
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
|
///
|
|
/// - Parameters:
|
|
/// - rate: LFO sweep rate in Hz. Range `[0.05, 5.0]`. Defaults to `0.5`.
|
|
/// - feedback: Feedback gain in `[0, 0.9]`. Higher values deepen the notches.
|
|
/// Range `[0.0, 0.9]`. Defaults to `0.5`.
|
|
public final class PhaserPedal: Pedal {
|
|
|
|
/// One-line description shown in the picker and info panel.
|
|
public override var summary: String {
|
|
"Sweeping phase shifter for swirling, watery motion."
|
|
}
|
|
|
|
// MARK: - Parameters
|
|
|
|
/// LFO sweep rate in Hz. Range [0.05, 5.0].
|
|
@UIParam public var rate: Double = 0.5
|
|
|
|
/// Feedback gain in [0, 0.9]. Deepens the all-pass notches.
|
|
@UIParam public var feedback: Double = 0.5
|
|
|
|
// MARK: - Constants
|
|
|
|
/// Default wet/dry blend — even mix for classic phaser comb-filter sweep.
|
|
private static let defaultMix: Double = 0.5
|
|
|
|
/// Internal `Phaser.Audio` mix — set to 1.0 so the base `Pedal` handles dry/wet.
|
|
private let phaserInternalMix: Double = 1.0
|
|
|
|
/// LFO depth fraction — sweeps the all-pass coefficient across its full range.
|
|
private let phaserDepth: Double = 0.9
|
|
|
|
/// Center frequency in Hz for the all-pass coefficient sweep.
|
|
private let phaserCenterFreq: Double = 800.0
|
|
|
|
/// Number of cascaded all-pass stages. Must be 4, 6, or 8.
|
|
private let phaserStages: Int = 6
|
|
|
|
// MARK: - UI knobs
|
|
|
|
/// Rate knob range in Hz (LFO sweep frequency).
|
|
private let rateRange: ClosedRange<Double> = 0.05 ... 5.0
|
|
|
|
/// Feedback knob range (all-pass feedback gain).
|
|
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.9
|
|
|
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
|
[
|
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
|
]
|
|
}
|
|
|
|
public override var effectKnobs: [PedalKnob] {
|
|
[
|
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
|
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
|
]
|
|
}
|
|
|
|
// MARK: - Init
|
|
|
|
/// Creates a phaser 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: "Phaser",
|
|
inputBus: inputBus,
|
|
outputBus: outputBus,
|
|
initialMix: PhaserPedal.defaultMix
|
|
)
|
|
}
|
|
|
|
// MARK: - Effect
|
|
|
|
/// Applies cascaded all-pass phasing and returns the fully-wet signal.
|
|
///
|
|
/// `Phaser.Audio` is mono-in / mono-out. The base `Pedal` class mixes this with
|
|
/// the dry signal according to the `mix` parameter.
|
|
///
|
|
/// - Parameter dry: Dry mono input signal.
|
|
/// - Returns: Wet mono phaser output.
|
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
|
Phaser.Audio(
|
|
input: dry,
|
|
rate: $rate,
|
|
depth: phaserDepth,
|
|
centerFreq: phaserCenterFreq,
|
|
feedback: $feedback,
|
|
stages: phaserStages,
|
|
mix: phaserInternalMix,
|
|
sampleRate: sampleRate
|
|
)
|
|
}
|
|
}
|