diff --git a/AR-MIX-Live-FX-Host-Standalone-v0.3.html b/AR-MIX-Live-FX-Host-Standalone-v0.3.html index b0c4ee273..afbc1c25b 100644 --- a/AR-MIX-Live-FX-Host-Standalone-v0.3.html +++ b/AR-MIX-Live-FX-Host-Standalone-v0.3.html @@ -3262,7 +3262,7 @@ let mode='FX', lastStatus={}, deviceInventory=null, ioTab='device', lastSignature='', focusedInput=2; let monitorSendsExpanded=false; // DEVICE1: staged selections are UI-only; only positive native ACK changes active hardware. - let deviceDraft=null,deviceBusy=false,deviceNote='',deviceRequest='',deviceRequestSeq=0,lastDeviceRefresh=0; + let deviceDraft=null,deviceBusy=false,deviceNote='',deviceRequest='',deviceRequestSeq=0,lastDeviceRefresh=0,lastDeviceRescan=0; // Pending SOURCE ACK is a UI projection only; monitor.js owns the native route. let quickSourcePending=null; const el=id=>document.getElementById(id); @@ -4083,10 +4083,20 @@ (deviceSameEndpoint(d)&& (!pinsEqual(d.enabledInputs,a.enabledInputs)||!pinsEqual(d.enabledOutputs,a.enabledOutputs)))); } - function deviceRefresh(){ + function deviceRefresh(rescan=false){ if(!isNative()||deviceBusy)return; - const now=Date.now();if(now-lastDeviceRefresh<1000)return; - lastDeviceRefresh=now;backend.emitEvent('arMixAction',{action:'audioDeviceInventory'}); + const now=Date.now(); + if(rescan){ + if(now-lastDeviceRescan<1000)return; // one vendor scan per user action burst + lastDeviceRescan=now; + deviceNote='SCANNING DRIVER LIST · output must be MUTED'; + }else{ + if(now-lastDeviceRefresh<300)return; + lastDeviceRefresh=now; + } + backend.emitEvent('arMixAction',{ + action:rescan?'audioDeviceRefresh':'audioDeviceInventory' + }); } function deviceApply(){ if(!isNative()||deviceBusy||!deviceDraft||!deviceInventory?.active)return; @@ -4132,7 +4142,7 @@ 'NO VERIFIED DEVICE · select a reported interface and APPLY DEVICE')); if(!types.length){ panel.appendChild(node('p','arIODeviceEmpty', - isNative()?'Scanning actual Windows drivers. Use REFRESH DEVICE LIST if needed.': + isNative()?'No devices reported in the cached list. MUTE outputs, then press REFRESH DEVICE LIST to rescan.': 'Hardware cannot be changed in a browser-only preview.')); } else if(d){ const t=deviceType(d.backend),separate=!!t?.separate; @@ -4479,7 +4489,7 @@ if(b.dataset.ioClose!==undefined){e.preventDefault();e.stopImmediatePropagation();closeIO();return;} if(b.dataset.ioTab){e.preventDefault();e.stopImmediatePropagation();ioTab=b.dataset.ioTab;matrixMessage='';lastSignature='';refreshIO();return;} if(b.dataset.ioRefreshDevice!==undefined){ - e.preventDefault();e.stopImmediatePropagation();deviceRefresh();return; + e.preventDefault();e.stopImmediatePropagation();deviceRefresh(true);return; } if(b.dataset.ioDeviceApply!==undefined){ e.preventDefault();e.stopImmediatePropagation();deviceApply();return; @@ -4564,6 +4574,13 @@ const hadDraft=deviceDirty(); deviceInventory=d; if(!hadDraft&&!deviceBusy)deviceDraft=makeDeviceDraft(); + if(d?.scanState==='SCANNED') + deviceNote='DEVICE LIST REFRESHED · '+Number(d.scanDurationMs||0).toFixed(0)+' ms · output remains MUTED'; + else if(d?.scanState==='BLOCKED_ARMED') + deviceNote='REFRESH REJECTED · MUTE MAIN/OUTPUT1 and finish audio transitions first'; + else if(d?.scanState==='SCAN_ERROR') + deviceNote='DRIVER SCAN FAILED · current device remains unchanged'; + // CACHED is a non-disruptive snapshot; do not erase pending operator notes. lastSignature='';if(!overlay.hidden)refreshIO(); }); backend?.addEventListener?.('arMixAudioDeviceApplyAck',ack=>{ diff --git a/src/Main.cpp b/src/Main.cpp index 10938bf68..43c7cecf8 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -748,6 +748,56 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr // DEVICE1: the WebView2 matrix is the operator GUI; JUCE remains the // single device owner. No hardware calls ever run from the audio callback. + // DEVICE2: reading the device list must never repeatedly scan vendor + // drivers simply because the user opened the I/O matrix. JUCE has already + // enumerated device types during normal startup. An explicit REFRESH is the + // only additional scan, and is refused while any output is armed. + void emitDeviceInventory(bool explicitRescan) + { + const bool scanSafe=engine_.allOutputsDisarmed() + && !engine_.independentClockActive() + && !engine_.hasTemporaryDiagnosticDevice() + && !engine_.isGraphSwitchPending() + && !nativeShowBusy_ && !studioBackupBusy_; + const auto started=monotonicMilliseconds(); + juce::String scanState=explicitRescan?(scanSafe?"SCANNED":"BLOCKED_ARMED"):"CACHED"; + auto inventory=std::make_unique(); + juce::Array types; + auto& manager=engine_.devices(); + for(auto* type:manager.getAvailableDeviceTypes()) + { + if(type==nullptr)continue; + if(explicitRescan && scanSafe) + { + try { type->scanForDevices(); } + catch(const std::exception&) { scanState="SCAN_ERROR"; } + catch(...) { scanState="SCAN_ERROR"; } + } + auto item=std::make_unique(); + item->setProperty("name",type->getTypeName()); + item->setProperty("active",type->getTypeName()==manager.getCurrentAudioDeviceType()); + item->setProperty("separate",type->hasSeparateInputsAndOutputs()); + juce::Array inputs,outputs; + for(const auto& n:type->getDeviceNames(true))inputs.add(n); + for(const auto& n:type->getDeviceNames(false))outputs.add(n); + item->setProperty("inputs",juce::var(inputs)); + item->setProperty("outputs",juce::var(outputs)); + types.add(juce::var(item.release())); + } + const auto elapsed=monotonicMilliseconds()-started; + inventory->setProperty("types",juce::var(types)); + inventory->setProperty("currentType",manager.getCurrentAudioDeviceType()); + inventory->setProperty("active",currentDeviceSnapshot()); + inventory->setProperty("scanState",scanState); + inventory->setProperty("scanDurationMs",static_cast(elapsed)); + if(explicitRescan) + diagnostics_.record("DEVICE_REFRESH", + scanState+" | "+juce::String(static_cast(elapsed))+" ms"); + if(browser_.loaded) + browser_.emitEventIfBrowserIsVisible("arMixAudioDeviceInventory", + juce::var(inventory.release())); + } + juce::var currentDeviceSnapshot() { // This readback is used for UI and ACK, never to claim that a staged @@ -929,7 +979,13 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr (rate>0&&std::abs(actual.sampleRate-rate)>1.0)|| (block>0&&actual.bufferSize!=static_cast(block))|| (!candidate.useDefaultInputChannels&&actual.inputChannels!=candidate.inputChannels)|| - (!candidate.useDefaultOutputChannels&&actual.outputChannels!=candidate.outputChannels))) + (!candidate.useDefaultOutputChannels&&actual.outputChannels!=candidate.outputChannels)|| + opened->getActiveInputChannels()!=actual.inputChannels|| + opened->getActiveOutputChannels()!=actual.outputChannels|| + opened->getActiveInputChannels().countNumberOfSetBits()<1|| + opened->getActiveOutputChannels().countNumberOfSetBits()<2|| + std::abs(opened->getCurrentSampleRate()-actual.sampleRate)>1.0|| + opened->getCurrentBufferSizeSamples()!=actual.bufferSize)) error="Driver readback mismatch; device setting was not accepted"; if(error.isEmpty()&&!engine_.finishManualAudioSetup()) error="Device opened but direct safe production session was rejected"; @@ -1845,30 +1901,13 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr } else if (action == "audioDeviceInventory") { - // Explicit inventory request: no device re-open, no output arm. - auto inventory=std::make_unique(); - juce::Array types; - auto& manager=engine_.devices(); - for(auto* type:manager.getAvailableDeviceTypes()) { - if(type==nullptr)continue; - type->scanForDevices(); - auto item=std::make_unique(); - item->setProperty("name",type->getTypeName()); - item->setProperty("active",type->getTypeName()==manager.getCurrentAudioDeviceType()); - item->setProperty("separate",type->hasSeparateInputsAndOutputs()); - juce::Array inputs,outputs; - for(const auto& n:type->getDeviceNames(true))inputs.add(n); - for(const auto& n:type->getDeviceNames(false))outputs.add(n); - item->setProperty("inputs",juce::var(inputs)); - item->setProperty("outputs",juce::var(outputs)); - types.add(juce::var(item.release())); - } - inventory->setProperty("types",juce::var(types)); - inventory->setProperty("currentType",manager.getCurrentAudioDeviceType()); - inventory->setProperty("active",currentDeviceSnapshot()); - if(browser_.loaded) - browser_.emitEventIfBrowserIsVisible("arMixAudioDeviceInventory", - juce::var(inventory.release())); + // Fast read-only snapshot, no forced third-party ASIO scan. + emitDeviceInventory(false); + } + else if (action == "audioDeviceRefresh") + { + // Slow vendor rescan: deliberate operator request, MUTE required. + emitDeviceInventory(true); } else if (action == "audioDeviceApply") { diff --git a/tests/mixer_io_operator_contract_test.mjs b/tests/mixer_io_operator_contract_test.mjs index 932936e76..9e5baeaf7 100644 --- a/tests/mixer_io_operator_contract_test.mjs +++ b/tests/mixer_io_operator_contract_test.mjs @@ -240,6 +240,30 @@ test('SOURCE1 mute-only instant SOURCE uses one native ACK; armed output is reje assert.doesNotMatch(io,/new AudioContext\(/); }); + +test('DEVICE2 native device list is cached on overlay open; explicit scan is fail-closed',()=>{ + const native=read('src/Main.cpp'),gui=read('web/mixer-io.js'); + const section=native.slice(native.indexOf('else if (action == "audioDeviceInventory")'), + native.indexOf('else if (action == "audioDeviceApply")')); + assert.match(section,/emitDeviceInventory\(false\)/); + assert.match(section,/action == "audioDeviceRefresh"/); + assert.match(section,/emitDeviceInventory\(true\)/); + assert.doesNotMatch(section,/scanForDevices/); + const inventory=native.slice(native.indexOf('void emitDeviceInventory('), + native.indexOf('juce::var currentDeviceSnapshot()')); + assert.match(inventory,/explicitRescan && scanSafe/); + assert.match(inventory,/engine_\.allOutputsDisarmed\(\)/); + assert.match(inventory,/type->scanForDevices\(\)/); + assert.match(inventory,/scanDurationMs/); + assert.match(gui,/rescan\?'audioDeviceRefresh':'audioDeviceInventory'/); + assert.match(gui,/SCAN_ERROR|BLOCKED_ARMED/); + const apply=native.slice(native.indexOf('void applyCustomAudioDevice('), + native.indexOf('void showDeviceSetup()',native.indexOf('void applyCustomAudioDevice('))); + assert.match(apply,/opened->getActiveInputChannels\(\)!=actual\.inputChannels/); + assert.match(apply,/opened->getActiveOutputChannels\(\)!=actual\.outputChannels/); + assert.match(apply,/opened->getCurrentBufferSizeSamples\(\)!=actual\.bufferSize/); +}); + test('SOURCE2 selected-channel popover selects verified physical ports without a second router',()=>{ const js=read('web/mixer-io.js'); assert.match(js,/function refreshFocus\(s\)/); diff --git a/tests/mixer_io_smoke.py b/tests/mixer_io_smoke.py index 1a917ae62..1dcef4813 100644 --- a/tests/mixer_io_smoke.py +++ b/tests/mixer_io_smoke.py @@ -122,6 +122,15 @@ async def main(): {name:'DirectSound',active:false,separate:true, inputs:['Legacy Mic'],outputs:['Legacy Speakers']} ]})""") + # DEVICE2: opening custom panel reads cached hardware, never rescans vendors. + native_actions=await page.evaluate("""()=>window.__armixTestActions.filter(x=> + x.name==='arMixAction')""") + assert any(x['data']['action']=='audioDeviceInventory' for x in native_actions) + assert not any(x['data']['action']=='audioDeviceRefresh' for x in native_actions) + await page.locator('[data-io-refresh-device]').click() + refreshed=await page.evaluate("""()=>window.__armixTestActions.filter(x=> + x.name==='arMixAction'&&x.data.action==='audioDeviceRefresh')""") + assert len(refreshed)==1,refreshed assert await page.locator('.arIODeviceBackend').is_visible() assert await page.locator('.arIODevicePin').count()==8 assert await page.locator('.arIODeviceCapture').is_disabled() diff --git a/web/mixer-io.js b/web/mixer-io.js index ebb46c6b8..bfe9c5914 100644 --- a/web/mixer-io.js +++ b/web/mixer-io.js @@ -9,7 +9,7 @@ let mode='FX', lastStatus={}, deviceInventory=null, ioTab='device', lastSignature='', focusedInput=2; let monitorSendsExpanded=false; // DEVICE1: staged selections are UI-only; only positive native ACK changes active hardware. - let deviceDraft=null,deviceBusy=false,deviceNote='',deviceRequest='',deviceRequestSeq=0,lastDeviceRefresh=0; + let deviceDraft=null,deviceBusy=false,deviceNote='',deviceRequest='',deviceRequestSeq=0,lastDeviceRefresh=0,lastDeviceRescan=0; // Pending SOURCE ACK is a UI projection only; monitor.js owns the native route. let quickSourcePending=null; const el=id=>document.getElementById(id); @@ -830,10 +830,20 @@ (deviceSameEndpoint(d)&& (!pinsEqual(d.enabledInputs,a.enabledInputs)||!pinsEqual(d.enabledOutputs,a.enabledOutputs)))); } - function deviceRefresh(){ + function deviceRefresh(rescan=false){ if(!isNative()||deviceBusy)return; - const now=Date.now();if(now-lastDeviceRefresh<1000)return; - lastDeviceRefresh=now;backend.emitEvent('arMixAction',{action:'audioDeviceInventory'}); + const now=Date.now(); + if(rescan){ + if(now-lastDeviceRescan<1000)return; // one vendor scan per user action burst + lastDeviceRescan=now; + deviceNote='SCANNING DRIVER LIST · output must be MUTED'; + }else{ + if(now-lastDeviceRefresh<300)return; + lastDeviceRefresh=now; + } + backend.emitEvent('arMixAction',{ + action:rescan?'audioDeviceRefresh':'audioDeviceInventory' + }); } function deviceApply(){ if(!isNative()||deviceBusy||!deviceDraft||!deviceInventory?.active)return; @@ -879,7 +889,7 @@ 'NO VERIFIED DEVICE · select a reported interface and APPLY DEVICE')); if(!types.length){ panel.appendChild(node('p','arIODeviceEmpty', - isNative()?'Scanning actual Windows drivers. Use REFRESH DEVICE LIST if needed.': + isNative()?'No devices reported in the cached list. MUTE outputs, then press REFRESH DEVICE LIST to rescan.': 'Hardware cannot be changed in a browser-only preview.')); } else if(d){ const t=deviceType(d.backend),separate=!!t?.separate; @@ -1226,7 +1236,7 @@ if(b.dataset.ioClose!==undefined){e.preventDefault();e.stopImmediatePropagation();closeIO();return;} if(b.dataset.ioTab){e.preventDefault();e.stopImmediatePropagation();ioTab=b.dataset.ioTab;matrixMessage='';lastSignature='';refreshIO();return;} if(b.dataset.ioRefreshDevice!==undefined){ - e.preventDefault();e.stopImmediatePropagation();deviceRefresh();return; + e.preventDefault();e.stopImmediatePropagation();deviceRefresh(true);return; } if(b.dataset.ioDeviceApply!==undefined){ e.preventDefault();e.stopImmediatePropagation();deviceApply();return; @@ -1311,6 +1321,13 @@ const hadDraft=deviceDirty(); deviceInventory=d; if(!hadDraft&&!deviceBusy)deviceDraft=makeDeviceDraft(); + if(d?.scanState==='SCANNED') + deviceNote='DEVICE LIST REFRESHED · '+Number(d.scanDurationMs||0).toFixed(0)+' ms · output remains MUTED'; + else if(d?.scanState==='BLOCKED_ARMED') + deviceNote='REFRESH REJECTED · MUTE MAIN/OUTPUT1 and finish audio transitions first'; + else if(d?.scanState==='SCAN_ERROR') + deviceNote='DRIVER SCAN FAILED · current device remains unchanged'; + // CACHED is a non-disruptive snapshot; do not erase pending operator notes. lastSignature='';if(!overlay.hidden)refreshIO(); }); backend?.addEventListener?.('arMixAudioDeviceApplyAck',ack=>{