From e37dcc23c64bcc9292fed35b7290b8241bd24567 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 5 Nov 2026 07:36:04 +0700 Subject: [PATCH 1/2] INTEGRATOR: real ChannelId GUI fader/pan/mute/solo dispatcher with native ACK/readback --- integration/ApprovedNativeControlIntent.h | 59 +++++++++++++++++ integration/ApprovedNativeRuntimeSnapshot.h | 28 ++++++-- src/Main.cpp | 70 +++++++++++++++++--- tests/approved_native_v8_projection_test.cpp | 28 ++++++++ 4 files changed, 167 insertions(+), 18 deletions(-) diff --git a/integration/ApprovedNativeControlIntent.h b/integration/ApprovedNativeControlIntent.h index 29e049293..e5062b9a3 100644 --- a/integration/ApprovedNativeControlIntent.h +++ b/integration/ApprovedNativeControlIntent.h @@ -1,6 +1,9 @@ // SPDX-License-Identifier: AGPL-3.0-only #pragma once #include "ApprovedNativeV8Projection.h" +#include "../engine/core/DynamicChannelRoster.h" +#include +#include #include #include #include @@ -169,4 +172,60 @@ inline ApprovedNativeControlIntent translateApprovedNativeControl( converted->setProperty("payload",juce::var(translatedPayload.release())); return {juce::var(converted.release()),{}}; } + +inline bool approvedNativeId(const juce::var& value,std::uint64_t& result) { + if(!value.isString()||!nativeV8Decimal(value))return false; + const auto bytes=value.toString().toStdString(); + std::uint64_t decoded=0; + const auto parsed=std::from_chars(bytes.data(),bytes.data()+bytes.size(),decoded); + if(parsed.ec!=std::errc{} || + parsed.ptr!=bytes.data()+bytes.size() || decoded==0) + return false; + result=decoded; + return true; +} + +// The only PCM mutation route for the approved Pages WebView controller. +// This does NOT own a callback, plugin instance, graph or UI state. +// The installed ENGINE source must accept the exact epoch/revision/ChannelId. +// No fallback to ordinal-only M4 or synthetic JS/DSP is permitted. +template +inline bool executeApprovedNativeControl(Engine& engine, + const juce::var& translated) { + if(!translated.isObject())return false; + std::uint64_t epoch=0,revision=0,roster=0,id=0; + if(!approvedNativeId(translated.getProperty("deviceEpoch",{}),epoch) || + !approvedNativeId(translated.getProperty("baseGraphRevision",{}),revision) || + !approvedNativeId(translated.getProperty("baseRosterRevision",{}),roster) || + !approvedNativeId(translated.getProperty("targetChannelId",{}),id)) + return false; + const auto payload=translated.getProperty("payload",{}); + if(!payload.isObject())return false; + const auto operation=translated.getProperty("operation","").toString(); + const auto channel=armix::mixer::ChannelId{id}; + if(operation=="NATIVE_SET_CHANNEL_MIX" || + operation=="NATIVE_SET_BUS_MIX") { + const auto rawGain=payload.getProperty("gain",{}); + const auto rawPan=payload.getProperty("pan",{}); + double gain=0.,pan=0.; + if(!nativeV8Number(rawGain,gain) || + !nativeV8Number(rawPan,pan) || + gain<0. || gain>4. || pan< -1. || pan>1.) + return false; + if(operation=="NATIVE_SET_CHANNEL_MIX") + return engine.setNativeInputMix(epoch,revision,channel, + static_cast(gain),static_cast(pan)); + return engine.setNativeBusMix(epoch,revision,channel, + static_cast(gain),static_cast(pan)); + } + if(operation=="NATIVE_SET_CHANNEL_MUTE_SOLO") { + const auto mute=payload.getProperty("mute",{}); + const auto solo=payload.getProperty("solo",{}); + if(!mute.isBool()||!solo.isBool())return false; + return engine.setNativeInputMuteSolo(epoch,revision,channel, + static_cast(mute), + static_cast(solo)); + } + return false; +} } // namespace armix::console diff --git a/integration/ApprovedNativeRuntimeSnapshot.h b/integration/ApprovedNativeRuntimeSnapshot.h index b0c663162..f1610740a 100644 --- a/integration/ApprovedNativeRuntimeSnapshot.h +++ b/integration/ApprovedNativeRuntimeSnapshot.h @@ -84,16 +84,30 @@ inline bool projectInstalledNativeChannelIdGraph( // comes from the verified installed ENGINE status above, not the caller. if (!projectApprovedNativeV8(snapshot,bus,true)) return false; - // Reading a PCM graph is not a mutating operation: Main.cpp still has a - // G0 reject handler. Until ENGINE/INTEGRATOR jointly install a real - // dispatcher and matching readback, advertise ZERO supported controls. - // In particular, projectApprovedNativeV8's generic WIRE structure alone - // must not enable WIRE intent before native transaction dispatch exists. + // Advertise only controls provided by the currently installed and + // positively admitted native callback (never inferred from a JSON shape + // or the browser). Both the native and public capability are required by + // the stateless control translator. WIRE remains explicitly disabled + // until the native structural dispatcher is independently admitted. + juce::Array available; + const auto nativeOps=bus.getProperty("supportedOps",{}); + const auto* actual=nativeOps.getArray(); + const auto has=[&](const char* op) { + return actual && actual->contains(juce::String(op)); + }; + if(has("NATIVE_SET_CHANNEL_MIX")) { + available.add(juce::String("SET_FADER")); + available.add(juce::String("SET_PAN")); + } + if(has("NATIVE_SET_CHANNEL_MUTE_SOLO")) { + available.add(juce::String("SET_MUTE")); + available.add(juce::String("SET_SOLO")); + } const auto graph=snapshot.getProperty("graph",{}); const auto caps=graph.getProperty("capabilities",{}); if (auto* props=caps.getDynamicObject()) - props->setProperty("supportedOps",juce::var(juce::Array{})); - // Full vendor/Show/physical FAT not done. Never promote product LIVE. + props->setProperty("supportedOps",juce::var(available)); + // Product LIVE stays false until independent vendor/Show/hardware FAT. return true; } } // namespace armix::console diff --git a/src/Main.cpp b/src/Main.cpp index 398cc5b25..c8857c105 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -7,6 +7,7 @@ #include "ApprovedGuiResources.h" #include "ApprovedConsoleNativeTransportV6.h" #include "../integration/ApprovedNativeRuntimeSnapshot.h" +#include "../integration/ApprovedNativeControlIntent.h" #include "LiveAudioEngine.h" #include "ArSonMixStartupSplash.h" #include "VstOrbitController.h" @@ -32,6 +33,7 @@ #include #include #include +#include namespace { @@ -201,16 +203,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr emitApprovedNativeSnapshot(); }) .withEventListener ("arMixConsoleIntent", [this] (juce::var args) { - // Until ENGINE #266 owns production ChannelId graph, ALL v6 - // control intents are native-rejected, never silently emulated - // via the old ordinal-only M4 engine. - const auto accepted = approvedNativeSnapshot(); - if (browser_.loaded) - { - browser_.emitEventIfBrowserIsVisible ("arMixConsoleAck", - armix::native_console_m2::reject (args, accepted)); - browser_.emitEventIfBrowserIsVisible ("arMixConsoleSnapshot", accepted); - } + // The native control thread owns ONLY accepted mutations. + // No GUI-side PCM, no legacy ordinal fallback and no fake ACK. + handleApprovedNativeControl(args); }) .withEventListener ("arMixParameter", [this] (juce::var args) { onParameter (args); }) .withEventListener ("arMixAction", [this] (juce::var args) { onAction (args); }) @@ -278,7 +273,8 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr std::unique_ptr audioSetupWindow_; juce::String startupError_, lastAudioXml_; bool initialStateSent_ = false; - bool consoleSubscribed_ = false; // WebView v6 G0 subscription, not PCM admission + bool consoleSubscribed_ = false; // Real snapshot subscription; not FAT certification + juce::StringArray acceptedControlRequests_; // bounded request replay fence bool webViewPeerWarmed_ = false; bool webViewStartupNoticeSent_ = false; juce::uint32 webViewStartupTick_ = 0; @@ -722,6 +718,58 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr "arMixConsoleSnapshot", approvedNativeSnapshot()); } + // One native dispatcher; the source of truth is the already installed + // ENGINE callback. This code executes on the JUCE message thread, not RT. + void handleApprovedNativeControl(const juce::var& request) + { + const auto beforeLive=engine_.status(); + const auto before=approvedNativeSnapshot(beforeLive); + const auto route=beforeLive.getProperty("dryRoutingLab",{}); + const auto installedBus=route.getProperty("nativeBus",{}); + const auto idValue=request.getProperty("requestId",{}); + const auto id=idValue.isString()?idValue.toString():juce::String{}; + const bool replay=id.isNotEmpty()&&acceptedControlRequests_.contains(id); + // All well-formed IDs are consumed once, including failed mutations. + // Bounded storage avoids unbounded memory growth in a long session. + if(id.isNotEmpty()&&id.length()<=128&&!replay) { + acceptedControlRequests_.add(id); + if(acceptedControlRequests_.size()>512) + acceptedControlRequests_.remove(0); + } + const auto translated=armix::console::translateApprovedNativeControl( + request,before,installedBus); + const bool applied=!replay&&translated.ok()&& + armix::console::executeApprovedNativeControl(engine_,translated.translated); + // An engine setter ACK is not independent PCM evidence. Re-read the + // same physical callback authority after mutation before claiming it + // was accepted; browser then explicitly requests LATER readback. + const auto after=applied?approvedNativeSnapshot():before; + const auto device=after.getProperty("device",{}); + const auto graph=after.getProperty("graph",{}); + const auto caps=graph.getProperty("capabilities",{}); + const bool nativeStillAdmitted=applied&&caps.isObject()&& + static_cast(caps.getProperty("callbackOwnsChannelIds",false))&& + device.getProperty("epoch","0").toString()== + request.getProperty("deviceEpoch","").toString(); + auto ack=std::make_unique(); + ack->setProperty("requestId",id); + ack->setProperty("status",nativeStillAdmitted?"ACCEPTED":"REJECTED"); + ack->setProperty("errorCode",nativeStillAdmitted?"NONE": + replay?"DUPLICATE_REQUEST_ID": + translated.error.isNotEmpty()?translated.error: + applied?"NATIVE_CALLBACK_LOST":"NATIVE_PCM_MUTATION_REJECTED"); + ack->setProperty("deviceEpoch",device.getProperty("epoch","0")); + ack->setProperty("graphRevision",graph.getProperty("revision","0")); + ack->setProperty("rosterRevision",graph.getProperty("rosterRevision","0")); + ack->setProperty("productionCallbackLive",false); + if(browser_.loaded) + browser_.emitEventIfBrowserIsVisible("arMixConsoleAck", + juce::var(ack.release())); + // NEVER emit a same-handler optimistic snapshot. The approved browser + // sends arMixConsoleSubscribe AFTER ACK and verifies a later producer + // readback before moving fader/route UI from its accepted state. + } + void onParameter (const juce::var& args) { const auto name = args.getProperty ("parameter", {}).toString(); diff --git a/tests/approved_native_v8_projection_test.cpp b/tests/approved_native_v8_projection_test.cpp index ed7e0629f..004481c81 100644 --- a/tests/approved_native_v8_projection_test.cpp +++ b/tests/approved_native_v8_projection_test.cpp @@ -11,6 +11,28 @@ #include using namespace armix::console; + +// Compile-time and runtime proof that accepted v8 native intents route to +// the actual ChannelId setter rather than a fake WebView-only state change. +struct NativeControlProbe { + std::uint64_t lastEpoch=0,lastRevision=0,lastId=0; + float lastGain= -1.f,lastPan= -2.f; + bool lastMute=false,lastSolo=false; + bool setNativeInputMix(std::uint64_t e,std::uint64_t r, + armix::mixer::ChannelId id,float g,float p) { + lastEpoch=e;lastRevision=r;lastId=id.value;lastGain=g;lastPan=p; + return true; + } + bool setNativeBusMix(std::uint64_t e,std::uint64_t r, + armix::mixer::ChannelId id,float g,float p) { + return setNativeInputMix(e,r,id,g,p); + } + bool setNativeInputMuteSolo(std::uint64_t e,std::uint64_t r, + armix::mixer::ChannelId id,bool m,bool s) { + lastEpoch=e;lastRevision=r;lastId=id.value; + lastMute=m;lastSolo=s;return true; + } +}; static juce::var parse(const char* bytes) { auto json=juce::JSON::parse(juce::String::fromUTF8(bytes)); assert(json.isObject()); @@ -90,6 +112,12 @@ static void controlIntentTranslationCases(const juce::var& canonical, const auto fader=makeIntent("SET_FADER",juce::var(-12.0),source); const auto translated=translateApprovedNativeControl(fader,accepted,bus); assert(translated.ok()); + NativeControlProbe producer; + assert(executeApprovedNativeControl(producer,translated.translated)); + assert(producer.lastEpoch==91 && producer.lastRevision==25); + assert(producer.lastId==9007199254740993ULL); + assert(std::abs(producer.lastGain-std::pow(10.,-12./20.))<0.000001); + assert(!executeApprovedNativeControl(producer,juce::var{})); assert(translated.translated.getProperty("operation","").toString() =="NATIVE_SET_CHANNEL_MIX"); assert(translated.translated.getProperty("targetChannelId","").toString() From 0abfb4642cf4ff8c572b2b9085a7ff3b46a4fff3 Mon Sep 17 00:00:00 2001 From: Ari Sulistiono Date: Thu, 5 Nov 2026 08:27:36 +0700 Subject: [PATCH 2/2] M3-F: operator first-sound path on real JUCE pins, explicit output arm, truthful native footer --- src/Main.cpp | 3 + tests/approved_native_m2_contract.test.cjs | 26 ++++ web/approved-native-bridge.js | 138 +++++++++++++++++++++ 3 files changed, 167 insertions(+) diff --git a/src/Main.cpp b/src/Main.cpp index c8857c105..5ff9bbd5a 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1118,6 +1118,9 @@ class ConsoleWindow final : public juce::DocumentWindow, private juce::Timer, pr safe->startupError_.clear(); safe->diagnostics_.record ("DIRECT_ROUTE_APPROVED", "User confirmed selected ASIO/WASAPI backend in AUDIO SETUP"); + // Refresh native physical port inventory after the user + // finishes device selection; never require a restart. + safe->emitApprovedNativeSnapshot(); } else { diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 233cac153..4820f388d 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -350,3 +350,29 @@ test("M3 Windows bundle owns pointerup fader gesture and fences native FX keyboa assert.ok(bridge.includes("scope?.findTrack?.(el)")); assert.ok(!bridge.includes('window.addEventListener("pointerup"')); }); + +test("native Windows operator can explicitly patch first physical input, arm and mute",()=>{ + const js=read("web/approved-native-bridge.js"); + const main=read("src/Main.cpp"); + const engine=read("src/LiveAudioEngine.h"); + assert.match(js,/REAL AUDIO · FIRST SOUND/); + assert.match(js,/action:"audioSetup"/); + assert.match(js,/d\.inputEndpoints\.filter\(p=>/); + assert.match(js,/d\.enabledInputs\.includes\(p\.port\)/); + assert.match(js,/action:"routingSourceSwitch",requestId:pendingSourceId/); + assert.match(js,/channel:0,mode:"MONO",left:pin,right:-1/); + assert.match(js,/action:"monitor",value:true/); + assert.match(js,/action:"monitor",value:false/); + assert.match(js,/expectedEpoch:epoch,expectedRevision:revision/); + assert.match(js,/arMixSourceSwitchAck/); + assert.match(js,/arMixAudioArmAck/); + assert.match(js,/if\(ack\.ok===true\)/); + assert.match(js,/NATIVE PATCH REJECTED:/); + assert.match(js,/NO VERIFIED AUDIO DEVICE/); + assert.match(js,/REAL NATIVE PCM · FAT PENDING/); + assert.match(main,/action=="routingSourceSwitch"/); + assert.match(main,/engine_\.liveOutputArmFault\(\)/); + assert.match(main,/safe->emitApprovedNativeSnapshot\(\)/); + assert.match(engine,/juce::String switchDryRoutingLabSource\(/); + assert.match(engine,/setOutputMuted\(true\)/); +}); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 639567490..4de3e37aa 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -144,7 +144,127 @@ paint("right",right); } } + + // Native-only operator controls in the EXISTING approved More menu: + // user selects REAL JUCE active pin -> explicitly patches CH1 -> arms output. + // No auto-arm, demo PCM, guessed physical port or second GUI. + let hardware=null, inputSelect=null, routeBtn=null, armBtn=null, muteBtn=null; + let hardwareNote=null, pendingSourceId=0, sourceSerial=100; + const safeNativeCounter=x=>{ + if(typeof x!=="string" || !/^[1-9]\d*$/.test(x))return null; + const number=Number(x); + return Number.isSafeInteger(number)&&number>0?number:null; + }; + const legacy=()=>hardware?.raw?.legacyM4; + const deviceReady=()=>!!(hardware?.device?.backend && + hardware.device.sampleRate>0 && + hardware.device.enabledInputs.length>0 && + hardware.device.enabledOutputs.length>=2 && legacy()?.active===true); + function updateHardwarePanel(next) { + hardware=next || null; + const d=next?.device; + const deviceOpen=Boolean(d?.backend && d.sampleRate>0 && + d.enabledOutputs.length>=2); + const label=document.getElementById("transport"); + if(label)label.textContent=!deviceOpen?"Device not ready": + d.outputArmed?"Output armed":"Output muted"; + const warning=document.querySelector?.(".status-bar .warning"); + if(warning)warning.textContent=!deviceOpen?"NO VERIFIED AUDIO DEVICE": + next.admitted&&d.outputArmed?"REAL NATIVE PCM · FAT PENDING": + "NO AUDIBLE OUTPUT · PATCH INPUT + ARM"; + if(!inputSelect)return; + const pins=deviceOpen?d.inputEndpoints.filter(p=> + p.active===true && d.enabledInputs.includes(p.port)):[]; + const key=pins.map(p=>p.id+"|"+p.label).join(";"); + if(inputSelect.dataset.pins!==key) { + const before=inputSelect.value; + inputSelect.dataset.pins=key; + inputSelect.replaceChildren(); + const option=document.createElement("option"); + option.value="";option.textContent="Physical input for CH1"; + inputSelect.appendChild(option); + for(const pin of pins){ + const item=document.createElement("option"); + item.value=String(pin.port); + item.textContent=pin.label+" · IN "+(pin.port+1); + inputSelect.appendChild(item); + } + if(pins.some(p=>String(p.port)===before))inputSelect.value=before; + } + inputSelect.disabled=!deviceReady(); + if(routeBtn)routeBtn.disabled=!deviceReady() || + inputSelect.value==="" || pendingSourceId!==0; + if(armBtn)armBtn.disabled=!deviceReady() || + legacy()?.routeAccepted!==true || d.outputArmed; + if(muteBtn)muteBtn.disabled=!deviceOpen || !d.outputArmed; + if(hardwareNote)hardwareNote.textContent=!deviceOpen? + "Open Audio Setup: select a real input and output.": + !deviceReady()?"Verify ASIO/WASAPI input/output masks.": + !legacy()?.routeAccepted?"Select input, PATCH CH1, then ARM output.": + !d.outputArmed?"Input patch accepted. Reduce speaker volume before ARM.": + "User-armed output · check physical sound and native meter."; + } + function installFirstSoundMenu() { + const menu=document.querySelector?.("#moreTools .more-tools-panel"); + if(!menu || typeof document.createElement!=="function")return; + const item=(tag,cls,label)=>{ + const el=document.createElement(tag); + el.className=cls;el.textContent=label; + if(tag==="button")el.type="button"; + return el; + }; + const caption=item("span","more-tools-caption","REAL AUDIO · FIRST SOUND"); + const setup=item("button","tool","Audio Setup"); + setup.addEventListener("click",()=>{ + backend.emitEvent("arMixAction",{action:"audioSetup"}); + status("NATIVE: select actual ASIO/WASAPI input + output in Audio Setup."); + }); + inputSelect=item("select","toolbar-select",""); + inputSelect.setAttribute("aria-label","JUCE physical input for CH1"); + inputSelect.addEventListener("change",()=>updateHardwarePanel(hardware)); + routeBtn=item("button","tool","Patch CH1"); + routeBtn.addEventListener("click",()=>{ + const d=hardware?.device,l=legacy(); + const epoch=safeNativeCounter(d?.epoch); + const revision=safeNativeCounter(l?.routingRevision); + const pin=Number(inputSelect?.value); + if(!deviceReady()||inputSelect.value==="" || + epoch===null||revision===null|| + !Number.isInteger(pin)||!d.enabledInputs.includes(pin)){ + status("NATIVE: invalid input pin, epoch or route revision.");return; + } + pendingSourceId=++sourceSerial; + routeBtn.disabled=true; + backend.emitEvent("arMixAction",{ + action:"routingSourceSwitch",requestId:pendingSourceId, + channel:0,mode:"MONO",left:pin,right:-1, + deviceEpoch:epoch,revision + }); + status("NATIVE: CH1 physical input patch pending real ACK."); + }); + armBtn=item("button","tool","Arm output"); + armBtn.addEventListener("click",()=>{ + if(!deviceReady()||legacy()?.routeAccepted!==true)return; + const epoch=safeNativeCounter(hardware.device.epoch); + const revision=safeNativeCounter(legacy().routingRevision); + if(epoch===null||revision===null)return; + backend.emitEvent("arMixAction",{action:"monitor",value:true, + expectedEpoch:epoch,expectedRevision:revision}); + status("NATIVE: output ARM requested; awaiting JUCE ACK."); + }); + muteBtn=item("button","tool","Mute output"); + muteBtn.addEventListener("click",()=>{ + backend.emitEvent("arMixAction",{action:"monitor",value:false}); + status("NATIVE: output MUTE requested; awaiting JUCE ACK."); + }); + hardwareNote=item("span","more-tools-caption","Device not initialized"); + hardwareNote.style.whiteSpace="normal"; + menu.append(caption,setup,inputSelect,routeBtn,armBtn,muteBtn,hardwareNote); + updateHardwarePanel(hardware); + } + function onNativeReadback(next) { + updateHardwarePanel(next); const caps=next?.graph?.capabilities; const nativeAdmitted=next.admitted && caps?.callbackOwnsChannelIds===true; if (!nativeAdmitted) { @@ -195,6 +315,22 @@ }); backend.addEventListener("arMixConsoleSnapshot", snapshot=>controller.onSnapshot(snapshot)); backend.addEventListener("arMixConsoleAck", ack=>controller.onAck(ack)); + backend.addEventListener("arMixSourceSwitchAck", ack=>{ + if(!pendingSourceId||ack?.requestId!==pendingSourceId)return; + pendingSourceId=0; + if(ack.ok===true) { + status("NATIVE: CH1 PATCH accepted by JUCE; validating later readback."); + controller.subscribe(); + }else status("NATIVE PATCH REJECTED: "+(ack?.error||"stale physical route")); + updateHardwarePanel(hardware); + }); + backend.addEventListener("arMixAudioArmAck", ack=>{ + if(ack?.ok===true){ + status(ack.armed?"NATIVE: user ARM accepted; checking real PCM.": + "NATIVE: output muted."); + controller.subscribe(); + }else status("NATIVE ARM REJECTED: "+(ack?.error||"device not ready")); + }); } const nativeHooks=Object.freeze({ enabled:connected, @@ -340,6 +476,8 @@ // finishFaderPointer via build_approved_native_gui.py hook. A later // window.pointerup listener would run after that handler clears the gesture. const ready=()=>{ + installFirstSoundMenu(); + updateHardwarePanel(null); stopDemo(); status("NATIVE: subscribed · waiting for true device and accepted ChannelId graph"); backend.emitEvent("arMixGuiReady",{