Skip to content
Merged
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
34 changes: 31 additions & 3 deletions scripts/build_approved_native_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,49 @@ def accepted_pages_html() -> str:
NATIVE_EVENT_HOOKS = (
("function wireGraphCommit(ops,{record=true}={}){\n",
"function wireGraphCommit(ops,{record=true}={}){\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeWire?.(ops))return false;\n"),
" if(window.__JUCE__?.backend){window.__ARMIX_NATIVE_M2__?.consumeWire?.(ops);return false;}\n"),
("function wireWsUndo(){\n",
"function wireWsUndo(){\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeUndo?.())return false;\n"),
" if(window.__JUCE__?.backend){window.__ARMIX_NATIVE_M2__?.consumeUndo?.();return false;}\n"),
("function handleField(event){\n",
"function handleField(event){\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeField?.(event))return;\n"),
" if(window.__JUCE__?.backend){window.__ARMIX_NATIVE_M2__?.consumeField?.(event);return;}\n"),
(" if(a==='wireExpand'){document.querySelector('.section-rail",
" if(window.__JUCE__?.backend&&!window.__ARMIX_NATIVE_M2__?.enabled)return;\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeAction?.(t,a,btn))return;\n"
" if(a==='wireExpand'){document.querySelector('.section-rail"),
("document.querySelector('.console-body').addEventListener('dblclick',e=>{\n"
" const t=findTrack(e.target);if(!t)return;\n",
"document.querySelector('.console-body').addEventListener('dblclick',e=>{\n"
" const t=findTrack(e.target);if(!t)return;\n"
" if(window.__JUCE__?.backend&&!window.__ARMIX_NATIVE_M2__?.enabled)return;\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeDoubleClick?.(e,t))return;\n"),
# Native-only: prevent keyboard FX moves from mutating demo inserts in JUCE.
("function fxNativeTransactionRequired(){\n",
"function fxNativeTransactionRequired(){\n"
" if(window.__JUCE__?.backend)return true;\n"),
# Source's pointerup clears faderGesture BEFORE the later deferred bridge
# listener runs. Dispatch exactly once at the actual gesture commit point.
(" const g=faderGesture;faderGesture=null;\n"
" g.box.releasePointerCapture?.(ev.pointerId);\n",
" const g=faderGesture;faderGesture=null;\n"
" g.box.releasePointerCapture?.(ev.pointerId);\n"
" if(window.__ARMIX_NATIVE_M2__?.consumeField?.({target:g.input,type:'change'}))return;\n"),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve Sends on Faders semantics when committing native gestures

With an admitted native graph containing a GROUP or FX_RETURN, #sofToggle still enables Sends on Faders through the original GUI handler. This new pointer-release hook nevertheless calls consumeField, which unconditionally translates level into SET_FADER; it never checks sofEnabled or the selected send destination. Consequently, moving a fader labeled SEND changes the channel's main gain instead of its send, despite toggleSof() explicitly promising that main faders are protected. Expose the active fader mode and dispatch the appropriate native send operation, or block Sends on Faders until that operation is supported.

AGENTS.md reference: AGENTS.md:L16-L16

Useful? React with 👍 / 👎.

# Native WebView2 only: expose the original Pages IIFE model to the thin
# bridge. No second renderer/state reducer, no change to public /preview/.
("restorePluginPreferences();init();\n})();",
"window.__ARMIX_NATIVE_SCOPE__=Object.freeze({\n"
" get tracks(){return tracks;},get master(){return master;},\n"
" make,render,findTrack,displayMeterDbfs,\n"
" colors:COLORS,wireGraph:ArSonWireGraph,\n"
" allocateWireId(){return nextWireId++;},\n"
" installGraph(channels,main,edges){\n"
" tracks=channels;master=main;wireEdges=edges;\n"
" wireWsHistory=[];selectedWireEdgeId=null;\n"
" syncWireOutputProjection();render();\n"
" },\n"
" stopDemo(){if(preview)togglePreview();}\n"
"});\nrestorePluginPreferences();init();\n})();"),
)


Expand Down
8 changes: 8 additions & 0 deletions tests/approved_native_gui_bundle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self)
self.assertEqual(bundle.public_from_native(native), approved)
self.assertNotIn("__ARMIX_NATIVE_M2__", approved)
self.assertIn("__ARMIX_NATIVE_M2__", native)
# M3 native-only scope is embedded inside the existing Pages IIFE:
# no visual duplication; it must be stripped in public_from_native.
self.assertIn("window.__ARMIX_NATIVE_SCOPE__=Object.freeze({", native)
self.assertNotIn("__ARMIX_NATIVE_SCOPE__", approved)
self.assertIn("make,render,findTrack,displayMeterDbfs", native)
self.assertIn("installGraph(channels,main,edges)", native)
self.assertIn("if(window.__JUCE__?.backend)return true;", native)
self.assertIn("consumeField?.({target:g.input,type:'change'})", native)
self.assertEqual(manifest["approvedPagesHtmlSha256"], bundle.sha256((source / "index.html").read_bytes()))
self.assertNotEqual(native, (ROOT / "web/index.html").read_text("utf-8"))
self.assertIn("approved-native-bridge.js", native)
Expand Down
104 changes: 104 additions & 0 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,107 @@ test("M2 code edits approved Pages *events* only, not a second native GUI/audio
assert.doesNotMatch(native,/BinaryData::consolenative_html|BinaryData::index_html/);
assert.doesNotMatch(adapter,/AudioContext|AudioWorklet|processBlock|setChannelGainDb/);
});

test("M3 native-only Pages scope performs real bridge projection, fader intent and ACK readback",()=>{
const vm=require("node:vm"),sent=[],listeners=new Map();
let nextId=100,nextEdgeId=200,paints=0,rollbacks=0;
const scope={
tracks:[],master:{id:1,name:"Master"},colors:["#568ead"],
wireGraph:{validateCandidateGraph:()=>({ok:true})},
make:(name,kind,color)=>({id:nextId++,name,kind,color,selected:false}),
render(){paints++;},
findTrack(){return this.tracks[0];},
displayMeterDbfs(){},
allocateWireId(){return nextEdgeId++;},
installGraph(channels,main,edges){
this.tracks=channels;this.master=main;this.edges=edges;this.render();
},
stopDemo(){}
};
const native={
emitEvent:(name,payload)=>sent.push({name,payload}),
addEventListener:(name,fn)=>listeners.set(name,fn)
};
const info={textContent:""},previewButton={disabled:false,setAttribute(){}};
const document={
readyState:"complete",documentElement:{dataset:{}},
getElementById:id=>id==="info"?info:id==="preview"?previewButton:null,
querySelector:()=>null,addEventListener(){}
};
const window={
__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},setTimeout(){return 0;}
};
vm.runInNewContext(read("web/approved-native-bridge.js"),{
window,document,performance:{now:()=>0},console
},{timeout:1500});
assert.equal(sent[0].name,"arMixGuiReady");
assert.equal(sent[1].name,"arMixConsoleSubscribe");
assert.equal(window.__ARMIX_APPROVED_NATIVE_GUI__.acceptedGraphConnected,false);
const accepted=acceptedFixture();
listeners.get("arMixConsoleSnapshot")(accepted);
assert.equal(window.__ARMIX_APPROVED_NATIVE_GUI__.acceptedGraphConnected,true);
assert.equal(scope.tracks.length,1);
assert.equal(scope.tracks[0].level,-6);
assert.equal(scope.edges[0].sourceId,scope.tracks[0].id);
assert.equal(previewButton.disabled,true);
const gesture={dataset:{field:"level"},value:"-12",min:"-60",max:"10",closest:()=>null};
assert.equal(window.__ARMIX_NATIVE_M2__.consumeField({target:gesture,type:"change"}),true);
const command=sent.findLast(x=>x.name==="arMixConsoleIntent");
assert.ok(command);
assert.equal(command.payload.operation,"SET_FADER");
assert.equal(command.payload.targetChannelId,"9007199254740993");
assert.equal(command.payload.payload.valueDb,-12);
assert.equal(scope.tracks[0].level,-6,"GUI cannot optimistically commit before readback");
listeners.get("arMixConsoleAck")({
requestId:command.payload.requestId,status:"ACCEPTED",errorCode:"NONE",
deviceEpoch:accepted.device.epoch,graphRevision:"5",rosterRevision:"7"
});
assert.equal(scope.tracks[0].level,-6,"ACK alone cannot repaint");
const updated=clone(accepted);updated.graph.channels[0].controls.faderDb=-12;
listeners.get("arMixConsoleSnapshot")(updated);
assert.equal(scope.tracks[0].level,-12);
const before=paints;
gesture.value="-24";
window.__ARMIX_NATIVE_M2__.consumeField({target:gesture,type:"change"});
const rejected=sent.findLast(x=>x.name==="arMixConsoleIntent").payload;
listeners.get("arMixConsoleAck")({
requestId:rejected.requestId,status:"REJECTED",errorCode:"UNSUPPORTED_OP",
deviceEpoch:accepted.device.epoch,graphRevision:"5",rosterRevision:"7"
});
rollbacks=paints-before;
assert.ok(rollbacks>0,"REJECTED restores the original GUI model");
assert.equal(scope.tracks[0].level,-12);
assert.equal(window.__ARMIX_NATIVE_M2__.state().pending,null);
// Selected hardware WIRE gesture must bind to the *real* decimal-string
// EdgeId and publish only after native graph ACK + a later PCM readback.
const sourceUi=scope.tracks[0].id,edgeUi=scope.edges[0].id;
assert.equal(window.__ARMIX_NATIVE_M2__.consumeWire([
{type:"REMOVE",sourceId:sourceUi,edgeId:edgeUi}
]),true);
const wire=sent.findLast(x=>x.name==="arMixConsoleIntent").payload;
assert.equal(wire.operation,"APPLY_WIRE_TRANSACTION");
assert.equal(wire.targetChannelId,"9007199254740993");
assert.equal(wire.payload.changes[0].edgeId,"9223372036854775808");
assert.equal(scope.edges.length,1,"pending WIRE cannot change drawn routing");
listeners.get("arMixConsoleAck")({
requestId:wire.requestId,status:"ACCEPTED",errorCode:"NONE",
deviceEpoch:accepted.device.epoch,graphRevision:"6",rosterRevision:"7"
});
assert.equal(scope.edges.length,1,"ACK is not the graph publication");
const unwired=clone(updated);unwired.graph.revision="6";unwired.graph.edges=[];
listeners.get("arMixConsoleSnapshot")(unwired);
assert.equal(scope.edges.length,0,"accepted snapshot replaces reference wire");
});

