fix: highlighting sync

This commit is contained in:
Felix Roos 2022-11-10 17:15:10 +01:00
parent c7c90b0647
commit 372bdf8be7
10 changed files with 347 additions and 335 deletions

View file

@ -49,7 +49,7 @@ export function MiniRepl({ tune, hideOutsideView = false, init, enableKeyboard }
view,
pattern,
active: started && !activeCode?.includes('strudel disable-highlighting'),
getTime: () => scheduler.phase,
getTime: () => scheduler.getPhase(),
});
// set active pattern on ctrl+enter

View file

@ -14,9 +14,9 @@ function useHighlighting({ view, pattern, active, getTime }) {
const audioTime = getTime();
// force min framerate of 10 fps => fixes crash on tab refocus, where lastEnd could be far away
// see https://github.com/tidalcycles/strudel/issues/108
const begin = Math.max(lastEnd.current || audioTime, audioTime - 1 / 10);
const begin = Math.max(lastEnd.current || audioTime, audioTime - 1 / 10, 0); // negative time seems buggy
const span = [begin, audioTime + 1 / 60];
lastEnd.current = audioTime + 1 / 60;
lastEnd.current = span[1];
highlights.current = highlights.current.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
highlights.current = highlights.current.concat(haps); // add potential new onsets

View file

@ -48,7 +48,6 @@ function useStrudel({ defaultOutput, interval, getTime, evalOnMount = false, ini
const togglePlay = async () => {
if (started) {
scheduler.pause();
// scheduler.stop();
} else {
await activateCode();
}