MiniRepl: add punchcard flag for implicit vis

+ reintroduce editPattern
+ add punchcards to mini-notation.mdx
This commit is contained in:
Felix Roos 2023-01-13 15:13:39 +01:00
parent e4f538b674
commit b2c6d87633
10 changed files with 323 additions and 310 deletions

View file

@ -13,7 +13,8 @@ import { logger } from '@strudel.cycles/core';
const getTime = () => getAudioContext().currentTime;
export function MiniRepl({ tune, hideOutsideView = false, enableKeyboard, drawTime, canvasHeight = 200 }) {
export function MiniRepl({ tune, hideOutsideView = false, enableKeyboard, drawTime, punchcard, canvasHeight = 200 }) {
drawTime = drawTime || (punchcard ? [0, 4] : undefined);
const {
code,
setCode,
@ -32,6 +33,7 @@ export function MiniRepl({ tune, hideOutsideView = false, enableKeyboard, drawTi
} = useStrudel({
initialCode: tune,
defaultOutput: webaudioOutput,
editPattern: (pat) => (punchcard ? pat.punchcard() : pat),
getTime,
evalOnMount: !!drawTime,
drawContext: !!drawTime ? (canvasId) => document.querySelector('#' + canvasId)?.getContext('2d') : null,

View file

@ -10,7 +10,7 @@ function usePatternFrame({ pattern, started, getTime, onDraw, drawTime = [-2, 2]
useEffect(() => {
if (pattern) {
const t = getTime();
const futureHaps = pattern.queryArc(t, t + lookahead);
const futureHaps = pattern.queryArc(t, t + lookahead + 0.1); // +0.1 = workaround for weird holes in query..
visibleHaps.current = visibleHaps.current.filter((h) => h.whole.begin < t);
visibleHaps.current = visibleHaps.current.concat(futureHaps);
}

View file

@ -12,6 +12,7 @@ function useStrudel({
initialCode = '',
autolink = false,
beforeEval,
editPattern,
afterEval,
onEvalError,
onToggle,
@ -44,6 +45,7 @@ function useStrudel({
getTime,
drawContext,
transpiler,
editPattern,
beforeEval: ({ code }) => {
setCode(code);
beforeEval?.();