osc timing now hopefully works everywhere

This commit is contained in:
Felix Roos
2022-04-02 22:41:04 +02:00
parent 0c726d835d
commit c8e9fe519f
3 changed files with 9 additions and 11 deletions
+2 -7
View File
@@ -10,8 +10,6 @@ import { State, TimeSpan } from '@strudel.cycles/core';
ready?: boolean; // if false, query will not be called on change props
} */
export let startedAt;
// function useCycle(props: UseCycleProps) {
function useCycle(props) {
// onX must use useCallback!
@@ -44,7 +42,7 @@ function useCycle(props) {
?.filter((event) => event.part.begin.equals(event.whole.begin))
.forEach((event) => {
Tone.getTransport().schedule((time) => {
onEvent(time, event, startedAt);
onEvent(time, event, Tone.getContext().currentTime);
Tone.Draw.schedule(() => {
// do drawing or DOM manipulation here
onDraw?.(time, event);
@@ -59,10 +57,7 @@ function useCycle(props) {
const start = async () => {
setStarted(true);
if (!startedAt) {
await Tone.start();
startedAt = Date.now() - Tone.getContext().currentTime * 1000;
}
await Tone.start();
Tone.getTransport().start('+0.1');
};
const stop = () => {
+2 -2
View File
@@ -27,7 +27,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
const cycle = useCycle({
onDraw,
onEvent: useCallback(
(time, event, startedAt) => {
(time, event, currentTime) => {
try {
onEvent?.(event);
const { onTrigger, velocity } = event.context;
@@ -41,7 +41,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
/* console.warn('no instrument chosen', event);
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
} else {
onTrigger(time, event, startedAt);
onTrigger(time, event, currentTime);
}
} catch (err) {
console.warn(err);