add poc for krill parsing

This commit is contained in:
Felix Roos 2022-02-06 12:41:20 +01:00
parent 74355e86da
commit 2062e4233e
6 changed files with 2202 additions and 9 deletions

View file

@ -6,15 +6,11 @@ import * as Tone from 'tone';
import useCycle from './useCycle';
import type { Hap, Pattern } from './types';
import { tetris } from './tunes';
import _mini from './mini';
const { Fraction, TimeSpan } = strudel;
const fr = (v: number) => new Fraction(v);
const ts = (start: number, end: number) => new TimeSpan(fr(start), fr(end));
const parse = (code: string): Pattern => {
const { sequence, pure, reify, slowcat, fastcat, cat, stack, silence } = strudel; // make available to eval
return eval(code);
};
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);
const synth = new Tone.PolySynth().toDestination();
synth.set({

34
repl/src/mini.ts Normal file
View file

@ -0,0 +1,34 @@
import * as krill from '../krill-parser';
import * as strudel from '../../strudel.mjs';
export function patternifyAST(ast: any): any {
switch (ast.type_) {
case 'pattern':
return strudel.sequence(...ast.source_.map(patternifyAST));
case 'element':
if (typeof ast.source_ !== 'object') {
return ast.source_;
}
return patternifyAST(ast.source_);
}
}
export default (str: string) => patternifyAST(krill.parse(`"${str}"`));
/*
TODO:
export interface Arguments {
alignment: string;
}
export interface ElementStub {
type_: string;
source_: string;
options_?: any;
}
export interface PatternStub {
type_: string; // pattern
arguments_: Arguments;
source_: ElementStub[];
}
*/