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
@@ -760,6 +760,7 @@ public struct ShoeGazeBuilderView: View {
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
rigBypassButton
rigMuteButton
inputMuteButton
helpButton
if let midi: MIDIController = midi {
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
@@ -1117,6 +1118,7 @@ public struct ShoeGazeBuilderView: View {
helpButton
rigBypassButton
rigMuteButton
inputMuteButton
EngineConfigView(
shoeGaze: shoeGaze,
hardwareSampleRate: hardwareSampleRate,
@@ -1202,6 +1204,22 @@ public struct ShoeGazeBuilderView: View {
.help("Mute the entire rig output — silences all sound")
}
/// Input-mute toggle, shown beside the Start/Stop transport. Silences the incoming guitar / mic
/// signal (distinct from the rig-output mute). Comes up muted on each engine start.
private var inputMuteButton: some View {
let muted: Bool = shoeGaze.inputMuted
return Button {
shoeGaze.toggleInputMuted()
} label: {
Label(muted ? "Input Muted" : "Mute Input",
systemImage: muted ? "mic.slash.fill" : "mic.fill")
.font(.subheadline)
}
.buttonStyle(.bordered)
.tint(muted ? .red : .gray)
.help("Mute the input feeding the pedals — silences the incoming guitar / mic signal")
}
// MARK: - Board area
private var boardArea: some View {
@@ -1396,9 +1414,15 @@ public struct ShoeGazeBuilderView: View {
onEnableLiveInput()
}
// A test-loop choice (or live with no host hook / no permission) leaves the test loop.
} else if MicrophonePermission.isAuthorized, shoeGaze.engine.numInputChannels > 0 {
// First launch with no saved choice but mic already granted → default to live input.
} else if shoeGaze.engine.numInputChannels > 0 {
// First launch, no saved choice → default to live input In 0 rather than the test-loop
// arpeggio. `switchInput` requests mic access and falls back to the test loop on denial.
switchInput(to: .liveInput(channel: 0))
} else if let onEnableLiveInput, MicrophonePermission.isAuthorized {
// iOS first launch with no input channel yet but mic already granted → rebuild with a
// live input silently. (Undetermined permission stays on the test loop to avoid an
// unprompted rebuild; the user can enable live input explicitly.)
onEnableLiveInput()
}
}