add eval example
This commit is contained in:
parent
4142b113e9
commit
76822717f4
1 changed files with 27 additions and 0 deletions
|
|
@ -9,6 +9,33 @@ It allows creating strudel patterns from input code that is optimized for minima
|
||||||
npm i @strudel.cycles/eval --save
|
npm i @strudel.cycles/eval --save
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
import { evaluate, extend } from '@strudel.cycles/eval';
|
||||||
|
import * as strudel from '@strudel.cycles/core';
|
||||||
|
|
||||||
|
extend(strudel); // add strudel to eval scope
|
||||||
|
|
||||||
|
async function run(code) {
|
||||||
|
const { pattern } = await evaluate(code);
|
||||||
|
const events = pattern.firstCycle();
|
||||||
|
console.log(events.map((e) => e.show()).join('\n'));
|
||||||
|
}
|
||||||
|
|
||||||
|
run('sequence([a3, [b3, c4]])');
|
||||||
|
```
|
||||||
|
|
||||||
|
yields:
|
||||||
|
|
||||||
|
```js
|
||||||
|
(0/1 -> 1/2, 0/1 -> 1/2, a3)
|
||||||
|
(1/2 -> 3/4, 1/2 -> 3/4, b3)
|
||||||
|
(3/4 -> 1/1, 3/4 -> 1/1, c4)
|
||||||
|
```
|
||||||
|
|
||||||
|
[play with @strudel.cycles/eval on codesandbox](https://codesandbox.io/s/strudel-eval-example-ndz1d8?file=/src/index.js)
|
||||||
|
|
||||||
## Dev Notes
|
## Dev Notes
|
||||||
|
|
||||||
shift-traverser is currently monkey patched because its package.json uses estraverse@^4.2.0,
|
shift-traverser is currently monkey patched because its package.json uses estraverse@^4.2.0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue