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
23 changes: 23 additions & 0 deletions scripts/build_approved_native_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@
'<script defer src="assets/approved-native-context-menu.js"></script>')
SCHEMA = "arsonmix.approved-native-pages-bundle.v2"

NATIVE_BOOT_GUARD = (
'<style id="armix-native-boot-guard">\n'
'html[data-armix-native-boot="waiting"] #tracks,'
'html[data-armix-native-boot="waiting"] #master,'
'html[data-armix-native-boot="waiting"] #wireLayer'
'{visibility:hidden!important;pointer-events:none!important}\n'
'html[data-armix-native-boot="waiting"] .console-body{position:relative}\n'
'html[data-armix-native-boot="waiting"] .console-body::after{'
'content:"Audio connection unavailable · Open Audio I/O to check your driver";'
'position:absolute;inset:20% 8%;z-index:30;display:flex;'
'align-items:center;justify-content:center;text-align:center;'
'padding:20px;color:#b3c5d0;background:rgba(12,22,31,.94);'
'border:1px solid #465b69;border-radius:8px;'
'font:400 14px/1.6 sans-serif;pointer-events:none}\n'
'</style><script>document.documentElement.dataset.armixNativeBoot="waiting";</script>\n'
)


def sha256(data: bytes) -> str:
return hashlib.sha256(data).hexdigest()
Expand Down Expand Up @@ -263,6 +280,9 @@ def native_html(approved: str | None = None) -> str:
if html.count(before) != 1 or after in html:
raise ValueError("Native-only M2 control hook anchor drift: " + before[:55])
html = html.replace(before, after, 1)
if html.count("</head>") != 1:
raise ValueError("Approved Pages missing unique native boot guard anchor")
html = html.replace("</head>", NATIVE_BOOT_GUARD + "</head>", 1)
html = html.replace("</body>", ADAPTER_MARKER + "\n</body>")
return html.replace("\n", newline)

