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>
74 lines
2.8 KiB
Swift
74 lines
2.8 KiB
Swift
// VolumePedalTests.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("VolumePedal")
|
|
struct VolumePedalTests {
|
|
|
|
/// Renders a Volume pedal at the given position and returns the stereo output samples.
|
|
private func render(position: Double) 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: VolumePedal = VolumePedal(inputBus: srcBus.index, outputBus: dstBus.index)
|
|
pedal.position = position
|
|
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)
|
|
}
|
|
|
|
private func rms(_ samples: [Float]) -> Double {
|
|
guard !samples.isEmpty else { return 0 }
|
|
let sumSquares: Double = samples.reduce(0) { $0 + Double($1) * Double($1) }
|
|
return (sumSquares / Double(samples.count)).squareRoot()
|
|
}
|
|
|
|
@Test func buildsAndProducesNonSilentOutputAtUnity() throws {
|
|
let samples: [Float] = try render(position: 1.0)
|
|
#expect(!samples.isEmpty)
|
|
#expect(hasNonSilentOutput(samples), "VolumePedal at unity produced silence")
|
|
}
|
|
|
|
@Test func zeroPositionIsSilent() throws {
|
|
let samples: [Float] = try render(position: 0.0)
|
|
#expect(!hasNonSilentOutput(samples), "VolumePedal at position 0 should be silent")
|
|
}
|
|
|
|
@Test func positionScalesLevelMonotonically() throws {
|
|
let full: Double = rms(try render(position: 1.0))
|
|
let half: Double = rms(try render(position: 0.5))
|
|
let quarter: Double = rms(try render(position: 0.25))
|
|
#expect(full > half, "position 1.0 should be louder than 0.5")
|
|
#expect(half > quarter, "position 0.5 should be louder than 0.25")
|
|
}
|
|
|
|
@Test func exposesPositionKnob() throws {
|
|
let pedal: VolumePedal = VolumePedal()
|
|
// Effect knob (before the common Mix/Level pair) is Position.
|
|
#expect(pedal.effectKnobs.map { $0.label } == ["Position"])
|
|
}
|
|
}
|