Skip to content

Commit

Permalink
Merge pull request #1046 from tidalcycles/fix-cyclist
Browse files Browse the repository at this point in the history
fix cyclist fizzling out
  • Loading branch information
felixroos authored Apr 5, 2024
2 parents 7839d6b + df23ea6 commit 8f47551
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/core/cyclist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ export class Cyclist {
this.lastBegin = begin;
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
this.lastEnd = end;
this.lastTick = phase;

if (phase < t) {
// avoid querying haps that are in the past anyway
console.log(`skip query: too late`);
return;
}

// query the pattern for events
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps });

this.lastTick = phase;

haps.forEach((hap) => {
if (hap.hasOnset()) {
const targetTime =
Expand Down
3 changes: 1 addition & 2 deletions packages/core/zyklus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ function createClock(
// callback as long as we're inside the lookahead
while (phase < lookahead) {
phase = round ? Math.round(phase * precision) / precision : phase;
phase >= t && callback(phase, duration, tick, t);
phase < t && console.log('TOO LATE', phase); // what if latency is added from outside?
callback(phase, duration, tick, t); // callback has to skip / handle phase < t!
phase += duration; // increment phase by duration
tick++;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/superdough/superdough.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@ export const superdough = async (value, t, hapDuration) => {
value.duration = hapDuration;
// calculate absolute time
t = typeof t === 'string' && t.startsWith('=') ? Number(t.slice(1)) : ac.currentTime + t;
if (t < ac.currentTime) {
console.warn(
`[superdough]: cannot schedule sounds in the past (target: ${t.toFixed(2)}, now: ${ac.currentTime.toFixed(2)})`,
);
return;
}
// destructure
let {
s = 'triangle',
Expand Down

0 comments on commit 8f47551

Please sign in to comment.