Files
ShoeGaze/Tests/LyrebirdShoeGazeTests/BoardSelectionTests.swift
T
2026-06-21 12:25:18 -07:00

101 lines
3.7 KiB
Swift

// BoardSelectionTests.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("Board selection / crossfade")
struct BoardSelectionTests {
@Test func selectBoardSetsSelectGainsAndCrossfadeTime() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
let board2: PedalBoard = try shoeGaze.addBoard()
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
// Default: both boards audible (select gain 1), no solo.
#expect(board1.selectGainNode?.value == 1.0)
#expect(board2.selectGainNode?.value == 1.0)
#expect(shoeGaze.activeBoardIndex == nil)
// Solo board 2 with a half-second crossfade.
let crossfadeSeconds: Double = 0.5
shoeGaze.selectBoard(board2, crossfadeSeconds: crossfadeSeconds)
#expect(board1.selectGainNode?.value == 0.0, "non-selected board fades out")
#expect(board2.selectGainNode?.value == 1.0, "selected board fades in")
#expect(board1.crossfadeTimeNode?.value == crossfadeSeconds)
#expect(board2.crossfadeTimeNode?.value == crossfadeSeconds)
#expect(shoeGaze.activeBoardIndex == 1)
// Back to all audible.
shoeGaze.selectAllBoards(crossfadeSeconds: crossfadeSeconds)
#expect(board1.selectGainNode?.value == 1.0)
#expect(board2.selectGainNode?.value == 1.0)
#expect(shoeGaze.activeBoardIndex == nil)
}
@Test func boardAddedWhileSoloedComesUpSilent() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.05,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
// Solo board 1.
shoeGaze.selectBoard(board1, crossfadeSeconds: 0.0)
// A board finalized while a solo is active must come up silent.
let board2: PedalBoard = try shoeGaze.addBoard()
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
#expect(board2.selectGainNode?.value == 0.0, "board added mid-solo must be muted")
#expect(board1.selectGainNode?.value == 1.0, "soloed board stays audible")
}
@Test func soloedBoardRendersNonSilent() throws {
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
duration: 0.2,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: url) }
let shoeGaze: ShoeGaze = ShoeGaze(engine: engine)
let board1: PedalBoard = try shoeGaze.addBoard()
try board1.add(OverdrivePedal())
try shoeGaze.finalizeBoard(board1)
let board2: PedalBoard = try shoeGaze.addBoard()
try board2.add(DelayPedal())
try shoeGaze.finalizeBoard(board2)
// Instant crossfade so the soloed board is full level immediately.
shoeGaze.selectBoard(board1, crossfadeSeconds: 0.0)
try engine.start()
let samples: [Float] = readStereoCAF(url: url)
#expect(!samples.isEmpty)
#expect(hasNonSilentOutput(samples), "soloed board should still produce audio")
}
}