simplify querying

+ hopefully fix mini repl switching bug
This commit is contained in:
Felix Roos 2022-02-18 22:34:42 +01:00
parent d26467d0de
commit d58a706b9b

View File

@ -29,19 +29,15 @@ function useCycle(props: UseCycleProps) {
// query next cycle in the middle of the current // query next cycle in the middle of the current
const cancelFrom = timespan.begin.valueOf(); const cancelFrom = timespan.begin.valueOf();
Tone.Transport.cancel(cancelFrom); Tone.Transport.cancel(cancelFrom);
const queryNextTime = (cycle + 1) * cycleDuration - 0.1; // const queryNextTime = (cycle + 1) * cycleDuration - 0.1;
const delta = queryNextTime - Tone.Transport.seconds; const queryNextTime = (cycle + 1) * cycleDuration - 0.5;
if (delta < 0.2) {
// if calling Tone.Transport.schedule barely before the scheduled time, it sometimes happen that the event is swallowed // if queryNextTime would be before current time, execute directly (+0.1 for safety that it won't miss)
// i think this has something to do with the fact that Tone.Transport.schedule is called with a time that is slightly before the scheduled time const t = Math.max(Tone.Transport.seconds, queryNextTime) + 0.1;
// so, if the delta is too small (using 0.2 for no specific reason), just schedule directly Tone.Transport.schedule(() => {
// this if branch should only be entered if the user triggers the scheduling, to make sure no endless recursion is happening
query(cycle + 1); query(cycle + 1);
} else { }, t);
Tone.Transport.schedule(() => {
query(cycle + 1);
}, queryNextTime);
}
// schedule events for next cycle // schedule events for next cycle
events events
?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf()) ?.filter((event) => event.part.begin.valueOf() === event.whole.begin.valueOf())