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
+34 -2
View File
@@ -33,6 +33,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
private static let inputChannels: Int = 1
private static let numAudioBuses: Int = 256
/// UserDefaults keys persisting the last-used engine channel counts. Must match the keys
/// written by the builder's engine-config UI (`EngineConfigView.inputChannelsDefaultsKey` /
/// `outputChannelsDefaultsKey`) so the choice survives relaunch.
private static let inputChannelsDefaultsKey: String = "ShoeGaze.inputChannels"
private static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
/// Reads a persisted channel count, clamped to `[minimum, 8]`, falling back to `fallback` when
/// no value has been saved yet.
private static func persistedChannelCount(
forKey key: String,
fallback: Int,
minimum: Int
) -> Int {
let defaults: UserDefaults = UserDefaults.standard
guard defaults.object(forKey: key) != nil else { return fallback }
let stored: Int = defaults.integer(forKey: key)
let maximumChannels: Int = 8
return max(minimum, min(stored, maximumChannels))
}
// MARK: - Window geometry constants
private static let windowWidth: CGFloat = 1_400
@@ -95,11 +115,23 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
override init() {
let coreDriver: CoreAudioDriver = CoreAudioDriver()
// Seed I/O from the last-used counts so a multi-input/output setup survives relaunch (and a
// saved live-input channel stays valid). Falls back to the built-in defaults on first launch.
let restoredOutputs: Int = AppDelegate.persistedChannelCount(
forKey: AppDelegate.outputChannelsDefaultsKey,
fallback: AppDelegate.outputChannels,
minimum: 1
)
let restoredInputs: Int = AppDelegate.persistedChannelCount(
forKey: AppDelegate.inputChannelsDefaultsKey,
fallback: AppDelegate.inputChannels,
minimum: 0
)
let engine: SynthesisEngine = SynthesisEngine(
blockSize: AppDelegate.blockSize,
sampleRate: AppDelegate.sampleRate,
numOutputChannels: AppDelegate.outputChannels,
numInputChannels: AppDelegate.inputChannels,
numOutputChannels: restoredOutputs,
numInputChannels: restoredInputs,
numAudioBuses: AppDelegate.numAudioBuses,
driver: coreDriver
)