diff --git a/repl/src/App.tsx b/repl/src/App.tsx index 18d9e797..0ad4653e 100644 --- a/repl/src/App.tsx +++ b/repl/src/App.tsx @@ -5,9 +5,11 @@ import cx from './cx'; import * as Tone from 'tone'; import useCycle from './useCycle'; import type { Hap, Pattern } from './types'; -import { tetris } from './tunes'; +import * as tunes from './tunes'; import _mini from './mini'; +const { tetris, tetrisMini } = tunes; + const { sequence, pure, reify, slowcat, fastcat, cat, stack, silence } = strudel; // make available to eval const mini = _mini; // for eval (direct import wont work somehow) const parse = (code: string): Pattern => eval(code); @@ -21,7 +23,7 @@ synth.set({ }); function App() { - const [code, setCode] = useState(tetris); + const [code, setCode] = useState(tetrisMini); const [log, setLog] = useState(''); const logBox = useRef(); const [error, setError] = useState(); diff --git a/repl/src/mini.ts b/repl/src/mini.ts index 1dbeacd6..40e31b8a 100644 --- a/repl/src/mini.ts +++ b/repl/src/mini.ts @@ -1,11 +1,14 @@ import * as krill from '../krill-parser'; import * as strudel from '../../strudel.mjs'; -const { sequence, silence } = strudel; +const { sequence, stack, silence } = strudel; export function patternifyAST(ast: any): any { switch (ast.type_) { case 'pattern': + if (ast.arguments_.alignment === 'v') { + return stack(...ast.source_.map(patternifyAST)); + } return sequence(...ast.source_.map(patternifyAST)); case 'element': if (ast.source_ === '~') { @@ -16,11 +19,20 @@ export function patternifyAST(ast: any): any { } return patternifyAST(ast.source_); } + // *3 => options_.operator.arguments_.amount = 1/3 } /* export default (str: string) => patternifyAST(krill.parse(`"${str}"`)); */ export default (...strings: string[]) => { - return sequence(...strings.map((str) => patternifyAST(krill.parse(`"${str}"`)))); + const pattern = sequence( + ...strings.map((str) => { + const ast = krill.parse(`"${str}"`); + // console.log('ast', ast); + return patternifyAST(ast); + }) + ); + // console.log('mini pattern', pattern); + return pattern; }; /* diff --git a/repl/src/tunes.ts b/repl/src/tunes.ts index f2b75380..5685d190 100644 --- a/repl/src/tunes.ts +++ b/repl/src/tunes.ts @@ -46,6 +46,8 @@ export const tetris = `stack( ) )._slow(16);`; +export const tetrisMini = `mini('[[e5 [b4 c5] d5 [c5 b4]] [a4 [a4 c5] e5 [d5 c5]] [b4 [~ c5] d5 e5] [c5 a4 a4 ~] [[~ d5] [~ f5] a5 [g5 f5]] [e5 [~ c5] e5 [d5 c5]] [b4 [b4 c5] d5 e5] [c5 a4 a4 ~]],[[e2 e3 e2 e3 e2 e3 e2 e3] [a2 a3 a2 a3 a2 a3 a2 a3] [g#2 g#3 g#2 g#3 e2 e3 e2 e3] [a2 a3 a2 a3 a2 a3 b1 c2] [d2 d3 d2 d3 d2 d3 d2 d3] [c2 c3 c2 c3 c2 c3 c2 c3] [b1 b2 b1 b2 e2 e3 e2 e3] [a1 a2 a1 a2 a1 a2 a1 a2]]')._slow(16);`; + // "sequence('c3', 'eb3', sequence('g3', 'f3'))" // /* `sequence( stack('c4','eb4','g4'),