perf(tuner): idle the always-on tuner viz rAF when there's no signal (#647)

The v3 home tuner card runs continuously, and every tuner visualization
drove a self-rescheduling 60fps requestAnimationFrame loop that never
stopped — pinning a renderer core even on a silent home screen with the
needle/strobe at rest.

Make each viz idle its loop once there's nothing left to animate, and
re-kick it from update() on the next reading that actually moves it:

- analogue-gauge: stop when the needle + drum strip have settled on their
  targets (|target-current| below a sub-visible epsilon); restart when a
  new reading moves the target.
- strobe / mace-fx-iii / chef-mt3: stop when there's no live signal and the
  strobe drift (and glow fade) have fully decayed; restart on the next note.
- toilet-tuner: stop when silent and the plunger has eased back to centre;
  restart on the next reading (guarded so repeated no-signal updates don't
  re-kick a parked loop).

Active tuning is unchanged — the loop runs whenever a note is sounding or
the indicator is still moving. Bumps tuner 1.3.1 -> 1.3.2.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Byron Gamatos
2026-06-29 23:12:42 +02:00
committed by GitHub
co-authored by Claude Opus 4.8
parent dfa825b4ab
commit a732e1f9d2
6 changed files with 86 additions and 1 deletions
@@ -18,6 +18,8 @@
// ── Constants ─────────────────────────────────────────────────────
var _TUNER_LABEL_H = 12; // px height of each drum label
var _TUNER_NEEDLE_HALF_SWEEP = 90; // degrees — ±50 cents = horizontal (180° apart)
var _SETTLE_A = 0.05; // deg — needle "settled" threshold (sub-visible)
var _SETTLE_Y = 0.1; // px — drum-strip "settled" threshold
var _TUNER_IN_TUNE_THRESHOLD = 2;
var _TUNER_STRIP_START_MIDI = 14; // ~18 Hz — covers 20 Hz minimum
var _TUNER_STRIP_END_MIDI = 84; // ~1047 Hz C6
@@ -321,9 +323,34 @@
currentAngle += (targetAngle - currentAngle) * lf;
_setNeedle(currentAngle);
// Stop once the needle has settled on its target — a static needle
// needs no repaint. update() re-kicks the loop when a new reading
// moves the target, so this idles the always-on tuner (no signal /
// steady pitch) instead of pinning a core at 60 fps forever.
if (Math.abs(targetDrumY - currentDrumY) <= _SETTLE_Y
&& Math.abs(targetAngle - currentAngle) <= _SETTLE_A) {
currentDrumY = targetDrumY; currentAngle = targetAngle;
freqStrip.style.transform = 'translateY(' + currentDrumY + 'px)';
noteStrip.style.transform = 'translateY(' + currentDrumY + 'px)';
_setNeedle(currentAngle);
rafId = null;
return;
}
rafId = requestAnimationFrame(_animate);
}
// Restart the loop only when there's actually something to animate toward
// (a new target). Reset lastTime so the first frame after an idle gap
// doesn't take one big easing step.
function _kick() {
if (rafId === null
&& (Math.abs(targetDrumY - currentDrumY) > _SETTLE_Y
|| Math.abs(targetAngle - currentAngle) > _SETTLE_A)) {
lastTime = performance.now();
rafId = requestAnimationFrame(_animate);
}
}
rafId = requestAnimationFrame(_animate);
// ── Public API ────────────────────────────────────────────────
@@ -360,6 +387,7 @@
bulbEl.style.backgroundColor = '#2a1010';
bulbEl.style.border = '2px solid #4a2020';
bulbEl.style.boxShadow = 'none';
_kick(); // animate back to rest, then the loop self-stops
return;
}
@@ -376,6 +404,7 @@
bulbEl.style.border = '2px solid #4a2020';
bulbEl.style.boxShadow = 'none';
}
_kick(); // a new reading moved the target → run until it settles
}
function destroy() {