start packaging
This commit is contained in:
parent
a19d789145
commit
6f60a3a1d5
98 changed files with 11162 additions and 11122 deletions
56
packages/eval/evaluate.mjs
Normal file
56
packages/eval/evaluate.mjs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import * as strudel from '../core/strudel.mjs';
|
||||
import '../tone/tone.mjs';
|
||||
import '../midi/midi.mjs';
|
||||
import '../tonal/voicings.mjs';
|
||||
import '../../packages/tonal/tonal.mjs';
|
||||
import '../../packages/xen/xen.mjs';
|
||||
import '../../packages/xen/tune.mjs';
|
||||
import '../core/euclid.mjs';
|
||||
import euclid from '../core/euclid.mjs';
|
||||
import '../repl-react/pianoroll.mjs';
|
||||
import '../repl-react/draw.mjs';
|
||||
import * as uiHelpers from '../repl-react/ui.mjs';
|
||||
import * as drawHelpers from '../repl-react/draw.mjs';
|
||||
import gist from '../core/gist.js';
|
||||
import shapeshifter from './shapeshifter.mjs';
|
||||
import { mini } from '../mini/mini.mjs';
|
||||
import * as Tone from 'tone';
|
||||
import * as toneHelpers from '../tone/tone.mjs';
|
||||
import * as voicingHelpers from '../tonal/voicings.mjs';
|
||||
|
||||
// this will add all methods from definedMethod to strudel + connect all the partial application stuff
|
||||
const bootstrapped = { ...strudel, ...strudel.Pattern.prototype.bootstrap() };
|
||||
// console.log('bootstrapped',bootstrapped.transpose(2).transpose);
|
||||
|
||||
function hackLiteral(literal, names, func) {
|
||||
names.forEach((name) => {
|
||||
Object.defineProperty(literal.prototype, name, {
|
||||
get: function () {
|
||||
return func(String(this));
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// with this, you can do 'c2 [eb2 g2]'.mini.fast(2) or 'c2 [eb2 g2]'.m.fast(2),
|
||||
hackLiteral(String, ['mini', 'm'], bootstrapped.mini); // comment out this line if you panic
|
||||
hackLiteral(String, ['pure', 'p'], bootstrapped.pure); // comment out this line if you panic
|
||||
|
||||
// this will add everything to global scope, which is accessed by eval
|
||||
Object.assign(globalThis, Tone, bootstrapped, toneHelpers, voicingHelpers, drawHelpers, uiHelpers, {
|
||||
gist,
|
||||
euclid,
|
||||
mini,
|
||||
});
|
||||
|
||||
export const evaluate = async (code) => {
|
||||
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
||||
drawHelpers.cleanup();
|
||||
uiHelpers.cleanup();
|
||||
let evaluated = await eval(shapeshifted);
|
||||
if (evaluated?.constructor?.name !== 'Pattern') {
|
||||
const message = `got "${typeof evaluated}" instead of pattern`;
|
||||
throw new Error(message + (typeof evaluated === 'function' ? ', did you forget to call a function?' : '.'));
|
||||
}
|
||||
return { mode: 'javascript', pattern: evaluated };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue