Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/FullertonVariantsTests.swift
T
josh 292261a088 refactor(ui): make widthUnits mean "base width in columns" + tidy overrides
Follow-up cleanup now that card width is content-derived. Redefine widthUnits
as the card's base width in knob columns (1 = 3-wide, 2 = 4-wide) — both the
knob-grid column count and the card's minimum width — with selector/switch rows
able to push wider. Values above 2 no longer do anything.

- Delete the now-misleading widthUnits 3/4 overrides on 11 amps; they inherit
  AmpVoicePedal's 2 (all full-surface amps → the same tight 4-wide card).
- Remove Mutant's redundant override (2 knobs + 2 switches → 3-wide either way).
- Cabinet: keep widthUnits 2 so it's 4-wide like the amps — its Cab/Mic/Mic B
  selector captions (voice names) need the room to stay readable (per request).
- Looper keeps widthUnits 3 (the one pedal still using the flat multiple for its
  bespoke timeline/knobs/transport layout).
- Refresh the widthUnits docs (base + AmpVoicePedal + Cabinet); update the amp
  tests' widthUnits assertions (3/4 → 2; Looper stays 3).

675 tests pass; no visual change to the amps, Cabinet now matches their width.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-05 09:05:40 -07:00

135 lines
6.4 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// FullertonVariantsTests.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("Fullerton blackface variants")
struct FullertonVariantsTests {
private let sampleRate: Double = 48000.0
private func render<P: AmpVoicePedal>(_ make: () -> P, configure: (P) -> 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: 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
}
}
private let variants: [(name: String, make: () -> FullertonReverbAmpPedal)] = [
("Fullerton Deluxe", { FullertonDeluxeAmpPedal() }),
("Fullerton Ivy League", { FullertonPrincetonAmpPedal() }),
]
@Test func bothBuildNonSilentFinite() throws {
for v: (name: String, make: () -> FullertonReverbAmpPedal) in variants {
let s: [Float] = try render(v.make)
#expect(hasNonSilentOutput(s), "\(v.name) produced silence")
#expect(s.allSatisfy { $0.isFinite }, "\(v.name) produced non-finite output")
}
}
@Test func variantsDifferFromTwinAndEachOther() throws {
// Same knob settings, different voicing (power-amp drive; plus cab for Princeton) → different output.
let cfg: (FullertonReverbAmpPedal) -> Void = { $0.gain = 6.0; $0.reverb = 0.3 }
let twin: [Float] = try render({ FullertonReverbAmpPedal() }, configure: cfg)
let deluxe: [Float] = try render({ FullertonDeluxeAmpPedal() }, configure: cfg)
let princeton: [Float] = try render({ FullertonPrincetonAmpPedal() }, configure: cfg)
#expect(windowedSSD(twin, deluxe) > 0, "Deluxe should differ from the Twin")
#expect(windowedSSD(deluxe, princeton) > 0, "Princeton should differ from the Deluxe")
}
@Test func inheritedReverbAndBrightWork() throws {
// The reverb knob and Bright switch are inherited from the Twin — spot-check on the Deluxe.
let dry: [Float] = try render({ FullertonDeluxeAmpPedal() }) { $0.reverb = 0.0 }
let wet: [Float] = try render({ FullertonDeluxeAmpPedal() }) { $0.reverb = 0.9 }
#expect(windowedSSD(dry, wet) > 0, "inherited reverb had no effect")
let flat: [Float] = try render({ FullertonPrincetonAmpPedal() }) { $0.bright = 0.0 }
let bright: [Float] = try render({ FullertonPrincetonAmpPedal() }) { $0.bright = 1.0 }
#expect(windowedSSD(flat, bright) > 0, "inherited bright switch had no effect")
}
@Test func stayWithinCeilingAtMaxGain() throws {
let ceilingEpsilon: Double = 1.0e-4
for v: (name: String, make: () -> FullertonReverbAmpPedal) in variants {
let hot: [Float] = try render(v.make) { (pedal: FullertonReverbAmpPedal) in
pedal.gain = 11.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.reverb = 1.0
pedal.bright = 1.0
pedal.intensity = 1.0
}
let peak: Double = hot.reduce(0.0) { Swift.max($0, abs(Double($1))) }
#expect(peak <= 1.0 + ceilingEpsilon, "\(v.name) peak \(peak) exceeds the ±1 ceiling")
}
}
@Test func inheritFullControlSurface() throws {
for v: (name: String, make: () -> FullertonReverbAmpPedal) in variants {
let pedal: FullertonReverbAmpPedal = v.make()
#expect(pedal.effectKnobs.map { $0.label }
== ["Gain", "Bass", "Mid", "Treble", "Reverb", "Speed", "Intensity"], "\(v.name) knobs")
#expect(pedal.effectSwitches.map { $0.label } == ["Bright", "Reverb FX", "Vibrato"], "\(v.name) switches")
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"], "\(v.name) selectors")
#expect(pedal.widthUnits == 2, "\(v.name) width")
#expect(pedal.toneStackModel == .fender, "\(v.name) tone stack")
#expect(pedal.powerAmpOversample == 4, "\(v.name) should oversample the harder-driven power amp at 4×")
}
}
@Test func reverbRoundTripsThroughState() throws {
let pedal: FullertonDeluxeAmpPedal = FullertonDeluxeAmpPedal()
pedal.reverb = 0.7
pedal.cab = 3.0
let restored: FullertonDeluxeAmpPedal = FullertonDeluxeAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.reverb == 0.7 && restored.cab == 3.0, "Deluxe state did not round-trip")
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Fullerton Deluxe") is FullertonDeluxeAmpPedal)
#expect(PedalRegistry.makePedal(type: "Fullerton Ivy League") is FullertonPrincetonAmpPedal)
}
@Test func legacyPrincetonNameStillResolves() throws {
// The pedal's display name was "Fullerton Princeton" when first shipped; rigs saved then key
// on that string. The legacy alias must still reconstruct the (renamed) pedal so it isn't
// silently dropped on load.
#expect(PedalRegistry.makePedal(type: "Fullerton Princeton") is FullertonPrincetonAmpPedal)
}
}