From 29fceff9b334e63ae86b1e6339c4f21673f99fdf Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 1 May 2022 14:13:20 +0200 Subject: [PATCH] handle edge case --- repl/src/CodeMirror6.jsx | 2 +- repl/src/useHighlighting.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/repl/src/CodeMirror6.jsx b/repl/src/CodeMirror6.jsx index 1209163a..942843d7 100644 --- a/repl/src/CodeMirror6.jsx +++ b/repl/src/CodeMirror6.jsx @@ -37,7 +37,7 @@ const highlightField = StateField.define({ } return highlights; } catch (err) { - console.warn('highlighting error', err); + // console.warn('highlighting error', err); return highlights; } }, diff --git a/repl/src/useHighlighting.js b/repl/src/useHighlighting.js index 9e20fe34..855fb5d6 100644 --- a/repl/src/useHighlighting.js +++ b/repl/src/useHighlighting.js @@ -12,13 +12,18 @@ function useHighlighting({ view, pattern, active }) { let frame = requestAnimationFrame(updateHighlights); function updateHighlights() { - const audioTime = Tone.getTransport().seconds; - const span = [lastEnd || audioTime, audioTime + 1 / 60]; - lastEnd = audioTime + 1 / 60; - highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active - const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset()); - highlights = highlights.concat(haps); // add potential new onsets - view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps + try { + const audioTime = Tone.getTransport().seconds; + const span = [lastEnd || audioTime, audioTime + 1 / 60]; + lastEnd = audioTime + 1 / 60; + highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active + const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset()); + highlights = highlights.concat(haps); // add potential new onsets + view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps + } catch (err) { + // console.log('error in updateHighlights', err); + view.dispatch({ effects: setHighlights.of([]) }); + } frame = requestAnimationFrame(updateHighlights); }