diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py
index 2d9729a28..3dbc667a7 100644
--- a/scripts/build_approved_native_gui.py
+++ b/scripts/build_approved_native_gui.py
@@ -229,6 +229,14 @@ def accepted_pages_html() -> str:
" if(input&&input!==sendKnobDrag?.input&&!row.pending){\n"
" input.value=String(row.levelDb);paintWireKnob(input,row.levelDb);\n"
" }\n"
+ " // Inspector LCD follows independent accepted native PCM readback,\n"
+ " // not a speculative range input. No strip or inspector rerender.\n"
+ " const ws=document.getElementById('wireWsGain');\n"
+ " if(ws?.dataset.wsGain===String(edge.id)&&!row.pending){\n"
+ " if(document.activeElement!==ws)ws.value=String(row.levelDb);\n"
+ " const value=document.getElementById('wireWsGainText');\n"
+ " if(value)value.textContent=row.levelDb+' dB';\n"
+ " }\n"
" }\n"
" },\n"
" syncVerifiedM4Wires(rows,ids){\n"
@@ -286,6 +294,21 @@ def accepted_pages_html() -> str:
)
+# Native-only WIRE Inspector: keep the public /preview/ HTML strictly unchanged.
+# These fail-closed exact-source edits are reversed by public_from_native().
+# A PRIMARY_OUT is unity, a PARALLEL_SEND can target MAIN, and native edits
+# are never accepted by the browser mock before installed PCM readback.
+NATIVE_EVENT_HOOKS += (
+ (" const tapEditable=!native||(src.nativeTapAvailable===true&&\n edge?.kind==='send'&&['PRE_FADER','POST_FADER'].includes(edge.nativeTap));\n",
+ " const gainEditable=edge&&(!native?edge.kind!=='primary':\n window.__ARMIX_NATIVE_M2__?.canWireGain?.(edge.id,edge.sourceId)===true);\n const tapEditable=edge&&(!native?edge.kind!=='primary':\n window.__ARMIX_NATIVE_M2__?.canWireTap?.(edge.id,edge.sourceId)===true);\n"),
+ (" const controls=edge?\n '
'+\n ''+\n ''+edge.levelDb+' dB'+\n ''+\n ''+\n '
':\n 'Managed by existing '+escapeHtml(info.kind.toUpperCase())+' routing. No duplicate WIRE edge.
';\n",
+ " const controls=edge?\n ''+\n ''+\n ''+(edge.kind==='primary'?'PRIMARY · UNITY':\n edge.levelDb+' dB')+''+\n ''+\n ''+\n '
':\n 'Managed by existing '+escapeHtml(info.kind.toUpperCase())+' routing. No duplicate WIRE edge.
';\n"),
+ ("document.getElementById('wireWsInspector').addEventListener('input',e=>{\n const gain=e.target.closest?.('[data-ws-gain]');\n if(!gain)return;\n const edge=wireEdges.find(x=>x.id===Number(gain.dataset.wsGain)&&x.enabled);\n if(!edge||edge.destId===master.id)return;\n const amount=Math.max(-60,Math.min(6,Math.round(Number(gain.value)||0)));\n if(!wireGraphCommit([{type:'GAIN',sourceId:edge.sourceId,edgeId:edge.id,\n levelDb:amount}],{record:false}))return;\n document.getElementById('wireWsGainText').textContent=amount+' dB';\n});\ndocument.getElementById('wireWsInspector').addEventListener('change',e=>{\n const gain=e.target.closest?.('[data-ws-gain]'),tap=e.target.closest?.('[data-ws-tap]');\n if(tap){\n const edge=wireEdges.find(x=>x.id===Number(tap.dataset.wsTap)&&x.enabled);\n if(!edge||!wireGraphCommit([{type:'MODE',sourceId:edge.sourceId,edgeId:edge.id,\n mode:tap.value==='split'?'split':'send'}],{record:false}))return;\n const owner=wireSourceTrack(edge.sourceId);if(owner)owner.wireTapMode=tap.value==='split'?'split':'send';\n }\n if(gain||tap){\n wireWsRecord(wireWsEditBefore);wireWsEditBefore=null;render();renderWireWorkspace();\n say('WIRE inspector accepted · reference graph only');\n }\n});\n\n",
+ "document.getElementById('wireWsInspector').addEventListener('input',e=>{\n const gain=e.target.closest?.('[data-ws-gain]');\n if(!gain)return;\n const edge=wireEdges.find(x=>x.id===Number(gain.dataset.wsGain)&&x.enabled);\n if(!edge||edge.kind==='primary')return;\n const amount=Math.max(-60,Math.min(6,Math.round(Number(gain.value)||0)));\n if(window.__JUCE__?.backend){\n if(window.__ARMIX_NATIVE_M2__?.canWireGain?.(edge.id,edge.sourceId)!==true)return;\n // Coalesce rapid gestures in the existing native control queue. This LCD\n // shows a pending operation, NEVER a speculative accepted PCM level.\n window.__ARMIX_NATIVE_M2__?.consumeWire?.([{type:'GAIN',\n sourceId:edge.sourceId,edgeId:edge.id,levelDb:amount}]);\n const readout=document.getElementById('wireWsGainText');\n if(readout)readout.textContent='PENDING · '+amount+' dB';\n return;\n }\n if(!wireGraphCommit([{type:'GAIN',sourceId:edge.sourceId,edgeId:edge.id,\n levelDb:amount}],{record:false}))return;\n document.getElementById('wireWsGainText').textContent=amount+' dB';\n});\ndocument.getElementById('wireWsInspector').addEventListener('change',e=>{\n const gain=e.target.closest?.('[data-ws-gain]'),tap=e.target.closest?.('[data-ws-tap]');\n if(window.__JUCE__?.backend){\n if(gain){\n const edge=wireEdges.find(x=>x.id===Number(gain.dataset.wsGain)&&x.enabled);\n if(edge?.kind!=='primary'&&window.__ARMIX_NATIVE_M2__?.canWireGain?.(edge.id,edge.sourceId)===true){\n // Keyboard-only range change may not have emitted 'input'.\n window.__ARMIX_NATIVE_M2__?.consumeWire?.([{type:'GAIN',sourceId:edge.sourceId,\n edgeId:edge.id,levelDb:Math.max(-60,Math.min(6,Math.round(Number(gain.value)||0)))}]);\n }\n }\n if(tap){\n const edge=wireEdges.find(x=>x.id===Number(tap.dataset.wsTap)&&x.enabled);\n const requested=tap.value==='split'?'split':'send';\n // Restore the accepted selector position immediately. An independent\n // structural readback will move it after the engine actually publishes.\n tap.value=edge?.nativeTap==='PRE_FADER'?'split':'send';\n if(edge&&window.__ARMIX_NATIVE_M2__?.canWireTap?.(edge.id,edge.sourceId)===true){\n window.__ARMIX_NATIVE_M2__?.consumeWire?.([{type:'MODE',sourceId:edge.sourceId,\n edgeId:edge.id,mode:requested}]);\n say('WIRE tap requested · awaiting accepted native PCM readback');\n }else say('WIRE tap unavailable · native graph or EdgeId changed');\n }\n wireWsEditBefore=null;return; // native owns state; no demo undo or full repaint\n }\n if(tap){\n const edge=wireEdges.find(x=>x.id===Number(tap.dataset.wsTap)&&x.enabled);\n if(!edge||!wireGraphCommit([{type:'MODE',sourceId:edge.sourceId,edgeId:edge.id,\n mode:tap.value==='split'?'split':'send'}],{record:false}))return;\n const owner=wireSourceTrack(edge.sourceId);if(owner)owner.wireTapMode=tap.value==='split'?'split':'send';\n }\n if(gain||tap){\n wireWsRecord(wireWsEditBefore);wireWsEditBefore=null;render();renderWireWorkspace();\n say('WIRE inspector accepted · reference graph only');\n }\n});\n\n"),
+)
+
+
+
def native_html(approved: str | None = None) -> str:
original = accepted_pages_html() if approved is None else approved
newline = "\r\n" if "\r\n" in original else "\n"
diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs
index fc5bdb022..f5ea8b916 100644
--- a/tests/approved_native_m2_contract.test.cjs
+++ b/tests/approved_native_m2_contract.test.cjs
@@ -27,6 +27,93 @@ function acceptedFixture(){
tap:"POST",gainLinear:1,enabled:true,signalKind:"AUDIO"}];
return s;
}
+test("WIRE inspector controls PRIMARY BUS and PARALLEL MAIN by actual EdgeId, with native readback only",()=>{
+ const vm=require("node:vm"),{execFileSync}=require("node:child_process");
+ const publicHtml=read("site/preview-v2/index.html");
+ assert.doesNotMatch(publicHtml,/__ARMIX_NATIVE_M2__/,
+ "public approved /preview/ must never own native control authority");
+ const html=execFileSync("python3",["-c",
+ "from scripts.build_approved_native_gui import native_html; from pathlib import Path; print(native_html(Path('site/preview-v2/index.html').read_text(encoding='utf-8')))"
+ ],{encoding:"utf8",maxBuffer:10*1024*1024});
+ const bridge=read("web/approved-native-bridge.js");
+ const builder=read("scripts/build_approved_native_gui.py");
+ assert.match(bridge,/function admittedParallelWire\(uiSourceId,uiEdgeId,operation\)/);
+ assert.match(bridge,/e\.edgeId===edgeId&&e\.from===source&&e\.primaryOutput===false/);
+ assert.match(builder,/getElementById\('wireWsGainText'\)/);
+ assert.match(builder,/!row\.pending/);
+ const renderStart=html.indexOf("function renderWireWsInspector(){");
+ const renderEnd=html.indexOf("function renderWireWorkspace(){",renderStart);
+ assert.ok(renderStart>0&&renderEnd>renderStart);
+ const primary={id:41,sourceId:1,destId:2,kind:"primary",mode:"routeOnly",
+ nativeTap:"POST_FADER",levelDb:0,enabled:true};
+ const parallel={id:42,sourceId:1,destId:3,kind:"send",mode:"send",
+ nativeTap:"POST_FADER",levelDb:-6,enabled:true};
+ const panel={hidden:false,innerHTML:""},readout={textContent:"-6 dB"};
+ const observed=[];
+ const gain=input=>input?.dataset?.wsGain!==undefined?input:null;
+ const tap=input=>input?.dataset?.wsTap!==undefined?input:null;
+ const handlers={};
+ const scope={
+ document:{getElementById(id){
+ if(id==="wireWsInspector")return { ...panel, addEventListener(type,fn){handlers[type]=fn},
+ get hidden(){return panel.hidden},set hidden(v){panel.hidden=v},
+ get innerHTML(){return panel.innerHTML},set innerHTML(v){panel.innerHTML=v}};
+ if(id==="wireWsGainText")return readout;
+ return null;
+ }},
+ window:{__JUCE__:{backend:{}},__ARMIX_NATIVE_M2__:{
+ canWireGain(edge,source){return edge===42&&source===1},
+ canWireTap(edge,source){return edge===42&&source===1},
+ consumeWire(changes){observed.push(changes)}
+ }},
+ wireWsOpen:true,wireWsInspect:{src:1,dst:2},wireWsRemoveConfirm:null,
+ wireWsEditBefore:null,
+ wireEdges:[primary,parallel],
+ tracks:[{id:1,kind:"audio",name:"Vocal"},{id:2,kind:"bus",name:"Bus A"}],
+ master:{id:3,kind:"master",name:"MAIN"},
+ wireWsRoutes:()=>[],
+ wireWsRouteKind:(src,dst)=>({kind:"wire",edge:src===1&&dst===2?primary:parallel}),
+ wireWsLabel:id=>"CH "+id,escapeHtml:s=>String(s),
+ wireSourceTrack:id=>({id}),wireGraphCommit(){throw Error("native must not mutate demo graph")},
+ wireWsSnapshot(){throw Error("native must not take demo undo snapshot")},
+ wireWsRecord(){throw Error("native must not create demo undo history")},
+ render(){throw Error("native must not rebuild mixer DOM")},
+ renderWireWorkspace(){throw Error("native must not rebuild inspector")},
+ say:s=>observed.push(s)
+ };
+ vm.runInNewContext(html.slice(renderStart,renderEnd),scope);
+ vm.runInNewContext("renderWireWsInspector()",scope);
+ assert.match(panel.innerHTML,/PRIMARY · UNITY/);
+ assert.match(panel.innerHTML,/data-ws-gain="41"[^>]+disabled/);
+ scope.wireWsInspect={src:1,dst:3};
+ vm.runInNewContext("renderWireWsInspector()",scope);
+ assert.match(panel.innerHTML,/data-ws-gain="42"/);
+ assert.doesNotMatch(panel.innerHTML,/data-ws-gain="42"[^>]+disabled/);
+ assert.match(panel.innerHTML,/POST FADER/);
+ const eventStart=html.indexOf("document.getElementById('wireWsInspector').addEventListener('focusin',");
+ const eventEnd=html.indexOf("document.getElementById('wireLegend').addEventListener('change',",eventStart);
+ assert.ok(eventStart>0&&eventEnd>eventStart);
+ vm.runInNewContext(html.slice(eventStart,eventEnd),scope);
+ const event=(element,selector)=>({target:{closest:name=>name===selector?element:null}});
+ handlers.input(event({dataset:{wsGain:"41"},value:"-10"},"[data-ws-gain]"));
+ assert.equal(observed.length,0,"PRIMARY BUS has no independent SEND gain");
+ handlers.input(event({dataset:{wsGain:"42"},value:"-12"},"[data-ws-gain]"));
+ assert.deepEqual(JSON.parse(JSON.stringify(observed[0])),[{
+ type:"GAIN",sourceId:1,edgeId:42,levelDb:-12
+ }],"PARALLEL MAIN has the exact writable EdgeId");
+ assert.equal(readout.textContent,"PENDING · -12 dB",
+ "input gesture is pending; never labels it accepted");
+ const picker={dataset:{wsTap:"42"},value:"split"};
+ handlers.change(event(picker,"[data-ws-tap]"));
+ assert.equal(picker.value,"send","native tap selector waits for independent PCM readback");
+ assert.deepEqual(JSON.parse(JSON.stringify(observed[1])),[{
+ type:"MODE",sourceId:1,edgeId:42,mode:"split"
+ }]);
+ assert.match(observed[2],/awaiting accepted native PCM readback/);
+ assert.equal(primary.levelDb,0);
+ assert.equal(parallel.levelDb,-6,"reference WIRE graph never becomes native routing owner");
+});
+
test("native PRE_FADER WIRE inspector uses one exact SET_TAP PCM intent and accepted readback",()=>{
const bridge=read("web/approved-native-bridge.js");
const preview=read("site/preview-v2/index.html");
diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js
index ab7831212..3aa78e0d6 100644
--- a/web/approved-native-bridge.js
+++ b/web/approved-native-bridge.js
@@ -372,14 +372,25 @@
return; // next coalesced target follows ACK + independent readback
}
}
- function requestWireGain(op){
+ // Every editable WIRE scalar must resolve an exact native ChannelId +
+ // EdgeId, not a destination kind, strip label, or reference graph index.
+ // A PARALLEL_SEND can legally point to MAIN; a PRIMARY_OUT can point to BUS.
+ function admittedParallelWire(uiSourceId,uiEdgeId,operation){
const current=controller?.state()?.current;
- const edgeId=wireByUiId.get(op.edgeId),source=nativeByUiId.get(op.sourceId);
+ const source=nativeByUiId.get(uiSourceId),edgeId=wireByUiId.get(uiEdgeId);
+ if(!flags.acceptedGraphConnected||!current?.admitted||current.retained||
+ !source||!edgeId||!current.graph.capabilities.supportedOps.includes(operation))
+ return null;
+ const matches=current.graph.edges.filter(e=>e.enabled&&
+ e.edgeId===edgeId&&e.from===source&&e.primaryOutput===false);
+ return matches.length===1?matches[0]:null;
+ }
+ function requestWireGain(op){
const db=Number(op.levelDb);
- if(!current?.admitted||!current.graph.capabilities.supportedOps.includes("SET_WIRE_GAIN")||
- !Number.isFinite(db)||db< -60||db>6)return false;
- const edge=current.graph.edges.find(e=>e.enabled&&e.edgeId===edgeId&&e.from===source);
- if(!edge||edge.primaryOutput!==false)return false;
+ if(!Number.isFinite(db)||db< -60||db>6||
+ !admittedParallelWire(op.sourceId,op.edgeId,"SET_WIRE_GAIN"))return false;
+ const current=controller.state().current;
+ const edgeId=wireByUiId.get(op.edgeId),source=nativeByUiId.get(op.sourceId);
// A physical SEND fader floor is -infinity (zero PCM), NOT -60 dB linear.
pendingWireGains.set(edgeId,{source,gain:db<=-60?0:Math.pow(10,db/20),identity:current.identity});
queueWireGainFlush();return true;
@@ -3643,6 +3654,14 @@
}
status("NATIVE: "+action+" is not an accepted ChannelId operation");return true;
},
+ canWireGain(uiEdgeId,uiSourceId){
+ return !!admittedParallelWire(uiSourceId,uiEdgeId,"SET_WIRE_GAIN");
+ },
+ canWireTap(uiEdgeId,uiSourceId){
+ const edge=admittedParallelWire(uiSourceId,uiEdgeId,"APPLY_WIRE_TRANSACTION");
+ return !!edge&&["PRE_FADER","POST_FADER"].includes(edge.tap)&&
+ !controller?.state()?.pending;
+ },
consumeWire(ops,retries=0) {
if (!connected)return false;
if(logicalView) {