mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-19 17:48:33 +00:00
timecat mini notation
This commit is contained in:
parent
fabfee5976
commit
8fa9fda9b4
@ -31,6 +31,13 @@ function reify(thing: any) {
|
|||||||
return pure(thing);
|
return pure(thing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function minify(thing: any) {
|
||||||
|
if (typeof thing === 'string') {
|
||||||
|
return mini(thing);
|
||||||
|
}
|
||||||
|
return reify(thing);
|
||||||
|
}
|
||||||
|
|
||||||
const applyOptions = (parent: any) => (pat: any, i: number) => {
|
const applyOptions = (parent: any) => (pat: any, i: number) => {
|
||||||
const ast = parent.source_[i];
|
const ast = parent.source_[i];
|
||||||
const options = ast.options_;
|
const options = ast.options_;
|
||||||
@ -44,7 +51,10 @@ const applyOptions = (parent: any) => (pat: any, i: number) => {
|
|||||||
}
|
}
|
||||||
console.warn(`operator "${operator.type_}" not implemented`);
|
console.warn(`operator "${operator.type_}" not implemented`);
|
||||||
}
|
}
|
||||||
// TODO: options.weight = "@"
|
if (options?.weight) {
|
||||||
|
// weight is handled by parent
|
||||||
|
return pat;
|
||||||
|
}
|
||||||
// TODO: bjorklund e.g. "c3(5,8)"
|
// TODO: bjorklund e.g. "c3(5,8)"
|
||||||
const unimplemented = Object.keys(options || {}).filter((key) => key !== 'operator');
|
const unimplemented = Object.keys(options || {}).filter((key) => key !== 'operator');
|
||||||
if (unimplemented.length) {
|
if (unimplemented.length) {
|
||||||
@ -62,6 +72,10 @@ export function patternifyAST(ast: any): any {
|
|||||||
if (ast.arguments_.alignment === 'v') {
|
if (ast.arguments_.alignment === 'v') {
|
||||||
return stack(...children);
|
return stack(...children);
|
||||||
}
|
}
|
||||||
|
const weightedChildren = ast.source_.some((child) => !!child.options_?.weight);
|
||||||
|
if (weightedChildren) {
|
||||||
|
return timeCat(...ast.source_.map((child, i) => [child.options_?.weight || 1, children[i]]));
|
||||||
|
}
|
||||||
return sequence(...children);
|
return sequence(...children);
|
||||||
case 'element':
|
case 'element':
|
||||||
if (ast.source_ === '~') {
|
if (ast.source_ === '~') {
|
||||||
@ -113,7 +127,13 @@ export const mini = (...strings: string[]) => {
|
|||||||
return pattern;
|
return pattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// shorthand for mini
|
||||||
const m = mini;
|
const m = mini;
|
||||||
|
// shorthand for stack, automatically minifying strings
|
||||||
|
const s = (...strings) => {
|
||||||
|
const patternified = strings.map((s) => minify(s));
|
||||||
|
return stack(...patternified);
|
||||||
|
};
|
||||||
|
|
||||||
// includes haskell style (raw krill parsing)
|
// includes haskell style (raw krill parsing)
|
||||||
export const h = (string: string) => {
|
export const h = (string: string) => {
|
||||||
|
|||||||
@ -1,3 +1,9 @@
|
|||||||
|
export const timeCatMini = `s(
|
||||||
|
'c3@3 [eb3, g3, [c4 d4]/2]',
|
||||||
|
'c2 g2',
|
||||||
|
m\`[eb4@5 [f4 eb4 d4]@3] [eb4 c4]/2\`.slow(8)
|
||||||
|
)`;
|
||||||
|
|
||||||
export const timeCat = `stack(
|
export const timeCat = `stack(
|
||||||
timeCat([3, c3], [1, stack(eb3, g3, m(c4, d4).slow(2))]),
|
timeCat([3, c3], [1, stack(eb3, g3, m(c4, d4).slow(2))]),
|
||||||
m(c2, g2),
|
m(c2, g2),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user