mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 04:28:30 +00:00
fix: clock jitter in cyclist
This commit is contained in:
parent
8d8c843ccf
commit
ba8f996103
@ -17,40 +17,38 @@ export class Cyclist {
|
|||||||
this.lastEnd = 0; // query end of last tick
|
this.lastEnd = 0; // query end of last tick
|
||||||
this.getTime = getTime; // get absolute time
|
this.getTime = getTime; // get absolute time
|
||||||
this.num_cycles_at_cps_change = 0;
|
this.num_cycles_at_cps_change = 0;
|
||||||
|
this.seconds_at_cps_change; // clock phase when cps was changed
|
||||||
this.onToggle = onToggle;
|
this.onToggle = onToggle;
|
||||||
this.latency = latency; // fixed trigger time offset
|
this.latency = latency; // fixed trigger time offset
|
||||||
this.clock = createClock(
|
this.clock = createClock(
|
||||||
getTime,
|
getTime,
|
||||||
// called slightly before each cycle
|
// called slightly before each cycle
|
||||||
(phase, duration, tick) => {
|
(phase, duration) => {
|
||||||
if (tick === 0) {
|
|
||||||
this.origin = phase;
|
|
||||||
}
|
|
||||||
if (this.num_ticks_since_cps_change === 0) {
|
if (this.num_ticks_since_cps_change === 0) {
|
||||||
this.num_cycles_at_cps_change = this.lastEnd;
|
this.num_cycles_at_cps_change = this.lastEnd;
|
||||||
|
this.seconds_at_cps_change = phase;
|
||||||
}
|
}
|
||||||
this.num_ticks_since_cps_change++;
|
this.num_ticks_since_cps_change++;
|
||||||
|
const seconds_since_cps_change = this.num_ticks_since_cps_change * duration;
|
||||||
|
const num_cycles_since_cps_change = seconds_since_cps_change * this.cps;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const time = getTime();
|
|
||||||
const begin = this.lastEnd;
|
const begin = this.lastEnd;
|
||||||
this.lastBegin = begin;
|
this.lastBegin = begin;
|
||||||
|
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
|
||||||
//convert ticks to cycles, so you can query the pattern for events
|
|
||||||
const eventLength = duration * this.cps;
|
|
||||||
const end = this.num_cycles_at_cps_change + this.num_ticks_since_cps_change * eventLength;
|
|
||||||
this.lastEnd = end;
|
this.lastEnd = end;
|
||||||
|
|
||||||
// query the pattern for events
|
// query the pattern for events
|
||||||
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps });
|
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps });
|
||||||
|
|
||||||
const tickdeadline = phase - time; // time left until the phase is a whole number
|
this.lastTick = phase;
|
||||||
this.lastTick = time + tickdeadline;
|
|
||||||
|
|
||||||
haps.forEach((hap) => {
|
haps.forEach((hap) => {
|
||||||
if (hap.part.begin.equals(hap.whole.begin)) {
|
if (hap.hasOnset()) {
|
||||||
const deadline = (hap.whole.begin - begin) / this.cps + tickdeadline + latency;
|
const deadline =
|
||||||
|
(hap.whole.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency;
|
||||||
const duration = hap.duration / this.cps;
|
const duration = hap.duration / this.cps;
|
||||||
onTrigger?.(hap, deadline, duration, this.cps);
|
onTrigger?.(hap, '=' + deadline, duration, this.cps);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user