tetris in mini notation

This commit is contained in:
Felix Roos 2022-02-06 13:01:18 +01:00
parent 4437f7c89e
commit 06ebcfff89
2 changed files with 39 additions and 3 deletions

View File

@ -1,18 +1,27 @@
import * as krill from '../krill-parser';
import * as strudel from '../../strudel.mjs';
const { sequence, silence } = strudel;
export function patternifyAST(ast: any): any {
switch (ast.type_) {
case 'pattern':
return strudel.sequence(...ast.source_.map(patternifyAST));
return sequence(...ast.source_.map(patternifyAST));
case 'element':
if (ast.source_ === '~') {
return silence;
}
if (typeof ast.source_ !== 'object') {
return ast.source_;
}
return patternifyAST(ast.source_);
}
}
export default (str: string) => patternifyAST(krill.parse(`"${str}"`));
/* export default (str: string) => patternifyAST(krill.parse(`"${str}"`)); */
export default (...strings: string[]) => {
return sequence(...strings.map((str) => patternifyAST(krill.parse(`"${str}"`))));
};
/*
TODO:

View File

@ -1,4 +1,4 @@
export const tetris = `stack(sequence(
export const tetrisWithFunctions = `stack(sequence(
'e5', sequence('b4', 'c5'), 'd5', sequence('c5', 'b4'),
'a4', sequence('a4', 'c5'), 'e5', sequence('d5', 'c5'),
'b4', sequence(silence, 'c5'), 'd5', 'e5',
@ -19,6 +19,33 @@ export const tetris = `stack(sequence(
)
)._slow(16)`;
export const tetris = `stack(
sequence(
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 ~'
)
),
sequence(
mini(
'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'),