mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 12:08:28 +00:00
Merge pull request #134 from tidalcycles/scheduler-improvements
Scheduler improvements
This commit is contained in:
commit
f2f3511a2f
@ -10,18 +10,20 @@ import { State, TimeSpan } from '@strudel.cycles/core';
|
|||||||
export class Scheduler {
|
export class Scheduler {
|
||||||
worker;
|
worker;
|
||||||
pattern;
|
pattern;
|
||||||
constructor({ audioContext, interval = 0.2, onEvent }) {
|
constructor({ audioContext, interval = 0.2, onEvent, latency = 0.2 }) {
|
||||||
this.worker = new ClockWorker(
|
this.worker = new ClockWorker(
|
||||||
audioContext,
|
audioContext,
|
||||||
(begin, end) => {
|
(begin, end) => {
|
||||||
this.pattern.query(new State(new TimeSpan(begin, end))).forEach((e) => {
|
this.pattern.query(new State(new TimeSpan(begin + latency, end + latency))).forEach((e) => {
|
||||||
if (!e.part.begin.equals(e.whole.begin)) {
|
if (!e.part.begin.equals(e.whole.begin)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (e.context.onTrigger) {
|
||||||
|
// TODO: kill first param, as it's contained in e
|
||||||
|
e.context.onTrigger(e.whole.begin, e, audioContext.currentTime, 1 /* cps */);
|
||||||
|
}
|
||||||
if (onEvent) {
|
if (onEvent) {
|
||||||
onEvent?.(e);
|
onEvent?.(e);
|
||||||
} else {
|
|
||||||
console.warn('unplayable event: no audio node nor onEvent callback', e);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user