iOS live input via permission-gated engine rebuild

Live input on iOS needs an input channel, but constructing the engine with one
up-front makes iOS prompt for the microphone at the first Start even in
test-loop mode. Instead the engine starts input-less (no prompt) and is rebuilt
on demand:

- ShoeGazeBuilderView gains an optional onEnableLiveInput hook. When the user
  picks live input but the engine has no input channel, the picker offers a
  "Live Input" option that calls the hook; the input binding routes there too.
  On macOS (engine already has an input channel) the hook is nil and live input
  is selected directly.
- The iOS app model implements the hook: request mic access, then on grant
  snapshot the rig (rigData), stop + teardown the engine, rebuild it with one
  input channel, restore the rig (loadRig), and select live input. The new
  ShoeGaze is published so the @Observable host view re-binds.
- Input persistence restores live on relaunch: a saved live choice with the mic
  already authorised triggers the same rebuild silently (no prompt).

Test: a rig captured on a 0-input engine restores onto a freshly built 1-input
engine and live input is then selectable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 20:52:11 -07:00
parent 4627b3b800
commit 705b4ed534
4 changed files with 208 additions and 37 deletions
@@ -39,6 +39,53 @@ struct ShoeGazeMultiBoardTests {
#expect(shoeGaze.boards.count == 2)
}
@Test func rigSnapshotRestoresAcrossEnginesWithInputChannel() throws {
// Backs the iOS "enable live input" rebuild: a rig captured on a 0-input engine must
// restore onto a freshly built 1-input engine, and live input must then be selectable.
let renderDuration: Double = 0.05
// Source engine: no input channels (the iOS default before live input is enabled).
let (engineA, urlA): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numInputChannels: 0,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: urlA) }
let shoeGazeA: ShoeGaze = ShoeGaze(engine: engineA)
let board1: PedalBoard = try shoeGazeA.addBoard()
board1.label = "Lead"
try shoeGazeA.appendPedal(type: "Overdrive", to: board1)
try shoeGazeA.finalizeBoard(board1)
let board2: PedalBoard = try shoeGazeA.addBoard()
board2.label = "Clean"
try shoeGazeA.appendPedal(type: "Graphic EQ", to: board2)
try shoeGazeA.finalizeBoard(board2)
let snapshot: Data = try shoeGazeA.rigData()
// Destination engine: one input channel (the rebuilt engine for live input).
let (engineB, urlB): (SynthesisEngine, URL) = makeNRTEngine(
duration: renderDuration,
numInputChannels: 1,
numAudioBuses: 64
)
defer { try? FileManager.default.removeItem(at: urlB) }
let shoeGazeB: ShoeGaze = ShoeGaze(engine: engineB)
try shoeGazeB.loadRig(from: snapshot)
// The rig round-trips: same board count and labels.
#expect(shoeGazeB.boards.count == 2)
#expect(shoeGazeB.boards.first?.label == "Lead")
#expect(shoeGazeB.boards.last?.label == "Clean")
// Live input is now selectable on the rebuilt engine.
#expect(throws: Never.self) {
try shoeGazeB.setInputSource(.liveInput(channel: 0))
}
}
@Test func soloBlendAndAllControlBoardAudibility() throws {
let renderDuration: Double = 0.05
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(