Compare commits

..

26 Commits

Author SHA1 Message Date
froos 401491fdba Merge branch 'main' into daslyfe/defaultgain 2025-10-20 20:37:50 +02:00
Switch Angel AKA Jade Rose 6e58c973af Merge pull request 'Bug Fix: Wavetable: phase wrapping at 1 and detune' (#1620) from glossing/strudel:glossing/wrap-phase-typo into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1620
2025-10-18 04:29:19 +02:00
Switch Angel AKA Jade Rose 2473a5391d Merge branch 'main' into glossing/wrap-phase-typo 2025-10-17 04:55:25 +02:00
froos 4e17cfbdd6 Merge pull request 'github samples: default to "samples" if repository is not specified' (#1644) from prezmop/strudel:main into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1644
2025-10-16 20:26:26 +02:00
prezmop 83c7e63432 update docs 2025-10-16 18:20:22 +02:00
prezmop 909e0154fe default to samples if repo not found 2025-10-16 18:20:13 +02:00
froos ef4e21ac40 Merge pull request 'Docs: add example of custom chained function' (#1642) from dariusk/strudel:main into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1642
2025-10-16 17:33:39 +02:00
Aria 3c1a8c8bdb Format 2025-10-14 11:41:11 -05:00
Aria b7e941c649 Merge branch 'main' into glossing/wrap-phase-typo 2025-10-14 11:40:29 -05:00
Switch Angel AKA Jade Rose ded91fab7d Merge pull request 'Feature: Distortion Modes' (#1561) from glossing/strudel:glossing/distortion-modes into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1561
2025-10-13 07:26:50 +02:00
Darius Kazemi 9c5c71c31a Removing semicolon to be more idiomatic;;; 2025-10-11 17:52:26 -07:00
Darius Kazemi af53bab259 Fixing some syntax and a typo 2025-10-11 17:50:58 -07:00
Darius Kazemi 0065db8569 Docs: add example of custom chained function
This adds a subsection to the "Understand/Coding Syntax" documentation that shows a simple example of converting the previous chain of effects into a custom, reusable chained function. There's also a prompt for the reader to experiment.
2025-10-11 17:40:55 -07:00
Aria 6f703e48e7 Merge branch 'main' into glossing/wrap-phase-typo 2025-10-08 16:44:35 -05:00
Aria 1ae773acc4 Merge branch 'main' into glossing/wrap-phase-typo 2025-10-05 18:21:05 -05:00
Aria 120f89d57f Handle detune in the presence of pitch envelope 2025-10-04 01:37:57 -05:00
Aria 99e14dae5c Consistency 2025-10-02 01:12:42 -05:00
Aria ac582b4d40 Wrap properly when phase === 1 2025-10-02 01:06:29 -05:00
Felix Roos ef13c45496 fix: also adjust gain curve for 1.2 2025-07-05 13:04:51 +02:00
Felix Roos 1a279ef536 Merge remote-tracking branch 'origin/main' into daslyfe/defaultgain 2025-07-05 12:55:26 +02:00
Felix Roos dc62fea714 set default gain to .8 if version tag is set <= 1.2 2025-07-05 12:47:58 +02:00
daslyfe 940d36436b Merge branch 'main' into daslyfe/defaultgain 2025-06-28 22:08:14 +02:00
Jade (Rose) Rowland 3a483c0669 working 2025-06-27 16:12:06 -04:00
Jade (Rose) Rowland 0df20ca5bf gainlin 2025-06-27 16:12:00 -04:00
Jade (Rose) Rowland 39b9d2b9b5 Merge branch 'main' into daslyfe/defaultgain 2025-06-27 16:00:41 -04:00
Jade (Rose) Rowland 91d7a09c06 default to 1 2025-04-27 16:30:20 -04:00
12 changed files with 149 additions and 39 deletions
+12
View File
@@ -396,6 +396,18 @@ export const { velocity } = registerControl('velocity');
*
*/
export const { gain } = registerControl('gain');
/**
* Applies a linear gain adjustment
*
* @name gainlinear
* @synonyms gainlin
* @param {number | Pattern} amount gainlin
* @example
* s("hh*8").gainlin(".4!2 1 .4!2 1 .4 1").fast(2)
*
*/
export const { gainlinear, gainlin } = registerControl('gainlinear', 'gainlin');
/**
* Gain applied after all effects have been processed.
*
View File
+1
View File
@@ -153,6 +153,7 @@ samples('github:tidalcycles/dirt-samples')
The format is `github:<user>/<repo>/<branch>`.
If `<repo>` and `<branch>` are not specified, they will default to `samples` and `main` respectively.
It expects a `strudel.json` file to be present at the root of the given repository, which declares the sample paths in the repo.
The format is also expected to be the same as explained above.
+12 -5
View File
@@ -121,13 +121,20 @@ function githubPath(base, subpath = '') {
if (!base.startsWith('github:')) {
throw new Error('expected "github:" at the start of pseudoUrl');
}
let [_, path] = base.split('github:');
let path = base.slice('github:'.length);
path = path.endsWith('/') ? path.slice(0, -1) : path;
if (path.split('/').length === 2) {
// assume main as default branch if none set
path += '/main';
let components = path.split('/');
let user = components[0];
let repo = components.length >= 2 ? components[1] : 'samples';
let branch = components.length >= 3 ? components[2] : 'main';
let other = components.slice(3);
if (subpath) {
other.push(subpath);
}
return `https://raw.githubusercontent.com/${path}/${subpath}`;
other = other.join('/');
return `https://raw.githubusercontent.com/${user}/${repo}/${branch}/${other}`;
}
export const processSampleMap = (sampleMap, fn, baseUrl = sampleMap._base || '') => {
+16 -15
View File
@@ -37,7 +37,7 @@ export function registerSound(key, onTrigger, data = {}) {
soundMap.setKey(key, { onTrigger, data });
}
let gainCurveFunc = (val) => val;
let gainCurveFunc = (val) => Math.pow(val, 2);
export function applyGainCurve(val) {
return gainCurveFunc(val);
@@ -141,9 +141,9 @@ export const getAudioDevices = async () => {
return devicesMap;
};
let defaultDefaultValues = {
const defaultDefaultValues = {
s: 'triangle',
gain: 0.8,
gain: 1,
postgain: 1,
density: '.03',
ftype: '12db',
@@ -166,17 +166,6 @@ let defaultDefaultValues = {
fft: 8,
};
const defaultDefaultDefaultValues = Object.freeze({ ...defaultDefaultValues });
export function setDefault(control, value) {
// const main = getControlName(control); // we cant do this because superdough is independent of strudel/core
defaultDefaultValues[control] = value;
}
export function resetDefaults() {
defaultDefaultValues = { ...defaultDefaultDefaultValues };
}
let defaultControls = new Map(Object.entries(defaultDefaultValues));
export function setDefaultValue(key, value) {
@@ -195,9 +184,17 @@ export function resetDefaultValues() {
}
export function setVersionDefaults(version) {
resetDefaultValues();
if (version === '1.0') {
const v = Number(version);
if (v <= 1.0) {
setDefaultValue('fanchor', 0.5);
}
if (v <= 1.2) {
setDefaultValue('gain', 0.8);
setGainCurve((v) => v);
} else {
setDefaultValue('gain', 1);
setGainCurve((v) => Math.pow(v, 2));
}
}
export const resetLoadedSounds = () => soundMap.set({});
@@ -406,6 +403,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
bank,
source,
gain = getDefaultValue('gain'),
gainlinear,
postgain = getDefaultValue('postgain'),
density = getDefaultValue('density'),
duckorbit,
@@ -503,6 +501,9 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
velocity = applyGainCurve(velocity);
tremolodepth = applyGainCurve(tremolodepth);
gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future
if (gainlinear != null) {
gain *= gainlinear;
}
const end = t + hapDuration;
const endWithRelease = end + release;
+2 -2
View File
@@ -231,12 +231,12 @@ export async function onTriggerSynth(t, value, onended, tables, cps, frameLen) {
begin: t,
end: envEnd,
frequency,
detune: value.detune,
freqspread: value.detune,
position: value.wt,
warp: value.warp,
warpMode: warpmode,
voices: Math.max(value.unison ?? 1, 1),
spread: value.spread,
panspread: value.spread,
phaserand: (value.wtphaserand ?? value.unison > 1) ? 1 : 0,
},
{ outputChannelCount: [2] },
+17 -13
View File
@@ -1050,14 +1050,15 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
return [
{ name: 'begin', defaultValue: 0, min: 0, max: Number.POSITIVE_INFINITY },
{ name: 'end', defaultValue: 0, min: 0, max: Number.POSITIVE_INFINITY },
{ name: 'frequency', defaultValue: 220, minValue: 0.01, maxValue: 20000 },
{ name: 'detune', defaultValue: 0.18 },
{ name: 'position', defaultValue: 0, minValue: 0, maxValue: 1 },
{ name: 'warp', defaultValue: 0, minValue: 0, maxValue: 1 },
{ name: 'frequency', defaultValue: 440, min: Number.EPSILON },
{ name: 'detune', defaultValue: 0 },
{ name: 'freqspread', defaultValue: 0.18, min: 0 },
{ name: 'position', defaultValue: 0, min: 0, max: 1 },
{ name: 'warp', defaultValue: 0, min: 0, max: 1 },
{ name: 'warpMode', defaultValue: 0 },
{ name: 'voices', defaultValue: 1, minValue: 1, maxValue: 32 },
{ name: 'spread', defaultValue: 0.7, minValue: 0, maxValue: 1 },
{ name: 'phaserand', defaultValue: 0, minValue: 0, maxValue: 1 },
{ name: 'voices', defaultValue: 1, min: 1 },
{ name: 'panspread', defaultValue: 0.7, min: 0, max: 1 },
{ name: 'phaserand', defaultValue: 0, min: 0, max: 1 },
];
}
@@ -1235,10 +1236,12 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
_sampleFrame(frame, phase) {
const len = frame.length;
const pos = phase * len;
const i = pos | 0;
let i = pos | 0;
if (i >= len) i = 0; // fast wrap
const frac = pos - i;
const a = frame[i];
const i1 = i + 1 < len ? i + 1 : 0; // fast wrap
let i1 = i + 1;
if (i1 >= len) i1 = 0;
const b = frame[i1];
return a + (b - a) * frac;
}
@@ -1268,6 +1271,7 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
}
for (let i = 0; i < outL.length; i++) {
const detune = pv(parameters.detune, i);
const freqspread = pv(parameters.freqspread, i);
const tablePos = clamp(pv(parameters.position, i), 0, 1);
const idx = tablePos * (this.numFrames - 1);
const fIdx = idx | 0;
@@ -1276,9 +1280,9 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
const warpMode = pv(parameters.warpMode, i);
const voices = pv(parameters.voices, i);
const phaseRand = clamp(pv(parameters.phaserand, i), 0, 1);
const spread = voices > 1 ? clamp(pv(parameters.spread, i), 0, 1) : 0;
const gain1 = Math.sqrt(0.5 - 0.5 * spread);
const gain2 = Math.sqrt(0.5 + 0.5 * spread);
const panspread = voices > 1 ? clamp(pv(parameters.panspread, i), 0, 1) : 0;
const gain1 = Math.sqrt(0.5 - 0.5 * panspread);
const gain2 = Math.sqrt(0.5 + 0.5 * panspread);
let f = pv(parameters.frequency, i);
f = applySemitoneDetuneToFrequency(f, detune / 100); // overall detune
const normalizer = 1 / Math.sqrt(voices);
@@ -1291,7 +1295,7 @@ class WavetableOscillatorProcessor extends AudioWorkletProcessor {
gainL = gain2;
gainR = gain1;
}
const fVoice = applySemitoneDetuneToFrequency(f, getUnisonDetune(voices, detune, n)); // voice detune
const fVoice = applySemitoneDetuneToFrequency(f, getUnisonDetune(voices, freqspread, n)); // voice detune
const dPhase = fVoice * this.invSR;
const level = this._chooseMip(dPhase);
const table = this.tables[level];
+69
View File
@@ -4527,6 +4527,75 @@ exports[`runs examples > example "gain" example index 0 1`] = `
]
`;
exports[`runs examples > example "gainlinear" example index 0 1`] = `
[
"[ 0/1 → 1/16 | s:hh gainlinear:0.4 ]",
"[ 1/16 → 1/8 | s:hh gainlinear:0.4 ]",
"[ 1/8 → 3/16 | s:hh gainlinear:1 ]",
"[ 3/16 → 1/4 | s:hh gainlinear:0.4 ]",
"[ 1/4 → 5/16 | s:hh gainlinear:0.4 ]",
"[ 5/16 → 3/8 | s:hh gainlinear:1 ]",
"[ 3/8 → 7/16 | s:hh gainlinear:0.4 ]",
"[ 7/16 → 1/2 | s:hh gainlinear:1 ]",
"[ 1/2 → 9/16 | s:hh gainlinear:0.4 ]",
"[ 9/16 → 5/8 | s:hh gainlinear:0.4 ]",
"[ 5/8 → 11/16 | s:hh gainlinear:1 ]",
"[ 11/16 → 3/4 | s:hh gainlinear:0.4 ]",
"[ 3/4 → 13/16 | s:hh gainlinear:0.4 ]",
"[ 13/16 → 7/8 | s:hh gainlinear:1 ]",
"[ 7/8 → 15/16 | s:hh gainlinear:0.4 ]",
"[ 15/16 → 1/1 | s:hh gainlinear:1 ]",
"[ 1/1 → 17/16 | s:hh gainlinear:0.4 ]",
"[ 17/16 → 9/8 | s:hh gainlinear:0.4 ]",
"[ 9/8 → 19/16 | s:hh gainlinear:1 ]",
"[ 19/16 → 5/4 | s:hh gainlinear:0.4 ]",
"[ 5/4 → 21/16 | s:hh gainlinear:0.4 ]",
"[ 21/16 → 11/8 | s:hh gainlinear:1 ]",
"[ 11/8 → 23/16 | s:hh gainlinear:0.4 ]",
"[ 23/16 → 3/2 | s:hh gainlinear:1 ]",
"[ 3/2 → 25/16 | s:hh gainlinear:0.4 ]",
"[ 25/16 → 13/8 | s:hh gainlinear:0.4 ]",
"[ 13/8 → 27/16 | s:hh gainlinear:1 ]",
"[ 27/16 → 7/4 | s:hh gainlinear:0.4 ]",
"[ 7/4 → 29/16 | s:hh gainlinear:0.4 ]",
"[ 29/16 → 15/8 | s:hh gainlinear:1 ]",
"[ 15/8 → 31/16 | s:hh gainlinear:0.4 ]",
"[ 31/16 → 2/1 | s:hh gainlinear:1 ]",
"[ 2/1 → 33/16 | s:hh gainlinear:0.4 ]",
"[ 33/16 → 17/8 | s:hh gainlinear:0.4 ]",
"[ 17/8 → 35/16 | s:hh gainlinear:1 ]",
"[ 35/16 → 9/4 | s:hh gainlinear:0.4 ]",
"[ 9/4 → 37/16 | s:hh gainlinear:0.4 ]",
"[ 37/16 → 19/8 | s:hh gainlinear:1 ]",
"[ 19/8 → 39/16 | s:hh gainlinear:0.4 ]",
"[ 39/16 → 5/2 | s:hh gainlinear:1 ]",
"[ 5/2 → 41/16 | s:hh gainlinear:0.4 ]",
"[ 41/16 → 21/8 | s:hh gainlinear:0.4 ]",
"[ 21/8 → 43/16 | s:hh gainlinear:1 ]",
"[ 43/16 → 11/4 | s:hh gainlinear:0.4 ]",
"[ 11/4 → 45/16 | s:hh gainlinear:0.4 ]",
"[ 45/16 → 23/8 | s:hh gainlinear:1 ]",
"[ 23/8 → 47/16 | s:hh gainlinear:0.4 ]",
"[ 47/16 → 3/1 | s:hh gainlinear:1 ]",
"[ 3/1 → 49/16 | s:hh gainlinear:0.4 ]",
"[ 49/16 → 25/8 | s:hh gainlinear:0.4 ]",
"[ 25/8 → 51/16 | s:hh gainlinear:1 ]",
"[ 51/16 → 13/4 | s:hh gainlinear:0.4 ]",
"[ 13/4 → 53/16 | s:hh gainlinear:0.4 ]",
"[ 53/16 → 27/8 | s:hh gainlinear:1 ]",
"[ 27/8 → 55/16 | s:hh gainlinear:0.4 ]",
"[ 55/16 → 7/2 | s:hh gainlinear:1 ]",
"[ 7/2 → 57/16 | s:hh gainlinear:0.4 ]",
"[ 57/16 → 29/8 | s:hh gainlinear:0.4 ]",
"[ 29/8 → 59/16 | s:hh gainlinear:1 ]",
"[ 59/16 → 15/4 | s:hh gainlinear:0.4 ]",
"[ 15/4 → 61/16 | s:hh gainlinear:0.4 ]",
"[ 61/16 → 31/8 | s:hh gainlinear:1 ]",
"[ 31/8 → 63/16 | s:hh gainlinear:0.4 ]",
"[ 63/16 → 4/1 | s:hh gainlinear:1 ]",
]
`;
exports[`runs examples > example "gap" example index 0 1`] = `[]`;
exports[`runs examples > example "grow" example index 0 1`] = `
+17
View File
@@ -60,6 +60,23 @@ Strudel makes heavy use of chained functions. Here is a more sophisticated examp
.room(0.5)`}
/>
## Write your own chained function
You can write your own chained function using `register`. Here's the above chain but registered as a reusable, chained function.
<MiniRepl
client:idle
tune={`const effectChain = register('effectChain', (pat) => pat
.s("sawtooth")
.cutoff(500)
//.delay(0.5)
.room(0.5)
)
note("a3 c#4 e4 a4").effectChain()`}
/>
Try adding `.rev()` after `effectChain()` to hear further effects added.
# Comments
The `//` in the example above is a line comment, resulting in the `delay` function being ignored.
+1 -1
View File
@@ -381,7 +381,7 @@ Sampler effects are functions that can be used to change the behaviour of sample
### scrub
<JsDoc client:idle name="Pattern.scrub" h={0} />{' '}
<JsDoc client:idle name="Pattern.scrub" h={0} />
### speed
@@ -117,7 +117,7 @@ export function SettingsTab({ started }) {
const canChangeAudioDevice = AudioContext.prototype.setSinkId != null;
return (
<div className="text-foreground p-4 space-y-4 w-full" style={{ fontFamily }}>
{canChangeAudioDevice && (
<FormItem label="Audio Output Device">
<AudioDeviceSelector
isDisabled={started}
@@ -132,6 +132,7 @@ export function SettingsTab({ started }) {
}}
/>
</FormItem>
)}
<FormItem label="Audio Engine Target">
<AudioEngineTargetSelector
target={audioEngineTarget}
-2
View File
@@ -13,7 +13,6 @@ import {
resetGlobalEffects,
resetLoadedSounds,
initAudioOnFirstClick,
resetDefaults,
} from '@strudel/webaudio';
import { setVersionDefaultsFrom } from './util.mjs';
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
@@ -182,7 +181,6 @@ export function useReplContext() {
const resetEditor = async () => {
(await getModule('@strudel/tonal'))?.resetVoicings();
resetDefaults();
resetGlobalEffects();
clearCanvas();
clearHydra();