handle edge case
This commit is contained in:
parent
bdb5dabba5
commit
29fceff9b3
2 changed files with 13 additions and 8 deletions
|
|
@ -37,7 +37,7 @@ const highlightField = StateField.define({
|
||||||
}
|
}
|
||||||
return highlights;
|
return highlights;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('highlighting error', err);
|
// console.warn('highlighting error', err);
|
||||||
return highlights;
|
return highlights;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,18 @@ function useHighlighting({ view, pattern, active }) {
|
||||||
let frame = requestAnimationFrame(updateHighlights);
|
let frame = requestAnimationFrame(updateHighlights);
|
||||||
|
|
||||||
function updateHighlights() {
|
function updateHighlights() {
|
||||||
const audioTime = Tone.getTransport().seconds;
|
try {
|
||||||
const span = [lastEnd || audioTime, audioTime + 1 / 60];
|
const audioTime = Tone.getTransport().seconds;
|
||||||
lastEnd = audioTime + 1 / 60;
|
const span = [lastEnd || audioTime, audioTime + 1 / 60];
|
||||||
highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
lastEnd = audioTime + 1 / 60;
|
||||||
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
highlights = highlights.concat(haps); // add potential new onsets
|
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
||||||
view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps
|
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);
|
frame = requestAnimationFrame(updateHighlights);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue