mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 13:48:40 +00:00
Merge pull request #983 from tidalcycles/clear-hydra
fix: clear hydra on reset
This commit is contained in:
commit
5ebaa3e1ce
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user