mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-22 13:13:10 -04:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c21bc161d6 | |||
| 8d65092c97 | |||
| b6a9943b5a |
+3
-11
@@ -4,18 +4,10 @@ OSC output for strudel patterns! Currently only tested with super collider / sup
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
OSC will only work if you run the REPL locally + the OSC server besides it:
|
Make sure you've [set up strudel locally](https://github.com/tidalcycles/strudel/blob/main/CONTRIBUTING.md#project-setup). Then run:
|
||||||
|
|
||||||
From the project root:
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
npm run repl
|
pnpm osc
|
||||||
```
|
|
||||||
|
|
||||||
and in a seperate shell:
|
|
||||||
|
|
||||||
```js
|
|
||||||
npm run osc
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This should give you
|
This should give you
|
||||||
@@ -26,7 +18,7 @@ osc server running on port 57121
|
|||||||
websocket server running on port 8080
|
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:
|
Now open the REPL and type:
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import OSC from 'osc-js';
|
|||||||
|
|
||||||
import { logger, parseNumeral, Pattern } from '@strudel/core';
|
import { logger, parseNumeral, Pattern } from '@strudel/core';
|
||||||
|
|
||||||
|
let subs = {};
|
||||||
let connection; // Promise<OSC>
|
let connection; // Promise<OSC>
|
||||||
function connect() {
|
function connect() {
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
@@ -25,6 +26,13 @@ function connect() {
|
|||||||
console.log('[osc] disconnected');
|
console.log('[osc] disconnected');
|
||||||
reject('OSC connection closed');
|
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));
|
osc.on('error', (err) => reject(err));
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
connection = undefined;
|
connection = undefined;
|
||||||
@@ -34,6 +42,24 @@ function connect() {
|
|||||||
return connection;
|
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.
|
* Sends each hap as an OSC message, which can be picked up by SuperCollider or any other OSC-enabled software.
|
||||||
|
|||||||
@@ -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/>.
|
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 = {
|
const config = {
|
||||||
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
|
receiver: 'ws', // @param {string} Where messages sent via 'send' method will be delivered to, 'ws' for Websocket clients, 'udp' for udp client
|
||||||
|
|||||||
Reference in New Issue
Block a user