Persist I/O + input via the rig, not UserDefaults

The rig snapshot already stores inputSource + input/output channel counts and
syncs them via the autosave envelope and the iCloud rig library. Make that the
single source of truth instead of the parallel UserDefaults path.

- RigStore.restore applies the saved channel layout (applyChannelLayout) before
  loadRig, while stopped at launch, so a saved live-input channel validates
  against the restored count instead of falling back to the test loop. The
  general loadRig policy (don't force layout mid-session) is unchanged.
- applyInputSource and the engine-config onConfigApplied now autosave, so input
  and I/O changes are captured into the rig immediately.
- Remove the UserDefaults keys and read/write sites: ShoeGaze.inputSelection
  (builder view + iOS model) and the ShoeGaze.inputChannels/outputChannels keys
  added earlier (EngineConfigView + both app targets build at the default layout
  now; RigStore.restore supplies the rig's layout).
- Fresh-launch default: the seed paths set inputSource = liveInput(0) when the
  engine has an input channel, so a first launch listens to the instrument. A
  restored rig keeps its own saved input; the view's on-appear hook only requests
  mic access for a restored live selection (test-loop fallback on denial).

Test: RigStore.restoreAppliesSavedChannelLayoutAndInput. 461 tests pass; both
app targets build.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-11 15:34:23 -07:00
parent 5987ec7b78
commit cc3a986cde
7 changed files with 121 additions and 133 deletions
@@ -31,10 +31,6 @@ public struct EngineConfigView: View {
/// Channel-count stepper bounds.
private static let maxInputs: Int = 8
private static let maxOutputs: Int = 8
/// UserDefaults keys persisting the last-used engine channel counts so they survive relaunch.
/// The app targets read these when constructing the engine (fallback to their own defaults).
static let inputChannelsDefaultsKey: String = "ShoeGaze.inputChannels"
static let outputChannelsDefaultsKey: String = "ShoeGaze.outputChannels"
/// Sample-rate comparison tolerance in Hz.
private static let rateEpsilon: Double = 0.5
private static let rowSpacing: CGFloat = 12
@@ -166,21 +162,12 @@ public struct EngineConfigView: View {
outputChannels: pendingOutputs
)
}
persistChannelCounts()
onConfigApplied()
} catch {
print("[EngineConfigView] live reconfigure failed: \(error)")
}
}
/// Persists the current channel counts so the next launch rebuilds the engine with the same
/// I/O. Read by the app targets at engine-construction time.
private func persistChannelCounts() {
let defaults: UserDefaults = UserDefaults.standard
defaults.set(pendingInputs, forKey: EngineConfigView.inputChannelsDefaultsKey)
defaults.set(pendingOutputs, forKey: EngineConfigView.outputChannelsDefaultsKey)
}
private func label(_ text: String) -> some View {
Text(text)
.font(.subheadline)
@@ -205,7 +192,6 @@ public struct EngineConfigView: View {
outputChannels: pendingOutputs
)
}
persistChannelCounts()
}
try shoeGaze.engine.start()
} catch {