diff --git a/ShoeGaze.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ShoeGaze.xcworkspace/xcshareddata/swiftpm/Package.resolved index c7317f1..7d66ae5 100644 --- a/ShoeGaze.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/ShoeGaze.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "6963980dd14bc118dfae577e57517f2776cb0d010d7b4ae798bdb57e4f0d2cb7", + "originHash" : "f5174c66e77b86ada0723482273f3d43cce9269f39894b2deb371f09e04069ab", "pins" : [ { "identity" : "linenoise-swift", @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://realizedsound.mooo.com/josh/Lyrebird", "state" : { - "revision" : "d6875da2cb6628c4274454dd55a632dd76212759", - "version" : "1.6.4" + "revision" : "ea0aa84ca796d9a21667e4b5a7d76a1ac2c280b6", + "version" : "1.7.1" } }, { diff --git a/Sources/LyrebirdShoeGaze/PedalType.swift b/Sources/LyrebirdShoeGaze/PedalType.swift index 95eb472..e064687 100644 --- a/Sources/LyrebirdShoeGaze/PedalType.swift +++ b/Sources/LyrebirdShoeGaze/PedalType.swift @@ -44,7 +44,9 @@ public struct PedalType: RawRepresentable, Hashable, Sendable { public extension PedalType { // Drive & dynamics - static let amp = PedalType("Amp") + static let california = PedalType("California") + static let british = PedalType("British") + static let chime = PedalType("Chime") static let neuralAmp = PedalType("Neural Amp") static let overdrive = PedalType("Overdrive") static let distortion = PedalType("Distortion") diff --git a/Sources/LyrebirdShoeGaze/Pedals/AmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AmpPedal.swift deleted file mode 100644 index b350038..0000000 --- a/Sources/LyrebirdShoeGaze/Pedals/AmpPedal.swift +++ /dev/null @@ -1,172 +0,0 @@ -// AmpPedal.swift -// Lyrebird -// -// Copyright (c) 2026 Joshua Parmenter / realizedsound -// SPDX-License-Identifier: MIT - -import LyrebirdSynth -import LyrebirdUI - -/// A full component-style guitar amp: preamp tube stage → tone stack → power-amp tube stage → -/// speaker cabinet, all white-box (no neural capture). -/// -/// Signal chain (inside `effect(_:)`): -/// ``` -/// dry → TriodeStage(drive: gain) (preamp) -/// → ToneStack(bass, mid, treble, model) (tone stack — Fender/Marshall/Vox, live-selectable) -/// → TriodeStage(power-amp drive) (power-amp warmth) -/// → ConvolutionReverb(cab IR) (speaker cabinet — live-selectable voice) -/// → mono out -/// ``` -/// -/// The tone-stack model and cabinet voice are each built once per option at `build()` and picked -/// live with a `Select` (so both round-trip through the rig save format). The amp is fully wet; -/// `Level` is the master volume. Built on Lyrebird 1.7's `TriodeStage` / `ToneStack` plus -/// ShoeGaze's synthesized cabinet IRs. -/// -/// > Note: `Select` evaluates *all* its inputs every block (SC parity — keeps state in sync), so -/// > every tone-stack model **and** every cabinet convolver runs continuously, not just the -/// > selected one. That is a few extra IIRs plus one partitioned-FFT convolver per unselected -/// > cabinet voice — a real (but bounded) CPU cost that scales with the number of voices. The -/// > cabinet IRs are synthesized at `build()` for the injected `sampleRate`; a live engine -/// > sample-rate change takes effect on the next rebuild. -/// -/// ## Parameters -/// -/// Inherits `bypass` and `level` (master) from `Pedal`, plus: -/// -/// - `gain`: Preamp drive. Range `[1, 30]`. -/// - `bass` / `mid` / `treble`: Tone-stack controls in `[0, 1]`. -/// - `amp`: Tone-stack model (Fender / Marshall / Vox). -/// - `cab`: Speaker-cabinet voice. -public final class AmpPedal: Pedal { - - /// One-line description shown in the picker and info panel. - public override var summary: String { - "Full tube amp — preamp, tone stack, power amp, and speaker cabinet in one." - } - - /// The amp is fully wet (it replaces the dry signal); hide the Mix control. - public override var showsMixControl: Bool { false } - - /// Amp-head-style double-width card so the four tone knobs plus the Amp / Cab selectors and - /// master lay out with room, rather than cramping into a single-width stompbox. - public override var widthUnits: Int { 2 } - - // MARK: - Parameters - - /// Preamp drive into the first tube stage. Range [1, 30]. - @UIParam public var gain: Double = 6.0 - - /// Tone-stack bass control in [0, 1]. - @UIParam public var bass: Double = 0.5 - - /// Tone-stack mid control in [0, 1]. - @UIParam public var mid: Double = 0.5 - - /// Tone-stack treble control in [0, 1]. - @UIParam public var treble: Double = 0.6 - - /// Selected tone-stack model as an index into `ToneStackModel.allCases`. - @UIParam public var amp: Double = 0.0 - - /// Selected cabinet voice as an index into `CabinetVoice.allCases`. - @UIParam public var cab: Double = 0.0 - - // MARK: - Constants - - private static let defaultMix: Double = 1.0 - - /// Preamp grid bias — a little asymmetry for even-harmonic warmth. - private let preampBias: Double = 0.2 - /// Fixed power-amp stage drive and bias (gentler than the preamp). - private let powerAmpDrive: Double = 1.5 - private let powerAmpBias: Double = 0.0 - /// Fully-wet convolution; the base class provides bypass and master level. - private let cabinetMix: Double = 1.0 - - /// Gain knob range. - private let gainRange: ClosedRange = 1.0 ... 30.0 - private let toneRange: ClosedRange = 0.0 ... 1.0 - - private static let ampStops: [PedalSelectorKnob.Stop] = ToneStackModel.allCases - .enumerated() - .map { (index: Int, model: ToneStackModel) in - PedalSelectorKnob.Stop(title: model.displayName, value: Double(index)) - } - - private static let cabStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases - .enumerated() - .map { (index: Int, voice: CabinetVoice) in - PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index)) - } - - // MARK: - Init - - /// Creates an amp 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: "Amp", - inputBus: inputBus, - outputBus: outputBus, - initialMix: AmpPedal.defaultMix - ) - } - - // MARK: - UI - - public override var effectKnobs: [PedalKnob] { - [ - PedalKnob(label: "Gain", node: $gain, range: gainRange), - PedalKnob(label: "Bass", node: $bass, range: toneRange), - PedalKnob(label: "Mid", node: $mid, range: toneRange), - PedalKnob(label: "Treble", node: $treble, range: toneRange), - ] - } - - public override var effectSelectors: [PedalSelectorKnob] { - [ - PedalSelectorKnob(label: "Amp", node: $amp, stops: AmpPedal.ampStops), - PedalSelectorKnob(label: "Cab", node: $cab, stops: AmpPedal.cabStops), - ] - } - - // MARK: - Effect - - /// Preamp → tone stack (model-selected) → power amp → cabinet (voice-selected). - /// - /// - Parameter dry: Dry mono input signal. - /// - Returns: The amped, cab-convolved mono output. - public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { - let sr: Double = sampleRate - - // Preamp tube stage. - let preamp: TriodeStage = TriodeStage(input: dry, drive: $gain, bias: preampBias, oversample: 4) - - // Tone stack — one per model, picked live. - let toneStacks: [any ValidGeneratorInput] = ToneStackModel.allCases.map { (model: ToneStackModel) in - ToneStack(input: preamp, bass: $bass, mid: $mid, treble: $treble, model: model) - } - let toned: Select.Audio = Select.Audio(which: $amp, inputs: toneStacks) - - // Power-amp tube stage (fixed, gentle). - let powerAmp: TriodeStage = TriodeStage(input: toned, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2) - - // Speaker cabinet — one convolver per voice, picked live. - let cabinets: [any ValidGeneratorInput] = CabinetVoice.allCases.map { (voice: CabinetVoice) in - ConvolutionReverb.Audio( - input: powerAmp, - ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr), - mix: cabinetMix - ) - } - return Select.Audio(which: $cab, inputs: cabinets) - } -} diff --git a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift new file mode 100644 index 0000000..d44d76a --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift @@ -0,0 +1,150 @@ +// AmpVoicePedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// Shared base for the fixed-voicing amp pedals (California / British / Chime). +/// +/// Each concrete amp fixes one tone-stack ``ToneStackModel`` and adds one signature control, but +/// shares the common chain built here: +/// ``` +/// dry → TriodeStage(drive: gain) (preamp) +/// → ToneStack(bass, mid, treble, model) (fixed per amp) +/// → TriodeStage(power-amp drive) (power-amp warmth) +/// → shapeVoice(_:) (subclass signature filter) +/// → ConvolutionReverb(cab IR) (speaker cabinet — live-selectable voice) +/// ``` +/// Fully wet (the amp replaces the dry signal); `Level` is the master. Double-width amp-head card. +/// +/// Subclasses override ``toneStackModel``, ``summaryText``, ``signatureKnobs``, and +/// ``shapeVoice(_:)``, and may set a voice-appropriate default `gain` in their `init`. +open class AmpVoicePedal: Pedal { + + // MARK: - Common parameters + + /// Preamp drive into the first tube stage. Range [1, 30]. + @UIParam public var gain: Double = 6.0 + /// Tone-stack bass control in [0, 1]. + @UIParam public var bass: Double = 0.5 + /// Tone-stack mid control in [0, 1]. + @UIParam public var mid: Double = 0.5 + /// Tone-stack treble control in [0, 1]. + @UIParam public var treble: Double = 0.6 + /// Selected cabinet voice as an index into `CabinetVoice.allCases`. + @UIParam public var cab: Double = 0.0 + + // MARK: - Subclass configuration + + /// The fixed tone-stack model for this amp voice. Subclasses override. + open var toneStackModel: ToneStackModel { .fender } + /// One-line description. Subclasses override. + open var summaryText: String { "Tube amp." } + /// The amp's signature knob(s), appended after Gain/Bass/Mid/Treble. Default none. + open var signatureKnobs: [PedalKnob] { [] } + + /// Applies the amp's signature post-power-amp shaping (e.g. a bright/presence shelf or a cut + /// low-pass). Default: identity. Subclasses override. + /// + /// - Parameter signal: The post-power-amp signal. + /// - Returns: The shaped signal fed to the cabinet. + open func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + signal + } + + // MARK: - Constants + + private static let defaultMix: Double = 1.0 + /// Preamp grid bias — a little asymmetry for even-harmonic warmth. + private let preampBias: Double = 0.2 + /// Fixed power-amp stage drive/bias (gentler than the preamp). + private let powerAmpDrive: Double = 1.5 + private let powerAmpBias: Double = 0.0 + private let cabinetMix: Double = 1.0 + + let gainRange: ClosedRange = 1.0 ... 30.0 + let toneRange: ClosedRange = 0.0 ... 1.0 + /// Range for a signature control that maps [0, 1] (Bright / Presence / Cut amount). + let signatureRange: ClosedRange = 0.0 ... 1.0 + + private static let cabStops: [PedalSelectorKnob.Stop] = CabinetVoice.allCases + .enumerated() + .map { (index: Int, voice: CabinetVoice) in + PedalSelectorKnob.Stop(title: voice.displayName, value: Double(index)) + } + + // MARK: - Chrome + + /// The amp is fully wet (it replaces the dry signal); hide the Mix control. + public override var showsMixControl: Bool { false } + + /// Amp-head-style double-width card. + public override var widthUnits: Int { 2 } + + public override var summary: String { summaryText } + + // MARK: - Init + + /// Creates an amp voice pedal. + /// + /// - Parameters: + /// - name: Display name (the amp voice, e.g. "California"). + /// - 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( + name: String, + inputBus: Int = 0, + outputBus: Int = 0 + ) { + super.init( + name: name, + inputBus: inputBus, + outputBus: outputBus, + initialMix: AmpVoicePedal.defaultMix + ) + } + + // MARK: - UI + + public override var effectKnobs: [PedalKnob] { + [ + PedalKnob(label: "Gain", node: $gain, range: gainRange), + PedalKnob(label: "Bass", node: $bass, range: toneRange), + PedalKnob(label: "Mid", node: $mid, range: toneRange), + PedalKnob(label: "Treble", node: $treble, range: toneRange), + ] + signatureKnobs + } + + public override var effectSelectors: [PedalSelectorKnob] { + [ + PedalSelectorKnob(label: "Cab", node: $cab, stops: AmpVoicePedal.cabStops), + ] + } + + // MARK: - Effect + + /// Preamp → fixed tone stack → power amp → signature shaping → cabinet (voice-selected). + /// + /// - Parameter dry: Dry mono input signal. + /// - Returns: The amped, cab-convolved mono output. + public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { + let sr: Double = sampleRate + let preamp: TriodeStage = TriodeStage(input: dry, drive: $gain, bias: preampBias, oversample: 4) + let toned: ToneStack = ToneStack( + input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel) + let powerAmp: TriodeStage = TriodeStage( + input: toned, drive: powerAmpDrive, bias: powerAmpBias, oversample: 2) + let shaped: any ValidGeneratorInput = shapeVoice(powerAmp) + let cabinets: [any ValidGeneratorInput] = CabinetVoice.allCases.map { (voice: CabinetVoice) in + ConvolutionReverb.Audio( + input: shaped, + ir: CabinetIRFactory.makeIR(voice: voice, sampleRate: sr), + mix: cabinetMix + ) + } + return Select.Audio(which: $cab, inputs: cabinets) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/BritishAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/BritishAmpPedal.swift new file mode 100644 index 0000000..84fd5d1 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/BritishAmpPedal.swift @@ -0,0 +1,46 @@ +// BritishAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// British-voiced amp (mid-forward crunch) with a **Presence** upper-high lift control. +/// +/// A ``AmpVoicePedal`` fixed to the British tone stack, defaulting to a higher gain for crunch. +public final class BritishAmpPedal: AmpVoicePedal { + + /// Presence amount in [0, 1] → 0…`presenceMaxGainDb` of lift above `presenceFreqHz`. + @UIParam public var presence: Double = 0.4 + + private let presenceFreqHz: Double = 4500.0 + private let presenceMaxGainDb: Double = 8.0 + private let shelfSlope: Double = 0.7 + + public override var toneStackModel: ToneStackModel { .marshall } + public override var summaryText: String { + "British crunch — forward mids and bite, with a Presence lift." + } + public override var signatureKnobs: [PedalKnob] { + [PedalKnob(label: "Presence", node: $presence, range: signatureRange)] + } + + /// Creates a British amp. + /// + /// - 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: "British", inputBus: inputBus, outputBus: outputBus) + gain = 10.0 // crunch-leaning default + cab = 1.0 // default to the British 4×12 cab + } + + public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let gainDB: LinLin.Audio = LinLin.Audio( + $presence, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: presenceMaxGainDb) + return RBJHighShelf.Audio(input: signal, freq: presenceFreqHz, gain: gainDB, slope: shelfSlope) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/CaliforniaAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/CaliforniaAmpPedal.swift new file mode 100644 index 0000000..06e7662 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/CaliforniaAmpPedal.swift @@ -0,0 +1,45 @@ +// CaliforniaAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// American-voiced amp (scooped-mid, bright clean) with a **Bright** high-shelf sparkle control. +/// +/// A ``AmpVoicePedal`` fixed to the American tone stack, defaulting to a lower gain for headroom. +public final class CaliforniaAmpPedal: AmpVoicePedal { + + /// Bright high-shelf amount in [0, 1] → 0…`brightMaxGainDb` of lift above `brightFreqHz`. + @UIParam public var bright: Double = 0.3 + + private let brightFreqHz: Double = 3200.0 + private let brightMaxGainDb: Double = 6.0 + private let shelfSlope: Double = 1.0 + + public override var toneStackModel: ToneStackModel { .fender } + public override var summaryText: String { + "American clean — scooped mids, glassy top, with a Bright sparkle shelf." + } + public override var signatureKnobs: [PedalKnob] { + [PedalKnob(label: "Bright", node: $bright, range: signatureRange)] + } + + /// Creates a California amp. + /// + /// - 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: "California", inputBus: inputBus, outputBus: outputBus) + gain = 4.0 // clean-leaning default + } + + public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let gainDB: LinLin.Audio = LinLin.Audio( + $bright, inLo: 0.0, inHi: 1.0, outLo: 0.0, outHi: brightMaxGainDb) + return RBJHighShelf.Audio(input: signal, freq: brightFreqHz, gain: gainDB, slope: shelfSlope) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/ChimeAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/ChimeAmpPedal.swift new file mode 100644 index 0000000..d0c258f --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/ChimeAmpPedal.swift @@ -0,0 +1,48 @@ +// ChimeAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// Chimey/jangly amp (bell-like top boost) with a **Cut** control that rolls off the high end as +/// it's turned up — the classic top-boost "Cut" behavior. +/// +/// A ``AmpVoicePedal`` fixed to the chime tone stack. +public final class ChimeAmpPedal: AmpVoicePedal { + + /// Cut amount in [0, 1]: `0` = fully open/bright, `1` = darkest. Maps to a low-pass cutoff + /// swept from `cutOpenHz` down to `cutDarkHz`. + @UIParam public var cut: Double = 0.2 + + private let cutOpenHz: Double = 9000.0 + private let cutDarkHz: Double = 2500.0 + private let cutQ: Double = 0.707 + + public override var toneStackModel: ToneStackModel { .vox } + public override var summaryText: String { + "Chimey top-boost jangle with a Cut control that tames the highs." + } + public override var signatureKnobs: [PedalKnob] { + [PedalKnob(label: "Cut", node: $cut, range: signatureRange)] + } + + /// Creates a Chime amp. + /// + /// - 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: "Chime", inputBus: inputBus, outputBus: outputBus) + gain = 5.0 + } + + public override func shapeVoice(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + // cut 0 → cutOpenHz (bright), cut 1 → cutDarkHz (dark). + let cutoff: LinLin.Audio = LinLin.Audio( + $cut, inLo: 0.0, inHi: 1.0, outLo: cutOpenHz, outHi: cutDarkHz) + return RBJLowPass.Audio(input: signal, freq: cutoff, q: cutQ) + } +} diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index 8fae858..0d2bf11 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -31,7 +31,9 @@ public enum PedalRegistry { /// `ShoeGaze.loadRig(from:)` updates `inputBus`/`outputBus` when adding the pedal /// to a board via `board.add(_:)`. public static let builtIn: [String: @MainActor () -> Pedal] = [ - "Amp": { AmpPedal() }, + "California": { CaliforniaAmpPedal() }, + "British": { BritishAmpPedal() }, + "Chime": { ChimeAmpPedal() }, "Neural Amp": { NeuralAmpPedal() }, "Overdrive": { OverdrivePedal() }, "Distortion": { DistortionPedal() }, diff --git a/Sources/LyrebirdShoeGazeUI/HelpView.swift b/Sources/LyrebirdShoeGazeUI/HelpView.swift index 915bb8a..28fb2c0 100644 --- a/Sources/LyrebirdShoeGazeUI/HelpView.swift +++ b/Sources/LyrebirdShoeGazeUI/HelpView.swift @@ -178,9 +178,9 @@ public struct HelpView: View { + "built-in speaker impulse responses.", "The Cabinet pedal's built-in cab voicings are original impulse responses generated in " + "code — not captures of any third-party hardware or IR pack.", - "The Amp pedal's tone stack follows the Yeh & Smith analysis of the Fender/Marshall/Vox " - + "tone-stack circuit (\"Discretization of the '59 Fender Bassman Tone Stack\", DAFx-06); " - + "its models are original code, not captures of specific hardware.", + "The California, British, and Chime amp pedals' tone stacks follow the Yeh & Smith analysis " + + "of the classic passive tone-stack circuit (\"Discretization of the '59 Fender Bassman Tone " + + "Stack\", DAFx-06); their models are original code, not captures of specific hardware.", "The Neural Amp pedal loads GuitarML Proteus / NeuralPi capture models (the open LSTM " + "format from github.com/GuitarML). You supply the model file; none are bundled, and " + "those models are licensed by their respective authors.", diff --git a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift index 2276dd9..278b9fd 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift @@ -42,7 +42,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable { } private static let mapping: [String: PedalCategory] = [ - "Amp": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain, + "California": .gain, "British": .gain, "Chime": .gain, "Neural Amp": .gain, "Overdrive": .gain, "Distortion": .gain, "Fuzz": .gain, "Volume": .gain, "Compressor": .dynamics, "Sustainer": .dynamics, "Limiter": .dynamics, "Noise Gate": .dynamics, "Graphic EQ": .filter, "Auto-Wah": .filter, "Wah": .filter, "Mutant": .filter, "Cabinet": .filter, diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index f340ae5..14d83a1 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift @@ -54,7 +54,7 @@ public struct PedalPaletteView: View { /// 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] = [ - "Amp", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", + "California", "British", "Chime", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", "Volume", "Graphic EQ", "Tremolo", "Phaser", "Modulation", "Chorus", "Flanger", "Vibrato", "Rotary", "Auto-Wah", "Wah", "Mutant", "Cabinet", "Ring Modulator", "Diffuser", "Bitcrusher", "Granulator", diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index 8eba5af..27320b4 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -17,7 +17,9 @@ import LyrebirdShoeGaze /// here in the UI target. Unrecognised names fall through to `.gray`. private func enclosureColor(for displayName: String) -> Color { switch displayName { - case "Amp": return Color(red: 0.18, green: 0.17, blue: 0.20) // amp-head charcoal + case "California": return Color(red: 0.20, green: 0.28, blue: 0.34) // West-Coast steel blue + case "British": return Color(red: 0.30, green: 0.16, blue: 0.10) // oxblood tolex + case "Chime": return Color(red: 0.16, green: 0.24, blue: 0.22) // vintage green case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet case "Overdrive": return Color(red: 0.85, green: 0.42, blue: 0.08) // warm orange case "Distortion": return Color(red: 0.80, green: 0.26, blue: 0.12) // hot rust diff --git a/Tests/LyrebirdShoeGazeTests/AmpPedalTests.swift b/Tests/LyrebirdShoeGazeTests/AmpPedalTests.swift deleted file mode 100644 index a0f85f4..0000000 --- a/Tests/LyrebirdShoeGazeTests/AmpPedalTests.swift +++ /dev/null @@ -1,108 +0,0 @@ -// AmpPedalTests.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("AmpPedal") -struct AmpPedalTests { - - private let sampleRate: Double = 48000.0 - - private func render(configure: (AmpPedal) -> Void = { _ in }) throws -> [Float] { - let (engine, url): (SynthesisEngine, URL) = makeNRTEngine( - duration: 0.2, sampleRate: sampleRate, 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: AmpPedal = AmpPedal(inputBus: srcBus.index, outputBus: dstBus.index) - pedal.sampleRate = sampleRate - 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, sampleRate: sampleRate) - } - - private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double { - guard a.count >= skip + window, b.count >= skip + window else { return 0.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 buildsAndProducesNonSilentFiniteOutput() throws { - let samples: [Float] = try render() - #expect(!samples.isEmpty) - #expect(hasNonSilentOutput(samples), "AmpPedal produced silence") - #expect(samples.allSatisfy { $0.isFinite }, "AmpPedal produced non-finite output") - } - - @Test func gainChangesOutput() throws { - let clean: [Float] = try render { $0.gain = 2.0 } - let hot: [Float] = try render { $0.gain = 25.0 } - #expect(hasNonSilentOutput(clean) && hasNonSilentOutput(hot)) - #expect(windowedSSD(clean, hot) > 0, "gain had no effect") - } - - @Test func toneControlsChangeOutput() throws { - let dark: [Float] = try render { $0.treble = 0.0; $0.bass = 1.0 } - let bright: [Float] = try render { $0.treble = 1.0; $0.bass = 0.0 } - #expect(windowedSSD(dark, bright) > 0, "tone controls had no effect") - } - - @Test func midChangesOutput() throws { - let scooped: [Float] = try render { $0.mid = 0.0 } - let full: [Float] = try render { $0.mid = 1.0 } - #expect(windowedSSD(scooped, full) > 0, "mid control had no effect") - } - - @Test func ampModelChangesOutput() throws { - let fender: [Float] = try render { $0.amp = 0.0 } - let vox: [Float] = try render { $0.amp = 2.0 } - #expect(windowedSSD(fender, vox) > 0, "amp model had no effect") - } - - @Test func cabChangesOutput() throws { - let cabA: [Float] = try render { $0.cab = 0.0 } - let cabB: [Float] = try render { $0.cab = 2.0 } - #expect(windowedSSD(cabA, cabB) > 0, "cab selection had no effect") - } - - @Test func exposesControls() throws { - let pedal: AmpPedal = AmpPedal() - #expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble"]) - #expect(pedal.effectSelectors.map { $0.label } == ["Amp", "Cab"]) - #expect(pedal.widthUnits == 2, "amp head should use a double-width card") - } - - @Test func selectionsRoundTripThroughState() throws { - let pedal: AmpPedal = AmpPedal() - pedal.amp = 1.0 - pedal.cab = 2.0 - let restored: AmpPedal = AmpPedal() - restored.applyState(pedal.captureState()) - #expect(restored.amp == 1.0 && restored.cab == 2.0, "amp/cab selection did not round-trip") - } - - @Test func registeredInBuiltInRegistry() throws { - let pedal: Pedal? = PedalRegistry.makePedal(type: "Amp") - #expect(pedal is AmpPedal) - } -} diff --git a/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift b/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift new file mode 100644 index 0000000..a2d6a86 --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/AmpVoicePedalTests.swift @@ -0,0 +1,156 @@ +// AmpVoicePedalTests.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("AmpVoicePedal") +struct AmpVoicePedalTests { + + private let sampleRate: Double = 48000.0 + + private func render(_ make: () -> P, configure: (P) -> Void = { _ in }) throws -> [Float] { + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine( + duration: 0.2, sampleRate: sampleRate, 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: P = make() + pedal.inputBus = srcBus.index + pedal.outputBus = dstBus.index + pedal.sampleRate = sampleRate + 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, sampleRate: sampleRate) + } + + private func windowedSSD(_ a: [Float], _ b: [Float], skip: Int = 4096, window: Int = 4096) -> Double { + guard a.count >= skip + window, b.count >= skip + window else { return 0.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 + } + } + + /// The three concrete voices under test, keyed by their display name / registry key. + private let voices: [(name: String, make: () -> AmpVoicePedal)] = [ + ("California", { CaliforniaAmpPedal() }), + ("British", { BritishAmpPedal() }), + ("Chime", { ChimeAmpPedal() }), + ] + + @Test func allVoicesBuildNonSilentFiniteOutput() throws { + for voice in voices { + let samples: [Float] = try render(voice.make) + #expect(!samples.isEmpty) + #expect(hasNonSilentOutput(samples), "\(voice.name) produced silence") + #expect(samples.allSatisfy { $0.isFinite }, "\(voice.name) produced non-finite output") + } + } + + @Test func gainChangesOutput() throws { + for voice in voices { + let clean: [Float] = try render(voice.make) { $0.gain = 2.0 } + let hot: [Float] = try render(voice.make) { $0.gain = 25.0 } + #expect(windowedSSD(clean, hot) > 0, "\(voice.name) gain had no effect") + } + } + + @Test func toneControlsChangeOutput() throws { + for voice in voices { + let dark: [Float] = try render(voice.make) { $0.treble = 0.0; $0.bass = 1.0 } + let bright: [Float] = try render(voice.make) { $0.treble = 1.0; $0.bass = 0.0 } + #expect(windowedSSD(dark, bright) > 0, "\(voice.name) tone controls had no effect") + } + } + + @Test func midChangesOutput() throws { + for voice in voices { + let scooped: [Float] = try render(voice.make) { $0.mid = 0.0 } + let full: [Float] = try render(voice.make) { $0.mid = 1.0 } + #expect(windowedSSD(scooped, full) > 0, "\(voice.name) mid control had no effect") + } + } + + @Test func cabChangesOutput() throws { + for voice in voices { + let cabA: [Float] = try render(voice.make) { $0.cab = 0.0 } + let cabB: [Float] = try render(voice.make) { $0.cab = 2.0 } + #expect(windowedSSD(cabA, cabB) > 0, "\(voice.name) cab selection had no effect") + } + } + + // MARK: - Signature controls + + @Test func californiaBrightChangesOutput() throws { + let flat: [Float] = try render({ CaliforniaAmpPedal() }) { $0.bright = 0.0 } + let sparkle: [Float] = try render({ CaliforniaAmpPedal() }) { $0.bright = 1.0 } + #expect(windowedSSD(flat, sparkle) > 0, "California Bright had no effect") + } + + @Test func britishPresenceChangesOutput() throws { + let flat: [Float] = try render({ BritishAmpPedal() }) { $0.presence = 0.0 } + let lifted: [Float] = try render({ BritishAmpPedal() }) { $0.presence = 1.0 } + #expect(windowedSSD(flat, lifted) > 0, "British Presence had no effect") + } + + @Test func chimeCutChangesOutput() throws { + let open: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 0.0 } + let dark: [Float] = try render({ ChimeAmpPedal() }) { $0.cut = 1.0 } + #expect(windowedSSD(open, dark) > 0, "Chime Cut had no effect") + } + + // MARK: - Chrome / config + + @Test func exposesControls() throws { + #expect(CaliforniaAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Bright"]) + #expect(BritishAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Presence"]) + #expect(ChimeAmpPedal().effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Cut"]) + for voice in voices { + let pedal: AmpVoicePedal = voice.make() + #expect(pedal.effectSelectors.map { $0.label } == ["Cab"], "\(voice.name) selectors") + #expect(pedal.widthUnits == 2, "\(voice.name) amp head should use a double-width card") + #expect(pedal.showsMixControl == false, "\(voice.name) should be fully wet") + } + } + + @Test func distinctToneStackModels() throws { + #expect(CaliforniaAmpPedal().toneStackModel == .fender) + #expect(BritishAmpPedal().toneStackModel == .marshall) + #expect(ChimeAmpPedal().toneStackModel == .vox) + } + + @Test func selectionsRoundTripThroughState() throws { + let pedal: CaliforniaAmpPedal = CaliforniaAmpPedal() + pedal.gain = 12.0 + pedal.cab = 2.0 + pedal.bright = 0.8 + let restored: CaliforniaAmpPedal = CaliforniaAmpPedal() + restored.applyState(pedal.captureState()) + #expect(restored.gain == 12.0 && restored.cab == 2.0 && restored.bright == 0.8, + "California controls did not round-trip") + } + + @Test func registeredInBuiltInRegistry() throws { + #expect(PedalRegistry.makePedal(type: "California") is CaliforniaAmpPedal) + #expect(PedalRegistry.makePedal(type: "British") is BritishAmpPedal) + #expect(PedalRegistry.makePedal(type: "Chime") is ChimeAmpPedal) + } +}