This commit is contained in:
Felix Roos 2022-02-27 12:08:23 +01:00
parent ef3ab6161f
commit 9442b5c66b
9 changed files with 107 additions and 90 deletions

View file

@ -6,7 +6,7 @@ import usePostMessage from "./usePostMessage.js";
let s4 = () => {
return Math.floor((1 + Math.random()) * 65536).toString(16).substring(1);
};
function useRepl({tune, defaultSynth, autolink = true, onEvent}) {
function useRepl({tune, defaultSynth, autolink = true, onEvent, onDraw}) {
const id = useMemo(() => s4(), []);
const [code, setCode] = useState(tune);
const [activeCode, setActiveCode] = useState();
@ -44,6 +44,7 @@ function useRepl({tune, defaultSynth, autolink = true, onEvent}) {
}
};
const cycle = useCycle({
onDraw,
onEvent: useCallback((time, event) => {
try {
onEvent?.(event);
@ -71,6 +72,7 @@ function useRepl({tune, defaultSynth, autolink = true, onEvent}) {
try {
return pattern?.query(span) || [];
} catch (err) {
console.warn(err);
err.message = "query error: " + err.message;
setError(err);
return [];