mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 04:58:27 +00:00
clock fail strategy
This commit is contained in:
parent
94ccfa631e
commit
7d2110d75f
@ -2,6 +2,12 @@ import { parseNumeral, Pattern, getEventOffsetMs } from '@strudel/core';
|
|||||||
import { Invoke } from './utils.mjs';
|
import { Invoke } from './utils.mjs';
|
||||||
|
|
||||||
let offsetTime;
|
let offsetTime;
|
||||||
|
let weight = 1;
|
||||||
|
let timeAtPrevOffsetSample;
|
||||||
|
let rollingOffsetTime;
|
||||||
|
|
||||||
|
|
||||||
|
// let prevTime = 0;
|
||||||
Pattern.prototype.osc = function () {
|
Pattern.prototype.osc = function () {
|
||||||
return this.onTrigger(async (time, hap, currentTime, cps = 1, targetTime) => {
|
return this.onTrigger(async (time, hap, currentTime, cps = 1, targetTime) => {
|
||||||
hap.ensureObjectValue();
|
hap.ensureObjectValue();
|
||||||
@ -14,12 +20,22 @@ Pattern.prototype.osc = function () {
|
|||||||
|
|
||||||
const params = [];
|
const params = [];
|
||||||
// console.log(time, currentTime)
|
// console.log(time, currentTime)
|
||||||
|
|
||||||
const unixTimeSecs = Date.now() / 1000;
|
const unixTimeSecs = Date.now() / 1000;
|
||||||
|
const newOffsetTime = unixTimeSecs - currentTime;
|
||||||
|
|
||||||
if (offsetTime == null) {
|
if (unixTimeSecs - timeAtPrevOffsetSample > 2) {
|
||||||
const unixTimeSecs = Date.now() / 1000;
|
timeAtPrevOffsetSample = unixTimeSecs;
|
||||||
offsetTime = unixTimeSecs - currentTime;
|
rollingOffsetTime = newOffsetTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//account for the js clock freezing or resetting for some reason
|
||||||
|
if (offsetTime == null || Math.abs(rollingOffsetTime - offsetTime) > .1
|
||||||
|
) {
|
||||||
|
offsetTime = newOffsetTime;
|
||||||
|
}
|
||||||
|
// prevTime = currentTime;
|
||||||
const timestamp = offsetTime + targetTime
|
const timestamp = offsetTime + targetTime
|
||||||
// const timestamp = unixTimeSecs + (targetTime - currentTime)
|
// const timestamp = unixTimeSecs + (targetTime - currentTime)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user