mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-27 13:38:40 +00:00
working
This commit is contained in:
parent
e12421cee8
commit
cb57d8f497
@ -11,17 +11,14 @@ export class Cyclist {
|
|||||||
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
constructor({ interval, onTrigger, onToggle, onError, getTime, latency = 0.1 }) {
|
||||||
this.started = false;
|
this.started = false;
|
||||||
this.cps = 1;
|
this.cps = 1;
|
||||||
|
this.num_ticks_since_cps_change = 0;
|
||||||
// this.num_ticks_since_cps_change = 0;
|
|
||||||
this.lastTick = 0; // absolute time when last tick (clock callback) happened
|
this.lastTick = 0; // absolute time when last tick (clock callback) happened
|
||||||
this.lastBegin = 0; // query begin of last tick
|
this.lastBegin = 0; // query begin of last tick
|
||||||
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_since_last_cps_change = 0;
|
this.num_cycles_since_last_cps_change = 0;
|
||||||
this.time_last_cps_change = 0;
|
|
||||||
this.onToggle = onToggle;
|
this.onToggle = onToggle;
|
||||||
this.latency = latency; // fixed trigger time offset
|
this.latency = latency; // fixed trigger time offset
|
||||||
const round = (x) => Math.round(x * 1000) / 1000;
|
|
||||||
this.clock = createClock(
|
this.clock = createClock(
|
||||||
getTime,
|
getTime,
|
||||||
// called slightly before each cycle
|
// called slightly before each cycle
|
||||||
@ -37,12 +34,16 @@ export class Cyclist {
|
|||||||
const time = getTime();
|
const time = getTime();
|
||||||
const begin = this.lastEnd;
|
const begin = this.lastEnd;
|
||||||
this.lastBegin = begin;
|
this.lastBegin = begin;
|
||||||
|
|
||||||
|
//convert ticks to cycles, so you can query the pattern for events
|
||||||
const eventLength = duration * this.cps;
|
const eventLength = duration * this.cps;
|
||||||
const end = this.num_cycles_since_last_cps_change + this.num_ticks_since_cps_change * eventLength;
|
const end = this.num_cycles_since_last_cps_change + this.num_ticks_since_cps_change * eventLength;
|
||||||
// const end = round(begin + duration * this.cps);
|
|
||||||
this.lastEnd = end;
|
this.lastEnd = end;
|
||||||
|
|
||||||
|
// query the pattern for events
|
||||||
const haps = this.pattern.queryArc(begin, end);
|
const haps = this.pattern.queryArc(begin, end);
|
||||||
const tickdeadline = phase - time; // time left till phase tick begins
|
|
||||||
|
const tickdeadline = phase - time; // time left until the phase is a whole number
|
||||||
this.lastTick = time + tickdeadline;
|
this.lastTick = time + tickdeadline;
|
||||||
|
|
||||||
haps.forEach((hap) => {
|
haps.forEach((hap) => {
|
||||||
@ -69,7 +70,6 @@ export class Cyclist {
|
|||||||
this.onToggle?.(v);
|
this.onToggle?.(v);
|
||||||
}
|
}
|
||||||
start() {
|
start() {
|
||||||
// this.time_last_cps_change = 0;
|
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.num_ticks_since_cps_change = 0;
|
||||||
this.num_cycles_since_last_cps_change = 0;
|
this.num_cycles_since_last_cps_change = 0;
|
||||||
if (!this.pattern) {
|
if (!this.pattern) {
|
||||||
@ -101,7 +101,6 @@ export class Cyclist {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.cps = cps;
|
this.cps = cps;
|
||||||
// this.time_last_cps_change = this.getTime();
|
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.num_ticks_since_cps_change = 0;
|
||||||
}
|
}
|
||||||
log(begin, end, haps) {
|
log(begin, end, haps) {
|
||||||
|
|||||||
@ -39,6 +39,7 @@ function createClock(
|
|||||||
const pause = () => clear();
|
const pause = () => clear();
|
||||||
const stop = () => {
|
const stop = () => {
|
||||||
tick = 0;
|
tick = 0;
|
||||||
|
phase = 0;
|
||||||
clear();
|
clear();
|
||||||
};
|
};
|
||||||
const getPhase = () => phase;
|
const getPhase = () => phase;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user