Compare commits

...

3 Commits

Author SHA1 Message Date
Felix Roos c21bc161d6 some osc helper functions 2024-02-18 20:41:06 +01:00
Felix Roos 8d65092c97 update osc readme 2024-02-15 10:00:01 +01:00
Felix Roos b6a9943b5a use es6 import 2024-02-15 09:59:52 +01:00
3 changed files with 30 additions and 12 deletions
+3 -11
View File
@@ -4,18 +4,10 @@ OSC output for strudel patterns! Currently only tested with super collider / sup
## Usage
OSC will only work if you run the REPL locally + the OSC server besides it:
From the project root:
Make sure you've [set up strudel locally](https://github.com/tidalcycles/strudel/blob/main/CONTRIBUTING.md#project-setup). Then run:
```js
npm run repl
```
and in a seperate shell:
```js
npm run osc
pnpm osc
```
This should give you
@@ -26,7 +18,7 @@ osc server running on port 57121
websocket server running on port 8080
```
Now open Supercollider (with the super dirt startup file)
Now open Supercollider (with the super dirt startup file) or run `sclang`.
Now open the REPL and type:
+26
View File
@@ -8,6 +8,7 @@ import OSC from 'osc-js';
import { logger, parseNumeral, Pattern } from '@strudel/core';
let subs = {};
let connection; // Promise<OSC>
function connect() {
if (!connection) {
@@ -25,6 +26,13 @@ function connect() {
console.log('[osc] disconnected');
reject('OSC connection closed');
});
osc.on('*', (msg) => {
Object.entries(subs).forEach(([route, callback]) => {
if (msg.address.startsWith(route)) {
callback(msg.args, msg);
}
});
});
osc.on('error', (err) => reject(err));
}).catch((err) => {
connection = undefined;
@@ -34,6 +42,24 @@ function connect() {
return connection;
}
export const connectOSC = connect;
export async function sendOSC(...msg) {
const osc = await connect();
const t = Date.now();
const message = new OSC.Message(...msg);
const bundle = new OSC.Bundle([message], t);
bundle.timestamp(t); // workaround for https://github.com/adzialocha/osc-js/issues/60
osc.send(bundle);
}
export function subOSC(route, callback) {
subs[route] = callback;
}
export function unsubOSC(route) {
delete subs[route];
}
/**
*
* Sends each hap as an OSC message, which can be picked up by SuperCollider or any other OSC-enabled software.
+1 -1
View File
@@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/st
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
const OSC = require('osc-js');
import OSC from 'osc-js';
const config = {
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client