-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathplay.js
37 lines (29 loc) · 983 Bytes
/
play.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { createMuse, compile, length } from "./createMuse.js";
function playSample(name, context, state) {
const audio = document.querySelector(`#${name}-audio`);
audio.volume = state.sampleVolume;
audio.currentTime = 0;
audio.play();
}
const createSamples = state => state.samples.reduce((acc, cur) => {
acc[cur.name] = (duration, ctx) => playSample(cur.name, ctx, state);
return acc;
}, {})
const bindKeys = state => obj => {
state.keyBindings = obj;
}
const makeIncluded = (state) => ({
// createMuse: createMuse(state),
compile,
length,
bindKeys: bindKeys(state),
createMuse: createMuse(createSamples(state))
});
export function play(state) {
const cm = document.querySelector("#cm");
const prog = cm.view.state.doc.toString();
window.localStorage.setItem("muse-samples", JSON.stringify(state.samples));
const included = makeIncluded(state);
const f = new Function(...Object.keys(included), prog)
const result = new f(...Object.values(included));
}