workaround for osc-js timestamp bug, reduce latency

This commit is contained in:
alex 2022-04-01 15:37:50 +01:00
parent 4ef70d2a15
commit ac01a621be

View File

@ -3,17 +3,18 @@ import { Pattern, isPattern } from '@strudel.cycles/core/strudel.mjs';
const comm = new OSC();
comm.open();
// TODO - get startTime from scheduler
const startTime = Date.now();
const latency = 0.2;
const latency = 0.1;
Pattern.prototype.osc = function () {
return this._withEvent((event) => {
const onTrigger = (time, event) => {
console.log(time);
const keyvals = Object.entries(event.value).flat();
const ts = startTime + ((time+latency)*1000);
const ts = Math.floor(startTime + ((time + latency) * 1000));
const message = new OSC.Message('/dirt/play',...keyvals);
const bundle = new OSC.Bundle([message], ts)
const bundle = new OSC.Bundle([message], ts);
bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60
comm.send(bundle);
};
return event.setContext({ ...event.context, onTrigger });