23d607b9fc
- AmpPedal: double-width (widthUnits 2) amp-head card so the four tone knobs + Amp/Cab selectors + master aren't cramped. Uses the generic single-column content (no greedy Spacers → no flow-canvas height issue). - Neural Amp model loader: PedalView renders, for a NeuralAmpPedal, a "Load Model…" picker (.fileImporter for .json) plus the loaded model's filename. Picking sets Pedal.resourcePath and asks the host to rebuild the board so the model applies live. Picker + AppKit stay in the UI layer (core imports none). - New `pedalRebuildAction` environment value (@MainActor @Sendable), installed by ShoeGazeBuilderView; it resolves the pedal's board via a new branch-aware `ShoeGaze.board(containing:)` (finds pedals inside parallel / stereo-split branches, not just the main chain) and rebuilds it via the live-safe `rebuildBoard(_:from:)`. Tests: AmpPedal widthUnits == 2; board(containing:) finds main + branch pedals and returns nil for a stranger. Full suite 502. (SwiftUI loader flow needs on-device visual QA.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
109 lines
4.3 KiB
Swift
109 lines
4.3 KiB
Swift
// 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)
|
|
}
|
|
}
|