Merge branch 'main' into atfornesmain

This commit is contained in:
Felix Roos 2023-11-24 11:10:15 +01:00
commit 71b4e14dd3
17 changed files with 249 additions and 127 deletions

View file

@ -1,33 +1,33 @@
import { getDrawContext } from '@strudel.cycles/core';
let audio = false;
let hydra;
function appendCanvas(c) {
const { canvas: testCanvas } = getDrawContext();
c.canvas.id = 'hydra-canvas';
c.canvas.style.position = 'absolute';
c.canvas.style.position = 'fixed';
c.canvas.style.top = '0px';
testCanvas.after(c.canvas);
return testCanvas;
}
export async function initHydra(config) {
audio = config?.audio || false;
export async function initHydra(options = {}) {
//load and init hydra
if (!document.getElementById('hydra-canvas')) {
await import('https://unpkg.com/hydra-synth');
hydra = new Hydra({ detectAudio: audio });
const { src = 'https://unpkg.com/hydra-synth', ...opts } = options;
await import(src);
hydra = new Hydra(opts);
appendCanvas(hydra);
// s0.init({ src: hydraCanvas }); // whats that?
}
// if config.audio is true
// if options.detectAudio is true
// and current canvas des not detect audio
if (config?.audio && !hydra.detectAudio) {
if (options?.detectAudio && !hydra?.detectAudio) {
//remove previous canvas without audio detection
document.getElementById('hydra-canvas').remove();
// create and append a new audio responsive canvas
hydra = new Hydra({ detectAudio: audio });
appendCanvas(hydra);
return initHydra(options);
}
}