diff --git a/Sources/LyrebirdShoeGaze/PedalSwitch.swift b/Sources/LyrebirdShoeGaze/PedalSwitch.swift index a141bbe..527711c 100644 --- a/Sources/LyrebirdShoeGaze/PedalSwitch.swift +++ b/Sources/LyrebirdShoeGaze/PedalSwitch.swift @@ -54,6 +54,11 @@ public struct PedalSwitch { /// to their first (off) option — while the tempo indicator is turned off. Defaults to `false`. public let tempoDependent: Bool + /// When `true`, committing a new position asks the host to rebuild the board — for switches that + /// change the *graph topology* (e.g. a clean/drive channel that adds or removes a gain stage), + /// the same mechanism as ``PedalSelectorKnob/rebuildsOnChange``. Defaults to `false`. + public let rebuildsOnChange: Bool + /// Creates a switch descriptor. /// /// - Parameters: @@ -62,17 +67,21 @@ public struct PedalSwitch { /// (`pedal.$mode`, `pedal.$direction`, …). /// - options: Ordered switch positions, left to right. At least two. /// - tempoDependent: `true` if the switch depends on the tempo/clock. Defaults to `false`. + /// - rebuildsOnChange: Ask the host to rebuild the board when a new position is committed. Use + /// for switches that change graph topology (e.g. a channel switch). Defaults to `false`. public init( label: String, node: UIParamNode, options: [Option], - tempoDependent: Bool = false + tempoDependent: Bool = false, + rebuildsOnChange: Bool = false ) { precondition(options.count >= 2, "PedalSwitch requires at least two options") self.label = label self.node = node self.options = options self.tempoDependent = tempoDependent + self.rebuildsOnChange = rebuildsOnChange } /// The value of the next option after the one nearest `current`, wrapping to the first — so a diff --git a/Sources/LyrebirdShoeGaze/PedalType.swift b/Sources/LyrebirdShoeGaze/PedalType.swift index 6f63a7d..893aac5 100644 --- a/Sources/LyrebirdShoeGaze/PedalType.swift +++ b/Sources/LyrebirdShoeGaze/PedalType.swift @@ -56,6 +56,7 @@ public extension PedalType { static let fullertonReverb = PedalType("Fullerton Reverb") static let fullertonDeluxe = PedalType("Fullerton Deluxe") static let fullertonPrinceton = PedalType("Fullerton Princeton") + static let fullertonDrive = PedalType("Fullerton Drive") static let jazzClean = PedalType("Jazz Clean") static let chimeTopBoost = PedalType("Chime Top Boost") static let neuralAmp = PedalType("Neural Amp") diff --git a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift index 4451592..3963e0c 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/AmpVoicePedal.swift @@ -85,6 +85,16 @@ open class AmpVoicePedal: Pedal { signal } + /// The preamp gain stage — the (post-`inputShaping`) input driven through the first tube stage + /// at `Gain`. Default: one `TriodeStage`. A channel-switching amp overrides this to cascade an + /// extra stage on its drive channel (call `super.preampStage(_:)` for the clean stage first). + /// + /// - Parameter signal: The post-`inputShaping` input signal. + /// - Returns: The preamp output fed into the tone stack. + open func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + TriodeStage(input: signal, drive: $gain, bias: preampBias, oversample: preampOversample) + } + /// Drive into the power-amp `TriodeStage`. Defaults to the fixed power-amp drive. Two kinds of /// amp override it: a **master-volume** amp returns a live `Master` knob mapped to a drive range /// (turning Master up pushes the power-amp stage into saturation — the real master-volume @@ -105,6 +115,8 @@ open class AmpVoicePedal: Pedal { private static let defaultMix: Double = 1.0 /// Preamp grid bias — a little asymmetry for even-harmonic warmth. private let preampBias: Double = 0.2 + /// Oversampling factor for the preamp stage (4× — the preamp can be driven hard by `Gain`). + let preampOversample: Int = 4 /// Fixed power-amp stage drive/bias (gentler than the preamp). private let powerAmpDrive: Double = 1.5 private let powerAmpBias: Double = 0.0 @@ -211,7 +223,7 @@ open class AmpVoicePedal: Pedal { /// - Returns: The post-power-amp, pre-cabinet mono signal. func preCabinetCore(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput { let preShaped: any ValidGeneratorInput = inputShaping(dry) - let preamp: TriodeStage = TriodeStage(input: preShaped, drive: $gain, bias: preampBias, oversample: 4) + let preamp: any ValidGeneratorInput = preampStage(preShaped) let toned: ToneStack = ToneStack( input: preamp, bass: $bass, mid: $mid, treble: $treble, model: toneStackModel) let processed: any ValidGeneratorInput = onboardEffects(toned) diff --git a/Sources/LyrebirdShoeGaze/Pedals/FullertonDriveAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/FullertonDriveAmpPedal.swift new file mode 100644 index 0000000..6fc39d4 --- /dev/null +++ b/Sources/LyrebirdShoeGaze/Pedals/FullertonDriveAmpPedal.swift @@ -0,0 +1,109 @@ +// FullertonDriveAmpPedal.swift +// Lyrebird +// +// Copyright (c) 2026 Joshua Parmenter / realizedsound +// SPDX-License-Identifier: MIT + +import LyrebirdSynth +import LyrebirdUI + +/// American **two-channel combo** — a blackface-style clean plus a hotter overdrive channel, with +/// spring reverb and a Bright switch. The modern gigging combo (Hot Rod / Blues Jr. lineage). +/// +/// The **Channel** switch selects Clean or Drive. On the Drive channel a second cascaded +/// ``TriodeStage`` (set by the `Drive` knob) is added ahead of the tone stack for preamp overdrive; +/// on Clean it is omitted entirely. Because the channel changes the graph topology the switch is +/// `rebuildsOnChange` — flipping it rebuilds the board (like the cab selector), so only the selected +/// channel's stages are ever built. +public final class FullertonDriveAmpPedal: AmpVoicePedal { + + /// Spring-reverb wet mix in [0, 1]. + @UIParam public var reverb: Double = 0.25 + /// Drive-channel preamp gain (the cascaded overdrive stage). Range [1, 30]. + @UIParam public var drive: Double = 8.0 + /// Bright switch: `0` = flat, `1` = treble shelf engaged. + @UIParam public var bright: Double = 0.0 + /// Channel select: `0` = Clean, `1` = Drive (the cascaded overdrive stage). + @UIParam public var channel: Double = 0.0 + + private let brightFreqHz: Double = 3200.0 + private let brightMaxGainDb: Double = 6.0 + private let brightSlope: Double = 1.0 + /// Grid bias of the cascaded drive stage — a little asymmetry for even-harmonic grind. + private let driveBias: Double = 0.25 + /// Channel-select threshold: `>= this` selects the Drive channel. + private let channelThreshold: Double = 0.5 + + private let reverbRange: ClosedRange = 0.0 ... 1.0 + private let driveRange: ClosedRange = 1.0 ... 30.0 + private let cleanValue: Double = 0.0 + private let driveValue: Double = 1.0 + + public override var toneStackModel: ToneStackModel { .fender } + public override var summaryText: String { + "American two-channel combo — blackface clean plus an overdrive channel, with reverb and Bright." + } + public override var signatureKnobs: [PedalKnob] { + [ + PedalKnob(label: "Reverb", node: $reverb, range: reverbRange), + PedalKnob(label: "Drive", node: $drive, range: driveRange), + ] + } + + /// Wider card for the Reverb/Drive knobs plus the Bright and Channel switches. + public override var widthUnits: Int { 3 } + + public override var effectSwitches: [PedalSwitch] { + [ + PedalSwitch( + label: "Bright", + node: $bright, + options: [ + PedalSwitch.Option(title: "Off", value: cleanValue), + PedalSwitch.Option(title: "On", value: driveValue), + ] + ), + PedalSwitch( + label: "Channel", + node: $channel, + options: [ + PedalSwitch.Option(title: "Clean", value: cleanValue), + PedalSwitch.Option(title: "Drive", value: driveValue), + ], + rebuildsOnChange: true + ), + ] + } + + /// Creates a Fullerton Drive 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: "Fullerton Drive", inputBus: inputBus, outputBus: outputBus) + gain = 4.0 + cab = 0.0 // American 1×12 + } + + /// Bright switch: a high-shelf lift ahead of the preamp (identity when off, live, no rebuild). + public override func inputShaping(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let shelfGainDb: any ValidGeneratorInput = $bright * brightMaxGainDb + return RBJHighShelf.Audio( + input: signal, freq: brightFreqHz, gain: shelfGainDb, slope: brightSlope) + } + + /// Clean preamp, plus a cascaded overdrive stage on the Drive channel. The `channel` value is + /// read at board-build time (the switch is `rebuildsOnChange`), so only the selected channel's + /// stages exist in the graph. + public override func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let clean: any ValidGeneratorInput = super.preampStage(signal) + guard channel >= channelThreshold else { return clean } + return TriodeStage(input: clean, drive: $drive, bias: driveBias, oversample: preampOversample) + } + + /// Spring reverb in the onboard-effects slot (after the tone stack). + public override func onboardEffects(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + SpringReverb.Audio(input: signal, mix: $reverb, sampleRate: sampleRate) + } +} diff --git a/Sources/LyrebirdShoeGaze/Pedals/JazzCleanAmpPedal.swift b/Sources/LyrebirdShoeGaze/Pedals/JazzCleanAmpPedal.swift index a616fce..91e5597 100644 --- a/Sources/LyrebirdShoeGaze/Pedals/JazzCleanAmpPedal.swift +++ b/Sources/LyrebirdShoeGaze/Pedals/JazzCleanAmpPedal.swift @@ -38,6 +38,10 @@ public final class JazzCleanAmpPedal: AmpVoicePedal { @UIParam public var bright: Double = 0.0 /// Chorus footswitch: `1` = chorus engaged (stereo), `0` = bypassed (dry, mono-equivalent). @UIParam public var chorusEnabled: Double = 1.0 + /// Drive-channel preamp gain (the onboard distortion). Range [1, 30]. + @UIParam public var drive: Double = 8.0 + /// Channel select: `0` = Clean, `1` = Distortion (the cascaded onboard-distortion stage). + @UIParam public var channel: Double = 0.0 // MARK: - Constants @@ -50,9 +54,15 @@ public final class JazzCleanAmpPedal: AmpVoicePedal { /// Fixed chorus wet/dry blend when the chorus is engaged (the amp has no chorus-mix knob). private let chorusMixValue: Double = 0.5 + /// Grid bias of the cascaded distortion stage — solid-state-flavoured, near-symmetric. + private let driveBias: Double = 0.1 + /// Channel-select threshold: `>= this` selects the Distortion channel. + private let channelThreshold: Double = 0.5 + private let reverbRange: ClosedRange = 0.0 ... 1.0 private let chorusRateRange: ClosedRange = 0.1 ... 5.0 private let chorusDepthRange: ClosedRange = 0.0005 ... 0.015 + private let driveRange: ClosedRange = 1.0 ... 30.0 private let switchOffValue: Double = 0.0 private let switchOnValue: Double = 1.0 @@ -60,13 +70,14 @@ public final class JazzCleanAmpPedal: AmpVoicePedal { public override var toneStackModel: ToneStackModel { .fender } public override var summaryText: String { - "Solid-state clean — lush stereo chorus, spring reverb, and a Bright switch." + "Solid-state clean — lush stereo chorus, spring reverb, a Bright switch, and a Distortion channel." } public override var signatureKnobs: [PedalKnob] { [ PedalKnob(label: "Reverb", node: $reverb, range: reverbRange), PedalKnob(label: "Rate", node: $chorusRate, range: chorusRateRange), PedalKnob(label: "Depth", node: $chorusDepth, range: chorusDepthRange), + PedalKnob(label: "Drive", node: $drive, range: driveRange), ] } @@ -109,9 +120,27 @@ public final class JazzCleanAmpPedal: AmpVoicePedal { PedalSwitch.Option(title: "On", value: switchOnValue), ] ), + PedalSwitch( + label: "Channel", + node: $channel, + options: [ + PedalSwitch.Option(title: "Clean", value: switchOffValue), + PedalSwitch.Option(title: "Dist", value: switchOnValue), + ], + rebuildsOnChange: true + ), ] } + /// Clean preamp, plus the onboard-distortion stage on the Distortion channel. The `channel` + /// value is read at board-build time (the switch is `rebuildsOnChange`), so only the selected + /// channel's stages exist in the graph. + public override func preampStage(_ signal: any ValidGeneratorInput) -> any ValidGeneratorInput { + let clean: any ValidGeneratorInput = super.preampStage(signal) + guard channel >= channelThreshold else { return clean } + return TriodeStage(input: clean, drive: $drive, bias: driveBias, oversample: preampOversample) + } + // MARK: - Hooks /// Bright switch: a high-shelf lift ahead of the preamp (identity when off, live, no rebuild). diff --git a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift index 8274c2c..c6a838e 100644 --- a/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift +++ b/Sources/LyrebirdShoeGaze/Presets/PedalRegistry.swift @@ -43,6 +43,7 @@ public enum PedalRegistry { "Fullerton Reverb": { FullertonReverbAmpPedal() }, "Fullerton Deluxe": { FullertonDeluxeAmpPedal() }, "Fullerton Princeton": { FullertonPrincetonAmpPedal() }, + "Fullerton Drive": { FullertonDriveAmpPedal() }, "Jazz Clean": { JazzCleanAmpPedal() }, "Chime Top Boost": { ChimeTopBoostAmpPedal() }, "Neural Amp": { NeuralAmpPedal() }, diff --git a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift index cfb4918..8fbe819 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalCategory.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalCategory.swift @@ -44,7 +44,7 @@ public enum PedalCategory: String, CaseIterable, Identifiable, Sendable { } private static let mapping: [String: PedalCategory] = [ - "California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Princeton": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp, + "California": .amp, "British": .amp, "British Plexi": .amp, "British JTM": .amp, "British Bluesbreaker": .amp, "Chime": .amp, "Chime 15": .amp, "Chime Normal": .amp, "Chime Baby": .amp, "Fullerton Reverb": .amp, "Fullerton Deluxe": .amp, "Fullerton Princeton": .amp, "Fullerton Drive": .amp, "Jazz Clean": .amp, "Chime Top Boost": .amp, "Neural Amp": .amp, "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, diff --git a/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift b/Sources/LyrebirdShoeGazeUI/PedalPaletteView.swift index 382f000..01c75f5 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] = [ - "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Princeton", "Jazz Clean", "Chime Top Boost", "Neural Amp", "Overdrive", "Distortion", "Compressor", "Sustainer", "Limiter", "Noise Gate", "Fuzz", + "California", "British", "British Plexi", "British JTM", "British Bluesbreaker", "Chime", "Chime 15", "Chime Normal", "Chime Baby", "Fullerton Reverb", "Fullerton Deluxe", "Fullerton Princeton", "Fullerton Drive", "Jazz Clean", "Chime Top Boost", "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/PedalSwitchView.swift b/Sources/LyrebirdShoeGazeUI/PedalSwitchView.swift index c776b65..1b24e7f 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalSwitchView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalSwitchView.swift @@ -49,6 +49,9 @@ public struct PedalSwitchView: View { // MARK: - Properties private let pedalSwitch: PedalSwitch + /// Called once when a tap commits a different position — used to trigger a board rebuild for + /// `rebuildsOnChange` switches (e.g. a channel switch). `nil` for plain switches. + private let onCommit: (() -> Void)? @Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool @@ -56,9 +59,13 @@ public struct PedalSwitchView: View { /// Creates a segmented switch view. /// - /// - Parameter pedalSwitch: The discrete switch descriptor to render. - public init(_ pedalSwitch: PedalSwitch) { + /// - Parameters: + /// - pedalSwitch: The discrete switch descriptor to render. + /// - onCommit: Called when a tap selects a different position. Used for `rebuildsOnChange` + /// switches; `nil` otherwise. + public init(_ pedalSwitch: PedalSwitch, onCommit: (() -> Void)? = nil) { self.pedalSwitch = pedalSwitch + self.onCommit = onCommit } // MARK: - Body @@ -97,7 +104,9 @@ public struct PedalSwitchView: View { private func segment(option: PedalSwitch.Option, isActive: Bool) -> some View { Button(action: { + let changed: Bool = option.value != pedalSwitch.node.value pedalSwitch.node.update(option.value) + if changed { onCommit?() } }) { Text(option.title) .font(.system(size: PedalSwitchView.fontSize, weight: .semibold)) diff --git a/Sources/LyrebirdShoeGazeUI/PedalView.swift b/Sources/LyrebirdShoeGazeUI/PedalView.swift index 0b3701d..9966b4b 100644 --- a/Sources/LyrebirdShoeGazeUI/PedalView.swift +++ b/Sources/LyrebirdShoeGazeUI/PedalView.swift @@ -29,6 +29,7 @@ private func enclosureColor(for displayName: String) -> Color { case "Fullerton Reverb": return Color(red: 0.15, green: 0.22, blue: 0.30) // blackface panel case "Fullerton Deluxe": return Color(red: 0.17, green: 0.20, blue: 0.26) // blackface, warmer case "Fullerton Princeton": return Color(red: 0.19, green: 0.19, blue: 0.23) // small blackface + case "Fullerton Drive": return Color(red: 0.22, green: 0.18, blue: 0.24) // two-channel combo case "Jazz Clean": return Color(red: 0.14, green: 0.30, blue: 0.34) // solid-state silver-teal case "Chime Top Boost": return Color(red: 0.20, green: 0.32, blue: 0.20) // vox-green tolex case "Neural Amp": return Color(red: 0.22, green: 0.16, blue: 0.30) // deep neural violet @@ -824,7 +825,12 @@ public struct PedalView: View { if !switches.isEmpty { HStack(alignment: .top, spacing: PedalView.knobSpacing) { ForEach(Array(switches.enumerated()), id: \.offset) { pair in - PedalSwitchView(pair.element) + PedalSwitchView( + pair.element, + onCommit: pair.element.rebuildsOnChange + ? { [pedal, pedalRebuildAction] in pedalRebuildAction(pedal) } + : nil + ) } } } diff --git a/Tests/LyrebirdShoeGazeTests/FullertonDriveAmpPedalTests.swift b/Tests/LyrebirdShoeGazeTests/FullertonDriveAmpPedalTests.swift new file mode 100644 index 0000000..01b48ed --- /dev/null +++ b/Tests/LyrebirdShoeGazeTests/FullertonDriveAmpPedalTests.swift @@ -0,0 +1,128 @@ +// FullertonDriveAmpPedalTests.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("FullertonDriveAmpPedal") +struct FullertonDriveAmpPedalTests { + + private let sampleRate: Double = 48000.0 + + private func render(configure: (FullertonDriveAmpPedal) -> Void = { _ in }) throws -> [Float] { + let (engine, url): (SynthesisEngine, URL) = makeNRTEngine( + duration: 0.3, 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: FullertonDriveAmpPedal = FullertonDriveAmpPedal( + 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 buildsNonSilentFiniteOutput() throws { + let samples: [Float] = try render() + #expect(hasNonSilentOutput(samples), "Fullerton Drive produced silence") + #expect(samples.allSatisfy { $0.isFinite }, "Fullerton Drive produced non-finite output") + } + + @Test func channelSwitchChangesOutput() throws { + // The value is read at build time (rebuildsOnChange); configure runs before build, so the + // Drive channel cascades its extra stage. + let clean: [Float] = try render { $0.channel = 0.0 } + let drive: [Float] = try render { $0.channel = 1.0; $0.drive = 15.0 } + #expect(hasNonSilentOutput(clean) && hasNonSilentOutput(drive)) + #expect(windowedSSD(clean, drive) > 0, "channel switch had no effect") + } + + @Test func driveKnobChangesDriveChannel() throws { + let low: [Float] = try render { $0.channel = 1.0; $0.drive = 2.0 } + let high: [Float] = try render { $0.channel = 1.0; $0.drive = 25.0 } + #expect(windowedSSD(low, high) > 0, "Drive knob had no effect on the drive channel") + } + + @Test func reverbAndBrightChangeOutput() throws { + let dry: [Float] = try render { $0.reverb = 0.0 } + let wet: [Float] = try render { $0.reverb = 0.9 } + #expect(windowedSSD(dry, wet) > 0, "reverb had no effect") + let flat: [Float] = try render { $0.bright = 0.0 } + let bright: [Float] = try render { $0.bright = 1.0 } + #expect(windowedSSD(flat, bright) > 0, "bright switch had no effect") + } + + @Test func channelSwitchRebuildsOnChange() throws { + let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal() + let channel: PedalSwitch? = pedal.effectSwitches.first { $0.label == "Channel" } + #expect(channel?.rebuildsOnChange == true, "Channel switch should rebuild on change") + } + + @Test func outputStaysWithinCeilingOnDriveChannel() throws { + let ceilingEpsilon: Double = 1.0e-4 + let hot: [Float] = try render { (pedal: FullertonDriveAmpPedal) in + pedal.gain = 30.0 + pedal.bass = 1.0 + pedal.treble = 1.0 + pedal.reverb = 1.0 + pedal.bright = 1.0 + pedal.channel = 1.0 + pedal.drive = 30.0 + } + let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) } + #expect(peak <= 1.0 + ceilingEpsilon, "peak \(peak) exceeds the ±1 ceiling on the drive channel") + #expect(peak > 0.3, "unexpectedly quiet: \(peak)") + } + + @Test func exposesControlSurface() throws { + let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal() + #expect(pedal.effectKnobs.map { $0.label } == ["Gain", "Bass", "Mid", "Treble", "Reverb", "Drive"]) + #expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Channel"]) + #expect(pedal.effectSelectors.map { $0.label } == ["Cab"]) + #expect(pedal.widthUnits == 3) + #expect(pedal.toneStackModel == .fender) + } + + @Test func controlsRoundTripThroughState() throws { + let pedal: FullertonDriveAmpPedal = FullertonDriveAmpPedal() + pedal.reverb = 0.6 + pedal.drive = 12.0 + pedal.bright = 1.0 + pedal.channel = 1.0 + pedal.cab = 2.0 + let restored: FullertonDriveAmpPedal = FullertonDriveAmpPedal() + restored.applyState(pedal.captureState()) + #expect(restored.reverb == 0.6 && restored.drive == 12.0) + #expect(restored.bright == 1.0 && restored.channel == 1.0 && restored.cab == 2.0) + } + + @Test func registeredInBuiltInRegistry() throws { + #expect(PedalRegistry.makePedal(type: "Fullerton Drive") is FullertonDriveAmpPedal) + } +} diff --git a/Tests/LyrebirdShoeGazeTests/JazzCleanAmpPedalTests.swift b/Tests/LyrebirdShoeGazeTests/JazzCleanAmpPedalTests.swift index d28753a..ed37016 100644 --- a/Tests/LyrebirdShoeGazeTests/JazzCleanAmpPedalTests.swift +++ b/Tests/LyrebirdShoeGazeTests/JazzCleanAmpPedalTests.swift @@ -123,6 +123,16 @@ struct JazzCleanAmpPedalTests { #expect(windowedSSD(flat, bright) > 0, "bright switch had no effect") } + @Test func distortionChannelChangesOutput() throws { + // Channel is read at build time (rebuildsOnChange); configure runs before build, so the + // Distortion channel cascades its extra gain stage. + let clean: [Float] = try renderStereo { $0.channel = 0.0 }.left + let dist: [Float] = try renderStereo { $0.channel = 1.0; $0.drive = 18.0 }.left + #expect(windowedSSD(clean, dist) > 0, "distortion channel had no effect") + let channel: PedalSwitch? = JazzCleanAmpPedal().effectSwitches.first { $0.label == "Channel" } + #expect(channel?.rebuildsOnChange == true, "Channel switch should rebuild on change") + } + @Test func bothChannelsStayWithinCeilingWithFXEngaged() throws { let ceilingEpsilon: Double = 1.0e-4 let (left, right): ([Float], [Float]) = try renderStereo { (pedal: JazzCleanAmpPedal) in @@ -141,8 +151,8 @@ struct JazzCleanAmpPedalTests { @Test func exposesFullControlSurface() throws { let pedal: JazzCleanAmpPedal = JazzCleanAmpPedal() #expect(pedal.effectKnobs.map { $0.label } - == ["Gain", "Bass", "Mid", "Treble", "Reverb", "Rate", "Depth"]) - #expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Chorus"]) + == ["Gain", "Bass", "Mid", "Treble", "Reverb", "Rate", "Depth", "Drive"]) + #expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Chorus", "Channel"]) #expect(pedal.effectSelectors.map { $0.label } == ["Cab"]) #expect(pedal.effectSelectors.first?.rebuildsOnChange == true) #expect(pedal.widthUnits == 3) @@ -159,6 +169,8 @@ struct JazzCleanAmpPedalTests { pedal.chorusDepth = 0.008 pedal.bright = 1.0 pedal.chorusEnabled = 0.0 + pedal.channel = 1.0 + pedal.drive = 11.0 pedal.cab = 3.0 let restored: JazzCleanAmpPedal = JazzCleanAmpPedal() restored.applyState(pedal.captureState()) @@ -168,6 +180,7 @@ struct JazzCleanAmpPedalTests { #expect(restored.chorusDepth == 0.008) #expect(restored.bright == 1.0) #expect(restored.chorusEnabled == 0.0) + #expect(restored.channel == 1.0 && restored.drive == 11.0) #expect(restored.cab == 3.0) }