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:
2026-07-11 15:17:51 -07:00
parent f61961b90b
commit 5987ec7b78
14 changed files with 382 additions and 8 deletions
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Internal synthesizer that copies one hardware input bus to a board head bus.
///
@@ -18,6 +19,17 @@ import LyrebirdSynth
/// `teardown()` releases the head bus back to the allocator.
final class HardwareInputPassThrough: SynthesizerBase {
// MARK: - Parameters
/// Input mute — `0` = audible, `1` = muted (a hard gate on the incoming signal, distinct from
/// the rig-output mute). Driven across every board input node by `ShoeGaze.setInputMuted(_:)`,
/// which sets a newly-added node to the session's current mute state. Defaults audible so
/// direct users (e.g. `ChainRouter`) that don't drive the mute pass the signal through.
@UIParam var inputMute: Double = 0.0
/// The live `UIParamNode` backing `inputMute`, driven by `ShoeGaze.setInputMuted(_:)`.
var inputMuteNode: UIParamNode { $inputMute }
// MARK: - Routing
/// Index of the hardware input bus to read from (typically `engine.numOutputChannels`).
@@ -26,6 +38,11 @@ final class HardwareInputPassThrough: SynthesizerBase {
/// Index of the board head bus to write to.
private let outputBusIndex: Int
// MARK: - Constants
/// Lag time in seconds for the mute transition — smooths audible ↔ muted to prevent clicks.
private let muteLagTime: Double = 0.02
// MARK: - Init
/// Creates a pass-through that copies `inputBusIndex` to `outputBusIndex`.
@@ -43,6 +60,9 @@ final class HardwareInputPassThrough: SynthesizerBase {
// MARK: - Build
override func build() {
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
// Gate the copied signal by a lagged mute: mute 0 → gain 1 (audible), 1 → gain 0 (silent).
let muteLagged: Lag.Control = Lag.Control(input: $inputMute, time: muteLagTime)
let muteGain: any ValidGeneratorInput = (muteLagged - 1.0) * -1.0
output(bus: outputBusIndex, source: input(bus: inputBusIndex) * muteGain)
}
}
@@ -5,6 +5,7 @@
// SPDX-License-Identifier: MIT
import LyrebirdSynth
import LyrebirdUI
/// Internal synthesizer that copies the shared global test-loop bus to a board head bus.
///
@@ -19,6 +20,16 @@ import LyrebirdSynth
/// - Note: Must be removed from the engine before the board's `teardown()` releases the head bus.
final class TestLoopTap: SynthesizerBase {
// MARK: - Parameters
/// Input mute — `0` = audible, `1` = muted. Driven across every board input node by
/// `ShoeGaze.setInputMuted(_:)`, which sets a newly-added node to the session's current mute
/// state. Defaults audible so direct users that don't drive the mute pass the signal through.
@UIParam var inputMute: Double = 0.0
/// The live `UIParamNode` backing `inputMute`, driven by `ShoeGaze.setInputMuted(_:)`.
var inputMuteNode: UIParamNode { $inputMute }
// MARK: - Routing
/// Index of the shared global test-loop bus to read from.
@@ -27,6 +38,11 @@ final class TestLoopTap: SynthesizerBase {
/// Index of the board head bus to write to.
private let outputBusIndex: Int
// MARK: - Constants
/// Lag time in seconds for the mute transition — smooths audible ↔ muted to prevent clicks.
private let muteLagTime: Double = 0.02
// MARK: - Init
/// Creates a tap that copies `inputBusIndex` (the global test bus) to `outputBusIndex`
@@ -44,6 +60,9 @@ final class TestLoopTap: SynthesizerBase {
// MARK: - Build
override func build() {
output(bus: outputBusIndex, source: input(bus: inputBusIndex))
// Gate the copied signal by a lagged mute: mute 0 → gain 1 (audible), 1 → gain 0 (silent).
let muteLagged: Lag.Control = Lag.Control(input: $inputMute, time: muteLagTime)
let muteGain: any ValidGeneratorInput = (muteLagged - 1.0) * -1.0
output(bus: outputBusIndex, source: input(bus: inputBusIndex) * muteGain)
}
}
@@ -360,6 +360,8 @@ public final class MIDIController {
shoeGaze.toggleRigBypassed()
case .rigMute:
shoeGaze.toggleRigMuted()
case .inputMute:
shoeGaze.toggleInputMuted()
case .allBoards:
// One-shot: cancel any solo and bring every board back up.
shoeGaze.selectAllBoards(crossfadeSeconds: boardActionCrossfade)
@@ -422,7 +424,7 @@ public final class MIDIController {
/// Not used for resolution (bindings resolve by UUID) — purely a human-readable snapshot.
private func hint(for action: MIDIMap.Action) -> String? {
switch action {
case .rigBypass, .rigMute, .allBoards:
case .rigBypass, .rigMute, .inputMute, .allBoards:
return nil
case .boardSolo(let boardID), .boardAudible(let boardID), .boardBypass(let boardID):
return board(id: boardID)?.label
@@ -72,6 +72,8 @@ public struct MIDIMap: Codable, Equatable, Sendable {
case rigBypass
/// Mutes/unmutes the rig output (a hard silence, not a bypass).
case rigMute
/// Mutes/unmutes the input feeding every board (the incoming guitar / mic signal).
case inputMute
/// Cancels any solo and makes every board audible again (the "All" button).
case allBoards
case boardSolo(boardID: UUID)
+39
View File
@@ -302,6 +302,7 @@ public final class ShoeGaze {
outputBusIndex: board.headBus.index
)
try engine.add(tap, position: NodePosition.after(source))
tap.inputMuteNode.update(inputMuted ? 1.0 : 0.0)
testLoopTaps.append(tap)
// Record the tap as the head input node so PedalBoard.add(_:) can chain the first
// pedal after it automatically (without needing an explicit `after:`).
@@ -317,6 +318,7 @@ public final class ShoeGaze {
outputBusIndex: board.headBus.index
)
try engine.add(passThrough)
passThrough.inputMuteNode.update(inputMuted ? 1.0 : 0.0)
inputPassThroughs.append(passThrough)
board.headInputNode = passThrough
}
@@ -433,6 +435,11 @@ public final class ShoeGaze {
/// `true` when the rig output is muted (hard-silenced, not bypassed). Survives a rebuild.
public private(set) var rigMuted: Bool = false
/// `true` when the **input** feeding every board is muted — the incoming guitar / mic signal,
/// distinct from ``rigMuted`` (the output). Defaults `true` and is re-asserted on each user
/// engine start so a fresh start is silent until the player un-mutes. See ``setInputMuted(_:)``.
public private(set) var inputMuted: Bool = true
/// Identities of boards currently in per-board full bypass. Observable so UI toggles refresh;
/// authoritative bypass value lives on each board's `boardBypassNode`. Transient (not persisted).
public private(set) var bypassedBoards: Set<ObjectIdentifier> = []
@@ -585,6 +592,38 @@ public final class ShoeGaze {
setRigMuted(!rigMuted)
}
/// Mutes or un-mutes the **input** feeding every board — the incoming guitar / mic signal,
/// distinct from the rig-output ``setRigMuted(_:)``. Applied to every board's input writer
/// (test-loop tap or hardware pass-through), smoothed to avoid clicks.
///
/// Defaults muted (``inputMuted`` starts `true`) and is re-asserted on each user engine start
/// so a fresh start is silent until the player un-mutes — preventing accidental input noise.
///
/// - Parameter muted: `true` to silence the input, `false` to let it through.
public func setInputMuted(_ muted: Bool) {
let value: Double = muted ? 1.0 : 0.0
for tap: TestLoopTap in testLoopTaps {
tap.inputMuteNode.update(value)
}
for passThrough: HardwareInputPassThrough in inputPassThroughs {
passThrough.inputMuteNode.update(value)
}
inputMuted = muted
}
/// Toggles the input mute. See ``setInputMuted(_:)``.
public func toggleInputMuted() {
setInputMuted(!inputMuted)
}
/// The live mute-gain values of every board input writer (test-loop taps and hardware
/// pass-throughs). `1` = muted, `0` = audible. Exposed for tests to confirm the RT nodes are
/// actually driven by ``setInputMuted(_:)``, not just the ``inputMuted`` flag.
var inputMuteNodeValues: [Double] {
testLoopTaps.map { $0.inputMuteNode.value }
+ inputPassThroughs.map { $0.inputMuteNode.value }
}
/// Removes a single board and its associated input source and output master from
/// the engine, then releases the board's buses. The other boards are unaffected.
///