Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions AR-MIX-Live-FX-Host-Standalone-v0.3.html
Original file line number Diff line number Diff line change
Expand Up @@ -3250,7 +3250,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);
Expand Down Expand Up @@ -4005,10 +4005,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;
Expand Down Expand Up @@ -4054,7 +4064,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;
Expand Down Expand Up @@ -4401,7 +4411,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;
Expand Down Expand Up @@ -4486,6 +4496,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=>{
Expand Down
89 changes: 64 additions & 25 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::DynamicObject>();
juce::Array<juce::var> 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<juce::DynamicObject>();
item->setProperty("name",type->getTypeName());
item->setProperty("active",type->getTypeName()==manager.getCurrentAudioDeviceType());
item->setProperty("separate",type->hasSeparateInputsAndOutputs());
juce::Array<juce::var> 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<double>(elapsed));
if(explicitRescan)
diagnostics_.record("DEVICE_REFRESH",
scanState+" | "+juce::String(static_cast<juce::int64>(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
Expand Down Expand Up @@ -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<int>(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";
Expand Down Expand Up @@ -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::DynamicObject>();
juce::Array<juce::var> types;
auto& manager=engine_.devices();
for(auto* type:manager.getAvailableDeviceTypes()) {
if(type==nullptr)continue;
type->scanForDevices();
auto item=std::make_unique<juce::DynamicObject>();
item->setProperty("name",type->getTypeName());
item->setProperty("active",type->getTypeName()==manager.getCurrentAudioDeviceType());
item->setProperty("separate",type->hasSeparateInputsAndOutputs());
juce::Array<juce::var> 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")
{
Expand Down
24 changes: 24 additions & 0 deletions tests/mixer_io_operator_contract_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,27 @@ test('SOURCE1 mute-only instant SOURCE uses one native ACK; armed output is reje
assert.match(monitor,/window\.__arMixRevertMixerDraft\(\)/);
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/);
});
9 changes: 9 additions & 0 deletions tests/mixer_io_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,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()
Expand Down
29 changes: 23 additions & 6 deletions web/mixer-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -764,10 +764,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;
Expand Down Expand Up @@ -813,7 +823,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;
Expand Down Expand Up @@ -1160,7 +1170,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;
Expand Down Expand Up @@ -1245,6 +1255,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=>{
Expand Down
Loading