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
)
@@ -37,6 +37,9 @@ final class ShoeGazeBuilderiOSAppModel {
/// UserDefaults key persisting the input selection. Must match the key written by the
/// builder view (`ShoeGazeBuilderView.inputSelectionDefaultsKey`).
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
/// UserDefaults key persisting the last-used output-channel count. Must match the key written by
/// the builder's engine-config UI (`EngineConfigView.outputChannelsDefaultsKey`).
private static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
/// Persisted value meaning "live input, channel 0".
private static let liveInputChannelZeroTag: Int = 0
@@ -144,10 +147,17 @@ final class ShoeGazeBuilderiOSAppModel {
) -> (engine: SynthesisEngine, driver: iOSAudioDriver, shoeGaze: ShoeGaze) {
let sampleRate: Double = AVAudioSession.sharedInstance().sampleRate
let driver: iOSAudioDriver = iOSAudioDriver()
// Restore the last-used output count so it survives relaunch (input stays on the
// permission-gated rebuild flow). Falls back to the default on first launch.
let defaults: UserDefaults = UserDefaults.standard
let maximumChannels: Int = 8
let restoredOutputs: Int = defaults.object(forKey: outputChannelsDefaultsKey) != nil
? max(1, min(defaults.integer(forKey: outputChannelsDefaultsKey), maximumChannels))
: ShoeGazeBuilderiOSAppModel.outputChannels
let engine: SynthesisEngine = SynthesisEngine(
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
sampleRate: sampleRate,
numOutputChannels: ShoeGazeBuilderiOSAppModel.outputChannels,
numOutputChannels: restoredOutputs,
numInputChannels: inputChannels,
numAudioBuses: ShoeGazeBuilderiOSAppModel.numAudioBuses,
driver: driver