Merge pull request #983 from tidalcycles/clear-hydra

fix: clear hydra on reset
This commit is contained in:
Felix Roos 2024-03-10 00:42:50 +01:00 committed by GitHub
commit 5ebaa3e1ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,8 @@
import { getDrawContext } from '@strudel/draw';
import { controls } from '@strudel/core';
let latestOptions;
let hydra;
export async function initHydra(options = {}) {
// reset if options have changed since last init
@ -25,7 +27,7 @@ export async function initHydra(options = {}) {
hydraConfig.canvas = canvas;
await import(/* @vite-ignore */ src);
const hydra = new Hydra(hydraConfig);
hydra = new Hydra(hydraConfig);
if (feedStrudel) {
const { canvas } = getDrawContext();
canvas.style.display = 'none';
@ -34,4 +36,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;

View File

@ -18,6 +18,7 @@ import {
import { defaultAudioDeviceName } from '../settings.mjs';
import { getAudioDevices, setAudioDevice } from './util.mjs';
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
import { clearHydra } from '@strudel/hydra';
import { useCallback, useEffect, useRef, useState } from 'react';
import { settingsMap, useSettings } from '../settings.mjs';
import {
@ -76,6 +77,11 @@ export function Repl({ embedded = false }) {
onUpdateState: (state) => {
setReplState({ ...state });
},
onToggle: (playing) => {
if (!playing) {
clearHydra();
}
},
afterEval: (all) => {
const { code } = all;
setLatestCode(code);
@ -166,6 +172,7 @@ export function Repl({ embedded = false }) {
const resetEditor = async () => {
resetGlobalEffects();
clearCanvas();
clearHydra();
resetLoadedSounds();
editorRef.current.repl.setCps(0.5);
await prebake(); // declare default samples
@ -190,6 +197,7 @@ export function Repl({ embedded = false }) {
setActivePattern(patternData.id);
setViewingPatternData(patternData);
clearCanvas();
clearHydra();
resetLoadedSounds();
resetGlobalEffects();
await prebake(); // declare default samples