mirror of
https://codeberg.org/uzu/strudel
synced 2026-11-22 16:57:23 -05:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e60541260c | |||
| 46f01053da | |||
| 9feb0f44cf | |||
| e12e980e04 | |||
| d25df719df | |||
| d71526d946 | |||
| 9dc19fb9bf | |||
| 4a158db9d2 | |||
| 55839e7ee8 | |||
| 9aaa9bee6b | |||
| 1834d689ef | |||
| 77a7a148f0 | |||
| 52931e879d | |||
| d5c9be1c30 | |||
| 2b30ab3008 | |||
| 13cbeb3f67 | |||
| 352d8659ec |
@@ -0,0 +1,23 @@
|
||||
In line with [our humane policy](POLICY.md), code and documentation
|
||||
should not be written by LLM agents. To this end, agents should not
|
||||
edit the codebase or make any commits that are intended to be
|
||||
contributed upstream. Likewise, LLM output should not be pasted into
|
||||
issues, comments, pull requests and so on.
|
||||
|
||||
A contributor's personal use of LLMs and related technology is their
|
||||
own business, whether for research, analysis, bug discovery or other
|
||||
assistive technology, so long as the output is not included in any
|
||||
contributions to our projects.
|
||||
|
||||
Strudel is AGPL licensed, and so any code integrated with it also
|
||||
comes under that license. This should be carefully considered before
|
||||
distributing software integrated with strudel, including making it
|
||||
available over a network.
|
||||
|
||||
Strudel has purposefully moved away from github.com, as a closed
|
||||
source platform with ethical issues. Please do not fork strudel back
|
||||
to that platform, or similar corporate platforms.
|
||||
|
||||
Projects using strudel must not use "strudel" in their name, unless
|
||||
they are 'official' projects, or have the blessing of the strudel
|
||||
community.
|
||||
@@ -73,6 +73,15 @@ export function registerControl(names, ...aliases) {
|
||||
return bag;
|
||||
}
|
||||
|
||||
// Constructs a superdirt effect bus control
|
||||
const sdbus = register('sdbus', function (busid, control_name, busval, pat) {
|
||||
return pat[control_name]('c' + busid).withValue((val) => {
|
||||
const newval = { ...val };
|
||||
newval['^' + control_name] = [busid, busval];
|
||||
return newval;
|
||||
});
|
||||
});
|
||||
|
||||
export function registerMultiControl(names, maxControls, ...aliases) {
|
||||
names = Array.isArray(names) ? names : [names];
|
||||
let bag = {};
|
||||
|
||||
@@ -74,12 +74,12 @@ export class Cyclist {
|
||||
// query the pattern for events
|
||||
const haps = this.pattern
|
||||
.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' })
|
||||
.filter((hap) => hap.hasOnset())
|
||||
.filter((hap) => hap.hasOnset() || hap.context.processParts)
|
||||
// Sort the haps based on their onset, so cps changes within the
|
||||
// tick duration happen in the correct order.
|
||||
.sort((a, b) => {
|
||||
const aBegin = a.whole.begin;
|
||||
const bBegin = b.whole.begin;
|
||||
const aBegin = a.part.begin;
|
||||
const bBegin = b.part.begin;
|
||||
// If haps happen at the same time, trigger the haps that cause
|
||||
// cps changes first, so the durations of the simultaneous haps
|
||||
// are adjusted accordingly.
|
||||
@@ -96,7 +96,7 @@ export class Cyclist {
|
||||
});
|
||||
|
||||
haps.forEach((hap) => {
|
||||
const targetTime = (hap.whole.begin - this.checkpoint.cycles) / this.cps + this.checkpoint.seconds;
|
||||
const targetTime = (hap.part.begin - this.checkpoint.cycles) / this.cps + this.checkpoint.seconds;
|
||||
if (tickEndTime < targetTime) {
|
||||
// If the targetTime exceeds the tickEndTime, this means
|
||||
// the cps has slowed down, and the latter haps from the query
|
||||
@@ -110,7 +110,7 @@ export class Cyclist {
|
||||
this.cps = hap.value.cps;
|
||||
this.num_ticks_since_checkpoint = 0;
|
||||
this.checkpoint = {
|
||||
cycles: hap.whole.begin,
|
||||
cycles: hap.part.begin,
|
||||
seconds: targetTime,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class Hap {
|
||||
then the whole will be returned as None, in which case the given
|
||||
value will have been sampled from the point halfway between the
|
||||
start and end of the 'part' timespan.
|
||||
The context is to store a list of source code locations causing the event.
|
||||
The context is to store metadata, including a list of source code locations causing the event.
|
||||
|
||||
The word 'Event' is more or less a reserved word in javascript, hence this
|
||||
class is named called 'Hap'.
|
||||
@@ -161,6 +161,10 @@ export class Hap {
|
||||
return new Hap(this.whole, this.part, this.value, context);
|
||||
}
|
||||
|
||||
withContext(f) {
|
||||
return new Hap(this.whole, this.part, this.value, f(this.context));
|
||||
}
|
||||
|
||||
ensureObjectValue() {
|
||||
/* if (isNote(hap.value)) {
|
||||
// supports primitive hap values that look like notes
|
||||
|
||||
@@ -64,7 +64,12 @@ export class Pattern {
|
||||
this.__steps = steps === undefined ? undefined : Fraction(steps);
|
||||
}
|
||||
|
||||
_processParts() {
|
||||
return this.withHap((hap) => hap.withContext((c) => ({ ...c, processParts: true })));
|
||||
}
|
||||
|
||||
setSteps(steps) {
|
||||
// TODO shouldn't this be pure and return a new pattern?
|
||||
this._steps = steps;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
+35
-7
@@ -52,6 +52,7 @@ export function parseControlsFromHap(hap, cps) {
|
||||
controls.unit === 'c' && controls.speed != null && (controls.speed = controls.speed / cps);
|
||||
const channels = controls.channels;
|
||||
channels != undefined && (controls.channels = JSON.stringify(channels));
|
||||
|
||||
return controls;
|
||||
}
|
||||
|
||||
@@ -77,16 +78,42 @@ export async function oscOutput(hap, targetTime, cps = 1) {
|
||||
const controls = parseControlsFromHap(hap, cps);
|
||||
const keyvals = Object.entries(controls).flat();
|
||||
const msg = { address: '/dirt/play', args: keyvals, timestamp: ts };
|
||||
|
||||
if ('oschost' in hap.value) {
|
||||
msg['host'] = hap.value['oschost'];
|
||||
}
|
||||
if ('oscport' in hap.value) {
|
||||
msg['port'] = hap.value['oscport'];
|
||||
}
|
||||
ws.send(JSON.stringify(msg));
|
||||
}
|
||||
|
||||
export async function superdirtTrigger(hap, currentTime, cps = 1, targetTime) {
|
||||
const ws = await connect();
|
||||
const controls = parseControlsFromHap(hap, cps);
|
||||
const ts = collator.calculateTimestamp(currentTime, targetTime) * 1000;
|
||||
|
||||
let oschost = '127.0.0.1';
|
||||
let oscport = 57120;
|
||||
let bushost = oschost;
|
||||
let busport = 57110;
|
||||
|
||||
for (const [k, v] of Object.entries(controls)) {
|
||||
if (k.startsWith('^')) {
|
||||
const bus_idval = v;
|
||||
const msg = JSON.stringify({
|
||||
oschost: bushost,
|
||||
oscport: busport,
|
||||
address: '/c_set',
|
||||
args: bus_idval,
|
||||
timestamp: ts,
|
||||
});
|
||||
// console.log('bus message', msg);
|
||||
ws.send(msg);
|
||||
// So they aren't sent with trigger messages
|
||||
delete controls[k];
|
||||
}
|
||||
}
|
||||
|
||||
if (hap.hasOnset()) {
|
||||
const keyvals = Object.entries(controls).flat();
|
||||
ws.send(JSON.stringify({ oschost, oscport, address: '/dirt/play', args: keyvals, timestamp: ts }));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sends each hap as an OSC message, which can be picked up by SuperCollider or any other OSC-enabled software.
|
||||
@@ -101,3 +128,4 @@ export const osc = register('osc', (pat) => {
|
||||
ensureMinimalOutput();
|
||||
return pat.onSchedule(oscOutput);
|
||||
});
|
||||
export const superdirt = register('superdirt', (pat) => pat._processParts().onTrigger(superdirtTrigger));
|
||||
|
||||
+9
-13
@@ -12,18 +12,13 @@ import { WebSocketServer } from 'ws';
|
||||
import osc from 'osc';
|
||||
|
||||
const WS_PORT = 8080; // WebSocket server port
|
||||
const OSC_REMOTE_IP = '127.0.0.1';
|
||||
const OSC_REMOTE_PORT = 57120;
|
||||
|
||||
const udpPort = new osc.UDPPort({
|
||||
localAddress: '0.0.0.0',
|
||||
localPort: 0,
|
||||
remoteAddress: OSC_REMOTE_IP,
|
||||
remotePort: OSC_REMOTE_PORT,
|
||||
});
|
||||
|
||||
udpPort.open();
|
||||
console.log(`[Sending OSC] ${OSC_REMOTE_IP}:${OSC_REMOTE_PORT}`);
|
||||
|
||||
udpPort.on('error', (e) => {
|
||||
console.log('Error: ', e);
|
||||
@@ -36,23 +31,24 @@ wss.on('connection', (ws) => {
|
||||
console.log('New WebSocket connection');
|
||||
|
||||
ws.on('message', (message) => {
|
||||
let osc_host = '127.0.0.1';
|
||||
let osc_port = 57120;
|
||||
let oschost = '127.0.0.1';
|
||||
let oscport = 57120;
|
||||
|
||||
try {
|
||||
const data = JSON.parse(message);
|
||||
if ('host' in data) {
|
||||
osc_host = data['host'];
|
||||
if ('oschost' in data) {
|
||||
oschost = data['oschost'];
|
||||
delete data['oschost'];
|
||||
}
|
||||
if ('port' in data) {
|
||||
osc_port = data['port'];
|
||||
if ('oscport' in data) {
|
||||
oscport = data['oscport'];
|
||||
delete data['oscport'];
|
||||
}
|
||||
let msg = { address: data['address'], args: data['args'] };
|
||||
if ('timestamp' in data) {
|
||||
msg = { timeTag: osc.timeTag(0, data['timestamp']), packets: [msg] };
|
||||
}
|
||||
|
||||
udpPort.send(msg, osc_host, osc_port);
|
||||
udpPort.send(msg, oschost, oscport);
|
||||
} catch (err) {
|
||||
console.error('Error parsing message:', err);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@
|
||||
"@strudel/soundfonts": "workspace:*",
|
||||
"@strudel/tonal": "workspace:*",
|
||||
"@strudel/transpiler": "workspace:*",
|
||||
"@strudel/webaudio": "workspace:*",
|
||||
"@strudel/websocket": "workspace:*"
|
||||
"@strudel/webaudio": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-replace": "^6.0.2",
|
||||
|
||||
@@ -15,7 +15,6 @@ export async function prebake() {
|
||||
import('@strudel/hydra'),
|
||||
import('@strudel/soundfonts'),
|
||||
import('@strudel/midi'),
|
||||
import('@strudel/websocket'),
|
||||
// import('@strudel/xen'),
|
||||
// import('@strudel/serial'),
|
||||
// import('@strudel/csound'),
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# @strudel/websocket
|
||||
|
||||
This package adds websocket input to strudel Patterns.
|
||||
|
||||
It connects to a websocket server and exposes the latest received value (parsed as JSON) as a pattern.
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import './websocket.mjs';
|
||||
|
||||
export * from './websocket.mjs';
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"name": "@strudel/websocket",
|
||||
"version": "1.0.0",
|
||||
"description": "Websocket input for strudel",
|
||||
"main": "index.mjs",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"main": "dist/index.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
"algorave"
|
||||
],
|
||||
"author": "Alex McLean <alex@slab.org>",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://codeberg.org/uzu/strudel/issues"
|
||||
},
|
||||
"homepage": "https://codeberg.org/uzu/strudel#readme",
|
||||
"dependencies": {
|
||||
"@strudel/core": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.11"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { dependencies } from './package.json';
|
||||
import { resolve } from 'path';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [],
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolve(__dirname, 'index.mjs'),
|
||||
formats: ['es'],
|
||||
fileName: (ext) => ({ es: 'index.mjs' })[ext],
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [...Object.keys(dependencies)],
|
||||
},
|
||||
target: 'esnext',
|
||||
},
|
||||
});
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
websocket.mjs - simple websocket client as a pattern
|
||||
Copyright (C) 2026 Strudel contributors -- see <https://codeberg.org/uzu/strudel/src/branch/main/packages/websocket/websocket.mjs>
|
||||
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/>.
|
||||
*/
|
||||
|
||||
import { logger, signal } from '@strudel/core';
|
||||
|
||||
const connections = {};
|
||||
const values = {};
|
||||
|
||||
function connect(addr) {
|
||||
if (connections[addr]) {
|
||||
return connections[addr];
|
||||
}
|
||||
const ws = new WebSocket(addr);
|
||||
connections[addr] = ws;
|
||||
ws.addEventListener('open', () => {
|
||||
logger(`[websocket] connected to ${addr}`);
|
||||
});
|
||||
ws.addEventListener('message', (event) => {
|
||||
try {
|
||||
console.log(event.data);
|
||||
values[addr] = JSON.parse(event.data);
|
||||
} catch {
|
||||
logger(`[websocket] received invalid json on ${addr}`);
|
||||
}
|
||||
});
|
||||
ws.addEventListener('close', () => {
|
||||
logger(`[websocket] disconnected from ${addr}`);
|
||||
delete connections[addr];
|
||||
});
|
||||
ws.addEventListener('error', () => {
|
||||
logger(`[websocket] failed to connect to ${addr}`);
|
||||
delete connections[addr];
|
||||
});
|
||||
return ws;
|
||||
}
|
||||
|
||||
export function websocket(addr) {
|
||||
connect(addr);
|
||||
return signal(() => values[addr] ?? {});
|
||||
}
|
||||
Generated
-16
@@ -538,9 +538,6 @@ importers:
|
||||
'@strudel/webaudio':
|
||||
specifier: workspace:*
|
||||
version: link:../webaudio
|
||||
'@strudel/websocket':
|
||||
specifier: workspace:*
|
||||
version: link:../websocket
|
||||
devDependencies:
|
||||
'@rollup/plugin-replace':
|
||||
specifier: ^6.0.2
|
||||
@@ -725,16 +722,6 @@ importers:
|
||||
specifier: ^6.0.11
|
||||
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||
|
||||
packages/websocket:
|
||||
dependencies:
|
||||
'@strudel/core':
|
||||
specifier: workspace:*
|
||||
version: link:../core
|
||||
devDependencies:
|
||||
vite:
|
||||
specifier: ^6.0.11
|
||||
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||
|
||||
packages/xen:
|
||||
dependencies:
|
||||
'@strudel/core':
|
||||
@@ -870,9 +857,6 @@ importers:
|
||||
'@strudel/webaudio':
|
||||
specifier: workspace:*
|
||||
version: link:../packages/webaudio
|
||||
'@strudel/websocket':
|
||||
specifier: workspace:*
|
||||
version: link:../packages/websocket
|
||||
'@strudel/xen':
|
||||
specifier: workspace:*
|
||||
version: link:../packages/xen
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
"@strudel/tonal": "workspace:*",
|
||||
"@strudel/transpiler": "workspace:*",
|
||||
"@strudel/webaudio": "workspace:*",
|
||||
"@strudel/websocket": "workspace:*",
|
||||
"@strudel/mondo": "workspace:*",
|
||||
"@strudel/xen": "workspace:*",
|
||||
"@supabase/supabase-js": "^2.48.1",
|
||||
|
||||
@@ -11,7 +11,7 @@ import QA from '@components/QA';
|
||||
|
||||
Up until now, most of the functions we've seen are what other music programs are typically capable of: sequencing sounds, playing notes, controlling effects.
|
||||
|
||||
In this chapter, we are going to look at functions that are more unique to tidal.
|
||||
In this chapter, we are going to look at functions that are more unique to Strudel.
|
||||
|
||||
**reverse patterns with rev**
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ export function loadModules() {
|
||||
import('@strudel/desktopbridge/oscbridge.mjs'),
|
||||
]);
|
||||
} else {
|
||||
modules = modules.concat([import('@strudel/midi'), import('@strudel/osc'), import('@strudel/websocket')]);
|
||||
modules = modules.concat([import('@strudel/midi'), import('@strudel/osc')]);
|
||||
}
|
||||
|
||||
return evalScope(settingPatterns, ...modules);
|
||||
|
||||
Reference in New Issue
Block a user