Files
ShoeGaze/docs/plans/2.1.1-input-mute-and-io-persistence.md
T
josh 5987ec7b78 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>
2026-07-11 15:17:51 -07:00

3.3 KiB

2.1.1 — Input mute + I/O persistence

Two small, related fixes to cut down accidental noise at engine start and make the input configuration survive relaunch.

(a) Input mute toggle

A hard mute on the input feeding every board (the guitar / mic signal), distinct from the existing rig-output mute. Goals:

  • Defaults muted, and is re-asserted muted every time the engine is (user-)started, so a fresh start is silent until the player un-mutes — kills accidental ruckus.
  • A toggle button sits next to the Start/Stop transport.
  • MIDI mappable (Program Change + computer key), like Rig Mute.
  • Also default the input source to In 0 (live input) instead of the test-loop arpeggio.

RT graph

Each board's input writer (TestLoopTap in test-loop mode, HardwareInputPassThrough in live mode) gains an @UIParam inputMute (0 = audible, 1 = muted). build() multiplies the copied signal by a lagged mute gain (20 ms, click-free), mirroring BoardOutputMaster.rigOutputGainStage().

ShoeGaze

  • public private(set) var inputMuted: Bool = true
  • setInputMuted(_:) drives every testLoopTaps + inputPassThroughs mute node; toggleInputMuted().
  • addBoard() sets each new input node's mute to the current inputMuted so rebuilds stay consistent.

Engine start

EngineConfigView.startEngine() calls shoeGaze.setInputMuted(true) after a successful user Start. Transient stop/start-around-rebuild paths (applyInputSource, performClear) call engine.start() directly and are unaffected — they preserve the current mute state.

MIDI

  • MIDIMap.Action.inputMute
  • MIDIController.perform → toggleInputMuted(); hint → nil.
  • MIDIMappingSheet switch row "Input Mute".

Default to In 0

ShoeGazeBuilderView.restoreInputSelection() first-launch (no saved choice) branch requests mic access and selects .liveInput(channel: 0) (falling back to test loop on denial / no input), instead of only auto-selecting when already authorised.

(b) Persist In/Out channel counts (+ reliable last-input)

The last-used input selection already persists (ShoeGaze.inputSelection), but the engine's channel counts do not — so on relaunch the engine reverts to the app default (1 in / 2 out). A saved input channel >= the smaller default count then fails validation and silently falls back to the test loop. That is the "In doesn't persist" bug.

Fix: persist the channel counts too.

  • WRITE: EngineConfigView persists pendingInputs / pendingOutputs to UserDefaults (ShoeGaze.inputChannels / ShoeGaze.outputChannels) whenever they change while stopped.
  • READ/APPLY at launch, where the engine is actually constructed:
    • macOS AppDelegate: seed numInputChannels / numOutputChannels from the saved values (fallback 1 / 2).
    • iOS ShoeGazeBuilderiOSAppModel: seed numOutputChannels from saved (fallback 2). Input stays on the existing permission-gated rebuild flow.

Key strings are duplicated in the app targets with a "must match" comment, matching the existing convention for inputSelectionDefaultsKey.

Tests

  • InputMuteTests — HardwareInputPassThrough / TestLoopTap mute gain; ShoeGaze.setInputMuted drives all input nodes; addBoard brings a new board up at the current mute state.
  • MIDIController — an inputMute switch action toggles shoeGaze.inputMuted.