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
48 changes: 48 additions & 0 deletions tests/approved_native_m2_contract.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2907,3 +2907,51 @@ test("MV-2 merged #767 retains one selector; #768 unique duplex/one-pin guards a
{inventory,draft:reset,requestId:"gui1-fallback"});
assert.deepEqual(recovered.request.config.enabledOutputs,[0,1]);
});

test("GUI-2 native FX catalog projection keeps exact M4 processor identity",()=>{
const rows=Array(8).fill(null);
rows[1]={instanceId:"18446744073709551615",catalogId:"eq.a",bypassed:true};
rows[3]={instanceId:"9007199254740993",catalogId:"unknown",bypassed:false};
const before=JSON.stringify(rows);
const result=fxRackVM.m4Presentation(rows,new Map([["eq.a",{name:"EQ One"}]]),true);
assert.equal(result.fxOn,false);assert.equal(result.slots.length,8);
assert.deepEqual(result.slots[1].instance,{id:"18446744073709551615",name:"EQ One"});
assert.deepEqual(result.slots[3].instance,{id:"9007199254740993",name:"VST3 Loaded"});
assert.equal(result.slots[0].instance,null);
assert.equal(fxRackVM.m4Presentation(rows,new Map(),null).fxOn,null);
assert.equal(JSON.stringify(rows),before,"M4 metadata never edits native FX");
const forged=rows.slice();forged[1]={catalogId:"eq.a",bypassed:false};
assert.equal(fxRackVM.m4Presentation(forged,new Map(),false),null);
});
test("GUI-2 native FX pending settlement requires ACK, exact lease and epoch",()=>{
const epoch="18446744073709551612";
const ch={id:"9007199254740993",fxRackBypassed:false,
inserts:[{id:"18446744073709551615",bypassed:true}]};
const next={device:{epoch},graph:{channels:[ch]}};
const p={requestId:"fx42",channelId:ch.id,kind:"insert",
insertId:"18446744073709551615",bypassed:true,epoch,acked:false};
assert.equal(fxRackVM.nativePowerSettlement(p,next),"WAIT");
assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true},next),"CONFIRMED");
assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true},
{...next,device:{epoch:"18446744073709551613"}}),"STALE");
assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true},
{...next,graph:{channels:[{...ch,inserts:[{id:"new",bypassed:true}]}]}}),"WAIT");
assert.equal(fxRackVM.nativePowerSettlement({...p,acked:true,kind:"rack",bypassed:false},next),"CONFIRMED");
assert.equal(fxRackVM.nativePowerSettlement(null,next),"NONE");
});
test("GUI-2 M4 rack pending selector rejects revisions and unaccepted authority",()=>{
const s={authority:"M4",deviceEpoch:"17",routeRevision:"8",
channels:[{fxRackBypassed:true}]};
const p={channel:0,epoch:"17",revision:"8",bypassed:true,acked:false};
assert.equal(fxRackVM.m4RackSettlement(p,s),"WAIT");
assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},s),"CONFIRMED");
assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},{...s,routeRevision:"9"}),"STALE");
assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},{...s,authority:"CHANNEL_ID"}),"STALE");
assert.equal(fxRackVM.m4RackSettlement({...p,acked:true},
{...s,channels:[{fxRackBypassed:false}]}),"WAIT");
const source=read("web/approved-native-bridge.js");
assert.ok(source.includes("fxRackVM.m4Presentation("));
assert.ok(source.includes("fxRackVM.nativePowerSettlement("));
assert.ok(source.includes("fxRackVM.m4RackSettlement("));
assert.doesNotMatch(source,/const actual=p\.kind==="rack"\?/);
});
48 changes: 47 additions & 1 deletion web/approved-fx-rack-view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,51 @@
});
}

return Object.freeze({powerReadback,mountedRackMatches});

// M4 inventory and catalog names are UI metadata, never an installed
// ChannelId processor graph or permission to resurrect a retired instance.
function m4Presentation(instances,catalog,acceptedRack) {
if(!Array.isArray(instances))return null;
const slots=[];
for(let index=0;index<8;index++){
const live=instances[index];
if(live!=null &&
(typeof live.instanceId!=="string"||!live.instanceId||
typeof live.catalogId!=="string"||!live.catalogId||
typeof live.bypassed!=="boolean"))return null;
const name=live?(catalog?.get?.(live.catalogId)?.name||"VST3 Loaded"):"None";
slots.push({index,name,bypassed:live?.bypassed===true,
instance:live?{id:live.instanceId,name}:null});
}
return {fxOn:typeof acceptedRack==="boolean"?!acceptedRack:null,slots};
}
// ACK alone is not installed PCM proof. Correlate channel, insert lease,
// physical device epoch and subsequent accepted readback.
function nativePowerSettlement(pending,snapshot) {
if(!pending)return "NONE";
if(pending.epoch!==undefined &&
snapshot?.device?.epoch!==pending.epoch)return "STALE";
if(pending.acked!==true)return "WAIT";
const channels=snapshot?.graph?.channels;
if(!Array.isArray(channels))return "WAIT";
const channel=channels.find(ch=>ch.id===pending.channelId);
if(!channel)return "WAIT";
const value=pending.kind==="rack"?channel.fxRackBypassed:
pending.kind==="insert"?
channel.inserts?.find(i=>i.id===pending.insertId)?.bypassed:
undefined;
return typeof value==="boolean"&&value===pending.bypassed?
"CONFIRMED":"WAIT";
}
function m4RackSettlement(pending,session) {
if(!pending)return "NONE";
if(session?.authority!=="M4"||
session.deviceEpoch!==pending.epoch||
session.routeRevision!==pending.revision)return "STALE";
return pending.acked===true&&
session.channels?.[pending.channel]?.fxRackBypassed===pending.bypassed?
"CONFIRMED":"WAIT";
}
return Object.freeze({powerReadback,mountedRackMatches,
m4Presentation,nativePowerSettlement,m4RackSettlement});
});
46 changes: 19 additions & 27 deletions web/approved-native-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1385,12 +1385,9 @@
function reconcileM4RackReadback(next){
const session=next?.raw?.mixerSession;
for(const [lane,p] of pendingM4RackPowers){
if(session?.authority!=="M4"||
session.deviceEpoch!==p.epoch||session.routeRevision!==p.revision){
pendingM4RackPowers.delete(lane);continue;
}
const actual=session.channels?.[lane]?.fxRackBypassed;
if(p.acked && actual===p.bypassed)pendingM4RackPowers.delete(lane);
const decision=fxRackVM.m4RackSettlement(p,session);
if(decision==="STALE"||decision==="CONFIRMED")
pendingM4RackPowers.delete(lane);
}
}
// Global A/B is a SINGLE native atomic override. Individual racks and
Expand Down Expand Up @@ -1459,7 +1456,7 @@
const bypassed=rack?!ch.fxRackBypassed:!insert.bypassed;
const requestId="native-rack-"+(++nativeFxPowerSerial);
pendingNativeFxPower={requestId,channelId,kind:rack?"rack":"insert",
insertId:insert?.id,bypassed,acked:false};
insertId:insert?.id,bypassed,epoch:current.device.epoch,acked:false};
backend.emitEvent("arMixAction",{action:rack?
"routingNativeFxRackBypass":"routingNativeFxInsertBypass",
requestId,channelId,deviceEpoch:current.device.epoch,
Expand Down Expand Up @@ -1605,23 +1602,22 @@
if(!Array.isArray(m?.fxInstances)||!scope?.tracks)return;
for(let lane=0;lane<10;lane++){
const t=scope.tracks.find(x=>x.id===m4TrackIds[lane]);
const rows=m.fxInstances[lane];
if(!t||!Array.isArray(rows))continue;
let change=false;
const acceptedRack=mixerSession()?.authority==="M4"?
mixerSession()?.channels?.[lane]?.fxRackBypassed:undefined;
if(typeof acceptedRack==="boolean" && t.fxOn===acceptedRack){
t.fxOn=!acceptedRack;change=true;
const projection=fxRackVM.m4Presentation(m.fxInstances[lane],
nativeCatalog,acceptedRack);
if(!t||!projection)continue;
let change=false;
if(projection.fxOn!==null&&t.fxOn!==projection.fxOn){
t.fxOn=projection.fxOn;change=true;
}
for(let slot=0;slot<8;slot++){
const live=rows[slot],entry=nativeCatalog.get(live?.catalogId);
const name=live?(entry?.name||"VST3 Loaded"):"None";
if(t.fx[slot]!==name || t.slotBypass[slot]!==Boolean(live?.bypassed) ||
(t.fxInsertIds?.[slot]?.id||null)!==(live?.instanceId||null)){
t.fx[slot]=name;
t.slotBypass[slot]=Boolean(live?.bypassed);
for(const slot of projection.slots){
const index=slot.index;
if(t.fx[index]!==slot.name||t.slotBypass[index]!==slot.bypassed||
(t.fxInsertIds?.[index]?.id||null)!==(slot.instance?.id||null)){
t.fx[index]=slot.name;t.slotBypass[index]=slot.bypassed;
if(!Array.isArray(t.fxInsertIds))t.fxInsertIds=Array(8).fill(null);
t.fxInsertIds[slot]=live?{id:live.instanceId,name}:null;
t.fxInsertIds[index]=slot.instance;
change=true;
}
}
Expand Down Expand Up @@ -2883,13 +2879,9 @@
status("VST3 loaded · "+inserted.name+" · native PCM readback verified");
}
}
if(pendingNativeFxPower?.acked){
const p=pendingNativeFxPower;
const ch=next.graph.channels.find(x=>x.id===p.channelId);
const actual=p.kind==="rack"?ch?.fxRackBypassed:
ch?.inserts?.find(x=>x.id===p.insertId)?.bypassed;
if(actual===p.bypassed)pendingNativeFxPower=null;
}
const fxSettlement=fxRackVM.nativePowerSettlement(pendingNativeFxPower,next);
if(fxSettlement==="CONFIRMED"||fxSettlement==="STALE")
pendingNativeFxPower=null;
if(startupWire)window.queueMicrotask(flushStartupWire);
status("Mixer settings updated");
}
Expand Down
Loading