From 7554f59a328acc706119d0952b50ab9fdee8c623 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 19 Feb 2026 07:47:17 +0100 Subject: fix(mq_editor): offset playhead to partial t_start when playing single partial (key 3) handoff(Claude): playhead offset fix for single partial playback --- tools/mq_editor/app.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/mq_editor/app.js b/tools/mq_editor/app.js index 1c6d548..55b8d25 100644 --- a/tools/mq_editor/app.js +++ b/tools/mq_editor/app.js @@ -388,7 +388,7 @@ for (const el of [birthPersistenceEl, deathAgeEl, phaseErrorWeightEl, minLengthE el.addEventListener('change', () => { if (stftCache) runExtraction(); }); } -function playAudioBuffer(buffer, statusMsg) { +function playAudioBuffer(buffer, statusMsg, timeOffset = 0) { const startTime = audioContext.currentTime; currentSource = audioContext.createBufferSource(); currentSource.buffer = buffer; @@ -406,7 +406,7 @@ function playAudioBuffer(buffer, statusMsg) { setStatus(statusMsg, 'info'); function tick() { if (!currentSource) return; - viewer.setPlayheadTime(audioContext.currentTime - startTime); + viewer.setPlayheadTime(timeOffset + audioContext.currentTime - startTime); requestAnimationFrame(tick); } tick(); @@ -530,7 +530,9 @@ document.addEventListener('keydown', (e) => { const partial = extractedPartials[sel]; if (!partial) return; stopAudio(); - playAudioBuffer(getAudioBuffer([partial], 0.05), `Playing partial #${sel}...`); + const tStart = Math.min(...partial.times); + const offset = Math.max(0, tStart - 0.05); + playAudioBuffer(getAudioBuffer([partial], 0.05), `Playing partial #${sel}...`, offset); } else if (e.code === 'KeyP') { e.preventDefault(); if (viewer) viewer.togglePeaks(); -- cgit v1.2.3