mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 03:28:33 +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 { getDrawContext } from '@strudel/draw';
|
||||||
|
import { controls } from '@strudel/core';
|
||||||
|
|
||||||
let latestOptions;
|
let latestOptions;
|
||||||
|
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
|
||||||
@ -25,7 +27,7 @@ export async function initHydra(options = {}) {
|
|||||||
hydraConfig.canvas = canvas;
|
hydraConfig.canvas = canvas;
|
||||||
|
|
||||||
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';
|
||||||
@ -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;
|
export const H = (p) => () => p.queryArc(getTime(), getTime())[0].value;
|
||||||
|
|||||||
@ -18,6 +18,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 {
|
||||||
@ -76,6 +77,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);
|
||||||
@ -166,6 +172,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
|
||||||
@ -190,6 +197,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