b29c8848ef
External review found the lagged mute gate leaks a faint transient (~-54 dB) on its first blocks: Lag seeds its state at 0, so gating on a lagged value never starts at exactly zero on a rig that comes up muted — the moment the mute is meant to keep things quiet. Measured directly via an NRT render. - Gate the input with a hard, un-lagged kill switch `(inputMute - 1) * -1` in both HardwareInputPassThrough and TestLoopTap. A muted node is then exactly silent from the first sample; a kill-switch mute is expected to be abrupt. Drop the now-unused muteLagTime constant. - Flip the library default to `inputMuted = false` (audible). Muting is the app's Start-time policy (EngineConfigView already re-asserts muted on user Start), so headless/offline library use isn't forced silent and render tests that route the test-loop through a board no longer depend on a leak to see signal. The pulsing glow now also starts at engine Start rather than before it. - Tests: add render-level mutedInputRendersSilent (exact silence) and unmutedInputRendersSignal; update the default-state and MIDI-latch expectations; drop the StereoRouting un-mutes that the leak had made necessary. - Plan doc: correct the mute default / gate description and the UserDefaults note. 463 tests pass; both app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
90 lines
4.7 KiB
Markdown
90 lines
4.7 KiB
Markdown
# 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:
|
||
|
||
- The app **re-asserts it muted every time the engine is (user-)started**, so a fresh start
|
||
is silent until the player un-mutes — kills accidental ruckus. (The library-level default is
|
||
*audible*; muting is the app's Start-time policy, so headless / offline library use isn't
|
||
forced silent.)
|
||
- 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 **hard** gain `(inputMute − 1)·−1` — an un-lagged kill switch. (A lagged
|
||
gate never settles to exactly zero on its first blocks and leaks a faint transient at the very
|
||
moment the mute is meant to keep things quiet; a kill-switch mute is expected to be abrupt.)
|
||
|
||
### ShoeGaze
|
||
|
||
- `public private(set) var inputMuted: Bool = false` (app mutes on Start)
|
||
- `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 + input via the rig (iCloud), not UserDefaults
|
||
|
||
The rig snapshot (`ShoeGazeState`) **already** persists `inputSource`, `numInputChannels`,
|
||
and `numOutputChannels`, and the autosave envelope + rig library (iCloud) already carry
|
||
them. Two problems remained:
|
||
|
||
1. `loadRig(from:)` deliberately does **not** apply the saved channel layout (forcing it on
|
||
every mid-session load would fight the global engine config / the iOS live-input rebuild).
|
||
So at **launch**, the engine kept the app default (1 in / 2 out); a saved live-input
|
||
channel `>=` that count failed validation and fell back to the test loop — the "In
|
||
doesn't persist" bug.
|
||
2. A **second, competing** persistence path (`ShoeGazeBuilderView`'s UserDefaults
|
||
`ShoeGaze.inputSelection`, plus the iOS model's copy) fought the rig's own `inputSource`.
|
||
|
||
Fix — make the rig the single source of truth:
|
||
|
||
- **Launch applies the saved layout.** `RigStore.restore` calls
|
||
`applyChannelLayout(from: state)` **before** `loadRig`, while the engine is stopped, so the
|
||
input-channel validation runs against the restored count. A launch restore is exactly the
|
||
place this is wanted (unlike a mid-session load), so the general `loadRig` policy is
|
||
unchanged.
|
||
- **Input changes autosave.** `applyInputSource` / the engine-config `onConfigApplied` call
|
||
`autosave()`, so a changed input or I/O layout is captured into the rig immediately.
|
||
- **No UserDefaults path.** The `ShoeGaze.inputSelection` key and its read/write sites (builder
|
||
view + iOS model) are removed; the engine channel counts are never persisted to UserDefaults at
|
||
all. The app targets build the engine at the default layout; `RigStore.restore` supplies the
|
||
rig's saved layout.
|
||
- **Fresh-launch default.** When there is no autosaved rig, the seed paths
|
||
(`AppDelegate.seedInitialBoard` / iOS `seedFallbackBoard`) set `inputSource = .liveInput(0)`
|
||
when the engine has an input channel, so a first launch listens to the instrument rather
|
||
than the test loop. A restored rig keeps its own saved input. The builder view's on-appear
|
||
hook now only requests mic access for a restored live-input selection (falling back to the
|
||
test loop on denial).
|
||
|
||
## 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`.
|