strudel/packages/eval
Felix Roos 87162a9f31 Publish
- @strudel.cycles/core@0.1.0
 - @strudel.cycles/embed@0.1.0
 - @strudel.cycles/eval@0.1.0
 - @strudel.cycles/midi@0.1.0
 - @strudel.cycles/mini@0.1.0
 - @strudel.cycles/osc@0.1.0
 - @strudel.cycles/react@0.1.0
 - @strudel.cycles/serial@0.1.0
 - @strudel.cycles/tonal@0.1.0
 - @strudel.cycles/tone@0.1.0
 - @strudel.cycles/webaudio@0.1.0
 - @strudel.cycles/xen@0.1.0
2022-05-19 19:13:46 +02:00
..
shift-traverser redo headers 2022-04-28 14:38:41 +01:00
test add evalScope + deprecate extend 2022-05-17 00:31:20 +02:00
.gitignore rename repl + fix eval for spread op 2022-03-25 20:48:27 +01:00
evaluate.mjs fix tests 2022-05-18 00:18:12 +02:00
index.mjs unify barrel exports 2022-05-17 21:38:47 +02:00
package-lock.json Publish 2022-05-19 19:13:46 +02:00
package.json Publish 2022-05-19 19:13:46 +02:00
README.md hide todo 2022-05-18 00:21:11 +02:00
shapeshifter.mjs redo headers 2022-04-28 14:38:41 +01:00

@strudel.cycles/eval

This package contains the strudel code transformer and evaluator. It allows creating strudel patterns from input code that is optimized for minimal keystrokes and human readability.

Install

npm i @strudel.cycles/eval --save

Example

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:

(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

Dev Notes

shift-traverser is currently monkey patched because its package.json uses estraverse@^4.2.0, which does not support the spread operator (Error: Unknown node type SpreadProperty.). By monkey patched, I mean I copied the source of shift-traverser to a subfolder and installed the dependencies (shift-spec + estraverse@^5.3.0)