kinda fixed it, need to find cause of incorrect cps calculation
This commit is contained in:
parent
cba96049a3
commit
19df19375d
2 changed files with 9 additions and 11 deletions
|
|
@ -8,7 +8,7 @@ import createClock from './zyklus.mjs';
|
||||||
import { logger } from './logger.mjs';
|
import { logger } from './logger.mjs';
|
||||||
|
|
||||||
export class Cyclist {
|
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.started = false;
|
||||||
this.cps = 0.5;
|
this.cps = 0.5;
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.num_ticks_since_cps_change = 0;
|
||||||
|
|
@ -35,14 +35,11 @@ export class Cyclist {
|
||||||
try {
|
try {
|
||||||
const begin = this.lastEnd;
|
const begin = this.lastEnd;
|
||||||
|
|
||||||
this.lastBegin = begin;
|
|
||||||
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
|
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
|
||||||
|
let cycle = this.now();
|
||||||
this.lastEnd = end;
|
//magic number that fixes cycle calcuation, cycle is probably not being calculated correctly
|
||||||
|
const modifier = this.cps * -interval;
|
||||||
this.lastTick = phase;
|
cycle = cycle + modifier;
|
||||||
|
|
||||||
const cycle = this.now();
|
|
||||||
|
|
||||||
if (phase < t) {
|
if (phase < t) {
|
||||||
// avoid querying haps that are in the past anyway
|
// avoid querying haps that are in the past anyway
|
||||||
|
|
@ -60,10 +57,14 @@ export class Cyclist {
|
||||||
const duration = hap.duration / this.cps;
|
const duration = hap.duration / this.cps;
|
||||||
// the following line is dumb and only here for backwards compatibility
|
// the following line is dumb and only here for backwards compatibility
|
||||||
// see https://github.com/tidalcycles/strudel/pull/1004
|
// see https://github.com/tidalcycles/strudel/pull/1004
|
||||||
|
|
||||||
const deadline = targetTime - phase;
|
const deadline = targetTime - phase;
|
||||||
onTrigger?.(hap, deadline, duration, this.cps, targetTime, cycle);
|
onTrigger?.(hap, deadline, duration, this.cps, targetTime, cycle);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
this.lastBegin = begin;
|
||||||
|
this.lastEnd = end;
|
||||||
|
this.lastTick = phase;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger(`[cyclist] error: ${e.message}`);
|
logger(`[cyclist] error: ${e.message}`);
|
||||||
onError?.(e);
|
onError?.(e);
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,8 @@ export class NeoCyclist {
|
||||||
constructor({ onTrigger, onToggle, getTime }) {
|
constructor({ onTrigger, onToggle, getTime }) {
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.cps = 0.5;
|
this.cps = 0.5;
|
||||||
this.lastTick = 0; // absolute time when last tick (clock callback) happened
|
|
||||||
this.getTime = getTime; // get absolute time
|
this.getTime = getTime; // get absolute time
|
||||||
this.time_at_last_tick_message = 0;
|
this.time_at_last_tick_message = 0;
|
||||||
|
|
||||||
this.num_cycles_at_cps_change = 0;
|
|
||||||
this.onToggle = onToggle;
|
this.onToggle = onToggle;
|
||||||
this.latency = 0.1; // fixed trigger time offset
|
this.latency = 0.1; // fixed trigger time offset
|
||||||
this.cycle = 0;
|
this.cycle = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue