diff --git a/AR-MIX-Live-FX-Host-Standalone-v0.3.html b/AR-MIX-Live-FX-Host-Standalone-v0.3.html index b4ad10b4a..0a7173964 100644 --- a/AR-MIX-Live-FX-Host-Standalone-v0.3.html +++ b/AR-MIX-Live-FX-Host-Standalone-v0.3.html @@ -1251,6 +1251,93 @@ } } window.__arMixSetLedMeterLevel=setLedMeterLevel; + +// Native-only visual interpolation. JUCE sends true peak samples at 12 Hz; +// never change that realtime/data cadence to control animation smoothness. +// Exactly ONE pending timer + ONE rAF serve every live meter (not one per bar). +const NATIVE_METER_FRAME_MS=34; // ceiling 29.4 scheduled paint frames/s +const nativeMeterStates=new Map(); +const nativeMeterDirect=new URLSearchParams(location.search).get('metermotion')==='direct'; +const nativeMeterMotionStats={frames:0,scheduled:0,targets:0,meterPaintCalls:0,frameBudgetMs:NATIVE_METER_FRAME_MS,active:0}; +let nativeMeterTimer=0,nativeMeterRAF=0,nativeMeterLastTime=0; +function nativeMeterStep(level,target,fallVelocity,dt){ + const span=Math.max(0,Math.min(.065,Number(dt)||0)); + if(target>level){ + // About 85% of an upward step in 34ms; almost immediate at real speech peaks. + const v=level+(target-level)*(1-Math.exp(-span/.018)); + return {level:target-v<.3?target:v,velocity:0}; + } + if(target{ + nativeMeterTimer=0; + if(!document.hidden)nativeMeterRAF=requestAnimationFrame(animateNativeMeters); + },NATIVE_METER_FRAME_MS); +} +function animateNativeMeters(now){ + nativeMeterRAF=0; + if(document.hidden){nativeMeterLastTime=0;return;} + const dt=nativeMeterLastTime?Math.min(.065,Math.max(0,(now-nativeMeterLastTime)/1000)):NATIVE_METER_FRAME_MS/1000; + nativeMeterLastTime=now; + nativeMeterMotionStats.frames++; + let active=0; + for(const [el,s] of nativeMeterStates){ + if(!el.isConnected){nativeMeterStates.delete(el);continue;} + const next=nativeMeterStep(s.level,s.target,s.velocity,dt); + s.level=next.level;s.velocity=next.velocity; + setLedMeterLevel(el,s.level); + nativeMeterMotionStats.meterPaintCalls++; + if(Math.abs(s.level-s.target)>.3)active++; + } + nativeMeterMotionStats.active=active; + if(active)scheduleNativeMeterFrame(); + else nativeMeterLastTime=0; +} +function setNativeMeterTarget(el,rawValue){ + if(!el)return; + const target=clamp(Number(rawValue)||0,0,100); + let s=nativeMeterStates.get(el); + if(!s){ + // Mixer DOM may be rebuilt after a preset/FX edit: prune detached nodes + // without polling or leaking strong references to old LED bars. + if(nativeMeterStates.size>4) + for(const [old] of nativeMeterStates)if(!old.isConnected)nativeMeterStates.delete(old); + s={level:0,target:0,velocity:0};nativeMeterStates.set(el,s); + setLedMeterLevel(el,0); + } + s.target=target; + nativeMeterMotionStats.targets++; + if(nativeMeterDirect||document.hidden|| + (typeof matchMedia==='function'&&matchMedia('(prefers-reduced-motion: reduce)').matches)){ + s.level=target;s.velocity=0;setLedMeterLevel(el,target); + return; + } + if(Math.abs(s.level-target)>.3)scheduleNativeMeterFrame(); +} +window.__arMixSetNativeMeterTarget=setNativeMeterTarget; +window.__arMixMeterMotionStats=nativeMeterMotionStats; +document.addEventListener('visibilitychange',()=>{ + if(!document.hidden)return; + if(nativeMeterTimer){clearTimeout(nativeMeterTimer);nativeMeterTimer=0;} + if(nativeMeterRAF){cancelAnimationFrame(nativeMeterRAF);nativeMeterRAF=0;} + nativeMeterLastTime=0; + for(const [el,s] of nativeMeterStates){ + if(!el.isConnected){nativeMeterStates.delete(el);continue;} + s.level=s.target;s.velocity=0;setLedMeterLevel(el,s.level); + } + nativeMeterMotionStats.active=0; +}); + // Observe only the stable mixer root, never disposable strips; no hot-path reflow. if(typeof ResizeObserver==='function'){ const ledResizeObserver=new ResizeObserver(()=>{ diff --git a/docs/ARD_056_NATIVE_METER_BALLISTICS_VISUAL_AUDIT_2026-10-27.md b/docs/ARD_056_NATIVE_METER_BALLISTICS_VISUAL_AUDIT_2026-10-27.md new file mode 100644 index 000000000..69b103fb9 --- /dev/null +++ b/docs/ARD_056_NATIVE_METER_BALLISTICS_VISUAL_AUDIT_2026-10-27.md @@ -0,0 +1,34 @@ +# ARD-056 P2 — Native meter ballistics and GUI visual audit (2026-10-27) + +## Basis and boundaries + +Screenshot: user Windows 11 Pro native EXE at 1594×928, Channel 1 LED lit, un-routed preview lanes dark, Auto Orbit visible. This screenshot cannot establish actual FPS, GPU utilization, or repaint duration. Base main de4dd81c; PR #97 is simultaneously modifying FX Rack/channel selection/GUI optics, so visual scope is carefully separated. + +## Engineering audit + +1. Native JUCE src/Main.cpp calls startTimerHz(12) and publishes arMixStatus at 12Hz. The native audio callback remains unchanged. +2. Old web/bridge.js did source release using Math.max(raw,old-5) for each 12Hz status. That makes a stepped release tied to telemetry count, not elapsed time. +3. web/app.js paints fixed-palette 7px quantised LED segments; PR #96 avoids dirty CSS writes. Do not revert that renderer or distort its stationary color bands. +4. Browser demo simulates separate 25Hz meter changes, not native sound; the new ballistics work only through the JUCE native bridge. + +## Implemented scheduling and signal motion + +- One shared native meter scheduler for live CH1 input and master L/R/aux, with 34ms timer then one requestAnimationFrame, at most ~29.4 scheduled paint frames/sec (actual observed FPS can be less). No per-strip loops or timers and no idle rAF after levels settle. +- Fast attack: exponential rise with 18ms time constant, never overshoots. Gravity release: begin with at least 14 percent-units/second, accelerate +230 percent-units/s² up to 100 percent-units/second terminal rate, never overshoots. +- Time delta bounded to 65ms; after hidden-tab transition cancel timer and RAF and synchronize to latest target; reduced-motion or ?metermotion=direct displays raw native levels without animation. +- DOM Map prunes stale disconnected LED elements when mixer re-renders. Observability: window.__arMixMeterMotionStats for developer diagnostics only, never advertised as GPU proof. +- No modification to JUCE telemetry/audio RT callback, FX Orbit, FX Rack, PAN, faders, LED colors, clip/peak hold, or shadow styles. + +## Visual UX audit, screenshot-based + +- Strengths: identifiable 10-channel colors and master, coherent dark console palette, metallic fader cap assets, segmented LED scale, clear Orbit trajectory. +- P0 addressed here: stiff stair-step native metering; improve motion perception while preserving stationary LED color bands and bounded updates. +- P1: repeated ADD FX in the un-routed lanes can visually imply live DSP; PR #97 currently owns channel-aware FX/Rack remediation, so do not duplicate or overwrite that concurrent work. +- P1: tiny LUFS/true peak label, channel names, and footer status need selective typography/contrast tests at 1366×768 and 125% DPI, rather than global font/strip resizing. +- P1: Orbit popup obscures several input strips; current anchored workflow is functional, but reconsider side docking or collision avoidance after PR #97 settles (no extra glow/backdrop blur). +- P1: very strong bevels in top toolbar and left-rail are visually heavier than mixer; coordinate with approved BTN-180 recipes and PR #97 before altering. Do not remove mandated seven rest/seven pressed shadows. +- Preserve honest native routing indication: live CH1 and master meter are not proof that the other nine channels or master FX have audio DSP. + +## Verification gate + +Run deterministic ballistics tests for rise/fall/acceleration/no-overshoot and single scheduler, CSS/standalone parity, Chromium + Firefox GUI test, and Windows native MSVC CTests/package. Reconcile latest main and review PR #97 before merge. Validate on affected standard Windows hardware with direct versus animated mode, input quiet/loud, Orbit open/closed, p95 and GPU profiler. No claim of real end-to-end FPS or audio FAT from CI. diff --git a/tests/gui_workflow_contract_test.mjs b/tests/gui_workflow_contract_test.mjs index 501c0734a..c45c124cf 100644 --- a/tests/gui_workflow_contract_test.mjs +++ b/tests/gui_workflow_contract_test.mjs @@ -64,3 +64,16 @@ test('quantised LED meter avoids redundant raw CSS writes while preserving diagn assert.ok(monitor.includes('const setTextIfChanged=')); assert.ok(bridge.includes('footer.textContent!==text')); }); + +test('native 12Hz status uses one capped shared visual meter scheduler',()=>{ + assert.ok(app.includes('const NATIVE_METER_FRAME_MS=34;')); + assert.ok(app.includes('const nativeMeterStates=new Map()')); + assert.ok(app.includes('function nativeMeterStep(')); + assert.ok(app.includes('function scheduleNativeMeterFrame(')); + assert.ok(app.includes('if(nativeMeterTimer||nativeMeterRAF||document.hidden)return;')); + assert.ok(app.includes("window.__arMixSetNativeMeterTarget=setNativeMeterTarget")); + assert.ok(bridge.includes('window.__arMixSetNativeMeterTarget(el,level)')); + assert.ok(!bridge.includes('liveInputLevel-5'), 'release must use elapsed time, not telemetry count'); + assert.ok(!bridge.includes('liveOutputLeft-5')); + assert.ok(!app.includes('setInterval(animateNativeMeters'), 'no perpetual meter frame timer'); +}); diff --git a/tests/main_v08_native_integration_test.mjs b/tests/main_v08_native_integration_test.mjs index 2ea90ec7a..87485d986 100644 --- a/tests/main_v08_native_integration_test.mjs +++ b/tests/main_v08_native_integration_test.mjs @@ -30,8 +30,10 @@ test('no fake oscillating VUs inside native JUCE',()=>{ const scheduled=app.indexOf('meterTimer=setTimeout(',scheduler); assert.ok(a>scheduler && guard>a && guardscheduler && schedulerGuard{ assert.match(src,/setProperty \("channelDb", juce::Decibels::gainToDecibels/); diff --git a/tests/native_ui_contract_test.mjs b/tests/native_ui_contract_test.mjs index 77f9ce1b8..48e8041af 100644 --- a/tests/native_ui_contract_test.mjs +++ b/tests/native_ui_contract_test.mjs @@ -20,10 +20,11 @@ test('native app never runs demo sine meters',()=>{ assert.ok(app.indexOf('meterRAF=requestAnimationFrame(t=>{meterRAF=0;meters(t)});',scheduler)>scheduler); }); test('native meter reads DSP and hides all 11 visual-only channels',()=>{ - assert.match(bridge,/inputLevel=percent\(d\.inputPeak\)/); - assert.match(bridge,/outputLevel=percent\(d\.peak\)/); - assert.ok(bridge.includes('["masterL",liveOutputLeft]')); - assert.ok(bridge.includes('["masterR",liveOutputRight]')); + assert.ok(bridge.includes('percent(d.inputPeak)'),'CH1 uses native audio input peak'); + assert.ok(bridge.includes('percent(d.peakLeft)') && bridge.includes('percent(d.peakRight)'),'real output L/R peak inputs'); + assert.ok(bridge.includes('percent(d.peak)'),'master aux uses native output peak'); + assert.ok(bridge.includes('window.__arMixSetNativeMeterTarget(el,level)'),'native data is fed to bounded visual presenter'); + assert.ok(!bridge.includes('liveInputLevel-5'),'remove callback-cadence smoothing'); assert.match(bridge,/track\.dataset\.preview="1"/); assert.ok(bridge.includes("meter-fill{opacity:0!important}")); }); diff --git a/tests/reconciled_gui_engine_contract_test.mjs b/tests/reconciled_gui_engine_contract_test.mjs index af9bc2c9e..5af0350fd 100644 --- a/tests/reconciled_gui_engine_contract_test.mjs +++ b/tests/reconciled_gui_engine_contract_test.mjs @@ -24,9 +24,10 @@ test('native desktop does not run any visual-only sine meter loop',()=>{ const timer=app.indexOf('meterTimer=setTimeout(',scheduler); assert.ok(scheduler>=0 && fn>scheduler && early>fn && earlyscheduler && scheduleGuard{ diff --git a/tests/ui_smoke.py b/tests/ui_smoke.py index d2ea743ac..dfef0141d 100644 --- a/tests/ui_smoke.py +++ b/tests/ui_smoke.py @@ -130,6 +130,25 @@ def shared_shadow_shape(shadow): return {before,after:e.getAttribute('style'),lit,level:ledMeterCache.get(e).level}; }""") assert dirty['before']==dirty['after'] and dirty['level']==1.1,dirty + # Deterministic native-style time-based ballistics: fast attack, + # gravity release, non-overshoot, single shared 30fps visual owner. + ballistic=await page.evaluate("""()=>{ + const fast=nativeMeterStep(8,96,0,.034); + const down=nativeMeterStep(96,8,0,.034); + const further=nativeMeterStep(down.level,8,down.velocity,.034); + const zero=nativeMeterStep(8,8,14,.034); + const overshoot=nativeMeterStep(2,0,96,.065); + return {fast,down,further,zero,overshoot,cap:NATIVE_METER_FRAME_MS, + nativeTarget:typeof window.__arMixSetNativeMeterTarget, + stats:typeof window.__arMixMeterMotionStats}; + }""") + assert ballistic['cap']>=34 and ballistic['nativeTarget']=='function',ballistic + assert ballistic['fast']['level']>80 and ballistic['fast']['level']<=96,ballistic + assert 94{ clipLatch['0']=true; diff --git a/web/app.js b/web/app.js index 6288ee500..281fe2aa7 100644 --- a/web/app.js +++ b/web/app.js @@ -58,6 +58,93 @@ function setLedMeterLevel(el,rawLevel){ } } window.__arMixSetLedMeterLevel=setLedMeterLevel; + +// Native-only visual interpolation. JUCE sends true peak samples at 12 Hz; +// never change that realtime/data cadence to control animation smoothness. +// Exactly ONE pending timer + ONE rAF serve every live meter (not one per bar). +const NATIVE_METER_FRAME_MS=34; // ceiling 29.4 scheduled paint frames/s +const nativeMeterStates=new Map(); +const nativeMeterDirect=new URLSearchParams(location.search).get('metermotion')==='direct'; +const nativeMeterMotionStats={frames:0,scheduled:0,targets:0,meterPaintCalls:0,frameBudgetMs:NATIVE_METER_FRAME_MS,active:0}; +let nativeMeterTimer=0,nativeMeterRAF=0,nativeMeterLastTime=0; +function nativeMeterStep(level,target,fallVelocity,dt){ + const span=Math.max(0,Math.min(.065,Number(dt)||0)); + if(target>level){ + // About 85% of an upward step in 34ms; almost immediate at real speech peaks. + const v=level+(target-level)*(1-Math.exp(-span/.018)); + return {level:target-v<.3?target:v,velocity:0}; + } + if(target{ + nativeMeterTimer=0; + if(!document.hidden)nativeMeterRAF=requestAnimationFrame(animateNativeMeters); + },NATIVE_METER_FRAME_MS); +} +function animateNativeMeters(now){ + nativeMeterRAF=0; + if(document.hidden){nativeMeterLastTime=0;return;} + const dt=nativeMeterLastTime?Math.min(.065,Math.max(0,(now-nativeMeterLastTime)/1000)):NATIVE_METER_FRAME_MS/1000; + nativeMeterLastTime=now; + nativeMeterMotionStats.frames++; + let active=0; + for(const [el,s] of nativeMeterStates){ + if(!el.isConnected){nativeMeterStates.delete(el);continue;} + const next=nativeMeterStep(s.level,s.target,s.velocity,dt); + s.level=next.level;s.velocity=next.velocity; + setLedMeterLevel(el,s.level); + nativeMeterMotionStats.meterPaintCalls++; + if(Math.abs(s.level-s.target)>.3)active++; + } + nativeMeterMotionStats.active=active; + if(active)scheduleNativeMeterFrame(); + else nativeMeterLastTime=0; +} +function setNativeMeterTarget(el,rawValue){ + if(!el)return; + const target=clamp(Number(rawValue)||0,0,100); + let s=nativeMeterStates.get(el); + if(!s){ + // Mixer DOM may be rebuilt after a preset/FX edit: prune detached nodes + // without polling or leaking strong references to old LED bars. + if(nativeMeterStates.size>4) + for(const [old] of nativeMeterStates)if(!old.isConnected)nativeMeterStates.delete(old); + s={level:0,target:0,velocity:0};nativeMeterStates.set(el,s); + setLedMeterLevel(el,0); + } + s.target=target; + nativeMeterMotionStats.targets++; + if(nativeMeterDirect||document.hidden|| + (typeof matchMedia==='function'&&matchMedia('(prefers-reduced-motion: reduce)').matches)){ + s.level=target;s.velocity=0;setLedMeterLevel(el,target); + return; + } + if(Math.abs(s.level-target)>.3)scheduleNativeMeterFrame(); +} +window.__arMixSetNativeMeterTarget=setNativeMeterTarget; +window.__arMixMeterMotionStats=nativeMeterMotionStats; +document.addEventListener('visibilitychange',()=>{ + if(!document.hidden)return; + if(nativeMeterTimer){clearTimeout(nativeMeterTimer);nativeMeterTimer=0;} + if(nativeMeterRAF){cancelAnimationFrame(nativeMeterRAF);nativeMeterRAF=0;} + nativeMeterLastTime=0; + for(const [el,s] of nativeMeterStates){ + if(!el.isConnected){nativeMeterStates.delete(el);continue;} + s.level=s.target;s.velocity=0;setLedMeterLevel(el,s.level); + } + nativeMeterMotionStats.active=0; +}); + // Observe only the stable mixer root, never disposable strips; no hot-path reflow. if(typeof ResizeObserver==='function'){ const ledResizeObserver=new ResizeObserver(()=>{ diff --git a/web/bridge.js b/web/bridge.js index 43997faee..de1601071 100644 --- a/web/bridge.js +++ b/web/bridge.js @@ -10,12 +10,21 @@ function paintMeter(el,value){ if(!el)return; const level=Math.max(0,Math.min(100,Number(value)||0)); - if(typeof window.__arMixSetLedMeterLevel==="function")window.__arMixSetLedMeterLevel(el,level); + if(typeof window.__arMixSetNativeMeterTarget==="function") + window.__arMixSetNativeMeterTarget(el,level); + else if(typeof window.__arMixSetLedMeterLevel==="function") + window.__arMixSetLedMeterLevel(el,level); else el.style.setProperty("--level",level+"%"); } // Clear preview levels before first real device callback/status. + // One-time native boot clear includes unrouted preview channels. Keep it + // direct so the live 30fps animator owns ONLY CH1 and real Master meters. document.querySelectorAll("[data-meter],#masterMeterL,#masterMeterR,#masterMeterAux") - .forEach(el=>paintMeter(el,0)); + .forEach(el=>{ + if(typeof window.__arMixSetLedMeterLevel==="function") + window.__arMixSetLedMeterLevel(el,0); + else el.style.setProperty("--level","0%"); + }); const send = (action, more = {}) => backend.emitEvent("arMixAction", {action, ...more}); const state = {catalog: [], chain: [], scanning: false, message: "Connecting to native host...", @@ -1033,7 +1042,6 @@ } if(changed)patchMixer(); } - let liveInputLevel=0, liveOutputLevel=0, liveOutputLeft=0, liveOutputRight=0; backend.addEventListener("arMixStatus",d=>{ state.device=d; state.monitor=!!d.monitor; @@ -1049,21 +1057,15 @@ :"NO AUDIO DEVICE · SELECT AUDIO SETUP"; toStatus(text); // Only CH1 and master are sourced from a real native audio callback. - const inputLevel=percent(d.inputPeak), outputLevel=percent(d.peak); - // Real left/right peaks reflect PAN. Fast attack, capped 12-Hz UI release. - liveInputLevel=Math.max(inputLevel,liveInputLevel-5); - liveOutputLevel=Math.max(outputLevel,liveOutputLevel-5); - liveOutputLeft=Math.max(percent(d.peakLeft),liveOutputLeft-5); - liveOutputRight=Math.max(percent(d.peakRight),liveOutputRight-5); - const meter=document.querySelector('[data-meter="0"]'); - paintMeter(meter,liveInputLevel); - for(const [key,level] of [["masterL",liveOutputLeft],["masterR",liveOutputRight]]){ - const target=document.querySelector('[data-meter="'+key+'"]')|| - document.getElementById(key==="masterL"?"masterMeterL":"masterMeterR"); - paintMeter(target,level); - } - const aux=document.getElementById("masterMeterAux"); - paintMeter(aux,liveOutputLevel); + // No fixed "-5 per telemetry callback" smoothing: its speed changed + // with source cadence and fought the shared elapsed-time ballistics. + // UI animation is capped at 29.4fps; native peaks remain unmodified. + paintMeter(document.querySelector('[data-meter="0"]'),percent(d.inputPeak)); + paintMeter(document.querySelector('[data-meter="masterL"]')|| + document.getElementById("masterMeterL"),percent(d.peakLeft)); + paintMeter(document.querySelector('[data-meter="masterR"]')|| + document.getElementById("masterMeterR"),percent(d.peakRight)); + paintMeter(document.getElementById("masterMeterAux"),percent(d.peak)); // Design-only LUFS/true-peak fields have no native measurement yet. const lufs=document.getElementById("masterLufs"),tp=document.getElementById("masterDbtp"); if(lufs&&lufs.textContent!=="—")lufs.textContent="—";