mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
Merge branch 'osc' of https://github.com/tidalcycles/strudel into osc
This commit is contained in:
commit
4ef70d2a15
21
packages/osc/osc.mjs
Normal file
21
packages/osc/osc.mjs
Normal file
@ -0,0 +1,21 @@
|
||||
import OSC from './node_modules/osc-js/lib/osc.js';
|
||||
import { Pattern, isPattern } from '@strudel.cycles/core/strudel.mjs';
|
||||
|
||||
const comm = new OSC();
|
||||
comm.open();
|
||||
const startTime = Date.now();
|
||||
const latency = 0.2;
|
||||
|
||||
Pattern.prototype.osc = function () {
|
||||
return this._withEvent((event) => {
|
||||
const onTrigger = (time, event) => {
|
||||
console.log(time);
|
||||
const keyvals = Object.entries(event.value).flat();
|
||||
const ts = startTime + ((time+latency)*1000);
|
||||
const message = new OSC.Message('/dirt/play',...keyvals);
|
||||
const bundle = new OSC.Bundle([message], ts)
|
||||
comm.send(bundle);
|
||||
};
|
||||
return event.setContext({ ...event.context, onTrigger });
|
||||
});
|
||||
};
|
||||
@ -4,7 +4,7 @@
|
||||
"description": "OSC messaging for strudel",
|
||||
"main": "osc.mjs",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test": "echo \"No tests present.\" && exit 0",
|
||||
"server": "node server.js",
|
||||
"tidal-sniffer": "node tidal-sniffer.js",
|
||||
"client": "npx serve -p 4321"
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
const dgram = require('dgram')
|
||||
const OSC = require('osc-js');
|
||||
|
||||
const config = {
|
||||
@ -18,6 +19,9 @@ const config = {
|
||||
port: 8080, // @param {number} Port of WebSocket server
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
const osc = new OSC({ plugin: new OSC.BridgePlugin(config) });
|
||||
|
||||
osc.open(); // start a WebSocket server on port 8080
|
||||
@ -27,12 +31,15 @@ console.log('osc server running on port', config.udpServer.port);
|
||||
console.log('websocket server running on port', config.wsServer.port);
|
||||
|
||||
// listen for messages from the client
|
||||
osc.on('*', (m) => {
|
||||
// forward message to supercollider??
|
||||
const message = new OSC.Message(m.address, ...m.args);
|
||||
osc.send(message); // will it even be received??
|
||||
console.log('forward:', m.address, m.args);
|
||||
});
|
||||
// osc.on('*', (m) => {
|
||||
// console.log("hmm!");
|
||||
// const ts = m.args.shift();
|
||||
// const message = new OSC.Message(m.address, ...m.args);
|
||||
// console.log(m.args);
|
||||
// const bundle = new OSC.Bundle([message], new Date(ts))
|
||||
// osc.send(bundle);
|
||||
// console.log('forward:', bundle);
|
||||
// });
|
||||
|
||||
/*
|
||||
example tidal messages:
|
||||
|
||||
@ -28,6 +28,7 @@ import '@strudel.cycles/xen/tune.mjs';
|
||||
import '@strudel.cycles/core/euclid.mjs';
|
||||
import '@strudel.cycles/tone/pianoroll.mjs';
|
||||
import '@strudel.cycles/tone/draw.mjs';
|
||||
import '@strudel.cycles/osc/osc.mjs';
|
||||
|
||||
extend(Tone, strudel, strudel.Pattern.prototype.bootstrap(), toneHelpers, voicingHelpers, drawHelpers, uiHelpers, {
|
||||
gist,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user