kinda fixed it, need to find cause of incorrect cps calculation

This commit is contained in:
Jade (Rose) Rowland
2024-05-13 10:33:18 -04:00
parent cba96049a3
commit 19df19375d
2 changed files with 9 additions and 11 deletions
+9 -8
View File
@@ -8,7 +8,7 @@ import createClock from './zyklus.mjs';
import { logger } from './logger.mjs';
export class Cyclist {
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1, setInterval, clearInterval }) {
constructor({ interval = 0.05, onTrigger, onToggle, onError, getTime, latency = 0.1, setInterval, clearInterval }) {
this.started = false;
this.cps = 0.5;
this.num_ticks_since_cps_change = 0;
@@ -35,14 +35,11 @@ export class Cyclist {
try {
const begin = this.lastEnd;
this.lastBegin = begin;
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
this.lastEnd = end;
this.lastTick = phase;
const cycle = this.now();
let cycle = this.now();
//magic number that fixes cycle calcuation, cycle is probably not being calculated correctly
const modifier = this.cps * -interval;
cycle = cycle + modifier;
if (phase < t) {
// avoid querying haps that are in the past anyway
@@ -60,10 +57,14 @@ export class Cyclist {
const duration = hap.duration / this.cps;
// the following line is dumb and only here for backwards compatibility
// see https://github.com/tidalcycles/strudel/pull/1004
const deadline = targetTime - phase;
onTrigger?.(hap, deadline, duration, this.cps, targetTime, cycle);
}
});
this.lastBegin = begin;
this.lastEnd = end;
this.lastTick = phase;
} catch (e) {
logger(`[cyclist] error: ${e.message}`);
onError?.(e);
-3
View File
@@ -10,11 +10,8 @@ export class NeoCyclist {
constructor({ onTrigger, onToggle, getTime }) {
this.started = false;
this.cps = 0.5;
this.lastTick = 0; // absolute time when last tick (clock callback) happened
this.getTime = getTime; // get absolute time
this.time_at_last_tick_message = 0;
this.num_cycles_at_cps_change = 0;
this.onToggle = onToggle;
this.latency = 0.1; // fixed trigger time offset
this.cycle = 0;