diff --git a/scripts/build_approved_native_gui.py b/scripts/build_approved_native_gui.py index dc3178d81..08dc37a85 100644 --- a/scripts/build_approved_native_gui.py +++ b/scripts/build_approved_native_gui.py @@ -23,6 +23,7 @@ NATIVE_ADAPTER = ROOT / "web" / "approved-native-bridge.js" ADAPTER_MARKER = ('\n' '\n' + '\n' '\n' '\n' '\n') @@ -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())] diff --git a/tests/approved_native_cold_start_smoke.py b/tests/approved_native_cold_start_smoke.py index 9d7f05232..0ac252381 100644 --- a/tests/approved_native_cold_start_smoke.py +++ b/tests/approved_native_cold_start_smoke.py @@ -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']}], diff --git a/tests/approved_native_gui_bundle_test.py b/tests/approved_native_gui_bundle_test.py index 51a5f19b8..0f425100e 100644 --- a/tests/approved_native_gui_bundle_test.py +++ b/tests/approved_native_gui_bundle_test.py @@ -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) diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index 5121d64e8..4b4661048 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -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)); @@ -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"),{ @@ -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"), @@ -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();} }; @@ -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);}}; @@ -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"\]/); }); @@ -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]); +}); diff --git a/tests/live_fader_held_drag.test.cjs b/tests/live_fader_held_drag.test.cjs index 0b2db1447..93f5ea605 100644 --- a/tests/live_fader_held_drag.test.cjs +++ b/tests/live_fader_held_drag.test.cjs @@ -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; @@ -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;} }; diff --git a/web/approved-channel-strip-view-model.js b/web/approved-channel-strip-view-model.js new file mode 100644 index 000000000..2e2b90cb6 --- /dev/null +++ b/web/approved-channel-strip-view-model.js @@ -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}); +}); diff --git a/web/approved-device-view-model.js b/web/approved-device-view-model.js index 4f47b66b2..1a1a74be4 100644 --- a/web/approved-device-view-model.js +++ b/web/approved-device-view-model.js @@ -122,8 +122,11 @@ const noInput=type?.separate===true&&draft?.capture===""; const inputValid=noInput||Boolean(type?.inputs?.includes(draft?.capture)); const outputValid=Boolean(outputOptions.includes(draft?.playback)); + const selectedOutputPins=Array.isArray(draft?.outputPins)? + draft.outputPins:Array.isArray(active.enabledOutputs)?active.enabledOutputs:[]; const canApply=Boolean(type && draft?.backend && inputValid&&outputValid&& - (type.separate===true||draft.capture===draft.playback)); + (type.separate===true||draft.capture===draft.playback)&& + (!same||selectedOutputPins.length>=2)); const selectedPins=(key,enabled)=>Array.isArray(draft?.[key])? draft[key]:Array.isArray(enabled)?enabled:[]; return {type,same,backendOptions:types.map(t=>t.name), @@ -169,11 +172,17 @@ if(!view.inputOptions.includes(value))return draft; return {...draft,capture:value, playback:view.type?.separate?draft.playback:value, - inputPins:null,outputPins:null}; + inputPins:null,outputPins:null,rate:0,buffer:0}; } if(field==="playback") { - if(!view.outputOptions.includes(value))return draft; - return {...draft,playback:value,inputPins:null,outputPins:null}; + if(!view.outputOptions.includes(value)|| + (view.type?.separate!==true&&!view.inputOptions.includes(value))) + return draft; + // A JUCE non-separate backend has one duplex endpoint identity. + // Never present an input/output mismatch that native must reject. + return {...draft,playback:value, + capture:view.type?.separate?draft.capture:value, + inputPins:null,outputPins:null,rate:0,buffer:0}; } if(field==="rate"||field==="buffer") { const options=field==="rate"?view.rateOptions:view.bufferOptions; @@ -208,8 +217,8 @@ expectedDeviceGeneration:generation, config:{backend:draft.backend,captureDevice:draft.capture, playbackDevice:draft.playback,sampleRate:rate,bufferSize:buffer, - enabledInputs:same?draft.inputPins:[], - enabledOutputs:same?draft.outputPins:[], + enabledInputs:same?presentation.inputPins:[], + enabledOutputs:same?presentation.outputPins:[], ...(confirmRetainedPinMapping?{confirmRetainedPinMapping:true}:{}), ...(assignMain?{assignSelectedPlaybackPinsToMain:true}:{})}}; const pending={requestId,expected:{backend:draft.backend, diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index d2705cf25..eb871b9d6 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -5,10 +5,12 @@ const backend = window.__JUCE__?.backend; const protocol = window.ArSonApprovedNativeContract; const deviceVM = window.ArSonApprovedDeviceViewModel; + const stripVM = window.ArSonApprovedChannelStripViewModel; // 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 && deviceVM); + const connected = Boolean(backend?.emitEvent && backend?.addEventListener && + protocol && deviceVM && stripVM); // Public browser preview keeps its header; the native JUCE caption replaces it. if (backend?.emitEvent && backend?.addEventListener) document.documentElement?.classList?.add?.("armix-native-desktop"); @@ -412,12 +414,7 @@ queueWireGainFlush();return true; } function nativeOutputTargets(t,channels=activeView()?.graph?.channels||[]){ - const source=nativeIdFor(t),reserved=["Master","SOURCE ONLY (No Main)","MAIN","NONE"]; - return channels.filter(ch=>ch.id!==source&&["INPUT","GROUP","FX_RETURN"].includes(ch.role)) - .map(ch=>{const label=displayNameFor(ch); - return {id:ch.id,label:reserved.includes(label)|| - channels.filter(other=>displayNameFor(other)===label).length>1? - label+" ["+ch.id+"]":label};}); + return stripVM.outputTargets(channels,nativeIdFor(t),displayNameFor); } let pendingNativeGainIntent=false; const intent = (operation,t,payload) => { @@ -523,20 +520,13 @@ t.pan=ch.controls.pan*100; t.mute=ch.controls.mute; t.solo=ch.controls.solo; - // Admitted ChannelId readback already carries actual physical pins. - // Do not retain the public demo's "None" when native PCM is active. - if(ch.role==="INPUT"){ - const src=ch.source||{},l=/^in:(\d+)$/.exec(src.portId||""), - r=/^in:(\d+)$/.exec(src.portIdRight||""); - t.input=native.retained && src.bindingState==="NEEDS_REMAP"? - NEEDS_REMAP:l?inputLabelFor({mode:src.sourceFormat==="STEREO"?"STEREO":"MONO", - left:Number(l[1]),right:r?Number(r[1]):-1}):"None"; - } - const out=accepted.channels.find(dest=>dest.id===ch.primaryOutId); - // Identity-safe labels also handle duplicate names and reserved labels. - const target=out&&nativeOutputTargets(t,accepted.channels).find(x=>x.id===out.id); - if(ch.role!=="MAIN")t.output=out?.role==="MAIN"?"Master": - (target?.label||"SOURCE ONLY (No Main)"); + // Derive SOURCE/PRIMARY OUT labels only from the native installed readback. + const labels=stripVM.readbackBindings({native,channel:ch, + channels:accepted.channels, + targets:nativeOutputTargets(t,accepted.channels), + inputLabel:inputLabelFor}); + if(labels.input!==undefined)t.input=labels.input; + if(labels.output!==undefined)t.output=labels.output; const direct=Array.isArray(native.raw?.externalOutputs)? native.raw.externalOutputs.find(x=>x.channelId===ch.id):null; const pair=direct && hardwareOutputPairs().find(p=> @@ -905,13 +895,9 @@ } select.title=projected.title; const pending=pendingExternal.get(id); - if(pending && next?.device?.epoch && next.device.epoch!==pending.epoch) - pendingExternal.delete(id); // stale device: release only this strip - else if(pending?.acked && - (((state==="LIVE"||state==="MUTED") && - row.physicalLeft===pending.left && - row.physicalRight===pending.right) || - (pending.left===-1 && !row))){ + const result=stripVM.externalPending(pending,next?.device?.epoch,state,row); + if(result==="STALE")pendingExternal.delete(id); + else if(result==="CONFIRMED"){ pendingExternal.delete(id); status(state==="MUTED"?"EXTERNAL OUT patched · hardware output muted": "EXTERNAL OUT verified · "+t.name+" → "+value); @@ -3296,38 +3282,18 @@ orbitTarget:nativeOrbitTarget, orbitAction:nativeOrbitAction, inputChoices(t) { - if(t?.kind!=="audio")return ["None"]; - if(controller?.state()?.current?.retained&&!logicalView)return [t.input||"None"]; - const choices=inputChoicesFor().map(x=>x.label); - // The native BUS lane is selectable only for display: never invent a - // hardware pin or promote the internal BUS to a writable physical IN. - if(t.input===INTERNAL_BUS)choices.push(INTERNAL_BUS); - return choices; + return stripVM.inputChoices(t,inputChoicesFor(), + controller?.state()?.current?.retained,!(!logicalView),INTERNAL_BUS); }, externalChoices(t) { - if(t?.kind==="master")return ["None"]; - const labels=hardwareOutputPairs().map(p=>p.label); - if(t?.externalOutput && !labels.includes(t.externalOutput)) - labels.push(t.externalOutput); - return labels; + return stripVM.externalChoices(t,hardwareOutputPairs()); }, outputChoices(t) { - if(logicalView&&t?.kind==="master")return ["Choose audio output"]; - if(t?.kind==="master") - return [hardware?.retained?NEEDS_REMAP: - String(hardware?.device?.playbackDevice||t.output||"Choose audio output")]; - if(t?.kind!=="master"){ - // M4 accepts MAIN or source-only. Bus routing is via native WIRE, - // never pretend the demo's other destinations have native PCM. - const options=["Master","SOURCE ONLY (No Main)"]; - const graph=controller?.state()?.current?.graph; - if((logicalView||mixerSession()?.authority==="CHANNEL_ID")&& - (logicalView?.graph?.channels||graph?.channels)) - for(const target of nativeOutputTargets(t))options.push(target.label); - if(t.output&&!options.includes(t.output))options.push(t.output); - return options; - } - return [t?.output||"None"]; + return stripVM.primaryChoices({track:t,logical:Boolean(logicalView), + retained:Boolean(hardware?.retained), + playbackDevice:hardware?.device?.playbackDevice, + authority:mixerSession()?.authority, + targets:nativeOutputTargets(t)}); }, consumeField(event) { if (!connected)return false; @@ -3490,11 +3456,8 @@ if(t.kind==="master"){ el.value=t.output;openNativeAudioIO();return true; } - const graph=controller?.state()?.current?.graph; - const destination=nativeOutputTargets(t).find(ch=>ch.label===el.value); - const target=el.value==="Master"?"MAIN": - el.value==="SOURCE ONLY (No Main)"?"NONE": - destination?destination.label:null; + const target=stripVM.resolvePrimarySelection(el.value, + nativeOutputTargets(t)); // No optimistic GUI state. Both this menu and the WIRE jack use // the same ID/epoch-guarded, acknowledged native route transaction. if(el.value!==t.output && !requestPrimaryOut(t,target)){