mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 04:28:30 +00:00
scheduler error callback
This commit is contained in:
parent
591855919e
commit
e77129fa51
@ -11,24 +11,29 @@ export class Scheduler {
|
|||||||
pattern;
|
pattern;
|
||||||
phase;
|
phase;
|
||||||
cps = 1;
|
cps = 1;
|
||||||
constructor({ interval = 0.1, onTrigger, latency = 0.1 }) {
|
constructor({ interval = 0.1, onTrigger, onError, latency = 0.1 }) {
|
||||||
this.worker = new ClockWorker((_, interval) => {
|
this.worker = new ClockWorker((_, interval) => {
|
||||||
const begin = this.phase;
|
try {
|
||||||
const end = this.phase + interval * this.cps;
|
const begin = this.phase;
|
||||||
this.phase = end;
|
const end = this.phase + interval * this.cps;
|
||||||
const haps = this.pattern.queryArc(begin, end);
|
this.phase = end;
|
||||||
haps.forEach((hap) => {
|
const haps = this.pattern.queryArc(begin, end);
|
||||||
if (typeof hap.value?.cps === 'number') {
|
haps.forEach((hap) => {
|
||||||
this.setCps(hap.value?.cps);
|
if (typeof hap.value?.cps === 'number') {
|
||||||
}
|
this.setCps(hap.value?.cps);
|
||||||
if (!hap.part.begin.equals(hap.whole.begin)) {
|
}
|
||||||
return;
|
if (!hap.part.begin.equals(hap.whole.begin)) {
|
||||||
}
|
return;
|
||||||
const deadline = (hap.whole.begin - begin) / this.cps + latency;
|
}
|
||||||
// TODO: use legato / duration of objectified value
|
const deadline = (hap.whole.begin - begin) / this.cps + latency;
|
||||||
const duration = hap.duration / this.cps;
|
// TODO: use legato / duration of objectified value
|
||||||
onTrigger?.(hap, deadline, duration);
|
const duration = hap.duration / this.cps;
|
||||||
});
|
onTrigger?.(hap, deadline, duration);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('scheduler error', err);
|
||||||
|
onError?.(err);
|
||||||
|
}
|
||||||
}, interval);
|
}, interval);
|
||||||
}
|
}
|
||||||
start() {
|
start() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user