mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-21 20:55:12 -04:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c3e07afd3 | |||
| c54fa7d266 | |||
| a25f763796 | |||
| 91ad3d729f | |||
| 4cb0488839 | |||
| 663229ecde | |||
| cdb623cb66 | |||
| 28d7e0e489 | |||
| aba594b72a | |||
| 5d7c6c3e4b | |||
| 820744dc27 | |||
| 5445f0812f | |||
| 98b7003504 |
+27
-17
@@ -4,21 +4,13 @@ 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:
|
Assuming you have [node.js](https://nodejs.org/) installed, you can run the osc bridge server via:
|
||||||
|
|
||||||
From the project root:
|
```sh
|
||||||
|
npx @strudel/osc
|
||||||
```js
|
|
||||||
npm run repl
|
|
||||||
```
|
```
|
||||||
|
|
||||||
and in a seperate shell:
|
You should see something like:
|
||||||
|
|
||||||
```js
|
|
||||||
npm run osc
|
|
||||||
```
|
|
||||||
|
|
||||||
This should give you
|
|
||||||
|
|
||||||
```log
|
```log
|
||||||
osc client running on port 57120
|
osc client running on port 57120
|
||||||
@@ -26,14 +18,32 @@ 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)
|
### --port
|
||||||
|
|
||||||
Now open the REPL and type:
|
By default it will use port 57120 for the osc client, which is what [superdirt](https://github.com/musikinformatik/SuperDirt) uses. You can change it via the `--port` option:
|
||||||
|
|
||||||
```js
|
```sh
|
||||||
s("<bd sd> hh").osc()
|
npx @strudel/osc --port 7771 # classic dirt
|
||||||
```
|
```
|
||||||
|
|
||||||
or just [click here](https://strudel.cc/#cygiPGJkIHNkPiBoaCIpLm9zYygp)...
|
### --debug
|
||||||
|
|
||||||
|
To log all incoming osc messages, add the `--debug` flag:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npx @strudel/osc --debug
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage in Strudel
|
||||||
|
|
||||||
|
To test it in strudel, you have can use `all(osc)` to send all events through osc:
|
||||||
|
|
||||||
|
```js
|
||||||
|
$: s("bd*4")
|
||||||
|
|
||||||
|
all(osc)
|
||||||
|
```
|
||||||
|
|
||||||
|
[open in repl](https://strudel.cc/#JDogcygiYmQqNCIpCgphbGwob3NjKQ%3D%3D)
|
||||||
|
|
||||||
You can read more about [how to use Superdirt with Strudel the Tutorial](https://strudel.cc/learn/input-output/#superdirt-api)
|
You can read more about [how to use Superdirt with Strudel the Tutorial](https://strudel.cc/learn/input-output/#superdirt-api)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
|
|
||||||
import OSC from 'osc-js';
|
import OSC from 'osc-js';
|
||||||
|
|
||||||
import { logger, parseNumeral, Pattern, isNote, noteToMidi, ClockCollator } from '@strudel/core';
|
import { logger, parseNumeral, register, isNote, noteToMidi, ClockCollator } from '@strudel/core';
|
||||||
|
|
||||||
let connection; // Promise<OSC>
|
let connection; // Promise<OSC>
|
||||||
function connect() {
|
function connect() {
|
||||||
@@ -81,6 +81,4 @@ export async function oscTrigger(hap, currentTime, cps = 1, targetTime) {
|
|||||||
* @memberof Pattern
|
* @memberof Pattern
|
||||||
* @returns Pattern
|
* @returns Pattern
|
||||||
*/
|
*/
|
||||||
Pattern.prototype.osc = function () {
|
export const osc = register('osc', (pat) => pat.onTrigger(oscTrigger));
|
||||||
return this.onTrigger(oscTrigger);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel/osc",
|
"name": "@strudel/osc",
|
||||||
"version": "1.2.4",
|
"version": "1.2.10",
|
||||||
"description": "OSC messaging for strudel",
|
"description": "OSC messaging for strudel",
|
||||||
"main": "osc.mjs",
|
"main": "osc.mjs",
|
||||||
|
"bin": "./server.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"main": "dist/index.mjs"
|
"main": "dist/index.mjs"
|
||||||
|
|||||||
+43
-2
@@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
/*
|
/*
|
||||||
server.js - <short description TODO>
|
server.js - <short description TODO>
|
||||||
Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/osc/server.js>
|
Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/osc/server.js>
|
||||||
@@ -6,6 +8,19 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
|
|
||||||
import OSC from 'osc-js';
|
import OSC from 'osc-js';
|
||||||
|
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
function getArgValue(flag) {
|
||||||
|
const i = args.indexOf(flag);
|
||||||
|
if (i !== -1) {
|
||||||
|
const nextIsFlag = args[i + 1]?.startsWith('--') ?? true;
|
||||||
|
if (nextIsFlag) return true;
|
||||||
|
return args[i + 1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let udpClientPort = Number(getArgValue('--port')) || 57120;
|
||||||
|
let debug = Number(getArgValue('--debug')) || 0;
|
||||||
|
|
||||||
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
|
||||||
udpServer: {
|
udpServer: {
|
||||||
@@ -17,7 +32,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
udpClient: {
|
udpClient: {
|
||||||
host: 'localhost', // @param {string} Hostname of udp client for messaging
|
host: 'localhost', // @param {string} Hostname of udp client for messaging
|
||||||
port: 57120, // @param {number} Port of udp client for messaging
|
port: udpClientPort, // @param {number} Port of udp client for messaging
|
||||||
},
|
},
|
||||||
wsServer: {
|
wsServer: {
|
||||||
host: 'localhost', // @param {string} Hostname of WebSocket server
|
host: 'localhost', // @param {string} Hostname of WebSocket server
|
||||||
@@ -27,8 +42,34 @@ const config = {
|
|||||||
|
|
||||||
const osc = new OSC({ plugin: new OSC.BridgePlugin(config) });
|
const osc = new OSC({ plugin: new OSC.BridgePlugin(config) });
|
||||||
|
|
||||||
osc.open(); // start a WebSocket server on port 8080
|
if (debug) {
|
||||||
|
osc.on('*', (message) => {
|
||||||
|
const { address, args } = message;
|
||||||
|
let str = '';
|
||||||
|
for (let i = 0; i < args.length; i += 2) {
|
||||||
|
str += `${args[i]}: ${args[i + 1]} `;
|
||||||
|
}
|
||||||
|
console.log(`${address} ${str}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
osc.on('error', (message) => {
|
||||||
|
if (message.toString().includes('EADDRINUSE')) {
|
||||||
|
console.log(`------ ERROR -------
|
||||||
|
a server is already running on port 57121! to stop it:
|
||||||
|
1. run "lsof -ti :57121 | xargs kill -9" (macos / linux)
|
||||||
|
2. re-run the osc server
|
||||||
|
`);
|
||||||
|
} else {
|
||||||
|
console.log(message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
osc.open();
|
||||||
|
|
||||||
console.log('osc client running on port', config.udpClient.port);
|
console.log('osc client running on port', config.udpClient.port);
|
||||||
console.log('osc server running on port', config.udpServer.port);
|
console.log('osc server running on port', config.udpServer.port);
|
||||||
console.log('websocket server running on port', config.wsServer.port);
|
console.log('websocket server running on port', config.wsServer.port);
|
||||||
|
if (debug) {
|
||||||
|
console.log('debug logs enabled. incoming messages will appear below');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user