encapsulate cyclist

This commit is contained in:
Felix Roos
2023-10-02 20:56:45 +02:00
parent f089037f18
commit 25be8fca0d
3 changed files with 7 additions and 3 deletions
+2 -2
View File
@@ -5,7 +5,6 @@ import { setTime } from './time.mjs';
import { evalScope } from './evaluate.mjs';
import { register } from './pattern.mjs';
import { isTauri } from '../../website/src/tauri.mjs';
import { CyclistBridge } from '../desktopbridge/cyclistbridge.mjs';
export function repl({
interval,
@@ -18,6 +17,7 @@ export function repl({
transpiler,
onToggle,
editPattern,
createCyclist,
}) {
//TODO: could maybe be enabled with a command or a switch in settings?
const abelinkEnabled = isTauri();
@@ -28,7 +28,7 @@ export function repl({
getTime,
onToggle,
};
const scheduler = abelinkEnabled ? new CyclistBridge(cyclistParams) : new Cyclist(cyclistParams);
const scheduler = createCyclist?.(cyclistParams) || new Cyclist(p);
const setPattern = (pattern, autostart = true) => {
pattern = editPattern?.(pattern) || pattern;
+2
View File
@@ -19,6 +19,7 @@ function useStrudel({
drawContext,
drawTime = [-2, 2],
paintOptions = {},
createCyclist, // (params) => Cyclist
}) {
const id = useMemo(() => s4(), []);
canvasId = canvasId || `canvas-${id}`;
@@ -45,6 +46,7 @@ function useStrudel({
onEvalError?.(err);
},
getTime,
createCyclist,
drawContext,
transpiler,
editPattern,
+3 -1
View File
@@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { cleanupDraw, cleanupUi, controls, evalScope, getDrawContext, logger } from '@strudel.cycles/core';
import { cleanupDraw, cleanupUi, controls, evalScope, getDrawContext, logger, Cyclist } from '@strudel.cycles/core';
import { CodeMirror, cx, flash, useHighlighting, useStrudel, useKeydown } from '@strudel.cycles/react';
import { getAudioContext, initAudioOnFirstClick, resetLoadedSounds, webaudioOutput } from '@strudel.cycles/webaudio';
import { createClient } from '@supabase/supabase-js';
@@ -23,6 +23,7 @@ import { settingPatterns } from '../settings.mjs';
import { code2hash, hash2code } from './helpers.mjs';
import { isTauri } from '../tauri.mjs';
import { useWidgets } from '@strudel.cycles/react/src/hooks/useWidgets.mjs';
import { CyclistBridge } from '@strudel/desktopbridge/cyclistbridge.mjs';
const { latestCode } = settingsMap.get();
@@ -164,6 +165,7 @@ export function Repl({ embedded = false }) {
drawContext,
// drawTime: [0, 6],
paintOptions,
createCyclist: (p) => (isTauri() ? new CyclistBridge(p) : new Cyclist(p)),
});
// init code