Merge pull request #135 from tidalcycles/trigger-simplification

remove cycle + delta from onTrigger
This commit is contained in:
Felix Roos 2022-06-16 20:48:06 +02:00 committed by GitHub
commit 0ce70f4d0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

View File

@ -22,13 +22,15 @@ let startedAt = -1;
*/ */
Pattern.prototype.osc = function () { Pattern.prototype.osc = function () {
return this._withHap((hap) => { return this._withHap((hap) => {
const onTrigger = (time, hap, currentTime, cps, cycle, delta) => { const onTrigger = (time, hap, currentTime, cps) => {
const cycle = hap.wholeOrPart().begin.valueOf();
const delta = hap.duration.valueOf();
// time should be audio time of onset // time should be audio time of onset
// currentTime should be current time of audio context (slightly before time) // currentTime should be current time of audio context (slightly before time)
if (startedAt < 0) { if (startedAt < 0) {
startedAt = Date.now() - currentTime * 1000; startedAt = Date.now() - currentTime * 1000;
} }
const controls = Object.assign({}, { cps: cps, cycle: cycle, delta: delta }, hap.value); const controls = Object.assign({}, { cps, cycle, delta }, hap.value);
const keyvals = Object.entries(controls).flat(); const keyvals = Object.entries(controls).flat();
const ts = Math.floor(startedAt + (time + latency) * 1000); const ts = Math.floor(startedAt + (time + latency) * 1000);
const message = new OSC.Message('/dirt/play', ...keyvals); const message = new OSC.Message('/dirt/play', ...keyvals);

View File

@ -57,14 +57,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawP
/* console.warn('no instrument chosen', event); /* console.warn('no instrument chosen', event);
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */ throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
} else { } else {
onTrigger( onTrigger(time, event, currentTime, 1 /* cps */);
time,
event,
currentTime,
1 /* cps */,
event.wholeOrPart().begin.valueOf(),
event.duration.valueOf(),
);
} }
} catch (err) { } catch (err) {
console.warn(err); console.warn(err);