mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 20:48:27 +00:00
fix: clear hydra on reset
This commit is contained in:
parent
0875e805b4
commit
012b19c79e
@ -1,4 +1,4 @@
|
|||||||
import { getDrawContext } from '@strudel/core';
|
import { getDrawContext, controls } from '@strudel/core';
|
||||||
|
|
||||||
let latestOptions;
|
let latestOptions;
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ function appendCanvas(c) {
|
|||||||
return testCanvas;
|
return testCanvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let hydra;
|
||||||
export async function initHydra(options = {}) {
|
export async function initHydra(options = {}) {
|
||||||
// reset if options have changed since last init
|
// reset if options have changed since last init
|
||||||
if (latestOptions && JSON.stringify(latestOptions) !== JSON.stringify(options)) {
|
if (latestOptions && JSON.stringify(latestOptions) !== JSON.stringify(options)) {
|
||||||
@ -19,7 +20,6 @@ export async function initHydra(options = {}) {
|
|||||||
latestOptions = options;
|
latestOptions = options;
|
||||||
//load and init hydra
|
//load and init hydra
|
||||||
if (!document.getElementById('hydra-canvas')) {
|
if (!document.getElementById('hydra-canvas')) {
|
||||||
console.log('reinit..');
|
|
||||||
const {
|
const {
|
||||||
src = 'https://unpkg.com/hydra-synth',
|
src = 'https://unpkg.com/hydra-synth',
|
||||||
feedStrudel = false,
|
feedStrudel = false,
|
||||||
@ -27,7 +27,7 @@ export async function initHydra(options = {}) {
|
|||||||
} = { detectAudio: false, ...options };
|
} = { detectAudio: false, ...options };
|
||||||
|
|
||||||
await import(/* @vite-ignore */ src);
|
await import(/* @vite-ignore */ src);
|
||||||
const hydra = new Hydra(hydraConfig);
|
hydra = new Hydra(hydraConfig);
|
||||||
if (feedStrudel) {
|
if (feedStrudel) {
|
||||||
const { canvas } = getDrawContext();
|
const { canvas } = getDrawContext();
|
||||||
canvas.style.display = 'none';
|
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;
|
export const H = (p) => () => p.queryArc(getTime(), getTime())[0].value;
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import {
|
|||||||
import { defaultAudioDeviceName } from '../settings.mjs';
|
import { defaultAudioDeviceName } from '../settings.mjs';
|
||||||
import { getAudioDevices, setAudioDevice } from './util.mjs';
|
import { getAudioDevices, setAudioDevice } from './util.mjs';
|
||||||
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
|
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
|
||||||
|
import { clearHydra } from '@strudel/hydra';
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { settingsMap, useSettings } from '../settings.mjs';
|
import { settingsMap, useSettings } from '../settings.mjs';
|
||||||
import {
|
import {
|
||||||
@ -75,6 +76,11 @@ export function Repl({ embedded = false }) {
|
|||||||
onUpdateState: (state) => {
|
onUpdateState: (state) => {
|
||||||
setReplState({ ...state });
|
setReplState({ ...state });
|
||||||
},
|
},
|
||||||
|
onToggle: (playing) => {
|
||||||
|
if (!playing) {
|
||||||
|
clearHydra();
|
||||||
|
}
|
||||||
|
},
|
||||||
afterEval: (all) => {
|
afterEval: (all) => {
|
||||||
const { code } = all;
|
const { code } = all;
|
||||||
setLatestCode(code);
|
setLatestCode(code);
|
||||||
@ -165,6 +171,7 @@ export function Repl({ embedded = false }) {
|
|||||||
const resetEditor = async () => {
|
const resetEditor = async () => {
|
||||||
resetGlobalEffects();
|
resetGlobalEffects();
|
||||||
clearCanvas();
|
clearCanvas();
|
||||||
|
clearHydra();
|
||||||
resetLoadedSounds();
|
resetLoadedSounds();
|
||||||
editorRef.current.repl.setCps(0.5);
|
editorRef.current.repl.setCps(0.5);
|
||||||
await prebake(); // declare default samples
|
await prebake(); // declare default samples
|
||||||
@ -189,6 +196,7 @@ export function Repl({ embedded = false }) {
|
|||||||
setActivePattern(patternData.id);
|
setActivePattern(patternData.id);
|
||||||
setViewingPatternData(patternData);
|
setViewingPatternData(patternData);
|
||||||
clearCanvas();
|
clearCanvas();
|
||||||
|
clearHydra();
|
||||||
resetLoadedSounds();
|
resetLoadedSounds();
|
||||||
resetGlobalEffects();
|
resetGlobalEffects();
|
||||||
await prebake(); // declare default samples
|
await prebake(); // declare default samples
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user