mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-23 19:48:31 +00:00
more options for zyklus api:
+ allow setting custom interval functions + allow disabling phase rounding
This commit is contained in:
parent
10bd668033
commit
dc977b292d
@ -7,6 +7,9 @@ function createClock(
|
|||||||
duration = 0.05, // duration of each cycle
|
duration = 0.05, // duration of each cycle
|
||||||
interval = 0.1, // interval between callbacks
|
interval = 0.1, // interval between callbacks
|
||||||
overlap = 0.1, // overlap between callbacks
|
overlap = 0.1, // overlap between callbacks
|
||||||
|
setInterval = globalThis.setInterval,
|
||||||
|
clearInterval = globalThis.clearInterval,
|
||||||
|
round = true,
|
||||||
) {
|
) {
|
||||||
let tick = 0; // counts callbacks
|
let tick = 0; // counts callbacks
|
||||||
let phase = 0; // next callback time
|
let phase = 0; // next callback time
|
||||||
@ -22,7 +25,7 @@ function createClock(
|
|||||||
}
|
}
|
||||||
// callback as long as we're inside the lookahead
|
// callback as long as we're inside the lookahead
|
||||||
while (phase < lookahead) {
|
while (phase < lookahead) {
|
||||||
phase = Math.round(phase * precision) / precision;
|
phase = round ? Math.round(phase * precision) / precision : phase;
|
||||||
phase >= t && callback(phase, duration, tick, t);
|
phase >= t && callback(phase, duration, tick, t);
|
||||||
phase < t && console.log('TOO LATE', phase); // what if latency is added from outside?
|
phase < t && console.log('TOO LATE', phase); // what if latency is added from outside?
|
||||||
phase += duration; // increment phase by duration
|
phase += duration; // increment phase by duration
|
||||||
@ -35,7 +38,10 @@ function createClock(
|
|||||||
onTick();
|
onTick();
|
||||||
intervalID = setInterval(onTick, interval * 1000);
|
intervalID = setInterval(onTick, interval * 1000);
|
||||||
};
|
};
|
||||||
const clear = () => intervalID !== undefined && clearInterval(intervalID);
|
const clear = () => {
|
||||||
|
intervalID !== undefined && clearInterval(intervalID);
|
||||||
|
intervalID = undefined;
|
||||||
|
};
|
||||||
const pause = () => clear();
|
const pause = () => clear();
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
tick = 0;
|
tick = 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user