diff --git a/tests/approved_native_m2_contract.test.cjs b/tests/approved_native_m2_contract.test.cjs index bc019fad3..6bb778791 100644 --- a/tests/approved_native_m2_contract.test.cjs +++ b/tests/approved_native_m2_contract.test.cjs @@ -999,11 +999,15 @@ test("Native FX GUI routes through ChannelId PCM with no operator MONITOR ritual const activeProjection=read("integration/ApprovedNativeV8Projection.h"); assert.match(activeProjection,/insert->setProperty\("catalogId",catalog\)/); assert.match(activeProjection,/ch->setProperty\("fxRackBypassed",rackBypassed\)/); - assert.match(bridge,/controller\.intent\("LOAD_INSERT",nativeId,/); - assert.match(bridge,/if\(accepted\?\.admitted && nativeCh\)/); + assert.match(bridge,/fxRackVM\.nativeInsertPlan\(accepted,/); + assert.match(bridge,/controller\.intent\("LOAD_INSERT",plan\.channelId,plan\.payload\)/); + assert.match(bridge,/accepted\?\.admitted \|\| mixerSession\(\)\?\.authority==="CHANNEL_ID"/); assert.match(lab,/nativeAccepted_\.fxOwners->externalChannel\(\)==target/); assert.match(bridge,/pendingFxInsert=\{authority:"CHANNEL_ID"/); - assert.match(bridge,/inserted\?\.catalogId===p\.id/); + const fxVM=read("web/approved-fx-rack-view-model.js"); + assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(pendingFxInsert,next,confirmed\)/); + assert.match(fxVM,/fx\.catalogId!==pending\.id/); + assert.match(fxVM,/confirmed\.requestId!==pending\.requestId/); assert.match(translate,/if\(op=="LOAD_INSERT"\)/); assert.match(snapshot,/available\.add\(juce::String\("LOAD_INSERT"\)\)/); assert.match(main,/engine_\.installNativeVst3\(/); @@ -2833,7 +2837,8 @@ test("Guitar FX picker binding is real, visible and matches native installed reg assert.ok(bridge.includes("const presentFxCatalog=()=>scope?.setNativeCatalog?.(")); assert.ok(guiBuilder.includes("setNativeCatalog(rows)")); assert.ok(guiBuilder.includes("renderPluginCatalog();renderFastPicker();")); - assert.ok(bridge.includes('controller.intent("LOAD_INSERT",nativeId,')); + assert.ok(bridge.includes('fxRackVM.nativeInsertPlan(accepted,')); + assert.ok(bridge.includes('controller.intent("LOAD_INSERT",plan.channelId,plan.payload)')); assert.ok(bridge.includes('pendingFxInsert={authority:"CHANNEL_ID"')); }); @@ -3488,3 +3493,137 @@ test("MV-7 bridge delegates WIRE decisions, preserves only one native controller assert.doesNotMatch(read("web/approved-wire-view-model.js"), /backend\.emitEvent|window\.setTimeout|document\.querySelector/); }); + +test("MV-8 FX native insert preflight keeps exact ChannelId, slot and installed roster",()=>{ + const id="9007199254740993",id2="9007199254740995"; + const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{ + revision:"55",capabilities:{supportedOps:["LOAD_INSERT","MOVE_INSERT","REMOVE_INSERT"]}, + channels:[{id,role:"INPUT",inserts:[{id:"fx-1",catalogId:"eq"}]}, + {id:id2,role:"GROUP",inserts:[]}]}}; + const before=JSON.stringify(snapshot); + const ask={channelId:id,slot:1,catalogId:"vendor.vst3"}; + assert.deepEqual(fxRackVM.nativeInsertPlan(snapshot,ask),{ + kind:"READY",channelId:id,payload:{catalogId:"vendor.vst3",slot:1}}); + const unavailable=(snap=snapshot,params=ask)=> + assert.equal(fxRackVM.nativeInsertPlan(snap,params).kind,"UNAVAILABLE"); + unavailable(snapshot,{...ask,pending:true}); + unavailable(snapshot,{...ask,slot:0});unavailable(snapshot,{...ask,slot:2}); + unavailable(snapshot,{...ask,slot:8});unavailable(snapshot,{...ask,slot:1.5}); + unavailable(snapshot,{...ask,channelId:Number(id)}); + unavailable(snapshot,{...ask,channelId:"18446744073709551616"}); + unavailable(snapshot,{...ask,catalogId:""}); + unavailable({...snapshot,admitted:false});unavailable({...snapshot,retained:true}); + unavailable({...snapshot,graph:{...snapshot.graph,capabilities:{supportedOps:[]}}}); + unavailable({...snapshot,graph:{...snapshot.graph,channels:[ + snapshot.graph.channels[0],{...snapshot.graph.channels[0]}]}}); + unavailable({...snapshot,graph:{...snapshot.graph,channels:[ + snapshot.graph.channels[0], + {id:id2,role:"GROUP",inserts:[{id:"fx-1",catalogId:"eq"}]}]}}); + assert.equal(JSON.stringify(snapshot),before); +}); +test("MV-8 FX move/remove preflight preserves exact instance and destination",()=>{ + const a="9007199254740993",b="9007199254740995"; + const base={admitted:true,retained:false,graph:{capabilities:{ + supportedOps:["MOVE_INSERT","REMOVE_INSERT"]}, + channels:[{id:a,role:"INPUT",inserts:[{id:"lease-a"},{id:"lease-b"}]}, + {id:b,role:"GROUP",inserts:[]}]}}; + const request={channelId:a,slot:0,instanceId:"lease-a", + move:true,destinationId:b,position:0}; + assert.deepEqual(fxRackVM.nativeEditPlan(base,request),{ + kind:"READY",operation:"MOVE_INSERT",channelId:a, + payload:{slot:0,instanceId:"lease-a",toChannelId:b,toSlot:0}}); + assert.deepEqual(fxRackVM.nativeEditPlan(base,{channelId:a,slot:1, + instanceId:"lease-b"}),{kind:"READY",operation:"REMOVE_INSERT", + channelId:a,payload:{slot:1,instanceId:"lease-b"}}); + assert.equal(fxRackVM.nativeEditPlan(base,{...request,destinationId:a, + position:0}).kind,"NO_CHANGE"); + const bad=(s=base,args=request)=>assert.equal( + fxRackVM.nativeEditPlan(s,args).kind,"UNAVAILABLE"); + bad(base,{...request,slot:1}); + bad(base,{...request,instanceId:"vendor.vst3"}); + bad(base,{...request,destinationId:"0"}); + bad(base,{...request,destinationId:null}); // lost mapping never deletes FX + bad(base,{...request,destinationId:Number(b)}); + bad(base,{...request,move:false}); // stray target cannot become REMOVE + bad(base,{...request,move:"yes"}); + bad(base,{...request,position:1}); + bad(base,{...request,position:-1}); + bad({...base,retained:true}); + bad({...base,graph:{...base.graph,channels:[ + base.graph.channels[0],{...base.graph.channels[1], + inserts:[{id:"lease-a"}]}]}}); + bad({...base,graph:{...base.graph,capabilities:{supportedOps:[]}}}); +}); +test("MV-8 FX inserted editor requires correlated controller proof and unique lease",()=>{ + const ch="9007199254740993",cat="vendor.vst3"; + const pending={authority:"CHANNEL_ID",requestId:"r-7",channelId:ch, + id:cat,slot:0,epoch:"73"}; + const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{ + channels:[{id:ch,role:"INPUT",inserts:[ + {id:"live-instance-a",catalogId:cat,name:"Vendor VST3"}]}]}}; + const ack={requestId:"r-7",operation:"LOAD_INSERT",targetChannelId:ch, + payload:{catalogId:cat,slot:0}}; + assert.deepEqual(fxRackVM.nativeInsertSettlement(pending,snapshot,ack),{ + kind:"CONFIRMED",channelId:ch,slot:0,catalogId:cat, + instanceId:"live-instance-a",name:"Vendor VST3"}); + assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot,null).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot, + {...ack,requestId:"r-8"}).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot, + {...ack,targetChannelId:"71"}).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending,snapshot, + {...ack,payload:{catalogId:"different",slot:0}}).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending, + {...snapshot,device:{epoch:"74"}},ack).kind,"STALE"); + assert.equal(fxRackVM.nativeInsertSettlement(pending, + {...snapshot,admitted:false},ack).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending, + {...snapshot,graph:{channels:[...snapshot.graph.channels, + {id:"91",role:"GROUP",inserts:[ + {id:"live-instance-a",catalogId:cat}]}]}},ack).kind,"WAIT"); + assert.equal(fxRackVM.nativeInsertSettlement(pending, + {...snapshot,graph:{channels:[{id:ch,role:"INPUT",inserts:[ + {id:"live-instance-b",catalogId:"different"}]}]}},ack).kind,"WAIT"); + assert.deepEqual(fxRackVM.nativeInsertSettlement(null,snapshot,ack),{kind:"NONE"}); +}); +test("MV-8 FX native bypass plan and ACK are independent of global and insert states",()=>{ + const channelId="9007199254740993"; + const snapshot={admitted:true,retained:false,device:{epoch:"73"},graph:{ + revision:"22",channels:[{id:channelId,role:"INPUT",fxRackBypassed:false, + inserts:[{id:"lease-1",bypassed:true},{id:"lease-2",bypassed:false}]}]}}; + const rack=fxRackVM.nativePowerPlan(snapshot,{channelId,action:"fxOn"}); + assert.equal(rack.kind,"READY"); + assert.equal(rack.pending.bypassed,true); + assert.equal(rack.action,"routingNativeFxRackBypass"); + assert.equal(rack.payload.revision,"22"); + const slot=fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:0}); + assert.equal(slot.kind,"READY"); + assert.equal(slot.pending.insertId,"lease-1"); + assert.equal(slot.pending.bypassed,false); + assert.equal(slot.payload.value,false); + assert.equal(fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:2}).kind,"UNAVAILABLE"); + assert.equal(fxRackVM.nativePowerPlan(snapshot,{channelId,action:"slotPower",slot:0, + pending:true}).kind,"UNAVAILABLE"); + const p={...slot.pending,requestId:"fx-17"}; + assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"other",ok:true}),"IGNORE"); + assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:true, + channelId,bypassed:false,insertId:"lease-1"}),"ACKED"); + assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:true, + channelId,bypassed:false,insertId:"replaced"}),"REJECTED"); + assert.equal(fxRackVM.nativePowerAckResult(p,{requestId:"fx-17",ok:false, + channelId,bypassed:false}),"REJECTED"); + assert.equal(fxRackVM.nativePowerAckResult(null,{}),"IGNORE"); +}); +test("MV-8 FX bridge delegates preflight and settlement to existing pure FX VM",()=>{ + const bridge=read("web/approved-native-bridge.js"); + assert.match(bridge,/fxRackVM\.nativeInsertPlan\(/); + assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(/); + assert.match(bridge,/fxRackVM\.nativeEditPlan\(/); + assert.match(bridge,/move:!!target/); + assert.match(bridge,/fxRackVM\.nativePowerPlan\(/); + assert.match(bridge,/fxRackVM\.nativePowerAckResult\(/); + assert.match(bridge,/controller\.intent\(plan\.channelId,|controller\.intent\("LOAD_INSERT",plan\.channelId/); + assert.match(bridge,/controller\.intent\(decision\.operation,decision\.channelId/); + assert.doesNotMatch(read("web/approved-fx-rack-view-model.js"), + /backend\.emitEvent|document\.querySelector|setTimeout\(/); +}); diff --git a/tests/rc_operator_workflow_contract.test.mjs b/tests/rc_operator_workflow_contract.test.mjs index 5230ed66f..d1ebed48f 100644 --- a/tests/rc_operator_workflow_contract.test.mjs +++ b/tests/rc_operator_workflow_contract.test.mjs @@ -55,8 +55,15 @@ test('FX picker closes and opens an actual editor only after accepted native or assert.match(bridge,/effect\.id!==instanceId\|\|effect\.catalogId!==catalogId/); assert.match(bridge,/justInsertedLogicalFx/); assert.match(bridge,/scope\?\.closeNativePicker\?\.\(\);\s*openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.catalogId,inserted\.id\)/); - assert.match(bridge,/openVerifiedInsertedFx\(p\.channelId,p\.slot,p\.id,inserted\.id\)/); - assert.match(bridge,/confirmed\.requestId===pendingFxInsert\.requestId/); + // Native editor requires verified accepted lease, not catalog key or ACK. + const fxVM=read('web/approved-fx-rack-view-model.js'); + assert.match(bridge,/fxRackVM\.nativeInsertSettlement\(pendingFxInsert,next,confirmed\)/); + assert.match(bridge,/if\(fxInsert\.kind==="CONFIRMED"\)/); + assert.match(bridge,/openVerifiedInsertedFx\(fxInsert\.channelId,fxInsert\.slot,/); + assert.match(bridge,/fxInsert\.catalogId,fxInsert\.instanceId\)/); + assert.match(fxVM,/confirmed\.requestId!==pending\.requestId/); + assert.match(fxVM,/fx\.catalogId!==pending\.id/); + assert.match(bridge,/pendingFxInsert=null;\s*scope\?\.closeNativePicker\?\.\(\)/); assert.match(bridge,/ack\.channel===p\.channel && ack\.slot===p\.slot/); assert.match(bridge,/paintM4FxInstances\(state\);\s*scope\?\.closeNativePicker\?\.\(\);\s*openRoutedFxEditor\(p\.channel,p\.slot,actual\.instanceId,epoch,revision\)/); assert.match(bridge,/consumeAction\?\.\(track,"openPlugin"/); diff --git a/web/approved-fx-rack-view-model.js b/web/approved-fx-rack-view-model.js index d03b19e99..b67e56c6e 100644 --- a/web/approved-fx-rack-view-model.js +++ b/web/approved-fx-rack-view-model.js @@ -109,6 +109,125 @@ session.channels?.[pending.channel]?.fxRackBypassed===pending.bypassed? "CONFIRMED":"WAIT"; } + + // MV-8: do not invent JS-owned FX identities or interpret a catalog key + // as an instance lease. These plans may only target admitted native PCM. + const VALID_ROLES=new Set(["INPUT","GROUP","FX_RETURN","MAIN"]); + function channelId(value) { + if(typeof value!=="string"||!/^[1-9][0-9]*$/.test(value))return false; + try{return BigInt(value)<=18446744073709551615n;}catch{return false;} + } + function rosterUnique(graph) { + if(!Array.isArray(graph?.channels))return false; + const seen=new Set(); + for(const ch of graph.channels) { + if(!Array.isArray(ch?.inserts))return false; + for(const fx of ch.inserts) { + if(typeof fx?.id!=="string"||!fx.id||seen.has(fx.id))return false; + seen.add(fx.id); + } + } + return true; + } + function nativeInsertPlan(snapshot,{channelId:id,slot,catalogId,pending=false}={}) { + const graph=snapshot?.graph; + if(pending||snapshot?.admitted!==true||snapshot?.retained===true|| + !channelId(id)||typeof catalogId!=="string"||!catalogId|| + !Number.isInteger(slot)||slot<0||slot>=8|| + !graph?.capabilities?.supportedOps?.includes("LOAD_INSERT")|| + !rosterUnique(graph))return {kind:"UNAVAILABLE"}; + const matches=graph.channels.filter(ch=>ch.id===id); + if(matches.length!==1||!VALID_ROLES.has(matches[0].role)|| + matches[0].inserts.length!==slot)return {kind:"UNAVAILABLE"}; + return {kind:"READY",channelId:id,payload:{catalogId,slot}}; + } + function nativeEditPlan(snapshot,{channelId:id,slot,instanceId, + move=false,destinationId=null,position=null}={}) { + const graph=snapshot?.graph; + // A MOVE with a lost destination must NEVER become a REMOVE. + if(typeof move!=="boolean"|| + (!move&&(destinationId!==null||position!==null))) + return {kind:"UNAVAILABLE"}; + const operation=move?"MOVE_INSERT":"REMOVE_INSERT"; + if(snapshot?.admitted!==true||snapshot?.retained===true|| + !channelId(id)||!Number.isInteger(slot)||slot<0||slot>=8|| + typeof instanceId!=="string"||!instanceId|| + !graph?.capabilities?.supportedOps?.includes(operation)|| + !rosterUnique(graph))return {kind:"UNAVAILABLE"}; + const sources=graph.channels.filter(ch=>ch.id===id); + if(sources.length!==1||!VALID_ROLES.has(sources[0].role)|| + sources[0].inserts[slot]?.id!==instanceId) + return {kind:"UNAVAILABLE"}; + const payload={slot,instanceId}; + if(move){ + if(!channelId(destinationId)||!Number.isInteger(position))return {kind:"UNAVAILABLE"}; + const targets=graph.channels.filter(ch=>ch.id===destinationId); + if(targets.length!==1||!VALID_ROLES.has(targets[0].role)) + return {kind:"UNAVAILABLE"}; + const same=destinationId===id,max=targets[0].inserts.length-(same?1:0); + if(position<0||position>max||(!same&&max>=8)) + return {kind:"UNAVAILABLE"}; + if(same&&slot===position)return {kind:"NO_CHANGE"}; + payload.toChannelId=destinationId; + payload.toSlot=position; + } + return {kind:"READY",operation,channelId:id,payload}; + } + // createController is the ONLY source of matched ACK + independent + // readback. We additionally check exact editor lease before navigation. + function nativeInsertSettlement(pending,snapshot,confirmed){ + if(!pending||pending.authority!=="CHANNEL_ID")return {kind:"NONE"}; + if(snapshot?.device?.epoch!==pending.epoch)return {kind:"STALE"}; + if(!confirmed||confirmed.operation!=="LOAD_INSERT"|| + confirmed.requestId!==pending.requestId)return {kind:"WAIT"}; + if(snapshot?.admitted!==true||snapshot.retained===true|| + confirmed.targetChannelId!==pending.channelId|| + confirmed.payload?.catalogId!==pending.id|| + confirmed.payload?.slot!==pending.slot|| + !channelId(pending.channelId)||!rosterUnique(snapshot.graph)) + return {kind:"WAIT"}; + const ch=snapshot.graph.channels.filter(c=>c.id===pending.channelId); + const fx=ch.length===1?ch[0].inserts[pending.slot]:null; + if(!fx||fx.catalogId!==pending.id|| + typeof fx.id!=="string"||!fx.id)return {kind:"WAIT"}; + return {kind:"CONFIRMED",channelId:pending.channelId, + slot:pending.slot,catalogId:fx.catalogId,instanceId:fx.id,name:fx.name}; + } + function nativePowerPlan(snapshot,{channelId:id,action,slot,pending=false}={}){ + const graph=snapshot?.graph; + if(pending||snapshot?.admitted!==true||snapshot?.retained===true|| + !channelId(id)||!Array.isArray(graph?.channels)||!rosterUnique(graph)) + return {kind:"UNAVAILABLE"}; + const matches=graph.channels.filter(ch=>ch.id===id); + if(matches.length!==1)return {kind:"UNAVAILABLE"}; + const ch=matches[0],rack=action==="fxOn"; + if(!rack&&action!=="slotPower")return {kind:"UNAVAILABLE"}; + const insert=rack?null:ch.inserts?.[slot]; + if(rack?typeof ch.fxRackBypassed!=="boolean": + !Number.isInteger(slot)||slot<0||slot>=8|| + typeof insert?.id!=="string"||!insert.id|| + typeof insert.bypassed!=="boolean")return {kind:"UNAVAILABLE"}; + const bypassed=rack?!ch.fxRackBypassed:!insert.bypassed; + return {kind:"READY",action:rack?"routingNativeFxRackBypass": + "routingNativeFxInsertBypass", + pending:{channelId:id,kind:rack?"rack":"insert", + insertId:insert?.id,bypassed,epoch:snapshot.device?.epoch,acked:false}, + payload:{channelId:id,deviceEpoch:snapshot.device?.epoch, + revision:graph.revision,value:bypassed, + ...(rack?{}:{slot,insertId:insert.id})}}; + } + function nativePowerAckResult(pending,ack){ + if(!pending||!ack||ack.requestId!==pending.requestId)return "IGNORE"; + if(ack.ok!==true||ack.channelId!==pending.channelId|| + ack.bypassed!==pending.bypassed|| + (ack.insertId!==undefined&& + pending.kind==="insert"&&ack.insertId!==pending.insertId)) + return "REJECTED"; + return "ACKED"; + } + return Object.freeze({powerReadback,mountedRackMatches, - m4Presentation,nativePowerSettlement,m4RackSettlement}); + m4Presentation,nativePowerSettlement,m4RackSettlement, + nativeInsertPlan,nativeEditPlan,nativeInsertSettlement, + nativePowerPlan,nativePowerAckResult}); }); diff --git a/web/approved-native-bridge.js b/web/approved-native-bridge.js index 87d874dd9..d5d4c15f1 100644 --- a/web/approved-native-bridge.js +++ b/web/approved-native-bridge.js @@ -1322,18 +1322,21 @@ } function editNativeFx(t,slot,target,position,token){ const current=controller?.state()?.current,id=nativeIdFor(t); - const actual=current?.graph?.channels.find(c=>c.id===id)?.inserts?.[slot]; - const to=target?nativeIdFor(target):null,operation=target?"MOVE_INSERT":"REMOVE_INSERT"; - if(!current?.admitted||!actual||actual.id!==token||!current.graph.capabilities.supportedOps.includes(operation)){ - status("FX edit unavailable · refresh accepted native instance");return false; - } - if(target&&to===id&&slot===position)return false; - const payload={slot,instanceId:token}; - if(target){payload.toChannelId=to;payload.toSlot=position;} - const result=controller.intent(operation,id,payload); + const decision=fxRackVM.nativeEditPlan(current,{ + channelId:id,slot,instanceId:token,move:!!target, + destinationId:target?nativeIdFor(target):null, + position:target?position:null}); + if(decision.kind!=="READY"){ + if(decision.kind!=="NO_CHANGE") + status("FX edit unavailable · refresh accepted native instance"); + return false; + } + const result=controller.intent(decision.operation,decision.channelId, + decision.payload); if(!result.ok){status("FX edit rejected · "+result.error);return false;} window.setTimeout(()=>controller?.expire(result.requestId),8000); - status(target?"Moving native FX · awaiting accepted readback":"Removing native FX · awaiting accepted readback"); + status(target?"Moving native FX · awaiting accepted readback": + "Removing native FX · awaiting accepted readback"); return true; } function requestNativeFxPower(t,slot,bypass){ @@ -1438,26 +1441,16 @@ } window.__ARMIX_NATIVE_GLOBAL_FX__={toggle:toggleGlobalFx}; function requestAdmittedFxPower(t,action,button){ - const session=mixerSession(),current=controller?.state()?.current; - const channelId=nativeIdFor(t); - const ch=current?.graph?.channels?.find(x=>x.id===channelId); - if(session?.authority!=="CHANNEL_ID"||!current?.admitted|| - !channelId||!ch||pendingNativeFxPower)return false; - const rack=action==="fxOn",slot=Number(button?.dataset?.slot); - const insert=!rack&&Number.isInteger(slot)&&slot>=0&&slot<8? - ch.inserts?.[slot]:null; - if((rack&&typeof ch.fxRackBypassed!=="boolean")|| - (!rack&&(!insert||typeof insert.id!=="string"|| - !insert.id||typeof insert.bypassed!=="boolean")))return false; - const bypassed=rack?!ch.fxRackBypassed:!insert.bypassed; + if(mixerSession()?.authority!=="CHANNEL_ID")return false; + const current=controller?.state()?.current; + const plan=fxRackVM.nativePowerPlan(current,{ + channelId:nativeIdFor(t),action, + slot:action==="fxOn"?null:Number(button?.dataset?.slot), + pending:!!pendingNativeFxPower}); + if(plan.kind!=="READY")return false; const requestId="native-rack-"+(++nativeFxPowerSerial); - pendingNativeFxPower={requestId,channelId,kind:rack?"rack":"insert", - insertId:insert?.id,bypassed,epoch:current.device.epoch,acked:false}; - backend.emitEvent("arMixAction",{action:rack? - "routingNativeFxRackBypass":"routingNativeFxInsertBypass", - requestId,channelId,deviceEpoch:current.device.epoch, - revision:current.graph.revision,value:bypassed, - ...(rack?{}:{slot,insertId:insert.id})}); + pendingNativeFxPower={requestId,...plan.pending}; + backend.emitEvent("arMixAction",{action:plan.action,requestId,...plan.payload}); window.setTimeout(()=>{ if(pendingNativeFxPower?.requestId!==requestId)return; pendingNativeFxPower=null; @@ -2856,21 +2849,14 @@ if(confirmed?.operation==="APPLY_WIRE_TRANSACTION") playAcceptedWireImpact(confirmed.payload.changes); finishNativeTrack(next);finishNativeTrackDelete(next); - if(pendingFxInsert?.authority==="CHANNEL_ID" && - confirmed?.operation==="LOAD_INSERT" && - confirmed.requestId===pendingFxInsert.requestId){ - const p=pendingFxInsert; - const inserted=next.graph.channels.find(ch=>ch.id===p.channelId) - ?.inserts?.[p.slot]; - // The selected catalog key is NOT the live VST3 instance token. - // Match catalog against catalog, while requiring a real processor ID. - if(inserted?.catalogId===p.id && - typeof inserted.id==="string" && inserted.id.length>0){ - pendingFxInsert=null; - scope?.closeNativePicker?.(); - openVerifiedInsertedFx(p.channelId,p.slot,p.id,inserted.id); - status("VST3 loaded · "+inserted.name+" · native PCM readback verified"); - } + const fxInsert=fxRackVM.nativeInsertSettlement(pendingFxInsert,next,confirmed); + if(fxInsert.kind==="STALE")pendingFxInsert=null; + if(fxInsert.kind==="CONFIRMED"){ + pendingFxInsert=null; + scope?.closeNativePicker?.(); + openVerifiedInsertedFx(fxInsert.channelId,fxInsert.slot, + fxInsert.catalogId,fxInsert.instanceId); + status("VST3 loaded · "+fxInsert.name+" · native PCM readback verified"); } const fxSettlement=fxRackVM.nativePowerSettlement(pendingNativeFxPower,next); if(fxSettlement==="CONFIRMED"||fxSettlement==="STALE") @@ -3038,13 +3024,12 @@ controller?.subscribe(); // ACK alone never establishes physical bypass. }); backend.addEventListener("arMixNativeFxPowerAck",ack=>{ - const p=pendingNativeFxPower; - if(!p||ack?.requestId!==p.requestId)return; - if(ack?.ok!==true || ack?.channelId!==p.channelId || - ack?.bypassed!==p.bypassed){ + const verdict=fxRackVM.nativePowerAckResult(pendingNativeFxPower,ack); + if(verdict==="IGNORE")return; + if(verdict==="REJECTED"){ pendingNativeFxPower=null; status("NATIVE FX rejected · "+(ack?.error||"stale epoch or insert")); - }else p.acked=true; + }else pendingNativeFxPower.acked=true; controller.subscribe(); // ACK is not independently observed PCM state }); backend.addEventListener("arMixRoutingFxRackAck",ack=>{ @@ -3818,20 +3803,18 @@ const channel=m4Index(track),slot=Number(target?.slot); const accepted=controller?.state().current; const nativeId=nativeIdFor(track); - const nativeCh=accepted?.graph?.channels?.find(ch=>ch.id===nativeId); - if(accepted?.admitted && nativeCh) { - if(!plugin || !["INPUT","GROUP","FX_RETURN","MAIN"].includes(nativeCh.role) || - !accepted.graph.capabilities.supportedOps.includes("LOAD_INSERT") || - !Number.isInteger(slot)||slot<0||slot>=8 || - !Array.isArray(nativeCh.inserts)||nativeCh.inserts.length!==slot){ + if(accepted?.admitted || mixerSession()?.authority==="CHANNEL_ID") { + const plan=fxRackVM.nativeInsertPlan(accepted,{ + channelId:nativeId,slot,catalogId:plugin?.id, + pending:!!pendingFxInsert}); + if(plan.kind!=="READY"){ status("VST3 unavailable · select an empty native ChannelId FX slot"); return true; } - const request=controller.intent("LOAD_INSERT",nativeId, - {catalogId:id,slot}); + const request=controller.intent("LOAD_INSERT",plan.channelId,plan.payload); if(!request.ok){status("VST3 rejected · "+request.error);return true;} pendingFxInsert={authority:"CHANNEL_ID",requestId:request.requestId, - id,channelId:nativeId,slot}; + id,channelId:plan.channelId,slot,epoch:accepted.device.epoch}; status(track.name+" · preparing VST3 without stopping MAIN"); window.setTimeout(()=>{ if(pendingFxInsert?.requestId!==request.requestId)return;