refactor scheduler constructor + add onEvent

This commit is contained in:
Felix Roos 2022-04-14 00:32:41 +02:00
parent 5629c0ee72
commit 325eec2c6f
2 changed files with 11 additions and 8 deletions

View File

@ -18,10 +18,13 @@ Loading...</textarea
const { cat, State, TimeSpan } = strudel;
Object.assign(window, strudel); // add strudel to eval scope
const audioContext = getAudioContext();
const interval = 0.1;
const lookahead = 0.5;
const scheduler = new Scheduler(audioContext, interval, lookahead);
const scheduler = new Scheduler({
audioContext: getAudioContext(),
interval: 0.1,
onEvent: (e) => {
e.context?.createAudioNode?.(e);
},
});
let initialCode = `sequence(1,2).mul(55/2) // frequencies
.mul(slowcat(1,2))

View File

@ -3,7 +3,7 @@ import ClockWorker from './clockworker.mjs';
class Scheduler {
worker;
pattern;
constructor(audioContext, interval = 0.2) {
constructor({ audioContext, interval = 0.2, onEvent }) {
this.worker = new ClockWorker(
audioContext,
(begin, end) => {
@ -11,10 +11,10 @@ class Scheduler {
if (!e.part.begin.equals(e.whole.begin)) {
return;
}
if (e.context.createAudioNode) {
e.context.createAudioNode(e);
if (onEvent) {
onEvent?.(e);
} else {
console.warn('unplayable event: no audio node');
console.warn('unplayable event: no audio node nor onEvent callback', e);
}
});
},