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
3 changes: 3 additions & 0 deletions scripts/build_approved_native_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
NATIVE_ADAPTER = ROOT / "web" / "approved-native-bridge.js"
ADAPTER_MARKER = ('<script defer src="assets/approved-native-contract.js"></script>\n'
'<script defer src="assets/approved-device-view-model.js"></script>\n'
'<script defer src="assets/approved-channel-strip-view-model.js"></script>\n'
'<script defer src="assets/approved-native-bridge.js"></script>\n'
'<script defer src="assets/approved-native-context-menu.js"></script>\n'
'<script defer src="assets/approved-native-legal.js"></script>\n')
Expand Down Expand Up @@ -362,6 +363,8 @@ def stage(out: Path) -> dict:
out / "assets" / "approved-native-contract.js")
shutil.copy2(ROOT / "web" / "approved-device-view-model.js",
out / "assets" / "approved-device-view-model.js")
shutil.copy2(ROOT / "web" / "approved-channel-strip-view-model.js",
out / "assets" / "approved-channel-strip-view-model.js")
native = native_html(approved.decode("utf-8")).encode("utf-8")
(out / "index.html").write_bytes(native)
files = [out / "index.html", *sorted(p for p in (out / "assets").rglob("*") if p.is_file())]
Expand Down
5 changes: 5 additions & 0 deletions tests/approved_native_cold_start_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def main():
# capture prerequisite. Verify native intent/ACK on the approved
# assembled Windows GUI at every supported viewport.
page.locator('.command-bar [data-native-io]').click()
assert page.evaluate("""()=>Boolean(
window.ArSonApprovedChannelStripViewModel &&
window.__ARMIX_NATIVE_M2__?.inputChoices &&
window.__ARMIX_NATIVE_M2__?.outputChoices)"""), (
'native assembled GUI missing GUI-1 Channel Strip ViewModel')
io_inventory={
'types':[{'name':'Windows Audio','separate':True,
'inputs':['Studio Mic'],'outputs':['Speakers']}],
Expand Down
6 changes: 6 additions & 0 deletions tests/approved_native_gui_bundle_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ def test_native_is_exact_assembled_public_pages_plus_nonvisual_native_seam(self)
self.assertLess(native.index('assets/approved-native-contract.js'),
native.index('assets/approved-device-view-model.js'))
self.assertLess(native.index('assets/approved-device-view-model.js'),
native.index('assets/approved-channel-strip-view-model.js'))
self.assertLess(native.index('assets/approved-channel-strip-view-model.js'),
native.index('assets/approved-native-bridge.js'))
self.assertNotIn('assets/approved-channel-strip-view-model.js', approved)
self.assertEqual(
(out / 'assets/approved-channel-strip-view-model.js').read_bytes(),
(ROOT / 'web/approved-channel-strip-view-model.js').read_bytes())
vm_source = (ROOT / "web/approved-device-view-model.js").read_bytes()
self.assertEqual((out / "assets/approved-device-view-model.js").read_bytes(),
vm_source)
Expand Down
142 changes: 137 additions & 5 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const assert=require("node:assert/strict");
const {readFileSync}=require("node:fs");
const protocol=require("../web/approved-native-contract.js");
const deviceVM=require("../web/approved-device-view-model.js");
const stripVM=require("../web/approved-channel-strip-view-model.js");
const read=p=>readFileSync(p,"utf8");
const fixtures=JSON.parse(read("integration/console-v6/fixtures.json"));
const clone=x=>JSON.parse(JSON.stringify(x));
Expand Down Expand Up @@ -1248,7 +1249,7 @@ test("M3 native-only Pages scope performs real bridge projection, fader intent a
querySelector:()=>null,addEventListener(){}
};
const window={
__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},queueMicrotask(fn){microtasks.push(fn);},setTimeout(fn,ms){timers.push({fn,ms});return timers.length;}
};
vm.runInNewContext(read("web/approved-native-bridge.js"),{
Expand Down Expand Up @@ -1472,7 +1473,7 @@ test("P0 native FX rack and per-slot readback update mounted strip without repla
querySelector:selector=>selector.startsWith('.strip[data-id=')?strip:null,
addEventListener(){}
};
const win={__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
const win={__JUCE__:{backend:native},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},
setTimeout(){return 0},clearTimeout(){},queueMicrotask(fn){fn();}};
vm.runInNewContext(read("web/approved-native-bridge.js"),
Expand Down Expand Up @@ -1650,7 +1651,7 @@ test("P0 FIRST SOUND G0 offers verified input and leaves automatic MAIN to nativ
addEventListener(){}
};
win={
__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},
setTimeout(){return 0},clearTimeout(){},queueMicrotask(fn){fn();}
};
Expand Down Expand Up @@ -1737,7 +1738,7 @@ test("P0 native hardware IN remains selectable after ChannelId ownership, failed
id==="preview"?{disabled:true}:null,
querySelector:()=>null,addEventListener(){}
};
const win={__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
const win={__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,ArSonApprovedChannelStripViewModel:stripVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},
setTimeout(){return 0},clearTimeout(){},
queueMicrotask(fn){microtasks.push(fn);}};
Expand Down Expand Up @@ -2164,7 +2165,9 @@ test("O2 external OUT never reports LIVE while driver output is muted",()=>{
assert.match(projection,/snapshot\?\.device\?\.outputArmed===true\?"LIVE":"MUTED"/);
assert.match(projection,/state==="MUTED"\?"ASIO pair connected/);
assert.match(bridge,/deviceVM\.externalPresentation\(next,row,choices\)/);
assert.match(bridge,/state==="LIVE"\|\|state==="MUTED"/);
assert.match(bridge,/stripVM\.externalPending\(pending,next\?\.device\?\.epoch,state,row\)/);
assert.match(read("web/approved-channel-strip-view-model.js"),
/state==="LIVE"\|\|state==="MUTED"/);
assert.match(bridge,/EXTERNAL OUT patched · hardware output muted/);
assert.match(css,/external-out-state\[data-status="MUTED"\]/);
});
Expand Down Expand Up @@ -2625,3 +2628,132 @@ test("MV-2 render uses the existing one ViewModel and keeps native transport aut
assert.equal(deviceVM.setupPresentation(inventory,deviceVM.setupDraft(inventory),{
...deviceVM.setupInitial(),remapGeneration:inventory.active.deviceGeneration}).canReusePins,true);
});


// GUI-1: native source/OUT Channel Strip presentation has zero DOM or
// mixer-owned state. One tested model is used by native readback & hook UI.
test("GUI-1 Channel Strip output labels preserve uint64 identity, reserved names and source-only",()=>{
const large="18446744073709551615",dup="9007199254740993";
const channels=[
{id:"11",role:"INPUT",name:"Vocal"},
{id:large,role:"GROUP",name:"Master"},
{id:dup,role:"GROUP",name:"Drums"},
{id:"17",role:"FX_RETURN",name:"Drums"},
{id:"99",role:"MAIN",name:"MAIN"}];
const targets=stripVM.outputTargets(channels,"11",row=>row.name);
assert.deepEqual(targets,[
{id:large,label:"Master ["+large+"]"},
{id:dup,label:"Drums ["+dup+"]"},
{id:"17",label:"Drums [17]"}]);
assert.equal(stripVM.resolvePrimarySelection("Master",targets),"MAIN");
assert.equal(stripVM.resolvePrimarySelection("SOURCE ONLY (No Main)",targets),"NONE");
assert.equal(stripVM.resolvePrimarySelection("Drums ["+dup+"]",targets),
"Drums ["+dup+"]");
assert.equal(stripVM.resolvePrimarySelection("Drums",targets),null,
"ambiguous human names cannot silently route another channel");
assert.equal(stripVM.resolvePrimarySelection("Unknown",targets),null);
const output=stripVM.primaryChoices({track:{kind:"audio",output:"Master"},
authority:"CHANNEL_ID",targets});
assert.deepEqual(output.slice(0,2),["Master","SOURCE ONLY (No Main)"]);
assert.ok(output.includes("Master ["+large+"]"));
assert.equal(JSON.stringify(channels).includes(large),true);
});
test("GUI-1 Channel Strip source, physical output and MAIN pickers fail closed on loss",()=>{
const t={kind:"audio",input:"None",output:"Master",
externalOutput:"Needs Remap · OUT 3/4"};
const pins=[{label:"None"},{label:"Mono · Mic 1"}];
assert.deepEqual(stripVM.inputChoices(t,pins,false,false,
"Internal BUS (read-only)"),["None","Mono · Mic 1"]);
const bus={...t,input:"Internal BUS (read-only)"};
assert.ok(stripVM.inputChoices(bus,pins,false,false,"Internal BUS (read-only)")
.includes("Internal BUS (read-only)"));
assert.deepEqual(stripVM.inputChoices(bus,pins,true,false,
"Internal BUS (read-only)"),["Internal BUS (read-only)"],
"retained hardware cannot propose new physical IN");
assert.deepEqual(stripVM.inputChoices({kind:"bus",input:"Mic 1"},pins,
false,false,"Internal BUS (read-only)"),["None"]);
assert.deepEqual(stripVM.externalChoices(t,[{label:"None"},{label:"OUT 5/6"}]),
["None","OUT 5/6","Needs Remap · OUT 3/4"]);
assert.deepEqual(stripVM.externalChoices({kind:"master"},[]),["None"]);
assert.deepEqual(stripVM.primaryChoices({track:{kind:"master",output:"Master"},
retained:true,playbackDevice:"Old ASIO"}),["Audio connection lost"]);
assert.deepEqual(stripVM.primaryChoices({track:{kind:"master"},
logical:true}),["Choose audio output"]);
assert.deepEqual(stripVM.primaryChoices({track:t,authority:"M4",targets:[
{id:"9",label:"BUS A"}]}),["Master","SOURCE ONLY (No Main)"],
"M4 never advertises ChannelId BUS routing");
});
test("GUI-1 Channel Strip input and PRIMARY OUT require installed native readback",()=>{
const channels=[{id:"1",role:"INPUT",primaryOutId:"100",
source:{portId:"in:0",sourceFormat:"MONO"}},
{id:"100",role:"MAIN",name:"MAIN"}];
const read=stripVM.readbackBindings({native:{retained:false},
channel:channels[0],channels,targets:[],
inputLabel:p=>p.left===0?"Mono · Mic 1":"None"});
assert.deepEqual(read,{input:"Mono · Mic 1",output:"Master"});
const offline=stripVM.readbackBindings({native:{retained:true},
channel:{...channels[0],primaryOutId:null,
source:{bindingState:"NEEDS_REMAP",portId:"in:0"}},
channels,targets:[],inputLabel:()=>{throw Error("no phantom pin");}});
assert.deepEqual(offline,{input:"Audio connection lost",
output:"SOURCE ONLY (No Main)"});
const invalid=stripVM.readbackBindings({native:{retained:false},
channel:{...channels[0],source:{portId:"in:9007199254740993"}},
channels,targets:[],inputLabel:()=>{throw Error("unsafe port index");}});
assert.equal(invalid.input,"None");
});
test("GUI-1 external OUT pending waits for matching ACK and later readback",()=>{
const p={requestId:"ext-1",epoch:"19",left:2,right:3,acked:false};
const row={physicalLeft:2,physicalRight:3};
assert.equal(stripVM.externalPending(p,"19","LIVE",row),"PENDING",
"installed-looking row cannot clear command without correlated ACK");
const ack={...p,acked:true};
assert.equal(stripVM.externalPending(ack,"19","LIVE",
{...row,physicalRight:5}),"PENDING");
assert.equal(stripVM.externalPending(ack,"18","LIVE",row),"STALE",
"new device epoch invalidates pending output");
assert.equal(stripVM.externalPending(ack,"19","MUTED",row),"CONFIRMED");
assert.equal(stripVM.externalPending(ack,"19","LIVE",null),"PENDING");
assert.equal(stripVM.externalPending({...ack,left:-1,right:-1},
"19","NONE",null),"CONFIRMED","remove requires observed absent row");
assert.equal(stripVM.externalPending(null,"19","LIVE",row),"NONE");
});
test("GUI-1 packaged native bridge uses one strip selector and one route dispatcher",()=>{
const s=read("web/approved-native-bridge.js");
const model=read("web/approved-channel-strip-view-model.js");
assert.match(s,/stripVM\.readbackBindings\(/);
assert.match(s,/stripVM\.externalPending\(/);
assert.match(s,/stripVM\.inputChoices\(/);
assert.match(s,/stripVM\.primaryChoices\(/);
assert.match(s,/stripVM\.resolvePrimarySelection\(/);
assert.doesNotMatch(s,/const source=nativeIdFor\(t\),reserved=/);
assert.doesNotMatch(s,/const destination=nativeOutputTargets\(t\)\.find\(ch=>ch.label===el.value\)/);
assert.doesNotMatch(model,/backend\.emitEvent|AudioContext|AudioWorklet|document\.|localStorage|createPluginInstance/);
assert.equal((s.match(/backend\.emitEvent\("arMixAction",\{action:"routingExternalOutput"/g)||[]).length,1);
});
test("MV-2 merged #767 retains one selector; #768 unique duplex/one-pin guards are forward-ported",()=>{
const inventory={active:{open:true,authorized:true,backend:"ASIO",
captureDevice:"Duplex A",playbackDevice:"Duplex A",deviceGeneration:12,
enabledInputs:[0],enabledOutputs:[0,1],inputNames:["Mic"],
outputNames:["L","R"],rates:[48000],buffers:[256]},
types:[{name:"ASIO",separate:false,inputs:["Duplex A","Duplex B"],
outputs:["Duplex A","Duplex B"]}]};
const draft=deviceVM.setupDraft(inventory);
const changed=deviceVM.setupEditDraft(draft,inventory,{field:"playback",value:"Duplex B"});
assert.equal(changed.capture,"Duplex B");
assert.equal(changed.playback,"Duplex B");
assert.deepEqual(changed.outputPins,null);
assert.equal(changed.rate,0);
assert.equal(deviceVM.setupPresentation(inventory,changed).canApply,true);
assert.equal(deviceVM.setupBegin(deviceVM.setupInitial(),
{inventory,draft:changed,requestId:"gui1-duplex"}).request.config.captureDevice,"Duplex B");
const onePin=deviceVM.setupEditDraft(draft,inventory,
{side:"output",index:1,checked:false});
assert.equal(deviceVM.setupPresentation(inventory,onePin).canApply,false);
assert.equal(deviceVM.setupBegin(deviceVM.setupInitial(),
{inventory,draft:onePin,requestId:"gui1-one"}),null);
const reset={...draft,outputPins:null,inputPins:null};
const recovered=deviceVM.setupBegin(deviceVM.setupInitial(),
{inventory,draft:reset,requestId:"gui1-fallback"});
assert.deepEqual(recovered.request.config.enabledOutputs,[0,1]);
});
2 changes: 2 additions & 0 deletions tests/live_fader_held_drag.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {readFileSync}=require("node:fs");
const vm=require("node:vm");
const protocol=require("../web/approved-native-contract.js");
const deviceVM=require("../web/approved-device-view-model.js");
const stripVM=require("../web/approved-channel-strip-view-model.js");
const read=p=>readFileSync(p,"utf8");
const clone=x=>JSON.parse(JSON.stringify(x));
const fixture=JSON.parse(read("integration/console-v6/fixtures.json")).g0;
Expand Down Expand Up @@ -77,6 +78,7 @@ function harness({m4=false}={}){
};
const window={
__JUCE__:{backend},ArSonApprovedNativeContract:protocol,ArSonApprovedDeviceViewModel:deviceVM,
ArSonApprovedChannelStripViewModel:stripVM,
__ARMIX_NATIVE_SCOPE__:scope,addEventListener(){},
setTimeout(fn,delay=0){timers.push({fn,at:now+Math.max(0,Number(delay)||0)});return timers.length;}
};
Expand Down
95 changes: 95 additions & 0 deletions web/approved-channel-strip-view-model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// SPDX-License-Identifier: AGPL-3.0-only
// GUI-1: pure Channel Strip SOURCE/OUTPUT presentation for the ONE native
// /preview/ mixer. No DOM, dispatch, installed mixer state, or PCM authority.
(function (root, factory) {
const api=factory();
if(typeof module==="object"&&module.exports)module.exports=api;
if(root)root.ArSonApprovedChannelStripViewModel=api;
})(typeof globalThis==="object"?globalThis:undefined,function () {
"use strict";
const ONLY="SOURCE ONLY (No Main)";
const RESERVED=new Set(["Master",ONLY,"MAIN","NONE"]);
const REMAP="Audio connection lost";
// Preserve decimal-string native ChannelIds, even beyond JS safe integers.
// Reserved and duplicate operator names cannot shadow OUT commands.
function outputTargets(channels,sourceId,nameFor) {
if(!Array.isArray(channels))return [];
const rows=channels.map(ch=>({ch,name:typeof nameFor==="function"?
nameFor(ch):ch?.name}));
const counts=new Map();
for(const row of rows)counts.set(row.name,(counts.get(row.name)||0)+1);
return rows.filter(({ch})=>ch&&ch.id!==sourceId&&
["INPUT","GROUP","FX_RETURN"].includes(ch.role)).map(({ch,name})=>({
id:ch.id,label:RESERVED.has(name)||counts.get(name)>1?
name+" ["+ch.id+"]":name}));
}
function inputChoices(track,physical,retained,logical,internalBus) {
if(track?.kind!=="audio")return ["None"];
if(retained&&!logical)return [track.input||"None"];
const labels=Array.isArray(physical)?physical.map(p=>p.label):["None"];
// Internal BUS is a readback-only label, never offered as a physical pin.
if(track.input===internalBus&&!labels.includes(internalBus))
labels.push(internalBus);
return labels;
}
function externalChoices(track,pairs) {
if(track?.kind==="master")return ["None"];
const labels=Array.isArray(pairs)?pairs.map(p=>p.label):[];
if(track?.externalOutput&&!labels.includes(track.externalOutput))
labels.push(track.externalOutput);
return labels;
}
function primaryChoices({track,logical=false,retained=false,
playbackDevice="",authority="",targets=[]}) {
if(track?.kind==="master"){
if(logical)return ["Choose audio output"];
return [retained?REMAP:
String(playbackDevice||track.output||"Choose audio output")];
}
const labels=["Master",ONLY];
if(logical||authority==="CHANNEL_ID")
for(const target of targets)labels.push(target.label);
if(track?.output&&!labels.includes(track.output))labels.push(track.output);
return labels;
}
function resolvePrimarySelection(value,targets) {
if(value==="Master")return "MAIN";
if(value===ONLY)return "NONE";
return Array.isArray(targets)&&targets.some(x=>x.label===value)?value:null;
}
function readbackBindings({native,channel,channels,targets,inputLabel}) {
const out={};
if(channel?.role==="INPUT"){
const src=channel.source||{};
const left=/^in:([0-9]+)$/.exec(src.portId||"");
const right=/^in:([0-9]+)$/.exec(src.portIdRight||"");
const l=left?Number(left[1]):-1,r=right?Number(right[1]):-1;
const verified=left&&Number.isSafeInteger(l)&&
(src.sourceFormat!=="STEREO"||right&&Number.isSafeInteger(r));
out.input=native?.retained&&src.bindingState==="NEEDS_REMAP"?REMAP:
verified?inputLabel({mode:src.sourceFormat==="STEREO"?"STEREO":"MONO",
left:l,right:r}):"None";
}
if(channel?.role!=="MAIN"){
const dest=Array.isArray(channels)?
channels.find(x=>x.id===channel?.primaryOutId):null;
const target=dest&&targets.find(t=>t.id===dest.id);
out.output=dest?.role==="MAIN"?"Master":
target?.label||ONLY;
}
return out;
}
// Same single bridge-side pending Map: ACK without independent native
// readback must never clear pending or label a physical output LIVE.
function externalPending(pending,epoch,state,row) {
if(!pending)return "NONE";
if(epoch && epoch!==pending.epoch)return "STALE";
if(pending.acked!==true)return "PENDING";
if(((state==="LIVE"||state==="MUTED")&&row&&
row.physicalLeft===pending.left&&row.physicalRight===pending.right)||
(pending.left===-1&&!row))return "CONFIRMED";
return "PENDING";
}
return Object.freeze({outputTargets,inputChoices,externalChoices,
primaryChoices,resolvePrimarySelection,readbackBindings,externalPending});
});
Loading
Loading