Expand All @@ -274,6 +294,9 @@ def public_from_native(native: str) -> str:
if html.count(ADAPTER_MARKER + "\n") != 1:
raise ValueError("Native adapter marker missing or duplicated")
html = html.replace(ADAPTER_MARKER + "\n", "", 1)
if html.count(NATIVE_BOOT_GUARD) != 1:
raise ValueError("Native boot guard missing or duplicated")
html = html.replace(NATIVE_BOOT_GUARD, "", 1)
for before, after in reversed(NATIVE_EVENT_HOOKS):
if html.count(after) != 1:
raise ValueError("Native-only M2 control hook missing or duplicated")
Expand Down
34 changes: 30 additions & 4 deletions src/LiveAudioEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
bool selectedRetainedAsioDriverForReopen() {
using Policy=armix::session::MixerDeviceBindingPolicy;
if(deviceManager_.getCurrentAudioDevice() || !acceptedMixerBinding_ ||
!Policy::isAsio4All(*acceptedMixerBinding_) ||
acceptedMixerBinding_->backend!="ASIO" ||
!asioPinnedRegistration_.valid() || !attached_ || independent_.active() ||
deviceManager_.getCurrentAudioDeviceType()!="ASIO")return false;
juce::AudioDeviceManager::AudioDeviceSetup setup;
Expand All @@ -497,7 +497,7 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
bool authorizeRetainedAsioRestart() {
using Policy=armix::session::MixerDeviceBindingPolicy;
if(!hasRetainedNativeSession() || !acceptedMixerBinding_ ||
!Policy::isAsio4All(*acceptedMixerBinding_) || !asioPinnedRegistration_.valid() ||
acceptedMixerBinding_->backend!="ASIO" || !asioPinnedRegistration_.valid() ||
!allOutputsDisarmed() || independent_.active() || !attached_ || handoff_.busy() ||
fxMovePhase_.load(std::memory_order_acquire)!=0 ||
routeReconfiguring_.load(std::memory_order_acquire) ||
Expand Down Expand Up @@ -542,9 +542,10 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
}
bool reattachRetainedAsioMixer() {
using Policy=armix::session::MixerDeviceBindingPolicy;
if(!acceptedMixerBinding_ || !Policy::isAsio4All(*acceptedMixerBinding_) ||
if(!acceptedMixerBinding_ || acceptedMixerBinding_->backend!="ASIO" ||
!hasRetainedNativeSession() || !allOutputsDisarmed() ||
!directFence_.permitted() || handoff_.busy())return false;
!directFence_.permitted() || handoff_.busy() ||
!sameRetainedAsioDriver())return false;
armix::session::MixerSessionDocument document;
if(!dryRoutingLab_.describeRetainedAsioSession(document))return false;
document.binding=*acceptedMixerBinding_;
Expand All @@ -558,6 +559,31 @@ class LiveAudioEngine final : private juce::AudioIODeviceCallback
acceptedMixerBinding_=std::move(inspected.live);
return true;
}
// A SOURCE NONE starter is not an authored Show: it has no FX/WIRE to
// rebind, yet still must survive an ASIO STOP/START as an actual PCM
// mixer. Keep the old playback identity and pin names; no auto-redirect.
bool hasPristineSilentMixerAwaitingAsio() const noexcept {
return dryRoutingLab_.hasPristineSilentMixerAwaitingDevice() &&
acceptedMixerBinding_ && acceptedMixerBinding_->backend=="ASIO" &&
asioPinnedRegistration_.valid() && attached_ && !independent_.active();
}
bool rebuildPristineSilentAsioMixer() {
if(!hasPristineSilentMixerAwaitingAsio() || !allOutputsDisarmed() ||
handoff_.busy() ||
routeReconfiguring_.load(std::memory_order_acquire) ||
diagnosticRoute()!=armix::diagnostics::Route::normal)return false;
auto* device=deviceManager_.getCurrentAudioDevice();
if(!device || !device->isOpen() || !sameRetainedAsioDriver())return false;
const auto current=readMixerBinding(*device);
if(current.backend!="ASIO" ||
current.playback!=acceptedMixerBinding_->playback ||
current.outputMask!=acceptedMixerBinding_->outputMask ||
current.outputNames!=acceptedMixerBinding_->outputNames ||
current.rate!=acceptedMixerBinding_->rate)return false;
if(!approveDirectRoute(&asioPinnedRegistration_))return false;
return startUnpatchedProductionSession().isEmpty() &&
dryRoutingLab_.channelIdPhysicalPcmActive();
}
bool takeAsioResetMonitorIntent() noexcept {
return resumeMainAfterAsioReset_.exchange(false,std::memory_order_acq_rel);
}
Expand Down
9 changes: 9 additions & 0 deletions src/LiveDryRoutingLab.h
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,15 @@ class LiveDryRoutingLab final {
return true;
return false;
}
// A pristine SOURCE NONE mixer must not disappear when an ASIO callback
// stops/restarts. It contains no authored FX, WIRE, source or fader edit;
// rebuilding it is safe only on CONTROL after verifying the same device.
bool hasPristineSilentMixerAwaitingDevice() const noexcept {
return active() && sourceTemplate_.isObject() &&
!acceptedRoute_.isObject() && !nativeStructureLive_ &&
!nativeControlDirty_ && !channelIdPhysicalPcmActive() &&
!hasAuthoredMixerContent();
}
// CONTROL only. The verified profile proves identical port ordinals.
// Rebuild DSP scratch/PDC while retaining the accepted document and
// compatible processors. Never re-use a processor at a different rate.
Expand Down
51 changes: 41 additions & 10 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
.withNativeIntegrationEnabled()
.withEventListener ("arMixGuiReady", [this] (juce::var ready)
{
// A Pages-only demo cannot authenticate native session readiness.
if (ready.getProperty ("gui", "").toString() !=
"APPROVED_PAGES_PREVIEW_BUTTONS" ||
!static_cast<bool> (ready.getProperty ("nativeBridgeAttached", false)))
{
diagnostics_.record ("GUI_NATIVE_BRIDGE_MISSING",
"Ignoring Pages-only readiness notification");
return;
}
browser_.loaded = true;
guiReadyTick_ = juce::Time::getMillisecondCounter();
// WebView2 may finish its first navigation while this
Expand Down Expand Up @@ -2522,7 +2531,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
return error;
}
if(bindingMode==MixerBindingMode::exact && startupOnSavedDevice &&
armix::session::MixerDeviceBindingPolicy::isAsio4All(doc.binding))
doc.binding.backend=="ASIO")
bindingMode=MixerBindingMode::verifiedAsioRestart;
const bool resume=startupOnSavedDevice &&
(bindingMode==MixerBindingMode::exact || bindingMode==MixerBindingMode::verifiedAsioRestart) &&
Expand Down Expand Up @@ -5415,15 +5424,16 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr

void serviceAsioMixerRestart() {
const auto epoch=engine_.dryRoutingLabEpoch();
if(epoch==asioRecoveryEpoch_ || !engine_.hasRetainedNativeSession() ||
const bool retained=engine_.hasRetainedNativeSession();
const bool silent=engine_.hasPristineSilentMixerAwaitingAsio();
if(epoch==asioRecoveryEpoch_ || (!retained && !silent) ||
audioDeviceApplyActive_ || (audioSetupWindow_ && audioSetupWindow_->isVisible()) ||
nativeShowBusy_ || studioBackupBusy_ || mixerSessionWorker_.busy() || catalog_.busy() ||
engine_.isGraphSwitchPending() || engine_.independentClockActive() ||
engine_.diagnosticRoute()!=armix::diagnostics::Route::normal)return;
auto* device=engine_.devices().getCurrentAudioDevice();
if(device) {
if(device->getTypeName()!="ASIO" ||
!device->getName().startsWithIgnoreCase("ASIO4ALL") ||
!engine_.sameRetainedAsioDriver())return;
} else if(!engine_.selectedRetainedAsioDriverForReopen()) {
// The device pointer disappeared: never open an unapproved or
Expand All @@ -5448,28 +5458,49 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
setup.useDefaultInputChannels=!setup.inputChannels.isZero();
setup.useDefaultOutputChannels=true;
asioRecoveryGate_.driverTransaction(now);
if(!device)diagnostics_.record("ASIO4ALL_DEVICE_MISSING",
if(!device)diagnostics_.record("ASIO_DEVICE_MISSING",
"Reopening previously approved registered ASIO driver; no fallback");
const auto error=openSelectedAudioDevice("ASIO",setup,true);
asioRecoveryGate_.carryInternalEpoch(engine_.dryRoutingLabEpoch());
device=engine_.devices().getCurrentAudioDevice();
if(error.isNotEmpty() || !device || !device->isOpen()) {
diagnostics_.record("ASIO4ALL_REOPEN_FAILED",error);
diagnostics_.record("ASIO_REOPEN_FAILED",error);
emitApprovedNativeSnapshot();
return;
}
}
if(silent) {
// Recreate the original unedited SOURCE NONE PCM publisher only
// after proving the SAME ASIO driver and playback pin identity.
// No saved mixer, FX or WIRE may be replaced by this path.
if(!engine_.rebuildPristineSilentAsioMixer()) {
asioRecoveryGate_.bindFailed(now);
diagnostics_.record("ASIO_SILENT_MIXER_REBUILD_REJECTED",
"Registered ASIO driver/pins or native graph not ready");
emitApprovedNativeSnapshot();
return;
}
asioRecoveryEpoch_=engine_.dryRoutingLabEpoch();
asioRecoveryGate_.carryInternalEpoch(asioRecoveryEpoch_);
asioRecoveryGate_.recovered();
mixerSessionStatus_="PRISTINE_SOURCE_NONE_REATTACHED";
mixerSessionError_.clear();
diagnostics_.record("ASIO_SILENT_MIXER_REATTACHED",
"Same physical ASIO output; no mic source and no auto-arm");
emitApprovedNativeSnapshot();
return;
}
if(!engine_.authorizeRetainedAsioRestart()) {
// Admission can lag driver restart without any driver call.
// It MUST NOT exhaust the bounded reopen/correction allowance.
asioRecoveryGate_.waitForReadback(now);
diagnostics_.record("ASIO4ALL_BIND_NOT_READY","Waiting for verified callback/readback");
diagnostics_.record("ASIO_BIND_NOT_READY","Waiting for verified callback/readback");
return;
}
if(const auto corrected=engine_.asioRestartPinCorrection()) {
if(!asioRecoveryGate_.mayChangeDriver()) {
asioRecoveryGate_.waitForReadback(now);
diagnostics_.record("ASIO4ALL_PIN_CORRECTION_DEFERRED",
diagnostics_.record("ASIO_PIN_CORRECTION_DEFERRED",
"Driver transaction budget exhausted for this physical epoch");
return;
}
Expand All @@ -5485,7 +5516,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
reopened->getActiveInputChannels()!=corrected->inputChannels ||
reopened->getActiveOutputChannels()!=corrected->outputChannels ||
!engine_.authorizeRetainedAsioRestart()) {
diagnostics_.record("ASIO4ALL_PIN_CORRECTION_FAILED",
diagnostics_.record("ASIO_PIN_CORRECTION_FAILED",
error.isNotEmpty()?error:juce::String("Readback changed during correction"));
emitApprovedNativeSnapshot();
return;
Expand All @@ -5498,7 +5529,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
// current epoch; retry without reopening hardware at an
// exponentially bounded CONTROL cadence.
asioRecoveryGate_.bindFailed(now);
diagnostics_.record("ASIO4ALL_REATTACH_FAILED",error);
diagnostics_.record("ASIO_REATTACH_FAILED",error);
emitApprovedNativeSnapshot();
return;
}
Expand All @@ -5509,7 +5540,7 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr
mixerSessionError_.clear();
if(engine_.takeAsioResetMonitorIntent())requestAutomaticMain(false);
if(engine_.isMonitorEnabled())mixerSessionStatus_="RESTORED_MONITORING";
diagnostics_.record("ASIO4ALL_REATTACHED","Verified driver and current MAIN pair");
diagnostics_.record("ASIO_REATTACHED","Verified driver and current MAIN pair");
emitApprovedNativeSnapshot();
}

Expand Down
5 changes: 4 additions & 1 deletion src/NativeMixerSessionDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ struct MixerDeviceBindingPolicy final {
(mode==Mode::verifiedDeviceApply &&
(saved.backend!=live.backend || saved.playback!=live.playback)))
return count==2?VerifiedNativeOutputs{count,0,1,-1,-1,false}:unavailable;
// The host checks the pinned registered ASIO driver identity first.
// Physical MAIN pin mapping still requires exact verified readback.
if(mode==Mode::verifiedAsioRestart &&
(!isAsio4All(live) || saved.backend!=live.backend || saved.playback!=live.playback))
(saved.backend!="ASIO" || live.backend!="ASIO" ||
saved.capture!=live.capture || saved.playback!=live.playback))
return unavailable;
auto outputs=document.outputs;
outputs.activeOutputChannels=count;
Expand Down
4 changes: 4 additions & 0 deletions tests/approved_native_cold_start_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def main():
# Native Console is ALWAYS visible, even with no callback/device.
# Bridge still rejects unadmitted PCM edits until accepted readback.
assert page.locator('.console-pane').is_visible()
assert page.locator('html').get_attribute('data-armix-native-boot')=='waiting'
assert page.locator('#tracks').evaluate('e=>getComputedStyle(e).visibility')=='hidden'
assert not page.evaluate('()=>window.__nativeIntents.length')
# Built-in JUCE DSP must be discoverable before ANY third-party
# VST3 catalog response. The native host never inserts demo FX.
Expand Down Expand Up @@ -214,6 +216,8 @@ def show_select(value):
state['legacyM4']={'active':True,'routeAccepted':True,'routingRevision':'77',
'nativeBusStructural':False,'fxInstances':[[] for _ in range(14)]}
emit(page,'arMixConsoleSnapshot',state)
page.wait_for_function('()=>document.documentElement.dataset.armixNativeBoot==="ready"')
assert page.locator('#tracks').evaluate('e=>getComputedStyle(e).visibility')=='visible'
page.locator('.console-pane').wait_for(state='visible')
if 'collapsed-send' in (page.locator('.console-body').get_attribute('class') or ''):
page.locator('.section-rail [data-section="send"]').click()
Expand Down
7 changes: 7 additions & 0 deletions tests/approved_native_gui_bundle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self)
approved = (source / "index.html").read_text("utf-8")
native = (out / "index.html").read_text("utf-8")
self.assertEqual(bundle.public_from_native(native), approved)
self.assertIn('id="armix-native-boot-guard"', native)
self.assertNotIn('id="armix-native-boot-guard"', approved)
self.assertIn('data-armix-native-boot="waiting"', native)
self.assertIn('nativeBridgeAttached:true',
(out / 'assets/approved-native-bridge.js').read_text('utf-8'))
self.assertNotIn("__ARMIX_NATIVE_M2__", approved)
self.assertIn("__ARMIX_NATIVE_M2__", native)
# Never let a missing ASIO driver or delayed native snapshot
Expand Down Expand Up @@ -52,6 +57,8 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self)
self.assertIn("orbitAction", context_menu)
self.assertNotIn("approved-native-context-menu.js", approved)
self.assertIn("arMixGuiReady", (out / "assets/approved-native-bridge.js").read_text("utf-8"))
self.assertIn('".plugin-disclaimer"',
(out / "assets/approved-native-bridge.js").read_text("utf-8"))
for asset in (source / "assets").iterdir():
self.assertEqual((out / "assets" / asset.name).read_bytes(), asset.read_bytes(),
"Native /preview/ asset differs: " + asset.name)
Expand Down
Loading
Loading