mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 13:48:34 +00:00
+ make cyclist trigger backwards compatible for now
+ add absolute time as new 5th onTrigger param
This commit is contained in:
parent
14a5e7dcb6
commit
e8f6124a07
@ -23,7 +23,7 @@ export class Cyclist {
|
|||||||
this.clock = createClock(
|
this.clock = createClock(
|
||||||
getTime,
|
getTime,
|
||||||
// called slightly before each cycle
|
// called slightly before each cycle
|
||||||
(phase, duration) => {
|
(phase, duration, _, t) => {
|
||||||
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.seconds_at_cps_change = phase;
|
||||||
@ -45,10 +45,13 @@ export class Cyclist {
|
|||||||
|
|
||||||
haps.forEach((hap) => {
|
haps.forEach((hap) => {
|
||||||
if (hap.hasOnset()) {
|
if (hap.hasOnset()) {
|
||||||
const deadline =
|
const targetTime =
|
||||||
(hap.whole.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency;
|
(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);
|
// 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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -166,14 +166,15 @@ export function repl({
|
|||||||
|
|
||||||
export const getTrigger =
|
export const getTrigger =
|
||||||
({ getTime, defaultOutput }) =>
|
({ getTime, defaultOutput }) =>
|
||||||
async (hap, deadline, duration, cps) => {
|
async (hap, deadline, duration, cps, t) => {
|
||||||
|
// TODO: get rid of deadline after https://github.com/tidalcycles/strudel/pull/1004
|
||||||
try {
|
try {
|
||||||
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
|
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
|
||||||
await defaultOutput(hap, deadline, duration, cps);
|
await defaultOutput(hap, deadline, duration, cps, t);
|
||||||
}
|
}
|
||||||
if (hap.context.onTrigger) {
|
if (hap.context.onTrigger) {
|
||||||
// call signature of output / onTrigger is different...
|
// call signature of output / onTrigger is different...
|
||||||
await hap.context.onTrigger(getTime() + deadline, hap, getTime(), cps);
|
await hap.context.onTrigger(getTime() + deadline, hap, getTime(), cps, t);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger(`[cyclist] error: ${err.message}`, 'error');
|
logger(`[cyclist] error: ${err.message}`, 'error');
|
||||||
|
|||||||
@ -16,7 +16,9 @@ const hap2value = (hap) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const webaudioOutputTrigger = (t, hap, ct, cps) => superdough(hap2value(hap), t - ct, hap.duration / cps, cps);
|
export const webaudioOutputTrigger = (t, hap, ct, cps) => superdough(hap2value(hap), t - ct, hap.duration / cps, cps);
|
||||||
export const webaudioOutput = (hap, deadline, hapDuration) => superdough(hap2value(hap), deadline, hapDuration);
|
// uses more precise, absolute t if available, see https://github.com/tidalcycles/strudel/pull/1004
|
||||||
|
export const webaudioOutput = (hap, deadline, hapDuration, cps, t) =>
|
||||||
|
superdough(hap2value(hap), t ? `=${t}` : deadline, hapDuration);
|
||||||
|
|
||||||
Pattern.prototype.webaudio = function () {
|
Pattern.prototype.webaudio = function () {
|
||||||
return this.onTrigger(webaudioOutputTrigger);
|
return this.onTrigger(webaudioOutputTrigger);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user