Compare commits

..

2 Commits

Author SHA1 Message Date
Felix Roos 3c32b3b0aa Merge remote-tracking branch 'origin/main' into kabelsalat-adapter 2026-10-15 16:12:39 +02:00
Felix Roos c492e21e1d move kabelsalat to separate package + add registerChainEffect in
superdough to load it
2026-10-12 18:11:00 +02:00
40 changed files with 460 additions and 683 deletions
-3
View File
@@ -131,6 +131,3 @@ fabric.properties
samples/*
!samples/README.md
.idea/
.vscode
!settings.json
+6 -7
View File
@@ -2,10 +2,6 @@
Thanks for wanting to contribute!!! There are many ways you can add value to this project
## Humane interaction
Please read [POLICY.md](POLICY.md) for important details of our Code of Conduct, and policy around AI/LLM use.
## Move to codeberg
Along with many other live coding projects, we have moved from Microsoft's Github platform to Codeberg for ethical reasons. Please don't fork the project back to github.
@@ -38,7 +34,7 @@ Use one of the Communication Channels listed above.
## Improve the Docs
If you find some weak spots in the [docs](https://strudel.cc/workshop/getting-started/), you can edit each file directly on codeberg. There are "Edit this page" links in the right sidebar that take you to the right place. If you're unfamiliar with codeberg/git, please ask questions.
If you find some weak spots in the [docs](https://strudel.cc/workshop/getting-started/), you can edit each file directly on codeberg. There are "Edit this page" links in the right sidebar that take you to the right place.
## Propose a Feature
@@ -52,7 +48,11 @@ At the time of writing we have a PR backlog, and generally prioritise bugfixes a
### AI/LLM policy
Strudel is a project handmade by humans, with thought and nuance. See [Policy](POLICY.md) for our policy on LLM use.
Strudel is a project handmade by humans, with thought and nuance.
If you have used LLMs (so called 'AI'), please detail that in the pull request. We are still developing our response to the onslaught of LLM technology, but for practical and legal reasons are currently not accepting wholly LLM-generated code. We are also not accepting PRs that add LLM features to strudel itself.
There are #llm-chat and #llm-share channels on [our discord](https://discord.com/invite/HGEdXmRkzT). Please do not discuss or share LLM-related things outside of those channels.
## Creating and sharing a new project using strudel
@@ -254,4 +254,3 @@ ORDER BY created_at ASC;
## Have Fun
Remember to have fun, and that this project is driven by the passion of volunteers!
-41
View File
@@ -1,41 +0,0 @@
# Code of Conduct
## The Short Version
We are dedicated to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, ethnicity, religion (or lack thereof), technology choices, and so on. This applies both in person or via online media.
## The Less Short Version
Harassment includes offensive verbal comments related to gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, ethnicity, religion, technology choices, deliberate intimidation, stalking, following, disruption of performances, inappropriate physical contact, and unwelcome sexual attention.
If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact an admin immediately.
If you report an incident of harassment you can expect to be listened to and taken seriously. The admin will take action they deem appropriate in response depending on the scale and severity of the incident. For example:
1. Discuss the perpetrator's behaviour with them and ask them to stop. Explain what they have done and why it is unacceptable. Remind the perpetrator of the code of conduct. Monitor the perpetrator's behaviour and if it improves then they will continue to be welcome.
2. Temporarily exclude the perpetrator from the forum for a cool-off period. Explain what they have done and why it is unacceptable and remind them of the code of conduct. Monitor the person's behaviour and if it improves then they will continue to be welcome.
3. Remove the perpetrator from the forum. Explain what they have done and why it is unacceptable and remind them of the code of conduct.
# Post-AI humane policy for live coding development
Please follow the following policy on AI/LLM use.
## Community
All community members should be treated with respect and kindness. We welcome contributors to the community who are ready to follow this policy as well as the above code of conduct.
## Principles
* We wish to protect the humanity of our communities and projects, to support the motivation and well-being of all of its contributors and users.
* To this end, contributors and other users of our projects should not have to engage with LLM-generated code and text as part of their community work.
* We recognise that LLM-based scraping and generation of (A)GPL code shared by ourselves and others is of questionable legality. For example, under many juristictions, LLM-generated work does not have a copyright holder and can therefore not be licensed under the (A)GPL.
* 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.
## In practice
* Contributions including LLM-generated content will be declined.
* LLM-generated text (e.g. commit messages, issue comments, forum posts etc) generated by LLMs will be flagged, and ultimately deleted.
* We encourage asking each other questions and working through problems to promote collective knowledge and creative ideas (never telling each other to "just google it").
* We strongly discourage others from forking/importing our projects into corporate AI platforms, including Microsoft Github.
* All contributions must be submitted by a person who understands the changes, is happy to answer questions about them, and where possible, help maintain the code in the future.
* In community discussion channels (at the time of writing, this refers to the uzu discord server), all discussion (including criticism) of LLM technology and use should be kept to designated channels.
+3 -5
View File
@@ -41,14 +41,12 @@ Licensing info for the default sound banks can be found over on the [dough-sampl
There are many ways to contribute to this project! See [contribution guide](./CONTRIBUTING.md). You can find the full list of contributors [here](https://codeberg.org/uzu/strudel/activity/contributors).
Please see [POLICY.md](POLICY.md) for our code of conduct and humane AI/LLM policy.
## Community
Strudel is a member of the 'Uzu' family of pattern-based live coding languages, along with TidalCycles and friends.
There is a #strudel channel on the TidalCycles discord: <https://discord.com/invite/HGEdXmRkzT>
There are a range of strudel channels on the Uzu discord: <https://discord.com/invite/HGEdXmRkzT>
You can also ask questions and find related discussions on the tidal club forum: <https://club.tidalcycles.org/>
You can also ask questions and find related discussions on the Uzu web forum: <https://uzu.lurk.org/>
The discord and forum is shared with the haskell (tidal) and python (vortex) siblings of this project.
We also have a mastodon account: <a rel="me" href="https://social.toplap.org/@strudel">social.toplap.org/@strudel</a>
-32
View File
@@ -104,32 +104,6 @@ function getCanvasWidget(id, options = {}) {
return canvas;
}
function getListWidget(id, options = {}) {
const { width = 600, height = 100 } = options;
let el = document.getElementById(id) || document.createElement('div');
el.style.width = width + 'px';
el.style.height = height + 'px';
el.style.overflowY = 'auto';
el.style.overflowX = 'auto';
el.style.boxSizing = 'border-box';
el.style.padding = '4px';
el.style.fontFamily = 'monospace';
el.style.lineHeight = '1.4';
el.style.whiteSpace = 'pre';
el.style.background = 'var(--background)';
el.style.color = 'var(--foreground)';
el.style.border = '1px solid var(--lineHighlight)';
// reset on every (re-)evaluation instead of persisting scroll state across it
el.replaceChildren();
el.scrollTop = 0;
el.follow = true;
el.onscroll = () => {
el.follow = el.scrollHeight - el.scrollTop - el.clientHeight < 4;
};
setWidget(id, el);
return el;
}
registerWidget('_pianoroll', (id, options = {}, pat) => {
const ctx = getCanvasWidget(id, options).getContext('2d');
return pat.tag(id).pianoroll({ fold: 1, ...options, ctx, id });
@@ -166,9 +140,3 @@ registerWidget('_spectrum', (id, options = {}, pat) => {
const ctx = getCanvasWidget(id, options).getContext('2d');
return pat.spectrum({ ...options, ctx, id });
});
registerWidget('_print', (id, options = {}, pat) => {
options = { width: 600, height: 100, maxLines: 500, ...options };
const el = getListWidget(id, options);
return pat.print({ ...options, el, id });
});
+23 -88
View File
@@ -28,34 +28,31 @@ export class Cyclist {
this.started = false;
this.beforeStart = beforeStart;
this.cps = 0.5;
this.checkpoint = {
// new checkpoints are created when there's a change in cps
cycles: 0, // number of cycles when cps was changed
seconds: 0, // clock phase when cps was changed
};
this.num_ticks_since_checkpoint = 0;
this.num_ticks_since_cps_change = 0;
this.lastTick = 0; // absolute time when last tick (clock callback) happened
this.lastBegin = 0; // query begin of last tick
this.lastEnd = 0; // query end of last tick
this.getTime = getTime; // get absolute time
this.num_cycles_at_cps_change = 0;
this.seconds_at_cps_change; // clock phase when cps was changed
this.onToggle = onToggle;
this.latency = latency; // fixed trigger time offset
this.clock = createClock(
getTime,
// called slightly before each cycle
(phase, duration, _, t) => {
if (this.num_ticks_since_checkpoint === 0) {
this.checkpoint = {
cycles: this.lastEnd,
seconds: phase,
};
if (this.num_ticks_since_cps_change === 0) {
this.num_cycles_at_cps_change = this.lastEnd;
this.seconds_at_cps_change = phase;
}
this.num_ticks_since_checkpoint++;
this.num_ticks_since_cps_change++;
const seconds_since_cps_change = this.num_ticks_since_cps_change * duration;
const num_cycles_since_cps_change = seconds_since_cps_change * this.cps;
try {
var begin = this.lastEnd;
const begin = this.lastEnd;
this.lastBegin = begin;
var end = this.checkpoint.cycles + this.num_ticks_since_checkpoint * duration * this.cps;
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
this.lastEnd = end;
this.lastTick = phase;
@@ -65,79 +62,20 @@ export class Cyclist {
return;
}
const tickEndTime = phase + duration;
// query the pattern for events
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' });
var cpsChanged = false;
do {
cpsChanged = false;
// query the pattern for events
const haps = this.pattern
.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' })
.filter((hap) => hap.hasOnset())
// 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;
// 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.
if (aBegin.eq(bBegin)) {
if (a.value.cps !== undefined) {
return b.value.cps !== undefined ? 0 : -1;
}
if (b.value.cps !== undefined) {
return 1;
}
return 0;
}
return aBegin.sub(bBegin);
});
haps.forEach((hap) => {
const targetTime = (hap.whole.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
// no longer fall within the window of the current tick.
// They'll be scheduled during the next tick.
return;
}
onSchedule?.(hap, targetTime + this.latency, hap.value.cps ?? this.cps);
haps.forEach((hap) => {
if (hap.hasOnset()) {
const targetTime =
(hap.whole.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency;
onSchedule?.(hap, targetTime, this.cps);
if (hap.value.cps !== undefined && this.cps != hap.value.cps) {
cpsChanged = true;
this.cps = hap.value.cps;
this.num_ticks_since_checkpoint = 0;
this.checkpoint = {
cycles: hap.whole.begin,
seconds: targetTime,
};
}
});
// If there are any haps in the query that trigger changes to the
// cps that result in the pattern speeding up, the current cycle end
// may not capture all the haps that need to be scheduled.
// If this is the case, we repeat the query + scheduling with a
// newly calculated end time.
// This process can repeat multiple times until no additional
// changes to the cps are triggered.
// In practice, this doesn't happen more than once during a tick.
if (cpsChanged) {
begin = end;
const remainingSecondsSinceCheckpoint = tickEndTime - this.checkpoint.seconds;
const remainingCycles = remainingSecondsSinceCheckpoint * this.cps;
end = this.checkpoint.cycles + remainingCycles;
this.lastEnd = end;
if (end < begin) {
// If the new end is before the old end this means the track
// slowed down, so we don't need to schedule additional haps.
// Otherwise, schedule the remaining events.
break;
this.num_ticks_since_cps_change = 0;
}
}
} while (cpsChanged);
});
} catch (e) {
errorLogger(e);
onError?.(e);
@@ -163,11 +101,8 @@ export class Cyclist {
}
async start() {
await this.beforeStart?.();
this.checkpoint = {
cycles: 0,
seconds: 0,
};
this.num_ticks_since_checkpoint = 0;
this.num_ticks_since_cps_change = 0;
this.num_cycles_at_cps_change = 0;
if (!this.pattern) {
throw new Error('Scheduler: no pattern set! call .setPattern first.');
}
@@ -197,7 +132,7 @@ export class Cyclist {
return;
}
this.cps = cps;
this.num_ticks_since_checkpoint = 0;
this.num_ticks_since_cps_change = 0;
}
log(begin, end, haps) {
const onsets = haps.filter((h) => h.hasOnset());
+1 -24
View File
@@ -420,7 +420,7 @@ export const binaryNL = (n, nBits = 16) => {
* .partials(randL(8))
*/
export const randL = (n) => {
return signal((t, controls) => (nVal) => getRandsAtTime(t, nVal, controls.randSeed).map(Math.abs)).appLeft(reify(n));
return signal((t) => (nVal) => getRandsAtTime(t, nVal).map(Math.abs)).appLeft(reify(n));
};
export const randrun = (n) => {
@@ -1143,26 +1143,3 @@ export const perx = new Pattern(function (state) {
const n = Fraction(1).div(state.span.duration);
return [new Hap(undefined, state.span, Math.log(n) / Math.log(2) + 1)];
});
/**
* A signal that goes from `0` to `1` over one cycle, and then stays at `1` forever.
* Mainly useful in combination with other functions that reset the cycle. See also
* `close`.
* @tags temporal
* @example
* sound("bd sd [- bd] sd".fast(2))
* .lpf(open.slow(4).range(300,3000)) // close envelope over 4 cycles
* .restart("x/4") // restart every 4 cycles
*/
export const open = signal((t) => t.min(1));
/**
* The same as `open`, but goes from `1` to `0` over one cycle, and then
* stays on `0` forever.
* @tags temporal
* @example
* sound("bd sd [- bd] sd".fast(2))
* .lpf(close.slow(4).range(300,3000)) // close envelope over 4 cycles
* .restart("x/4") // restart every 4 cycles
*/
export const close = signal((t) => Fraction(1).sub(t).max(0));
-1
View File
@@ -4,4 +4,3 @@ export * from './draw.mjs';
export * from './pianoroll.mjs';
export * from './spiral.mjs';
export * from './pitchwheel.mjs';
export * from './print.mjs';
-98
View File
@@ -1,98 +0,0 @@
/*
print.mjs - prints hap values to the console or a scrollable inline widget
Copyright (C) 2022 Strudel contributors - see
<https://codeberg.org/uzu/strudel/src/branch/main/packages/draw/print.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, Pattern, stringifyValues } from '@strudel/core';
const printed = {};
// counts .print() calls within one synchronous evaluation, then resets for the
// next
let printIndex = 0;
let printIndexResetQueued = false;
function nextPrintIndex() {
const index = printIndex++;
if (!printIndexResetQueued) {
printIndexResetQueued = true;
queueMicrotask(() => {
printIndex = 0;
printIndexResetQueued = false;
});
}
return index;
}
function formatTime(hap, round, padding) {
const begin = hap.wholeOrPart().begin;
if (round === 0) {
return String(begin.sam().valueOf()).padEnd(padding);
}
const factor = 10 ** round;
const time = Math.round(begin.valueOf() * factor) / factor;
return String(time).padEnd(padding + round + 1);
}
function appendLine(el, text, maxLines) {
const line = document.createElement('div');
line.textContent = text;
el.appendChild(line);
while (el.childElementCount > maxLines) {
el.removeChild(el.firstChild);
}
if (el.follow) {
el.scrollTop = el.scrollHeight;
}
}
/**
* Prints the values of a pattern's events. Without a leading underscore, prints
* to the existing console panel, labeled with its position among other
* `print()` calls, e.g. `[print(line:1)]`. With the `_` prefix, it shows a
* scrollable widget inside the code instead, and its content resets on
* every (re-)evaluation.
*
* @name print
* @tags visualization
* @param {number} width widget width in px, `_print` only. defaults to 600
* @param {number} height widget height in px, `_print` only. defaults to 100
* @param {number} maxLines max lines kept, `_print` only. defaults to 500
* @param {number} round decimal digits for the event time. defaults to 4. `0`
* shows only the cycle
* @param {number} padding integer digits reserved for the cycle, so it stays
* aligned once cycles reach 10 or 100. defaults to 3
* @example
* s("bd sd hh cp").print()
* @example
* s("bd sd hh*2 cp")._print({ round: 5 })
*/
Pattern.prototype.print = function (options = {}) {
const { el, id = 1, maxLines = 500, round = 4, padding = 3 } = options;
if (!el) {
const label = `print(line:${nextPrintIndex() + 1})`;
return this.onTrigger((hap) => {
logger(`[${label}] ${formatTime(hap, round, padding)}: ${stringifyValues(hap.value, true)}`);
}, false);
}
printed[id] = new WeakSet();
return this.draw(
(haps) => {
haps
.filter((hap) => !printed[id].has(hap))
.forEach((hap) => {
printed[id].add(hap);
appendLine(el, `${formatTime(hap, round, padding)}: ${stringifyValues(hap.value, true)}`, maxLines);
});
},
{ lookbehind: 0, lookahead: 0, id },
);
};
+2 -2
View File
@@ -29,10 +29,10 @@
},
"homepage": "https://codeberg.org/uzu/strudel/",
"dependencies": {
"web-tree-sitter": "^0.24.7",
"tree-sitter-haskell": "^0.23.1"
"web-tree-sitter": "^0.24.7"
},
"devDependencies": {
"tree-sitter-haskell": "^0.23.1",
"vite": "^6.0.11"
},
"engines": {
+3 -9
View File
@@ -1,8 +1,6 @@
import Parser from 'web-tree-sitter';
import treeSitterWasm from 'web-tree-sitter/tree-sitter.wasm?url';
import grammarWasm from 'tree-sitter-haskell/tree-sitter-haskell.wasm?url';
let base;
let base = '/';
export function setBase(path) {
base = path;
}
@@ -12,15 +10,11 @@ let isReady = false,
async function _loadParser() {
await Parser.init({
locateFile(scriptName, scriptDirectory) {
if (base) {
return `${base}${scriptName}`;
}
return treeSitterWasm;
return `${base}${scriptName}`;
},
});
parser = new Parser();
let grammarUrl = base ? `${base}tree-sitter-haskell.wasm` : grammarWasm;
const Lang = await Parser.Language.load(grammarUrl);
const Lang = await Parser.Language.load(`${base}tree-sitter-haskell.wasm`);
parser.setLanguage(Lang);
isReady = true;
return parser;
+41
View File
@@ -0,0 +1,41 @@
import { registerChainEffect, getFrequencyFromValue, getWorklet, logger, registerWorklet } from 'superdough';
import workletUrl from './worklet.mjs?audioworklet';
let kabel;
async function initKabelsalat() {
const { SalatRepl } = await import('@kabelsalat/web');
logger('[kabelsalat] ready');
kabel = new SalatRepl({ localScope: true });
return kabel;
}
initKabelsalat().catch((err) => {
logger(`kabelsalat init failed: ${err}`);
});
const compileKabel = (code) => {
if (!kabel) {
throw new Error('kabelsalat still loading');
}
const node = kabel.evaluate(code);
return node.compile({ log: false });
};
registerWorklet(workletUrl);
registerChainEffect('workletSrc', ({ audioContext, fx, value, chainID, start, gateEnd, releaseEnd }) => {
const workletSrc = fx.workletSrc
.replace(/\bpat\[(\d+)\]/g, (_, i) => fx.workletInputs[i])
.replaceAll('sFreq', getFrequencyFromValue(value))
.replaceAll('sGate', `cc('strudel-gate-${chainID}')`);
const { src, ugens, registers } = compileKabel(workletSrc);
const workletNode = getWorklet(audioContext, 'generic-processor', {}, { outputChannelCount: [2] });
workletNode.port.postMessage({
src,
schema: { ugens, registers },
start,
gateEnd,
end: releaseEnd,
});
return workletNode;
});
@@ -1,11 +1,11 @@
{
"name": "@strudel/websocket",
"version": "1.0.0",
"description": "Websocket input for strudel",
"main": "index.mjs",
"name": "@strudel/kabelsalat",
"version": "1.2.6",
"description": "kabelsalat integration for superdough",
"main": "kabelsalat.mjs",
"type": "module",
"publishConfig": {
"main": "dist/index.mjs"
"main": "dist/kabelsalat.mjs"
},
"scripts": {
"build": "vite build",
@@ -22,17 +22,20 @@
"livecoding",
"algorave"
],
"author": "Alex McLean <alex@slab.org>",
"author": "Felix Roos <flix91@gmail.com>",
"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:*"
"superdough": "workspace:*",
"@kabelsalat/lib": "^0.4.1",
"@kabelsalat/web": "^0.4.1"
},
"devDependencies": {
"vite": "^6.0.11"
"vite": "^6.0.11",
"vite-plugin-bundle-audioworklet":"workspace:*"
},
"engines": {
"node": ">=18.0.0"
@@ -1,15 +1,16 @@
import { defineConfig } from 'vite';
import { dependencies } from './package.json';
import { resolve } from 'path';
import bundleAudioWorkletPlugin from 'vite-plugin-bundle-audioworklet';
import { dependencies } from './package.json';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [],
plugins: [bundleAudioWorkletPlugin()],
build: {
lib: {
entry: resolve(__dirname, 'index.mjs'),
entry: resolve(__dirname, 'kabelsalat.mjs'),
formats: ['es'],
fileName: (ext) => ({ es: 'index.mjs' })[ext],
fileName: (ext) => ({ es: 'kabelsalat.mjs' })[ext],
},
rollupOptions: {
external: [...Object.keys(dependencies)],
+83
View File
@@ -0,0 +1,83 @@
import * as ugens from '@kabelsalat/lib/src/ugens.js';
const blockSize = 128;
const UGENS = new Map(Object.entries(ugens));
class GenericProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.playPos = 0;
const channels = 16;
this.outputs = new Array(channels).fill(0);
this.sources = new Array(channels).fill(0);
this.gateEnded = false;
this.started = false;
this.port.onmessage = (event) => {
let {
src,
schema: { ugens, registers },
start,
gateEnd,
end,
} = event.data;
this.start = start;
this.gateEnd = gateEnd;
this.end = end;
this.registers = new Array(registers).fill(0);
this.src = `o.fill(0); // reset outputs\n${src}`;
this.nodes = [];
for (let i = 0; i < ugens.length; i++) {
const ugen = ugens[i];
const nodeClass = UGENS.get(ugen.type);
const node = new nodeClass(i, ugen, sampleRate);
if (node.type === 'cc' && ugen.inputs?.[0]?.includes('strudel-gate')) {
node.setValue(1);
this.gateNode = node;
}
this.nodes[i] = node;
}
this.genSample = new Function(
'time',
'nodes',
'input',
'r', // registers
'o', // outputs
's', // sources
this.src,
);
};
}
process(inputs, outputs) {
const input = inputs[0]?.[0];
if (currentTime >= this.end) {
return false;
} else if (this.genSample === undefined || currentTime < this.start) {
// pending
return true;
}
this.started = true;
if (!this.gateEnded && currentTime > this.gateEnd) {
this.gateNode?.setValue(0);
this.gateEnded = true;
}
const output = outputs[0];
const outL = output[0];
const outR = output[1];
for (let n = 0; n < blockSize; n++) {
this.genSample(this.playPos, this.nodes, input ? input[n] : 0, this.registers, this.outputs, this.sources);
const left = this.outputs[0];
const right = this.outputs[1];
// Spread to stereo if possible; else mixdown to mono
if (outR) {
outL[n] = left;
outR[n] = right;
} else {
outL[n] = 0.5 * (left + right);
}
this.playPos += 1 / sampleRate;
}
return true;
}
}
registerProcessor('generic-processor', GenericProcessor);
+1 -2
View File
@@ -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",
-1
View File
@@ -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'),
-2
View File
@@ -36,8 +36,6 @@
"vite-plugin-bundle-audioworklet": "workspace:*"
},
"dependencies": {
"@kabelsalat/lib": "^0.4.1",
"@kabelsalat/web": "^0.4.1",
"nanostores": "^0.11.3"
},
"engines": {
+20 -29
View File
@@ -16,7 +16,6 @@ import {
gainNode,
getCompressor,
getDistortion,
getFrequencyFromValue,
getLfo,
getWorklet,
releaseAudioNode,
@@ -63,6 +62,11 @@ export function registerSound(key, onTrigger, data = {}) {
soundMap.setKey(key, { onTrigger, data });
}
const chainEffects = {};
export function registerChainEffect(name, effect) {
chainEffects[name] = effect;
}
let gainCurveFunc = (val) => val;
export function applyGainCurve(val) {
@@ -260,14 +264,6 @@ export function loadWorklets() {
return workletsLoading;
}
let kabel;
async function initKabelsalat() {
const { SalatRepl } = await import('@kabelsalat/web');
logger('[kabelsalat] ready');
kabel = new SalatRepl({ localScope: true });
return kabel;
}
// this function should be called on first user interaction (to avoid console warning)
export async function initAudio(options = {}) {
const {
@@ -314,7 +310,6 @@ export async function initAudio(options = {}) {
} catch (err) {
console.warn('could not load AudioWorklet effects', err);
}
await initKabelsalat();
logger('[superdough] ready');
}
let audioReady;
@@ -450,14 +445,6 @@ class Chain {
}
}
const compileKabel = (code) => {
if (!kabel) {
throw new Error('kabelsalat not loaded');
}
const node = kabel.evaluate(code);
return node.compile({ log: false });
};
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
// mapping from main FX and numbered FX chains to nodes
const nodes = { main: {} };
@@ -633,17 +620,21 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future
delaytime = delaytime ?? cycleToSeconds(delaysync, cps);
// Kabelsalat
if (fx.workletSrc !== undefined) {
const workletNode = getWorklet(ac, 'generic-processor', {}, { outputChannelCount: [2] });
chain.connect(workletNode);
const workletSrc = fx.workletSrc
.replace(/\bpat\[(\d+)\]/g, (_, i) => fx.workletInputs[i])
.replaceAll('sFreq', getFrequencyFromValue(value))
.replaceAll('sGate', `cc('strudel-gate-${chainID}')`);
/* global compileKabel */
const { src, ugens, registers } = compileKabel(workletSrc);
workletNode.port.postMessage({ src, schema: { ugens, registers }, start: t, gateEnd: end, end: endWithRelease });
// custom chain effect sink (used for kabelsalat)
for (let key in chainEffects) {
const effect = chainEffects[key];
if (fx[key] !== undefined) {
const node = effect({
audioContext: ac,
fx,
chainID,
value,
start: t,
gateEnd: end,
releaseEnd: endWithRelease,
});
node && chain.connect(node);
}
}
if (fx.stretch !== undefined) {
-81
View File
@@ -5,9 +5,6 @@
import OLAProcessor from './ola-processor';
import FFT from './fft.js';
import { getDistortionAlgorithm } from './helpers.mjs';
import * as ugens from '@kabelsalat/lib/src/ugens.js';
const UGENS = new Map(Object.entries(ugens));
const blockSize = 128;
const PI = Math.PI;
@@ -1492,81 +1489,3 @@ class TransientProcessor extends AudioWorkletProcessor {
}
registerProcessor('transient-processor', TransientProcessor);
class GenericProcessor extends AudioWorkletProcessor {
constructor() {
super();
this.playPos = 0;
const channels = 16;
this.outputs = new Array(channels).fill(0);
this.sources = new Array(channels).fill(0);
this.gateEnded = false;
this.started = false;
this.port.onmessage = (event) => {
let {
src,
schema: { ugens, registers },
start,
gateEnd,
end,
} = event.data;
this.start = start;
this.gateEnd = gateEnd;
this.end = end;
this.registers = new Array(registers).fill(0);
this.src = `o.fill(0); // reset outputs\n${src}`;
this.nodes = [];
for (let i = 0; i < ugens.length; i++) {
const ugen = ugens[i];
const nodeClass = UGENS.get(ugen.type);
const node = new nodeClass(i, ugen, sampleRate);
if (node.type === 'cc' && ugen.inputs?.[0]?.includes('strudel-gate')) {
node.setValue(1);
this.gateNode = node;
}
this.nodes[i] = node;
}
this.genSample = new Function(
'time',
'nodes',
'input',
'r', // registers
'o', // outputs
's', // sources
this.src,
);
};
}
process(inputs, outputs) {
const input = inputs[0]?.[0];
if (currentTime >= this.end) {
return false;
} else if (this.genSample === undefined || currentTime < this.start) {
// pending
return true;
}
this.started = true;
if (!this.gateEnded && currentTime > this.gateEnd) {
this.gateNode?.setValue(0);
this.gateEnded = true;
}
const output = outputs[0];
const outL = output[0];
const outR = output[1];
for (let n = 0; n < blockSize; n++) {
this.genSample(this.playPos, this.nodes, input ? input[n] : 0, this.registers, this.outputs, this.sources);
const left = this.outputs[0];
const right = this.outputs[1];
// Spread to stereo if possible; else mixdown to mono
if (outR) {
outL[n] = left;
outR[n] = right;
} else {
outL[n] = 0.5 * (left + right);
}
this.playPos += 1 / sampleRate;
}
return true;
}
}
registerProcessor('generic-processor', GenericProcessor);
-1
View File
@@ -3,7 +3,6 @@
"version": "0.2.0",
"private": true,
"description": "Experimental Tidal Code interpreter",
"main": "tidal.mjs",
"module": "tidal.mjs",
"repository": {
"type": "git",
+3
View File
@@ -94,6 +94,9 @@ export function getWidgetID(widgetConfig) {
function widgetWithLocation(node, widgetConfig) {
const id = getWidgetID(widgetConfig);
// Store the unique ID back into the config so it's available for widget management
// This is critical for block-based evaluation to match existing widgets with new ones
widgetConfig.id = id;
// add loc as identifier to first argument
// the sliderWithID function is assumed to be sliderWithID(id, value, min?, max?)
node.arguments.unshift({
-6
View File
@@ -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.
-3
View File
@@ -1,3 +0,0 @@
import './websocket.mjs';
export * from './websocket.mjs';
-43
View File
@@ -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] ?? {});
}
+25 -25
View File
@@ -359,13 +359,13 @@ importers:
packages/hs2js:
dependencies:
tree-sitter-haskell:
specifier: ^0.23.1
version: 0.23.1(tree-sitter@0.21.1)
web-tree-sitter:
specifier: ^0.24.7
version: 0.24.7
devDependencies:
tree-sitter-haskell:
specifier: ^0.23.1
version: 0.23.1(tree-sitter@0.21.1)
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)
@@ -389,6 +389,25 @@ 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/kabelsalat:
dependencies:
'@kabelsalat/lib':
specifier: ^0.4.1
version: 0.4.1
'@kabelsalat/web':
specifier: ^0.4.1
version: 0.4.1
superdough:
specifier: workspace:*
version: link:../superdough
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)
vite-plugin-bundle-audioworklet:
specifier: workspace:*
version: link:../vite-plugin-bundle-audioworklet
packages/midi:
dependencies:
'@strudel/core':
@@ -538,9 +557,6 @@ importers:
'@strudel/webaudio':
specifier: workspace:*
version: link:../webaudio
'@strudel/websocket':
specifier: workspace:*
version: link:../websocket
devDependencies:
'@rollup/plugin-replace':
specifier: ^6.0.2
@@ -592,12 +608,6 @@ importers:
packages/superdough:
dependencies:
'@kabelsalat/lib':
specifier: ^0.4.1
version: 0.4.1
'@kabelsalat/web':
specifier: ^0.4.1
version: 0.4.1
nanostores:
specifier: ^0.11.3
version: 0.11.3
@@ -725,16 +735,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':
@@ -834,6 +834,9 @@ importers:
'@strudel/hydra':
specifier: workspace:*
version: link:../packages/hydra
'@strudel/kabelsalat':
specifier: workspace:*
version: link:../packages/kabelsalat
'@strudel/midi':
specifier: workspace:*
version: link:../packages/midi
@@ -870,9 +873,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
-120
View File
@@ -2440,43 +2440,6 @@ exports[`runs examples > example "clip" example index 0 1`] = `
]
`;
exports[`runs examples > example "close" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd cutoff:3000 ]",
"[ 1/8 → 1/4 | s:sd cutoff:2915.625 ]",
"[ 5/16 → 3/8 | s:bd cutoff:2789.0625 ]",
"[ 3/8 → 1/2 | s:sd cutoff:2746.875 ]",
"[ 1/2 → 5/8 | s:bd cutoff:2662.5 ]",
"[ 5/8 → 3/4 | s:sd cutoff:2578.125 ]",
"[ 13/16 → 7/8 | s:bd cutoff:2451.5625 ]",
"[ 7/8 → 1/1 | s:sd cutoff:2409.375 ]",
"[ 1/1 → 9/8 | s:bd cutoff:2325 ]",
"[ 9/8 → 5/4 | s:sd cutoff:2240.625 ]",
"[ 21/16 → 11/8 | s:bd cutoff:2114.0625 ]",
"[ 11/8 → 3/2 | s:sd cutoff:2071.875 ]",
"[ 3/2 → 13/8 | s:bd cutoff:1987.5 ]",
"[ 13/8 → 7/4 | s:sd cutoff:1903.125 ]",
"[ 29/16 → 15/8 | s:bd cutoff:1776.5625 ]",
"[ 15/8 → 2/1 | s:sd cutoff:1734.375 ]",
"[ 2/1 → 17/8 | s:bd cutoff:1650 ]",
"[ 17/8 → 9/4 | s:sd cutoff:1565.625 ]",
"[ 37/16 → 19/8 | s:bd cutoff:1439.0625 ]",
"[ 19/8 → 5/2 | s:sd cutoff:1396.875 ]",
"[ 5/2 → 21/8 | s:bd cutoff:1312.5 ]",
"[ 21/8 → 11/4 | s:sd cutoff:1228.125 ]",
"[ 45/16 → 23/8 | s:bd cutoff:1101.5625 ]",
"[ 23/8 → 3/1 | s:sd cutoff:1059.375 ]",
"[ 3/1 → 25/8 | s:bd cutoff:975 ]",
"[ 25/8 → 13/4 | s:sd cutoff:890.625 ]",
"[ 53/16 → 27/8 | s:bd cutoff:764.0625 ]",
"[ 27/8 → 7/2 | s:sd cutoff:721.875 ]",
"[ 7/2 → 29/8 | s:bd cutoff:637.5 ]",
"[ 29/8 → 15/4 | s:sd cutoff:553.125 ]",
"[ 61/16 → 31/8 | s:bd cutoff:426.5625 ]",
"[ 31/8 → 4/1 | s:sd cutoff:384.375 ]",
]
`;
exports[`runs examples > example "coarse" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:hh coarse:1 ]",
@@ -8764,43 +8727,6 @@ exports[`runs examples > example "onTriggerTime" example index 0 1`] = `
]
`;
exports[`runs examples > example "open" example index 0 1`] = `
[
"[ 0/1 → 1/8 | s:bd cutoff:300 ]",
"[ 1/8 → 1/4 | s:sd cutoff:384.375 ]",
"[ 5/16 → 3/8 | s:bd cutoff:510.9375 ]",
"[ 3/8 → 1/2 | s:sd cutoff:553.125 ]",
"[ 1/2 → 5/8 | s:bd cutoff:637.5 ]",
"[ 5/8 → 3/4 | s:sd cutoff:721.875 ]",
"[ 13/16 → 7/8 | s:bd cutoff:848.4375 ]",
"[ 7/8 → 1/1 | s:sd cutoff:890.625 ]",
"[ 1/1 → 9/8 | s:bd cutoff:975 ]",
"[ 9/8 → 5/4 | s:sd cutoff:1059.375 ]",
"[ 21/16 → 11/8 | s:bd cutoff:1185.9375 ]",
"[ 11/8 → 3/2 | s:sd cutoff:1228.125 ]",
"[ 3/2 → 13/8 | s:bd cutoff:1312.5 ]",
"[ 13/8 → 7/4 | s:sd cutoff:1396.875 ]",
"[ 29/16 → 15/8 | s:bd cutoff:1523.4375 ]",
"[ 15/8 → 2/1 | s:sd cutoff:1565.625 ]",
"[ 2/1 → 17/8 | s:bd cutoff:1650 ]",
"[ 17/8 → 9/4 | s:sd cutoff:1734.375 ]",
"[ 37/16 → 19/8 | s:bd cutoff:1860.9375 ]",
"[ 19/8 → 5/2 | s:sd cutoff:1903.125 ]",
"[ 5/2 → 21/8 | s:bd cutoff:1987.5 ]",
"[ 21/8 → 11/4 | s:sd cutoff:2071.875 ]",
"[ 45/16 → 23/8 | s:bd cutoff:2198.4375 ]",
"[ 23/8 → 3/1 | s:sd cutoff:2240.625 ]",
"[ 3/1 → 25/8 | s:bd cutoff:2325 ]",
"[ 25/8 → 13/4 | s:sd cutoff:2409.375 ]",
"[ 53/16 → 27/8 | s:bd cutoff:2535.9375 ]",
"[ 27/8 → 7/2 | s:sd cutoff:2578.125 ]",
"[ 7/2 → 29/8 | s:bd cutoff:2662.5 ]",
"[ 29/8 → 15/4 | s:sd cutoff:2746.875 ]",
"[ 61/16 → 31/8 | s:bd cutoff:2873.4375 ]",
"[ 31/8 → 4/1 | s:sd cutoff:2915.625 ]",
]
`;
exports[`runs examples > example "orbit" example index 0 1`] = `
[
"[ 0/1 → 1/6 | s:hh delay:0.5 delaytime:0.25 orbit:1 ]",
@@ -10004,52 +9930,6 @@ exports[`runs examples > example "pressBy" example index 0 1`] = `
]
`;
exports[`runs examples > example "print" example index 0 1`] = `
[
"[ 0/1 → 1/4 | s:bd ]",
"[ 1/4 → 1/2 | s:sd ]",
"[ 1/2 → 3/4 | s:hh ]",
"[ 3/4 → 1/1 | s:cp ]",
"[ 1/1 → 5/4 | s:bd ]",
"[ 5/4 → 3/2 | s:sd ]",
"[ 3/2 → 7/4 | s:hh ]",
"[ 7/4 → 2/1 | s:cp ]",
"[ 2/1 → 9/4 | s:bd ]",
"[ 9/4 → 5/2 | s:sd ]",
"[ 5/2 → 11/4 | s:hh ]",
"[ 11/4 → 3/1 | s:cp ]",
"[ 3/1 → 13/4 | s:bd ]",
"[ 13/4 → 7/2 | s:sd ]",
"[ 7/2 → 15/4 | s:hh ]",
"[ 15/4 → 4/1 | s:cp ]",
]
`;
exports[`runs examples > example "print" example index 1 1`] = `
[
"[ 0/1 → 1/4 | s:bd ]",
"[ 1/4 → 1/2 | s:sd ]",
"[ 1/2 → 5/8 | s:hh ]",
"[ 5/8 → 3/4 | s:hh ]",
"[ 3/4 → 1/1 | s:cp ]",
"[ 1/1 → 5/4 | s:bd ]",
"[ 5/4 → 3/2 | s:sd ]",
"[ 3/2 → 13/8 | s:hh ]",
"[ 13/8 → 7/4 | s:hh ]",
"[ 7/4 → 2/1 | s:cp ]",
"[ 2/1 → 9/4 | s:bd ]",
"[ 9/4 → 5/2 | s:sd ]",
"[ 5/2 → 21/8 | s:hh ]",
"[ 21/8 → 11/4 | s:hh ]",
"[ 11/4 → 3/1 | s:cp ]",
"[ 3/1 → 13/4 | s:bd ]",
"[ 13/4 → 7/2 | s:sd ]",
"[ 7/2 → 29/8 | s:hh ]",
"[ 29/8 → 15/4 | s:hh ]",
"[ 15/4 → 4/1 | s:cp ]",
]
`;
exports[`runs examples > example "progNum" example index 0 1`] = `
[
"[ 0/1 → 1/1 | note:c4 progNum:10 midichan:1 ]",
-1
View File
@@ -97,7 +97,6 @@ const toneHelpersMocked = {
'_pitchwheel',
'_pianoroll',
'_spectrum',
'_print',
'markcss',
'p',
'dough',
-1
View File
@@ -80,7 +80,6 @@ export default defineConfig({
/^https:\/\/freesound\.org\/.*/i,
/^https:\/\/cdn\.freesound\.org\/.*/i,
/^https:\/\/shabda\.ndre\.gr\/.*/i,
/^https:\/\/felixroos\.github\.io\/webaudiofontdata\/.*/i,
].some((regex) => regex.test(url)),
handler: 'CacheFirst',
options: {
+1 -1
View File
@@ -48,9 +48,9 @@
"@strudel/tonal": "workspace:*",
"@strudel/transpiler": "workspace:*",
"@strudel/webaudio": "workspace:*",
"@strudel/websocket": "workspace:*",
"@strudel/mondo": "workspace:*",
"@strudel/xen": "workspace:*",
"@strudel/kabelsalat": "workspace:*",
"@supabase/supabase-js": "^2.48.1",
"@tailwindcss/forms": "^0.5.10",
"@tailwindcss/postcss": "^4.0.0",
@@ -1,3 +0,0 @@
<script is:inline>
window.location.pathname = `/workshop/getting-started`;
</script>
@@ -0,0 +1,90 @@
---
title: Getting Started
layout: ../../layouts/MainLayout.astro
---
import { MiniRepl } from '../../docs/MiniRepl';
import { JsDoc } from '../../docs/JsDoc';
# Welcome
Welcome to the Strudel documentation pages!
These pages will introduce you to [Strudel](https://strudel.cc/), a web-based [live coding](https://github.com/toplap/awesome-livecoding/) environment that implements the [Tidal Cycles](https://tidalcycles.org) algorithmic pattern language.
# What is Strudel?
[Strudel](https://strudel.cc/) is a version of [Tidal Cycles](https://tidalcycles.org) written in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), initiated by [Alex McLean](https://slab.org) and [Felix Roos](https://froos.cc/) in 2022.
Tidal Cycles, also known as Tidal, is a language for [algorithmic pattern](https://algorithmicpattern.org), and though it is most commonly used for [making music](https://tidalcycles.org/docs/showcase), it can be used for any kind of pattern making activity, including [weaving](https://www.youtube.com/watch?v=TfEmEsusXjU).
Tidal was first implemented as a library written in the [Haskell](https://www.haskell.org/) functional programming language, and by itself it does not make any sound.
To make sound, it has to be connected to a sound engine, and by default this is a [SuperCollider](https://supercollider.github.io/) plugin called [SuperDirt](https://github.com/musikinformatik/SuperDirt/).
As such, it can be difficult for first-time users to install both Tidal Cycles and SuperDirt, as there are many small details to get right.
Strudel however runs directly in your web browser, does not require any custom software installation, and can make sound all by itself.
# Strudel REPL and MiniREPL
The main place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/) ([what is a REPL?](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), but in these pages you will also encounter interactive "MiniREPLs" where you can listen to and edit Strudel patterns.
Try clicking the play icon below:
<MiniRepl client:idle tune={`s("bd sd")`} punchcard />
Then edit the text so it reads `s("bd sd cp hh")` and click the refresh icon.
Congratulations, you have now live coded your first Strudel pattern!
With Strudel, you can expressively write dynamic music pieces.
You don't need to know JavaScript or Tidal Cycles to make music with Strudel.
This interactive tutorial will guide you through the basics of Strudel.
# Show me some demos!
To see and hear what Strudel can do, visit the [Strudel REPL](https://strudel.cc/) and click the Shuffle icon in the top menu bar.
You can get a feel for Strudel by browsing and editing these examples and clicking the Refresh icon to update.
You can also browse through the examples [here](/examples).
Alternatively, you can get a taste of what Strudel can do by clicking play on this track:
<MiniRepl
client:idle
tune={`samples({
bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav','bd/BT0A0DA.wav','bd/BT0A0D3.wav','bd/BT0A0D0.wav','bd/BT0A0A7.wav'],
sd: ['sd/rytm-01-classic.wav','sd/rytm-00-hard.wav'],
hh: ['hh27/000_hh27closedhh.wav','hh/000_hh3closedhh.wav'],
}, 'github:tidalcycles/dirt-samples');
stack(
s("bd,[~ <sd!3 sd(3,4,2)>],hh*8") // drums
.speed(perlin.range(.7,.9)) // random sample speed variation
,"<a1 b1\*2 a1(3,8) e2>" // bassline
.off(1/8,x=>x.add(12).degradeBy(.5)) // random octave jumps
.add(perlin.range(0,.5)) // random pitch variation
.superimpose(add(.05)) // add second, slightly detuned voice
.note() // wrap in "note"
.decay(.15).sustain(0) // make each note of equal length
.s('sawtooth') // waveform
.gain(.4) // turn down
.cutoff(sine.slow(7).range(300,5000)) // automate cutoff
,"<Am7!3 <Em7 E7b13 Em7 Ebm7b5>>".voicings('lefthand') // chords
.superimpose(x=>x.add(.04)) // add second, slightly detuned voice
.add(perlin.range(0,.5)) // random pitch variation
.note() // wrap in "note"
.s('sawtooth') // waveform
.gain(.16) // turn down
.cutoff(500) // fixed cutoff
.attack(1) // slowly fade in
)
.slow(3/2)`}
/>
# Strudel is a work in progress 🚧
Please note that this project is still in its experimental state.
In the future, parts of it might change significantly.
This tutorial is also far from complete.
You can contribute to it clicking 'Edit this page' in the top right, or by visiting the [Strudel GitHub page](https://codeberg.org/uzu/strudel/).
# What's next?
Head on over to the [Notes](/learn/notes) page.
<br />
-3
View File
@@ -1,3 +0,0 @@
<script is:inline>
window.location.pathname = `/workshop/first-notes`;
</script>
+90
View File
@@ -0,0 +1,90 @@
---
title: Notes
layout: ../../layouts/MainLayout.astro
---
import { MiniRepl } from '../../docs/MiniRepl';
import { JsDoc } from '../../docs/JsDoc';
# Notes
Pitches are an important building block in many musical traditions.
In Strudel, pitches can be expressed as note names, note numbers or frequencies.
Here's the same pattern written in three different ways:
- `note`: letter notation, good for those who are familiar with western music theory:
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
- `note`: number notation, good for those who want to use recognisable pitches, but don't care about music theory:
<MiniRepl client:idle tune={`note("57 61 64 69")`} />
- `freq`: frequency notation, good for those who want to go beyond standardised tuning systems:
<MiniRepl client:idle tune={`freq("220 275 330 440")`} />
Let's look at those in more detail...
## `note` names
Notes names can be notated with the note letter, followed by the octave number. You can notate flats with `b` and sharps with `#`.
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
By the way, you can edit the contents of the player, and press "update" to hear your change!
You can also press "play" on the next player without needing to stop the last one.
## `note` numbers
If you prefer, you can also use numbers with `note` instead:
<MiniRepl client:idle tune={`note("57 61 64 69")`} />
These numbers are interpreted as so called [MIDI numbers](https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies), where adjacent whole numbers are one 'semitone' apart.
You could also write decimal numbers to get 'microtonal' pitches (in between the black and white piano notes):
<MiniRepl client:idle tune={`note("74.5 75 75.5 76")`} />
## `freq`
To get maximum freedom, you can also use `freq` to directly control the frequency:
<MiniRepl client:idle tune={`freq("220 275 330 440")`} />
## Hearing and frequency
In the above example, we play A3 (220Hz), C#4 natural (275Hz), E4 (330Hz) and A4 (440Hz), mirroring our previous examples.
But can you hear the difference between these individual frequencies?
<MiniRepl client:idle tune={`freq("220 221 223 224")`} />
How about these?
<MiniRepl client:idle tune={`freq("2020 2021 2023 2024")`} />
The higher we go up...
<MiniRepl client:idle tune={`freq("5020 5021 5023 5024")`} />
The less distance we can hear between the frequencies!
<MiniRepl client:idle tune={`freq("10020 10021 10023 10024")`} />
Why is this? [Human hearing operates logarithmically](https://www.audiocheck.net/soundtests_nonlinear.php).
## From notes to sounds
In this page, when we played a pattern of notes like this:
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
We heard a simple synthesised sound, in fact we heard a [triangle wave oscillator](https://en.wikipedia.org/wiki/Triangle_wave).
This is the default synthesiser used by Strudel, but how do we then make different sounds in Strudel?
Let's find out in the next page on [Sounds](/learn/sounds).
<br />
-3
View File
@@ -1,3 +0,0 @@
<script is:inline>
window.location.pathname = `/workshop/first-sounds`;
</script>
+40
View File
@@ -0,0 +1,40 @@
---
title: Sounds
layout: ../../layouts/MainLayout.astro
---
import { MiniRepl } from '../../docs/MiniRepl';
import { JsDoc } from '../../docs/JsDoc';
# Sounds
We can play sounds with `s`, in two different ways:
- `s` can trigger audio samples, where a sound file is loaded in the background and played back:
<MiniRepl client:idle tune={`s("bd hh sd hh")`} />
- `s` can trigger audio synthesisers, which are synthesised in real-time using code also running in the background:
<MiniRepl client:idle tune={`s("sawtooth square triangle sine")`} />
You can learn more about both of these approaches in the pages [Synths](/learn/synths) and [Samples](/learn/samples).
# Combining notes and sounds
In both of the above cases, we are no longer directly controlling the `note`/`freq` of the sound heard via `s`, as we were in the [Notes](/workshop/first-notes/) page.
So how can we both control the sound and the pitch? We can _combine_ `note`/`freq` with `s` to change the sound of our pitches:
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4").s("sawtooth")`} />
<MiniRepl client:idle tune={`note("57 61 64 69").s("sine")`} />
<MiniRepl client:idle tune={`freq("220 275 330 440").s("triangle")`} />
The last example will actually sound the same with or without `s`, because `triangle` is the default value for `s`.
What about combining different notes with different sounds at the same time?
<MiniRepl client:idle tune={`freq("220 275 330 440 550").s("triangle sawtooth sine")`} />
Hmm, something interesting is going on there, related to there being five notes and three sounds.
Let's now take a step back and think about the Strudel [Code](/learn/code/) we've been hearing so far.
@@ -103,10 +103,6 @@ What follows is the API doc of all the options you can pass:
<JsDoc client:idle name="spectrum" h={0} />
## Print
<JsDoc client:idle name="print" h={0} />
## markcss
<JsDoc client:idle name="markcss" h={0} />
+1 -1
View File
@@ -186,7 +186,7 @@ But don't worry if you don't know these terms, as they are not required to make
</Box>
**Add a rest in a sequence with '-' or '~'**
**Add a rests in a sequence with '-' or '~'**
<MiniRepl client:visible tune={`sound("bd hh - rim - bd hh rim")`} punchcard />
+9 -30
View File
@@ -13,41 +13,24 @@ import { examples } from '../../examples.mjs';
Welcome to the Strudel documentation pages!
You've come to the right place if you want to learn how to make music with code.
These pages will introduce you to [Strudel](https://strudel.cc/), a web-based [live coding](https://codeberg.org/toplap/awesome-livecoding/) environment that implements the [Tidal Cycles](https://tidalcycles.org) algorithmic pattern language.
## What is Strudel?
With Strudel, you can expressively write dynamic music pieces.<br/>
[Strudel](https://strudel.cc/) is a version of [Tidal Cycles](https://tidalcycles.org) written in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), initiated by [Alex McLean](https://slab.org) and [Felix Roos](https://froos.cc/) in 2022, quickly growing into a collective free/open source project with major [contributors and maintainers](https://codeberg.org/uzu/strudel/activity/contributors) including [Jade Rowland](https://www.instagram.com/_switch_angel/) and [Aria](https://www.instagram.com/gglossingg/).
Tidal Cycles, also known as Tidal, is a language for [algorithmic pattern](https://algorithmicpattern.org), and though it is most commonly used for [making music](https://tidalcycles.org/docs/showcase), it can be used for any kind of pattern making activity, including [weaving](https://www.youtube.com/watch?v=TfEmEsusXjU).
Tidal was first implemented as a library written in the [Haskell](https://www.haskell.org/) functional programming language, and by itself it does not make any sound.
To make sound, it has to be connected to a sound engine, and by default this is a [SuperCollider](https://supercollider.github.io/) plugin called [SuperDirt](https://codeberg.org/musikinformatik/SuperDirt).
As such, it can be difficult for first-time users to install both Tidal Cycles and SuperDirt, as there are many small details to get right.
Strudel however runs directly in your web browser, does not require any custom software installation, and can make sound all by itself.
It is an official port of the [Tidal Cycles](https://tidalcycles.org/) pattern language to JavaScript.<br/>
You don't need to know JavaScript or Tidal Cycles to make music with Strudel.
This interactive tutorial will guide you through the basics of Strudel.<br/>
The best place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/)
<div className="clear-both" />
## What can you do with Strudel?
- Live code music: make music with code in real time.
- Algorithmic composition: compose music using tidal's unique approach to pattern manipulation.
- Teaching: focussing on a low barrier of entry, Strudel is a good fit for teaching music and code at the same time.
- Integrate into your existing music setup: either via MIDI or OSC, you can use Strudel as a really flexible sequencer.
- live code music: make music with code in real time
- algorithmic composition: compose music using tidal's unique approach to pattern manipulation
- teaching: focussing on a low barrier of entry, Strudel is a good fit for teaching music and code at the same time.
- integrate into your existing music setup: either via MIDI or OSC, you can use Strudel as a really flexible sequencer
## Strudel REPL and MiniREPL
The main place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/) ([what is a REPL?](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), but in these pages you will also encounter interactive "MiniREPLs" where you can listen to and edit Strudel patterns.
Try clicking the play icon below:
<MiniRepl client:idle tune={`s("bd sd")`} punchcard />
Then edit the text so it reads `s("bd sd cp hh")` and click the refresh icon.
Congratulations, you have now live coded your first Strudel pattern!
## Show me some demos!
## Examples
Here are some examples of how strudel can sound:
@@ -55,10 +38,6 @@ Here are some examples of how strudel can sound:
These examples cannot fully encompass the variety of things you can do, so [check out the showcase](/intro/showcase/) for some videos of how people use Strudel.
## Contribute to Strudel
You can contribute to it clicking 'Edit this page' in the top right, or by visiting the [Strudel Codeberg page](https://codeberg.org/uzu/strudel/).
## Getting Started
The best way to start learning Strudel is the workshop.
+2 -1
View File
@@ -89,6 +89,7 @@ export function loadModules() {
import('@strudel/mqtt'),
import('@strudel/mondo'),
import('@strudel/dough'),
import('@strudel/kabelsalat'),
];
if (isTauri()) {
modules = modules.concat([
@@ -97,7 +98,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);