Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/ChimeTopBoostAmpPedalTests.swift
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

143 lines
6.1 KiB
Swift

// ChimeTopBoostAmpPedalTests.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("ChimeTopBoostAmpPedal")
struct ChimeTopBoostAmpPedalTests {
private let sampleRate: Double = 48000.0
private func render(configure: (ChimeTopBoostAmpPedal) -> 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: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal(
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(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "Chime Top Boost produced silence")
#expect(samples.allSatisfy { $0.isFinite }, "Chime Top Boost produced non-finite output")
}
@Test func cutChangesOutput() throws {
let open: [Float] = try render { $0.cut = 0.0 }
let dark: [Float] = try render { $0.cut = 1.0 }
#expect(windowedSSD(open, dark) > 0, "Cut had no effect")
}
@Test func tremoloIntensityChangesOutput() throws {
let off: [Float] = try render { $0.intensity = 0.0 }
let on: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0 }
#expect(windowedSSD(off, on) > 0, "tremolo intensity had no effect")
}
@Test func tremoloSpeedChangesOutput() throws {
let slow: [Float] = try render { $0.intensity = 1.0; $0.speed = 1.0 }
let fast: [Float] = try render { $0.intensity = 1.0; $0.speed = 10.0 }
#expect(windowedSSD(slow, fast) > 0, "tremolo speed had no effect")
}
@Test func brilliantSwitchChangesOutput() throws {
let flat: [Float] = try render { $0.brilliant = 0.0 }
let bright: [Float] = try render { $0.brilliant = 1.0 }
#expect(windowedSSD(flat, bright) > 0, "brilliant switch had no effect")
}
@Test func tremoloFootswitchBypassesToIdentity() throws {
// Footswitch off with Intensity up must equal no tremolo (Intensity 0), and differ from on.
// The differing `speed` is harmless: with depth gated to 0 the LFO is a constant 1.0.
let bypassed: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.tremoloEnabled = 0.0 }
let noTremolo: [Float] = try render { $0.intensity = 0.0 }
#expect(windowedSSD(bypassed, noTremolo) == 0.0, "tremolo footswitch off should be identity")
let engaged: [Float] = try render { $0.intensity = 1.0; $0.speed = 6.0; $0.tremoloEnabled = 1.0 }
#expect(windowedSSD(bypassed, engaged) > 0, "tremolo footswitch had no effect")
}
@Test func outputStaysWithinCeilingWithFXEngaged() throws {
let ceilingEpsilon: Double = 1.0e-4
let hot: [Float] = try render { (pedal: ChimeTopBoostAmpPedal) in
pedal.gain = 11.0
pedal.bass = 1.0
pedal.treble = 1.0
pedal.brilliant = 1.0
pedal.intensity = 1.0
pedal.speed = 6.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")
#expect(peak > 0.3, "unexpectedly quiet at max gain: \(peak)")
}
@Test func exposesFullControlSurface() throws {
let pedal: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
#expect(pedal.effectKnobs.map { $0.label }
== ["Gain", "Bass", "Mid", "Treble", "Cut", "Speed", "Intensity"])
#expect(pedal.effectSwitches.map { $0.label } == ["Brilliant", "Tremolo"])
#expect(pedal.effectSelectors.map { $0.label } == ["Cab"])
#expect(pedal.effectSelectors.first?.rebuildsOnChange == true)
#expect(pedal.widthUnits == 2)
#expect(pedal.showsMixControl == false)
#expect(pedal.toneStackModel == .vox)
}
@Test func controlsRoundTripThroughState() throws {
let pedal: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
pedal.gain = 7.0
pedal.cut = 0.6
pedal.speed = 9.0
pedal.intensity = 0.5
pedal.brilliant = 1.0
pedal.tremoloEnabled = 0.0
pedal.cab = 2.0
let restored: ChimeTopBoostAmpPedal = ChimeTopBoostAmpPedal()
restored.applyState(pedal.captureState())
#expect(restored.gain == 7.0)
#expect(restored.cut == 0.6)
#expect(restored.speed == 9.0)
#expect(restored.intensity == 0.5)
#expect(restored.brilliant == 1.0)
#expect(restored.tremoloEnabled == 0.0)
#expect(restored.cab == 2.0)
}
@Test func registeredInBuiltInRegistry() throws {
#expect(PedalRegistry.makePedal(type: "Chime Top Boost") is ChimeTopBoostAmpPedal)
}
}