mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 21:18:49 +00:00
mini: support stack with ","
This commit is contained in:
parent
f56d40ac8d
commit
3919a21650
@ -5,9 +5,11 @@ import cx from './cx';
|
|||||||
import * as Tone from 'tone';
|
import * as Tone from 'tone';
|
||||||
import useCycle from './useCycle';
|
import useCycle from './useCycle';
|
||||||
import type { Hap, Pattern } from './types';
|
import type { Hap, Pattern } from './types';
|
||||||
import { tetris } from './tunes';
|
import * as tunes from './tunes';
|
||||||
import _mini from './mini';
|
import _mini from './mini';
|
||||||
|
|
||||||
|
const { tetris, tetrisMini } = tunes;
|
||||||
|
|
||||||
const { sequence, pure, reify, slowcat, fastcat, cat, stack, silence } = strudel; // make available to eval
|
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 mini = _mini; // for eval (direct import wont work somehow)
|
||||||
const parse = (code: string): Pattern => eval(code);
|
const parse = (code: string): Pattern => eval(code);
|
||||||
@ -21,7 +23,7 @@ synth.set({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [code, setCode] = useState<string>(tetris);
|
const [code, setCode] = useState<string>(tetrisMini);
|
||||||
const [log, setLog] = useState('');
|
const [log, setLog] = useState('');
|
||||||
const logBox = useRef<any>();
|
const logBox = useRef<any>();
|
||||||
const [error, setError] = useState<Error>();
|
const [error, setError] = useState<Error>();
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import * as krill from '../krill-parser';
|
import * as krill from '../krill-parser';
|
||||||
import * as strudel from '../../strudel.mjs';
|
import * as strudel from '../../strudel.mjs';
|
||||||
|
|
||||||
const { sequence, silence } = strudel;
|
const { sequence, stack, silence } = strudel;
|
||||||
|
|
||||||
export function patternifyAST(ast: any): any {
|
export function patternifyAST(ast: any): any {
|
||||||
switch (ast.type_) {
|
switch (ast.type_) {
|
||||||
case 'pattern':
|
case 'pattern':
|
||||||
|
if (ast.arguments_.alignment === 'v') {
|
||||||
|
return stack(...ast.source_.map(patternifyAST));
|
||||||
|
}
|
||||||
return sequence(...ast.source_.map(patternifyAST));
|
return sequence(...ast.source_.map(patternifyAST));
|
||||||
case 'element':
|
case 'element':
|
||||||
if (ast.source_ === '~') {
|
if (ast.source_ === '~') {
|
||||||
@ -16,11 +19,20 @@ export function patternifyAST(ast: any): any {
|
|||||||
}
|
}
|
||||||
return patternifyAST(ast.source_);
|
return patternifyAST(ast.source_);
|
||||||
}
|
}
|
||||||
|
// *3 => options_.operator.arguments_.amount = 1/3
|
||||||
}
|
}
|
||||||
/* export default (str: string) => patternifyAST(krill.parse(`"${str}"`)); */
|
/* export default (str: string) => patternifyAST(krill.parse(`"${str}"`)); */
|
||||||
|
|
||||||
export default (...strings: string[]) => {
|
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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -46,6 +46,8 @@ export const tetris = `stack(
|
|||||||
)
|
)
|
||||||
)._slow(16);`;
|
)._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('c3', 'eb3', sequence('g3', 'f3'))" //
|
||||||
/* `sequence(
|
/* `sequence(
|
||||||
stack('c4','eb4','g4'),
|
stack('c4','eb4','g4'),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user