build
This commit is contained in:
parent
88bcfc5e48
commit
c263eac7fd
10 changed files with 93 additions and 15 deletions
15
docs/dist/App.js
vendored
15
docs/dist/App.js
vendored
|
|
@ -1,10 +1,11 @@
|
|||
import React, {useCallback, useLayoutEffect, useRef, useState} from "../_snowpack/pkg/react.js";
|
||||
import * as Tone from "../_snowpack/pkg/tone.js";
|
||||
import CodeMirror, {markEvent, markParens} from "./CodeMirror.js";
|
||||
import cx from "./cx.js";
|
||||
import {evaluate} from "./evaluate.js";
|
||||
import logo from "./logo.svg.proxy.js";
|
||||
import {useWebMidi} from "./midi.js";
|
||||
import playStatic from "./static.js";
|
||||
import {defaultSynth} from "./tone.js";
|
||||
import * as tunes from "./tunes.js";
|
||||
import useRepl from "./useRepl.js";
|
||||
const [_, codeParam] = window.location.href.split("#");
|
||||
|
|
@ -14,13 +15,6 @@ try {
|
|||
} catch (err) {
|
||||
console.warn("failed to decode", err);
|
||||
}
|
||||
const defaultSynth = new Tone.PolySynth().chain(new Tone.Gain(0.5), Tone.getDestination());
|
||||
defaultSynth.set({
|
||||
oscillator: {type: "triangle"},
|
||||
envelope: {
|
||||
release: 0.01
|
||||
}
|
||||
});
|
||||
function getRandomTune() {
|
||||
const allTunes = Object.values(tunes);
|
||||
const randomItem = (arr) => arr[Math.floor(Math.random() * arr.length)];
|
||||
|
|
@ -145,6 +139,9 @@ function App() {
|
|||
readOnly: true,
|
||||
ref: logBox,
|
||||
style: {fontFamily: "monospace"}
|
||||
})));
|
||||
})), /* @__PURE__ */ React.createElement("button", {
|
||||
className: "fixed right-4 bottom-2 z-[11]",
|
||||
onClick: () => playStatic(code)
|
||||
}, "static"));
|
||||
}
|
||||
export default App;
|
||||
|
|
|
|||
48
docs/dist/static.js
vendored
Normal file
48
docs/dist/static.js
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
import * as Tone from "../_snowpack/pkg/tone.js";
|
||||
import {State, TimeSpan} from "../_snowpack/link/strudel.js";
|
||||
import {getPlayableNoteValue} from "../_snowpack/link/util.js";
|
||||
import {evaluate} from "./evaluate.js";
|
||||
async function playStatic(code) {
|
||||
let start, took;
|
||||
const seconds = Number(prompt("How many seconds to run?")) || 60;
|
||||
start = performance.now();
|
||||
const {pattern: pat} = await evaluate(code);
|
||||
took = performance.now() - start;
|
||||
console.log("evaluate took", took, "ms");
|
||||
Tone.getTransport().stop();
|
||||
start = performance.now();
|
||||
const events = pat?.query(new State(new TimeSpan(0, seconds)))?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf())?.map((event) => ({
|
||||
time: event.whole.begin.valueOf(),
|
||||
duration: event.whole.end.sub(event.whole.begin).valueOf(),
|
||||
value: event.value,
|
||||
context: event.context
|
||||
}));
|
||||
took = performance.now() - start;
|
||||
console.log("query took", took, "ms");
|
||||
start = performance.now();
|
||||
events.forEach((event) => {
|
||||
Tone.getTransport().schedule((time) => {
|
||||
try {
|
||||
const {onTrigger, velocity} = event.context;
|
||||
if (!onTrigger) {
|
||||
if (defaultSynth) {
|
||||
const note = getPlayableNoteValue(event);
|
||||
defaultSynth.triggerAttackRelease(note, event.duration, time, velocity);
|
||||
} else {
|
||||
throw new Error("no defaultSynth passed to useRepl.");
|
||||
}
|
||||
} else {
|
||||
onTrigger(time, event);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
err.message = "unplayable event: " + err?.message;
|
||||
pushLog(err.message);
|
||||
}
|
||||
}, event.time);
|
||||
});
|
||||
took = performance.now() - start;
|
||||
console.log("schedule took", took, "ms");
|
||||
Tone.getTransport().start("+0.5");
|
||||
}
|
||||
export default playStatic;
|
||||
7
docs/dist/tone.js
vendored
7
docs/dist/tone.js
vendored
|
|
@ -20,6 +20,13 @@ import {
|
|||
} from "../_snowpack/pkg/tone.js";
|
||||
import {Piano} from "../_snowpack/pkg/@tonejs/piano.js";
|
||||
import {getPlayableNoteValue} from "../_snowpack/link/util.js";
|
||||
export const defaultSynth = new PolySynth().chain(new Gain(0.5), getDestination());
|
||||
defaultSynth.set({
|
||||
oscillator: {type: "triangle"},
|
||||
envelope: {
|
||||
release: 0.01
|
||||
}
|
||||
});
|
||||
const Pattern = _Pattern;
|
||||
Pattern.prototype.tone = function(instrument) {
|
||||
return this._withEvent((event) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue