diff --git a/site/preview-v2/assets/mixer-native-sonku.js b/site/preview-v2/assets/mixer-native-sonku.js index eda50abbc..e6e57fd7c 100644 --- a/site/preview-v2/assets/mixer-native-sonku.js +++ b/site/preview-v2/assets/mixer-native-sonku.js @@ -32,22 +32,18 @@ const native=()=>typeof backend()?.emitEvent==="function"; const snapshot=()=>window.__ARMIX_NATIVE_M2__?.fxEditorState?.()|| window.__ARMIX_NATIVE_M2__?.state?.()?.current; const angle=(v)=>((v%360)+360)%360; -// Listener faces the BOTTOM of this top-down stage. -// Acoustic coordinates stay fixed: FRONT=0°, RIGHT=+90°, REAR=180°, -// LEFT=-90°. When facing down, anatomical RIGHT appears screen-left. -// Perspective projection is presentation-only. Never remap the HRTF azimuth: -// 0° FRONT (screen bottom), +90° listener RIGHT (screen left). -// All emitters lie on one physically plausible horizontal ellipse; - // its rear half is occluded by the head and near half overlays the bust. +// Top-down listener faces the TOP: FRONT=0°, RIGHT=+90°, REAR=180°, +// LEFT=-90°. Presentation-only SVG projection; native HRIR ITD/ILD +// and audio rotation coordinates NEVER change. const STAGE=Object.freeze({x:200,y:174,rx:148,ry:83}); const stagePoint=(azimuthDegrees)=>{ const rad=angle(azimuthDegrees)*Math.PI/180; - return {x:STAGE.x-STAGE.rx*Math.sin(rad), - y:STAGE.y+STAGE.ry*Math.cos(rad)}; + return {x:STAGE.x+STAGE.rx*Math.sin(rad), + y:STAGE.y-STAGE.ry*Math.cos(rad)}; }; const stageAzimuth=(screenX,screenY)=> - Math.atan2((STAGE.x-screenX)/STAGE.rx, - (screenY-STAGE.y)/STAGE.ry)*180/Math.PI; + Math.atan2((screenX-STAGE.x)/STAGE.rx, + (STAGE.y-screenY)/STAGE.ry)*180/Math.PI; // At SPREAD=0 the two actual HRIR directions coincide. Separate the // drawings (not their acoustic coordinates) tangentially, with tiny tethers // identifying the shared acoustic point. L and R remain independently draggable. @@ -59,8 +55,8 @@ const displayPair=(azimuths)=>{ const n=Math.hypot(tangent.x,tangent.y)||1; const offset=Math.max(0,(46-distance)*0.5); return anchors.map((anchor,i)=>({ - anchor,visible:{x:anchor.x+(i===0?1:-1)*offset*tangent.x/n, - y:anchor.y+(i===0?1:-1)*offset*tangent.y/n} + anchor,visible:{x:anchor.x+(i===0?-1:1)*offset*tangent.x/n, + y:anchor.y+(i===0?-1:1)*offset*tangent.y/n} })); }; const root=document.createElement("section"); @@ -76,27 +72,41 @@ root.innerHTML=[ '', '', '', - '', + '', + '', + '', + '', + '', '', '', '', // Far orbit belongs BEHIND the listener; true perspective elliptical rail. - '', - '', - 'REAR', - 'FRONT', - 'RIGHTLEFT', - // Image stays a single 128px transparent original: never canvas-generated DSP. - '', - // Rear source icons are painted BELOW the person's head, not in front of it. + '', + '', + 'FRONT', + 'REAR', + 'LEFTRIGHT', + // Original vector back-view listener: anatomy and shoulders face UP. + // Do not rotate the old face PNG upside-down or alter native HRTF angles. + '', '', - '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', // Near orbit overlays lower bust, forming ONE plausible 3D spatial ring. - '', - '', + '', + '', // Near-field speaker icons are painted above the bust, with perspective. '', - '', + '', // No circle markers: each emitter is a small raised studio monitor. // Offsets at coincident directions are display-only; native azimuth stays equal. '', @@ -146,7 +156,8 @@ const mount=()=>{if(!root.isConnected)document.body.append(root)}; if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",mount,{once:true});else mount(); let current=null,accepted=defaults(),draft=defaults(),pending=null,latest=null, readId="",readSentAt=0,seq=1,clock=null,frame=null,observed=0,observedAt=0, - drag=null,dialDrag=null,rangeEdits=new Set(),visualPhase=0,visualAt=0; + drag=null,dialDrag=null,rangeEdits=new Set(),gestureStart=new Map(), + visualPhase=0,visualAt=0,liveTimer=null,lastLiveAt=0; const context=()=>{ if(!current||!native())return null; const s=snapshot(),id=window.__ARMIX_NATIVE_M2__?.nativeIdFor?.(current.track); @@ -267,22 +278,60 @@ function requestSnapshot(force=false){ readSentAt=now; backend().emitEvent("arMixAction",{action:"nativeSonKuSnapshot",requestId:readId,...c}); } -function send(next){ +// One reusable CONTROL gesture publisher for every SonKu slider, knob, +// keyboard nudge and SVG speaker. The JUCE PCM callback still owns audio. +// Limit UI→native emissions to <= 25Hz. At most ONE change in flight, with +// latest-wins coalescing; ACK + accepted snapshot remain mandatory before +// issuing the next. Never fill the DSP SPSC queue with raw pointer events. +const LIVE_INTERVAL_MS=40; +const sameSettings=(a,b)=>a&&b&&Object.keys(defaults()).every(k=>a[k]===b[k]); +function send(next,continuous=false){ if(!valid(next))return false; draft={...next};render(); if(!native()){accepted={...next};hint("BROWSER VISUAL ONLY · NO DSP");return true;} - if(pending){latest={...next};hint("DSP BUSY · FINAL CHANGE HELD");return true;} const c=context();if(!c){hint("NATIVE INSERT NOT ACCEPTED");return false;} + if(pending){ + latest=sameSettings(next,pending.settings)?null:{...next}; + if(!continuous)hint("DSP FOLLOWING · FINAL VALUE PENDING"); + return true; + } + if(sameSettings(next,accepted))return true; const id="sonku-"+String(Date.now()*1000+(++seq%1000)); pending={requestId:id,settings:{...next},context:c,ack:false}; backend().emitEvent("arMixAction",{action:"nativeSonKuSet",requestId:id,...c,settings:next}); - hint("DSP QUEUED · AWAITING AUDIO ACK");return true; + hint(continuous?"DSP LIVE · AWAITING AUDIO ACK":"DSP QUEUED · AWAITING AUDIO ACK"); + return true; +} +function cancelLiveTimer(){ + if(liveTimer!==null){clearTimeout(liveTimer);liveTimer=null;} +} +function liveInput(next){ + if(!valid(next))return false; + draft={...next};render(); + const now=performance.now(),wait=LIVE_INTERVAL_MS-(now-lastLiveAt); + if(wait<=0){ + cancelLiveTimer();lastLiveAt=now;return send(next,true); + } + if(liveTimer===null)liveTimer=setTimeout(()=>{ + liveTimer=null;lastLiveAt=performance.now(); + if(current&&!root.hidden)send({...draft},true); + },Math.max(0,wait)); + return true; +} +function commitInput(next){ + cancelLiveTimer();lastLiveAt=performance.now(); + return send(next,false); } function flushLatest(){ - if(latest){const next=latest;latest=null;send(next);} + if(latest){const next=latest;latest=null; + if(!sameSettings(next,accepted))send(next,true); + } } function finishFailure(reason){ - pending=null;latest=null;draft={...accepted};hint(reason);render();requestSnapshot(true); + cancelLiveTimer();pending=null;latest=null; + // Native failure is real. Never display false "applied" audio; read back + // authoritative DSP state, do not retry a stale device/graph on a timer. + draft={...accepted};hint(reason);render();requestSnapshot(true); } backend()?.addEventListener?.("arMixBuiltinSonKuQueue",r=>{ if(!pending||r?.requestId!==pending.requestId)return; @@ -308,6 +357,10 @@ backend()?.addEventListener?.("arMixBuiltinSonKuSnapshot",r=>{ accepted={...incoming};pending=null;hint("DSP APPLIED · ACCEPTED");flushLatest(); }else if(!drag&&!dialDrag&&rangeEdits.size===0){ accepted={...incoming};draft={...incoming}; + }else if(!pending){ + // Preserve live thumb ownership, yet advance the accepted mirror so a + // later failure/reopen never restores a stale value. + accepted={...incoming}; } if(Number.isFinite(r.observedAzimuthDegrees)){ // First authoritative phase anchors the loop once. Subsequent readbacks @@ -318,8 +371,8 @@ backend()?.addEventListener?.("arMixBuiltinSonKuSnapshot",r=>{ render(); }); $("skClose").addEventListener("click",()=>{root.hidden=true;current=null; - pending=null;latest=null;readId="";readSentAt=0;dialDrag=null; - rangeEdits.clear(); + cancelLiveTimer();pending=null;latest=null;readId="";readSentAt=0;dialDrag=null; + drag=null;rangeEdits.clear();gestureStart.clear();lastLiveAt=0; if(clock!==null){clearInterval(clock);clock=null;} if(frame!==null){cancelAnimationFrame(frame);frame=null;}}); $("skMotion").addEventListener("click",()=>send({...draft,moving:!draft.moving})); @@ -335,24 +388,28 @@ for(const [id,key,convert] of [ ["skReflections","roomAmount",v=>v/100], ["skAmbience","ambience",v=>v/100]]) { const slider=$(id); - // While a range gesture is active, timer-driven native readbacks MUST NOT - // overwrite the uncommitted value. Commit once on change/pointer release. - slider.addEventListener("pointerdown",()=>rangeEdits.add(id)); + // ALL acoustic sliders stream PCM changes on input, not only on release. + // Thumb ownership survives stale ACK snapshots; no speculative "APPLIED". + slider.addEventListener("pointerdown",()=>{ + rangeEdits.add(id);gestureStart.set(id,draft[key]); + }); slider.addEventListener("input",()=>{ if(slider.disabled)return; const value=Number(slider.value); if(!Number.isFinite(value))return; rangeEdits.add(id); - draft={...draft,[key]:convert(value)};render(); + liveInput({...draft,[key]:convert(value)}); }); slider.addEventListener("change",()=>{ - if(slider.disabled){rangeEdits.delete(id);return;} + gestureStart.delete(id);rangeEdits.delete(id); + if(slider.disabled)return; const value=Number(slider.value); - rangeEdits.delete(id); - if(Number.isFinite(value))send({...draft,[key]:convert(value)}); + if(Number.isFinite(value))commitInput({...draft,[key]:convert(value)}); }); slider.addEventListener("pointercancel",()=>{ - rangeEdits.delete(id);draft={...accepted};render(); + const original=gestureStart.has(id)?gestureStart.get(id):accepted[key]; + gestureStart.delete(id);rangeEdits.delete(id); + commitInput({...draft,[key]:original}); }); } for(const [id,key,convert] of [ @@ -362,12 +419,15 @@ for(const [id,key,convert] of [ ["skTrim","outputTrim",v=>fromDb(v)]]) { const input=$(id); input.addEventListener("input",()=>{const v=Number(input.value); - if(!Number.isFinite(v))return;draft={...draft,[key]:convert(v)};render();}); - input.addEventListener("change",()=>send({...draft,[key]:convert(Number(input.value))})); + if(Number.isFinite(v))liveInput({...draft,[key]:convert(v)}); + }); + input.addEventListener("change",()=>{ + const value=Number(input.value); + if(Number.isFinite(value))commitInput({...draft,[key]:convert(value)}); + }); } -// Control-surface tactile dials. Retain native