Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom OSC targets and documentation #623

Open
jarmitage opened this issue Jun 29, 2023 · 1 comment
Open

Custom OSC targets and documentation #623

jarmitage opened this issue Jun 29, 2023 · 1 comment

Comments

@jarmitage
Copy link
Contributor

jarmitage commented Jun 29, 2023

Tidal has facilities and docs for defining "OSC Targets": https://tidalcycles.org/docs/configuration/MIDIOSC/osc

Strudel currently only supports SuperDirt's OSC protocol: https://strudel.tidalcycles.org/learn/input-output

Here's the code:

/**
*
* Sends each hap as an OSC message, which can be picked up by SuperCollider or any other OSC-enabled software.
* For more info, read [MIDI & OSC in the docs](https://strudel.tidalcycles.org/learn/input-output)
*
* @name osc
* @memberof Pattern
* @returns Pattern
*/
Pattern.prototype.osc = function () {
return this.onTrigger(async (time, hap, currentTime, cps = 1) => {
hap.ensureObjectValue();
const osc = await connect();
const cycle = hap.wholeOrPart().begin.valueOf();
const delta = hap.duration.valueOf();
// time should be audio time of onset
// currentTime should be current time of audio context (slightly before time)
if (startedAt < 0) {
startedAt = Date.now() - currentTime * 1000;
}
const controls = Object.assign({}, { cps, cycle, delta }, hap.value);
// make sure n and note are numbers
controls.n && (controls.n = parseNumeral(controls.n));
controls.note && (controls.note = parseNumeral(controls.note));
const keyvals = Object.entries(controls).flat();
const ts = Math.floor(startedAt + (time + latency) * 1000);
const message = new OSC.Message('/dirt/play', ...keyvals);
const bundle = new OSC.Bundle([message], ts);
bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60
osc.send(bundle);
});
};

It would be great to be able to define OSC Targets for using Strudel to control other things, with some docs to go with it.

As an example, @freeeco wants to control Toybox in Reaktor similar to this https://cdm.link/2020/11/free-nano-community-modules-for-reaktor-blocks-with-tidalcycles-support-and-tons-of-toys/

As an additional thought, OSC inputs to Tidal have been a topic for a while:

OSC inputs to Strudel might be quite useful in various cases too, something to consider.

Another thought, regarding #33, perhaps there should be a separation between schema and protocol, i.e. you could potentially use the same schema over OSC, WebRTC, etc.

@felixroos
Copy link
Collaborator

setting target / port / address could work with regular params which are then used by osc:

x.target('name').port(3128).address('127.0.0.1').osc()

I think the dirt/play prefix should actually be removed + a new .superdirt function should be added with that prefix intact, see #63 (comment)

here's an example of how you'd get custom osc messages: https://strudel.tidalcycles.org/?XhW1Hcn-MriE this will send messages like dirt/play/x/1/y/3 or x/1/y/3 when dirt/play is removed.

is it a limiting factor if the message always uses key value pairs?

using ":" syntax, it is also possble to get array values: https://strudel.tidalcycles.org/?vigTL4LDX9dv although osc will currently still turn those into key value pairs, meaning [ 2, "arbitrary", "arguments" ] turns into 0/2/1/arbitrary/2/arguments. but maybe key value pairs are just fine.. i haven't used osc enough to know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants