1893576718
Headline: MIDI control for a Behringer FCB1010 (four phases). - MIDIController (Lyrebird MIDI client): connection indicator via source polling, background-queue->main-actor hop, MIDI Learn. - Volume and Wah pedals (Wah reuses the SVF bandpass sweep, driven by pedal position instead of an envelope follower). - CC -> any pedal knob (0-127 mapped across the knob range). - Program Change -> pedal/board/rig toggles: software latch for booleans, exclusive radio for board solo. Positional addressing with display-name hints; stale/out-of-range bindings are skipped, not fired. - Per-rig MIDIMap embedded in ShoeGazeState as an optional field (old rigs decode to nil; no preset version bump). Central MIDI Mapping sheet with Learn/Clear per control. Also included (same working branch): - Full board bypass and rig bypass (dry passthrough via cascaded crossfades in BoardOutputMaster), with UI toggles. - Horizontal pedal picker grouped by category in filter order. - Drag a palette pedal onto a chain card to insert before it (ShoeGaze.insertPedal); tap still appends. - iOS: guard macOS-only .menuStyle(.borderlessButton) to silence the _UIReparentingView warning; iCloud-unavailable alert; keep the device awake while audio runs. Tests: 24 added (Volume/Wah, MIDIMap Codable incl. legacy decode, CC and PC controller behavior, insert/bypass API). Full suite green; macOS and iOS app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
81 lines
3.0 KiB
Swift
81 lines
3.0 KiB
Swift
// WahPedalTests.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("WahPedal")
|
|
struct WahPedalTests {
|
|
|
|
/// Renders a Wah pedal at the given position / resonance and returns the stereo output.
|
|
private func render(position: Double, resonance: Double = 3.0) throws -> [Float] {
|
|
let renderDuration: Double = 0.2
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: renderDuration)
|
|
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: WahPedal = WahPedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
|
pedal.position = position
|
|
pedal.resonance = resonance
|
|
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)
|
|
}
|
|
|
|
/// Mean absolute difference between two equal-length renders.
|
|
private func meanAbsDiff(_ a: [Float], _ b: [Float]) -> Double {
|
|
let count: Int = min(a.count, b.count)
|
|
guard count > 0 else { return 0 }
|
|
var sum: Double = 0
|
|
for i: Int in 0 ..< count {
|
|
sum += abs(Double(a[i]) - Double(b[i]))
|
|
}
|
|
return sum / Double(count)
|
|
}
|
|
|
|
@Test func buildsAndProducesNonSilentOutput() throws {
|
|
let samples: [Float] = try render(position: 0.5)
|
|
#expect(!samples.isEmpty)
|
|
#expect(hasNonSilentOutput(samples), "WahPedal produced silence")
|
|
}
|
|
|
|
@Test func differentPositionsProduceDifferentOutput() throws {
|
|
let heel: [Float] = try render(position: 0.0)
|
|
let toe: [Float] = try render(position: 1.0)
|
|
// Sweeping the cutoff must audibly change the filtered signal.
|
|
let diff: Double = meanAbsDiff(heel, toe)
|
|
#expect(diff > 1e-4, "heel and toe positions produced near-identical output (diff \(diff))")
|
|
}
|
|
|
|
@Test func resonanceChangesOutput() throws {
|
|
let low: [Float] = try render(position: 0.5, resonance: 0.7)
|
|
let high: [Float] = try render(position: 0.5, resonance: 8.0)
|
|
let diff: Double = meanAbsDiff(low, high)
|
|
#expect(diff > 1e-4, "resonance change produced near-identical output (diff \(diff))")
|
|
}
|
|
|
|
@Test func exposesPositionAndResonanceKnobs() throws {
|
|
let pedal: WahPedal = WahPedal()
|
|
#expect(pedal.effectKnobs.map { $0.label } == ["Position", "Resonance"])
|
|
}
|
|
}
|