From f29ab609bdef49baa6eaac05be0c6cf48f5bbf93 Mon Sep 17 00:00:00 2001 From: Joshua Parmenter Date: Fri, 26 Jun 2026 17:55:16 -0700 Subject: [PATCH] Add Chorus, Sustainer, Ring Modulator pedals + pedal-info UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../ShoeGazeBuilder.xcodeproj/project.pbxproj | 8 +- README.md | 6 +- Sources/LyrebirdShoeGaze/Pedal.swift | 11 ++ Sources/LyrebirdShoeGaze/PedalType.swift | 5 + .../Pedals/AutoWahPedal.swift | 5 + .../Pedals/BassOctaverPedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/ChorusPedal.swift | 129 ++++++++++++++++ .../Pedals/CompressorPedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/DelayPedal.swift | 5 + .../Pedals/FeedbackDelayPedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/FuzzPedal.swift | 5 + .../Pedals/GraphicEQPedal.swift | 5 + .../Pedals/LimiterPedal.swift | 5 + .../Pedals/ModulationPedal.swift | 5 + .../Pedals/MultiTapDelayPedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/MutantPedal.swift | 5 + .../Pedals/NoiseGatePedal.swift | 5 + .../Pedals/OctaveUpSplitterPedal.swift | 5 + .../Pedals/OverdrivePedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/PhaserPedal.swift | 5 + .../Pedals/PingPongDelayPedal.swift | 5 + .../LyrebirdShoeGaze/Pedals/ReverbPedal.swift | 5 + .../Pedals/RingModulatorPedal.swift | 84 ++++++++++ .../Pedals/SustainerPedal.swift | 144 ++++++++++++++++++ .../Pedals/TremoloPedal.swift | 5 + .../Presets/PedalRegistry.swift | 16 ++ .../LyrebirdShoeGazeUI/PedalInfoView.swift | 129 ++++++++++++++++ .../LyrebirdShoeGazeUI/PedalPaletteView.swift | 41 +++-- Sources/LyrebirdShoeGazeUI/PedalView.swift | 26 +++- .../ChorusPedalTests.swift | 131 ++++++++++++++++ .../PedalInfoTests.swift | 43 ++++++ .../RingModulatorPedalTests.swift | 58 +++++++ .../SustainerPedalTests.swift | 64 ++++++++ 33 files changed, 964 insertions(+), 21 deletions(-) create mode 100644 Sources/LyrebirdShoeGaze/Pedals/ChorusPedal.swift create mode 100644 Sources/LyrebirdShoeGaze/Pedals/RingModulatorPedal.swift create mode 100644 Sources/LyrebirdShoeGaze/Pedals/SustainerPedal.swift create mode 100644 Sources/LyrebirdShoeGazeUI/PedalInfoView.swift create mode 100644 Tests/LyrebirdShoeGazeTests/ChorusPedalTests.swift create mode 100644 Tests/LyrebirdShoeGazeTests/PedalInfoTests.swift create mode 100644 Tests/LyrebirdShoeGazeTests/RingModulatorPedalTests.swift create mode 100644 Tests/LyrebirdShoeGazeTests/SustainerPedalTests.swift diff --git a/Demo/ShoeGazeBuilder.xcodeproj/project.pbxproj b/Demo/ShoeGazeBuilder.xcodeproj/project.pbxproj index e20f391..9808f45 100644 --- a/Demo/ShoeGazeBuilder.xcodeproj/project.pbxproj +++ b/Demo/ShoeGazeBuilder.xcodeproj/project.pbxproj @@ -163,7 +163,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = HE5VJFE9E4; @@ -176,7 +176,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 15.0; - MARKETING_VERSION = 0.91; + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; @@ -194,7 +194,7 @@ "CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 3; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = HE5VJFE9E4; ENABLE_HARDENED_RUNTIME = YES; @@ -206,7 +206,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 15.0; - MARKETING_VERSION = 0.91; + MARKETING_VERSION = 1.0; PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; diff --git a/README.md b/README.md index 4abba55..b724d04 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ signal (no hardware needed) or on live guitar through an audio input. ## Features -- **18 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and +- **21 modeled pedals** across drive, dynamics, EQ/filter, modulation, delay/reverb, and pitch — see the catalog below. - **Multi-board rigs** — build several boards and a board-mixer bar to **Solo** one (amp-channel style) or **Blend** any subset, each with its own level and a click-free crossfade. @@ -28,9 +28,9 @@ signal (no hardware needed) or on live guitar through an audio input. | Category | Pedals | |---|---| -| Drive & dynamics | Overdrive, Fuzz, Compressor, Limiter, Noise Gate | +| Drive & dynamics | Overdrive, Fuzz, Compressor, Sustainer, Limiter, Noise Gate | | EQ & filter | Graphic EQ, Auto-Wah, Mutant, Phaser | -| Modulation | Tremolo, Modulation | +| Modulation | Tremolo, Modulation, Chorus, Ring Modulator | | Delay & reverb | Delay, Feedback Delay, Multi-Tap Delay, Ping-Pong, Reverb | | Pitch & octave | Octave Splitter, Bass Octaver | diff --git a/Sources/LyrebirdShoeGaze/Pedal.swift b/Sources/LyrebirdShoeGaze/Pedal.swift index ca97d34..fac8272 100644 --- a/Sources/LyrebirdShoeGaze/Pedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedal.swift @@ -128,6 +128,17 @@ open class Pedal: SynthesizerBase { self.mix = initialMix } + // MARK: - Description + + /// One-line, user-facing description of what this pedal does. + /// + /// Shown as a subtitle in the pedal picker and as the body of the pedal's info panel. + /// **Every pedal must override this** with a short, non-proprietary sentence — the empty + /// default is a placeholder only (a test asserts every registered pedal sets it). + open var summary: String { + "" + } + // MARK: - UI knob descriptors /// Effect-specific knobs for this pedal, listed before the common knobs in the UI. diff --git a/Sources/LyrebirdShoeGaze/PedalType.swift b/Sources/LyrebirdShoeGaze/PedalType.swift index f410259..4d39035 100644 --- a/Sources/LyrebirdShoeGaze/PedalType.swift +++ b/Sources/LyrebirdShoeGaze/PedalType.swift @@ -59,6 +59,11 @@ public extension PedalType { // Modulation static let tremolo = PedalType("Tremolo") static let modulation = PedalType("Modulation") + static let chorus = PedalType("Chorus") + static let ringModulator = PedalType("Ring Modulator") + + // Dynamics (additional) + static let sustainer = PedalType("Sustainer") // Delay & reverb static let delay = PedalType("Delay") diff --git a/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift index c8e6928..bfdacc9 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/AutoWahPedal.swift @@ -27,6 +27,11 @@ import LyrebirdUI /// - `range`: Upper cutoff in Hz reached at full envelope. Sets the sweep span over `freqLo`. public final class AutoWahPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Touch-sensitive wah that sweeps a resonant filter from your playing dynamics." + } + // MARK: - Parameters /// Envelope drive into the cutoff sweep. Higher values open the filter on quieter input. diff --git a/Sources/LyrebirdShoeGaze/Pedals/BassOctaverPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/BassOctaverPedal.swift index f084fae..76124d9 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/BassOctaverPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/BassOctaverPedal.swift @@ -35,6 +35,11 @@ import LyrebirdUI /// - `mode` (two-state): `0` = Flip-flop (authentic OC-2), `1` = Tracking (pitch-tracked). public final class BassOctaverPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Adds a sub-octave below your note for bass-like weight." + } + // MARK: - Parameters /// −1 octave voice level in `[0, 1]`. diff --git a/Sources/LyrebirdShoeGaze/Pedals/ChorusPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/ChorusPedal.swift new file mode 100644 index 0000000..68b5060 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/ChorusPedal.swift @@ -0,0 +1,129 @@ +// ChorusPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// True-stereo chorus pedal. +/// +/// Two modulated delay lines, fed the same dry signal but driven by sine LFOs 180° apart, +/// produce a wide left/right shimmer. Unlike `ModulationPedal` (which sums Lyrebird's +/// `Chorus` to mono), this pedal is a ``PedalChannelKind/widener`` — it keeps the two voices +/// on separate channels for genuine stereo width. +/// +/// Signal path (per channel, inside `wideEffect(_:)`): +/// ``` +/// dry → DelayLine(delay: base ± depth·sin(rate)) → wet L / wet R +/// ``` +/// +/// The wet/dry blend and bypass are handled by the `Pedal` base class. +/// +/// ## Parameters +/// +/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: +/// +/// - Parameters: +/// - rate: LFO rate in Hz. Range `[0.05, 6]`. Defaults to `0.8`. +/// - depth: Delay-sweep depth in seconds (half-swing around the base delay). Range +/// `[0.0005, 0.008]`. Defaults to `0.003`. +public final class ChorusPedal: Pedal { + + // MARK: - Parameters + + /// LFO rate in Hz. Range [0.05, 6]. + @UIParam public var rate: Double = 0.8 + + /// Delay-sweep depth in seconds. Range [0.0005, 0.008]. + @UIParam public var depth: Double = 0.003 + + // MARK: - Constants + + /// Default wet/dry blend — chorus sits under the dry signal. + private static let defaultMix: Double = 0.5 + + /// Base delay around which the LFO sweeps, in seconds. + private let baseDelayTime: Double = 0.012 + + /// Maximum delay the lines are allocated for, in seconds. Covers `baseDelayTime + max depth`. + private let maxDelayTime: Double = 0.03 + + /// LFO phase for the left voice, in cycles. + private let leftPhase: Double = 0.0 + + /// LFO phase for the right voice, in cycles — a half cycle (180°) opposite the left. + private let rightPhase: Double = 0.5 + + // MARK: - UI knobs + + private let rateRange: ClosedRange = 0.05 ... 6.0 + private let depthRange: ClosedRange = 0.0005 ... 0.008 + + public override var effectKnobs: [PedalKnob] { + [ + PedalKnob(label: "Rate", node: $rate, range: rateRange), + PedalKnob(label: "Depth", node: $depth, range: depthRange), + ] + } + + // MARK: - Channel topology + + public override var channelKind: PedalChannelKind { .widener } + + // MARK: - Init + + /// Creates a stereo chorus 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: "Chorus", + inputBus: inputBus, + outputBus: outputBus, + initialMix: ChorusPedal.defaultMix + ) + } + + public override var summary: String { + "Lush stereo chorus: two detuned voices panned wide for shimmer and depth." + } + + // MARK: - Effect + + /// Builds one modulated delay line per channel, with the two LFOs in anti-phase. + /// + /// - Parameter dry: Dry mono input signal. + /// - Returns: The left and right wet voices. + public override func wideEffect( + _ dry: any ValidGeneratorInput + ) -> (left: any ValidGeneratorInput, right: any ValidGeneratorInput) { + (voice(dry, phase: leftPhase), voice(dry, phase: rightPhase)) + } + + /// One chorus voice: a delay line whose time is swept by a sine LFO around `baseDelayTime`. + private func voice( + _ dry: any ValidGeneratorInput, + phase: Double + ) -> any ValidGeneratorInput { + let sweep: OscSin.Audio = OscSin.Audio( + freq: $rate, + phase: phase, + mul: $depth, + add: baseDelayTime + ) + return DelayLine( + input: dry, + maxDelay: maxDelayTime, + delay: sweep, + sampleRate: sampleRate, + interpolation: .linear + ) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/CompressorPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/CompressorPedal.swift index 8ad6577..feb0d3e 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/CompressorPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/CompressorPedal.swift @@ -34,6 +34,11 @@ import LyrebirdUI /// Range `[1, 20]`. Defaults to `4.0`. public final class CompressorPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Feed-forward compressor that evens out dynamics, with a pre-gain input stage." + } + // MARK: - Parameters /// Pre-compression input gain in dB. Range [-12, 24]. `0` = unity. diff --git a/Sources/LyrebirdShoeGaze/Pedals/DelayPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/DelayPedal.swift index acb777c..146ae83 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/DelayPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/DelayPedal.swift @@ -28,6 +28,11 @@ import LyrebirdUI /// repeats. Range `[0.05, 6.0]` seconds. Defaults to `1.0`. public final class DelayPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Echo delay with adjustable time and decay, from slapback to long repeats." + } + // MARK: - Parameters /// Delay time in seconds. Range [0.01, 1.5]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift index 70f7234..63f9126 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/FeedbackDelayPedal.swift @@ -26,6 +26,11 @@ import LyrebirdUI /// - `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. diff --git a/Sources/LyrebirdShoeGaze/Pedals/FuzzPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/FuzzPedal.swift index e46841c..4810e8e 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/FuzzPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/FuzzPedal.swift @@ -36,6 +36,11 @@ import LyrebirdUI /// Range `[200, 8000]` Hz. Defaults to `3500.0`. public final class FuzzPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Thick, saturated fuzz for aggressive, sustaining distortion." + } + // MARK: - Parameters /// Pre-gain drive into the saturator. Range [1, 60]; higher = more fuzz. diff --git a/Sources/LyrebirdShoeGaze/Pedals/GraphicEQPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/GraphicEQPedal.swift index 70f8a9d..0746219 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/GraphicEQPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/GraphicEQPedal.swift @@ -39,6 +39,11 @@ import LyrebirdUI /// Defaults to `0.0`. public final class GraphicEQPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Five-band graphic EQ with per-band faders and a master output level." + } + // MARK: - Parameters /// Low-shelf gain in dB. Range [-12, 12]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/LimiterPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/LimiterPedal.swift index 8e9210d..abf8793 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/LimiterPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/LimiterPedal.swift @@ -31,6 +31,11 @@ import LyrebirdUI /// never exceeds this absolute value. Range `[0.1, 1.0]`. Defaults to `0.95`. public final class LimiterPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Brick-wall limiter with an input boost to push level safely to the ceiling." + } + // MARK: - Parameters /// Pre-limit input gain (linear multiplier). Range [1, 12]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/ModulationPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/ModulationPedal.swift index 042ec9f..7c67c94 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/ModulationPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/ModulationPedal.swift @@ -32,6 +32,11 @@ import LyrebirdUI /// Smaller values (0.001–0.01) produce classic chorus width. Defaults to `0.002`. public final class ModulationPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Classic mono chorus for subtle thickening and shimmer." + } + // MARK: - Parameters /// Chorus LFO rate in Hz. Range [0.1, 10]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/MultiTapDelayPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/MultiTapDelayPedal.swift index e27959f..8ab5592 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/MultiTapDelayPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/MultiTapDelayPedal.swift @@ -28,6 +28,11 @@ import LyrebirdUI /// - `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. diff --git a/Sources/LyrebirdShoeGaze/Pedals/MutantPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/MutantPedal.swift index c4eb1b0..21487a7 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/MutantPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/MutantPedal.swift @@ -26,6 +26,11 @@ import LyrebirdUI /// - `mode` (three-state): `0` = lowpass, `1` = bandpass (classic vowel wah), `2` = highpass. public final class MutantPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Envelope-following auto-wah / funk filter that opens with your picking." + } + // MARK: - Parameters /// Filter response selector. `0` = lowpass, `1` = bandpass, `2` = highpass. Driven by a three-state switch. diff --git a/Sources/LyrebirdShoeGaze/Pedals/NoiseGatePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/NoiseGatePedal.swift index 5737135..03f493d 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/NoiseGatePedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/NoiseGatePedal.swift @@ -37,6 +37,11 @@ import LyrebirdUI /// mute, `1` = no gating. Range `[0, 1]`. Defaults to `0.0`. public final class NoiseGatePedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Noise gate that silences hiss and hum below a tunable threshold." + } + // MARK: - Parameters /// Gate close threshold (linear amplitude). Range [0, 0.2]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/OctaveUpSplitterPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/OctaveUpSplitterPedal.swift index 69def72..667543a 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/OctaveUpSplitterPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/OctaveUpSplitterPedal.swift @@ -31,6 +31,11 @@ import LyrebirdUI /// - tone: Octave-channel low-pass cutoff in Hz. Range `[500, 8000]`. Defaults to `4000.0`. public final class OctaveUpSplitterPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Splits a clean octave-up voice alongside your dry signal in stereo." + } + // MARK: - Parameters /// Pre-gain into the octave-channel saturator. Range [1, 40]; higher = thicker octave fuzz. diff --git a/Sources/LyrebirdShoeGaze/Pedals/OverdrivePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/OverdrivePedal.swift index 576b040..9eb843a 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/OverdrivePedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/OverdrivePedal.swift @@ -27,6 +27,11 @@ import LyrebirdUI /// Range `(0, 20000]`. Defaults to `4000.0`. public final class OverdrivePedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Warm soft-clip overdrive with a tone control, from gentle grit to singing sustain." + } + // MARK: - Parameters /// Saturation drive amount. Range [1, 20]; higher = more clipping. diff --git a/Sources/LyrebirdShoeGaze/Pedals/PhaserPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/PhaserPedal.swift index 17ebea1..716eff7 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/PhaserPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/PhaserPedal.swift @@ -30,6 +30,11 @@ import LyrebirdUI /// 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]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/PingPongDelayPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/PingPongDelayPedal.swift index 37e78bf..548b4cc 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/PingPongDelayPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/PingPongDelayPedal.swift @@ -37,6 +37,11 @@ import LyrebirdUI /// 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, 1.0]. diff --git a/Sources/LyrebirdShoeGaze/Pedals/ReverbPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/ReverbPedal.swift index c4c9dd3..611b317 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/ReverbPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/ReverbPedal.swift @@ -31,6 +31,11 @@ import LyrebirdUI /// shorter tails. Defaults to `0.5`. public final class ReverbPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Reverb adding space and ambience, from small rooms to vast halls." + } + // MARK: - Parameters /// Room size in [0, 1]. Larger = longer reverb tail. diff --git a/Sources/LyrebirdShoeGaze/Pedals/RingModulatorPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/RingModulatorPedal.swift new file mode 100644 index 0000000..23ff4e6 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/RingModulatorPedal.swift @@ -0,0 +1,84 @@ +// RingModulatorPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// Ring modulator pedal. +/// +/// Multiplies the input by a tunable sine carrier, producing sum-and-difference sidebands — +/// metallic, bell-like, and robotic tones. Below ~30 Hz the carrier reads as tremolo-style +/// amplitude modulation; in the audio range it becomes classic ring modulation. +/// +/// Signal path (inside `effect(_:)`): +/// ``` +/// dry × OscSin(frequency) → wet +/// ``` +/// +/// The wet/dry blend and bypass are handled by the `Pedal` base class. +/// +/// ## Parameters +/// +/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: +/// +/// - Parameters: +/// - frequency: Carrier frequency in Hz. Range `[20, 2000]`. Defaults to `220.0`. +public final class RingModulatorPedal: Pedal { + + // MARK: - Parameters + + /// Carrier frequency in Hz. Range [20, 2000]. + @UIParam public var frequency: Double = 220.0 + + // MARK: - Constants + + /// Default wet/dry blend — ring mod is harsh, so keep the dry signal present. + private static let defaultMix: Double = 0.5 + + // MARK: - UI knobs + + private let frequencyRange: ClosedRange = 20.0 ... 2000.0 + + public override var effectKnobs: [PedalKnob] { + [ + PedalKnob(label: "Frequency", node: $frequency, range: frequencyRange), + ] + } + + // MARK: - Init + + /// Creates a ring modulator 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: "Ring Modulator", + inputBus: inputBus, + outputBus: outputBus, + initialMix: RingModulatorPedal.defaultMix + ) + } + + public override var summary: String { + "Multiplies your signal by a tunable carrier for metallic, bell-like, and robotic tones." + } + + // MARK: - Effect + + /// Multiplies the dry signal by the sine carrier. + /// + /// - Parameter dry: Dry mono input signal. + /// - Returns: The ring-modulated wet signal. + public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { + let carrier: OscSin.Audio = OscSin.Audio(freq: $frequency) + return dry * carrier + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/SustainerPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/SustainerPedal.swift new file mode 100644 index 0000000..5e8c44a --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/SustainerPedal.swift @@ -0,0 +1,144 @@ +// SustainerPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// Sustainer pedal: a one-knob compressor tuned for long, even sustain. +/// +/// A single `sustain` control drives a feed-forward compressor harder as it climbs — lowering +/// the threshold, raising the ratio, and adding makeup gain together — so notes bloom and hold +/// without the user juggling threshold/ratio (that's what the `Compressor` pedal is for). A +/// `tone` low-pass rounds off the squashed top end. +/// +/// Signal path (inside `effect(_:)`): +/// ``` +/// dry → Compressor(threshold↓, ratio↑, makeup↑ with sustain) → RBJLowPass(tone) → wet +/// ``` +/// +/// The wet/dry blend and bypass are handled by the `Pedal` base class. +/// +/// ## Parameters +/// +/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus: +/// +/// - Parameters: +/// - sustain: Amount of sustain/compression. `0` = gentle, `10` = maximum squash and hold. +/// Range `[0, 10]`. Defaults to `5.0`. +/// - tone: Output low-pass cutoff in Hz. Range `[800, 8000]`. Defaults to `6000.0`. +public final class SustainerPedal: Pedal { + + // MARK: - Parameters + + /// Sustain amount in [0, 10]. Higher = more compression, makeup, and hold. + @UIParam public var sustain: Double = 5.0 + + /// Output low-pass cutoff in Hz. Range [800, 8000]. + @UIParam public var tone: Double = 6000.0 + + // MARK: - Constants + + private static let defaultMix: Double = 1.0 + + /// Compressor envelope times, in seconds — fast attack to catch picks, slow release to hold. + private let attackTime: Double = 0.005 + private let releaseTime: Double = 0.4 + + /// Hard knee for a defined, punchy sustain. + private let kneeWidth: Double = 0.0 + + /// Butterworth tone low-pass (no resonant peak). + private let toneQ: Double = 0.707 + + /// `sustain` knob span, mapped to the compressor settings below. + private let sustainMin: Double = 0.0 + private let sustainMax: Double = 10.0 + + /// Threshold in dB at min / max sustain (lower threshold = more of the signal compressed). + private let thresholdAtMin: Double = -6.0 + private let thresholdAtMax: Double = -36.0 + + /// Compression ratio at min / max sustain. + private let ratioAtMin: Double = 2.0 + private let ratioAtMax: Double = 10.0 + + /// Makeup gain in dB at min / max sustain (compensates for the added gain reduction). + private let makeupAtMin: Double = 0.0 + private let makeupAtMax: Double = 18.0 + + // MARK: - UI knobs + + private let sustainRange: ClosedRange = 0.0 ... 10.0 + private let toneRange: ClosedRange = 800.0 ... 8000.0 + + public override var effectKnobs: [PedalKnob] { + [ + PedalKnob(label: "Sustain", node: $sustain, range: sustainRange), + PedalKnob(label: "Tone", node: $tone, range: toneRange), + ] + } + + // MARK: - Init + + /// Creates a sustainer 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: "Sustainer", + inputBus: inputBus, + outputBus: outputBus, + initialMix: SustainerPedal.defaultMix + ) + } + + public override var summary: String { + "Compressor tuned for long, even sustain — one knob to make notes bloom and hold." + } + + // MARK: - Effect + + /// Drives a compressor from the single `sustain` knob, then rolls off the top with `tone`. + /// + /// - Parameter dry: Dry mono input signal. + /// - Returns: The sustained, tone-shaped wet signal. + public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { + let threshold: LinLin.Audio = mapSustain(to: thresholdAtMin, thresholdAtMax) + let ratio: LinLin.Audio = mapSustain(to: ratioAtMin, ratioAtMax) + let makeup: LinLin.Audio = mapSustain(to: makeupAtMin, makeupAtMax) + + let compressed: Compressor.Audio = Compressor.Audio( + in: dry, + threshold: threshold, + ratio: ratio, + attack: attackTime, + release: releaseTime, + kneeWidth: kneeWidth, + makeupGain: makeup + ) + return RBJLowPass.Audio( + input: compressed, + freq: $tone, + q: toneQ + ) + } + + /// Maps the `sustain` knob `[sustainMin, sustainMax]` to `[outLo, outHi]`. + private func mapSustain(to outLo: Double, _ outHi: Double) -> LinLin.Audio { + LinLin.Audio( + $sustain, + inLo: sustainMin, + inHi: sustainMax, + outLo: outLo, + outHi: outHi + ) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/TremoloPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/TremoloPedal.swift index 9ea3628..f4800d8 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/TremoloPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/TremoloPedal.swift @@ -31,6 +31,11 @@ import LyrebirdUI /// Defaults to `0.7`. public final class TremoloPedal: Pedal { + /// One-line description shown in the picker and info panel. + public override var summary: String { + "Rhythmic volume modulation, from a gentle throb to choppy stutter." + } + // MARK: - Parameters /// LFO rate in Hz. Range [0.5, 12]. diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index dee0847..41ccca3 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -49,6 +49,9 @@ public enum PedalRegistry { "Limiter": { LimiterPedal() }, "Noise Gate": { NoiseGatePedal() }, "Graphic EQ": { GraphicEQPedal() }, + "Chorus": { ChorusPedal() }, + "Sustainer": { SustainerPedal() }, + "Ring Modulator": { RingModulatorPedal() }, ] /// Returns a new `Pedal` instance for the given type string, or `nil` if the type @@ -65,4 +68,17 @@ public enum PedalRegistry { guard let constructor: @MainActor () -> Pedal = builtIn[type] else { return nil } return constructor() } + + /// Returns the `summary` description for a built-in pedal type, or `""` if unknown. + /// + /// Instantiates the pedal to read its `summary` — cheap, since constructing a `Pedal` + /// does not call `build()` or touch the engine. Intended for the pedal picker, which has + /// only the type string; callers that render many rows should cache the result. + /// + /// - Parameter type: The `displayName` of the pedal. + /// - Returns: The pedal's one-line `summary`, or `""` for unknown types. + @MainActor + public static func summary(for type: String) -> String { + makePedal(type: type)?.summary ?? "" + } } diff --git a/Sources/LyrebirdShoeGazeUI/PedalInfoView.swift b/Sources/LyrebirdShoeGazeUI/PedalInfoView.swift new file mode 100644 index 0000000..991ba23 --- /dev/null +++ b/Sources/LyrebirdShoeGazeUI/PedalInfoView.swift @@ -0,0 +1,129 @@ +// PedalInfoView.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import SwiftUI +import LyrebirdUI +import LyrebirdShoeGaze + +/// An info panel for a single pedal: its description and the effect controls with their ranges. +/// +/// Shows `pedal.summary` and lists the **effect** controls only — `effectKnobs` + `effectSliders` +/// + `effectSwitches`, each with its value range or switch positions. The common Mix / Level / +/// bypass controls are intentionally omitted (they behave the same on every pedal). Presented +/// from the pedal's ⓘ button. +public struct PedalInfoView: View { + + // MARK: - Layout constants + + private static let sectionSpacing: CGFloat = 16 + private static let rowSpacing: CGFloat = 8 + private static let labelColumnWidth: CGFloat = 110 + private static let summaryOpacity: Double = 0.85 + private static let valueOpacity: Double = 0.7 + private static let headerOpacity: Double = 0.5 + + // MARK: - Properties + + private let pedal: Pedal + + @Environment(\.dismiss) private var dismiss + + // MARK: - Init + + /// Creates an info panel for `pedal`. + public init(pedal: Pedal) { + self.pedal = pedal + } + + // MARK: - Body + + public var body: some View { + NavigationStack { + ScrollView { + VStack(alignment: .leading, spacing: PedalInfoView.sectionSpacing) { + if !pedal.summary.isEmpty { + Text(pedal.summary) + .font(.body) + .foregroundStyle(.primary.opacity(PedalInfoView.summaryOpacity)) + .fixedSize(horizontal: false, vertical: true) + } + + if !controlRows.isEmpty { + VStack(alignment: .leading, spacing: PedalInfoView.rowSpacing) { + Text("CONTROLS") + .font(.caption2.weight(.semibold)) + .foregroundStyle(.secondary.opacity(PedalInfoView.headerOpacity)) + ForEach(Array(controlRows.enumerated()), id: \.offset) { pair in + controlRow(pair.element) + } + } + } + } + .padding() + .frame(maxWidth: .infinity, alignment: .leading) + } + .navigationTitle(pedal.displayName) + #if !os(macOS) + .navigationBarTitleDisplayMode(.inline) + #endif + .toolbar { + ToolbarItem(placement: .confirmationAction) { + Button("Done") { dismiss() } + } + } + } + } + + // MARK: - Control rows + + private func controlRow(_ row: ControlRow) -> some View { + HStack(alignment: .firstTextBaseline) { + Text(row.label) + .font(.callout.weight(.medium)) + .frame(width: PedalInfoView.labelColumnWidth, alignment: .leading) + Text(row.value) + .font(.callout.monospacedDigit()) + .foregroundStyle(.secondary.opacity(PedalInfoView.valueOpacity)) + Spacer(minLength: 0) + } + } + + /// One displayed control: a label and its range / options string. + private struct ControlRow { + let label: String + let value: String + } + + /// Effect controls only (knobs + sliders + switches), in display order. + private var controlRows: [ControlRow] { + var rows: [ControlRow] = [] + for knob: PedalKnob in pedal.effectKnobs { + rows.append(ControlRow(label: knob.label, value: PedalInfoView.rangeText(knob.range))) + } + for slider: PedalSlider in pedal.effectSliders { + rows.append(ControlRow(label: slider.label, value: PedalInfoView.rangeText(slider.range))) + } + for pedalSwitch: PedalSwitch in pedal.effectSwitches { + let options: String = pedalSwitch.options.map { $0.title }.joined(separator: " / ") + rows.append(ControlRow(label: pedalSwitch.label, value: options)) + } + return rows + } + + // MARK: - Formatting + + /// Formats a value range as `"lo – hi"`, using integers when both bounds are whole. + private static func rangeText(_ range: ClosedRange) -> String { + "\(number(range.lowerBound)) – \(number(range.upperBound))" + } + + private static func number(_ value: Double) -> String { + if value == value.rounded() { + return String(format: "%.0f", value) + } + return String(format: "%.3g", value) + } +} diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index b40ba6d..870380c 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift @@ -41,13 +41,17 @@ public struct PedalPaletteView: View { private static let routingCaptionOpacity: Double = 0.5 private static let routingCaptionFontSize: CGFloat = 10 private static let addGlyphOpacity: Double = 0.4 + /// Vertical gap between a pedal row's name and its description subtitle. + private static let rowSubtitleSpacing: CGFloat = 2 + /// Opacity of the pedal-row description subtitle. + private static let summaryOpacity: Double = 0.55 /// Preferred display order for the built-in pedals. Any registered pedal not listed here is /// appended afterwards (sorted) so the palette never silently drops a newly added pedal. private static let preferredOrder: [String] = [ - "Overdrive", "Compressor", "Limiter", "Noise Gate", "Fuzz", - "Graphic EQ", "Tremolo", "Phaser", "Modulation", - "Auto-Wah", "Mutant", "Bass Octaver", "Octave Splitter", + "Overdrive", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", + "Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", + "Auto-Wah", "Mutant", "Ring Modulator", "Bass Octaver", "Octave Splitter", "Delay", "Feedback Delay", "Multi-Tap Delay", "Ping-Pong", "Reverb", ] @@ -128,18 +132,29 @@ public struct PedalPaletteView: View { /// A full-width pedal row: tap appends to the main chain; drag carries `"add:"` so it can /// be dropped onto a stereo/parallel lane. private func pedalRow(_ name: String) -> some View { - Button { + let summary: String = PedalRegistry.summary(for: name) + return Button { onAdd(name) } label: { - HStack(spacing: 4) { - Text(name) - .font(.callout) - .foregroundStyle(Color.white) - .lineLimit(1) - Spacer(minLength: 0) - Image(systemName: "plus") - .font(.caption2) - .foregroundStyle(Color.white.opacity(PedalPaletteView.addGlyphOpacity)) + VStack(alignment: .leading, spacing: PedalPaletteView.rowSubtitleSpacing) { + HStack(spacing: 4) { + Text(name) + .font(.callout) + .foregroundStyle(Color.white) + .lineLimit(1) + Spacer(minLength: 0) + Image(systemName: "plus") + .font(.caption2) + .foregroundStyle(Color.white.opacity(PedalPaletteView.addGlyphOpacity)) + } + if !summary.isEmpty { + Text(summary) + .font(.caption2) + .foregroundStyle(Color.white.opacity(PedalPaletteView.summaryOpacity)) + .lineLimit(2) + .multilineTextAlignment(.leading) + .fixedSize(horizontal: false, vertical: true) + } } .padding(.horizontal, PedalPaletteView.cardPaddingH) .padding(.vertical, PedalPaletteView.cardPaddingV) diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index a9bee2a..abd95e8 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -31,6 +31,9 @@ private func enclosureColor(for displayName: String) -> Color { case "Limiter": return Color(red: 0.62, green: 0.16, blue: 0.20) // brick red case "Noise Gate": return Color(red: 0.24, green: 0.26, blue: 0.30) // gunmetal case "Graphic EQ": return Color(red: 0.14, green: 0.40, blue: 0.50) // deep teal + case "Chorus": return Color(red: 0.16, green: 0.50, blue: 0.64) // aqua + case "Sustainer": return Color(red: 0.22, green: 0.46, blue: 0.30) // pine green + case "Ring Modulator": return Color(red: 0.64, green: 0.30, blue: 0.10) // burnt amber default: return Color(red: 0.36, green: 0.36, blue: 0.38) // steel gray } } @@ -212,6 +215,8 @@ public struct PedalView: View { private static let screwHalfSize: CGFloat = 4 private static let namePlateBackgroundOpacity: Double = 0.35 private static let fontSizeNamePlate: CGFloat = 13 + /// Opacity of the trailing ⓘ info button on the name plate. + private static let infoButtonOpacity: Double = 0.7 private static let outerBorderLineWidth: CGFloat = 1.5 private static let innerHighlightLineWidth: CGFloat = 1 private static let innerHighlightPadding: CGFloat = 1 @@ -221,6 +226,9 @@ public struct PedalView: View { private let pedal: Pedal + /// Presentation flag for the pedal info panel (description + control ranges). + @State private var showInfo: Bool = false + // MARK: - Init /// Creates a stompbox pedal view for the given pedal. @@ -282,11 +290,15 @@ public struct PedalView: View { x: PedalView.shadowXOffset, y: PedalView.shadowYOffset ) + .sheet(isPresented: $showInfo) { + PedalInfoView(pedal: pedal) + .presentationDetents([.medium, .large]) + } } // MARK: - Subviews - /// Capsule name plate near the top of the enclosure. + /// Capsule name plate near the top of the enclosure, with a trailing info button. private var namePlate: some View { Text(pedal.displayName) .font(.system(size: PedalView.fontSizeNamePlate, weight: .bold, design: .rounded)) @@ -295,6 +307,18 @@ public struct PedalView: View { .padding(.vertical, PedalView.namePlatePaddingV) .background(Color.black.opacity(PedalView.namePlateBackgroundOpacity)) .clipShape(RoundedRectangle(cornerRadius: PedalView.namePlateCornerRadius)) + .frame(maxWidth: .infinity) + .overlay(alignment: .trailing) { + Button { + showInfo = true + } label: { + Image(systemName: "info.circle") + .font(.system(size: PedalView.fontSizeNamePlate)) + .foregroundStyle(Color.white.opacity(PedalView.infoButtonOpacity)) + } + .buttonStyle(.plain) + .help("About this pedal") + } } /// Grid of the effect knobs, in rows of up to `knobColumnCount`. diff --git a/Tests/LyrebirdShoeGazeTests/ChorusPedalTests.swift b/Tests/LyrebirdShoeGazeTests/ChorusPedalTests.swift new file mode 100644 index 0000000..2d8f73c --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/ChorusPedalTests.swift @@ -0,0 +1,131 @@ +// ChorusPedalTests.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Testing +import Foundation +import LyrebirdSynth +import LyrebirdUI +@testable import LyrebirdShoeGaze + +@MainActor +@Suite("ChorusPedal") +struct ChorusPedalTests { + + private func render(configure: (ChorusPedal) -> Void = { _ in }) throws -> [Float] { + let renderDuration: Double = 0.1 + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64) + defer { try? FileManager.default.removeItem(at: url) } + + let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + defer { + engine.busAllocator.releaseAudioBus(srcBus) + engine.busAllocator.releaseAudioBus(dstBus) + } + + let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index) + let pedal: ChorusPedal = ChorusPedal(inputBus: srcBus.index, outputBus: dstBus.index) + configure(pedal) + let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index) + try engine.add(source) + try engine.add(pedal, position: NodePosition.after(source)) + try engine.add(master, position: NodePosition.after(pedal)) + try engine.start() + return readStereoCAF(url: url) + } + + private func ssd(_ a: [Float], _ b: [Float]) -> Double { + let skip: Int = 2048, window: Int = 2048 + guard a.count >= skip + window, b.count >= skip + window else { return 0 } + return zip(a[skip..<(skip + window)], b[skip..<(skip + window)]).reduce(0.0) { acc, pair in + let d: Double = Double(pair.0 - pair.1); return acc + d * d + } + } + + @Test func buildsAndProducesNonSilentOutput() throws { + let samples: [Float] = try render() + #expect(!samples.isEmpty) + #expect(hasNonSilentOutput(samples), "ChorusPedal produced silence") + } + + @Test func rateChangesOutput() throws { + let slow: [Float] = try render { $0.rate = 0.1 } + let fast: [Float] = try render { $0.rate = 5.0 } + #expect(hasNonSilentOutput(slow) && hasNonSilentOutput(fast)) + #expect(ssd(slow, fast) > 0, "rate had no effect on output") + } + + @Test func depthChangesOutput() throws { + let shallow: [Float] = try render { $0.depth = 0.0005 } + let deep: [Float] = try render { $0.depth = 0.008 } + #expect(ssd(shallow, deep) > 0, "depth had no effect on output") + } + + @Test func leftAndRightVoicesDiffer() throws { + // The point of the widener: anti-phase LFOs make the two voices distinct. Activate the + // right channel (which a stereo board region does via PedalBoard.add) by setting + // `outputBusRight`, route each board bus to a separate hardware channel, and compare. + let renderDuration: Double = 0.1 + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64) + defer { try? FileManager.default.removeItem(at: url) } + + let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + let dstL: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + let dstR: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + defer { + engine.busAllocator.releaseAudioBus(srcBus) + engine.busAllocator.releaseAudioBus(dstL) + engine.busAllocator.releaseAudioBus(dstR) + } + + let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index) + let pedal: ChorusPedal = ChorusPedal(inputBus: srcBus.index, outputBus: dstL.index) + pedal.outputBusRight = dstR.index // emulate the stereo region a board would create + let master: StereoSplitTestMaster = StereoSplitTestMaster(left: dstL.index, right: dstR.index) + try engine.add(source) + try engine.add(pedal, position: NodePosition.after(source)) + try engine.add(master, position: NodePosition.after(pedal)) + try engine.start() + + // readStereoCAF returns interleaved [L, R, L, R, …]; even = left voice, odd = right voice. + let samples: [Float] = readStereoCAF(url: url) + let skipFrames: Int = 2048 + let windowFrames: Int = 2048 + guard samples.count >= 2 * (skipFrames + windowFrames) else { return } + + var lefts: [Float] = [] + var rights: [Float] = [] + for frame: Int in skipFrames ..< (skipFrames + windowFrames) { + lefts.append(samples[2 * frame]) + rights.append(samples[2 * frame + 1]) + } + #expect(hasNonSilentOutput(lefts) && hasNonSilentOutput(rights), "a chorus voice was silent") + + let ssdLR: Double = zip(lefts, rights).reduce(0.0) { acc, pair in + let d: Double = Double(pair.0 - pair.1); return acc + d * d + } + #expect(ssdLR > 0, "left and right chorus voices are identical — no stereo width") + } +} + +/// Routes two mono board buses to hardware left (bus 0) and right (bus 1) so a stereo widener's +/// channels can be captured separately by `readStereoCAF`. +@MainActor +private final class StereoSplitTestMaster: SynthesizerBase { + private let left: Int + private let right: Int + + init(left: Int, right: Int) { + self.left = left + self.right = right + super.init() + } + + override func build() { + output(bus: 0, source: input(bus: left)) + output(bus: 1, source: input(bus: right)) + } +} diff --git a/Tests/LyrebirdShoeGazeTests/PedalInfoTests.swift b/Tests/LyrebirdShoeGazeTests/PedalInfoTests.swift new file mode 100644 index 0000000..9d171ba --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/PedalInfoTests.swift @@ -0,0 +1,43 @@ +// PedalInfoTests.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Testing +import Foundation +import LyrebirdSynth +import LyrebirdUI +@testable import LyrebirdShoeGaze + +@MainActor +@Suite("Pedal info") +struct PedalInfoTests { + + @Test func everyBuiltInPedalHasASummary() throws { + for type: String in PedalRegistry.builtIn.keys { + let pedal: Pedal? = PedalRegistry.makePedal(type: type) + #expect(pedal != nil, "registry could not build \(type)") + let summary: String = pedal?.summary ?? "" + #expect(!summary.isEmpty, "\(type) has an empty summary — every pedal must set one") + } + } + + @Test func registrySummaryHelperMatchesInstance() throws { + #expect(PedalRegistry.summary(for: "Overdrive") == OverdrivePedal().summary) + #expect(PedalRegistry.summary(for: "Ring Modulator") == RingModulatorPedal().summary) + #expect(PedalRegistry.summary(for: "Nope") == "") + } + + @Test func effectControlsExcludeCommonControls() throws { + // The info panel lists effect controls only; the common Mix / Level / bypass live in the + // base `Pedal` and must never appear in effectKnobs/effectSliders/effectSwitches. + let pedal: GraphicEQPedal = GraphicEQPedal() + let effectLabels: [String] = + pedal.effectKnobs.map { $0.label } + + pedal.effectSliders.map { $0.label } + + pedal.effectSwitches.map { $0.label } + #expect(!effectLabels.contains("Mix")) + #expect(!effectLabels.contains("Level")) + } +} diff --git a/Tests/LyrebirdShoeGazeTests/RingModulatorPedalTests.swift b/Tests/LyrebirdShoeGazeTests/RingModulatorPedalTests.swift new file mode 100644 index 0000000..5a546c3 --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/RingModulatorPedalTests.swift @@ -0,0 +1,58 @@ +// RingModulatorPedalTests.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Testing +import Foundation +import LyrebirdSynth +import LyrebirdUI +@testable import LyrebirdShoeGaze + +@MainActor +@Suite("RingModulatorPedal") +struct RingModulatorPedalTests { + + private func render(frequency: Double) throws -> [Float] { + let renderDuration: Double = 0.1 + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64) + defer { try? FileManager.default.removeItem(at: url) } + + let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + defer { + engine.busAllocator.releaseAudioBus(srcBus) + engine.busAllocator.releaseAudioBus(dstBus) + } + + let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index) + let pedal: RingModulatorPedal = RingModulatorPedal(inputBus: srcBus.index, outputBus: dstBus.index) + pedal.frequency = frequency + let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index) + try engine.add(source) + try engine.add(pedal, position: NodePosition.after(source)) + try engine.add(master, position: NodePosition.after(pedal)) + try engine.start() + return readStereoCAF(url: url) + } + + @Test func buildsAndProducesNonSilentOutput() throws { + let samples: [Float] = try render(frequency: 220.0) + #expect(!samples.isEmpty) + #expect(hasNonSilentOutput(samples), "RingModulatorPedal produced silence") + } + + @Test func frequencyChangesOutput() throws { + let low: [Float] = try render(frequency: 100.0) + let high: [Float] = try render(frequency: 800.0) + #expect(hasNonSilentOutput(low) && hasNonSilentOutput(high)) + + let skip: Int = 1024, window: Int = 2048 + guard low.count >= skip + window, high.count >= skip + window else { return } + let ssd: Double = zip(low[skip..<(skip + window)], high[skip..<(skip + window)]).reduce(0.0) { acc, pair in + let d: Double = Double(pair.0 - pair.1); return acc + d * d + } + #expect(ssd > 0, "carrier frequency had no effect on output") + } +} diff --git a/Tests/LyrebirdShoeGazeTests/SustainerPedalTests.swift b/Tests/LyrebirdShoeGazeTests/SustainerPedalTests.swift new file mode 100644 index 0000000..4a0f1d8 --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/SustainerPedalTests.swift @@ -0,0 +1,64 @@ +// SustainerPedalTests.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import Testing +import Foundation +import LyrebirdSynth +import LyrebirdUI +@testable import LyrebirdShoeGaze + +@MainActor +@Suite("SustainerPedal") +struct SustainerPedalTests { + + private func render(configure: (SustainerPedal) -> Void = { _ in }) throws -> [Float] { + let renderDuration: Double = 0.1 + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration, numAudioBuses: 64) + defer { try? FileManager.default.removeItem(at: url) } + + let srcBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + let dstBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1) + defer { + engine.busAllocator.releaseAudioBus(srcBus) + engine.busAllocator.releaseAudioBus(dstBus) + } + + let source: TestLoopSource = TestLoopSource(targetBus: srcBus.index) + let pedal: SustainerPedal = SustainerPedal(inputBus: srcBus.index, outputBus: dstBus.index) + configure(pedal) + let master: TestRouteMaster = TestRouteMaster(inputBusIndex: dstBus.index) + try engine.add(source) + try engine.add(pedal, position: NodePosition.after(source)) + try engine.add(master, position: NodePosition.after(pedal)) + try engine.start() + return readStereoCAF(url: url) + } + + @Test func buildsAndProducesNonSilentOutput() throws { + let samples: [Float] = try render() + #expect(!samples.isEmpty) + #expect(hasNonSilentOutput(samples), "SustainerPedal produced silence") + } + + @Test func exposesSustainAndToneKnobs() throws { + let pedal: SustainerPedal = SustainerPedal() + #expect(pedal.effectKnobs.map { $0.label } == ["Sustain", "Tone"]) + } + + @Test func sustainAmountChangesOutput() throws { + // Min vs max sustain drive the compressor very differently → measurably different output. + let gentle: [Float] = try render { $0.sustain = 0.0 } + let squashed: [Float] = try render { $0.sustain = 10.0 } + #expect(hasNonSilentOutput(gentle) && hasNonSilentOutput(squashed)) + + let skip: Int = 1024, window: Int = 2048 + guard gentle.count >= skip + window, squashed.count >= skip + window else { return } + let ssd: Double = zip(gentle[skip..<(skip + window)], squashed[skip..<(skip + window)]).reduce(0.0) { acc, pair in + let d: Double = Double(pair.0 - pair.1); return acc + d * d + } + #expect(ssd > 0, "sustain knob had no effect on output") + } +}