diff --git a/packages/core/cyclist.mjs b/packages/core/cyclist.mjs index f0a9db5fc..33ac466e8 100644 --- a/packages/core/cyclist.mjs +++ b/packages/core/cyclist.mjs @@ -58,7 +58,6 @@ export class Cyclist { // query the pattern for events const haps = this.pattern.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' }); - haps.forEach((hap) => { if (hap.hasOnset() || hap.context.processParts) { const targetTime = @@ -68,7 +67,7 @@ export class Cyclist { // see https://codeberg.org/uzu/strudel/pulls/1004 const deadline = targetTime - phase; // this onTrigger has another signature - onTrigger?.(hap, deadline, duration, this.cps, targetTime); + onTrigger?.(hap, deadline, duration, this.cps, targetTime, begin); if (hap.value.cps !== undefined && this.cps != hap.value.cps) { this.cps = hap.value.cps; this.num_ticks_since_cps_change = 0; diff --git a/packages/core/neocyclist.mjs b/packages/core/neocyclist.mjs index 3e412074d..fa1013df1 100644 --- a/packages/core/neocyclist.mjs +++ b/packages/core/neocyclist.mjs @@ -44,7 +44,7 @@ export class NeoCyclist { const timeUntilTrigger = cycleToSeconds(hap.whole.begin - this.cycle, this.cps); const targetTime = timeUntilTrigger + currentTime + this.latency; const duration = cycleToSeconds(hap.duration, this.cps); - onTrigger?.(hap, 0, duration, this.cps, targetTime); + onTrigger?.(hap, 0, duration, this.cps, targetTime, begin); } }); }; diff --git a/packages/osc/osc.mjs b/packages/osc/osc.mjs index d05e6ca4c..0ba1e1cae 100644 --- a/packages/osc/osc.mjs +++ b/packages/osc/osc.mjs @@ -67,7 +67,7 @@ export async function oscTrigger(hap, currentTime, cps = 1, targetTime) { ws.send(JSON.stringify(msg)); } -export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime) { +export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime, queryBegin) { const ws = await connect(); const controls = parseControlsFromHap(hap, cps); const ts = collator.calculateTimestamp(currentTime, targetTime) * 1000; @@ -79,6 +79,8 @@ export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime) { for (const [k, v] of Object.entries(controls)) { if (k.startsWith('^')) { + const offset = hap.part.begin.sub(queryBegin) / cps; + console.log('part begin', +hap.part.begin, 'qBegin', queryBegin, 'adding', offset, 'to', ts); const bus_id = v; const bus_value = controls[k.substring(1)]; const msg = JSON.stringify({ @@ -86,18 +88,18 @@ export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime) { oscport: busport, address: '/c_set', args: [bus_id, bus_value], - timestamp: ts, + timestamp: ts + offset, }); - console.log('bus message', msg); + // console.log('bus message', msg); ws.send(msg); // So they aren't sent with trigger messages delete controls[k]; } } - if (hap.hasOnset) { + if (hap.hasOnset()) { const keyvals = Object.entries(controls).flat(); - ws.send(JSON.stringify({ oschost, oscport, address: '/dirt/play', args: keyvals, timestamp: ts })); + ws.send(JSON.stringify({ oschost, oscport, address: '/dirt/play', args: keyvals, timestamp: ts + offset })); } }