Add input mute + persist engine I/O counts
Input mute: a hard gate on the signal feeding every board (guitar / mic), distinct from the rig-output mute. Each board input writer (TestLoopTap / HardwareInputPassThrough) gains a lagged @UIParam mute gain; ShoeGaze holds inputMuted (default true), drives every input node, and brings newly-added boards up at the current state. A deliberate user Start re-asserts the mute so a fresh engine is silent until the player un-mutes — cutting accidental noise. Toggle sits beside the Start/Stop transport and is MIDI mappable (MIDIMap.Action.inputMute). First launch now defaults to live In 0 instead of the test-loop arpeggio. I/O persistence: the engine's input/output channel counts now persist to UserDefaults (written by EngineConfigView, restored by the app targets at engine construction), so a multi-channel setup survives relaunch and a saved live-input channel stays valid — fixing the input selection reverting to the test loop after a restart. Tests: InputMuteTests (default-muted, node driving, per-board adoption, live path) + a MIDI PC input-mute latch test. StereoRouting render tests un-mute before rendering. 460 tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
// InputMuteTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
import LyrebirdUI
|
||||
@testable import LyrebirdShoeGaze
|
||||
|
||||
/// Tests for the input mute — the hard gate on the signal feeding every board, distinct from the
|
||||
/// rig-output mute.
|
||||
@MainActor
|
||||
@Suite("InputMute")
|
||||
struct InputMuteTests {
|
||||
|
||||
/// A fresh session defaults to input-muted, and every board's input writer comes up muted so a
|
||||
/// just-started engine is silent until the player un-mutes.
|
||||
@Test func defaultsMutedAndDrivesInputNodes() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
#expect(sg.inputMuted)
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
|
||||
#expect(!sg.inputMuteNodeValues.isEmpty)
|
||||
}
|
||||
}
|
||||
|
||||
/// `setInputMuted(false)` un-mutes every input node and clears the flag; re-muting restores it.
|
||||
@Test func setInputMutedDrivesAllNodes() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
sg.setInputMuted(false)
|
||||
#expect(!sg.inputMuted)
|
||||
let audible: Double = 0.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
||||
|
||||
sg.toggleInputMuted()
|
||||
#expect(sg.inputMuted)
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == muted })
|
||||
}
|
||||
}
|
||||
|
||||
/// A board added while the input is un-muted comes up audible — the current mute state is
|
||||
/// applied to newly-wired input nodes, not just the ones present when the toggle flipped.
|
||||
@Test func newBoardAdoptsCurrentMuteState() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(duration: 0.05, numAudioBuses: 256)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let first: PedalBoard = try sg.addBoard()
|
||||
try first.add(VolumePedal())
|
||||
try sg.finalizeBoard(first)
|
||||
|
||||
sg.setInputMuted(false)
|
||||
|
||||
let second: PedalBoard = try sg.addBoard()
|
||||
try second.add(VolumePedal())
|
||||
try sg.finalizeBoard(second)
|
||||
|
||||
let audible: Double = 0.0
|
||||
#expect(sg.inputMuteNodeValues.count == 2)
|
||||
#expect(sg.inputMuteNodeValues.allSatisfy { $0 == audible })
|
||||
}
|
||||
}
|
||||
|
||||
/// The live-input pass-through path is driven identically to the test-loop tap path.
|
||||
@Test func liveInputPassThroughIsMuted() throws {
|
||||
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
||||
duration: 0.05,
|
||||
numOutputChannels: 2,
|
||||
numInputChannels: 1,
|
||||
numAudioBuses: 256
|
||||
)
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
let sg: ShoeGaze = ShoeGaze(engine: engine, inputSource: .liveInput(channel: 0))
|
||||
|
||||
try withExtendedLifetime(sg) {
|
||||
let board: PedalBoard = try sg.addBoard()
|
||||
try board.add(VolumePedal())
|
||||
try sg.finalizeBoard(board)
|
||||
|
||||
let muted: Double = 1.0
|
||||
#expect(sg.inputMuted)
|
||||
#expect(sg.inputMuteNodeValues == [muted])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,6 +80,26 @@ struct MIDIControllerPCTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test func inputMuteLatchesOnEachPressAndIsSeparateFromRigMute() throws {
|
||||
let (controller, sg, _, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
withExtendedLifetime(sg) {
|
||||
// A fresh session starts input-muted by default.
|
||||
#expect(sg.inputMuted == true, "input defaults muted")
|
||||
|
||||
controller.armSwitchLearn(.inputMute)
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2)) // learn only
|
||||
#expect(sg.inputMuted == true, "learn must not toggle")
|
||||
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == false, "first press un-mutes the input")
|
||||
#expect(sg.rigMuted == false, "input mute must not touch the rig-output mute")
|
||||
controller.ingestForTesting(.programChange(channel: 0, program: 2))
|
||||
#expect(sg.inputMuted == true, "second press re-mutes the input")
|
||||
}
|
||||
}
|
||||
|
||||
@Test func pedalBypassLatches() throws {
|
||||
let (controller, sg, boards, url): (MIDIController, ShoeGaze, [PedalBoard], URL) = try makeRig()
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
@@ -70,6 +70,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight != nil, "Stereo board should have a right tail bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -103,6 +104,7 @@ struct StereoRoutingTests {
|
||||
#expect(delay.outputBusRight != nil, "Auto-stereoized pedal should have a right output bus")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -128,6 +130,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "Stereo-native pedal should widen a mono board")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -156,6 +159,7 @@ struct StereoRoutingTests {
|
||||
|
||||
try board.add(ReverbPedal()) // mono pedal after merge, width-1
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
@@ -203,6 +207,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.width == 2, "collectStereo should make the board stereo")
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
return deinterleave(readStereoCAF(url: url))
|
||||
@@ -292,6 +297,7 @@ struct StereoRoutingTests {
|
||||
#expect(board.outputBusRight == nil)
|
||||
|
||||
try shoeGaze.finalizeBoard(board)
|
||||
shoeGaze.setInputMuted(false) // input defaults muted; un-mute so the test-loop signal renders
|
||||
try engine.start()
|
||||
|
||||
let samples: [Float] = readStereoCAF(url: url)
|
||||
|
||||
Reference in New Issue
Block a user