test("M3 Windows bundle owns pointerup fader gesture and fences native FX keyboard reorder",()=>{
const builder=read("scripts/build_approved_native_gui.py");
const bridge=read("web/approved-native-bridge.js");
assert.ok(builder.includes("const g=faderGesture;faderGesture=null;"));
assert.ok(builder.includes("consumeField?.({target:g.input,type:'change'})"));
assert.ok(builder.includes("function fxNativeTransactionRequired"));
assert.ok(builder.includes("__ARMIX_NATIVE_SCOPE__"));
assert.ok(bridge.includes("scope.installGraph(nextTracks,nextMaster,edges)"));
assert.ok(bridge.includes("scope?.findTrack?.(el)"));
assert.ok(!bridge.includes('window.addEventListener("pointerup"'));
});
84 changes: 51 additions & 33 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"use strict";
const backend = window.__JUCE__?.backend;
const protocol = window.ArSonApprovedNativeContract;
// The public GUI owns one lexical model. Native-only bundle exports a narrow
// reference to that SAME model; never reconstruct a parallel DOM/DSP.
const scope = window.__ARMIX_NATIVE_SCOPE__ || null;
const connected = Boolean(backend?.emitEvent && backend?.addEventListener && protocol);
// The old M1 wording is retained as an explicit boot-time fallback for
// release-train compatibility, NOT a claim that a demo graph is audio.
Expand All @@ -25,10 +28,7 @@
// reference-only physical operations are never passed off as live audio.
const demo = document.getElementById("preview");
if (demo) {demo.disabled = true;demo.title = "Demo meters disabled in native Windows application";}
if (typeof preview !== "undefined" && preview) {
preview = false; // original Pages animation sees false and stops itself
demo?.setAttribute("aria-pressed","false");
}
scope?.stopDemo?.();
document.documentElement.dataset.armixNativeAuthority =
flags.productionCallbackLive ? "product-live" :
flags.acceptedGraphConnected ? "pcm-accepted" : "not-admitted";
Expand All @@ -47,21 +47,21 @@
};
function projection(native) {
if (!native?.admitted || !Array.isArray(native.graph.edges) ||
typeof make !== "function" || typeof render !== "function" ||
typeof ArSonWireGraph === "undefined") return false;
!scope?.make || !scope?.render || !scope?.wireGraph ||
!scope?.installGraph || !scope?.allocateWireId) return false;
const accepted = native.graph;
// No fake default fader/mute/solo when the producer omitted real readback.
if (accepted.channels.some(ch => !ch.controls ||
!["faderDb","pan","mute","solo"].every(k => Object.hasOwn(ch.controls,k)))) return false;
const previous = new Map(tracks.concat(master).map(t=>[t.id,t]));
const previous = new Map(scope.tracks.concat(scope.master).map(t=>[t.id,t]));
const nextTracks = [], localByNative = new Map(), nextNativeByUi = new Map();
let nextMaster = null;
for (const [index,ch] of accepted.channels.entries()) {
const kind = ch.role==="MAIN"?"master":ch.role==="GROUP"?"bus":
ch.role==="FX_RETURN"?"fx":"audio";
const savedId = uiByNativeId.get(ch.id);
const t = savedId !== undefined && previous.has(savedId) ?
previous.get(savedId) : make(ch.name,kind,COLORS[index%COLORS.length]||"#568ead");
previous.get(savedId) : scope.make(ch.name,kind,scope.colors[index%scope.colors.length]||"#568ead");
if (savedId !== undefined) t.id = savedId;
// No Number(ch.id): all native identities stay canonical uint64 strings.
localByNative.set(ch.id,t.id);
Expand Down Expand Up @@ -99,30 +99,27 @@
const gainDb=isMain?0:Math.round(Math.max(-60,Math.min(6,
edge.gainLinear>0?20*Math.log10(edge.gainLinear):-60))*10)/10;
let uiId=uiByWireId.get(edge.edgeId);
if (uiId===undefined) uiId=nextWireId++;
if (uiId===undefined) uiId=scope.allocateWireId();
newWireByUi.set(uiId,edge.edgeId);
newUiByWire.set(edge.edgeId,uiId);
edges.push({id:uiId,sourceId:src,destId:dst,kind,mode,
enabled:true,levelDb:gainDb});
}
if (!ArSonWireGraph.validateCandidateGraph(nextTracks,nextMaster.id,edges).ok) return false;
if (!scope.wireGraph.validateCandidateGraph(nextTracks,nextMaster.id,edges).ok) return false;
const previouslySelected = nextTracks.filter(t=>t.selected);
if (!previouslySelected.length && nextTracks.length) nextTracks[0].selected=true;
// One atomic accepted readback projection. Demo wire reducer NEVER runs.
tracks=nextTracks;master=nextMaster;wireEdges=edges;
for (const [id,ui] of localByNative) uiByNativeId.set(id,ui);
nativeByUiId.clear();for(const [ui,id] of nextNativeByUi)nativeByUiId.set(ui,id);
wireByUiId.clear();for(const [ui,id] of newWireByUi)wireByUiId.set(ui,id);
uiByWireId.clear();for(const [id,ui] of newUiByWire)uiByWireId.set(id,ui);
if (typeof wireWsHistory!=="undefined")wireWsHistory=[];
selectedWireEdgeId=null;
syncWireOutputProjection();render();
scope.installGraph(nextTracks,nextMaster,edges);
return true;
}
// Native telemetry owns the physical meter. When no measured per-channel
// samples are published, leave the meter dark; never use Pages sine demo.
function paintNativeMeters(next) {
if (typeof displayMeterDbfs!=="function")return;
if (!scope?.displayMeterDbfs)return;
const data=next.telemetry?.channelMeterRmsPeak;
if (!data || typeof data!=="object")return;
const ts=performance.now();
Expand All @@ -141,7 +138,7 @@
const fill=root.querySelector('.meter-fill.'+side);
if(!fill)return;
const db=peak===null || peak===0?-90:20*Math.log10(peak);
displayMeterDbfs(fill,Math.max(-90,Math.min(6,db)),ts,ui+':'+(side==="left"?"L":"R"));
scope.displayMeterDbfs(fill,Math.max(-90,Math.min(6,db)),ts,ui+':'+(side==="left"?"L":"R"));
};
paint("left",l);
paint("right",right);
Expand Down Expand Up @@ -185,9 +182,15 @@
if(state.lastError==="PENDING_NATIVE_ACK"||state.lastError==="PENDING_ACCEPTED_SNAPSHOT")
status("NATIVE "+state.lastError+" · awaiting authoritative readback");
else if(state.lastError!=="ACCEPTED_READBACK"&&state.lastError!=="NONE"&&
state.lastError!=="NATIVE_NOT_SUBSCRIBED"&&
state.lastError!=="INVALID_NATIVE_SNAPSHOT")
state.lastError!=="NATIVE_NOT_SUBSCRIBED") {
lastNativeError=state.lastError;
// Native REJECTED / STALE / timeout must roll back a temporary fader
// cap and every input value; no optimistic GUI state survives.
if (!state.pending && flags.acceptedGraphConnected && scope?.render) {
scope.render();
if(state.current)paintNativeMeters(state.current);
}
}
}
});
backend.addEventListener("arMixConsoleSnapshot", snapshot=>controller.onSnapshot(snapshot));
Expand All @@ -199,21 +202,43 @@
if (!connected)return false;
const el=event.target,field=el?.dataset?.field;
if (!field)return false;
const t=typeof findTrack==="function"?findTrack(el):null;
const t=scope?.findTrack?.(el) || null;
if (!t)return true;
if (!flags.acceptedGraphConnected) {
if (field==="level")el.value=String(t.level);
else if (field==="pan")el.value=String(t.pan);
status("NATIVE: ChannelId PCM not admitted; control unchanged");
return true;
}
if (event.type!=="change") return true; // no optimistic input-frame mutations
// During a native pointer drag move the approved fader *cap* only.
// The authoritative track/PCM state stays unchanged until ACK+readback.
if (event.type!=="change") {
if (field==="level") {
const n=Number(el.value),min=Number(el.min),max=Number(el.max);
if ([n,min,max].every(Number.isFinite)&&max>min) {
const p=Math.max(0,Math.min(100,100*(n-min)/(max-min)));
const box=el.closest?.(".fader-box");
box?.style?.setProperty("--fader-fill",p+"%");
box?.style?.setProperty("--fader-lit",String(p/100));
box?.style?.setProperty("--fader-y",(100-p)+"%");
box?.style?.setProperty("--fader-frac",String(p/100));
Comment on lines +221 to +224

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restore the accepted fader position when a pointer drag is canceled

If a native fader drag ends with pointercancel rather than pointerup, these new CSS updates leave the cap at the uncommitted position. The original cancellation handler in site/preview-v2/index.html only clears faderGesture, so no intent is submitted and no ACK rejection or timeout triggers the new rollback path. Subsequent unchanged native snapshots also skip projection through lastPaintedSignature, leaving the displayed gain inconsistent with accepted audio state indefinitely. Add a native cancellation hook that restores the input and cap from the accepted track state.

AGENTS.md reference: AGENTS.md:L18-L18

Useful? React with 👍 / 👎.

}
}
return true;
}
const numeric=Number(el.value);
if (field==="level"&&Number.isFinite(numeric))
intent("SET_FADER",t,{valueDb:numeric});
else if (field==="pan"&&Number.isFinite(numeric))
intent("SET_PAN",t,{value:numeric/100});
else status("NATIVE: "+field+" awaits native capability; reference graph unchanged");
else if (field==="pan"&&Number.isFinite(numeric)) {
// Preserve hardware center detent without publishing demo PAN state.
const fine=el.dataset.panKeyboard==="true";
const bypass=el.dataset.panAltPointer==="true";
const value=!fine&&!bypass&&Math.abs(numeric)<=12?0:numeric;
intent("SET_PAN",t,{value:value/100});
} else {
status("NATIVE: "+field+" awaits native capability; reference graph unchanged");
scope?.render?.(); // restore SELECT/route control from accepted graph
}
return true;
},
consumeAction(t,action,btn) {
Expand Down Expand Up @@ -311,16 +336,9 @@
event.preventDefault();event.stopImmediatePropagation();
status("NATIVE: "+target.id+" requires real engine admission and readback");
},true);
// Native pointer fader uses the approved physical fader geometry, but no
// reference JS gain state. Send once at release, not on every pointer frame.
window.addEventListener("pointerup",()=>{
if (typeof faderGesture==="undefined"||!faderGesture)return;
const input=faderGesture.input,t=typeof findTrack==="function"?findTrack(input):null;
if (t) {
const db=Number(input.value);
if(Number.isFinite(db))intent("SET_FADER",t,{valueDb:db});
}
},true);
// Native fader is committed exactly once INSIDE the original GUI's
// finishFaderPointer via build_approved_native_gui.py hook. A later
// window.pointerup listener would run after that handler clears the gesture.
const ready=()=>{
stopDemo();
status("NATIVE: subscribed · waiting for true device and accepted ChannelId graph");
Expand Down
Loading