mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
refactor scheduler constructor + add onEvent
This commit is contained in:
parent
5629c0ee72
commit
325eec2c6f
@ -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))
|
||||
|
||||
@ -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);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user