summaryrefslogtreecommitdiff
path: root/tools/mq_editor/app.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mq_editor/app.js')
-rw-r--r--tools/mq_editor/app.js26
1 files changed, 11 insertions, 15 deletions
diff --git a/tools/mq_editor/app.js b/tools/mq_editor/app.js
index 380bb12..55b8d25 100644
--- a/tools/mq_editor/app.js
+++ b/tools/mq_editor/app.js
@@ -46,27 +46,20 @@ document.getElementById('hpK2').addEventListener('input', function() {
document.getElementById('hpK2Val').textContent = k >= 1.0 ? 'bypass' : fmtHz(f);
});
-function invalidatePartialSpectrum() {
- if (!viewer) return;
- viewer.synthOpts = getSynthParams().opts;
- viewer._partialSpecCache = null;
- viewer.renderPartialSpectrum(viewer.spectrumTime, true);
-}
-
// Show/hide global resonator params when forceResonator toggled
document.getElementById('forceResonator').addEventListener('change', function() {
document.getElementById('globalResParams').style.display = this.checked ? '' : 'none';
- invalidatePartialSpectrum();
+ if (viewer) viewer.render();
});
document.getElementById('globalR').addEventListener('input', function() {
document.getElementById('globalRVal').textContent = parseFloat(this.value).toFixed(4);
- invalidatePartialSpectrum();
+ if (viewer) viewer.render();
});
document.getElementById('globalGain').addEventListener('input', function() {
document.getElementById('globalGainVal').textContent = parseFloat(this.value).toFixed(2);
- invalidatePartialSpectrum();
+ if (viewer) viewer.render();
});
-document.getElementById('forceRGain').addEventListener('change', invalidatePartialSpectrum);
+document.getElementById('forceRGain').addEventListener('change', () => { if (viewer) viewer.render(); });
let audioBuffer = null;
let viewer = null;
@@ -207,7 +200,8 @@ function loadAudioBuffer(buffer, label) {
document.getElementById('exploreBtn').disabled = false;
document.getElementById('contourBtn').disabled = false;
editor.setViewer(viewer);
- viewer.onPartialSelect = (i) => editor.onPartialSelect(i);
+ viewer.onGetSynthOpts = () => getSynthParams().opts;
+ viewer.onPartialSelect = (i) => editor.onPartialSelect(i);
viewer.onRender = () => editor.onRender();
viewer.onBeforeChange = pushUndo;
viewer.onExploreMove = (time, freq) => {
@@ -394,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;
@@ -412,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();
@@ -536,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();