mirror of
https://codeberg.org/uzu/strudel
synced 2026-12-05 13:27:25 -05:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cd7c88e768 | |||
| a261d47b4e | |||
| 8b1d68e494 | |||
| 1686ff877c | |||
| 83b1c89d25 | |||
| 1743f65e61 | |||
| bb4b8bb27e | |||
| bdac0eccbd | |||
| 6333fa1ddf | |||
| 41e6084823 | |||
| fe9a75c9b6 | |||
| cd7c1dbd97 | |||
| 25b9fd991a | |||
| 375b25afd7 | |||
| afc7f1aab1 | |||
| 5e82110522 | |||
| 4616b374f3 | |||
| 98b71bcb4d | |||
| cf7dae5d7f | |||
| b3d9eab3b6 | |||
| c799a686c0 | |||
| f805560827 | |||
| f8bb10d2a0 | |||
| a160f76d23 | |||
| 3fc1cc871c | |||
| 2c2c6bc6bf | |||
| 089187b9b2 | |||
| dc441e68df | |||
| c6253789ab | |||
| b8b59d911f | |||
| a5079db6f7 | |||
| 36647afbbf | |||
| 7a343930aa | |||
| 266e5da109 | |||
| 3c32b3b0aa | |||
| c492e21e1d |
@@ -0,0 +1,41 @@
|
||||
name: Build and Deploy labeled serve-hot PRs
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [labeled]
|
||||
|
||||
# Allow one concurrent deployment
|
||||
concurrency:
|
||||
group: "warm-pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: ${{ github.event.label.name == 'serve-hot' }}
|
||||
runs-on: docker
|
||||
container: node:22-bookworm
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
allow-unsafe-pr-checkout: true
|
||||
- uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Install Dependencies
|
||||
run: pnpm install
|
||||
|
||||
- name: Build
|
||||
run: pnpm build
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
run: |
|
||||
eval $(ssh-agent -s)
|
||||
echo "$SSH_PRIVATE_KEY" | ssh-add -
|
||||
apt update && apt install -y rsync
|
||||
mkdir -p ~/.ssh
|
||||
ssh-keyscan matrix.toplap.org > ~/.ssh/known_hosts
|
||||
rsync -atv --delete --delete-after --progress \
|
||||
./website/dist/ \
|
||||
strudel@matrix.toplap.org:/home/strudel/deploy/pr-${{ github.event.pull_request.number }}.hot.strudel.cc
|
||||
@@ -1,23 +1,23 @@
|
||||
name: Build and Deploy hot PRs
|
||||
name: Build and Deploy to hot.strudel.cc on merge
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [labeled]
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
# Allow one concurrent deployment
|
||||
concurrency:
|
||||
group: "warm-pages"
|
||||
cancel-in-progress: false
|
||||
group: "pages"
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
if: ${{ github.event.label.name == 'serve-hot' }}
|
||||
runs-on: docker
|
||||
container: node:22-bookworm
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- uses: pnpm/action-setup@v4
|
||||
|
||||
- name: Install Dependencies
|
||||
@@ -27,14 +27,10 @@ jobs:
|
||||
run: pnpm build
|
||||
|
||||
- name: Deploy
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
run: |
|
||||
eval $(ssh-agent -s)
|
||||
echo "$SSH_PRIVATE_KEY" | ssh-add -
|
||||
apt update && apt install -y rsync
|
||||
mkdir -p ~/.ssh
|
||||
ssh-keyscan matrix.toplap.org > ~/.ssh/known_hosts
|
||||
rsync -atv --delete --delete-after --progress \
|
||||
./website/dist/ \
|
||||
strudel@matrix.toplap.org:/home/strudel/deploy/pr-${{ github.event.pull_request.number }}.hot.strudel.cc
|
||||
mkdir ~/.ssh
|
||||
ssh-keyscan matrix.toplap.org > ~/.ssh/known_hosts
|
||||
rsync -atv --delete --delete-after --progress ./website/dist/ strudel@matrix.toplap.org:/home/strudel/deploy/hot.strudel.cc
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
name: Build and Deploy to warm (strudel.cc)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
on: [workflow_dispatch]
|
||||
|
||||
# Allow one concurrent deployment
|
||||
concurrency:
|
||||
+1
-1
@@ -80,4 +80,4 @@
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
||||
import { basicSetup } from './basicSetup.mjs';
|
||||
import { flash, isFlashEnabled } from './flash.mjs';
|
||||
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
||||
import { keybindings } from './keybindings.mjs';
|
||||
import { editorActions, keybindings } from './keybindings.mjs';
|
||||
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
||||
import { activateTheme, initTheme, theme } from './themes.mjs';
|
||||
import { isTooltipEnabled } from './tooltip.mjs';
|
||||
@@ -101,6 +101,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
||||
syntaxHighlighting(defaultHighlightStyle),
|
||||
EditorView.updateListener.of((v) => onChange(v)),
|
||||
drawSelection({ cursorBlinkRate: 0 }),
|
||||
editorActions.of({ onEvaluate, onStop }),
|
||||
Prec.highest(
|
||||
keymap.of([
|
||||
{
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { defaultKeymap } from '@codemirror/commands';
|
||||
import { Prec, EditorState } from '@codemirror/state';
|
||||
import { defaultKeymap, toggleLineComment } from '@codemirror/commands';
|
||||
import { Facet, Prec, EditorState } from '@codemirror/state';
|
||||
import { keymap, ViewPlugin } from '@codemirror/view';
|
||||
// import { searchKeymap } from '@codemirror/search';
|
||||
import { emacs } from '@replit/codemirror-emacs';
|
||||
import { vim } from '@replit/codemirror-vim';
|
||||
import { vim, Vim } from '@replit/codemirror-vim';
|
||||
// import { vim } from './vim_test.mjs';
|
||||
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
||||
|
||||
// Per-editor way to plumb down { onEvaluate, onStop }, provided by initEditor.
|
||||
export const editorActions = Facet.define({ combine: (values) => values[0] ?? {} });
|
||||
|
||||
const vscodePlugin = ViewPlugin.fromClass(
|
||||
class {
|
||||
constructor() {}
|
||||
@@ -26,7 +29,18 @@ const keymaps = {
|
||||
vscode: vscodeExtension,
|
||||
};
|
||||
|
||||
export { Vim } from '@replit/codemirror-vim';
|
||||
export { Vim }; // export for patterns/prebake to define custom actions
|
||||
|
||||
Vim.defineEx('write', 'w', (cm) => cm.cm6.state.facet(editorActions).onEvaluate?.());
|
||||
Vim.defineEx('quit', 'q', (cm) => cm.cm6.state.facet(editorActions).onStop?.());
|
||||
|
||||
Vim.defineOperator('toggleComment', (cm, _args, _ranges, oldAnchor) => {
|
||||
// By the time an operator runs, vim has selected the motion's range in the
|
||||
// real editor so we can just call the normal codemirror command
|
||||
toggleLineComment(cm.cm6);
|
||||
return oldAnchor;
|
||||
});
|
||||
Vim.mapCommand('gc', 'operator', 'toggleComment', {}, { isEdit: true });
|
||||
|
||||
export function keybindings(name) {
|
||||
const active = keymaps[name];
|
||||
|
||||
+473
-2
@@ -4,8 +4,19 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
|
||||
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 } from './logger.mjs';
|
||||
import { Pattern, pure, register, reify } from './pattern.mjs';
|
||||
import {
|
||||
Pattern,
|
||||
pure,
|
||||
register,
|
||||
reify,
|
||||
logger,
|
||||
stack,
|
||||
slowcat,
|
||||
Fraction,
|
||||
sequence,
|
||||
lcm,
|
||||
__steps,
|
||||
} from '@strudel/pattern';
|
||||
|
||||
export function createParam(names) {
|
||||
let isMulti = Array.isArray(names);
|
||||
@@ -1297,6 +1308,16 @@ export const { channel } = registerControl('channel');
|
||||
*
|
||||
*/
|
||||
export const { cut } = registerControl('cut');
|
||||
/**
|
||||
* Similar to 'cut', but notes that begin at the same time don't cut eachother off.
|
||||
*
|
||||
* @name scut
|
||||
* @tags superdough
|
||||
* @param {number | Pattern} group scut group number
|
||||
* @example
|
||||
* chord("C G").voicing().s("piano").scut(1)
|
||||
*/
|
||||
export const { scut, stackcut } = registerControl('scut', 'stackCut');
|
||||
/**
|
||||
* Applies the cutoff frequency of the **l**ow-**p**ass **f**ilter.
|
||||
*
|
||||
@@ -3311,3 +3332,453 @@ export const bmod = (config) => pure({}).bmod(config);
|
||||
export const { transient } = registerControl(['transient', 'transsustain']);
|
||||
|
||||
export const { FXrelease, FXrel, FXr, fxr } = registerControl('FXrelease', 'FXrel', 'FXr', 'fxr');
|
||||
|
||||
// moved from pattern.mjs, because they use controls:
|
||||
|
||||
/**
|
||||
* Both speeds up the pattern (like 'fast') and the sample playback (like 'speed').
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("bd sd:2").hurry("<1 2 4 3>").slow(1.5)
|
||||
*/
|
||||
export const hurry = register('hurry', function (r, pat) {
|
||||
return pat._fast(r).mul(pure({ speed: r }));
|
||||
});
|
||||
|
||||
/**
|
||||
* Jux with adjustable stereo width. 0 = mono, 1 = full stereo.
|
||||
* @tags temporal
|
||||
* @name juxBy
|
||||
* @synonyms juxby
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxBy("<0 .5 1>/2", rev)
|
||||
*/
|
||||
export const { juxBy, juxby } = register(['juxBy', 'juxby'], function (by, func, pat) {
|
||||
by /= 2;
|
||||
const elem_or = function (dict, key, dflt) {
|
||||
if (key in dict) {
|
||||
return dict[key];
|
||||
}
|
||||
return dflt;
|
||||
};
|
||||
const left = pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) - by }));
|
||||
const right = func(pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) + by })));
|
||||
|
||||
return stack(left, right).setSteps(__steps ? lcm(left._steps, right._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Like juxBy, except it flips the ears each cycle.
|
||||
* @name juxFlipBy
|
||||
* @synonyms juxflipby, fluxBy, fluxby
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlipBy(".8", rev)
|
||||
*/
|
||||
export const { juxFlipBy, juxflipby, fluxBy, fluxby } = register(
|
||||
['juxFlipBy', 'juxflipby', 'fluxBy', 'fluxby'],
|
||||
function (by, func, pat) {
|
||||
return pat.juxBy(slowcat(by, -by), func);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* The jux function creates strange stereo effects, by applying a function to a pattern, but only in the right-hand channel.
|
||||
* @tags temporal, superdough
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(rev)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(press)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(iter(4))
|
||||
*/
|
||||
export const jux = register('jux', function (func, pat) {
|
||||
return pat._juxBy(1, func, pat);
|
||||
});
|
||||
|
||||
/**
|
||||
* Like jux, but flips the ears each cycle.
|
||||
* @name juxFlip
|
||||
* @synonyms juxflip, flux
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(rev)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(press)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(iter(4))
|
||||
*/
|
||||
export const { juxFlip, flux } = register(['juxFlip', 'juxflip', 'flux'], function (func, pat) {
|
||||
return pat._juxFlipBy(1, func, pat);
|
||||
});
|
||||
|
||||
/**
|
||||
* Superimpose and offset multiple times, gradually decreasing the velocity
|
||||
* @tags temporal
|
||||
* @name echo
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @param {number} times how many times to repeat
|
||||
* @param {number} time cycle offset between iterations
|
||||
* @param {number} feedback velocity multiplicator for each iteration
|
||||
* @example
|
||||
* s("bd sd").echo(3, 1/6, .8)
|
||||
*/
|
||||
export const echo = register('echo', function (times, time, feedback, pat) {
|
||||
return pat._echoWith(times, time, (pat, i) => pat.gain(Math.pow(feedback, i)));
|
||||
});
|
||||
|
||||
/**
|
||||
* Deprecated. Like echo, but the last 2 parameters are flipped.
|
||||
* @tags temporal
|
||||
* @name stut
|
||||
* @param {number} times how many times to repeat
|
||||
* @param {number} feedback velocity multiplicator for each iteration
|
||||
* @param {number} time cycle offset between iterations
|
||||
* @example
|
||||
* s("bd sd").stut(3, .8, 1/6)
|
||||
*/
|
||||
export const stut = register('stut', function (times, feedback, time, pat) {
|
||||
return pat._echoWith(times, time, (pat, i) => pat.gain(Math.pow(feedback, i)));
|
||||
});
|
||||
|
||||
/**
|
||||
* Sets the pattern's color to the given [hsla](https://www.w3schools.com/htmL/html_colors_hsl.asp)
|
||||
*
|
||||
* @name hsla
|
||||
* @param {number} hue (0 - 360)
|
||||
* @param {number} saturation percentage (0 - 100)
|
||||
* @param {number} lightness percentage (0 - 100)
|
||||
* @param {number} alpha (transparency) (0.0 - 1.0)
|
||||
* @tags visualization
|
||||
*/
|
||||
export const hsla = register('hsla', (h, s, l, a, pat) => {
|
||||
return pat.color(`hsla(${h}turn,${s * 100}%,${l * 100}%,${a})`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Sets the pattern's color to the given [hsl](https://www.w3schools.com/htmL/html_colors_hsl.asp)
|
||||
*
|
||||
* @name hsl
|
||||
* @param {number} hue (0 - 360)
|
||||
* @param {number} saturation percentage (0 - 100)
|
||||
* @param {number} lightness percentage (0 - 100)
|
||||
* @tags visualization
|
||||
*/
|
||||
export const hsl = register('hsl', (h, s, l, pat) => {
|
||||
return pat.color(`hsl(${h}turn,${s * 100}%,${l * 100}%)`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Cuts each sample into the given number of parts, allowing you to explore a technique known as 'granular synthesis'.
|
||||
* It turns a pattern of samples into a pattern of parts of samples.
|
||||
* @name chop
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes")
|
||||
* .chop(4)
|
||||
* .rev() // reverse order of chops
|
||||
* .loopAt(2) // fit sample into 2 cycles
|
||||
*
|
||||
*/
|
||||
export const chop = register('chop', function (n, pat) {
|
||||
const slices = Array.from({ length: n }, (x, i) => i);
|
||||
const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n }));
|
||||
const merge = function (a, b) {
|
||||
if ('begin' in a && 'end' in a && a.begin !== undefined && a.end !== undefined) {
|
||||
const d = a.end - a.begin;
|
||||
b = { begin: a.begin + b.begin * d, end: a.begin + b.end * d };
|
||||
}
|
||||
// return a;
|
||||
return Object.assign({}, a, b);
|
||||
};
|
||||
const func = function (o) {
|
||||
return sequence(slice_objects.map((slice_o) => merge(o, slice_o)));
|
||||
};
|
||||
return pat.squeezeBind(func).setSteps(__steps ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Cuts each sample into the given number of parts, triggering progressive portions of each sample at each loop.
|
||||
* @name striate
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("numbers:0 numbers:1 numbers:2").striate(6).slow(3)
|
||||
*/
|
||||
export const striate = register('striate', function (n, pat) {
|
||||
const slices = Array.from({ length: n }, (x, i) => i);
|
||||
const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n }));
|
||||
const slicePat = slowcat(...slice_objects);
|
||||
return pat
|
||||
.set(slicePat)
|
||||
._fast(n)
|
||||
.setSteps(__steps ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Makes the sample fit the given number of cycles by changing the speed.
|
||||
* @param {number} factor
|
||||
* @param {Pattern} pat
|
||||
* @param {number} [cps=0.5]
|
||||
* @name loopAt
|
||||
* @tags samples, pitch
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes").loopAt(2)
|
||||
*/
|
||||
const _loopAt = function (factor, pat, cps = 0.5) {
|
||||
return pat
|
||||
.speed((1 / factor) * cps)
|
||||
.unit('c')
|
||||
.slow(factor);
|
||||
};
|
||||
|
||||
export const { loopAt, loopat } = register(['loopAt', 'loopat'], function (factor, pat) {
|
||||
const steps = pat._steps ? pat._steps.div(factor) : undefined;
|
||||
return new Pattern((state) => _loopAt(factor, pat, state.controls._cps).query(state), steps);
|
||||
});
|
||||
|
||||
/**
|
||||
* Chops samples into the given number of slices, triggering those slices with a given pattern of slice numbers.
|
||||
* Instead of a number, it also accepts a list of numbers from 0 to 1 to slice at specific points.
|
||||
* @name slice
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks165").slice(8, "0 1 <2 2*2> 3 [4 0] 5 6 7".every(3, rev)).slow(0.75)
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks125").fit().slice([0,.25,.5,.75], "0 1 1 <2 3>")
|
||||
*/
|
||||
|
||||
export const slice = register(
|
||||
'slice',
|
||||
function (npat, ipat, opat) {
|
||||
return npat
|
||||
.innerBind((n) =>
|
||||
ipat.outerBind((i) =>
|
||||
opat.outerBind((o) => {
|
||||
// If it's not an object, assume it's a string and make it a 's' control parameter
|
||||
o = o instanceof Object ? o : { s: o };
|
||||
const begin = Array.isArray(n) ? n[i] : i / n;
|
||||
const end = Array.isArray(n) ? n[i + 1] : (i + 1) / n;
|
||||
return pure({ begin, end, _slices: n, ...o });
|
||||
}),
|
||||
),
|
||||
)
|
||||
.setSteps(ipat._steps);
|
||||
},
|
||||
false, // turns off auto-patternification
|
||||
);
|
||||
|
||||
/**
|
||||
* Works the same as slice, but changes the playback speed of each slice to match the duration of its step.
|
||||
* @name splice
|
||||
* @tags samples, pitch
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks165")
|
||||
* .splice(8, "0 1 [2 3 0]@2 3 0@2 7")
|
||||
*/
|
||||
|
||||
export const splice = register(
|
||||
'splice',
|
||||
function (npat, ipat, opat) {
|
||||
const sliced = slice(npat, ipat, opat);
|
||||
return new Pattern((state) => {
|
||||
// TODO - default cps to 0.5
|
||||
const cps = state.controls._cps || 1;
|
||||
const haps = sliced.query(state);
|
||||
return haps.map((hap) =>
|
||||
hap.withValue((v) => ({
|
||||
...{
|
||||
speed: (cps / v._slices / hap.whole.duration) * (v.speed || 1),
|
||||
unit: 'c',
|
||||
},
|
||||
...v,
|
||||
})),
|
||||
);
|
||||
}).setSteps(ipat._steps);
|
||||
},
|
||||
false, // turns off auto-patternification
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes the sample fit its event duration. Good for rhythmical loops like drum breaks.
|
||||
* Similar to `loopAt`.
|
||||
* @name fit
|
||||
* @tags samples, pitch
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes/2").fit()
|
||||
*/
|
||||
export const fit = register('fit', (pat) =>
|
||||
pat.withHaps((haps, state) =>
|
||||
haps.map((hap) =>
|
||||
hap.withValue((v) => {
|
||||
const slicedur = ('end' in v ? v.end : 1) - ('begin' in v ? v.begin : 0);
|
||||
return {
|
||||
...v,
|
||||
speed: ((state.controls._cps || 1) / hap.whole.duration) * slicedur,
|
||||
unit: 'c',
|
||||
};
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes the sample fit the given number of cycles and cps value, by
|
||||
* changing the speed. deprecated: use loopAt or fit instead, together with setCps / setCpm.
|
||||
* @name loopAtCps
|
||||
* @tags samples, pitch
|
||||
* @memberof Pattern.prototype
|
||||
* @deprecated
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes").loopAtCps(4,1.5).cps(1.5)
|
||||
*/
|
||||
export const { loopAtCps, loopatcps } = register(['loopAtCps', 'loopatcps'], function (factor, cps, pat) {
|
||||
return _loopAt(factor, pat, cps);
|
||||
});
|
||||
|
||||
let fadeGain = (p) => (p < 0.5 ? 1 : 1 - (p - 0.5) / 0.5);
|
||||
|
||||
/**
|
||||
* Cross-fades between left and right from 0 to 1:
|
||||
* - 0 = (full left, no right)
|
||||
* - .5 = (both equal)
|
||||
* - 1 = (no left, full right)
|
||||
*
|
||||
* @param {Pattern} a
|
||||
* @param {Pattern} pos
|
||||
* @param {Pattern} b
|
||||
* @name xfade
|
||||
* @tags amplitude
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* xfade(s("bd*2"), "<0 .25 .5 .75 1>", s("hh*8"))
|
||||
*/
|
||||
export let xfade = (a, pos, b) => {
|
||||
pos = reify(pos);
|
||||
a = reify(a);
|
||||
b = reify(b);
|
||||
let gaina = pos.fmap((v) => ({ gain: fadeGain(v) }));
|
||||
let gainb = pos.fmap((v) => ({ gain: fadeGain(1 - v) }));
|
||||
return stack(a.mul(gaina), b.mul(gainb));
|
||||
};
|
||||
|
||||
// the prototype version is actually flipped so left/right makes sense
|
||||
Pattern.prototype.xfade = function (pos, b) {
|
||||
return xfade(this, pos, b);
|
||||
};
|
||||
|
||||
const _distortWithAlg = function (name) {
|
||||
const func = function (args, pat) {
|
||||
const argsPat = reify(args).fmap((v) => (Array.isArray(v) ? [...v, name] : [v, 1, name]));
|
||||
if (!pat) {
|
||||
return pure({}).distort(argsPat);
|
||||
}
|
||||
return pat.distort(argsPat);
|
||||
};
|
||||
Pattern.prototype[name] = function (args) {
|
||||
return func(args, this);
|
||||
};
|
||||
return func;
|
||||
};
|
||||
|
||||
/**
|
||||
* Soft-clipping distortion
|
||||
*
|
||||
* @name soft
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const soft = _distortWithAlg('soft');
|
||||
|
||||
/**
|
||||
* Hard-clipping distortion
|
||||
*
|
||||
* @name hard
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const hard = _distortWithAlg('hard');
|
||||
|
||||
/**
|
||||
* Cubic polynomial distortion
|
||||
*
|
||||
* @name cubic
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const cubic = _distortWithAlg('cubic');
|
||||
|
||||
/**
|
||||
* Diode-emulating distortion
|
||||
*
|
||||
* @name diode
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const diode = _distortWithAlg('diode');
|
||||
|
||||
/**
|
||||
* Asymmetrical diode distortion
|
||||
*
|
||||
* @name asym
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const asym = _distortWithAlg('asym');
|
||||
|
||||
/**
|
||||
* Wavefolding distortion
|
||||
*
|
||||
* @name fold
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const fold = _distortWithAlg('fold');
|
||||
|
||||
/**
|
||||
* Wavefolding distortion composed with sinusoid
|
||||
*
|
||||
* @name sinefold
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const sinefold = _distortWithAlg('sinefold');
|
||||
|
||||
/**
|
||||
* Distortion via Chebyshev polynomials
|
||||
*
|
||||
* @name chebyshev
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const chebyshev = _distortWithAlg('chebyshev');
|
||||
|
||||
@@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import createClock from './zyklus.mjs';
|
||||
import { errorLogger, logger } from './logger.mjs';
|
||||
import { errorLogger, logger } from '@strudel/pattern';
|
||||
|
||||
export class Cyclist {
|
||||
constructor({
|
||||
|
||||
@@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
|
||||
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/>.
|
||||
*/
|
||||
|
||||
export const strudelScope = {};
|
||||
import { strudelScope } from '@strudel/pattern';
|
||||
|
||||
export const evalScope = async (...args) => {
|
||||
const results = await Promise.allSettled(args);
|
||||
|
||||
+35
-27
@@ -5,37 +5,45 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import * as controls from './controls.mjs'; // legacy
|
||||
export * from './euclid.mjs';
|
||||
import Fraction from './fraction.mjs';
|
||||
import createClock from './zyklus.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
export { Fraction, controls, createClock };
|
||||
import { Pattern } from '@strudel/pattern';
|
||||
export { controls, createClock };
|
||||
export * from '@strudel/pattern';
|
||||
export * from './controls.mjs';
|
||||
export * from './cyclist.mjs';
|
||||
export * from './evaluate.mjs';
|
||||
export * from './hap.mjs';
|
||||
export * from './impure.mjs';
|
||||
export * from './logger.mjs';
|
||||
export * from './pattern.mjs';
|
||||
export * from './pick.mjs';
|
||||
export * from './repl.mjs';
|
||||
export * from './signal.mjs';
|
||||
export * from './speak.mjs';
|
||||
export * from './state.mjs';
|
||||
export * from './schedulerState.mjs';
|
||||
export * from './timespan.mjs';
|
||||
export * from './ui.mjs';
|
||||
export * from './util.mjs';
|
||||
export { default as drawLine } from './drawLine.mjs';
|
||||
// below won't work with runtime.mjs (json import fails)
|
||||
/* import * as p from './package.json';
|
||||
export const version = p.version; */
|
||||
logger('🌀 @strudel/core loaded 🌀');
|
||||
if (globalThis._strudelLoaded) {
|
||||
console.warn(
|
||||
`@strudel/core was loaded more than once...
|
||||
This might happen when you have multiple versions of strudel installed.
|
||||
Please check with "npm ls @strudel/core".`,
|
||||
);
|
||||
}
|
||||
globalThis._strudelLoaded = true;
|
||||
export * from './evaluate.mjs';
|
||||
import { getClockTime } from './schedulerState.mjs';
|
||||
|
||||
// legacy:
|
||||
Pattern.prototype.onTrigger = function (onTrigger, dominant = true) {
|
||||
console.warn('onTrigger is deprecated.. use onSchedule(hap, time, cps) instead');
|
||||
return this.onSchedule((hap, t, cps) => {
|
||||
const currentTime = getClockTime();
|
||||
return onTrigger(hap, currentTime, cps, t);
|
||||
}, dominant);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* make something happen on event time
|
||||
* uses browser timeout which is innacurate for audio tasks
|
||||
* @param {Function} func
|
||||
* @name onTriggerTime
|
||||
* @tags external_io
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("bd!8").onTriggerTime((hap) => {console.log(hap)})
|
||||
*/
|
||||
Pattern.prototype.onTriggerTime = function (func) {
|
||||
return this.onSchedule((hap, targetTime) => {
|
||||
const diff = targetTime - getClockTime();
|
||||
setTimeout(() => {
|
||||
func(hap);
|
||||
}, diff * 1000);
|
||||
}, false);
|
||||
};
|
||||
|
||||
@@ -4,8 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
|
||||
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 } from './logger.mjs';
|
||||
import { ClockCollator, cycleToSeconds } from './util.mjs';
|
||||
import { logger, ClockCollator, cycleToSeconds } from '@strudel/pattern';
|
||||
|
||||
export class NeoCyclist {
|
||||
constructor({ onSchedule, onToggle, getTime, onTrigger }) {
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
},
|
||||
"homepage": "https://strudel.cc",
|
||||
"dependencies": {
|
||||
"fraction.js": "^5.2.1"
|
||||
"fraction.js": "^5.2.1",
|
||||
"@strudel/pattern": "workspace:*"
|
||||
},
|
||||
"gitHead": "0e26d4e741500f5bae35b023608f062a794905c2",
|
||||
"devDependencies": {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { NeoCyclist } from './neocyclist.mjs';
|
||||
import { evalScope } from './evaluate.mjs';
|
||||
import { Cyclist } from './cyclist.mjs';
|
||||
import { reset_state } from '@strudel/pattern';
|
||||
import { evaluate as _evaluate } from './evaluate.mjs';
|
||||
import { errorLogger, logger } from './logger.mjs';
|
||||
import { errorLogger, logger, register, Pattern, isPattern, silence, stack } from '@strudel/pattern';
|
||||
import {
|
||||
setCpsFunc,
|
||||
setIsStarted,
|
||||
@@ -10,9 +12,6 @@ import {
|
||||
setScheduleFunc,
|
||||
setClockTime,
|
||||
} from './schedulerState.mjs';
|
||||
import { evalScope } from './evaluate.mjs';
|
||||
import { register, Pattern, isPattern, silence, stack } from './pattern.mjs';
|
||||
import { reset_state } from './impure.mjs';
|
||||
|
||||
export function repl({
|
||||
onSchedule,
|
||||
|
||||
@@ -7,7 +7,8 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import { s, pan, getControlName } from '../controls.mjs';
|
||||
import { mini } from '../../mini/mini.mjs';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import Fraction from '../fraction.mjs';
|
||||
import { Fraction, sequence, pure, fast, stack } from '@strudel/pattern';
|
||||
import { sameFirst } from '../../pattern/test/pattern.test.mjs';
|
||||
|
||||
describe('controls', () => {
|
||||
it('should support controls', () => {
|
||||
@@ -44,3 +45,117 @@ describe('controls', () => {
|
||||
expect(getControlName('cutoff')).toEqual('cutoff');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chop', () => {
|
||||
it('Can _chop(2)', () => {
|
||||
expect(sequence({ sound: 'a' }, { sound: 'b' })._chop(2).firstCycle()).toStrictEqual(
|
||||
sequence(
|
||||
{ sound: 'a', begin: 0, end: 0.5 },
|
||||
{ sound: 'a', begin: 0.5, end: 1 },
|
||||
{ sound: 'b', begin: 0, end: 0.5 },
|
||||
{ sound: 'b', begin: 0.5, end: 1 },
|
||||
).firstCycle(),
|
||||
);
|
||||
});
|
||||
it('Can chop(2,3)', () => {
|
||||
expect(pure({ sound: 'a' }).fast(2).chop(2, 3).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
sequence(
|
||||
[
|
||||
{ sound: 'a', begin: 0, end: 0.5 },
|
||||
{ sound: 'a', begin: 0.5, end: 1 },
|
||||
],
|
||||
[
|
||||
{ sound: 'a', begin: 0, end: 1 / 3 },
|
||||
{ sound: 'a', begin: 1 / 3, end: 2 / 3 },
|
||||
{ sound: 'a', begin: 2 / 3, end: 1 },
|
||||
],
|
||||
)
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
it('Can chop chops', () => {
|
||||
expect(pure({ s: 'bev' }).chop(2).chop(2).firstCycle()).toStrictEqual(pure({ s: 'bev' }).chop(4).firstCycle());
|
||||
});
|
||||
});
|
||||
|
||||
describe('loopAt', () => {
|
||||
it('maintains steps', () => {
|
||||
expect(s('bev').chop(8).loopAt(2)._steps).toStrictEqual(Fraction(4));
|
||||
});
|
||||
});
|
||||
|
||||
describe('_steps', () => {
|
||||
it('Is correctly preserved/calculated through transformations', () => {
|
||||
expect(sequence({ n: 0 }, { n: 1 }, { n: 2 }).chop(4)._steps).toStrictEqual(Fraction(12));
|
||||
expect(sequence(0, 1, 2, 3).hurry(4)._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).chop(4)._steps).toStrictEqual(Fraction(8));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).striate(4)._steps).toStrictEqual(Fraction(8));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).slice(4, sequence(0, 1, 2, 3))._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).splice(4, sequence(0, 1, 2, 3))._steps).toStrictEqual(
|
||||
Fraction(4),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hurry', () => {
|
||||
it('Can speed up patterns and sounds', () => {
|
||||
sameFirst(s(sequence('a', 'b')).hurry(2), s(sequence('a', 'b')).fast(2).set({ speed: 2 }));
|
||||
});
|
||||
});
|
||||
|
||||
describe('jux', () => {
|
||||
it('Can juxtapose', () => {
|
||||
expect(pure({ a: 1 }).jux(fast(2)).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
stack(pure({ a: 1, pan: 0 }), pure({ a: 1, pan: 1 }).fast(2))
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('juxBy', () => {
|
||||
it('Can juxtapose by half', () => {
|
||||
expect(pure({ a: 1 }).juxBy(0.5, fast(2)).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
stack(pure({ a: 1, pan: 0.25 }), pure({ a: 1, pan: 0.75 }).fast(2))
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('striate', () => {
|
||||
it('Can striate(2)', () => {
|
||||
sameFirst(
|
||||
sequence({ sound: 'a' }).striate(2),
|
||||
sequence({ sound: 'a', begin: 0, end: 0.5 }, { sound: 'a', begin: 0.5, end: 1 }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('slice', () => {
|
||||
it('Can slice a sample', () => {
|
||||
sameFirst(
|
||||
s('break').slice(4, sequence(0, 1, 2, 3)),
|
||||
sequence(
|
||||
{ begin: 0, end: 0.25, s: 'break', _slices: 4 },
|
||||
{ begin: 0.25, end: 0.5, s: 'break', _slices: 4 },
|
||||
{ begin: 0.5, end: 0.75, s: 'break', _slices: 4 },
|
||||
{ begin: 0.75, end: 1, s: 'break', _slices: 4 },
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('splice', () => {
|
||||
it('Can splice a sample', () => {
|
||||
sameFirst(
|
||||
s('break').splice(4, sequence(0, 1, 2, 3)),
|
||||
sequence(
|
||||
{ begin: 0, end: 0.25, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.25, end: 0.5, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.5, end: 0.75, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.75, end: 1, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { logger } from '../core/logger.mjs';
|
||||
import { logger } from '@strudel/core';
|
||||
|
||||
// listen for log events from the Tauri backend and log in the UI
|
||||
await listen('log-event', (e) => {
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@strudel/kabelsalat",
|
||||
"version": "1.2.6",
|
||||
"description": "kabelsalat integration for superdough",
|
||||
"main": "kabelsalat.mjs",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"main": "dist/kabelsalat.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"prepublishOnly": "npm run build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"titdalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
"algorave"
|
||||
],
|
||||
"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": {
|
||||
"superdough": "workspace:*",
|
||||
"@kabelsalat/lib": "^0.4.1",
|
||||
"@kabelsalat/web": "^0.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.11",
|
||||
"vite-plugin-bundle-audioworklet":"workspace:*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { resolve } from 'path';
|
||||
import bundleAudioWorkletPlugin from 'vite-plugin-bundle-audioworklet';
|
||||
import { dependencies } from './package.json';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [bundleAudioWorkletPlugin()],
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolve(__dirname, 'kabelsalat.mjs'),
|
||||
formats: ['es'],
|
||||
fileName: (ext) => ({ es: 'kabelsalat.mjs' })[ext],
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [...Object.keys(dependencies)],
|
||||
},
|
||||
target: 'esnext',
|
||||
},
|
||||
});
|
||||
@@ -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,6 +1,6 @@
|
||||
import { describe, bench } from 'vitest';
|
||||
|
||||
import { calculateSteps } from '../../core/index.mjs';
|
||||
import { calculateSteps } from '@strudel/pattern';
|
||||
import { mini } from '../index.mjs';
|
||||
|
||||
describe('mini', () => {
|
||||
|
||||
@@ -5,8 +5,8 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import * as krill from './krill-parser.js';
|
||||
import * as strudel from '@strudel/core';
|
||||
import Fraction, { lcm } from '@strudel/core/fraction.mjs';
|
||||
import * as strudel from '@strudel/pattern';
|
||||
import { Fraction, lcm } from '@strudel/pattern';
|
||||
|
||||
const randOffset = 0.0003;
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"homepage": "https://codeberg.org/uzu/strudel#readme",
|
||||
"dependencies": {
|
||||
"@strudel/core": "workspace:*"
|
||||
"@strudel/pattern": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"peggy": "^4.2.0",
|
||||
|
||||
@@ -5,8 +5,8 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
*/
|
||||
|
||||
import { getLeafLocation, getLeafLocations, mini, mini2ast } from '../mini.mjs';
|
||||
import '@strudel/core/euclid.mjs';
|
||||
import { Fraction } from '@strudel/core/index.mjs';
|
||||
import '@strudel/pattern';
|
||||
import { Fraction } from '@strudel/pattern';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('mini', () => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// motion.mjs
|
||||
|
||||
import { signal } from '../core/signal.mjs';
|
||||
import { signal } from '@strudel/core';
|
||||
|
||||
/**
|
||||
* The accelerometer's x-axis value ranges from 0 to 1.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
index.mjs - <short description TODO>
|
||||
Copyright (C) 2025 Strudel contributors - see <https://codeberg.org/uzu/strudel/src/branch/main/packages/core/index.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/>.
|
||||
*/
|
||||
|
||||
export * from './euclid.mjs';
|
||||
import Fraction, { lcm } from './fraction.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
export { Fraction, lcm };
|
||||
export * from './hap.mjs';
|
||||
export * from './impure.mjs';
|
||||
export * from './logger.mjs';
|
||||
export * from './pattern.mjs';
|
||||
export * from './pick.mjs';
|
||||
export * from './signal.mjs';
|
||||
export * from './state.mjs';
|
||||
export * from './timespan.mjs';
|
||||
export * from './util.mjs';
|
||||
export { default as drawLine } from './drawLine.mjs';
|
||||
// below won't work with runtime.mjs (json import fails)
|
||||
/* import * as p from './package.json';
|
||||
export const version = p.version; */
|
||||
logger('🌀 @strudel/pattern loaded 🌀');
|
||||
if (globalThis._strudelLoaded) {
|
||||
console.warn(
|
||||
`@strudel/pattern was loaded more than once...
|
||||
This might happen when you have multiple versions of strudel installed.
|
||||
Please check with "npm ls @strudel/pattern".`,
|
||||
);
|
||||
}
|
||||
globalThis._strudelLoaded = true;
|
||||
@@ -5,7 +5,7 @@ let debounce = 1000,
|
||||
lastTime;
|
||||
|
||||
export function errorLogger(e, origin = 'cyclist') {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
if (typeof process !== 'undefined' && process.env.NODE_ENV === 'development') {
|
||||
console.error(e);
|
||||
}
|
||||
logger(`[${origin}] error: ${e.message}`);
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "@strudel/pattern",
|
||||
"version": "1.2.6",
|
||||
"description": "Port of Tidal Cycles to JavaScript. This package contains only the pattern representation.",
|
||||
"main": "index.mjs",
|
||||
"type": "module",
|
||||
"publishConfig": {
|
||||
"main": "dist/index.mjs"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"bench": "vitest bench",
|
||||
"build": "vite build",
|
||||
"prepublishOnly": "pnpm build"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||
},
|
||||
"keywords": [
|
||||
"tidalcycles",
|
||||
"strudel",
|
||||
"pattern",
|
||||
"livecoding",
|
||||
"algorave"
|
||||
],
|
||||
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"bugs": {
|
||||
"url": "https://codeberg.org/uzu/strudel/issues"
|
||||
},
|
||||
"homepage": "https://strudel.cc",
|
||||
"dependencies": {
|
||||
"fraction.js": "^5.2.1"
|
||||
},
|
||||
"gitHead": "0e26d4e741500f5bae35b023608f062a794905c2",
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.11",
|
||||
"vitest": "^3.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
}
|
||||
}
|
||||
@@ -26,12 +26,12 @@ import {
|
||||
} from './util.mjs';
|
||||
import drawLine from './drawLine.mjs';
|
||||
import { errorLogger, logger } from './logger.mjs';
|
||||
import { strudelScope } from './evaluate.mjs';
|
||||
import { getClockTime } from './schedulerState.mjs';
|
||||
|
||||
export const strudelScope = {};
|
||||
|
||||
let stringParser;
|
||||
|
||||
let __steps = true;
|
||||
export let __steps = true;
|
||||
|
||||
export const calculateSteps = function (x) {
|
||||
__steps = x ? true : false;
|
||||
@@ -959,15 +959,6 @@ export class Pattern {
|
||||
);
|
||||
}
|
||||
|
||||
// legacy:
|
||||
onTrigger(onTrigger, dominant = true) {
|
||||
console.warn('onTrigger is deprecated.. use onSchedule(hap, time, cps) instead');
|
||||
return this.onSchedule((hap, t, cps) => {
|
||||
const currentTime = getClockTime();
|
||||
return onTrigger(hap, currentTime, cps, t);
|
||||
}, dominant);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the current event to the console (visible in the side menu).
|
||||
* @param {Function} [func]
|
||||
@@ -2410,16 +2401,6 @@ export const fast = register(
|
||||
true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Both speeds up the pattern (like 'fast') and the sample playback (like 'speed').
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("bd sd:2").hurry("<1 2 4 3>").slow(1.5)
|
||||
*/
|
||||
export const hurry = register('hurry', function (r, pat) {
|
||||
return pat._fast(r).mul(pure({ speed: r }));
|
||||
});
|
||||
|
||||
/**
|
||||
* Slow down a pattern over the given number of cycles. Like the "/" operator in mini notation.
|
||||
*
|
||||
@@ -2738,7 +2719,9 @@ export const { segment, seg } = register(['segment', 'seg'], function (rate, pat
|
||||
* @example
|
||||
* s("hh*8").swingBy(1/3, 4)
|
||||
*/
|
||||
export const swingBy = register('swingBy', (swing, n, pat) => pat.inside(n, late(seq(0, swing / 2))));
|
||||
export const swingBy = register('swingBy', (swing, n, pat) =>
|
||||
pat.inside(n, late(stack(seq(0, silence), seq(silence, swing / 2).late(swing / 2)))),
|
||||
);
|
||||
|
||||
/**
|
||||
* Shorthand for swingBy with 1/3:
|
||||
@@ -2920,71 +2903,6 @@ export const palindrome = register(
|
||||
true,
|
||||
);
|
||||
|
||||
/**
|
||||
* Jux with adjustable stereo width. 0 = mono, 1 = full stereo.
|
||||
* @tags temporal
|
||||
* @name juxBy
|
||||
* @synonyms juxby
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxBy("<0 .5 1>/2", rev)
|
||||
*/
|
||||
export const { juxBy, juxby } = register(['juxBy', 'juxby'], function (by, func, pat) {
|
||||
by /= 2;
|
||||
const elem_or = function (dict, key, dflt) {
|
||||
if (key in dict) {
|
||||
return dict[key];
|
||||
}
|
||||
return dflt;
|
||||
};
|
||||
const left = pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) - by }));
|
||||
const right = func(pat.withValue((val) => Object.assign({}, val, { pan: elem_or(val, 'pan', 0.5) + by })));
|
||||
|
||||
return stack(left, right).setSteps(__steps ? lcm(left._steps, right._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Like juxBy, except it flips the ears each cycle.
|
||||
* @name juxFlipBy
|
||||
* @synonyms juxflipby, fluxBy, fluxby
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlipBy(".8", rev)
|
||||
*/
|
||||
export const { juxFlipBy, juxflipby, fluxBy, fluxby } = register(
|
||||
['juxFlipBy', 'juxflipby', 'fluxBy', 'fluxby'],
|
||||
function (by, func, pat) {
|
||||
return pat.juxBy(slowcat(by, -by), func);
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* The jux function creates strange stereo effects, by applying a function to a pattern, but only in the right-hand channel.
|
||||
* @tags temporal, superdough
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(rev)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(press)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").jux(iter(4))
|
||||
*/
|
||||
export const jux = register('jux', function (func, pat) {
|
||||
return pat._juxBy(1, func, pat);
|
||||
});
|
||||
|
||||
/**
|
||||
* Like jux, but flips the ears each cycle.
|
||||
* @name juxFlip
|
||||
* @synonyms juxflip, flux
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(rev)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(press)
|
||||
* @example
|
||||
* s("bd lt [~ ht] mt cp ~ bd hh").juxFlip(iter(4))
|
||||
*/
|
||||
export const { juxFlip, flux } = register(['juxFlip', 'juxflip', 'flux'], function (func, pat) {
|
||||
return pat._juxFlipBy(1, func, pat);
|
||||
});
|
||||
|
||||
/**
|
||||
* Superimpose and offset multiple times, applying the given function each time.
|
||||
* @tags temporal, functional
|
||||
@@ -3005,36 +2923,6 @@ export const { echoWith, echowith, stutWith, stutwith } = register(
|
||||
},
|
||||
);
|
||||
|
||||
/**
|
||||
* Superimpose and offset multiple times, gradually decreasing the velocity
|
||||
* @tags temporal
|
||||
* @name echo
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @param {number} times how many times to repeat
|
||||
* @param {number} time cycle offset between iterations
|
||||
* @param {number} feedback velocity multiplicator for each iteration
|
||||
* @example
|
||||
* s("bd sd").echo(3, 1/6, .8)
|
||||
*/
|
||||
export const echo = register('echo', function (times, time, feedback, pat) {
|
||||
return pat._echoWith(times, time, (pat, i) => pat.gain(Math.pow(feedback, i)));
|
||||
});
|
||||
|
||||
/**
|
||||
* Deprecated. Like echo, but the last 2 parameters are flipped.
|
||||
* @tags temporal
|
||||
* @name stut
|
||||
* @param {number} times how many times to repeat
|
||||
* @param {number} feedback velocity multiplicator for each iteration
|
||||
* @param {number} time cycle offset between iterations
|
||||
* @example
|
||||
* s("bd sd").stut(3, .8, 1/6)
|
||||
*/
|
||||
export const stut = register('stut', function (times, feedback, time, pat) {
|
||||
return pat._echoWith(times, time, (pat, i) => pat.gain(Math.pow(feedback, i)));
|
||||
});
|
||||
|
||||
export const applyN = register('applyN', function (n, func, p) {
|
||||
let result = p;
|
||||
for (let i = 0; i < n; i++) {
|
||||
@@ -3303,33 +3191,6 @@ export const { ribbon, rib } = register(['ribbon', 'rib'], (offset, cycles, pat)
|
||||
pat.early(offset).restart(pure(1).slow(cycles)),
|
||||
);
|
||||
|
||||
/**
|
||||
* Sets the pattern's color to the given [hsla](https://www.w3schools.com/htmL/html_colors_hsl.asp)
|
||||
*
|
||||
* @name hsla
|
||||
* @param {number} hue (0 - 360)
|
||||
* @param {number} saturation percentage (0 - 100)
|
||||
* @param {number} lightness percentage (0 - 100)
|
||||
* @param {number} alpha (transparency) (0.0 - 1.0)
|
||||
* @tags visualization
|
||||
*/
|
||||
export const hsla = register('hsla', (h, s, l, a, pat) => {
|
||||
return pat.color(`hsla(${h}turn,${s * 100}%,${l * 100}%,${a})`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Sets the pattern's color to the given [hsl](https://www.w3schools.com/htmL/html_colors_hsl.asp)
|
||||
*
|
||||
* @name hsl
|
||||
* @param {number} hue (0 - 360)
|
||||
* @param {number} saturation percentage (0 - 100)
|
||||
* @param {number} lightness percentage (0 - 100)
|
||||
* @tags visualization
|
||||
*/
|
||||
export const hsl = register('hsl', (h, s, l, pat) => {
|
||||
return pat.color(`hsl(${h}turn,${s * 100}%,${l * 100}%)`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tags each Hap with an identifier. Good for filtering. The function populates Hap.context.tags (Array).
|
||||
* @name tag
|
||||
@@ -3946,210 +3807,6 @@ Pattern.prototype.steps = Pattern.prototype.pace;
|
||||
// Control-related functions, i.e. ones that manipulate patterns of
|
||||
// objects
|
||||
|
||||
/**
|
||||
* Cuts each sample into the given number of parts, allowing you to explore a technique known as 'granular synthesis'.
|
||||
* It turns a pattern of samples into a pattern of parts of samples.
|
||||
* @name chop
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes")
|
||||
* .chop(4)
|
||||
* .rev() // reverse order of chops
|
||||
* .loopAt(2) // fit sample into 2 cycles
|
||||
*
|
||||
*/
|
||||
export const chop = register('chop', function (n, pat) {
|
||||
const slices = Array.from({ length: n }, (x, i) => i);
|
||||
const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n }));
|
||||
const merge = function (a, b) {
|
||||
if ('begin' in a && 'end' in a && a.begin !== undefined && a.end !== undefined) {
|
||||
const d = a.end - a.begin;
|
||||
b = { begin: a.begin + b.begin * d, end: a.begin + b.end * d };
|
||||
}
|
||||
// return a;
|
||||
return Object.assign({}, a, b);
|
||||
};
|
||||
const func = function (o) {
|
||||
return sequence(slice_objects.map((slice_o) => merge(o, slice_o)));
|
||||
};
|
||||
return pat.squeezeBind(func).setSteps(__steps ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Cuts each sample into the given number of parts, triggering progressive portions of each sample at each loop.
|
||||
* @name striate
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("numbers:0 numbers:1 numbers:2").striate(6).slow(3)
|
||||
*/
|
||||
export const striate = register('striate', function (n, pat) {
|
||||
const slices = Array.from({ length: n }, (x, i) => i);
|
||||
const slice_objects = slices.map((i) => ({ begin: i / n, end: (i + 1) / n }));
|
||||
const slicePat = slowcat(...slice_objects);
|
||||
return pat
|
||||
.set(slicePat)
|
||||
._fast(n)
|
||||
.setSteps(__steps ? Fraction(n).mulmaybe(pat._steps) : undefined);
|
||||
});
|
||||
|
||||
/**
|
||||
* Makes the sample fit the given number of cycles by changing the speed.
|
||||
* @param {number} factor
|
||||
* @param {Pattern} pat
|
||||
* @param {number} [cps=0.5]
|
||||
* @name loopAt
|
||||
* @tags samples, pitch
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes").loopAt(2)
|
||||
*/
|
||||
const _loopAt = function (factor, pat, cps = 0.5) {
|
||||
return pat
|
||||
.speed((1 / factor) * cps)
|
||||
.unit('c')
|
||||
.slow(factor);
|
||||
};
|
||||
|
||||
export const { loopAt, loopat } = register(['loopAt', 'loopat'], function (factor, pat) {
|
||||
const steps = pat._steps ? pat._steps.div(factor) : undefined;
|
||||
return new Pattern((state) => _loopAt(factor, pat, state.controls._cps).query(state), steps);
|
||||
});
|
||||
|
||||
/**
|
||||
* Chops samples into the given number of slices, triggering those slices with a given pattern of slice numbers.
|
||||
* Instead of a number, it also accepts a list of numbers from 0 to 1 to slice at specific points.
|
||||
* @name slice
|
||||
* @tags samples
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks165").slice(8, "0 1 <2 2*2> 3 [4 0] 5 6 7".every(3, rev)).slow(0.75)
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks125").fit().slice([0,.25,.5,.75], "0 1 1 <2 3>")
|
||||
*/
|
||||
|
||||
export const slice = register(
|
||||
'slice',
|
||||
function (npat, ipat, opat) {
|
||||
return npat
|
||||
.innerBind((n) =>
|
||||
ipat.outerBind((i) =>
|
||||
opat.outerBind((o) => {
|
||||
// If it's not an object, assume it's a string and make it a 's' control parameter
|
||||
o = o instanceof Object ? o : { s: o };
|
||||
const begin = Array.isArray(n) ? n[i] : i / n;
|
||||
const end = Array.isArray(n) ? n[i + 1] : (i + 1) / n;
|
||||
return pure({ begin, end, _slices: n, ...o });
|
||||
}),
|
||||
),
|
||||
)
|
||||
.setSteps(ipat._steps);
|
||||
},
|
||||
false, // turns off auto-patternification
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* make something happen on event time
|
||||
* uses browser timeout which is innacurate for audio tasks
|
||||
* @param {Function} func
|
||||
* @name onTriggerTime
|
||||
* @tags external_io
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("bd!8").onTriggerTime((hap) => {console.log(hap)})
|
||||
*/
|
||||
Pattern.prototype.onTriggerTime = function (func) {
|
||||
return this.onSchedule((hap, targetTime) => {
|
||||
const diff = targetTime - getClockTime();
|
||||
setTimeout(() => {
|
||||
func(hap);
|
||||
}, diff * 1000);
|
||||
}, false);
|
||||
};
|
||||
|
||||
/**
|
||||
* Works the same as slice, but changes the playback speed of each slice to match the duration of its step.
|
||||
* @name splice
|
||||
* @tags samples, pitch
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* s("breaks165")
|
||||
* .splice(8, "0 1 [2 3 0]@2 3 0@2 7")
|
||||
*/
|
||||
|
||||
export const splice = register(
|
||||
'splice',
|
||||
function (npat, ipat, opat) {
|
||||
const sliced = slice(npat, ipat, opat);
|
||||
return new Pattern((state) => {
|
||||
// TODO - default cps to 0.5
|
||||
const cps = state.controls._cps || 1;
|
||||
const haps = sliced.query(state);
|
||||
return haps.map((hap) =>
|
||||
hap.withValue((v) => ({
|
||||
...{
|
||||
speed: (cps / v._slices / hap.whole.duration) * (v.speed || 1),
|
||||
unit: 'c',
|
||||
},
|
||||
...v,
|
||||
})),
|
||||
);
|
||||
}).setSteps(ipat._steps);
|
||||
},
|
||||
false, // turns off auto-patternification
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes the sample fit its event duration. Good for rhythmical loops like drum breaks.
|
||||
* Similar to `loopAt`.
|
||||
* @name fit
|
||||
* @tags samples, pitch
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes/2").fit()
|
||||
*/
|
||||
export const fit = register('fit', (pat) =>
|
||||
pat.withHaps((haps, state) =>
|
||||
haps.map((hap) =>
|
||||
hap.withValue((v) => {
|
||||
const slicedur = ('end' in v ? v.end : 1) - ('begin' in v ? v.begin : 0);
|
||||
return {
|
||||
...v,
|
||||
speed: ((state.controls._cps || 1) / hap.whole.duration) * slicedur,
|
||||
unit: 'c',
|
||||
};
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Makes the sample fit the given number of cycles and cps value, by
|
||||
* changing the speed. deprecated: use loopAt or fit instead, together with setCps / setCpm.
|
||||
* @name loopAtCps
|
||||
* @tags samples, pitch
|
||||
* @memberof Pattern.prototype
|
||||
* @deprecated
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* samples({ rhodes: 'https://cdn.freesound.org/previews/132/132051_316502-lq.mp3' })
|
||||
* s("rhodes").loopAtCps(4,1.5).cps(1.5)
|
||||
*/
|
||||
export const { loopAtCps, loopatcps } = register(['loopAtCps', 'loopatcps'], function (factor, cps, pat) {
|
||||
return _loopAt(factor, pat, cps);
|
||||
});
|
||||
|
||||
/** exposes a custom value at query time. basically allows mutating state without evaluation
|
||||
* @param {function():Pattern} accessor
|
||||
* @returns {Pattern}
|
||||
@@ -4160,37 +3817,6 @@ export const ref = (accessor) =>
|
||||
.withValue(() => reify(accessor()))
|
||||
.innerJoin();
|
||||
|
||||
let fadeGain = (p) => (p < 0.5 ? 1 : 1 - (p - 0.5) / 0.5);
|
||||
|
||||
/**
|
||||
* Cross-fades between left and right from 0 to 1:
|
||||
* - 0 = (full left, no right)
|
||||
* - .5 = (both equal)
|
||||
* - 1 = (no left, full right)
|
||||
*
|
||||
* @param {Pattern} a
|
||||
* @param {Pattern} pos
|
||||
* @param {Pattern} b
|
||||
* @name xfade
|
||||
* @tags amplitude
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* xfade(s("bd*2"), "<0 .25 .5 .75 1>", s("hh*8"))
|
||||
*/
|
||||
export let xfade = (a, pos, b) => {
|
||||
pos = reify(pos);
|
||||
a = reify(a);
|
||||
b = reify(b);
|
||||
let gaina = pos.fmap((v) => ({ gain: fadeGain(v) }));
|
||||
let gainb = pos.fmap((v) => ({ gain: fadeGain(1 - v) }));
|
||||
return stack(a.mul(gaina), b.mul(gainb));
|
||||
};
|
||||
|
||||
// the prototype version is actually flipped so left/right makes sense
|
||||
Pattern.prototype.xfade = function (pos, b) {
|
||||
return xfade(this, pos, b);
|
||||
};
|
||||
|
||||
/**
|
||||
* creates a structure pattern from divisions of a cycle
|
||||
* especially useful for creating rhythms
|
||||
@@ -4287,108 +3913,6 @@ export const morph = (frompat, topat, bypat) => {
|
||||
return frompat.innerBind((from) => topat.innerBind((to) => bypat.innerBind((by) => _morph(from, to, by))));
|
||||
};
|
||||
|
||||
const _distortWithAlg = function (name) {
|
||||
const func = function (args, pat) {
|
||||
const argsPat = reify(args).fmap((v) => (Array.isArray(v) ? [...v, name] : [v, 1, name]));
|
||||
if (!pat) {
|
||||
return pure({}).distort(argsPat);
|
||||
}
|
||||
return pat.distort(argsPat);
|
||||
};
|
||||
Pattern.prototype[name] = function (args) {
|
||||
return func(args, this);
|
||||
};
|
||||
return func;
|
||||
};
|
||||
|
||||
/**
|
||||
* Soft-clipping distortion
|
||||
*
|
||||
* @name soft
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const soft = _distortWithAlg('soft');
|
||||
|
||||
/**
|
||||
* Hard-clipping distortion
|
||||
*
|
||||
* @name hard
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const hard = _distortWithAlg('hard');
|
||||
|
||||
/**
|
||||
* Cubic polynomial distortion
|
||||
*
|
||||
* @name cubic
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const cubic = _distortWithAlg('cubic');
|
||||
|
||||
/**
|
||||
* Diode-emulating distortion
|
||||
*
|
||||
* @name diode
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const diode = _distortWithAlg('diode');
|
||||
|
||||
/**
|
||||
* Asymmetrical diode distortion
|
||||
*
|
||||
* @name asym
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const asym = _distortWithAlg('asym');
|
||||
|
||||
/**
|
||||
* Wavefolding distortion
|
||||
*
|
||||
* @name fold
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const fold = _distortWithAlg('fold');
|
||||
|
||||
/**
|
||||
* Wavefolding distortion composed with sinusoid
|
||||
*
|
||||
* @name sinefold
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const sinefold = _distortWithAlg('sinefold');
|
||||
|
||||
/**
|
||||
* Distortion via Chebyshev polynomials
|
||||
*
|
||||
* @name chebyshev
|
||||
* @tags distortion, superdough
|
||||
* @param {number | Pattern} distortion amount of distortion to apply
|
||||
* @param {number | Pattern} volume linear postgain of the distortion
|
||||
*
|
||||
*/
|
||||
export const chebyshev = _distortWithAlg('chebyshev');
|
||||
|
||||
/**
|
||||
* Turns a list of patterns into a single pattern which outputs list-values
|
||||
*
|
||||
@@ -6,10 +6,11 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import { Hap } from './hap.mjs';
|
||||
import { Pattern, fastcat, pure, register, reify, silence, stack, sequenceP, isPattern } from './pattern.mjs';
|
||||
import { _mod } from './util.mjs';
|
||||
import { _mod, noteToMidi } from './util.mjs';
|
||||
import Fraction from './fraction.mjs';
|
||||
|
||||
import { id, keyAlias, getCurrentKeyboardState } from './util.mjs';
|
||||
import TimeSpan from './timespan.mjs';
|
||||
|
||||
export function steady(value) {
|
||||
// A continuous value
|
||||
@@ -1128,6 +1129,24 @@ export const cyclesPer = new Pattern(function (state) {
|
||||
return [new Hap(undefined, state.span, state.span.duration)];
|
||||
});
|
||||
|
||||
/**
|
||||
* A pattern measuring the duration of events, in seconds per event.
|
||||
* `secondsPer` doesn't have structure itself, but takes structue, and therefore
|
||||
* event durations, from the pattern that it is combined with.
|
||||
* For example `secondsPer.struct("1 1 [1 1] 1")` with `cps = 1` would give the same as `"0.25 0.25 [0.125 0.125] 0.25"`.
|
||||
*
|
||||
* @tags temporal
|
||||
* @synonyms sper
|
||||
* @example
|
||||
* note("f a [c d] e")
|
||||
* .dec(secondsPer.mul(1))
|
||||
*/
|
||||
export const secondsPer = new Pattern(function (state) {
|
||||
return [new Hap(undefined, state.span, state.span.duration.div(state.controls?._cps ?? 0.5))];
|
||||
});
|
||||
|
||||
export const sper = secondsPer;
|
||||
|
||||
/**
|
||||
* A pattern measuring the 'shortness' of events, or in other words, the duration of pattern events,
|
||||
* in events per cycle. `per` doesn't have structure itself, but takes structure, and therefore
|
||||
@@ -1181,3 +1200,93 @@ export const open = signal((t) => t.min(1));
|
||||
* .restart("x/4") // restart every 4 cycles
|
||||
*/
|
||||
export const close = signal((t) => Fraction(1).sub(t).max(0));
|
||||
|
||||
/**
|
||||
* Turns a pattern of numbers into a continuous signal.
|
||||
* Each number in the pattern specifies the value at its onset, and over the
|
||||
* duration of the hap, it will linearly transition to the value of the next hap.
|
||||
*
|
||||
* Alternatively, the end value of a hap can be specified explicitly using
|
||||
* array notation, in which case there will be a hard jump from the end value
|
||||
* of the hap, and the begin value of the next hap.
|
||||
*
|
||||
* Similar to other signals like `saw` or `perlin`, this signal should be sampled
|
||||
* at regular intervals to actually get the desired result.
|
||||
*
|
||||
* @name smooth
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(smooth("0 8").seg(16))
|
||||
* .scale('C major')
|
||||
* @example
|
||||
* n(smooth("0:8").seg(8))
|
||||
* .scale('C major')
|
||||
* @example
|
||||
* n("<0 0 0 3 0 4 0 7>*16").scale("e2:phrygian")
|
||||
* .s("saw").lpf(100).lpq(7)
|
||||
* .lpenv(smooth("<0 1@3 2 3 5 [8 [3 5] 2]*4@4 2:8 2:8 2:8 8>"))
|
||||
*
|
||||
*/
|
||||
export const smooth = register('smooth', (pat) => {
|
||||
return new Pattern((state) => {
|
||||
const haps = pat.query(state);
|
||||
if (!haps.length) {
|
||||
return haps;
|
||||
}
|
||||
// Find the last hap in the query
|
||||
const lastHap = haps.reduce((max, hap) => (hap.whole.end.gt(max.whole.end) ? hap : max));
|
||||
|
||||
let onsetHaps = [
|
||||
...haps,
|
||||
// Because the last hap in our query also needs to transition to the next value,
|
||||
// we query to find the next hap after the current last hap.
|
||||
// If that hap is outside of the smooth margin, we simply assume that there is no next hap (e.g. a rest).
|
||||
...pat.query(state.withSpan((span) => new TimeSpan(lastHap.whole.end, lastHap.whole.end))),
|
||||
]
|
||||
// sort by onsets
|
||||
.sort((a, b) => a.whole.begin.compare(b.whole.begin))
|
||||
// Make onsets unique
|
||||
.filter((x, i, arr) => i === arr.length - 1 || x.whole.begin.ne(arr[i + 1].whole.begin));
|
||||
|
||||
const newHaps = [];
|
||||
|
||||
for (const hap of haps) {
|
||||
// Find the next onset
|
||||
const next = onsetHaps.find((onsetHap) => onsetHap.whole.begin.eq(hap.whole.end));
|
||||
|
||||
newHaps.push(__smoothHap(state.span.begin, hap, next));
|
||||
}
|
||||
return newHaps;
|
||||
});
|
||||
});
|
||||
|
||||
function __smoothHap(time, hapA, hapB) {
|
||||
let a, b, context;
|
||||
if (Array.isArray(hapA.value)) {
|
||||
// Hap with array notation determines both start and end values.
|
||||
a = hapA.value[0];
|
||||
b = hapA.value[1];
|
||||
context = hapA.context;
|
||||
} else {
|
||||
a = hapA.value;
|
||||
if (hapB === undefined) {
|
||||
// With no hapB given, we simply copy the value of hapA so the value
|
||||
// remains the same throughout the hap.
|
||||
// E.g. smooth("0 1 -") will transition from 0 to 1 and then stay at 1 until the rest.
|
||||
b = hapA.value;
|
||||
context = hapA.context;
|
||||
} else {
|
||||
// Otherwise, transition to the value at the start of hapB.
|
||||
b = Array.isArray(hapB.value) ? hapB.value[0] : hapB.value;
|
||||
context = hapA.combineContext(hapB);
|
||||
}
|
||||
}
|
||||
if (typeof a === 'string') {
|
||||
a = noteToMidi(a);
|
||||
}
|
||||
if (typeof b === 'string') {
|
||||
b = noteToMidi(b);
|
||||
}
|
||||
const progress = time.sub(hapA.whole.begin).div(hapA.whole.end.sub(hapA.whole.begin));
|
||||
return new Hap(hapA.whole, hapA.part, a + (b - a) * (progress.lt(0) ? 0 : progress), context);
|
||||
}
|
||||
@@ -58,11 +58,12 @@ import {
|
||||
arp,
|
||||
} from '../index.mjs';
|
||||
|
||||
import { log, logValues, stackCenter } from '../pattern.mjs';
|
||||
import { reify, stackCenter } from '../pattern.mjs';
|
||||
|
||||
import { steady } from '../signal.mjs';
|
||||
|
||||
import { n, s } from '../controls.mjs';
|
||||
let n = (value) => reify(value).fmap((v) => ({ n: v }));
|
||||
let s = (value) => reify(value).fmap((v) => ({ s: v }));
|
||||
|
||||
const st = (begin, end) => new State(ts(begin, end));
|
||||
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
||||
@@ -71,7 +72,7 @@ const hap = (whole, part, value, context = {}) => new Hap(whole, part, value, co
|
||||
const third = Fraction(1, 3);
|
||||
const twothirds = Fraction(2, 3);
|
||||
|
||||
const sameFirst = (a, b) => {
|
||||
export const sameFirst = (a, b) => {
|
||||
return expect(a.sortHapsByPart().firstCycle()).toStrictEqual(b.sortHapsByPart().firstCycle());
|
||||
};
|
||||
|
||||
@@ -876,24 +877,6 @@ describe('Pattern', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('jux', () => {
|
||||
it('Can juxtapose', () => {
|
||||
expect(pure({ a: 1 }).jux(fast(2)).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
stack(pure({ a: 1, pan: 0 }), pure({ a: 1, pan: 1 }).fast(2))
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('juxBy', () => {
|
||||
it('Can juxtapose by half', () => {
|
||||
expect(pure({ a: 1 }).juxBy(0.5, fast(2)).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
stack(pure({ a: 1, pan: 0.25 }), pure({ a: 1, pan: 0.75 }).fast(2))
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('_squeezeJoin', () => {
|
||||
it('Can squeeze', () => {
|
||||
expect(
|
||||
@@ -931,46 +914,6 @@ describe('Pattern', () => {
|
||||
expect(sequence(1, 2, 3).ply(2).early(8).firstCycle().length).toBe(6);
|
||||
});
|
||||
});
|
||||
describe('striate', () => {
|
||||
it('Can striate(2)', () => {
|
||||
sameFirst(
|
||||
sequence({ sound: 'a' }).striate(2),
|
||||
sequence({ sound: 'a', begin: 0, end: 0.5 }, { sound: 'a', begin: 0.5, end: 1 }),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('chop', () => {
|
||||
it('Can _chop(2)', () => {
|
||||
expect(sequence({ sound: 'a' }, { sound: 'b' })._chop(2).firstCycle()).toStrictEqual(
|
||||
sequence(
|
||||
{ sound: 'a', begin: 0, end: 0.5 },
|
||||
{ sound: 'a', begin: 0.5, end: 1 },
|
||||
{ sound: 'b', begin: 0, end: 0.5 },
|
||||
{ sound: 'b', begin: 0.5, end: 1 },
|
||||
).firstCycle(),
|
||||
);
|
||||
});
|
||||
it('Can chop(2,3)', () => {
|
||||
expect(pure({ sound: 'a' }).fast(2).chop(2, 3).sortHapsByPart().firstCycle()).toStrictEqual(
|
||||
sequence(
|
||||
[
|
||||
{ sound: 'a', begin: 0, end: 0.5 },
|
||||
{ sound: 'a', begin: 0.5, end: 1 },
|
||||
],
|
||||
[
|
||||
{ sound: 'a', begin: 0, end: 1 / 3 },
|
||||
{ sound: 'a', begin: 1 / 3, end: 2 / 3 },
|
||||
{ sound: 'a', begin: 2 / 3, end: 1 },
|
||||
],
|
||||
)
|
||||
.sortHapsByPart()
|
||||
.firstCycle(),
|
||||
);
|
||||
});
|
||||
it('Can chop chops', () => {
|
||||
expect(pure({ s: 'bev' }).chop(2).chop(2).firstCycle()).toStrictEqual(pure({ s: 'bev' }).chop(4).firstCycle());
|
||||
});
|
||||
});
|
||||
describe('range', () => {
|
||||
it('Can be patterned', () => {
|
||||
expect(sequence(0, 0).range(sequence(0, 0.5), 1).firstCycle()).toStrictEqual(sequence(0, 0.5).firstCycle());
|
||||
@@ -1053,11 +996,6 @@ describe('Pattern', () => {
|
||||
sameFirst(sequence('a', 'b', 'c', 'd').press(), sequence(silence, 'a', silence, 'b', silence, 'c', silence, 'd'));
|
||||
});
|
||||
});
|
||||
describe('hurry', () => {
|
||||
it('Can speed up patterns and sounds', () => {
|
||||
sameFirst(s(sequence('a', 'b')).hurry(2), s(sequence('a', 'b')).fast(2).speed(2));
|
||||
});
|
||||
});
|
||||
/*describe('composable functions', () => {
|
||||
it('Can compose functions', () => {
|
||||
sameFirst(sequence(3, 4).fast(2).rev().fast(2), fast(2).rev().fast(2)(sequence(3, 4)));
|
||||
@@ -1076,32 +1014,6 @@ describe('Pattern', () => {
|
||||
});
|
||||
});
|
||||
*/
|
||||
describe('slice', () => {
|
||||
it('Can slice a sample', () => {
|
||||
sameFirst(
|
||||
s('break').slice(4, sequence(0, 1, 2, 3)),
|
||||
sequence(
|
||||
{ begin: 0, end: 0.25, s: 'break', _slices: 4 },
|
||||
{ begin: 0.25, end: 0.5, s: 'break', _slices: 4 },
|
||||
{ begin: 0.5, end: 0.75, s: 'break', _slices: 4 },
|
||||
{ begin: 0.75, end: 1, s: 'break', _slices: 4 },
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('splice', () => {
|
||||
it('Can splice a sample', () => {
|
||||
sameFirst(
|
||||
s('break').splice(4, sequence(0, 1, 2, 3)),
|
||||
sequence(
|
||||
{ begin: 0, end: 0.25, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.25, end: 0.5, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.5, end: 0.75, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
{ begin: 0.75, end: 1, s: 'break', _slices: 4, unit: 'c', speed: 1 },
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('chunk', () => {
|
||||
it('Processes each cycle of the source pattern multiple times, once for each chunk', () => {
|
||||
expect(sequence(0, 1, 2, 3).slow(2).chunk(2, add(10)).fast(4).firstCycleValues).toStrictEqual([
|
||||
@@ -1189,24 +1101,15 @@ describe('Pattern', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_steps', () => {
|
||||
it('Is correctly preserved/calculated through transformations', () => {
|
||||
expect(sequence(0, 1, 2, 3).linger(4)._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence(0, 1, 2, 3).iter(4)._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence(0, 1, 2, 3).fast(4)._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence(0, 1, 2, 3).hurry(4)._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence(0, 1, 2, 3).rev()._steps).toStrictEqual(Fraction(4));
|
||||
expect(sequence(1).segment(10)._steps).toStrictEqual(Fraction(10));
|
||||
expect(sequence(1, 0, 1).invert()._steps).toStrictEqual(Fraction(3));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).chop(4)._steps).toStrictEqual(Fraction(8));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).striate(4)._steps).toStrictEqual(Fraction(8));
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).slice(4, sequence(0, 1, 2, 3))._steps).toStrictEqual(
|
||||
Fraction(4),
|
||||
);
|
||||
expect(sequence({ s: 'bev' }, { s: 'amenbreak' }).splice(4, sequence(0, 1, 2, 3))._steps).toStrictEqual(
|
||||
Fraction(4),
|
||||
);
|
||||
expect(sequence({ n: 0 }, { n: 1 }, { n: 2 }).chop(4)._steps).toStrictEqual(Fraction(12));
|
||||
expect(
|
||||
pure((x) => x + 1)
|
||||
.setSteps(3)
|
||||
@@ -1319,11 +1222,6 @@ describe('Pattern', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('loopAt', () => {
|
||||
it('maintains steps', () => {
|
||||
expect(s('bev').chop(8).loopAt(2)._steps).toStrictEqual(Fraction(4));
|
||||
});
|
||||
});
|
||||
describe('bite', () => {
|
||||
it('works with uneven patterns', () => {
|
||||
sameFirst(
|
||||
@@ -1405,7 +1303,7 @@ describe('Pattern', () => {
|
||||
describe('logValues', () => {
|
||||
it('logs values to console', () => {
|
||||
const mockConsoleLog = vi.spyOn(console, 'log').mockImplementation(() => {});
|
||||
const pattern = pure('a').note('c#').logValues();
|
||||
const pattern = pure({ s: 'bd', speed: 2 }).logValues();
|
||||
const haps = pattern.queryArc(0, 1);
|
||||
|
||||
// Force a trigger
|
||||
@@ -1414,7 +1312,7 @@ describe('Pattern', () => {
|
||||
});
|
||||
|
||||
expect(mockConsoleLog).toHaveBeenCalledWith(
|
||||
'%c[hap] value:a note:c#',
|
||||
'%c[hap] s:bd speed:2',
|
||||
'background-color: black;color:white;border-radius:15px',
|
||||
);
|
||||
mockConsoleLog.mockRestore();
|
||||
@@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import Fraction from 'fraction.js';
|
||||
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
import {
|
||||
saw,
|
||||
@@ -24,8 +24,9 @@ import {
|
||||
per,
|
||||
perx,
|
||||
cyclesPer,
|
||||
smooth,
|
||||
} from '../signal.mjs';
|
||||
import { fastcat, sequence, State, TimeSpan, Hap, note } from '../index.mjs';
|
||||
import { fastcat, sequence, State, TimeSpan, Hap, seq, pure, silence } from '../index.mjs';
|
||||
|
||||
const st = (begin, end) => new State(ts(begin, end));
|
||||
const ts = (begin, end) => new TimeSpan(Fraction(begin), Fraction(end));
|
||||
@@ -122,6 +123,21 @@ describe('perx', () => {
|
||||
|
||||
describe('shuffle', () => {
|
||||
it('returns original pattern if input is 1', () => {
|
||||
expect(note('c d e f').sound('piano').shuffle(1).firstCycle()).toEqual(note('c d e f').sound('piano').firstCycle());
|
||||
expect(seq(1, 2, 3, 4).shuffle(1).firstCycle()).toEqual(seq(1, 2, 3, 4).firstCycle());
|
||||
});
|
||||
});
|
||||
|
||||
describe('smooth', () => {
|
||||
it('"0 1" equals a tri wave', () => {
|
||||
sameFirst(smooth(fastcat(0, 1)).seg(64), tri.seg(64));
|
||||
});
|
||||
it('"0:1" equals a saw wave', () => {
|
||||
sameFirst(smooth(pure([0, 1])).seg(64), saw.seg(64));
|
||||
});
|
||||
it('supports rests', () => {
|
||||
sameFirst(smooth(fastcat(0, 1, silence)).seg(64), fastcat(saw, 1, silence).seg(64));
|
||||
});
|
||||
it('supports notes', () => {
|
||||
sameFirst(smooth(fastcat('c2', 'c3')).seg(64), fastcat(tri.range(36, 48)).seg(64));
|
||||
});
|
||||
});
|
||||
@@ -6,7 +6,6 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { map, valued, mul } from '../value.mjs';
|
||||
import { n } from '../controls.mjs';
|
||||
|
||||
describe('Value', () => {
|
||||
it('unionWith', () => {
|
||||
@@ -0,0 +1,20 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import { dependencies } from './package.json';
|
||||
import { resolve } from 'path';
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
base: './',
|
||||
plugins: [],
|
||||
build: {
|
||||
lib: {
|
||||
entry: resolve(__dirname, 'index.mjs'),
|
||||
formats: ['es'],
|
||||
fileName: (ext) => ({ es: 'index.mjs' })[ext],
|
||||
},
|
||||
rollupOptions: {
|
||||
external: [...Object.keys(dependencies)],
|
||||
},
|
||||
target: 'esnext',
|
||||
},
|
||||
});
|
||||
@@ -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": {
|
||||
|
||||
@@ -288,12 +288,14 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '', option
|
||||
};
|
||||
|
||||
const cutGroups = [];
|
||||
const scutGroups = [];
|
||||
|
||||
export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||
let {
|
||||
s,
|
||||
nudge = 0, // TODO: is this in seconds?
|
||||
cut,
|
||||
scut,
|
||||
loop,
|
||||
clip = undefined, // if set, samples will be cut off when the hap ends
|
||||
n = 0,
|
||||
@@ -372,6 +374,23 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||
cutGroups[cut] = handle;
|
||||
}
|
||||
|
||||
// scut groups
|
||||
if (scut !== undefined) {
|
||||
if (scutGroups[scut] === undefined) {
|
||||
scutGroups[scut] = { t, handles: [] };
|
||||
}
|
||||
const prevGroup = scutGroups[scut];
|
||||
if (prevGroup.t !== t) {
|
||||
for (const prev of prevGroup.handles) {
|
||||
prev.node.gain.setValueAtTime(1, time);
|
||||
prev.node.gain.linearRampToValueAtTime(0, time + 0.01);
|
||||
}
|
||||
|
||||
scutGroups[scut] = { t, handles: [] };
|
||||
}
|
||||
scutGroups[scut].handles.push(handle);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
@@ -259,14 +263,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 {
|
||||
@@ -313,7 +309,6 @@ export async function initAudio(options = {}) {
|
||||
} catch (err) {
|
||||
console.warn('could not load AudioWorklet effects', err);
|
||||
}
|
||||
await initKabelsalat();
|
||||
logger('[superdough] ready');
|
||||
}
|
||||
let audioReady;
|
||||
@@ -449,14 +444,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: {} };
|
||||
@@ -632,17 +619,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) {
|
||||
|
||||
@@ -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;
|
||||
@@ -1494,81 +1491,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);
|
||||
|
||||
@@ -35,10 +35,12 @@
|
||||
"dependencies": {
|
||||
"@strudel/core": "workspace:*",
|
||||
"@strudel/draw": "workspace:*",
|
||||
"@strudel/pattern": "workspace:*",
|
||||
"superdough": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vite": "^6.0.11"
|
||||
"vite": "^6.0.11",
|
||||
"vitest": "^3.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
import { calculateContextLength, getExportCheckpoints } from '../util.mjs';
|
||||
import { cps } from '@strudel/core';
|
||||
import { slowcat, silence, fastcat } from '@strudel/pattern';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
describe('getCheckpoints()', () => {
|
||||
it('Should return the start and end checkpoints for an empty pattern', () => {
|
||||
expect(getExportCheckpoints(silence, 0.5, 1, 10)).toStrictEqual([
|
||||
{ cycle: 1, cps: 0.5 },
|
||||
{ cycle: 10, cps: 0.5 },
|
||||
]);
|
||||
});
|
||||
it('Should break up checkpoints for an empty pattern into chunks when a max duration is specified', () => {
|
||||
expect(getExportCheckpoints(silence, 0.5, 1, 10, 2)).toStrictEqual([
|
||||
{ cycle: 1, cps: 0.5 },
|
||||
{ cycle: 3, cps: 0.5 },
|
||||
{ cycle: 5, cps: 0.5 },
|
||||
{ cycle: 7, cps: 0.5 },
|
||||
{ cycle: 9, cps: 0.5 },
|
||||
{ cycle: 10, cps: 0.5 },
|
||||
]);
|
||||
});
|
||||
it('Should create checkpoints for cps changes', () => {
|
||||
expect(getExportCheckpoints(cps(fastcat(1, 2, 3, 4)), 0.5, 0, 2)).toStrictEqual([
|
||||
{ cycle: 0, cps: 1 },
|
||||
{ cycle: 0.25, cps: 2 },
|
||||
{ cycle: 0.5, cps: 3 },
|
||||
{ cycle: 0.75, cps: 4 },
|
||||
{ cycle: 1, cps: 1 },
|
||||
{ cycle: 1.25, cps: 2 },
|
||||
{ cycle: 1.5, cps: 3 },
|
||||
{ cycle: 1.75, cps: 4 },
|
||||
{ cycle: 2, cps: 0.5 },
|
||||
]);
|
||||
});
|
||||
it('Should create checkpoints for cps changes and split into chunks when a max duration is specified', () => {
|
||||
expect(getExportCheckpoints(cps(slowcat(1, 2, 3, 4)), 0.5, 1, 5, 0.75)).toStrictEqual([
|
||||
{ cycle: 1, cps: 2 },
|
||||
{ cycle: 1.75, cps: 2 },
|
||||
{ cycle: 2, cps: 3 },
|
||||
{ cycle: 2.75, cps: 3 },
|
||||
{ cycle: 3, cps: 4 },
|
||||
{ cycle: 3.75, cps: 4 },
|
||||
{ cycle: 4, cps: 1 },
|
||||
{ cycle: 4.75, cps: 1 },
|
||||
{ cycle: 5, cps: 0.5 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('calculateContextLength()', () => {
|
||||
it('Should work when there are only the start and end checkpoints', () => {
|
||||
expect(
|
||||
calculateContextLength(
|
||||
[
|
||||
{ cycle: 1, cps: 0.5 },
|
||||
{ cycle: 10, cps: 0.5 },
|
||||
],
|
||||
1000,
|
||||
),
|
||||
).toBe(18000);
|
||||
});
|
||||
it('Should calculate the context length correctly', () => {
|
||||
expect(
|
||||
calculateContextLength(
|
||||
[
|
||||
{ cycle: 1, cps: 1 },
|
||||
{ cycle: 2, cps: 0.5 },
|
||||
{ cycle: 3, cps: 2 },
|
||||
{ cycle: 5, cps: 1 },
|
||||
{ cycle: 6, cps: 0.5 },
|
||||
],
|
||||
1000,
|
||||
),
|
||||
).toBe(5000);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* @typedef {object} ExportCheckpoint
|
||||
* @property {number} cycle The point in time that the cps changes happens
|
||||
* @property {number} cps The new target cps (cycles per second)
|
||||
*/
|
||||
|
||||
/**
|
||||
* Queries the pattern from `begin` to `end` and returns a list of checkpoints
|
||||
* that signify the places in the pattern where the `cps` changes.
|
||||
* If `maxCheckpointDuration` is specified, additional checkpoints will be
|
||||
* inserted if the time difference between two checkpoints is longer than the
|
||||
* specified value.
|
||||
*
|
||||
* The returned list of checkpoints will always have at least 2 checkpoints,
|
||||
* signifying the start and end of the query.
|
||||
*
|
||||
* @param {Pattern} pattern The pattern to query
|
||||
* @param {number} cps The starting cps
|
||||
* @param {number} begin The start of the query
|
||||
* @param {number} end The end of the query
|
||||
* @param {number} maxCheckpointDuration The maximum time difference between checkpoints
|
||||
* @returns {ExportCheckpoint[]} A list of at least 2 checkpoints
|
||||
*/
|
||||
export function getExportCheckpoints(pattern, cps, begin, end, maxCheckpointDuration = Number.MAX_VALUE) {
|
||||
const cpsHaps = pattern
|
||||
.queryArc(0, end, { _cps: cps })
|
||||
.filter((hap) => hap.value.cps !== undefined)
|
||||
.sort((a, b) => {
|
||||
const aBegin = a.whole.begin.valueOf();
|
||||
const bBegin = b.whole.begin.valueOf();
|
||||
if (aBegin === bBegin) {
|
||||
// With multiple simultaneous haps that set the cps,
|
||||
// there must be an order for determinism.
|
||||
return a.value.cps - b.value.cps;
|
||||
}
|
||||
return aBegin - bBegin;
|
||||
})
|
||||
.map((hap) => {
|
||||
return {
|
||||
cycle: hap.whole.begin.valueOf(),
|
||||
cps: hap.value.cps,
|
||||
};
|
||||
});
|
||||
|
||||
// Insert starting checkpoint with the default cps
|
||||
cpsHaps.splice(0, 0, { cycle: 0, cps: cps });
|
||||
// Insert an ending checkpoint after the target end-time with the default cps
|
||||
cpsHaps.push({ cycle: end + 1, cps: cps });
|
||||
|
||||
const checkpoints = [];
|
||||
|
||||
for (var i = 0; i < cpsHaps.length - 1; i++) {
|
||||
const checkpointA = cpsHaps[i];
|
||||
const checkpointB = cpsHaps[i + 1];
|
||||
if (checkpointA.cycle === checkpointB.cycle) {
|
||||
// With multiple checkpoints at the same cycle, we only use the last one.
|
||||
continue;
|
||||
}
|
||||
if (checkpointB.cycle < begin) {
|
||||
// Not at the start yet
|
||||
continue;
|
||||
}
|
||||
var newCheckpoint;
|
||||
if (checkpointA.cycle <= begin && begin < checkpointB.cycle) {
|
||||
// Found the first checkpoint
|
||||
newCheckpoint = { cycle: begin, cps: checkpointA.cps };
|
||||
checkpoints.push(newCheckpoint);
|
||||
} else if (begin <= checkpointA.cycle) {
|
||||
newCheckpoint = { cycle: checkpointA.cycle, cps: checkpointA.cps };
|
||||
checkpoints.push(newCheckpoint);
|
||||
}
|
||||
if (newCheckpoint !== undefined) {
|
||||
while (maxCheckpointDuration < Math.min(checkpointB.cycle, end) - newCheckpoint.cycle) {
|
||||
newCheckpoint = { cycle: newCheckpoint.cycle + maxCheckpointDuration, cps: newCheckpoint.cps };
|
||||
checkpoints.push(newCheckpoint);
|
||||
}
|
||||
}
|
||||
if (end <= checkpointB.cycle) {
|
||||
checkpoints.push({ cycle: end, cps: checkpointB.cps });
|
||||
}
|
||||
}
|
||||
|
||||
return checkpoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the context length in number of samples based on a list of
|
||||
* checkpoints and the samplerate per second.
|
||||
*
|
||||
* @param {ExportCheckpoint[]} checkpoints
|
||||
* @param {number} sampleRate
|
||||
* @returns {number}
|
||||
*/
|
||||
export function calculateContextLength(checkpoints, sampleRate) {
|
||||
console.assert(checkpoints.length >= 2, 'checkpoints must contain at least two entries');
|
||||
|
||||
var total = 0;
|
||||
|
||||
for (let i = 0; i < checkpoints.length - 1; i++) {
|
||||
const changeA = checkpoints[i];
|
||||
const changeB = checkpoints[i + 1];
|
||||
const duration = changeB.cycle - changeA.cycle;
|
||||
total += duration / changeA.cps;
|
||||
}
|
||||
|
||||
return total * sampleRate;
|
||||
}
|
||||
+104
-47
@@ -10,7 +10,6 @@ import {
|
||||
getAudioContext,
|
||||
setLogger,
|
||||
rawdspOutput,
|
||||
registerWorklet,
|
||||
setAudioContext,
|
||||
initAudio,
|
||||
setSuperdoughAudioController,
|
||||
@@ -18,9 +17,14 @@ import {
|
||||
errorLogger,
|
||||
} from 'superdough';
|
||||
import { SuperdoughAudioController } from 'superdough/superdoughoutput.mjs';
|
||||
import { getExportCheckpoints, calculateContextLength } from './util.mjs';
|
||||
|
||||
const { Pattern, logger, repl } = strudel;
|
||||
|
||||
/**
|
||||
* @import { ExportCheckpoint } from '@strudel/core'
|
||||
*/
|
||||
|
||||
setLogger(logger);
|
||||
|
||||
const hap2value = (hap) => {
|
||||
@@ -46,7 +50,13 @@ export async function renderPatternAudio(
|
||||
) {
|
||||
let audioContext = getAudioContext();
|
||||
await audioContext.close();
|
||||
audioContext = new OfflineAudioContext(2, ((end - begin) / cps) * sampleRate, sampleRate);
|
||||
|
||||
const chunkSize = 1;
|
||||
|
||||
const checkpoints = getExportCheckpoints(pattern, cps, begin, end, chunkSize);
|
||||
const contextLength = calculateContextLength(checkpoints, sampleRate);
|
||||
|
||||
audioContext = new OfflineAudioContext(2, contextLength, sampleRate);
|
||||
setAudioContext(audioContext);
|
||||
setSuperdoughAudioController(new SuperdoughAudioController(audioContext));
|
||||
await initAudio({
|
||||
@@ -58,8 +68,8 @@ export async function renderPatternAudio(
|
||||
// so no chunked rendering. Bad performance, but at least it works.
|
||||
return (
|
||||
audioContext.suspend === undefined
|
||||
? renderPatternAudioWhole(audioContext, pattern, cps, begin, end)
|
||||
: renderPatternAudioInChunks(audioContext, pattern, cps, begin, end, 1)
|
||||
? renderPatternAudioWhole(audioContext, pattern, checkpoints)
|
||||
: renderPatternAudioInChunks(audioContext, pattern, checkpoints)
|
||||
)
|
||||
.then((renderedBuffer) => {
|
||||
const wavBuffer = audioBufferToWav(renderedBuffer);
|
||||
@@ -81,52 +91,89 @@ export async function renderPatternAudio(
|
||||
});
|
||||
}
|
||||
|
||||
async function renderPatternAudioWhole(audioContext, pattern, cps, begin, end) {
|
||||
/**
|
||||
* Renders a whole pattern to an OfflineAudioContext in one go.
|
||||
*
|
||||
* @param {OfflineAudioContext} audioContext The OfflineAudioContext to render to
|
||||
* @param {Pattern} pattern The pattern to render
|
||||
* @param {ExportCheckpoint[]} checkpoints A list of checkpoints indicating the cps changes throughout the song
|
||||
* @returns {Promise<AudioBuffer>}
|
||||
*/
|
||||
async function renderPatternAudioWhole(audioContext, pattern, checkpoints) {
|
||||
logger(`[webaudio] preloading`);
|
||||
|
||||
await scheduleHapsChunk(pattern, cps, begin, begin, end);
|
||||
var seconds = 0;
|
||||
|
||||
for (var i = 0; i < checkpoints.length - 1; i++) {
|
||||
const checkpointA = checkpoints[i];
|
||||
const checkpointB = checkpoints[i + 1];
|
||||
|
||||
seconds += await scheduleHapsChunk(pattern, seconds, checkpointA, checkpointB);
|
||||
}
|
||||
|
||||
logger('[webaudio] start rendering');
|
||||
|
||||
return audioContext.startRendering();
|
||||
}
|
||||
|
||||
async function renderPatternAudioInChunks(audioContext, pattern, cps, begin, end, chunkSizeInCycles) {
|
||||
let currentCycle = begin;
|
||||
let renderPromise = null;
|
||||
/**
|
||||
* Renders a whole pattern to an OfflineAudioContext in small chunks.
|
||||
* Rendering in chunks provides better rendering performance by keeping the
|
||||
* overall audio graph smaller.
|
||||
*
|
||||
* Not suppoerted on Firefox
|
||||
*
|
||||
* @param {OfflineAudioContext} audioContext
|
||||
* @param {Pattern} pattern
|
||||
* @param {ExportCheckpoint[]} checkpoints
|
||||
* @returns {Promise<AudioBuffer>}
|
||||
*/
|
||||
async function renderPatternAudioInChunks(audioContext, pattern, checkpoints) {
|
||||
let renderPromise;
|
||||
|
||||
// The grace period is used to suspend rendering before the next haps are scheduled.
|
||||
const gracePeriod = 1;
|
||||
|
||||
logger('[webaudio] start rendering');
|
||||
|
||||
while (currentCycle <= end) {
|
||||
const chunkStart = currentCycle;
|
||||
const chunkEnd = Math.min(currentCycle + chunkSizeInCycles, end);
|
||||
var lastSuspend = 0;
|
||||
var seconds = 0;
|
||||
|
||||
logger(`[webaudio] preloading cycles ${chunkStart} - ${chunkEnd}`);
|
||||
for (var i = 0; i < checkpoints.length - 1; i++) {
|
||||
const checkpointA = checkpoints[i];
|
||||
const checkpointB = checkpoints[i + 1];
|
||||
|
||||
await scheduleHapsChunk(pattern, cps, begin, chunkStart, chunkEnd);
|
||||
logger(`[webaudio] preloading cycles ${checkpointA.cycle} - ${checkpointB.cycle}`);
|
||||
|
||||
logger(`[webaudio] rendering cycles ${chunkStart} - ${chunkEnd}`);
|
||||
seconds += await scheduleHapsChunk(pattern, seconds, checkpointA, checkpointB);
|
||||
|
||||
currentCycle += chunkSizeInCycles;
|
||||
const lastCycle = i === checkpoints.length - 2;
|
||||
|
||||
// According to the MDN docs, suspends should be scheduled while
|
||||
// the audioContext is not currently running for better precision.
|
||||
// So we schedule the suspend first, and await after resuming.
|
||||
var suspendPromise;
|
||||
if (currentCycle < end) {
|
||||
// Make sure to suspend one cycle before the next currentCycle
|
||||
// so the next haps can be scheduled on time.
|
||||
suspendPromise = audioContext.suspend((currentCycle - begin - 1) / cps);
|
||||
}
|
||||
if (lastSuspend < seconds - gracePeriod || lastCycle) {
|
||||
if (lastCycle) {
|
||||
logger(`[webaudio] rendering seconds ${lastSuspend} - ${seconds}`);
|
||||
} else {
|
||||
logger(`[webaudio] rendering seconds ${lastSuspend} - ${seconds - gracePeriod}`);
|
||||
}
|
||||
|
||||
if (renderPromise === null) {
|
||||
renderPromise = audioContext.startRendering();
|
||||
} else {
|
||||
await audioContext.resume();
|
||||
}
|
||||
// According to the MDN docs, suspends should be scheduled while
|
||||
// the audioContext is not currently running for better precision.
|
||||
// So we schedule the suspend first, and await after resuming.
|
||||
var suspendPromise;
|
||||
if (!lastCycle) {
|
||||
suspendPromise = audioContext.suspend(seconds - gracePeriod);
|
||||
lastSuspend = seconds - gracePeriod;
|
||||
}
|
||||
|
||||
if (currentCycle < end) {
|
||||
await suspendPromise;
|
||||
if (renderPromise === undefined) {
|
||||
renderPromise = audioContext.startRendering();
|
||||
} else {
|
||||
await audioContext.resume();
|
||||
}
|
||||
|
||||
if (suspendPromise !== undefined) {
|
||||
await suspendPromise;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,28 +182,38 @@ async function renderPatternAudioInChunks(audioContext, pattern, cps, begin, end
|
||||
return renderPromise;
|
||||
}
|
||||
|
||||
async function scheduleHapsChunk(pattern, cps, begin, chunkStart, chunkEnd) {
|
||||
/**
|
||||
* Schedule all haps between 2 checkpoints
|
||||
*
|
||||
* @param {Pattern} pattern The pattern to render
|
||||
* @param {number} chunkStartTime The time in seconds where the chunk starts
|
||||
* @param {ExportCheckpoint} checkpointA The starting checkpoint of the chunk
|
||||
* @param {ExportCheckpoint} checkpointB The ending checkpoint of the chunk
|
||||
* @returns {number} The length of the scheduled chunk in seconds.
|
||||
*/
|
||||
async function scheduleHapsChunk(pattern, chunkStartTime, checkpointA, checkpointB) {
|
||||
// Calling superdough(...) in ascending onset time order is important
|
||||
// for controls that depend on the audio graph state like `cut`
|
||||
let haps = pattern
|
||||
.queryArc(chunkStart, chunkEnd, { _cps: cps })
|
||||
const haps = pattern
|
||||
.queryArc(checkpointA.cycle, checkpointB.cycle, { _cps: checkpointA.cps })
|
||||
.filter((hap) => hap.hasOnset())
|
||||
.sort((a, b) => a.whole.begin.valueOf() - b.whole.begin.valueOf());
|
||||
|
||||
for (const hap of haps) {
|
||||
if (hap.hasOnset()) {
|
||||
try {
|
||||
await superdough(
|
||||
hap2value(hap),
|
||||
(hap.whole.begin.valueOf() - begin) / cps,
|
||||
hap.duration / cps,
|
||||
cps,
|
||||
(hap.whole?.begin.valueOf() - begin) / cps,
|
||||
);
|
||||
} catch (err) {
|
||||
errorLogger(err, 'webaudio');
|
||||
}
|
||||
try {
|
||||
await superdough(
|
||||
hap2value(hap),
|
||||
(hap.whole.begin.valueOf() - checkpointA.cycle) / checkpointA.cps + chunkStartTime,
|
||||
hap.duration / checkpointA.cps,
|
||||
checkpointA.cps,
|
||||
(hap.whole?.begin.valueOf() - checkpointA.cycle) / checkpointA.cps + chunkStartTime,
|
||||
);
|
||||
} catch (err) {
|
||||
errorLogger(err, 'webaudio');
|
||||
}
|
||||
}
|
||||
|
||||
return (checkpointB.cycle - checkpointA.cycle) / checkpointA.cps;
|
||||
}
|
||||
|
||||
export function webaudioRepl(options = {}) {
|
||||
|
||||
Generated
+46
-8
@@ -258,6 +258,9 @@ importers:
|
||||
|
||||
packages/core:
|
||||
dependencies:
|
||||
'@strudel/pattern':
|
||||
specifier: workspace:*
|
||||
version: link:../pattern
|
||||
fraction.js:
|
||||
specifier: ^5.2.1
|
||||
version: 5.2.1
|
||||
@@ -392,6 +395,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':
|
||||
@@ -410,9 +432,9 @@ importers:
|
||||
|
||||
packages/mini:
|
||||
dependencies:
|
||||
'@strudel/core':
|
||||
'@strudel/pattern':
|
||||
specifier: workspace:*
|
||||
version: link:../core
|
||||
version: link:../pattern
|
||||
devDependencies:
|
||||
peggy:
|
||||
specifier: ^4.2.0
|
||||
@@ -500,6 +522,19 @@ 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/pattern:
|
||||
dependencies:
|
||||
fraction.js:
|
||||
specifier: ^5.2.1
|
||||
version: 5.2.1
|
||||
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)
|
||||
vitest:
|
||||
specifier: ^3.0.4
|
||||
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||
|
||||
packages/reference:
|
||||
devDependencies:
|
||||
vite:
|
||||
@@ -595,12 +630,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
|
||||
@@ -720,6 +749,9 @@ importers:
|
||||
'@strudel/draw':
|
||||
specifier: workspace:*
|
||||
version: link:../draw
|
||||
'@strudel/pattern':
|
||||
specifier: workspace:*
|
||||
version: link:../pattern
|
||||
superdough:
|
||||
specifier: workspace:*
|
||||
version: link:../superdough
|
||||
@@ -727,6 +759,9 @@ importers:
|
||||
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)
|
||||
vitest:
|
||||
specifier: ^3.0.4
|
||||
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||
|
||||
packages/websocket:
|
||||
dependencies:
|
||||
@@ -837,6 +872,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
|
||||
|
||||
@@ -11751,6 +11751,72 @@ exports[`runs examples > example "scrub" example index 1 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "scut" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | note:E3 s:piano scut:1 ]",
|
||||
"[ 0/1 → 1/2 | note:C4 s:piano scut:1 ]",
|
||||
"[ 0/1 → 1/2 | note:E4 s:piano scut:1 ]",
|
||||
"[ 0/1 → 1/2 | note:G4 s:piano scut:1 ]",
|
||||
"[ 0/1 → 1/2 | note:C5 s:piano scut:1 ]",
|
||||
"[ 1/2 → 1/1 | note:G3 s:piano scut:1 ]",
|
||||
"[ 1/2 → 1/1 | note:D4 s:piano scut:1 ]",
|
||||
"[ 1/2 → 1/1 | note:G4 s:piano scut:1 ]",
|
||||
"[ 1/2 → 1/1 | note:B4 s:piano scut:1 ]",
|
||||
"[ 1/1 → 3/2 | note:E3 s:piano scut:1 ]",
|
||||
"[ 1/1 → 3/2 | note:C4 s:piano scut:1 ]",
|
||||
"[ 1/1 → 3/2 | note:E4 s:piano scut:1 ]",
|
||||
"[ 1/1 → 3/2 | note:G4 s:piano scut:1 ]",
|
||||
"[ 1/1 → 3/2 | note:C5 s:piano scut:1 ]",
|
||||
"[ 3/2 → 2/1 | note:G3 s:piano scut:1 ]",
|
||||
"[ 3/2 → 2/1 | note:D4 s:piano scut:1 ]",
|
||||
"[ 3/2 → 2/1 | note:G4 s:piano scut:1 ]",
|
||||
"[ 3/2 → 2/1 | note:B4 s:piano scut:1 ]",
|
||||
"[ 2/1 → 5/2 | note:E3 s:piano scut:1 ]",
|
||||
"[ 2/1 → 5/2 | note:C4 s:piano scut:1 ]",
|
||||
"[ 2/1 → 5/2 | note:E4 s:piano scut:1 ]",
|
||||
"[ 2/1 → 5/2 | note:G4 s:piano scut:1 ]",
|
||||
"[ 2/1 → 5/2 | note:C5 s:piano scut:1 ]",
|
||||
"[ 5/2 → 3/1 | note:G3 s:piano scut:1 ]",
|
||||
"[ 5/2 → 3/1 | note:D4 s:piano scut:1 ]",
|
||||
"[ 5/2 → 3/1 | note:G4 s:piano scut:1 ]",
|
||||
"[ 5/2 → 3/1 | note:B4 s:piano scut:1 ]",
|
||||
"[ 3/1 → 7/2 | note:E3 s:piano scut:1 ]",
|
||||
"[ 3/1 → 7/2 | note:C4 s:piano scut:1 ]",
|
||||
"[ 3/1 → 7/2 | note:E4 s:piano scut:1 ]",
|
||||
"[ 3/1 → 7/2 | note:G4 s:piano scut:1 ]",
|
||||
"[ 3/1 → 7/2 | note:C5 s:piano scut:1 ]",
|
||||
"[ 7/2 → 4/1 | note:G3 s:piano scut:1 ]",
|
||||
"[ 7/2 → 4/1 | note:D4 s:piano scut:1 ]",
|
||||
"[ 7/2 → 4/1 | note:G4 s:piano scut:1 ]",
|
||||
"[ 7/2 → 4/1 | note:B4 s:piano scut:1 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "secondsPer" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | note:f decay:0.5 ]",
|
||||
"[ 1/4 → 1/2 | note:a decay:0.5 ]",
|
||||
"[ 1/2 → 5/8 | note:c decay:0.25 ]",
|
||||
"[ 5/8 → 3/4 | note:d decay:0.25 ]",
|
||||
"[ 3/4 → 1/1 | note:e decay:0.5 ]",
|
||||
"[ 1/1 → 5/4 | note:f decay:0.5 ]",
|
||||
"[ 5/4 → 3/2 | note:a decay:0.5 ]",
|
||||
"[ 3/2 → 13/8 | note:c decay:0.25 ]",
|
||||
"[ 13/8 → 7/4 | note:d decay:0.25 ]",
|
||||
"[ 7/4 → 2/1 | note:e decay:0.5 ]",
|
||||
"[ 2/1 → 9/4 | note:f decay:0.5 ]",
|
||||
"[ 9/4 → 5/2 | note:a decay:0.5 ]",
|
||||
"[ 5/2 → 21/8 | note:c decay:0.25 ]",
|
||||
"[ 21/8 → 11/4 | note:d decay:0.25 ]",
|
||||
"[ 11/4 → 3/1 | note:e decay:0.5 ]",
|
||||
"[ 3/1 → 13/4 | note:f decay:0.5 ]",
|
||||
"[ 13/4 → 7/2 | note:a decay:0.5 ]",
|
||||
"[ 7/2 → 29/8 | note:c decay:0.25 ]",
|
||||
"[ 29/8 → 15/4 | note:d decay:0.25 ]",
|
||||
"[ 15/4 → 4/1 | note:e decay:0.5 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "seed" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | s:bd ]",
|
||||
@@ -12831,6 +12897,181 @@ exports[`runs examples > example "slowcat" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "smooth" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | note:C3 ]",
|
||||
"[ 1/16 → 1/8 | note:D3 ]",
|
||||
"[ 1/8 → 3/16 | note:E3 ]",
|
||||
"[ 3/16 → 1/4 | note:F3 ]",
|
||||
"[ 1/4 → 5/16 | note:G3 ]",
|
||||
"[ 5/16 → 3/8 | note:A3 ]",
|
||||
"[ 3/8 → 7/16 | note:B3 ]",
|
||||
"[ 7/16 → 1/2 | note:C4 ]",
|
||||
"[ 1/2 → 9/16 | note:D4 ]",
|
||||
"[ 9/16 → 5/8 | note:C4 ]",
|
||||
"[ 5/8 → 11/16 | note:B3 ]",
|
||||
"[ 11/16 → 3/4 | note:A3 ]",
|
||||
"[ 3/4 → 13/16 | note:G3 ]",
|
||||
"[ 13/16 → 7/8 | note:F3 ]",
|
||||
"[ 7/8 → 15/16 | note:E3 ]",
|
||||
"[ 15/16 → 1/1 | note:D3 ]",
|
||||
"[ 1/1 → 17/16 | note:C3 ]",
|
||||
"[ 17/16 → 9/8 | note:D3 ]",
|
||||
"[ 9/8 → 19/16 | note:E3 ]",
|
||||
"[ 19/16 → 5/4 | note:F3 ]",
|
||||
"[ 5/4 → 21/16 | note:G3 ]",
|
||||
"[ 21/16 → 11/8 | note:A3 ]",
|
||||
"[ 11/8 → 23/16 | note:B3 ]",
|
||||
"[ 23/16 → 3/2 | note:C4 ]",
|
||||
"[ 3/2 → 25/16 | note:D4 ]",
|
||||
"[ 25/16 → 13/8 | note:C4 ]",
|
||||
"[ 13/8 → 27/16 | note:B3 ]",
|
||||
"[ 27/16 → 7/4 | note:A3 ]",
|
||||
"[ 7/4 → 29/16 | note:G3 ]",
|
||||
"[ 29/16 → 15/8 | note:F3 ]",
|
||||
"[ 15/8 → 31/16 | note:E3 ]",
|
||||
"[ 31/16 → 2/1 | note:D3 ]",
|
||||
"[ 2/1 → 33/16 | note:C3 ]",
|
||||
"[ 33/16 → 17/8 | note:D3 ]",
|
||||
"[ 17/8 → 35/16 | note:E3 ]",
|
||||
"[ 35/16 → 9/4 | note:F3 ]",
|
||||
"[ 9/4 → 37/16 | note:G3 ]",
|
||||
"[ 37/16 → 19/8 | note:A3 ]",
|
||||
"[ 19/8 → 39/16 | note:B3 ]",
|
||||
"[ 39/16 → 5/2 | note:C4 ]",
|
||||
"[ 5/2 → 41/16 | note:D4 ]",
|
||||
"[ 41/16 → 21/8 | note:C4 ]",
|
||||
"[ 21/8 → 43/16 | note:B3 ]",
|
||||
"[ 43/16 → 11/4 | note:A3 ]",
|
||||
"[ 11/4 → 45/16 | note:G3 ]",
|
||||
"[ 45/16 → 23/8 | note:F3 ]",
|
||||
"[ 23/8 → 47/16 | note:E3 ]",
|
||||
"[ 47/16 → 3/1 | note:D3 ]",
|
||||
"[ 3/1 → 49/16 | note:C3 ]",
|
||||
"[ 49/16 → 25/8 | note:D3 ]",
|
||||
"[ 25/8 → 51/16 | note:E3 ]",
|
||||
"[ 51/16 → 13/4 | note:F3 ]",
|
||||
"[ 13/4 → 53/16 | note:G3 ]",
|
||||
"[ 53/16 → 27/8 | note:A3 ]",
|
||||
"[ 27/8 → 55/16 | note:B3 ]",
|
||||
"[ 55/16 → 7/2 | note:C4 ]",
|
||||
"[ 7/2 → 57/16 | note:D4 ]",
|
||||
"[ 57/16 → 29/8 | note:C4 ]",
|
||||
"[ 29/8 → 59/16 | note:B3 ]",
|
||||
"[ 59/16 → 15/4 | note:A3 ]",
|
||||
"[ 15/4 → 61/16 | note:G3 ]",
|
||||
"[ 61/16 → 31/8 | note:F3 ]",
|
||||
"[ 31/8 → 63/16 | note:E3 ]",
|
||||
"[ 63/16 → 4/1 | note:D3 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "smooth" example index 1 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | note:C3 ]",
|
||||
"[ 1/8 → 1/4 | note:D3 ]",
|
||||
"[ 1/4 → 3/8 | note:E3 ]",
|
||||
"[ 3/8 → 1/2 | note:F3 ]",
|
||||
"[ 1/2 → 5/8 | note:G3 ]",
|
||||
"[ 5/8 → 3/4 | note:A3 ]",
|
||||
"[ 3/4 → 7/8 | note:B3 ]",
|
||||
"[ 7/8 → 1/1 | note:C4 ]",
|
||||
"[ 1/1 → 9/8 | note:C3 ]",
|
||||
"[ 9/8 → 5/4 | note:D3 ]",
|
||||
"[ 5/4 → 11/8 | note:E3 ]",
|
||||
"[ 11/8 → 3/2 | note:F3 ]",
|
||||
"[ 3/2 → 13/8 | note:G3 ]",
|
||||
"[ 13/8 → 7/4 | note:A3 ]",
|
||||
"[ 7/4 → 15/8 | note:B3 ]",
|
||||
"[ 15/8 → 2/1 | note:C4 ]",
|
||||
"[ 2/1 → 17/8 | note:C3 ]",
|
||||
"[ 17/8 → 9/4 | note:D3 ]",
|
||||
"[ 9/4 → 19/8 | note:E3 ]",
|
||||
"[ 19/8 → 5/2 | note:F3 ]",
|
||||
"[ 5/2 → 21/8 | note:G3 ]",
|
||||
"[ 21/8 → 11/4 | note:A3 ]",
|
||||
"[ 11/4 → 23/8 | note:B3 ]",
|
||||
"[ 23/8 → 3/1 | note:C4 ]",
|
||||
"[ 3/1 → 25/8 | note:C3 ]",
|
||||
"[ 25/8 → 13/4 | note:D3 ]",
|
||||
"[ 13/4 → 27/8 | note:E3 ]",
|
||||
"[ 27/8 → 7/2 | note:F3 ]",
|
||||
"[ 7/2 → 29/8 | note:G3 ]",
|
||||
"[ 29/8 → 15/4 | note:A3 ]",
|
||||
"[ 15/4 → 31/8 | note:B3 ]",
|
||||
"[ 31/8 → 4/1 | note:C4 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "smooth" example index 2 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0 ]",
|
||||
"[ 1/16 → 1/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.0625 ]",
|
||||
"[ 1/8 → 3/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.125 ]",
|
||||
"[ 3/16 → 1/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:0.1875 ]",
|
||||
"[ 1/4 → 5/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.25 ]",
|
||||
"[ 5/16 → 3/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:0.3125 ]",
|
||||
"[ 3/8 → 7/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.375 ]",
|
||||
"[ 7/16 → 1/2 | note:E3 s:saw cutoff:100 resonance:7 lpenv:0.4375 ]",
|
||||
"[ 1/2 → 9/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.5 ]",
|
||||
"[ 9/16 → 5/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.5625 ]",
|
||||
"[ 5/8 → 11/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.625 ]",
|
||||
"[ 11/16 → 3/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:0.6875 ]",
|
||||
"[ 3/4 → 13/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.75 ]",
|
||||
"[ 13/16 → 7/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:0.8125 ]",
|
||||
"[ 7/8 → 15/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:0.875 ]",
|
||||
"[ 15/16 → 1/1 | note:E3 s:saw cutoff:100 resonance:7 lpenv:0.9375 ]",
|
||||
"[ 1/1 → 17/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1 ]",
|
||||
"[ 17/16 → 9/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.0208333333333333 ]",
|
||||
"[ 9/8 → 19/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.0416666666666667 ]",
|
||||
"[ 19/16 → 5/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.0625 ]",
|
||||
"[ 5/4 → 21/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.0833333333333333 ]",
|
||||
"[ 21/16 → 11/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.1041666666666667 ]",
|
||||
"[ 11/8 → 23/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.125 ]",
|
||||
"[ 23/16 → 3/2 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.1458333333333333 ]",
|
||||
"[ 3/2 → 25/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.1666666666666667 ]",
|
||||
"[ 25/16 → 13/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.1875 ]",
|
||||
"[ 13/8 → 27/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.2083333333333333 ]",
|
||||
"[ 27/16 → 7/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.2291666666666667 ]",
|
||||
"[ 7/4 → 29/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.25 ]",
|
||||
"[ 29/16 → 15/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.2708333333333333 ]",
|
||||
"[ 15/8 → 31/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.2916666666666667 ]",
|
||||
"[ 31/16 → 2/1 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.3125 ]",
|
||||
"[ 2/1 → 33/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.3333333333333333 ]",
|
||||
"[ 33/16 → 17/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.3541666666666667 ]",
|
||||
"[ 17/8 → 35/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.375 ]",
|
||||
"[ 35/16 → 9/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.3958333333333333 ]",
|
||||
"[ 9/4 → 37/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.4166666666666667 ]",
|
||||
"[ 37/16 → 19/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.4375 ]",
|
||||
"[ 19/8 → 39/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.4583333333333333 ]",
|
||||
"[ 39/16 → 5/2 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.4791666666666667 ]",
|
||||
"[ 5/2 → 41/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.5 ]",
|
||||
"[ 41/16 → 21/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.5208333333333335 ]",
|
||||
"[ 21/8 → 43/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.5416666666666665 ]",
|
||||
"[ 43/16 → 11/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.5625 ]",
|
||||
"[ 11/4 → 45/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.5833333333333335 ]",
|
||||
"[ 45/16 → 23/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.6041666666666665 ]",
|
||||
"[ 23/8 → 47/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.625 ]",
|
||||
"[ 47/16 → 3/1 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.6458333333333335 ]",
|
||||
"[ 3/1 → 49/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.6666666666666665 ]",
|
||||
"[ 49/16 → 25/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.6875 ]",
|
||||
"[ 25/8 → 51/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.7083333333333335 ]",
|
||||
"[ 51/16 → 13/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.7291666666666665 ]",
|
||||
"[ 13/4 → 53/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.75 ]",
|
||||
"[ 53/16 → 27/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.7708333333333335 ]",
|
||||
"[ 27/8 → 55/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.7916666666666665 ]",
|
||||
"[ 55/16 → 7/2 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.8125 ]",
|
||||
"[ 7/2 → 57/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.8333333333333335 ]",
|
||||
"[ 57/16 → 29/8 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.8541666666666665 ]",
|
||||
"[ 29/8 → 59/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.875 ]",
|
||||
"[ 59/16 → 15/4 | note:A2 s:saw cutoff:100 resonance:7 lpenv:1.8958333333333335 ]",
|
||||
"[ 15/4 → 61/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.9166666666666665 ]",
|
||||
"[ 61/16 → 31/8 | note:B2 s:saw cutoff:100 resonance:7 lpenv:1.9375 ]",
|
||||
"[ 31/8 → 63/16 | note:E2 s:saw cutoff:100 resonance:7 lpenv:1.9583333333333335 ]",
|
||||
"[ 63/16 → 4/1 | note:E3 s:saw cutoff:100 resonance:7 lpenv:1.9791666666666665 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "someCycles" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:hh speed:0.5 ]",
|
||||
@@ -14108,106 +14349,76 @@ exports[`runs examples > example "sustain" example index 0 1`] = `
|
||||
|
||||
exports[`runs examples > example "swing" example index 0 1`] = `
|
||||
[
|
||||
"[ -1/12 ⇜ (0/1 → 1/24) | s:hh ]",
|
||||
"[ 0/1 → 1/8 | s:hh ]",
|
||||
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
|
||||
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
|
||||
"[ 1/6 → 7/24 | s:hh ]",
|
||||
"[ 1/4 → 3/8 | s:hh ]",
|
||||
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
|
||||
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
|
||||
"[ 5/12 → 13/24 | s:hh ]",
|
||||
"[ 1/2 → 5/8 | s:hh ]",
|
||||
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
|
||||
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
|
||||
"[ 2/3 → 19/24 | s:hh ]",
|
||||
"[ 3/4 → 7/8 | s:hh ]",
|
||||
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
|
||||
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
|
||||
"[ 11/12 → 25/24 | s:hh ]",
|
||||
"[ 1/1 → 9/8 | s:hh ]",
|
||||
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
|
||||
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
|
||||
"[ 7/6 → 31/24 | s:hh ]",
|
||||
"[ 5/4 → 11/8 | s:hh ]",
|
||||
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
|
||||
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
|
||||
"[ 17/12 → 37/24 | s:hh ]",
|
||||
"[ 3/2 → 13/8 | s:hh ]",
|
||||
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
|
||||
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
|
||||
"[ 5/3 → 43/24 | s:hh ]",
|
||||
"[ 7/4 → 15/8 | s:hh ]",
|
||||
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
|
||||
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
|
||||
"[ 23/12 → 49/24 | s:hh ]",
|
||||
"[ 2/1 → 17/8 | s:hh ]",
|
||||
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
|
||||
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
|
||||
"[ 13/6 → 55/24 | s:hh ]",
|
||||
"[ 9/4 → 19/8 | s:hh ]",
|
||||
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
|
||||
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
|
||||
"[ 29/12 → 61/24 | s:hh ]",
|
||||
"[ 5/2 → 21/8 | s:hh ]",
|
||||
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
|
||||
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
|
||||
"[ 8/3 → 67/24 | s:hh ]",
|
||||
"[ 11/4 → 23/8 | s:hh ]",
|
||||
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
|
||||
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
|
||||
"[ 35/12 → 73/24 | s:hh ]",
|
||||
"[ 3/1 → 25/8 | s:hh ]",
|
||||
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
|
||||
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
|
||||
"[ 19/6 → 79/24 | s:hh ]",
|
||||
"[ 13/4 → 27/8 | s:hh ]",
|
||||
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
|
||||
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
|
||||
"[ 41/12 → 85/24 | s:hh ]",
|
||||
"[ 7/2 → 29/8 | s:hh ]",
|
||||
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
|
||||
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
|
||||
"[ 11/3 → 91/24 | s:hh ]",
|
||||
"[ 15/4 → 31/8 | s:hh ]",
|
||||
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
|
||||
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "swingBy" example index 0 1`] = `
|
||||
[
|
||||
"[ -1/12 ⇜ (0/1 → 1/24) | s:hh ]",
|
||||
"[ 0/1 → 1/8 | s:hh ]",
|
||||
"[ 1/24 ⇜ (1/8 → 1/6) | s:hh ]",
|
||||
"[ (1/6 → 1/4) ⇝ 7/24 | s:hh ]",
|
||||
"[ 1/6 → 7/24 | s:hh ]",
|
||||
"[ 1/4 → 3/8 | s:hh ]",
|
||||
"[ 7/24 ⇜ (3/8 → 5/12) | s:hh ]",
|
||||
"[ (5/12 → 1/2) ⇝ 13/24 | s:hh ]",
|
||||
"[ 5/12 → 13/24 | s:hh ]",
|
||||
"[ 1/2 → 5/8 | s:hh ]",
|
||||
"[ 13/24 ⇜ (5/8 → 2/3) | s:hh ]",
|
||||
"[ (2/3 → 3/4) ⇝ 19/24 | s:hh ]",
|
||||
"[ 2/3 → 19/24 | s:hh ]",
|
||||
"[ 3/4 → 7/8 | s:hh ]",
|
||||
"[ 19/24 ⇜ (7/8 → 11/12) | s:hh ]",
|
||||
"[ (11/12 → 1/1) ⇝ 25/24 | s:hh ]",
|
||||
"[ 11/12 → 25/24 | s:hh ]",
|
||||
"[ 1/1 → 9/8 | s:hh ]",
|
||||
"[ 25/24 ⇜ (9/8 → 7/6) | s:hh ]",
|
||||
"[ (7/6 → 5/4) ⇝ 31/24 | s:hh ]",
|
||||
"[ 7/6 → 31/24 | s:hh ]",
|
||||
"[ 5/4 → 11/8 | s:hh ]",
|
||||
"[ 31/24 ⇜ (11/8 → 17/12) | s:hh ]",
|
||||
"[ (17/12 → 3/2) ⇝ 37/24 | s:hh ]",
|
||||
"[ 17/12 → 37/24 | s:hh ]",
|
||||
"[ 3/2 → 13/8 | s:hh ]",
|
||||
"[ 37/24 ⇜ (13/8 → 5/3) | s:hh ]",
|
||||
"[ (5/3 → 7/4) ⇝ 43/24 | s:hh ]",
|
||||
"[ 5/3 → 43/24 | s:hh ]",
|
||||
"[ 7/4 → 15/8 | s:hh ]",
|
||||
"[ 43/24 ⇜ (15/8 → 23/12) | s:hh ]",
|
||||
"[ (23/12 → 2/1) ⇝ 49/24 | s:hh ]",
|
||||
"[ 23/12 → 49/24 | s:hh ]",
|
||||
"[ 2/1 → 17/8 | s:hh ]",
|
||||
"[ 49/24 ⇜ (17/8 → 13/6) | s:hh ]",
|
||||
"[ (13/6 → 9/4) ⇝ 55/24 | s:hh ]",
|
||||
"[ 13/6 → 55/24 | s:hh ]",
|
||||
"[ 9/4 → 19/8 | s:hh ]",
|
||||
"[ 55/24 ⇜ (19/8 → 29/12) | s:hh ]",
|
||||
"[ (29/12 → 5/2) ⇝ 61/24 | s:hh ]",
|
||||
"[ 29/12 → 61/24 | s:hh ]",
|
||||
"[ 5/2 → 21/8 | s:hh ]",
|
||||
"[ 61/24 ⇜ (21/8 → 8/3) | s:hh ]",
|
||||
"[ (8/3 → 11/4) ⇝ 67/24 | s:hh ]",
|
||||
"[ 8/3 → 67/24 | s:hh ]",
|
||||
"[ 11/4 → 23/8 | s:hh ]",
|
||||
"[ 67/24 ⇜ (23/8 → 35/12) | s:hh ]",
|
||||
"[ (35/12 → 3/1) ⇝ 73/24 | s:hh ]",
|
||||
"[ 35/12 → 73/24 | s:hh ]",
|
||||
"[ 3/1 → 25/8 | s:hh ]",
|
||||
"[ 73/24 ⇜ (25/8 → 19/6) | s:hh ]",
|
||||
"[ (19/6 → 13/4) ⇝ 79/24 | s:hh ]",
|
||||
"[ 19/6 → 79/24 | s:hh ]",
|
||||
"[ 13/4 → 27/8 | s:hh ]",
|
||||
"[ 79/24 ⇜ (27/8 → 41/12) | s:hh ]",
|
||||
"[ (41/12 → 7/2) ⇝ 85/24 | s:hh ]",
|
||||
"[ 41/12 → 85/24 | s:hh ]",
|
||||
"[ 7/2 → 29/8 | s:hh ]",
|
||||
"[ 85/24 ⇜ (29/8 → 11/3) | s:hh ]",
|
||||
"[ (11/3 → 15/4) ⇝ 91/24 | s:hh ]",
|
||||
"[ 11/3 → 91/24 | s:hh ]",
|
||||
"[ 15/4 → 31/8 | s:hh ]",
|
||||
"[ 91/24 ⇜ (31/8 → 47/12) | s:hh ]",
|
||||
"[ (47/12 → 4/1) ⇝ 97/24 | s:hh ]",
|
||||
]
|
||||
`;
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
import { afterEach } from 'vitest';
|
||||
import { useRNG } from './packages/core/signal.mjs';
|
||||
import { setDefaultJoin } from './packages/core/pattern.mjs';
|
||||
import { useRNG, setDefaultJoin } from './packages/pattern/index.mjs';
|
||||
|
||||
afterEach(() => {
|
||||
// Avoid bleed between tests
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
"@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",
|
||||
|
||||
+17
-61
@@ -2,23 +2,20 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
|
||||
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
|
||||
import { MiniRepl } from './MiniRepl';
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Object} arguments
|
||||
* @param {number} [arguments.h] Adds a heading (like 3 for h3). Deprecated, add the heading in MDX instead.
|
||||
* @returns
|
||||
*/
|
||||
export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasHeight, hideMiniRepl }) {
|
||||
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
|
||||
const item = docs[name];
|
||||
if (!item) {
|
||||
console.warn(`JsDoc for ${name} not found`);
|
||||
return <div>Could not load docs for ${name}</div>;
|
||||
console.warn('Not found: ' + name);
|
||||
return <div />;
|
||||
}
|
||||
const CustomHeading = h ? `h${h}` : undefined;
|
||||
const description = parseAndReplaceLink(item.description ?? '');
|
||||
const CustomHeading = `h${h}`;
|
||||
const description =
|
||||
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
|
||||
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
|
||||
}) || '';
|
||||
return (
|
||||
<>
|
||||
{!!h && <CustomHeading id={name}>{item.longname}</CustomHeading>}
|
||||
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
|
||||
{!hideDescription && (
|
||||
<>
|
||||
{!!item.synonyms_text && (
|
||||
@@ -29,43 +26,19 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
|
||||
<div dangerouslySetInnerHTML={{ __html: description }} />
|
||||
</>
|
||||
)}
|
||||
{item.params && item.params.length > 0 && <p className="font-bold">Arguments</p>}
|
||||
<ul>
|
||||
{item.params?.map(({ name, type, description }, i) => {
|
||||
// Check if the param is actually the parameter of an object
|
||||
const objParamSeperator = name.indexOf('.');
|
||||
const isObjectParam = objParamSeperator !== -1;
|
||||
|
||||
return (
|
||||
<li key={i} className={isObjectParam ? 'list-none' : ''}>
|
||||
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
|
||||
{description ? <> - {removeHtmlTags(description)}</> : ''}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
{item.params?.map((param, i) => (
|
||||
<li key={i}>
|
||||
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{item.returns && (
|
||||
<p>
|
||||
<span className="font-bold">Returns</span>{' '}
|
||||
{item.returns
|
||||
.map((returnValue) => {
|
||||
const description = returnValue.description ? `- ${removeHtmlTags(returnValue.description)}` : '';
|
||||
return `${returnValue.type?.names?.join(' | ')} ${description}`;
|
||||
})
|
||||
.join(' or ')}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{item.examples?.length ? (
|
||||
<div className="space-y-2">
|
||||
{item.examples?.map((example, k) => {
|
||||
const key = `${item.longname}_example_${k}`;
|
||||
return hideMiniRepl ? (
|
||||
<pre key={key}>{example}</pre>
|
||||
) : (
|
||||
<MiniRepl tune={example} key={key} {...{ punchcard, canvasHeight }} />
|
||||
);
|
||||
})}
|
||||
{item.examples?.map((example, k) => (
|
||||
<MiniRepl tune={example} key={k} {...{ punchcard, canvasHeight }} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div />
|
||||
@@ -73,20 +46,3 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the jsDocs link with something else.
|
||||
* @param {string} string
|
||||
* @param {(name:string,longname: string) => string} [replaceWith]
|
||||
*/
|
||||
export const parseAndReplaceLink = (string, replaceWith) => {
|
||||
const jsDocsLinkRegex = /\{@link ([a-zA-Z\.#]+)\}/g;
|
||||
const fun = replaceWith ?? ((name, longname) => `<a target="_blank" href="/reference#${longname}">${name}</a>`);
|
||||
|
||||
return string.replaceAll(jsDocsLinkRegex, (_, longname) => {
|
||||
const name = [...longname.matchAll(/[a-zA-Z]*[\.#]?([a-zA-Z]+)/g)].at(0)?.at(1); //take the string after . or #
|
||||
return fun(name ?? longname, longname);
|
||||
});
|
||||
};
|
||||
|
||||
const removeHtmlTags = (string) => string.replace(/(<([^>]+)>)/gi, '');
|
||||
|
||||
@@ -3,7 +3,6 @@ import { memo, useEffect, useMemo, useState, Fragment } from 'react';
|
||||
import jsdocJson from '../../../../../doc.json';
|
||||
import { Textbox } from '@src/repl/components/panel/SettingsTab';
|
||||
import { settingsMap, useSettings } from '@src/settings.mjs';
|
||||
import { JsDoc } from '@src/docs/JsDoc';
|
||||
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
|
||||
|
||||
const availableFunctions = computeAvailableFunctions(jsdocJson);
|
||||
@@ -179,7 +178,48 @@ export const Reference = memo(function Reference() {
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<JsDoc name={entry.longname} hideMiniRepl></JsDoc>
|
||||
{!!entry.synonyms_text && (
|
||||
<p>
|
||||
Synonyms: <code>{entry.synonyms_text}</code>
|
||||
</p>
|
||||
)}
|
||||
|
||||
<p
|
||||
dangerouslySetInnerHTML={{
|
||||
// If we have an external url make sure it opens in another tab to not interrupt the player
|
||||
__html: entry.description.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`),
|
||||
}}
|
||||
></p>
|
||||
{entry.params && entry.params.length > 0 && <p className="font-bold">Arguments</p>}
|
||||
<ul>
|
||||
{entry.params?.map(({ name, type, description }, i) => {
|
||||
// Check if the param is actually the parameter of an object
|
||||
const objParamSeperator = name.indexOf('.');
|
||||
const isObjectParam = objParamSeperator !== -1;
|
||||
|
||||
return (
|
||||
<li key={i} className={isObjectParam ? 'list-none' : ''}>
|
||||
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
|
||||
{description ? <> - {getInnerText(description)}</> : ''}
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
{entry.returns && (
|
||||
<p>
|
||||
<span className="font-bold">Returns</span>{' '}
|
||||
{entry.returns.map(({ type, description }) => (
|
||||
<>
|
||||
{type?.names?.join(' | ')} {description ? <> - {getInnerText(description)}</> : ''}
|
||||
</>
|
||||
))}
|
||||
</p>
|
||||
)}
|
||||
{entry.examples?.map((example, j) => (
|
||||
<pre className="bg-background border border-muted" key={j}>
|
||||
{example}
|
||||
</pre>
|
||||
))}
|
||||
</section>
|
||||
)) || <p className="font-sans">Search or select a tag to get started.</p>}
|
||||
{detailVisibleFunctions.length > 0 && <div className="h-screen" />}
|
||||
|
||||
@@ -37,8 +37,11 @@ export function WelcomeTab({ context }) {
|
||||
tidalcycles
|
||||
</a>
|
||||
, which is a popular live coding language for music, written in Haskell. Strudel is free/open source software,
|
||||
with copyright owned by its [contributors](https://codeberg.org/uzu/strudel/activity/contributors). You can
|
||||
redistribute and/or modify it under the terms of the{' '}
|
||||
with copyright owned by its{' '}
|
||||
<a href="https://codeberg.org/uzu/strudel/activity/contributors" target="_blank">
|
||||
contributors
|
||||
</a>
|
||||
. You can redistribute and/or modify it under the terms of the{' '}
|
||||
<a href="https://codeberg.org/uzu/strudel/src/branch/main/LICENSE" target="_blank">
|
||||
GNU Affero General Public License
|
||||
</a>
|
||||
|
||||
@@ -89,6 +89,7 @@ export function loadModules() {
|
||||
import('@strudel/mqtt'),
|
||||
import('@strudel/mondo'),
|
||||
import('@strudel/dough'),
|
||||
import('@strudel/kabelsalat'),
|
||||
];
|
||||
if (isTauri()) {
|
||||
modules = modules.concat([
|
||||
|
||||
Reference in New Issue
Block a user