From 1834d689efbe2cc302940050ddfabac0b4ec6143 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 24 Oct 2025 20:48:35 +0100 Subject: [PATCH] fixes + tidying --- packages/core/controls.mjs | 9 +++++++++ packages/core/cyclist.mjs | 4 ++-- packages/osc/osc.mjs | 13 +++++-------- packages/osc/server.js | 1 - 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/controls.mjs b/packages/core/controls.mjs index a3ca638aa..5525827cf 100644 --- a/packages/core/controls.mjs +++ b/packages/core/controls.mjs @@ -72,6 +72,15 @@ export function registerControl(names, ...aliases) { return bag; } +// Constructs a superdirt effect bus control +const bus = register('bus', function (busid, control_name, busval, pat) { + return pat[control_name]('c' + busid).withValue((val) => { + const newval = { ...val }; + newval['^' + control_name] = [busid, busval]; + return newval; + }); +}); + /** * Select a sound / sample by name. When using mininotation, you can also optionally supply 'n' and 'gain' parameters * separated by ':'. diff --git a/packages/core/cyclist.mjs b/packages/core/cyclist.mjs index 33ac466e8..a0580e713 100644 --- a/packages/core/cyclist.mjs +++ b/packages/core/cyclist.mjs @@ -61,13 +61,13 @@ export class Cyclist { haps.forEach((hap) => { if (hap.hasOnset() || hap.context.processParts) { const targetTime = - (hap.whole.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency; + (hap.part.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency; const duration = hap.duration / this.cps; // the following line is dumb and only here for backwards compatibility // see https://codeberg.org/uzu/strudel/pulls/1004 const deadline = targetTime - phase; // this onTrigger has another signature - onTrigger?.(hap, deadline, duration, this.cps, targetTime, begin); + onTrigger?.(hap, deadline, duration, this.cps, targetTime); 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/osc/osc.mjs b/packages/osc/osc.mjs index 0ba1e1cae..c61e1c867 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, queryBegin) { +export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime) { const ws = await connect(); const controls = parseControlsFromHap(hap, cps); const ts = collator.calculateTimestamp(currentTime, targetTime) * 1000; @@ -79,16 +79,13 @@ export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime, qu 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 bus_idval = v; const msg = JSON.stringify({ oschost: bushost, oscport: busport, address: '/c_set', - args: [bus_id, bus_value], - timestamp: ts + offset, + args: bus_idval, + timestamp: ts, }); // console.log('bus message', msg); ws.send(msg); @@ -99,7 +96,7 @@ export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime, qu if (hap.hasOnset()) { const keyvals = Object.entries(controls).flat(); - ws.send(JSON.stringify({ oschost, oscport, address: '/dirt/play', args: keyvals, timestamp: ts + offset })); + ws.send(JSON.stringify({ oschost, oscport, address: '/dirt/play', args: keyvals, timestamp: ts })); } } diff --git a/packages/osc/server.js b/packages/osc/server.js index b0faf9923..5f2e62d73 100755 --- a/packages/osc/server.js +++ b/packages/osc/server.js @@ -48,7 +48,6 @@ wss.on('connection', (ws) => { if ('timestamp' in data) { msg = { timeTag: osc.timeTag(0, data['timestamp']), packets: [msg] }; } - console.log(msg, oschost, oscport); udpPort.send(msg, oschost, oscport); } catch (err) { console.error('Error parsing message:', err);