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:
@@ -33,26 +33,6 @@ 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
|
||||
@@ -115,23 +95,13 @@ 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
|
||||
)
|
||||
// The engine is built with the default layout; the autosaved rig's saved I/O layout (if any)
|
||||
// is applied by `RigStore.restore` below, so a multi-channel setup survives relaunch.
|
||||
let engine: SynthesisEngine = SynthesisEngine(
|
||||
blockSize: AppDelegate.blockSize,
|
||||
sampleRate: AppDelegate.sampleRate,
|
||||
numOutputChannels: restoredOutputs,
|
||||
numInputChannels: restoredInputs,
|
||||
numOutputChannels: AppDelegate.outputChannels,
|
||||
numInputChannels: AppDelegate.inputChannels,
|
||||
numAudioBuses: AppDelegate.numAudioBuses,
|
||||
driver: coreDriver
|
||||
)
|
||||
@@ -159,6 +129,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||
|
||||
/// Seeds one board with a single pedal so the builder opens with an audible starting point.
|
||||
private static func seedInitialBoard(into shoeGaze: ShoeGaze) {
|
||||
// Fresh launch (no autosaved rig): default to live In 0 rather than the test-loop arpeggio,
|
||||
// so the app comes up listening to the instrument. A restored rig keeps its own saved input.
|
||||
if shoeGaze.engine.numInputChannels > 0 {
|
||||
shoeGaze.inputSource = .liveInput(channel: 0)
|
||||
}
|
||||
var created: PedalBoard?
|
||||
do {
|
||||
let board: PedalBoard = try shoeGaze.addBoard()
|
||||
|
||||
Reference in New Issue
Block a user