remove old defaultSynth
This commit is contained in:
parent
699c8d5b60
commit
60616a5228
8 changed files with 17 additions and 44 deletions
4
packages/react/dist/index.cjs.js
vendored
4
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
7
packages/react/dist/index.es.js
vendored
7
packages/react/dist/index.es.js
vendored
|
|
@ -251,7 +251,7 @@ let s4 = () => {
|
||||||
};
|
};
|
||||||
const generateHash = (code) => encodeURIComponent(btoa(code));
|
const generateHash = (code) => encodeURIComponent(btoa(code));
|
||||||
|
|
||||||
function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawProp }) {
|
function useRepl({ tune, autolink = true, onEvent, onDraw: onDrawProp }) {
|
||||||
const id = useMemo(() => s4(), []);
|
const id = useMemo(() => s4(), []);
|
||||||
const [code, setCode] = useState(tune);
|
const [code, setCode] = useState(tune);
|
||||||
const [activeCode, setActiveCode] = useState();
|
const [activeCode, setActiveCode] = useState();
|
||||||
|
|
@ -290,7 +290,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
|
||||||
pushLog(err.message); // not with setError, because then we would have to setError(undefined) on next playable event
|
pushLog(err.message); // not with setError, because then we would have to setError(undefined) on next playable event
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onEvent, pushLog, defaultSynth],
|
[onEvent, pushLog],
|
||||||
),
|
),
|
||||||
onQuery: useCallback(
|
onQuery: useCallback(
|
||||||
(state) => {
|
(state) => {
|
||||||
|
|
@ -473,10 +473,9 @@ function Icon({ type }) {
|
||||||
}[type]);
|
}[type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function MiniRepl({ tune, defaultSynth, hideOutsideView = false, theme, init, onEvent, enableKeyboard }) {
|
function MiniRepl({ tune, hideOutsideView = false, init, onEvent, enableKeyboard }) {
|
||||||
const { code, setCode, pattern, activeCode, activateCode, evaluateOnly, error, cycle, dirty, togglePlay, stop } = useRepl({
|
const { code, setCode, pattern, activeCode, activateCode, evaluateOnly, error, cycle, dirty, togglePlay, stop } = useRepl({
|
||||||
tune,
|
tune,
|
||||||
defaultSynth,
|
|
||||||
autolink: false,
|
autolink: false,
|
||||||
onEvent
|
onEvent
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,9 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MiniRepl } from './components/MiniRepl';
|
import { MiniRepl } from './components/MiniRepl';
|
||||||
import 'tailwindcss/tailwind.css';
|
import 'tailwindcss/tailwind.css';
|
||||||
import { Tone, getDefaultSynth } from '@strudel.cycles/tone';
|
|
||||||
import { evalScope } from '@strudel.cycles/eval';
|
import { evalScope } from '@strudel.cycles/eval';
|
||||||
|
|
||||||
const defaultSynth = getDefaultSynth();
|
|
||||||
|
|
||||||
evalScope(
|
evalScope(
|
||||||
Tone,
|
|
||||||
import('@strudel.cycles/core'),
|
import('@strudel.cycles/core'),
|
||||||
import('@strudel.cycles/tone'),
|
import('@strudel.cycles/tone'),
|
||||||
import('@strudel.cycles/tonal'),
|
import('@strudel.cycles/tonal'),
|
||||||
|
|
@ -20,7 +16,7 @@ evalScope(
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<MiniRepl tune={`"c3"`} defaultSynth={defaultSynth} />
|
<MiniRepl tune={`"c3"`} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,10 @@ import './style.css';
|
||||||
import styles from './MiniRepl.module.css';
|
import styles from './MiniRepl.module.css';
|
||||||
import { Icon } from './Icon';
|
import { Icon } from './Icon';
|
||||||
|
|
||||||
export function MiniRepl({ tune, defaultSynth, hideOutsideView = false, theme, init, onEvent, enableKeyboard }) {
|
export function MiniRepl({ tune, hideOutsideView = false, init, onEvent, enableKeyboard }) {
|
||||||
const { code, setCode, pattern, activeCode, activateCode, evaluateOnly, error, cycle, dirty, togglePlay, stop } =
|
const { code, setCode, pattern, activeCode, activateCode, evaluateOnly, error, cycle, dirty, togglePlay, stop } =
|
||||||
useRepl({
|
useRepl({
|
||||||
tune,
|
tune,
|
||||||
defaultSynth,
|
|
||||||
autolink: false,
|
autolink: false,
|
||||||
onEvent,
|
onEvent,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ let s4 = () => {
|
||||||
};
|
};
|
||||||
const generateHash = (code) => encodeURIComponent(btoa(code));
|
const generateHash = (code) => encodeURIComponent(btoa(code));
|
||||||
|
|
||||||
function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawProp }) {
|
function useRepl({ tune, autolink = true, onEvent, onDraw: onDrawProp }) {
|
||||||
const id = useMemo(() => s4(), []);
|
const id = useMemo(() => s4(), []);
|
||||||
const [code, setCode] = useState(tune);
|
const [code, setCode] = useState(tune);
|
||||||
const [activeCode, setActiveCode] = useState();
|
const [activeCode, setActiveCode] = useState();
|
||||||
|
|
@ -56,7 +56,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
|
||||||
pushLog(err.message); // not with setError, because then we would have to setError(undefined) on next playable event
|
pushLog(err.message); // not with setError, because then we would have to setError(undefined) on next playable event
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[onEvent, pushLog, defaultSynth],
|
[onEvent, pushLog],
|
||||||
),
|
),
|
||||||
onQuery: useCallback(
|
onQuery: useCallback(
|
||||||
(state) => {
|
(state) => {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
import controls from '@strudel.cycles/core/controls.mjs';
|
import controls from '@strudel.cycles/core/controls.mjs';
|
||||||
import { evalScope, evaluate } from '@strudel.cycles/eval';
|
import { evalScope, evaluate } from '@strudel.cycles/eval';
|
||||||
import { CodeMirror, cx, flash, useHighlighting, useRepl, useWebMidi } from '@strudel.cycles/react';
|
import { CodeMirror, cx, flash, useHighlighting, useRepl, useWebMidi } from '@strudel.cycles/react';
|
||||||
import { getDefaultSynth, cleanupDraw, cleanupUi, Tone } from '@strudel.cycles/tone';
|
import { cleanupDraw, cleanupUi, Tone } from '@strudel.cycles/tone';
|
||||||
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import logo from './logo.svg';
|
import logo from './logo.svg';
|
||||||
|
|
@ -80,7 +80,6 @@ function getRandomTune() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const randomTune = getRandomTune();
|
const randomTune = getRandomTune();
|
||||||
const defaultSynth = getDefaultSynth();
|
|
||||||
const isEmbedded = window.location !== window.parent.location;
|
const isEmbedded = window.location !== window.parent.location;
|
||||||
function App() {
|
function App() {
|
||||||
// const [editor, setEditor] = useState();
|
// const [editor, setEditor] = useState();
|
||||||
|
|
@ -105,7 +104,6 @@ function App() {
|
||||||
hideConsole,
|
hideConsole,
|
||||||
} = useRepl({
|
} = useRepl({
|
||||||
tune: '// LOADING...',
|
tune: '// LOADING...',
|
||||||
defaultSynth,
|
|
||||||
});
|
});
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
initCode().then((decoded) => setCode(decoded || randomTune));
|
initCode().then((decoded) => setCode(decoded || randomTune));
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,8 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||||
|
|
||||||
import { Tone } from '@strudel.cycles/tone';
|
import { Tone } from '@strudel.cycles/tone';
|
||||||
import { State, TimeSpan } from '@strudel.cycles/core';
|
import { State, TimeSpan } from '@strudel.cycles/core';
|
||||||
import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs';
|
|
||||||
import { evaluate } from '@strudel.cycles/eval';
|
import { evaluate } from '@strudel.cycles/eval';
|
||||||
import { getDefaultSynth } from '@strudel.cycles/tone';
|
import { webaudioOutputTrigger } from '@strudel.cycles/webaudio';
|
||||||
|
|
||||||
const defaultSynth = getDefaultSynth();
|
|
||||||
|
|
||||||
// this is a test to play back events with as less runtime code as possible..
|
// this is a test to play back events with as less runtime code as possible..
|
||||||
// the code asks for the number of seconds to prequery
|
// the code asks for the number of seconds to prequery
|
||||||
|
|
@ -47,17 +44,8 @@ async function playStatic(code) {
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
Tone.getTransport().schedule((time) => {
|
Tone.getTransport().schedule((time) => {
|
||||||
try {
|
try {
|
||||||
const { onTrigger, velocity } = event.context;
|
const { onTrigger = webaudioOutputTrigger } = event.context;
|
||||||
if (!onTrigger) {
|
onTrigger(time, event);
|
||||||
if (defaultSynth) {
|
|
||||||
const note = getPlayableNoteValue(event);
|
|
||||||
defaultSynth.triggerAttackRelease(note, event.duration.valueOf(), time, velocity);
|
|
||||||
} else {
|
|
||||||
throw new Error('no defaultSynth passed to useRepl.');
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
onTrigger(time, event);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
err.message = 'unplayable event: ' + err?.message;
|
err.message = 'unplayable event: ' + err?.message;
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,14 @@
|
||||||
import { Tone } from '@strudel.cycles/tone';
|
|
||||||
import { evalScope } from '@strudel.cycles/eval';
|
import { evalScope } from '@strudel.cycles/eval';
|
||||||
import { MiniRepl as _MiniRepl } from '@strudel.cycles/react';
|
import { MiniRepl as _MiniRepl } from '@strudel.cycles/react';
|
||||||
import controls from '@strudel.cycles/core/controls.mjs';
|
import controls from '@strudel.cycles/core/controls.mjs';
|
||||||
import { samples } from '@strudel.cycles/webaudio';
|
import { samples } from '@strudel.cycles/webaudio';
|
||||||
|
import { prebake } from '../repl/src/prebake.mjs';
|
||||||
export const defaultSynth = new Tone.PolySynth().chain(new Tone.Gain(0.5), Tone.Destination).set({
|
|
||||||
oscillator: { type: 'triangle' },
|
|
||||||
envelope: {
|
|
||||||
release: 0.01,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
fetch('https://strudel.tidalcycles.org/EmuSP12.json')
|
fetch('https://strudel.tidalcycles.org/EmuSP12.json')
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((json) => samples(json, 'https://strudel.tidalcycles.org/EmuSP12/'));
|
.then((json) => samples(json, 'https://strudel.tidalcycles.org/EmuSP12/'));
|
||||||
|
|
||||||
|
|
||||||
evalScope(
|
evalScope(
|
||||||
Tone,
|
|
||||||
controls,
|
controls,
|
||||||
import('@strudel.cycles/core'),
|
import('@strudel.cycles/core'),
|
||||||
import('@strudel.cycles/tone'),
|
import('@strudel.cycles/tone'),
|
||||||
|
|
@ -29,6 +20,8 @@ evalScope(
|
||||||
import('@strudel.cycles/osc'),
|
import('@strudel.cycles/osc'),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
prebake();
|
||||||
|
|
||||||
export function MiniRepl({ tune }) {
|
export function MiniRepl({ tune }) {
|
||||||
return <_MiniRepl tune={tune} defaultSynth={defaultSynth} hideOutsideView={true} />;
|
return <_MiniRepl tune={tune} hideOutsideView={true} />;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue