mini: support stack with ","

This commit is contained in:
Felix Roos 2022-02-06 14:19:15 +01:00
parent f56d40ac8d
commit 3919a21650
3 changed files with 20 additions and 4 deletions

View File

@ -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<string>(tetris);
const [code, setCode] = useState<string>(tetrisMini);
const [log, setLog] = useState('');
const logBox = useRef<any>();
const [error, setError] = useState<Error>();

View File

@ -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;
};
/*

View File

@ -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'),