Replace QML CAVA polling with SSE server for smooth bars

DataSource fork+exec was limited to ~1fps. Now cava pipes into a Python
SSE server (port 5555) and the HTML connects directly via EventSource,
getting updates at up to 60fps without QML overhead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
ltadeu6 2026-06-07 09:37:58 -03:00
parent 5876701a64
commit 39e7c07309
No known key found for this signature in database
GPG key ID: FB9FDAB6B6F3418D
4 changed files with 59 additions and 22 deletions

View file

@ -886,18 +886,25 @@ for (let i = 0; i < VU_COUNT; i++) {
vuBars.push(bar);
}
// Called by QML with semicolon-separated CAVA values (0100 per bar)
// Called with semicolon-separated CAVA values (0100 per bar)
function updateBars(raw) {
if (!isPlaying) return;
const vals = raw.split(';');
vuBars.forEach((bar, i) => {
const v = Math.min(100, parseInt(vals[i] || 0, 10));
const h = Math.max(3, (v / 100) * MAX_BAR_H);
const v = Math.min(100, parseInt(vals[i] || 0, 10));
const h = Math.max(3, (v / 100) * MAX_BAR_H);
bar.style.height = h + 'px';
bar.style.opacity = 0.3 + 0.7 * (v / 100);
});
}
// Connect to CAVA SSE server (started by cava-start.sh via QML)
(function connectCava() {
const sse = new EventSource('http://127.0.0.1:5555');
sse.onmessage = e => { if (e.data) updateBars(e.data); };
sse.onerror = () => { sse.close(); setTimeout(connectCava, 3000); };
})();
/* ============================================================
FLOATING MUSIC NOTES
============================================================ */