fix: clear hydra on reset

This commit is contained in:
Felix Roos 2024-03-10 00:29:52 +01:00
parent 0875e805b4
commit 012b19c79e
2 changed files with 21 additions and 3 deletions

View file

@ -1,4 +1,4 @@
import { getDrawContext } from '@strudel/core';
import { getDrawContext, controls } from '@strudel/core';
let latestOptions;
@ -11,6 +11,7 @@ function appendCanvas(c) {
return testCanvas;
}
let hydra;
export async function initHydra(options = {}) {
// reset if options have changed since last init
if (latestOptions && JSON.stringify(latestOptions) !== JSON.stringify(options)) {
@ -19,7 +20,6 @@ export async function initHydra(options = {}) {
latestOptions = options;
//load and init hydra
if (!document.getElementById('hydra-canvas')) {
console.log('reinit..');
const {
src = 'https://unpkg.com/hydra-synth',
feedStrudel = false,
@ -27,7 +27,7 @@ export async function initHydra(options = {}) {
} = { detectAudio: false, ...options };
await import(/* @vite-ignore */ src);
const hydra = new Hydra(hydraConfig);
hydra = new Hydra(hydraConfig);
if (feedStrudel) {
const { canvas } = getDrawContext();
canvas.style.display = 'none';
@ -37,4 +37,14 @@ export async function initHydra(options = {}) {
}
}
export function clearHydra() {
if (hydra) {
hydra.hush();
}
globalThis.s0?.clear();
document.getElementById('hydra-canvas')?.remove();
globalThis.speed = controls.speed;
globalThis.shape = controls.shape;
}
export const H = (p) => () => p.queryArc(getTime(), getTime())[0].value;