Add live-input mic permission, audio-input entitlement, and engine-config review fixes
Live input was silent on macOS because the apps ran under hardened runtime without the microphone entitlement, so AUHAL input received silent zeros and the OS never prompted. Fixes: - Add com.apple.security.device.audio-input entitlement to the macOS Builder and Demo apps (CODE_SIGN_ENTITLEMENTS wired in both targets). - Add MicrophonePermission helper (AVCaptureDevice.requestAccess) and gate live-input selection through it in the Builder view and Demo controller; deny falls back to the test loop with an explanatory alert. - Fix ShoeGazeDemo inputChannels 6 -> 1 (built-in mics are mono; 6 made CoreAudio deliver silence). Engine-config review fixes: - installScopeTap now requires the engine stopped (precondition) and reconfigureEngine reinstalls the tap on every exit path via defer, so engine.scopeTap never points at a stale channel layout. - EngineConfigView stops the engine on a post-start (iOS) sample-rate mismatch instead of running pitch-shifted, and surfaces non-mismatch start errors through the alert. - Remove redundant installScopeTap call in the demo controller (ShoeGaze.init already installs it). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Bumped on transport/edit actions to force a re-read of `engine.isRunning`.
|
||||
@State private var transportTick: Bool = false
|
||||
|
||||
/// Shown when live input is selected but microphone access is denied/restricted.
|
||||
@State private var showMicDeniedAlert: Bool = false
|
||||
|
||||
#if !os(macOS)
|
||||
/// iOS file-dialog presentation flags + the document to export. (macOS uses the File menu.)
|
||||
@State private var showImporter: Bool = false
|
||||
@@ -117,6 +120,12 @@ public struct ShoeGazeBuilderView: View {
|
||||
blue: ShoeGazeBuilderView.backgroundBlue
|
||||
)
|
||||
)
|
||||
.alert("Microphone Access Needed", isPresented: $showMicDeniedAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
} message: {
|
||||
Text("Live input needs microphone access. Enable it in System Settings › Privacy & "
|
||||
+ "Security › Microphone, then select the input again.")
|
||||
}
|
||||
#if !os(macOS)
|
||||
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.json]) { result in
|
||||
handleImport(result)
|
||||
@@ -305,7 +314,23 @@ public struct ShoeGazeBuilderView: View {
|
||||
}
|
||||
|
||||
/// Switches input source, stopping/restarting the engine around the graph rebuild.
|
||||
///
|
||||
/// Live input requires microphone authorisation first — without it macOS feeds the AUHAL
|
||||
/// input silent zeros. The request is asynchronous, so when the source is `.liveInput` the
|
||||
/// actual switch is deferred until the grant resolves; a denial falls back to the test loop.
|
||||
private func switchInput(to source: InputSource) {
|
||||
guard case .liveInput = source else {
|
||||
applyInputSource(source)
|
||||
return
|
||||
}
|
||||
MicrophonePermission.request { granted in
|
||||
if !granted { showMicDeniedAlert = true }
|
||||
applyInputSource(granted ? source : .testLoop)
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies an input-source change, stopping/restarting the engine around the graph rebuild.
|
||||
private func applyInputSource(_ source: InputSource) {
|
||||
let wasRunning: Bool = shoeGaze.engine.isRunning
|
||||
if wasRunning { shoeGaze.engine.stop() }
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user