Files
strudel/packages/desktopbridge/oscbridge.mjs
Felix Roos 4a0d9de664 rename repl defaultOutput to onSchedule, error when defaultOutput is
passed. also rename xScheduler to xOutput, to be consistent with
webaudioOutput and friends
2026-10-11 20:54:50 +02:00

39 lines
1.1 KiB
JavaScript

import { Pattern, ClockCollator } from '@strudel/core';
import { parseControlsFromHap } from '@strudel/osc/osc.mjs';
import { Invoke } from './utils.mjs';
import { getAudioContext } from '@strudel/webaudio/index.mjs';
const collator = new ClockCollator({});
export async function tauriOscOutput(hap, targetTime, cps = 1) {
const controls = parseControlsFromHap(hap, cps);
const params = [];
const currentTime = getAudioContext().currentTime;
const timestamp = collator.calculateTimestamp(currentTime, targetTime);
Object.keys(controls).forEach((key) => {
const val = controls[key];
const value = typeof val === 'number' ? val.toString() : val;
if (value == null) {
return;
}
params.push({
name: key,
value,
valueisnumber: typeof val === 'number',
});
});
if (params.length === 0) {
return;
}
const message = { target: '/dirt/play', timestamp, params };
setTimeout(() => {
Invoke('sendosc', { messagesfromjs: [message] });
});
}
Pattern.prototype.osc = function () {
return this.onSchedule(tauriOscOutput);
};