mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-24 20:18:34 +00:00
highlight only events with onsets
This commit is contained in:
parent
f6d128842a
commit
d4607c68f7
@ -2,6 +2,8 @@ import { useEffect } from 'react';
|
|||||||
import { setHighlights } from './CodeMirror6';
|
import { setHighlights } from './CodeMirror6';
|
||||||
import { Tone } from '@strudel.cycles/tone';
|
import { Tone } from '@strudel.cycles/tone';
|
||||||
|
|
||||||
|
let highlights = []; // actively highlighted events
|
||||||
|
|
||||||
function useHighlighting({ view, pattern, started }) {
|
function useHighlighting({ view, pattern, started }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (view) {
|
if (view) {
|
||||||
@ -10,11 +12,10 @@ function useHighlighting({ view, pattern, started }) {
|
|||||||
|
|
||||||
function updateHighlights() {
|
function updateHighlights() {
|
||||||
const audioTime = Tone.getTransport().seconds;
|
const audioTime = Tone.getTransport().seconds;
|
||||||
const span = { begin: audioTime, end: audioTime + 1 / 60 };
|
highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
// TODO: remove isActive workaround when query is fixed
|
const haps = pattern.queryArc(audioTime, audioTime + 1 / 60).filter((hap) => hap.hasOnset());
|
||||||
const isActive = (event) => event.whole.end >= span.begin && event.whole.begin <= span.end;
|
highlights = highlights.concat(haps); // add potential new onsets
|
||||||
const events = pattern.queryArc(span.begin, span.end).filter(isActive);
|
view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps
|
||||||
view.dispatch({ effects: setHighlights.of(events) });
|
|
||||||
frame = requestAnimationFrame(updateHighlights);
|
frame = requestAnimationFrame(updateHighlights);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,6 +23,7 @@ function useHighlighting({ view, pattern, started }) {
|
|||||||
cancelAnimationFrame(frame);
|
cancelAnimationFrame(frame);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
highlights = [];
|
||||||
view.dispatch({ effects: setHighlights.of([]) });
|
view.dispatch({ effects: setHighlights.of([]) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user