mirror of
https://codeberg.org/uzu/strudel
synced 2026-12-06 13:42:47 -05:00
Compare commits
180 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fff2610a19 | |||
| 217fac5e11 | |||
| 207c9d5470 | |||
| 7a1075b746 | |||
| 34b7a81c8b | |||
| b30e3ad88f | |||
| 70b44f6694 | |||
| fdc5db6b9b | |||
| b49981aea6 | |||
| 0c38bfaf99 | |||
| d6ce044ccb | |||
| 255314f7fa | |||
| acf4628a16 | |||
| 2a35745f73 | |||
| 787f44bb38 | |||
| db62b8b6aa | |||
| dc1fe808c0 | |||
| a61418c54c | |||
| 2feba92516 | |||
| 2b001170de | |||
| fe06a1e59e | |||
| a4b83a364b | |||
| 1d8d0dae8c | |||
| d3a6cef369 | |||
| d0de54a880 | |||
| d1a4c3c60e | |||
| 118de38551 | |||
| 8bde1314c5 | |||
| f13dbe00e1 | |||
| 68598a674b | |||
| db2835c5cb | |||
| f92d6a0a03 | |||
| 31730842a7 | |||
| 9e92aba3de | |||
| 789376d151 | |||
| 0fc0996d5c | |||
| e000020a9f | |||
| 926cd6b772 | |||
| b1b026b56c | |||
| 49926243f6 | |||
| b298ac7b53 | |||
| cd7c88e768 | |||
| 4694c59d74 | |||
| 9e00181020 | |||
| ad98f1050d | |||
| e1e156296a | |||
| 4db94e163c | |||
| 438eb553bd | |||
| 379c075d56 | |||
| a261d47b4e | |||
| 8b1d68e494 | |||
| 6e550f5a6c | |||
| 2271593c06 | |||
| 7dd9cacc37 | |||
| 446f8468c4 | |||
| 28a6c304cd | |||
| 2668f4be2c | |||
| 4ddd09cf64 | |||
| 96f8c545ae | |||
| 1686ff877c | |||
| 83b1c89d25 | |||
| 1743f65e61 | |||
| bb4b8bb27e | |||
| bdac0eccbd | |||
| 6333fa1ddf | |||
| 41e6084823 | |||
| fe9a75c9b6 | |||
| cd7c1dbd97 | |||
| 25b9fd991a | |||
| 375b25afd7 | |||
| d3d311e105 | |||
| afc7f1aab1 | |||
| 4b3c6f90a5 | |||
| 5e82110522 | |||
| 4616b374f3 | |||
| 08e9e3893e | |||
| 98b71bcb4d | |||
| cf7dae5d7f | |||
| b3d9eab3b6 | |||
| 067f002d93 | |||
| c799a686c0 | |||
| f805560827 | |||
| f8bb10d2a0 | |||
| a160f76d23 | |||
| 3fc1cc871c | |||
| 2c2c6bc6bf | |||
| 089187b9b2 | |||
| dc441e68df | |||
| c6253789ab | |||
| 9e5e172931 | |||
| 1f5b8d6bcc | |||
| b8b59d911f | |||
| 11e64428dd | |||
| 551e8aed5e | |||
| a5079db6f7 | |||
| 36647afbbf | |||
| d13f040617 | |||
| 92b7db3a97 | |||
| aad846a45f | |||
| 4a060f20f2 | |||
| 3a5d917d7d | |||
| 893cd9e051 | |||
| c019be29ac | |||
| e263096efa | |||
| e74be00a7c | |||
| d90dd71bd9 | |||
| a14aaacc4f | |||
| aa3aea4398 | |||
| dcca8e45b1 | |||
| 16b2dba3b1 | |||
| 041815e466 | |||
| df27ef6fa9 | |||
| f6315df48a | |||
| faf8522de0 | |||
| c7d5ace20a | |||
| 441950898f | |||
| bd9d3f475b | |||
| c465eda72f | |||
| 03b0ac7e7b | |||
| 034f7d4332 | |||
| 7d195eb63f | |||
| 844ff20ce3 | |||
| f9aceecd5a | |||
| 5604087bc9 | |||
| bf49b35e59 | |||
| 636e97297f | |||
| 02a8f9ef36 | |||
| a85d7793ed | |||
| 9851807be7 | |||
| 4c237e49c3 | |||
| f9f5d853b2 | |||
| b87648ef11 | |||
| daa9065216 | |||
| b556b604aa | |||
| 57872d459f | |||
| 4b989018a7 | |||
| 4530ed9a3a | |||
| f331eda10d | |||
| 0eeeca8fb1 | |||
| b11ba9f2d9 | |||
| fc271a8879 | |||
| fdf243acee | |||
| 429dbcd80e | |||
| 6a85f711d2 | |||
| eca9f57e68 | |||
| d87abea11c | |||
| 08d2a4e3ae | |||
| 1756713096 | |||
| 841abc4827 | |||
| 46f01053da | |||
| 9feb0f44cf | |||
| e12e980e04 | |||
| d25df719df | |||
| d71526d946 | |||
| 7a343930aa | |||
| 266e5da109 | |||
| 5f88fab5d0 | |||
| 207fa00eac | |||
| 897ec4971d | |||
| d784f62d4d | |||
| f47caac716 | |||
| 0a88f2608a | |||
| 32d295d668 | |||
| 7d2d5db95d | |||
| 3c32b3b0aa | |||
| c492e21e1d | |||
| 88b7d14487 | |||
| 3ac25f7960 | |||
| 8b3ae4c514 | |||
| 9dc19fb9bf | |||
| 4a158db9d2 | |||
| 55839e7ee8 | |||
| 9aaa9bee6b | |||
| 1834d689ef | |||
| 77a7a148f0 | |||
| 52931e879d | |||
| d5c9be1c30 | |||
| 2b30ab3008 | |||
| 13cbeb3f67 | |||
| 352d8659ec |
@@ -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:
|
||||
@@ -44,6 +44,7 @@ Dirt-Samples
|
||||
tidal-drum-machines
|
||||
webaudiofontdata
|
||||
src-tauri/target
|
||||
mise.local.toml
|
||||
|
||||
# BEGIN JetBrains -> END JetBrains
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
In line with [our humane policy](POLICY.md#post-ai-humane-policy-for-live-coding-development), code and documentation
|
||||
should not be written by LLM agents. To this end, agents should not
|
||||
edit the codebase or make any commits that are intended to be
|
||||
contributed upstream. Likewise, LLM output should not be pasted into
|
||||
issues, comments, pull requests and so on.
|
||||
|
||||
A contributor's personal use of LLMs and related technology is their
|
||||
own business, whether for research, analysis, bug discovery or other
|
||||
assistive technology, so long as the output is not included in any
|
||||
contributions to our projects.
|
||||
|
||||
Strudel is [AGPL licensed](LICENSE), and so any code integrated with it also
|
||||
comes under that license. This should be carefully considered before
|
||||
distributing software integrated with strudel, including making it
|
||||
available over a network.
|
||||
|
||||
Strudel has purposefully moved away from github.com, as a closed
|
||||
source platform with ethical issues. Please do not fork strudel back
|
||||
to that platform, or similar corporate platforms.
|
||||
|
||||
Strudel's git repo is hosted by codeberg, which attempts to block bots
|
||||
including LLMs from accessing it, to avoid being overloaded. Agents
|
||||
should not try to circumvent this, instead encouraging developers
|
||||
to engage with the strudel community directly.
|
||||
|
||||
Projects using strudel must not use "strudel" in their name, unless
|
||||
they are 'official' projects, or have the blessing of the strudel
|
||||
community.
|
||||
@@ -5,6 +5,7 @@ import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import js from '@eslint/js';
|
||||
import { FlatCompat } from '@eslint/eslintrc';
|
||||
import { jsdoc } from 'eslint-plugin-jsdoc';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
@@ -93,4 +94,51 @@ export default [
|
||||
},
|
||||
},
|
||||
},
|
||||
jsdoc({
|
||||
files: ['packages/**/*.{js,mjs}'],
|
||||
config: 'flat/recommended-error',
|
||||
rules: {
|
||||
'jsdoc/no-undefined-types': [
|
||||
'error',
|
||||
{ definedTypes: ['Pattern', 'Pattern.prototype', 'Hap', 'KabelsalatExpression', 'TimeSpan', 'State'] },
|
||||
],
|
||||
'jsdoc/check-tag-names': ['error', { definedTags: ['tags', 'synonyms', 'noAutocomplete', 'superdirtOnly'] }],
|
||||
'jsdoc/no-restricted-syntax': [
|
||||
'error',
|
||||
{
|
||||
contexts: [
|
||||
{
|
||||
//@memberof without a .prototype
|
||||
comment:
|
||||
'JsdocBlock:has(JsdocTag[tag="memberof"]:not([name=/\\.prototype(?:\\s|$)/]):not([description=/\\.prototype(?:\\s|$)/]))',
|
||||
context: 'any',
|
||||
message: "Use '@memberof <Name>.prototype' instead.",
|
||||
},
|
||||
{
|
||||
context: 'FunctionDeclaration',
|
||||
comment: 'JsdocBlock:not(:has(JsdocTag[tag=/^(global|memberof)$/]))',
|
||||
message: 'JSDoc block should be explicitly labeled as @global or @memberof.',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
'jsdoc/require-description': 'error',
|
||||
'jsdoc/no-defaults': 0, //removes defaults with no alternative
|
||||
'jsdoc/require-jsdoc': 0,
|
||||
'jsdoc/tag-lines': 0,
|
||||
'jsdoc/require-returns-description': 0,
|
||||
'jsdoc/require-param-description': 0,
|
||||
'jsdoc/no-multi-asterisks': 0,
|
||||
'jsdoc/multiline-blocks': 0,
|
||||
'jsdoc/check-alignment': 0,
|
||||
'jsdoc/reject-any-type': 0,
|
||||
'jsdoc/reject-function-type': 0,
|
||||
},
|
||||
}),
|
||||
jsdoc({
|
||||
files: ['packages/core/**/*.{js,mjs}', 'packages/pattern/**/*.{js,mjs}'],
|
||||
rules: {
|
||||
'jsdoc/require-jsdoc': ['warn', { publicOnly: {}, enableFixer: false }],
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
@@ -3,9 +3,12 @@
|
||||
"includePattern": ".+\\.(js(doc|x)?|mjs)$",
|
||||
"excludePattern": "node_modules|shift-parser|shift-reducer|shift-traverser|dist"
|
||||
},
|
||||
"plugins": ["plugins/markdown", "jsdoc/jsdoc-synonyms"],
|
||||
"plugins": [
|
||||
"plugins/markdown",
|
||||
"jsdoc/jsdoc-synonyms"
|
||||
],
|
||||
"opts": {
|
||||
"destination": "./out/",
|
||||
"recurse": true
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-9
@@ -1,16 +1,19 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { dirname, resolve, win32, posix } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { parse } from 'acorn';
|
||||
import dependencyTree from 'dependency-tree';
|
||||
import { platform } from 'node:process';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const packageRoot = resolve(__dirname, '..');
|
||||
|
||||
function getExports(code) {
|
||||
// parse it with acorn
|
||||
let ast;
|
||||
try {
|
||||
ast = parse(code, {
|
||||
ecmaVersion: 11,
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -64,21 +67,26 @@ async function getUndocumented(path, docs) {
|
||||
}
|
||||
}
|
||||
|
||||
function getPackageRelativePosixPath(path) {
|
||||
path = path.replace(packageRoot, '');
|
||||
if (platform === 'win32') {
|
||||
path = path.replaceAll(win32.sep, posix.sep);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
// read doc.json file
|
||||
const { docs } = JSON.parse(await readFile(resolve(__dirname, '..', 'doc.json'), 'utf8'));
|
||||
const excludedFileTypes = /\.json$/;
|
||||
|
||||
const paths = dependencyTree.toList({
|
||||
filename: 'index.mjs',
|
||||
// filename: 'packages/core/index.mjs',
|
||||
directory: resolve(__dirname),
|
||||
filter: (path) => !path.includes('node_modules'),
|
||||
directory: packageRoot,
|
||||
filter: (path) => !path.includes('node_modules') && !excludedFileTypes.test(path),
|
||||
});
|
||||
// const paths = ['../packages/core/pattern.mjs', '../packages/core/hap.mjs'].map((rel) => resolve(__dirname, rel));
|
||||
|
||||
const undocumented = Object.fromEntries(
|
||||
await Promise.all(
|
||||
paths.map(async (path) => [path.replace(resolve(__dirname, '..'), ''), await getUndocumented(path, docs)]),
|
||||
),
|
||||
await Promise.all(paths.map(async (path) => [getPackageRelativePosixPath(path), await getUndocumented(path, docs)])),
|
||||
);
|
||||
|
||||
console.log(JSON.stringify(undocumented, null, 2));
|
||||
|
||||
+3
-2
@@ -67,14 +67,15 @@
|
||||
"dependency-tree": "^11.0.1",
|
||||
"eslint": "^9.19.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"eslint-plugin-jsdoc": "^65.5.3",
|
||||
"events": "^3.3.0",
|
||||
"globals": "^15.14.0",
|
||||
"jsdoc": "^4.0.4",
|
||||
"jsdoc-json": "^2.0.2",
|
||||
"lerna": "^8.1.9",
|
||||
"prettier": "^3.4.2",
|
||||
"vitest": "^3.0.4",
|
||||
"vite-plugin-bundle-audioworklet": "workspace:*"
|
||||
"vite-plugin-bundle-audioworklet": "workspace:*",
|
||||
"vitest": "^3.0.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { closeBrackets } from '@codemirror/autocomplete';
|
||||
import { indentWithTab } from '@codemirror/commands';
|
||||
import { indentWithTab, toggleLineComment, redo } from '@codemirror/commands';
|
||||
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
||||
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
||||
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||
@@ -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([
|
||||
{
|
||||
@@ -111,6 +112,10 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
||||
key: 'Alt-Enter',
|
||||
run: () => onEvaluate?.(),
|
||||
},
|
||||
{
|
||||
key: 'Ctrl-Shift-z',
|
||||
run: redo,
|
||||
},
|
||||
{
|
||||
key: 'Ctrl-.',
|
||||
run: () => onStop?.(),
|
||||
@@ -398,7 +403,8 @@ function s4() {
|
||||
/**
|
||||
* Overrides the css of highlighted events. Make sure to use single quotes!
|
||||
* @name markcss
|
||||
* @tag visualization
|
||||
* @tags visualization
|
||||
* @memberof Pattern.prototype
|
||||
* @example
|
||||
* note("c a f e")
|
||||
* .markcss('text-decoration:underline')
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -113,15 +113,17 @@ export const sliderPlugin = ViewPlugin.fromClass(
|
||||
},
|
||||
);
|
||||
|
||||
/* eslint jsdoc/check-param-names: "off" */
|
||||
/**
|
||||
* Displays a slider widget to allow the user manipulate a value
|
||||
*
|
||||
* @name slider
|
||||
* @tags external_io, visualization
|
||||
* @param {number} value Initial value
|
||||
* @param {number} min Minimum value - optional, defaults to 0
|
||||
* @param {number} max Maximum value - optional, defaults to 1
|
||||
* @param {number} step Step size - optional
|
||||
* @param {number} [min=0] Minimum value - optional, defaults to 0
|
||||
* @param {number} [max=1] Maximum value - optional, defaults to 1
|
||||
* @param {number} [step] Step size - optional
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export let slider = (value) => {
|
||||
console.warn('slider will only work when the transpiler is used... passing value as is');
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// eslint-disable-next-line no-undef
|
||||
// TODO: swap below line with above one when firefox supports esm imports in service workers
|
||||
// see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker?retiredLocale=de#browser_compatibility
|
||||
// import createClock from './zyklus.mjs';
|
||||
|
||||
+903
-31
File diff suppressed because it is too large
Load Diff
@@ -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({
|
||||
@@ -74,12 +74,12 @@ export class Cyclist {
|
||||
// query the pattern for events
|
||||
const haps = this.pattern
|
||||
.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' })
|
||||
.filter((hap) => hap.hasOnset())
|
||||
.filter((hap) => hap.hasOnset() || hap.context.processParts)
|
||||
// Sort the haps based on their onset, so cps changes within the
|
||||
// tick duration happen in the correct order.
|
||||
.sort((a, b) => {
|
||||
const aBegin = a.whole.begin;
|
||||
const bBegin = b.whole.begin;
|
||||
const aBegin = a.part.begin;
|
||||
const bBegin = b.part.begin;
|
||||
// If haps happen at the same time, trigger the haps that cause
|
||||
// cps changes first, so the durations of the simultaneous haps
|
||||
// are adjusted accordingly.
|
||||
@@ -96,7 +96,7 @@ export class Cyclist {
|
||||
});
|
||||
|
||||
haps.forEach((hap) => {
|
||||
const targetTime = (hap.whole.begin - this.checkpoint.cycles) / this.cps + this.checkpoint.seconds;
|
||||
const targetTime = (hap.part.begin - this.checkpoint.cycles) / this.cps + this.checkpoint.seconds;
|
||||
if (tickEndTime < targetTime) {
|
||||
// If the targetTime exceeds the tickEndTime, this means
|
||||
// the cps has slowed down, and the latter haps from the query
|
||||
@@ -110,7 +110,7 @@ export class Cyclist {
|
||||
this.cps = hap.value.cps;
|
||||
this.num_ticks_since_checkpoint = 0;
|
||||
this.checkpoint = {
|
||||
cycles: hap.whole.begin,
|
||||
cycles: hap.part.begin,
|
||||
seconds: targetTime,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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": {
|
||||
|
||||
+30
-5
@@ -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,10 +12,29 @@ 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';
|
||||
|
||||
/**
|
||||
* Creates a new Repl
|
||||
* @global
|
||||
* @param {object} options
|
||||
* @param {*} options.onSchedule
|
||||
* @param {*} options.defaultOutput
|
||||
* @param {*} options.onEvalError
|
||||
* @param {*} options.beforeEval
|
||||
* @param {*} options.beforeStart
|
||||
* @param {*} options.afterEval
|
||||
* @param {*} options.getTime
|
||||
* @param {*} options.transpiler
|
||||
* @param {*} options.onToggle
|
||||
* @param {*} options.editPattern
|
||||
* @param {*} options.onUpdateState
|
||||
* @param {*} options.sync = false
|
||||
* @param {*} options.setInterval
|
||||
* @param {*} options.clearInterval
|
||||
* @param {*} options.id
|
||||
* @param {*} options.mondo = false
|
||||
* @returns {object}
|
||||
*/
|
||||
export function repl({
|
||||
onSchedule,
|
||||
defaultOutput,
|
||||
@@ -127,6 +148,7 @@ export function repl({
|
||||
* @tags temporal
|
||||
* @alias setCpm
|
||||
* @param {number} cpm cycles per minute
|
||||
* @returns {pattern}
|
||||
* @example
|
||||
* setcpm(140/4) // =140 bpm in 4/4
|
||||
* $: s("bd*4,[- sd]*2").bank('tr707')
|
||||
@@ -156,7 +178,8 @@ export function repl({
|
||||
* $: sound("hh*8")
|
||||
* all(x => x.pianoroll())
|
||||
* ```
|
||||
*
|
||||
* @param {function(Pattern):Pattern} transform
|
||||
* @returns {Pattern}
|
||||
* @tags combiners
|
||||
*/
|
||||
const all = function (transform) {
|
||||
@@ -174,6 +197,8 @@ export function repl({
|
||||
* each(fast("<2 3>"))
|
||||
* ```
|
||||
* @tags combiners
|
||||
* @param {function(Pattern):Pattern} transform
|
||||
* @returns {pattern}
|
||||
*/
|
||||
const each = function (transform) {
|
||||
eachTransform = transform;
|
||||
|
||||
@@ -11,9 +11,11 @@ let scheduleFunc;
|
||||
let isStarted;
|
||||
|
||||
/**
|
||||
* Get the current cycle time as a number
|
||||
* @global
|
||||
* @name getTime
|
||||
* @tags internals
|
||||
* @returns {Number} the current cycle time as a number
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getTime() {
|
||||
if (!time) {
|
||||
@@ -22,15 +24,23 @@ export function getTime() {
|
||||
return time();
|
||||
}
|
||||
|
||||
/**
|
||||
* define how the cycle time should be computed
|
||||
* @global
|
||||
* @param {function():number} func
|
||||
* @tags internals
|
||||
*/
|
||||
export function setTime(func) {
|
||||
time = func;
|
||||
}
|
||||
|
||||
let clockTime;
|
||||
/**
|
||||
* Get the current clock time in seconds (onSchedule time)
|
||||
* @global
|
||||
* @name getClockTime
|
||||
* @tags internals
|
||||
* @returns {Number} the current clock time in seconds (onSchedule time)
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getClockTime() {
|
||||
if (!clockTime) {
|
||||
@@ -39,43 +49,81 @@ export function getClockTime() {
|
||||
return clockTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* define how the clock time should be computed
|
||||
* @global
|
||||
* @param {function():number} func
|
||||
*/
|
||||
export function setClockTime(func) {
|
||||
clockTime = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* define how Cycles per seconds are computed
|
||||
* @global
|
||||
* @tags internals
|
||||
* @param {function():number} func
|
||||
*/
|
||||
export function setCpsFunc(func) {
|
||||
cpsFunc = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current cycles per second
|
||||
* @global
|
||||
* @name getCps
|
||||
* @tags internals
|
||||
* @returns {Number} the current cycles per second
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getCps() {
|
||||
return cpsFunc?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the currently running pattern
|
||||
* @param {Pattern} pat
|
||||
*/
|
||||
export function setPattern(pat) {
|
||||
pattern = pat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently running pattern
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export function getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the function that applies a function for a given time and cps
|
||||
* @param {function(Pattern,number,number)} func
|
||||
*/
|
||||
export function setScheduleFunc(func) {
|
||||
scheduleFunc = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the function that applies a function for a given time and cps
|
||||
* @returns {function(Pattern,number,number)} taking a Pattern, the current time and cps as inputs
|
||||
*/
|
||||
export function getScheduleFunc() {
|
||||
return scheduleFunc;
|
||||
}
|
||||
|
||||
/**
|
||||
* start/stop the scheduler
|
||||
* @param {boolean | undefined} val
|
||||
*/
|
||||
export function setIsStarted(val) {
|
||||
isStarted = !!val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has the scheduler started?
|
||||
In the repl, this returns true only after the full pattern code has successfully executed without errors, including any prebake files, or if the scheduler was already running from a previous pattern update.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function getIsStarted() {
|
||||
return isStarted;
|
||||
}
|
||||
|
||||
@@ -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,6 +1,19 @@
|
||||
// will move to https://github.com/felixroos/zyklus
|
||||
// TODO: started flag
|
||||
|
||||
/**
|
||||
* Creates a Web Audio Clock
|
||||
* @global
|
||||
* @param {Function} getTime
|
||||
* @param {Function} callback
|
||||
* @param {number} [duration]
|
||||
* @param {number} [interval]
|
||||
* @param {number} [overlap]
|
||||
* @param {Function} [setInterval]
|
||||
* @param {Function} [clearInterval]
|
||||
* @param {boolean} round
|
||||
* @returns {object}
|
||||
*/
|
||||
function createClock(
|
||||
getTime,
|
||||
callback, // called slightly before each cycle
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -21,7 +21,8 @@ let D;
|
||||
*
|
||||
* @name initDough
|
||||
* @tags external_io
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Promise<void>}
|
||||
* @example
|
||||
* await initDough()
|
||||
* $: chord("<Dm9 Dm11 Dm7>").offset("<-1 0 1 0>").voicing()
|
||||
@@ -51,12 +52,12 @@ export async function doughOutput(hap, targetTime, cps = 1) {
|
||||
|
||||
/**
|
||||
*
|
||||
* Uses dough as the audio engine. more info at https://dough.strudel.cc
|
||||
* Uses dough as the audio engine. more info [here](https://dough.strudel.cc)
|
||||
*
|
||||
* @name dough
|
||||
* @tags external_io
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* $: chord("<Dm9 Dm11 Dm7>").offset("<-1 0 1 0>").voicing()
|
||||
* .phaser(3).fm(1.4).fmh(1.01)
|
||||
|
||||
+33
-25
@@ -43,31 +43,31 @@ const getValue = (e) => {
|
||||
* @name pianoroll
|
||||
* @synonyms punchcard
|
||||
* @tags visualization
|
||||
* @param {Object} options Object containing all the optional following parameters as key value pairs:
|
||||
* @param {integer} cycles number of cycles to be displayed at the same time - defaults to 4
|
||||
* @param {number} playhead location of the active notes on the time axis - 0 to 1, defaults to 0.5
|
||||
* @param {boolean} vertical displays the roll vertically - 0 by default
|
||||
* @param {boolean} labels displays labels on individual notes (see the label function) - 0 by default
|
||||
* @param {boolean} flipTime reverse the direction of the roll - 0 by default
|
||||
* @param {boolean} flipValues reverse the relative location of notes on the value axis - 0 by default
|
||||
* @param {number} overscan lookup X cycles outside of the cycles window to display notes in advance - 1 by default
|
||||
* @param {boolean} hideNegative hide notes with negative time (before starting playing the pattern) - 0 by default
|
||||
* @param {boolean} smear notes leave a solid trace - 0 by default
|
||||
* @param {boolean} fold notes takes the full value axis width - 0 by default
|
||||
* @param {string} active hexadecimal or CSS color of the active notes - defaults to #FFCA28
|
||||
* @param {string} inactive hexadecimal or CSS color of the inactive notes - defaults to #7491D2
|
||||
* @param {string} background hexadecimal or CSS color of the background - defaults to transparent
|
||||
* @param {string} playheadColor hexadecimal or CSS color of the line representing the play head - defaults to white
|
||||
* @param {boolean} fill notes are filled with color (otherwise only the label is displayed) - 0 by default
|
||||
* @param {boolean} fillActive active notes are filled with color - 0 by default
|
||||
* @param {boolean} stroke notes are shown with colored borders - 0 by default
|
||||
* @param {boolean} strokeActive active notes are shown with colored borders - 0 by default
|
||||
* @param {boolean} hideInactive only active notes are shown - 0 by default
|
||||
* @param {boolean} colorizeInactive use note color for inactive notes - 1 by default
|
||||
* @param {string} fontFamily define the font used by notes labels - defaults to 'monospace'
|
||||
* @param {integer} minMidi minimum note value to display on the value axis - defaults to 10
|
||||
* @param {integer} maxMidi maximum note value to display on the value axis - defaults to 90
|
||||
* @param {boolean} autorange automatically calculate the minMidi and maxMidi parameters - 0 by default
|
||||
* @param {object} [options] Object containing all the optional following parameters as key value pairs:
|
||||
* @param {number} [options.cycles=4] number of cycles to be displayed at the same time - defaults to 4
|
||||
* @param {number} [options.playhead=0.5] location of the active notes on the time axis - 0 to 1, defaults to 0.5
|
||||
* @param {boolean} [options.vertical=0] displays the roll vertically - 0 by default
|
||||
* @param {boolean} [options.labels=0] displays labels on individual notes (see the label function) - 0 by default
|
||||
* @param {boolean} [options.flipTime=0] reverse the direction of the roll - 0 by default
|
||||
* @param {boolean} [options.flipValues=0] reverse the relative location of notes on the value axis - 0 by default
|
||||
* @param {number} [options.overscan=1] lookup X cycles outside of the cycles window to display notes in advance - 1 by default
|
||||
* @param {boolean} [options.hideNegative=0] hide notes with negative time (before starting playing the pattern) - 0 by default
|
||||
* @param {boolean} [options.smear=0] notes leave a solid trace - 0 by default
|
||||
* @param {boolean} [options.fold=0] notes takes the full value axis width - 0 by default
|
||||
* @param {string} [options.active=#FFCA28] hexadecimal or CSS color of the active notes - defaults to #FFCA28
|
||||
* @param {string} [options.inactive='#7491D2'] hexadecimal or CSS color of the inactive notes - defaults to #7491D2
|
||||
* @param {string} [options.background='transparent'] hexadecimal or CSS color of the background - defaults to transparent
|
||||
* @param {string} [options.playheadColor='white'] hexadecimal or CSS color of the line representing the play head - defaults to white
|
||||
* @param {boolean} [options.fill=0] notes are filled with color (otherwise only the label is displayed) - 0 by default
|
||||
* @param {boolean} [options.fillActive=0] active notes are filled with color - 0 by default
|
||||
* @param {boolean} [options.stroke=0] notes are shown with colored borders - 0 by default
|
||||
* @param {boolean} [options.strokeActive=0] active notes are shown with colored borders - 0 by default
|
||||
* @param {boolean} [options.hideInactive=0] only active notes are shown - 0 by default
|
||||
* @param {boolean} [options.colorizeInactive=1] use note color for inactive notes - 1 by default
|
||||
* @param {string} [options.fontFamily='monospace'] define the font used by notes labels - defaults to 'monospace'
|
||||
* @param {number} [options.minMidi=10] minimum note value to display on the value axis - defaults to 10
|
||||
* @param {number} [options.maxMidi=90] maximum note value to display on the value axis - defaults to 90
|
||||
* @param {boolean} [options.autorange=0] automatically calculate the minMidi and maxMidi parameters - 0 by default
|
||||
* @see _pianoroll
|
||||
* @example
|
||||
* note("c2 a2 eb2")
|
||||
@@ -299,8 +299,16 @@ Pattern.prototype.punchcard = function (options) {
|
||||
* Displays a vertical pianoroll with event labels.
|
||||
* Supports all the same options as pianoroll.
|
||||
*
|
||||
* @param {object} options
|
||||
* @param {number} options.vertical
|
||||
* @param {number} options.labels
|
||||
* @param {number} options.stroke
|
||||
* @param {number} options.fillActive
|
||||
* @param {string} options.active
|
||||
* @name wordfall
|
||||
* @tags visualization
|
||||
* @returns {Pattern}
|
||||
* @memberof Pattern.prototype
|
||||
*/
|
||||
Pattern.prototype.wordfall = function (options) {
|
||||
return this.punchcard({ vertical: 1, labels: 1, stroke: 0, fillActive: 1, active: 'white', ...options });
|
||||
|
||||
@@ -148,14 +148,16 @@ export function pitchwheel({
|
||||
* Renders a pitch circle to visualize frequencies within one octave
|
||||
* @name pitchwheel
|
||||
* @tags visualization
|
||||
* @param {number} hapcircles
|
||||
* @param {number} circle
|
||||
* @param {number} edo
|
||||
* @param {string} root
|
||||
* @param {number} thickness
|
||||
* @param {number} hapRadius
|
||||
* @param {string} mode
|
||||
* @param {number} margin
|
||||
* @param {object} options
|
||||
* @param {number} options.hapcircles
|
||||
* @param {number} options.circle
|
||||
* @param {number} options.edo
|
||||
* @param {string} options.root
|
||||
* @param {number} options.thickness
|
||||
* @param {number} options.hapRadius
|
||||
* @param {string} options.mode
|
||||
* @param {number} options.margin
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* n("0 .. 12").scale("C:chromatic")
|
||||
* .s("sawtooth")
|
||||
|
||||
@@ -63,13 +63,15 @@ function appendLine(el, text, maxLines) {
|
||||
*
|
||||
* @name print
|
||||
* @tags visualization
|
||||
* @param {number} width widget width in px, `_print` only. defaults to 600
|
||||
* @param {number} height widget height in px, `_print` only. defaults to 100
|
||||
* @param {number} maxLines max lines kept, `_print` only. defaults to 500
|
||||
* @param {number} round decimal digits for the event time. defaults to 4. `0`
|
||||
* @param {object} options object that may have the following arguments
|
||||
* @param {number} options.width widget width in px, `_print` only. defaults to 600
|
||||
* @param {number} options.height widget height in px, `_print` only. defaults to 100
|
||||
* @param {number} options.maxLines max lines kept, `_print` only. defaults to 500
|
||||
* @param {number} options.round decimal digits for the event time. defaults to 4. `0`
|
||||
* shows only the cycle
|
||||
* @param {number} padding integer digits reserved for the cycle, so it stays
|
||||
* @param {number} options.padding integer digits reserved for the cycle, so it stays
|
||||
* aligned once cycles reach 10 or 100. defaults to 3
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("bd sd hh cp").print()
|
||||
* @example
|
||||
|
||||
+17
-16
@@ -130,22 +130,23 @@ function drawSpiral(options) {
|
||||
*
|
||||
* @name spiral
|
||||
* @tags visualization
|
||||
* @param {Object} options Object containing all the optional following parameters as key value pairs:
|
||||
* @param {number} stretch controls the rotations per cycle ratio, where 1 = 1 cycle / 360 degrees
|
||||
* @param {number} size the diameter of the spiral
|
||||
* @param {number} thickness line thickness
|
||||
* @param {string} cap style of line ends: butt (default), round, square
|
||||
* @param {string} inset number of rotations before spiral starts (default 3)
|
||||
* @param {string} playheadColor color of playhead, defaults to white
|
||||
* @param {number} playheadLength length of playhead in rotations, defaults to 0.02
|
||||
* @param {number} playheadThickness thickness of playheadrotations, defaults to thickness
|
||||
* @param {number} padding space around spiral
|
||||
* @param {number} steady steadyness of spiral vs playhead. 1 = spiral doesn't move, playhead does.
|
||||
* @param {number} activeColor color of active segment. defaults to foreground of theme
|
||||
* @param {number} inactiveColor color of inactive segments. defaults to gutterForeground of theme
|
||||
* @param {boolean} colorizeInactive wether or not to colorize inactive segments, defaults to 0
|
||||
* @param {boolean} fade wether or not past and future should fade out. defaults to 1
|
||||
* @param {boolean} logSpiral wether or not the spiral should be logarithmic. defaults to 0
|
||||
* @param {object} options Object containing all the optional following parameters as key value pairs:
|
||||
* @param {number} options.stretch controls the rotations per cycle ratio, where 1 = 1 cycle / 360 degrees
|
||||
* @param {number} options.size the diameter of the spiral
|
||||
* @param {number} options.thickness line thickness
|
||||
* @param {string} options.cap style of line ends: butt (default), round, square
|
||||
* @param {string} options.inset number of rotations before spiral starts (default 3)
|
||||
* @param {string} options.playheadColor color of playhead, defaults to white
|
||||
* @param {number} options.playheadLength length of playhead in rotations, defaults to 0.02
|
||||
* @param {number} options.playheadThickness thickness of playheadrotations, defaults to thickness
|
||||
* @param {number} options.padding space around spiral
|
||||
* @param {number} options.steady steadyness of spiral vs playhead. 1 = spiral doesn't move, playhead does.
|
||||
* @param {number} options.activeColor color of active segment. defaults to foreground of theme
|
||||
* @param {number} options.inactiveColor color of inactive segments. defaults to gutterForeground of theme
|
||||
* @param {boolean} options.colorizeInactive wether or not to colorize inactive segments, defaults to 0
|
||||
* @param {boolean} options.fade wether or not past and future should fade out. defaults to 1
|
||||
* @param {boolean} options.logSpiral wether or not the spiral should be logarithmic. defaults to 0
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* note("c2 a2 eb2")
|
||||
* .euclid(5,8)
|
||||
|
||||
@@ -38,7 +38,7 @@ const pitchesCache = new Map();
|
||||
*
|
||||
* @name edoScale
|
||||
* @param {string} scale Definition of EDO scale.
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* n("0 2 4 6 4 2").edoScale("C:LLsLLLs:2:1")
|
||||
* @example
|
||||
|
||||
@@ -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);
|
||||
@@ -15,7 +15,7 @@ import { getDevice } from './util.mjs';
|
||||
*/
|
||||
export class MidiInput {
|
||||
/**
|
||||
*
|
||||
* Constructs a new Midi input device
|
||||
* @param {string | number} input MIDI device name or index defaulting to 0
|
||||
*/
|
||||
constructor(input) {
|
||||
@@ -34,6 +34,7 @@ export class MidiInput {
|
||||
* Implementation for the cc() factory function tied to this specific input.
|
||||
* @param {number} cc MIDI CC number
|
||||
* @param {number | undefined} chan MIDI channel (1-16) or undefined for all channels
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
createCC(cc, chan) {
|
||||
const lookupMap = chan === undefined ? this._refs : this._refsByChan[chan];
|
||||
|
||||
+16
-2
@@ -113,6 +113,8 @@ function githubPath(base, subpath = '') {
|
||||
|
||||
/**
|
||||
* configures the default midimap, which is used when no "midimap" port is set
|
||||
* @global
|
||||
* @param {*} mapping
|
||||
* @tags external_io, midi
|
||||
* @example
|
||||
* defaultmidimap({ lpf: 74 })
|
||||
@@ -127,6 +129,8 @@ let loadCache = {};
|
||||
|
||||
/**
|
||||
* Adds midimaps to the registry. Inside each midimap, control names (e.g. lpf) are mapped to cc numbers.
|
||||
* @global
|
||||
* @param {string | object} map
|
||||
* @tags external_io, midi
|
||||
* @example
|
||||
* midimaps({ mymap: { lpf: 74 } })
|
||||
@@ -290,6 +294,12 @@ function sendNote(note, velocity, duration, device, midichan, timeMs) {
|
||||
* @tags external_io
|
||||
* @param {string | number} midiport MIDI device name or index defaulting to 0
|
||||
* @param {object} options Additional MIDI configuration options
|
||||
* @param {boolean} options.isController sending notes for midi controllers. Default is false
|
||||
* @param {number} options.noteOffsetMs note-off offset to prevent glitching in ms. Default is 10 or firefox and 1 otherwise
|
||||
* @param {number} options.midichannel default is 1
|
||||
* @param {number} options.velocity default is 0.9
|
||||
* @param {number} options.gain default is 1
|
||||
* @param {string} options.midimap default is 'default'
|
||||
* @example
|
||||
* note("c4").midichan(1).midi('IAC Driver Bus 1')
|
||||
*/
|
||||
@@ -476,6 +486,9 @@ Pattern.prototype.midi = function (midiport, options = {}) {
|
||||
|
||||
/**
|
||||
* Initialize a midi input device
|
||||
* @global
|
||||
* @param {string} input
|
||||
* @returns {MidiInput}
|
||||
*/
|
||||
async function _initializeInput(input) {
|
||||
if (isPattern(input)) {
|
||||
@@ -516,9 +529,10 @@ const midiInputs = {};
|
||||
* The output is a function that accepts a midi cc value to query as well as (optionally) a midi channel
|
||||
*
|
||||
* @name midin
|
||||
* @global
|
||||
* @tags external_io, midi
|
||||
* @param {string | number} input MIDI device name or index defaulting to 0
|
||||
* @returns {function(number, number=): Pattern} A function from (cc, channel?) to a pattern.
|
||||
* @returns {Promise<function(number, number=): Pattern>} A function from (cc, channel?) to a pattern.
|
||||
* When queried, the pattern will produces the most recently received midi value (normalized to 0 to 1)
|
||||
* that came through that cc number (and channel, if provided)
|
||||
* @example
|
||||
@@ -548,7 +562,7 @@ export async function midin(input) {
|
||||
* @name midikeys
|
||||
* @tags external_io, midi
|
||||
* @param {string | number} input MIDI device name or index defaulting to 0
|
||||
* @returns {function((number | Pattern)=): Pattern} A function that produces a pattern.
|
||||
* @returns {Promise<function((number | Pattern)=): Pattern>} A function that produces a pattern.
|
||||
* When queried, the pattern will produces the most recently played midi notes and velocities,
|
||||
* lasting for the specified duration
|
||||
* @example
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Input, Output } from 'webmidi';
|
||||
|
||||
/**
|
||||
* Get a string listing device names for error messages.
|
||||
* @global
|
||||
* @param {Input[] | Output[]} devices
|
||||
* @returns {string}
|
||||
*/
|
||||
@@ -18,6 +19,7 @@ export function getMidiDeviceNamesString(devices) {
|
||||
/**
|
||||
* Look up a device by index or name. Otherwise return a default device, or fail if none are connected.
|
||||
*
|
||||
* @global
|
||||
* @param {string | number} indexOrName
|
||||
* @param {Input[] | Output[]} devices
|
||||
* @returns {Input | Output | undefined}
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
"mondolang": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mondo": "*",
|
||||
"vite": "^6.0.11",
|
||||
"vitest": "^3.0.4"
|
||||
},
|
||||
|
||||
+16
-16
@@ -1,11 +1,11 @@
|
||||
// motion.mjs
|
||||
|
||||
import { signal } from '../core/signal.mjs';
|
||||
import { signal } from '@strudel/core';
|
||||
|
||||
/**
|
||||
* The accelerometer's x-axis value ranges from 0 to 1.
|
||||
* @name accelerationX
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms accX
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -16,7 +16,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The accelerometer's y-axis value ranges from 0 to 1.
|
||||
* @name accelerationY
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms accY
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -27,7 +27,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The accelerometer's z-axis value ranges from 0 to 1.
|
||||
* @name accelerationZ
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms accZ
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -38,7 +38,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's gravity x-axis value ranges from 0 to 1.
|
||||
* @name gravityX
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms gravX
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -49,7 +49,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's gravity y-axis value ranges from 0 to 1.
|
||||
* @name gravityY
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms gravY
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -60,7 +60,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's gravity z-axis value ranges from 0 to 1.
|
||||
* @name gravityZ
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms gravZ
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -71,7 +71,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's rotation around the alpha-axis value ranges from 0 to 1.
|
||||
* @name rotationAlpha
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms rotA, rotZ, rotationZ
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -82,7 +82,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's rotation around the beta-axis value ranges from 0 to 1.
|
||||
* @name rotationBeta
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms rotB, rotX, rotationX
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -93,7 +93,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's rotation around the gamma-axis value ranges from 0 to 1.
|
||||
* @name rotationGamma
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms rotG, rotY, rotationY
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -104,7 +104,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's orientation alpha value ranges from 0 to 1.
|
||||
* @name orientationAlpha
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms oriA, oriZ, orientationZ
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -115,7 +115,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's orientation beta value ranges from 0 to 1.
|
||||
* @name orientationBeta
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms oriB, oriX, orientationX
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -126,7 +126,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's orientation gamma value ranges from 0 to 1.
|
||||
* @name orientationGamma
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms oriG, oriY, orientationY
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -137,7 +137,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's absolute orientation alpha value ranges from 0 to 1.
|
||||
* @name absoluteOrientationAlpha
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms absOriA, absOriZ, absoluteOrientationZ
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -148,7 +148,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's absolute orientation beta value ranges from 0 to 1.
|
||||
* @name absoluteOrientationBeta
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms absOriB, absOriX, absoluteOrientationX
|
||||
* @tags external_io
|
||||
* @example
|
||||
@@ -159,7 +159,7 @@ import { signal } from '../core/signal.mjs';
|
||||
/**
|
||||
* The device's absolute orientation gamma value ranges from 0 to 1.
|
||||
* @name absoluteOrientationGamma
|
||||
* @return {Pattern}
|
||||
* @type {Pattern}
|
||||
* @synonyms absOriG, absOriY, absoluteOrientationY
|
||||
* @tags external_io
|
||||
* @example
|
||||
|
||||
+66
-7
@@ -52,13 +52,13 @@ export function parseControlsFromHap(hap, cps) {
|
||||
controls.unit === 'c' && controls.speed != null && (controls.speed = controls.speed / cps);
|
||||
const channels = controls.channels;
|
||||
channels != undefined && (controls.channels = JSON.stringify(channels));
|
||||
|
||||
return controls;
|
||||
}
|
||||
|
||||
let timeOrigin = performance.timeOrigin;
|
||||
export async function oscOutput(hap, targetTime, cps = 1) {
|
||||
const ws = await connect();
|
||||
|
||||
function getOscTimestamp(targetTime) {
|
||||
const timeMs = getClockBridge().getPerformanceTime(targetTime);
|
||||
if (!timeMs) {
|
||||
logger('[osc] clockbridge not ready');
|
||||
@@ -72,21 +72,76 @@ export async function oscOutput(hap, targetTime, cps = 1) {
|
||||
// shift time after microsleep
|
||||
timeOrigin -= deprivation;
|
||||
}
|
||||
const ts = timeOrigin + timeMs;
|
||||
return timeOrigin + timeMs;
|
||||
}
|
||||
|
||||
export async function oscOutput(hap, targetTime, cps = 1) {
|
||||
const ws = await connect();
|
||||
const ts = getOscTimestamp(targetTime);
|
||||
if (!ts) {
|
||||
return;
|
||||
}
|
||||
|
||||
const controls = parseControlsFromHap(hap, cps);
|
||||
const keyvals = Object.entries(controls).flat();
|
||||
const msg = { address: '/dirt/play', args: keyvals, timestamp: ts };
|
||||
|
||||
if ('oschost' in hap.value) {
|
||||
msg['host'] = hap.value['oschost'];
|
||||
msg.oschost = hap.value.oschost;
|
||||
}
|
||||
if ('oscport' in hap.value) {
|
||||
msg['port'] = hap.value['oscport'];
|
||||
msg.oscport = hap.value.oscport;
|
||||
}
|
||||
|
||||
ws.send(JSON.stringify(msg));
|
||||
}
|
||||
|
||||
export async function superdirtOutput(hap, targetTime, cps = 1) {
|
||||
const ws = await connect();
|
||||
const ts = getOscTimestamp(targetTime);
|
||||
if (!ts) {
|
||||
return;
|
||||
}
|
||||
|
||||
const controls = parseControlsFromHap(hap, cps);
|
||||
|
||||
const oschost = hap.value.oschost ?? '127.0.0.1';
|
||||
const oscport = hap.value.oscport ?? 57120;
|
||||
const bushost = oschost;
|
||||
const busport = 57110;
|
||||
|
||||
// send SuperDirt bus/control messages first
|
||||
for (const [key, busIdVal] of Object.entries(controls)) {
|
||||
if (key.startsWith('^')) {
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
oschost: bushost,
|
||||
oscport: busport,
|
||||
address: '/c_set',
|
||||
args: busIdVal,
|
||||
timestamp: ts,
|
||||
}),
|
||||
);
|
||||
// so they aren't sent with trigger messages
|
||||
delete controls[key];
|
||||
}
|
||||
}
|
||||
|
||||
// only trigger samples on haps that actually begin here
|
||||
if (hap.hasOnset()) {
|
||||
const keyvals = Object.entries(controls).flat();
|
||||
ws.send(
|
||||
JSON.stringify({
|
||||
oschost,
|
||||
oscport,
|
||||
address: '/dirt/play',
|
||||
args: keyvals,
|
||||
timestamp: ts,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sends each hap as an OSC message, which can be picked up by SuperCollider or any other OSC-enabled software.
|
||||
@@ -94,10 +149,14 @@ export async function oscOutput(hap, targetTime, cps = 1) {
|
||||
*
|
||||
* @name osc
|
||||
* @tags external_io
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const osc = register('osc', (pat) => {
|
||||
ensureMinimalOutput();
|
||||
return pat.onSchedule(oscOutput);
|
||||
});
|
||||
export const superdirt = register('superdirt', (pat) => {
|
||||
ensureMinimalOutput();
|
||||
return pat._processParts().onSchedule(superdirtOutput);
|
||||
});
|
||||
|
||||
+9
-13
@@ -12,18 +12,13 @@ import { WebSocketServer } from 'ws';
|
||||
import osc from 'osc';
|
||||
|
||||
const WS_PORT = 8080; // WebSocket server port
|
||||
const OSC_REMOTE_IP = '127.0.0.1';
|
||||
const OSC_REMOTE_PORT = 57120;
|
||||
|
||||
const udpPort = new osc.UDPPort({
|
||||
localAddress: '0.0.0.0',
|
||||
localPort: 0,
|
||||
remoteAddress: OSC_REMOTE_IP,
|
||||
remotePort: OSC_REMOTE_PORT,
|
||||
});
|
||||
|
||||
udpPort.open();
|
||||
console.log(`[Sending OSC] ${OSC_REMOTE_IP}:${OSC_REMOTE_PORT}`);
|
||||
|
||||
udpPort.on('error', (e) => {
|
||||
console.log('Error: ', e);
|
||||
@@ -36,23 +31,24 @@ wss.on('connection', (ws) => {
|
||||
console.log('New WebSocket connection');
|
||||
|
||||
ws.on('message', (message) => {
|
||||
let osc_host = '127.0.0.1';
|
||||
let osc_port = 57120;
|
||||
let oschost = '127.0.0.1';
|
||||
let oscport = 57120;
|
||||
|
||||
try {
|
||||
const data = JSON.parse(message);
|
||||
if ('host' in data) {
|
||||
osc_host = data['host'];
|
||||
if ('oschost' in data) {
|
||||
oschost = data['oschost'];
|
||||
delete data['oschost'];
|
||||
}
|
||||
if ('port' in data) {
|
||||
osc_port = data['port'];
|
||||
if ('oscport' in data) {
|
||||
oscport = data['oscport'];
|
||||
delete data['oscport'];
|
||||
}
|
||||
let msg = { address: data['address'], args: data['args'] };
|
||||
if ('timestamp' in data) {
|
||||
msg = { timeTag: osc.timeTag(0, data['timestamp']), packets: [msg] };
|
||||
}
|
||||
|
||||
udpPort.send(msg, osc_host, osc_port);
|
||||
udpPort.send(msg, oschost, oscport);
|
||||
} catch (err) {
|
||||
console.error('Error parsing message:', err);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
/* import { tauriOscOutput } from '../desktopbridge/oscbridge.mjs';
|
||||
import { isTauri } from '../desktopbridge/utils.mjs'; */
|
||||
import { oscOutput } from './osc.mjs';
|
||||
// const output = /* isTauri() ? tauriOscOutput : */ oscOutput;
|
||||
|
||||
const output = /* isTauri() ? tauriOscOutput : */ oscOutput;
|
||||
|
||||
export const superdirtOutput = (hap, targetTime, cps) => output(hap, targetTime, cps);
|
||||
export { superdirtOutput } from './osc.mjs';
|
||||
|
||||
@@ -15,10 +15,11 @@ import Fraction, { gcd } from './fraction.mjs';
|
||||
* - "-" hold previous value
|
||||
* - "." silence
|
||||
*
|
||||
* @tags visualization
|
||||
* @param {Pattern} pattern the pattern to use
|
||||
* @tags internal, visualization
|
||||
* @param {Pattern} pat the pattern to use
|
||||
* @param {number} chars max number of characters (approximately)
|
||||
* @returns string
|
||||
* @returns {string}
|
||||
* @global
|
||||
* @example
|
||||
* const line = drawLine("0 [1 2 3]", 10); // |0--123|0--123
|
||||
* console.log(line);
|
||||
@@ -64,12 +64,12 @@ export const bjorklund = function (ons, steps) {
|
||||
*
|
||||
* A negative number of steps changes it into `euclidLegato`.
|
||||
*
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @name euclid
|
||||
* @tags temporal
|
||||
* @param {number} pulses the number of onsets/beats
|
||||
* @param {number} steps the number of steps to fill
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* // The Cuban tresillo pattern.
|
||||
* note("c3").euclid(3,8)
|
||||
@@ -77,13 +77,13 @@ export const bjorklund = function (ons, steps) {
|
||||
|
||||
/**
|
||||
* Like `euclid`, but has an additional parameter for 'rotating' the resulting sequence.
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @name euclidRot
|
||||
* @tags temporal
|
||||
* @param {number} pulses the number of onsets/beats
|
||||
* @param {number} steps the number of steps to fill
|
||||
* @param {number} rotation offset in steps
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* // A Samba rhythm necklace from Brazil
|
||||
* note("c3").euclidRot(3,16,14)
|
||||
@@ -194,7 +194,7 @@ export const { euclidrot, euclidRot } = register(['euclidrot', 'euclidRot'], fun
|
||||
*
|
||||
* A negative number of steps changes it into `euclid`.
|
||||
* @name euclidLegato
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @tags temporal
|
||||
* @param {number} pulses the number of onsets/beats
|
||||
* @param {number} steps the number of steps to fill
|
||||
@@ -215,7 +215,7 @@ export const euclidLegato = register(['euclidLegato'], function (pulses, steps,
|
||||
*
|
||||
* A negative number of steps changes it into `euclidRot`.
|
||||
* @name euclidLegatoRot
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @tags temporal
|
||||
* @param {number} pulses the number of onsets/beats
|
||||
* @param {number} steps the number of steps to fill
|
||||
@@ -237,7 +237,7 @@ export const euclidLegatoRot = register(['euclidLegatoRot'], function (pulses, s
|
||||
* Inspired by the work of Malcom Braff.
|
||||
* @name euclidish
|
||||
* @synonyms eish
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @tags temporal
|
||||
* @param {number} pulses the number of onsets
|
||||
* @param {number} steps the number of steps to fill
|
||||
@@ -6,22 +6,40 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import Fraction from './fraction.mjs';
|
||||
import { stringifyValues } from './util.mjs';
|
||||
|
||||
/**
|
||||
* @tags internal
|
||||
* @class Event class, representing a discrete or samples event (or "happening").
|
||||
* This might be a fragment of an event, in which case the
|
||||
* timespan will be smaller than the 'whole' timespan, otherwise the
|
||||
* two timespans will be the same.
|
||||
*
|
||||
* The word "Event" is more or less a reserved word in javascript, hence this
|
||||
* class is named called `Hap`.
|
||||
*/
|
||||
export class Hap {
|
||||
/*
|
||||
Event class, representing a value active during the timespan
|
||||
'part'. This might be a fragment of an event, in which case the
|
||||
timespan will be smaller than the 'whole' timespan, otherwise the
|
||||
two timespans will be the same. The 'part' must never extend outside of the
|
||||
'whole'. If the event represents a continuously changing value
|
||||
then the whole will be returned as None, in which case the given
|
||||
value will have been sampled from the point halfway between the
|
||||
start and end of the 'part' timespan.
|
||||
The context is to store a list of source code locations causing the event.
|
||||
|
||||
The word 'Event' is more or less a reserved word in javascript, hence this
|
||||
class is named called 'Hap'.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create a hap. Create a hap. Haps and patterns are considered immutable, but you can create a new pattern with modified haps with functions like {@link Pattern#withHaps} and {@link Pattern#withValue}.
|
||||
*
|
||||
* @param {TimeSpan | undefined} whole timespan. If the event represents a continuously changing value
|
||||
* then the whole will be returned as None, in which case the given value will have been sampled from
|
||||
* the the start of the `part` timespan.
|
||||
* @param {TimeSpan} part of the timespan. May never extend outside of the `whole`.
|
||||
* @param {function(State):* | *} value active during the timespan `part`. Must be a function if `stateful` is set to `true`.
|
||||
* @param {object} [context={}] - The context is to store metadata. When two patterns are combined, their context objects are merged.
|
||||
* @param {Array<{ start: number, end: number }>} [context.locations] - list of source code locations causing the event
|
||||
* @param {string[]} [context.tags] Metadata about the Hap
|
||||
* @param {boolean} [stateful=false] - (experimental) if true the value depends on the state.
|
||||
*
|
||||
* @example
|
||||
* // Keep only haps whose full `whole` timespan is at least half a cycle long
|
||||
* s("bd, sd*2, hh*4")
|
||||
* .filterHaps((hap) => hap.whole !== undefined && hap.whole.duration >= 0.5);
|
||||
*
|
||||
* @example
|
||||
* // Keep only haps that begin within the first half of a cycle
|
||||
* note("c3 d3 e3 f3")
|
||||
* .filterHaps((hap) => hap.part.begin < 0.5);
|
||||
*/
|
||||
constructor(whole, part, value, context = {}, stateful = false) {
|
||||
this.whole = whole;
|
||||
this.part = part;
|
||||
@@ -161,6 +179,10 @@ export class Hap {
|
||||
return new Hap(this.whole, this.part, this.value, context);
|
||||
}
|
||||
|
||||
withContext(f) {
|
||||
return new Hap(this.whole, this.part, this.value, f(this.context));
|
||||
}
|
||||
|
||||
ensureObjectValue() {
|
||||
/* if (isNote(hap.value)) {
|
||||
// supports primitive hap values that look like notes
|
||||
@@ -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;
|
||||
@@ -4,8 +4,14 @@ let debounce = 1000,
|
||||
lastMessage,
|
||||
lastTime;
|
||||
|
||||
/**
|
||||
* Logs an error to the system and/or Strudel REPL console.
|
||||
* @global
|
||||
* @param {*} e
|
||||
* @param {string} origin
|
||||
*/
|
||||
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"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,11 +26,22 @@ const _pick = function (lookup, pat, modulo = true) {
|
||||
});
|
||||
};
|
||||
|
||||
export const pick = function (lookup, pat) {
|
||||
// backward compatibility - the args used to be flipped
|
||||
if (Array.isArray(pat)) {
|
||||
[pat, lookup] = [lookup, pat];
|
||||
}
|
||||
return __pick(lookup, pat);
|
||||
};
|
||||
|
||||
/** * Picks patterns (or plain values) either from a list (by index) or a lookup table (by name).
|
||||
* Similar to `inhabit`, but maintains the structure of the original patterns.
|
||||
* The lookup can also be a pattern of objects, such as a pattern of controls, in which case each of its events is used as the lookup table.
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pick
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* note("<0 1 2!2 3>".pick(["g a", "e f", "f g f g" , "g c d"]))
|
||||
@@ -40,16 +51,11 @@ const _pick = function (lookup, pat, modulo = true) {
|
||||
* sound("<0!2 [0,1] 1>".pick(["bd(3,8)", "sd sd"]))
|
||||
* @example
|
||||
* s("<a!2 [a,b] b>".pick({a: "bd(3,8)", b: "sd sd"}))
|
||||
* @example
|
||||
* // pick a field out of a pattern of objects
|
||||
* const pat = sound("bd cp").speed("<2 3>")
|
||||
* pat.fast("speed".pick(pat))
|
||||
*/
|
||||
|
||||
export const pick = function (lookup, pat) {
|
||||
// backward compatibility - the args used to be flipped
|
||||
if (Array.isArray(pat)) {
|
||||
[pat, lookup] = [lookup, pat];
|
||||
}
|
||||
return __pick(lookup, pat);
|
||||
};
|
||||
|
||||
const __pick = register('pick', function (lookup, pat) {
|
||||
return _pick(lookup, pat, false).innerJoin();
|
||||
});
|
||||
@@ -61,9 +67,10 @@ const __pick = register('pick', function (lookup, pat) {
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pickmod
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
|
||||
export const pickmod = register('pickmod', function (lookup, pat) {
|
||||
return _pick(lookup, pat, true).innerJoin();
|
||||
});
|
||||
@@ -72,7 +79,9 @@ export const pickmod = register('pickmod', function (lookup, pat) {
|
||||
* @tags combiners, functional
|
||||
* @param {Pattern} pat
|
||||
* @param {Pattern} lookup a pattern of indices or names
|
||||
* @param {function[] | object} lookup the array or lookup object of functions from which to pull
|
||||
* @param {Function[] | object} lookup the array or lookup object of functions from which to pull
|
||||
* @name pickF
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("bd [rim hh]").pickF("<0 1 2>", [rev,jux(rev),fast(2)])
|
||||
@@ -92,7 +101,9 @@ export const pickF = register('pickF', function (pickPattern, lookup, pat) {
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {Pattern} lookup a pattern of indices or names
|
||||
* @param {function[] | object} lookup the array or lookup object of functions from which to pull
|
||||
* @param {Function[] | object} lookup the array or lookup object of functions from which to pull
|
||||
* @name pickmodF
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const pickmodF = register('pickmodF', function (pickPattern, lookup, pat) {
|
||||
@@ -103,6 +114,7 @@ export const pickmodF = register('pickmodF', function (pickPattern, lookup, pat)
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* note("<0*4 1 2*2 3*3>".pickOut(["g a", "e f", "f g f g" , "g c d"]))
|
||||
@@ -116,6 +128,7 @@ export const pickOut = register('pickOut', function (lookup, pat) {
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const pickmodOut = register('pickmodOut', function (lookup, pat) {
|
||||
@@ -126,26 +139,30 @@ export const pickmodOut = register('pickmodOut', function (lookup, pat) {
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pickRestart
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const pickRestart = register('pickRestart', function (lookup, pat) {
|
||||
return _pick(lookup, pat, false).restartJoin();
|
||||
});
|
||||
|
||||
/** * The same as `pickRestart`, but if you pick a number greater than the size of the list,
|
||||
* it wraps around, rather than sticking at the maximum value.
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* "<a@2 b@2 c@2 d@2>".pickRestart({
|
||||
a: n("0 1 2 0"),
|
||||
b: n("2 3 4 ~"),
|
||||
c: n("[4 5] [4 3] 2 0"),
|
||||
d: n("0 -3 0 ~")
|
||||
}).scale("C:major").s("piano")
|
||||
*/
|
||||
/** The same as `pickRestart`, but if you pick a number greater than the size of the list,
|
||||
* it wraps around, rather than sticking at the maximum value.
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pickmodRestart
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* "<a@2 b@2 c@2 d@2>".pickRestart({
|
||||
a: n("0 1 2 0"),
|
||||
b: n("2 3 4 ~"),
|
||||
c: n("[4 5] [4 3] 2 0"),
|
||||
d: n("0 -3 0 ~")
|
||||
}).scale("C:major").s("piano")
|
||||
*/
|
||||
export const pickmodRestart = register('pickmodRestart', function (lookup, pat) {
|
||||
return _pick(lookup, pat, true).restartJoin();
|
||||
});
|
||||
@@ -154,6 +171,8 @@ export const pickmodRestart = register('pickmodRestart', function (lookup, pat)
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pickReset
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const pickReset = register('pickReset', function (lookup, pat) {
|
||||
@@ -165,6 +184,8 @@ export const pickReset = register('pickReset', function (lookup, pat) {
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @name pickmodReset
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const pickmodReset = register('pickmodReset', function (lookup, pat) {
|
||||
@@ -178,6 +199,7 @@ export const pickmodReset = register('pickmodReset', function (lookup, pat) {
|
||||
* @synonyms pickSqueeze
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* let a = s("bd(3,8)")
|
||||
@@ -201,6 +223,7 @@ export const { inhabit, pickSqueeze } = register(['inhabit', 'pickSqueeze'], fun
|
||||
* @tags combiners
|
||||
* @param {Pattern} pat
|
||||
* @param {*} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
|
||||
@@ -6,18 +6,26 @@ 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';
|
||||
|
||||
/**
|
||||
* A `signal` consisting of a constant value. Similar to `pure`, except that function
|
||||
* creates a pattern with one event per cycle, whereas 'steady' patterns don't have
|
||||
* an discrete structure.
|
||||
*
|
||||
* @param {*} value The constant value of the resulting pattern
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export function steady(value) {
|
||||
// A continuous value
|
||||
return new Pattern((state) => [new Hap(undefined, state.span, value)]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a signal given by the input function
|
||||
* Creates a "signal", an unstructured pattern consisting of a single value that changes over time.
|
||||
*
|
||||
* @name signal
|
||||
* @param {*} func
|
||||
@@ -42,7 +50,7 @@ export const signal = (func) => {
|
||||
/**
|
||||
* A sawtooth signal between 0 and 1.
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* note("<c3 [eb3,g3] g2 [g3,bb3]>*8")
|
||||
@@ -57,7 +65,7 @@ export const saw = signal((t) => _mod(t, 1));
|
||||
/**
|
||||
* A sawtooth signal between -1 and 1 (like `saw`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const saw2 = saw.toBipolar();
|
||||
@@ -65,7 +73,7 @@ export const saw2 = saw.toBipolar();
|
||||
/**
|
||||
* A sawtooth signal between 1 and 0 (like `saw`, but flipped).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* note("<c3 [eb3,g3] g2 [g3,bb3]>*8")
|
||||
@@ -80,7 +88,7 @@ export const isaw = signal((t) => 1 - _mod(t, 1));
|
||||
/**
|
||||
* A sawtooth signal between 1 and -1 (like `saw2`, but flipped).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const isaw2 = isaw.toBipolar();
|
||||
@@ -88,14 +96,14 @@ export const isaw2 = isaw.toBipolar();
|
||||
/**
|
||||
* A sine signal between -1 and 1 (like `sine`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const sine2 = signal((t) => Math.sin(Math.PI * 2 * t));
|
||||
|
||||
/**
|
||||
* A sine signal between 0 and 1.
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(sine.segment(16).range(0,15))
|
||||
@@ -107,7 +115,7 @@ export const sine = sine2.fromBipolar();
|
||||
/**
|
||||
* A cosine signal between 0 and 1.
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(stack(sine,cosine).segment(16).range(0,15))
|
||||
@@ -119,14 +127,14 @@ export const cosine = sine._early(Fraction(1).div(4));
|
||||
/**
|
||||
* A cosine signal between -1 and 1 (like `cosine`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const cosine2 = sine2._early(Fraction(1).div(4));
|
||||
|
||||
/**
|
||||
* A square signal between 0 and 1.
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(square.segment(4).range(0,7)).scale("C:minor")
|
||||
@@ -137,7 +145,7 @@ export const square = signal((t) => Math.floor(_mod(t * 2, 2)));
|
||||
/**
|
||||
* A square signal between -1 and 1 (like `square`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const square2 = square.toBipolar();
|
||||
@@ -145,7 +153,7 @@ export const square2 = square.toBipolar();
|
||||
/**
|
||||
* A square signal between 1 and 0 (like `square` but flipped).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const isquare = signal((t) => 1 - Math.floor(_mod(t * 2, 2)));
|
||||
@@ -153,7 +161,7 @@ export const isquare = signal((t) => 1 - Math.floor(_mod(t * 2, 2)));
|
||||
/**
|
||||
* A square signal between 1 and -1 (like `isquare`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const isquare2 = isquare.toBipolar();
|
||||
@@ -161,7 +169,7 @@ export const isquare2 = isquare.toBipolar();
|
||||
/**
|
||||
* A triangle signal between 0 and 1.
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(tri.segment(8).range(0,7)).scale("C:minor")
|
||||
@@ -172,7 +180,7 @@ export const tri = fastcat(saw, isaw);
|
||||
/**
|
||||
* A triangle signal between -1 and 1 (like `tri`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const tri2 = fastcat(saw2, isaw2);
|
||||
@@ -180,7 +188,7 @@ export const tri2 = fastcat(saw2, isaw2);
|
||||
/**
|
||||
* An inverted triangle signal between 1 and 0 (like `tri`, but flipped).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
* @example
|
||||
* n(itri.segment(8).range(0,7)).scale("C:minor")
|
||||
@@ -191,7 +199,7 @@ export const itri = fastcat(isaw, saw);
|
||||
/**
|
||||
* An inverted triangle signal between -1 and 1 (like `itri`, but bipolar).
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const itri2 = fastcat(isaw2, saw2);
|
||||
@@ -199,32 +207,11 @@ export const itri2 = fastcat(isaw2, saw2);
|
||||
/**
|
||||
* A signal representing the cycle time.
|
||||
*
|
||||
* @return {Pattern}
|
||||
* @returns {Pattern}
|
||||
* @tags generators
|
||||
*/
|
||||
export const time = signal(id);
|
||||
|
||||
/**
|
||||
* The mouse's x position value ranges from 0 to 1.
|
||||
* @name mousex
|
||||
* @synonyms mouseX
|
||||
* @return {Pattern}
|
||||
* @tags external_io
|
||||
* @example
|
||||
* n(mousex.segment(4).range(0,7)).scale("C:minor")
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* The mouse's y position value ranges from 0 to 1.
|
||||
* @name mousey
|
||||
* @synonyms mouseY
|
||||
* @return {Pattern}
|
||||
* @tags external_io
|
||||
* @example
|
||||
* n(mousey.segment(4).range(0,7)).scale("C:minor")
|
||||
*
|
||||
*/
|
||||
let _mouseY = 0,
|
||||
_mouseX = 0;
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -235,8 +222,29 @@ if (typeof window !== 'undefined') {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The mouse's y position value ranges from 0 to 1.
|
||||
* @name mousey
|
||||
* @synonyms mouseY
|
||||
* @type {Pattern}
|
||||
* @tags external_io
|
||||
* @example
|
||||
* n(mousey.segment(4).range(0,7)).scale("C:minor")
|
||||
*
|
||||
*/
|
||||
export const mousey = signal(() => _mouseY);
|
||||
export const mouseY = signal(() => _mouseY);
|
||||
|
||||
/**
|
||||
* The mouse's x position value ranges from 0 to 1.
|
||||
* @name mousex
|
||||
* @synonyms mouseX
|
||||
* @type {Pattern}
|
||||
* @tags external_io
|
||||
* @example
|
||||
* n(mousex.segment(4).range(0,7)).scale("C:minor")
|
||||
*
|
||||
*/
|
||||
export const mousex = signal(() => _mouseX);
|
||||
export const mouseX = signal(() => _mouseX);
|
||||
|
||||
@@ -324,7 +332,8 @@ export const getRandsAtTime = (t, n = 1, seed = 0) => {
|
||||
*
|
||||
* @name useRNG
|
||||
* @tags generators, math
|
||||
* @param {string} mod - Mode. One of 'legacy', 'precise'
|
||||
* @param {string} mode One of 'legacy', 'precise'
|
||||
* @returns {void}
|
||||
* @example
|
||||
* useRNG('legacy')
|
||||
* // Repeats every 300 cycles
|
||||
@@ -335,7 +344,9 @@ export const useRNG = (mode = 'legacy') => (RNG_MODE = mode);
|
||||
|
||||
/**
|
||||
* A discrete pattern of numbers from 0 to n-1
|
||||
* @param {number} n
|
||||
* @tags generators
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* n(run(4)).scale("C4:pentatonic")
|
||||
* // n("0 1 2 3").scale("C4:pentatonic")
|
||||
@@ -348,6 +359,7 @@ export const run = (n) => saw.range(0, n).round().segment(n);
|
||||
* @name binary
|
||||
* @tags generators
|
||||
* @param {number} n - input number to convert to binary
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* "hh".s().struct(binary(5))
|
||||
* // "hh".s().struct("1 0 1")
|
||||
@@ -364,6 +376,7 @@ export const binary = (n) => {
|
||||
* @tags generators
|
||||
* @param {number} n - input number to convert to binary
|
||||
* @param {number} nBits - pattern length, defaults to 16
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* "hh".s().struct(binaryN(55532, 16))
|
||||
* // "hh".s().struct("1 1 0 1 1 0 0 0 1 1 1 0 1 1 0 0")
|
||||
@@ -381,6 +394,8 @@ export const binaryN = (n, nBits = 16) => {
|
||||
* @name binaryL
|
||||
* @tags generators
|
||||
* @param {number} n - input number to convert to binary
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("saw").seg(8)
|
||||
* .partials(binaryL(irand(4096).add(1)))
|
||||
*/
|
||||
@@ -396,6 +411,7 @@ export const binaryL = (n) => {
|
||||
* @tags generators
|
||||
* @param {number} n - input number to convert to binary
|
||||
* @param {number} nBits - pattern length, defaults to 16
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const binaryNL = (n, nBits = 16) => {
|
||||
return reify(n)
|
||||
@@ -415,6 +431,7 @@ export const binaryNL = (n, nBits = 16) => {
|
||||
* @name randL
|
||||
* @tags generators
|
||||
* @param {number} n Number of random numbers to sample
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("saw").seg(16).n(irand(12)).scale("F1:minor")
|
||||
* .partials(randL(8))
|
||||
@@ -477,7 +494,7 @@ export const scramble = register('scramble', (n, pat) => {
|
||||
* @tags math
|
||||
* @param {Function} func Function from seed (or undefined) to seed (or undefined)
|
||||
* @param {Pattern} pat Pattern to update
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const withSeed = (func, pat) => {
|
||||
return new Pattern((state) => {
|
||||
@@ -496,6 +513,7 @@ export const withSeed = (func, pat) => {
|
||||
* @name seed
|
||||
* @tags math
|
||||
* @param {number} n A new seed. Can be any number.
|
||||
* @memberof Pattern.prototype
|
||||
* @example
|
||||
* $: s("hh*4").degrade();
|
||||
* $: s("bd*4").degrade().seed(1); // Will degrade different events from the hi-hat
|
||||
@@ -528,7 +546,8 @@ export const _brandBy = (p) => rand.fmap((x) => x < p);
|
||||
*
|
||||
* @name brandBy
|
||||
* @tags generators
|
||||
* @param {number} probability - a number between 0 and 1
|
||||
* @param {number} pPat probability - a number between 0 and 1
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*10").pan(brandBy(0.2))
|
||||
*/
|
||||
@@ -551,7 +570,8 @@ export const _irand = (i) => rand.fmap((x) => Math.trunc(x * i));
|
||||
*
|
||||
* @name irand
|
||||
* @tags generators
|
||||
* @param {number} n max value (exclusive)
|
||||
* @param {number} ipat max value (exclusive)
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* // randomly select scale notes from 0 - 7 (= C to C)
|
||||
* n(irand(8)).struct("x x*2 x x*3").scale("C:minor")
|
||||
@@ -616,14 +636,22 @@ export const chooseInWith = (pat, xs) => {
|
||||
*/
|
||||
export const choose = (...xs) => chooseWith(rand, xs);
|
||||
|
||||
/**
|
||||
* As with {choose}, but the structure comes from the chosen values, rather
|
||||
* than the pattern you're using to choose with.
|
||||
* @param {...any} xs
|
||||
* @returns {Pattern} - a continuous pattern.
|
||||
*/
|
||||
export const chooseIn = (...xs) => chooseInWith(rand, xs);
|
||||
|
||||
/**
|
||||
* Chooses from the given list of values (or patterns of values), according
|
||||
* to the pattern that the method is called on. The pattern should be in
|
||||
* the range 0 .. 1.
|
||||
* @name choose
|
||||
* @tags temporal
|
||||
* @param {...any} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
Pattern.prototype.choose = function (...xs) {
|
||||
@@ -633,8 +661,10 @@ Pattern.prototype.choose = function (...xs) {
|
||||
/**
|
||||
* As with choose, but the pattern that this method is called on should be
|
||||
* in the range -1 .. 1
|
||||
* @name choose2
|
||||
* @tags temporal
|
||||
* @param {...any} xs
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
Pattern.prototype.choose2 = function (...xs) {
|
||||
@@ -643,6 +673,7 @@ Pattern.prototype.choose2 = function (...xs) {
|
||||
|
||||
/**
|
||||
* Picks one of the elements at random each cycle.
|
||||
* @param {...any} xs
|
||||
* @tags temporal
|
||||
* @synonyms randcat
|
||||
* @returns {Pattern}
|
||||
@@ -696,6 +727,7 @@ export const wchoose = (...pairs) => wchooseWith(rand, ...pairs);
|
||||
|
||||
/**
|
||||
* Picks one of the elements at random each cycle by giving a probability to each element
|
||||
* @param {...any} pairs
|
||||
* @tags temporal
|
||||
* @synonyms wrandcat
|
||||
* @returns {Pattern}
|
||||
@@ -763,16 +795,14 @@ export const perlin = signal((t, controls) => _perlin(t, controls.randSeed));
|
||||
export const berlin = signal((t, controls) => _berlin(t, controls.randSeed));
|
||||
|
||||
/**
|
||||
* `degradeByWith` is like `degradeBy`, but with control over the random or other signal used to filter out the events.
|
||||
*
|
||||
* `degradeByWith` is like `degradeBy`, but with control over the signal used to degrade the pattern.
|
||||
* It removes events from a pattern given a signal of numbers and a cutoff value for interpreting that pattern as true or false.
|
||||
* `degradeBy(x)` is essentially `degradeByWith(rand, x)`
|
||||
*
|
||||
* This allows you to do things other than with `rand`, see examples below
|
||||
*
|
||||
* @name degradeByWith
|
||||
* @param {Pattern|number} test
|
||||
* @param {Pattern|number} testAgainst
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @tags temporal
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
@@ -794,9 +824,9 @@ export const degradeByWith = register('degradeByWith', (withPat, x, pat) => {
|
||||
*
|
||||
* @tags temporal
|
||||
* @name degradeBy
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {number} amount - a number between 0 and 1
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").degradeBy(0.2)
|
||||
* @example
|
||||
@@ -820,8 +850,8 @@ export const degradeBy = register(
|
||||
*
|
||||
* @tags temporal
|
||||
* @name degrade
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").degrade()
|
||||
* @example
|
||||
@@ -837,9 +867,9 @@ export const degrade = register('degrade', (pat) => pat._degradeBy(0.5), true, t
|
||||
*
|
||||
* @tags temporal
|
||||
* @name undegradeBy
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {number} amount - a number between 0 and 1
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").undegradeBy(0.2)
|
||||
* @example
|
||||
@@ -866,8 +896,8 @@ export const undegradeBy = register(
|
||||
*
|
||||
* @tags temporal
|
||||
* @name undegrade
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").undegrade()
|
||||
* @example
|
||||
@@ -885,10 +915,10 @@ export const undegrade = register('undegrade', (pat) => pat._undegradeBy(0.5), t
|
||||
*
|
||||
* @tags temporal
|
||||
* @name sometimesBy
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {number | Pattern} probability - a number between 0 and 1
|
||||
* @param {function} function - the transformation to apply
|
||||
* @returns Pattern
|
||||
* @param {Function} function - the transformation to apply
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").sometimesBy(.4, x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -905,9 +935,9 @@ export const sometimesBy = register('sometimesBy', function (patx, func, pat) {
|
||||
*
|
||||
* @tags temporal
|
||||
* @name sometimes
|
||||
* @memberof Pattern
|
||||
* @param {function} function - the transformation to apply
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {Function} function - the transformation to apply
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").sometimes(x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -921,10 +951,10 @@ export const sometimes = register('sometimes', function (func, pat) {
|
||||
* Similar to `sometimesBy`
|
||||
*
|
||||
* @name someCyclesBy
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {number | Pattern} probability - a number between 0 and 1
|
||||
* @param {function} function - the transformation to apply
|
||||
* @returns Pattern
|
||||
* @param {Function} function - the transformation to apply
|
||||
* @returns {Pattern}
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("bd,hh*8").someCyclesBy(.3, x=>x.speed("0.5"))
|
||||
@@ -946,8 +976,8 @@ export const someCyclesBy = register('someCyclesBy', function (patx, func, pat)
|
||||
* Shorthand for `.someCyclesBy(0.5, fn)`
|
||||
*
|
||||
* @name someCycles
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("bd,hh*8").someCycles(x=>x.speed("0.5"))
|
||||
@@ -961,8 +991,8 @@ export const someCycles = register('someCycles', function (func, pat) {
|
||||
* Shorthand for `.sometimesBy(0.75, fn)`
|
||||
*
|
||||
* @name often
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("hh*8").often(x=>x.speed("0.5"))
|
||||
@@ -976,8 +1006,8 @@ export const often = register('often', function (func, pat) {
|
||||
* Shorthand for `.sometimesBy(0.25, fn)`
|
||||
*
|
||||
* @name rarely
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @tags temporal
|
||||
* @example
|
||||
* s("hh*8").rarely(x=>x.speed("0.5"))
|
||||
@@ -992,8 +1022,8 @@ export const rarely = register('rarely', function (func, pat) {
|
||||
*
|
||||
* @tags temporal
|
||||
* @name almostNever
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").almostNever(x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -1007,8 +1037,8 @@ export const almostNever = register('almostNever', function (func, pat) {
|
||||
*
|
||||
* @tags temporal
|
||||
* @name almostAlways
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").almostAlways(x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -1022,8 +1052,8 @@ export const almostAlways = register('almostAlways', function (func, pat) {
|
||||
*
|
||||
* @tags temporal
|
||||
* @name never
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").never(x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -1032,13 +1062,12 @@ export const never = register('never', function (_, pat) {
|
||||
});
|
||||
|
||||
/**
|
||||
*
|
||||
* Shorthand for `.sometimesBy(1, fn)` (always calls fn)
|
||||
*
|
||||
* @tags temporal
|
||||
* @name always
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("hh*8").always(x=>x.speed("0.5"))
|
||||
*/
|
||||
@@ -1046,8 +1075,11 @@ export const always = register('always', function (func, pat) {
|
||||
return func(pat);
|
||||
});
|
||||
|
||||
//keyname: string | Array<string>
|
||||
//keyname reference: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values
|
||||
/**
|
||||
* checks if a key is down
|
||||
* @param {string | Array<string>} keyname reference: https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function _keyDown(keyname) {
|
||||
if (Array.isArray(keyname) === false) {
|
||||
keyname = [keyname];
|
||||
@@ -1066,8 +1098,8 @@ export function _keyDown(keyname) {
|
||||
*
|
||||
* @tags external_io
|
||||
* @name whenKey
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("bd(5,8)").whenKey("Control:j", x => x.segment(16).color("red")).whenKey("Control:i", x => x.fast(2).color("blue"))
|
||||
*/
|
||||
@@ -1083,12 +1115,11 @@ export const whenKey = register('whenKey', function (input, func, pat) {
|
||||
*
|
||||
* @tags external_io
|
||||
* @name keyDown
|
||||
* @memberof Pattern
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* keyDown("Control:j").pick([s("bd(5,8)"), s("cp(3,8)")])
|
||||
*/
|
||||
|
||||
export const keyDown = register('keyDown', function (pat) {
|
||||
return pat.fmap(_keyDown);
|
||||
});
|
||||
@@ -1101,6 +1132,7 @@ export const keyDown = register('keyDown', function (pat) {
|
||||
* See also its reciprocal, `per`, also known as `perCycle`.
|
||||
*
|
||||
* @tags temporal
|
||||
* @type {Pattern}
|
||||
* @example
|
||||
* // Shorter events are lower in pitch
|
||||
* sound("saw saw [saw saw] saw")
|
||||
@@ -1113,14 +1145,34 @@ 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
|
||||
* event durations, from the pattern that it is combined with.
|
||||
* For example `per.struct("1 1 [1 1] 1")` would give the same as `"4 4 [8 8] 4"`.
|
||||
* See also its reciprocal, `cyclesPer`.
|
||||
* @global
|
||||
* @tags temporal
|
||||
* @synonyms perCycle
|
||||
* @type {Pattern}
|
||||
* @example
|
||||
* // Shorter events are more distorted
|
||||
* n("0 0*2 0 0*2 0 [0 0 0]@2").sound("bd")
|
||||
@@ -1138,6 +1190,7 @@ export const perCycle = per;
|
||||
* returned value increases by one. `perx.struct("1 1 [1 [1 1]] 1")` would therefore be
|
||||
* the same as `"3 3 [4 [5 5]] 3"`.
|
||||
* @tags temporal
|
||||
* @type {Pattern}
|
||||
*/
|
||||
export const perx = new Pattern(function (state) {
|
||||
const n = Fraction(1).div(state.span.duration);
|
||||
@@ -1149,6 +1202,7 @@ export const perx = new Pattern(function (state) {
|
||||
* Mainly useful in combination with other functions that reset the cycle. See also
|
||||
* `close`.
|
||||
* @tags temporal
|
||||
* @type {Pattern}
|
||||
* @example
|
||||
* sound("bd sd [- bd] sd".fast(2))
|
||||
* .lpf(open.slow(4).range(300,3000)) // close envelope over 4 cycles
|
||||
@@ -1160,9 +1214,100 @@ export const open = signal((t) => t.min(1));
|
||||
* The same as `open`, but goes from `1` to `0` over one cycle, and then
|
||||
* stays on `0` forever.
|
||||
* @tags temporal
|
||||
* @type {Pattern}
|
||||
* @example
|
||||
* sound("bd sd [- bd] sd".fast(2))
|
||||
* .lpf(close.slow(4).range(300,3000)) // close envelope over 4 cycles
|
||||
* .restart("x/4") // restart every 4 cycles
|
||||
*/
|
||||
export const close = signal((t) => Fraction(1).sub(t).max(0));
|
||||
|
||||
/**
|
||||
* 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([
|
||||
@@ -1169,6 +1081,15 @@ describe('Pattern', () => {
|
||||
),
|
||||
);
|
||||
});
|
||||
it('Can pick values from a pattern of objects', () => {
|
||||
const pat = slowcat({ s: 'bd', speed: 2 }, { s: 'cp', speed: 3 });
|
||||
expect(
|
||||
pure('speed')
|
||||
.pick(pat)
|
||||
.queryArc(0, 2)
|
||||
.map((hap) => hap.value),
|
||||
).toStrictEqual([2, 3]);
|
||||
});
|
||||
});
|
||||
describe('pickmod', () => {
|
||||
it('Wraps indexes', () => {
|
||||
@@ -1180,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)
|
||||
@@ -1310,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(
|
||||
@@ -1396,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
|
||||
@@ -1405,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', () => {
|
||||
@@ -72,8 +72,11 @@ export const getEventOffsetMs = (targetTimeSeconds, currentTimeSeconds) => {
|
||||
|
||||
const pcs = ['C', 'Db', 'D', 'Eb', 'E', 'F', 'Gb', 'G', 'Ab', 'A', 'Bb', 'B'];
|
||||
/**
|
||||
* converts midi values into notes
|
||||
* @param {number} n
|
||||
* @deprecated only used in workshop (first-notes)
|
||||
* @noAutocomplete
|
||||
* @returns {string}
|
||||
*/
|
||||
export const midi2note = (n) => {
|
||||
const oct = Math.floor(n / 12) - 1;
|
||||
@@ -131,8 +134,8 @@ export const getPlayableNoteValue = (hap) => {
|
||||
* @name getFrequency
|
||||
* @tags pitch
|
||||
* @synonyms getFreq
|
||||
* @param {Hap | note | number} input
|
||||
* @returns {Number}
|
||||
* @param {Hap | note | number} hap input
|
||||
* @returns {number}
|
||||
* @example
|
||||
* i("4 8 9 10 - - 5 7 9 11 - -").tune("tranh3")
|
||||
* .mul(getFreq('c3'))
|
||||
@@ -209,6 +212,11 @@ export function curry(func, overload, arity = func.length) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
/**
|
||||
* parses a number. supports midi notes as strings
|
||||
* @param {number | string} numOrString
|
||||
* @returns {number}
|
||||
*/
|
||||
export function parseNumeral(numOrString) {
|
||||
const asNumber = Number(numOrString);
|
||||
if (!isNaN(asNumber)) {
|
||||
@@ -220,10 +228,20 @@ export function parseNumeral(numOrString) {
|
||||
throw new Error(`cannot parse as numeral: "${numOrString}"`);
|
||||
}
|
||||
|
||||
/**
|
||||
* map over the arguments of a function
|
||||
* @param {Function} fn
|
||||
* @param {Function} mapFn
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function mapArgs(fn, mapFn) {
|
||||
return (...args) => fn(...args.map(mapFn));
|
||||
}
|
||||
|
||||
/** converts the arguments of a function into numbers
|
||||
* @param {Function} fn
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function numeralArgs(fn) {
|
||||
return mapArgs(fn, parseNumeral);
|
||||
}
|
||||
@@ -325,7 +343,12 @@ export const sol2note = (n, notation = 'letters') => {
|
||||
return note + oct;
|
||||
};
|
||||
|
||||
// Remove duplicates from list
|
||||
/**
|
||||
* Remove duplicates from list
|
||||
* @template T
|
||||
* @param {T[]} a
|
||||
* @returns {T[]}
|
||||
*/
|
||||
export function uniq(a) {
|
||||
var seen = {};
|
||||
return a.filter(function (item) {
|
||||
@@ -333,14 +356,26 @@ export function uniq(a) {
|
||||
});
|
||||
}
|
||||
|
||||
// Remove duplicates from list, sorting in the process. Mutates argument!
|
||||
/**
|
||||
* Remove duplicate primitives from list, sorting in the process. Mutates argument!
|
||||
* Use {@link uniqsortr} for objects instead.
|
||||
* @template T
|
||||
* @param {T[]} a (only primitives)
|
||||
* @returns {T[]}
|
||||
*/
|
||||
export function uniqsort(a) {
|
||||
return a.sort().filter(function (item, pos, ary) {
|
||||
return !pos || item != ary[pos - 1];
|
||||
});
|
||||
}
|
||||
|
||||
// rational version
|
||||
/**
|
||||
* Remove duplicate objects from list, sorting in the process. Mutates argument!
|
||||
* Use {@link uniqsort} for primitives instead.
|
||||
* @template T
|
||||
* @param {T[]} a (only objects)
|
||||
* @returns {T[]}
|
||||
*/
|
||||
export function uniqsortr(a) {
|
||||
return a
|
||||
.sort((x, y) => x.compare(y))
|
||||
@@ -372,22 +407,47 @@ export function base64ToUnicode(base64String) {
|
||||
return decodedText;
|
||||
}
|
||||
|
||||
/**
|
||||
* converts unicode text into a URL hash
|
||||
* @ignore
|
||||
* @param {string} code
|
||||
* @returns {string}
|
||||
*/
|
||||
export function code2hash(code) {
|
||||
return encodeURIComponent(unicodeToBase64(code));
|
||||
//return '#' + encodeURIComponent(btoa(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* converts the URL hash into unicode text
|
||||
* @ignore
|
||||
* @param {string} hash
|
||||
* @returns {string}
|
||||
*/
|
||||
export function hash2code(hash) {
|
||||
return base64ToUnicode(decodeURIComponent(hash));
|
||||
//return atob(decodeURIComponent(codeParam || ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* maps over the entries of an object
|
||||
* @param {object} obj
|
||||
* @param {Function} fn
|
||||
* @returns {object}
|
||||
*/
|
||||
export function objectMap(obj, fn) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.map(fn);
|
||||
}
|
||||
return Object.fromEntries(Object.entries(obj).map(([k, v], i) => [k, fn(v, k, i)]));
|
||||
}
|
||||
|
||||
/**
|
||||
* converts the cycle into seconds
|
||||
* @param {number} cycle
|
||||
* @param {number} cps
|
||||
* @returns {number} `cycle / cps`
|
||||
*/
|
||||
export function cycleToSeconds(cycle, cps) {
|
||||
return cycle / cps;
|
||||
}
|
||||
@@ -451,6 +511,10 @@ export class ClockCollator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The total time that strudel has been running
|
||||
* @returns {number}
|
||||
*/
|
||||
export function getPerformanceTimeSeconds() {
|
||||
return performance.now() * 0.001;
|
||||
}
|
||||
@@ -471,21 +535,24 @@ export const keyAlias = new Map([
|
||||
]);
|
||||
let keyState;
|
||||
|
||||
/**
|
||||
* returns the all the keys currently being pressed or released
|
||||
* @returns {object | void}
|
||||
*/
|
||||
export function getCurrentKeyboardState() {
|
||||
if (keyState == null) {
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
keyState = {};
|
||||
// Listen for the keydown event to mark the key as pressed
|
||||
window.addEventListener('keydown', (event) => {
|
||||
keyState[event.key] = true; // Mark the key as pressed
|
||||
});
|
||||
if (typeof window !== 'undefined') {
|
||||
// Listen for the keydown event to mark the key as pressed
|
||||
window.addEventListener('keydown', (event) => {
|
||||
keyState[event.key] = true; // Mark the key as pressed
|
||||
});
|
||||
|
||||
// Listen for the keyup event to mark the key as released
|
||||
window.addEventListener('keyup', (event) => {
|
||||
keyState[event.key] = false; // Mark the key as released
|
||||
});
|
||||
// Listen for the keyup event to mark the key as released
|
||||
window.addEventListener('keyup', (event) => {
|
||||
keyState[event.key] = false; // Mark the key as released
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return { ...keyState }; // Return a shallow copy of the key state object
|
||||
@@ -511,8 +578,13 @@ export function getCurrentKeyboardState() {
|
||||
// return lcm((x * y) / gcd(x, y), ...z);
|
||||
// };
|
||||
|
||||
// Takes values -- typically derived from events, i.e. `hap`s -- and renders them
|
||||
// into a readable format
|
||||
/**
|
||||
* Takes values -- typically derived from events, i.e. `hap`s -- and renders them
|
||||
* into a readable format
|
||||
* @param {*} value
|
||||
* @param {boolean} [compact=false] creates a compacter version
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function stringifyValues(value, compact = false) {
|
||||
return typeof value === 'object'
|
||||
? compact
|
||||
@@ -7,6 +7,12 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import { curry } from './util.mjs';
|
||||
import { logger } from './logger.mjs';
|
||||
|
||||
/** combine two objects into one
|
||||
* @param {object} a
|
||||
* @param {object} b
|
||||
* @param {Function} func
|
||||
* @returns {object}
|
||||
*/
|
||||
export function unionWithObj(a, b, func) {
|
||||
if (b?.value !== undefined && Object.keys(b).length === 1) {
|
||||
// https://codeberg.org/uzu/strudel/issues/1026
|
||||
@@ -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',
|
||||
},
|
||||
});
|
||||
@@ -21,12 +21,29 @@ LOG=1 npx @strudel/sampler # adds logging
|
||||
PORT=5555 npx @strudel/sampler # changes port
|
||||
```
|
||||
|
||||
## static json
|
||||
### --json
|
||||
|
||||
when running with `--json`, you will simply get the json logged back:
|
||||
|
||||
```sh
|
||||
npx --yes @strudel/sampler --json > strudel.json
|
||||
npx @strudel/sampler --json > strudel.json
|
||||
```
|
||||
|
||||
this is useful if you want to create a sample pack from the current folder.
|
||||
|
||||
### `--dir`
|
||||
|
||||
specifies the directory to serve. defaults to cwd
|
||||
|
||||
```sh
|
||||
npx @strudel/sampler --dir ~/Music/samples
|
||||
```
|
||||
|
||||
### `--flat`
|
||||
|
||||
with `--flat`, each file gets its own name, not grouped by directory.
|
||||
|
||||
```sh
|
||||
npx @strudel/sampler --flat
|
||||
```
|
||||
|
||||
this is useful if you want to create a sample pack from the current folder.
|
||||
@@ -1,21 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import cowsay from 'cowsay';
|
||||
import { createReadStream, existsSync, writeFileSync } from 'fs';
|
||||
import { createReadStream, existsSync } from 'fs';
|
||||
import { readdir } from 'fs/promises';
|
||||
import http from 'http';
|
||||
import { join, resolve, sep } from 'path';
|
||||
import readline from 'readline';
|
||||
import os from 'os';
|
||||
|
||||
const LOG = !!process.env.LOG || false;
|
||||
const PORT = process.env.PORT || 5432;
|
||||
const VALID_AUDIO_EXTENSIONS = ['wav', 'mp3', 'ogg'];
|
||||
|
||||
const isAudioFile = (f) => {
|
||||
const args = {};
|
||||
|
||||
// parse args
|
||||
for (const arg of process.argv.slice(2)) {
|
||||
if (arg === '--json') args.json = true;
|
||||
if (arg === '--flat') args.flat = true;
|
||||
if (arg === '--dir') args.dir = process.argv[process.argv.indexOf(arg) + 1];
|
||||
}
|
||||
|
||||
const directory = resolve(args.dir || process.cwd());
|
||||
const banks = await getBanks(directory, args.flat);
|
||||
|
||||
// if --json, output banks and exit
|
||||
if (args.json) {
|
||||
// stringify in expanded format
|
||||
const json = JSON.stringify(banks, null, 2);
|
||||
process.stdout.write(json + '\n');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
function isAudioFile(f) {
|
||||
const ext = f.split('.').slice(-1)[0].toLowerCase();
|
||||
return VALID_AUDIO_EXTENSIONS.includes(ext);
|
||||
};
|
||||
}
|
||||
|
||||
async function getFilesInDirectory(directory) {
|
||||
let files = [];
|
||||
@@ -41,11 +60,11 @@ async function getFilesInDirectory(directory) {
|
||||
return files;
|
||||
}
|
||||
|
||||
async function getBanks(directory, flat = false) {
|
||||
let files = await getFilesInDirectory(directory);
|
||||
let banks = {};
|
||||
async function getBanks(directory, flat) {
|
||||
const banks = {};
|
||||
const files = await getFilesInDirectory(directory);
|
||||
directory = directory.split(sep).join('/');
|
||||
files = files.map((path) => {
|
||||
files.forEach((path) => {
|
||||
path = path.split(sep).join('/');
|
||||
const subDir = path.replace(directory, '');
|
||||
const subDirFlat = subDir.replaceAll('/', '_').slice(1); // remove initial underscore
|
||||
@@ -55,50 +74,7 @@ async function getBanks(directory, flat = false) {
|
||||
banks[bank].push(subDir);
|
||||
return subDir;
|
||||
});
|
||||
return { banks, files };
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
|
||||
function getArgValue(flag) {
|
||||
const i = args.indexOf(flag);
|
||||
if (i !== -1) {
|
||||
const nextIsFlag = args[i + 1]?.startsWith('--') ?? true;
|
||||
if (nextIsFlag) return true;
|
||||
return args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
function getInput(query) {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
});
|
||||
|
||||
return new Promise((resolve) =>
|
||||
rl.question(query, (response) => {
|
||||
rl.close();
|
||||
resolve(response);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
let directory = getArgValue('--dir') || process.cwd();
|
||||
directory = resolve(directory);
|
||||
if (args.includes('--json')) {
|
||||
const { banks } = await getBanks(directory, getArgValue('--flat'));
|
||||
const json = JSON.stringify(banks);
|
||||
const outFile = resolve(directory, 'strudel.json');
|
||||
if (existsSync(outFile)) {
|
||||
const answer = await getInput(`Warning: File already exists at ${outFile}. Overwrite? (y/N): `);
|
||||
if (answer.toLowerCase() !== 'y') {
|
||||
console.log('Aborted.');
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
writeFileSync(outFile, json, 'utf8');
|
||||
console.log(`Wrote json to ${outFile}`);
|
||||
process.exit(0);
|
||||
return banks;
|
||||
}
|
||||
|
||||
console.log(
|
||||
@@ -111,7 +87,6 @@ console.log(
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
res.setHeader('Access-Control-Allow-Origin', '*');
|
||||
const { banks, files } = await getBanks(directory, getArgValue('--flat'));
|
||||
if (req.url === '/') {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
return res.end(JSON.stringify(banks));
|
||||
|
||||
@@ -250,7 +250,7 @@ export function createFilter(context, start, end, params, cps, cycle) {
|
||||
} = params;
|
||||
|
||||
let frequencyParam, filter;
|
||||
if (model === 'ladder') {
|
||||
if (model === 'ladder' && type === 'lowpass') {
|
||||
filter = getWorklet(context, 'ladder-processor', { frequency, q, drive });
|
||||
frequencyParam = filter.parameters.get('frequency');
|
||||
} else {
|
||||
@@ -442,7 +442,8 @@ export function applyFM(param, value, begin) {
|
||||
} else {
|
||||
control = `fmi${i}${j}`;
|
||||
}
|
||||
const amt = value[control];
|
||||
// If we can't find fm3/fm2/fm1/etc, fall back to fm32/fm21/fm10/etc
|
||||
const amt = value[control] ?? (i === j + 1 ? value[`fmi${i}${j}`] : undefined);
|
||||
if (!amt) continue;
|
||||
let io = [];
|
||||
for (let [isMod, idx] of [
|
||||
|
||||
@@ -36,6 +36,8 @@ class OLAProcessor extends AudioWorkletProcessor {
|
||||
|
||||
/** Handles dynamic reallocation of input/output channels buffer
|
||||
* (channel numbers may vary during lifecycle)
|
||||
* @param {*} inputs
|
||||
* @param {*} outputs
|
||||
* @tags internals
|
||||
**/
|
||||
reallocateChannelsIfNeeded(inputs, outputs) {
|
||||
@@ -92,6 +94,7 @@ class OLAProcessor extends AudioWorkletProcessor {
|
||||
|
||||
/**
|
||||
* Read next web audio block to input buffers
|
||||
* @param {*} inputs
|
||||
* @tags internals
|
||||
**/
|
||||
readInputs(inputs) {
|
||||
@@ -114,6 +117,7 @@ class OLAProcessor extends AudioWorkletProcessor {
|
||||
}
|
||||
|
||||
/** Write next web audio block from output buffers
|
||||
* @param {*} outputs
|
||||
* @tags internals
|
||||
**/
|
||||
writeOutputs(outputs) {
|
||||
|
||||
@@ -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": {
|
||||
|
||||
@@ -35,13 +35,13 @@ function humanFileSize(bytes, si) {
|
||||
* Has optional param `n` (for instance, the `2` in `s("casio:2")`)
|
||||
*
|
||||
* Note: `must` be called with await, otherwise you'll get a pending Promise object.
|
||||
*
|
||||
* @global
|
||||
* @name getDuration
|
||||
* @synonym getDur
|
||||
* @synonyms getDur
|
||||
* @tags samples
|
||||
* @param {string} sampleName
|
||||
* @param {number} (optional) n
|
||||
*
|
||||
* @param {string} s sampleName
|
||||
* @param {number} [n]
|
||||
* @returns {Promise<object>}
|
||||
* @example
|
||||
* // Set a patterns cycle length to exactly the length of the sample
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
@@ -260,6 +260,7 @@ export async function fetchSampleMap(url) {
|
||||
/**
|
||||
* Loads a collection of samples to use with `s`
|
||||
* @tags samples
|
||||
* @global
|
||||
* @example
|
||||
* samples('github:tidalcycles/dirt-samples');
|
||||
* s("[bd ~]*2, [~ hh]*2, ~ sd")
|
||||
@@ -288,12 +289,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 +375,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,
|
||||
@@ -40,8 +39,9 @@ export let maxPolyphony = DEFAULT_MAX_POLYPHONY;
|
||||
* start to die out in first-in-first-out order once the max polyphony has been hit
|
||||
*
|
||||
* @name setMaxPolyphony
|
||||
* @global
|
||||
* @tags superdough
|
||||
* @param {number} Max polyphony. Defaults to 128
|
||||
* @param {number} polyphony Max polyphony. Defaults to 128
|
||||
* @example
|
||||
* setMaxPolyphony(4)
|
||||
* n(irand(24).seg(8)).scale("C#3:minor").room(1).release(4).gain(0.5)
|
||||
@@ -63,6 +63,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) {
|
||||
@@ -72,10 +77,10 @@ export function applyGainCurve(val) {
|
||||
/**
|
||||
* Apply a function to all gains provided in patterns. Can be used to rescale gain to be
|
||||
* quadratic, exponential, etc. rather than linear
|
||||
*
|
||||
* @global
|
||||
* @name setGainCurve
|
||||
* @tags amplitude, superdough
|
||||
* @param {Function} function to apply to all gain values
|
||||
* @param {Function} newGainCurveFunc function to apply to all gain values
|
||||
* @example
|
||||
* setGainCurve((x) => x * x) // quadratic gain
|
||||
* s("bd*4").gain(0.5) // equivalent to 0.25 gain normally
|
||||
@@ -126,11 +131,11 @@ async function aliasBankPath(path) {
|
||||
|
||||
/**
|
||||
* Register an alias for a bank of sounds.
|
||||
* @global
|
||||
* @param {...any} args either one or two arguments. first argument is bank to alias. Second argument is alias to use for the bank.
|
||||
* Optionally accepts a single argument map of bank aliases.
|
||||
* Optionally accepts a single argument string of a path to a JSON file containing bank aliases.
|
||||
* @param {string} bank - The bank to alias
|
||||
* @param {string} alias - The alias to use for the bank
|
||||
*
|
||||
* @returns {void}
|
||||
* @tags samples
|
||||
*/
|
||||
export async function aliasBank(...args) {
|
||||
@@ -150,6 +155,7 @@ export async function aliasBank(...args) {
|
||||
|
||||
/**
|
||||
* Register an alias for a sound.
|
||||
* @global
|
||||
* @tags samples
|
||||
* @param {string} original - The original sound name
|
||||
* @param {string} alias - The alias to use for the sound
|
||||
@@ -260,14 +266,6 @@ export function loadWorklets() {
|
||||
return workletsLoading;
|
||||
}
|
||||
|
||||
let kabel;
|
||||
async function initKabelsalat() {
|
||||
const { SalatRepl } = await import('@kabelsalat/web');
|
||||
logger('[kabelsalat] ready');
|
||||
kabel = new SalatRepl({ localScope: true });
|
||||
return kabel;
|
||||
}
|
||||
|
||||
// this function should be called on first user interaction (to avoid console warning)
|
||||
export async function initAudio(options = {}) {
|
||||
const {
|
||||
@@ -314,7 +312,6 @@ export async function initAudio(options = {}) {
|
||||
} catch (err) {
|
||||
console.warn('could not load AudioWorklet effects', err);
|
||||
}
|
||||
await initKabelsalat();
|
||||
logger('[superdough] ready');
|
||||
}
|
||||
let audioReady;
|
||||
@@ -450,14 +447,6 @@ class Chain {
|
||||
}
|
||||
}
|
||||
|
||||
const compileKabel = (code) => {
|
||||
if (!kabel) {
|
||||
throw new Error('kabelsalat not loaded');
|
||||
}
|
||||
const node = kabel.evaluate(code);
|
||||
return node.compile({ log: false });
|
||||
};
|
||||
|
||||
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
|
||||
// mapping from main FX and numbered FX chains to nodes
|
||||
const nodes = { main: {} };
|
||||
@@ -633,17 +622,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) {
|
||||
@@ -676,7 +669,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
chain.connect(initialGain);
|
||||
|
||||
// filter
|
||||
const ftype = getFilterType(value.ftype);
|
||||
const ftype = getFilterType(fx.ftype ?? value.ftype);
|
||||
|
||||
const filt = (params) => createFilter(ac, t, end, params, cps, cycle);
|
||||
if (fx.cutoff !== undefined) {
|
||||
@@ -701,6 +694,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||
};
|
||||
const lpParams = pickAndRename(fx, lpMap);
|
||||
lpParams.type = 'lowpass';
|
||||
lpParams.model = ftype;
|
||||
const { filter: lpf1, lfo: lfo1 } = filt(lpParams);
|
||||
fxNodes['lpf'] = [lpf1];
|
||||
fxNodes['lpf_lfo'] = [lfo1];
|
||||
|
||||
@@ -404,6 +404,89 @@ export function registerSynthSounds() {
|
||||
{ prebake: true, type: 'input' },
|
||||
);
|
||||
|
||||
registerSound(
|
||||
'goabd',
|
||||
(t, value, onended) => {
|
||||
const {
|
||||
duration,
|
||||
attack = 0,
|
||||
hold = 0.2,
|
||||
decay = 0.25,
|
||||
sustain = 0,
|
||||
release = 0,
|
||||
pdecay = 1,
|
||||
penv = 84,
|
||||
pcurve = 0.85,
|
||||
clip,
|
||||
} = value;
|
||||
const ctx = getAudioContext();
|
||||
const soundGain = 0.5;
|
||||
const mixGain = 1;
|
||||
|
||||
const freq = getFrequencyFromValue(value, 24);
|
||||
const f = getWorklet(ctx, 'goabd-freq-env-processor', {
|
||||
begin: t,
|
||||
end: t + pdecay,
|
||||
freq0: freq * Math.pow(2, penv / 12),
|
||||
freq1: freq,
|
||||
pcurve: pcurve,
|
||||
});
|
||||
const o = ctx.createOscillator();
|
||||
o.type = 'sine';
|
||||
o.frequency.value = 0;
|
||||
f.connect(o.frequency);
|
||||
const g = gainNode(soundGain);
|
||||
let soundDuration = attack + hold + decay;
|
||||
if (sustain > 0) {
|
||||
soundDuration = Math.max(soundDuration, duration) + release;
|
||||
}
|
||||
if (attack > 0) {
|
||||
g.gain.setValueAtTime(0.0001, t);
|
||||
g.gain.exponentialRampToValueAtTime(soundGain, t + attack);
|
||||
} else {
|
||||
g.gain.setValueAtTime(soundGain, t);
|
||||
}
|
||||
if (hold > 0) {
|
||||
g.gain.setValueAtTime(soundGain, t + attack + hold);
|
||||
}
|
||||
g.gain.exponentialRampToValueAtTime(Math.max(0.0001, sustain), t + soundDuration - release);
|
||||
g.gain.exponentialRampToValueAtTime(0.0001, t + soundDuration);
|
||||
o.start(t);
|
||||
|
||||
const mix = gainNode(mixGain);
|
||||
|
||||
onceEnded(o, () => {
|
||||
releaseAudioNode(f);
|
||||
releaseAudioNode(o);
|
||||
releaseAudioNode(g);
|
||||
releaseAudioNode(mix);
|
||||
onended();
|
||||
});
|
||||
|
||||
const node = o.connect(g).connect(mix);
|
||||
|
||||
// prevent clicking
|
||||
let mixDuration = soundDuration;
|
||||
if (clip != null) {
|
||||
mixDuration = Math.min(clip * duration, mixDuration);
|
||||
}
|
||||
const mixEnd = t + mixDuration;
|
||||
mix.gain.setValueAtTime(mixGain, mixEnd - 0.01);
|
||||
mix.gain.linearRampToValueAtTime(0, mixEnd);
|
||||
|
||||
o.stop(mixEnd);
|
||||
|
||||
return {
|
||||
node,
|
||||
nodes: { source: [o] },
|
||||
stop: (endTime) => {
|
||||
o.stop(endTime);
|
||||
},
|
||||
};
|
||||
},
|
||||
{ type: 'synth', prebake: true },
|
||||
);
|
||||
|
||||
[...noises].forEach((s) => {
|
||||
registerSound(
|
||||
s,
|
||||
|
||||
@@ -111,7 +111,11 @@ export function getCommonSampleInfo(hapValue, bank) {
|
||||
}
|
||||
|
||||
/** Selects entries from `source` and renames them via `map`
|
||||
* @global
|
||||
* @tags internals
|
||||
* @param {object} source
|
||||
* @param {*} map
|
||||
* @returns {*}
|
||||
*/
|
||||
export const pickAndRename = (source, map) => {
|
||||
return Object.fromEntries(Object.entries(map).map(([newKey, oldKey]) => [newKey, source[oldKey]]));
|
||||
|
||||
@@ -184,9 +184,14 @@ export function registerWaveTable(key, tables, params) {
|
||||
|
||||
/**
|
||||
* Loads a collection of wavetables to use with `s`
|
||||
*
|
||||
* @global
|
||||
* @param {string} url
|
||||
* @param {*} frameLen
|
||||
* @param {string} json
|
||||
* @param {object} options
|
||||
* @name tables
|
||||
* @tags wavetable
|
||||
* @returns {void}
|
||||
*/
|
||||
export const tables = async (url, frameLen, json, options = {}) => {
|
||||
if (json !== undefined) return _processTables(json, url, frameLen);
|
||||
|
||||
@@ -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;
|
||||
@@ -647,6 +644,7 @@ class PhaseVocoderProcessor extends OLAProcessor {
|
||||
}
|
||||
|
||||
/** Apply Hann window in-place
|
||||
* @param {number[]} input
|
||||
* @tags internals
|
||||
*/
|
||||
applyHannWindow(input) {
|
||||
@@ -695,6 +693,7 @@ class PhaseVocoderProcessor extends OLAProcessor {
|
||||
}
|
||||
|
||||
/** Shift peaks and regions of influence by pitchFactor into new specturm
|
||||
* @param {number} pitchFactor
|
||||
* @tags internals
|
||||
*/
|
||||
shiftPeaks(pitchFactor) {
|
||||
@@ -851,6 +850,8 @@ registerProcessor('pulse-oscillator', PulseOscillatorProcessor);
|
||||
|
||||
/** BYTE BEATS
|
||||
* @tags internals
|
||||
* @global
|
||||
* @typedef Chyx
|
||||
*/
|
||||
const chyx = {
|
||||
/*bit*/ bitC: function (x, y, z) {
|
||||
@@ -984,6 +985,49 @@ class ByteBeatProcessor extends AudioWorkletProcessor {
|
||||
|
||||
registerProcessor('byte-beat-processor', ByteBeatProcessor);
|
||||
|
||||
class GoaBdFreqEnvProcessor extends AudioWorkletProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [
|
||||
{ name: 'begin', defaultValue: 0 },
|
||||
{ name: 'end', defaultValue: 0 },
|
||||
{ name: 'freq0', defaultValue: 55 * 64 },
|
||||
{ name: 'freq1', defaultValue: 55 },
|
||||
{ name: 'pcurve', defaultValue: 0.5 },
|
||||
];
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.p0 = 0.006699687;
|
||||
this.p1 = 0.00001884606;
|
||||
this.time = 0;
|
||||
}
|
||||
|
||||
process(_inputs, outputs, params) {
|
||||
const begin = params['begin'][0];
|
||||
const end = params['end'][0];
|
||||
if (currentTime >= end) {
|
||||
return false;
|
||||
}
|
||||
if (currentTime <= begin) {
|
||||
return true;
|
||||
}
|
||||
const out = outputs[0][0];
|
||||
const freq0 = params['freq0'][0];
|
||||
const freq1 = params['freq1'][0];
|
||||
const pcurve = params['pcurve'][0];
|
||||
const p = (1 - pcurve) * this.p0 + pcurve * this.p1;
|
||||
const dt = (INVSR * 1) / (end - begin);
|
||||
for (let i = 0; i < out.length; i++) {
|
||||
out[i] = freq1 + (freq0 - freq1) / (1 + this.time / p);
|
||||
this.time += dt;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
registerProcessor('goabd-freq-env-processor', GoaBdFreqEnvProcessor);
|
||||
|
||||
class EnvelopeProcessor extends AudioWorkletProcessor {
|
||||
static get parameterDescriptors() {
|
||||
return [
|
||||
@@ -1492,81 +1536,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);
|
||||
|
||||
@@ -102,8 +102,8 @@ function scaleOffset(scale, offset, note) {
|
||||
*
|
||||
* @tags tonal
|
||||
* @param {string | number} amount Either number of semitones or interval string.
|
||||
* @returns Pattern
|
||||
* @memberof Pattern
|
||||
* @returns {Pattern}
|
||||
* @memberof Pattern.prototype
|
||||
* @name transpose
|
||||
* @synonyms trans
|
||||
* @example
|
||||
@@ -160,11 +160,11 @@ export const { transpose, trans } = register(['transpose', 'trans'], function tr
|
||||
* Transposes notes inside the scale by the number of steps.
|
||||
* Expected to be called on a Pattern which already has a {@link Pattern#scale}
|
||||
*
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @name scaleTranspose
|
||||
* @tags tonal
|
||||
* @param {offset} offset number of steps inside the scale
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @synonyms scaleTrans, strans
|
||||
* @example
|
||||
* "-8 [2,4,6]"
|
||||
@@ -255,7 +255,8 @@ function _getNearestScaleNote(scaleName, note, preferHigher = true) {
|
||||
* @name scale
|
||||
* @tags tonal
|
||||
* @param {string} scale Name of scale
|
||||
* @returns Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* n("0 2 4 6 4 2").scale("C:major")
|
||||
* @example
|
||||
|
||||
@@ -91,11 +91,10 @@ export const setVoicingRange = (name, range) => addVoicings(name, voicingRegistr
|
||||
*
|
||||
* @name addVoicings
|
||||
* @tags tonal
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {string} name identifier for the voicing dictionary
|
||||
* @param {Object} dictionary maps chord symbol to possible voicings
|
||||
* @param {object} dictionary maps chord symbol to possible voicings
|
||||
* @param {Array} range min, max note
|
||||
* @returns Pattern
|
||||
* @example
|
||||
* addVoicings('cookie', {
|
||||
* 7: ['3M 7m 9M 12P 15P', '7m 10M 13M 16M 19P'],
|
||||
@@ -135,9 +134,9 @@ const getVoicing = (chord, dictionaryName, lastVoicing) => {
|
||||
*
|
||||
* @name voicings
|
||||
* @tags tonal
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {string} dictionary which voicing dictionary to use.
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* stack("<C^7 A7 Dm7 G7>".voicings('lefthand'), "<C3 A2 D3 G2>").note()
|
||||
*/
|
||||
@@ -160,9 +159,9 @@ export const voicings = register('voicings', function (dictionary, pat) {
|
||||
*
|
||||
* @name rootNotes
|
||||
* @tags tonal
|
||||
* @memberof Pattern
|
||||
* @memberof Pattern.prototype
|
||||
* @param {octave} octave octave to use
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* "<C^7 A7 Dm7 G7>".rootNotes(2).note()
|
||||
*/
|
||||
@@ -196,7 +195,8 @@ export const rootNotes = register('rootNotes', function (octave, pat) {
|
||||
*
|
||||
* @name voicing
|
||||
* @tags tonal
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
* @memberof Pattern.prototype
|
||||
* @example
|
||||
* n("0 1 2 3").chord("<C Am F G>").voicing()
|
||||
*/
|
||||
|
||||
+37
-3
@@ -12,7 +12,10 @@ import { initAudioOnFirstClick, registerSynthSounds, webaudioRepl } from '@strud
|
||||
import { evaluate as _evaluate, transpiler } from '@strudel/transpiler';
|
||||
import { miniAllStrings } from '@strudel/mini';
|
||||
|
||||
// init logic
|
||||
/**
|
||||
* init logic
|
||||
* @global
|
||||
*/
|
||||
export async function defaultPrebake() {
|
||||
const loadModules = evalScope(
|
||||
evalScope,
|
||||
@@ -30,6 +33,28 @@ export async function defaultPrebake() {
|
||||
let initDone;
|
||||
|
||||
let repl;
|
||||
/** initiates strudel
|
||||
* @global
|
||||
* @param {object} options
|
||||
* @param {*} options.onSchedule
|
||||
* @param {*} options.defaultOutput
|
||||
* @param {*} options.onEvalError
|
||||
* @param {*} options.beforeEval
|
||||
* @param {*} options.beforeStart
|
||||
* @param {*} options.afterEval
|
||||
* @param {*} options.getTime
|
||||
* @param {*} options.transpiler
|
||||
* @param {*} options.onToggle
|
||||
* @param {*} options.editPattern
|
||||
* @param {*} options.onUpdateState
|
||||
* @param {*} options.sync = false
|
||||
* @param {*} options.setInterval
|
||||
* @param {*} options.clearInterval
|
||||
* @param {*} options.id
|
||||
* @param {*} options.mondo = false
|
||||
* @param {*} options.prebake
|
||||
* @returns {object}
|
||||
*/
|
||||
export function initStrudel(options = {}) {
|
||||
initAudioOnFirstClick();
|
||||
options.miniAllStrings !== false && miniAllStrings();
|
||||
@@ -58,12 +83,21 @@ Pattern.prototype.play = function () {
|
||||
return this;
|
||||
};
|
||||
|
||||
// stop playback
|
||||
/**
|
||||
* stop playback
|
||||
* @global
|
||||
*/
|
||||
export function hush() {
|
||||
repl.stop();
|
||||
}
|
||||
|
||||
// evaluate and play the given code using the transpiler
|
||||
/**
|
||||
* evaluate and play the given code using the transpiler
|
||||
* @global
|
||||
* @param {*} code
|
||||
* @param {*} autoplay
|
||||
* @returns {*}
|
||||
*/
|
||||
export async function evaluate(code, autoplay = true) {
|
||||
return repl.evaluate(code, autoplay);
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -99,12 +99,15 @@ function clearScreen(smear = 0, smearRGB = `0,0,0`, ctx = getDrawContext()) {
|
||||
* Renders an oscilloscope for the frequency domain of the audio signal.
|
||||
* @name fscope
|
||||
* @tags visualization
|
||||
* @param {string} color line color as hex or color name. defaults to white.
|
||||
* @param {number} scale scales the y-axis. Defaults to 0.25
|
||||
* @param {number} pos y-position relative to screen height. 0 = top, 1 = bottom of screen
|
||||
* @param {number} lean y-axis alignment where 0 = top and 1 = bottom
|
||||
* @param {number} min min value
|
||||
* @param {number} max max value
|
||||
* @memberof Pattern.prototype
|
||||
* @param {object} config object that may have the following arguments
|
||||
* @param {string} config.color line color as hex or color name. defaults to white.
|
||||
* @param {number} config.scale scales the y-axis. Defaults to 0.25
|
||||
* @param {number} config.pos y-position relative to screen height. 0 = top, 1 = bottom of screen
|
||||
* @param {number} config.lean y-axis alignment where 0 = top and 1 = bottom
|
||||
* @param {number} config.min min value
|
||||
* @param {number} config.max max value
|
||||
* @returns {Pattern}
|
||||
* @example
|
||||
* s("sawtooth").fscope()
|
||||
*/
|
||||
@@ -122,6 +125,7 @@ Pattern.prototype.fscope = function (config = {}) {
|
||||
/**
|
||||
* Renders an oscilloscope for the time domain of the audio signal.
|
||||
* @name scope
|
||||
* @memberof Pattern.prototype
|
||||
* @synonyms tscope
|
||||
* @tags visualization
|
||||
* @param {object} config optional config with options:
|
||||
|
||||
@@ -5,12 +5,13 @@ import { analysers, getAnalyzerData } from 'superdough';
|
||||
/**
|
||||
* Renders a spectrum analyzer for the incoming audio signal.
|
||||
* @name spectrum
|
||||
* @memberof Pattern.prototype
|
||||
* @tags visualization
|
||||
* @param {object} config optional config with options:
|
||||
* @param {integer} thickness line thickness in px (default 3)
|
||||
* @param {integer} speed scroll speed (default 1)
|
||||
* @param {integer} min min db (default -80)
|
||||
* @param {integer} max max db (default 0)
|
||||
* @param {number} [thickness=3] line thickness in px (default 3)
|
||||
* @param {number} [speed=1] scroll speed (default 1)
|
||||
* @param {number} [min=-80] min db (default -80)
|
||||
* @param {number} [max=0] max db (default 0)
|
||||
* @example
|
||||
* n("<0 4 <2 3> 1>*3")
|
||||
* .off(1/8, add(n(5)))
|
||||
|
||||
@@ -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.
|
||||
* @global
|
||||
* @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
|
||||
* @global
|
||||
* @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
|
||||
* @global
|
||||
* @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 = {}) {
|
||||
|
||||
@@ -20,7 +20,6 @@ function connect(addr) {
|
||||
});
|
||||
ws.addEventListener('message', (event) => {
|
||||
try {
|
||||
console.log(event.data);
|
||||
values[addr] = JSON.parse(event.data);
|
||||
} catch {
|
||||
logger(`[websocket] received invalid json on ${addr}`);
|
||||
|
||||
@@ -12,8 +12,8 @@ import { register } from '@strudel/core';
|
||||
*
|
||||
* Assumes pattern contains numerical scale degrees on the `i` control (see examples below). Accepts a scale name or list of frequencies (see all available names at the link on the reference). Returns a new pattern with all values mapped to a frequency ratio. Similar to `xen`.
|
||||
* @name tune
|
||||
* @returns Pattern
|
||||
* @memberof Pattern
|
||||
* @returns {Pattern}
|
||||
* @memberof Pattern.prototype
|
||||
* @param {(string | number[] )} scale
|
||||
* @deprecated
|
||||
* @example
|
||||
|
||||
+12
-6
@@ -7,7 +7,12 @@ This program is free software: you can redistribute it and/or modify it under th
|
||||
import { register, _mod, parseNumeral, removeUndefineds, Pattern, parray, State } from '@strudel/core';
|
||||
import Tune from './tunejs.js';
|
||||
|
||||
// returns a list of frequency ratios for given edo scale
|
||||
/**
|
||||
* returns a list of frequency ratios for given edo scale
|
||||
* @param {string} name
|
||||
* @returns {number[]}
|
||||
* @global
|
||||
*/
|
||||
export function edo(name) {
|
||||
if (!/^[1-9]+[0-9]*edo$/.test(name)) {
|
||||
throw new Error('not an edo scale: "' + name + '"');
|
||||
@@ -65,8 +70,8 @@ const trimFreq = (freq) => parseFloat(freq.toPrecision(10));
|
||||
* Assumes a numerical pattern of scale steps, and a scale. Scales accepted are all preset scale names of `tune`, arbitrary edos such as 31edo, or an array of frequency ratios. Assumes scales repeat at octave (2/1). Returns a new pattern with all values mapped to their associated frequency, assuming a base frequency of 220hz. See first 4 examples for the different ways you can input a scale into `xen`
|
||||
*
|
||||
* @name xen
|
||||
* @returns Pattern
|
||||
* @memberof Pattern
|
||||
* @returns {Pattern}
|
||||
* @memberof Pattern.prototype
|
||||
* @param {(string | number[] )} scaleNameOrRatios
|
||||
* @tags tonal
|
||||
* @example
|
||||
@@ -200,16 +205,16 @@ export const xen = register(
|
||||
* but you can specify a different original base with the standard optional array syntax '`:`'
|
||||
* @name withBase
|
||||
* @param {number} base
|
||||
* @param {number} (optional) originalBase
|
||||
* @param {number} [originalBase]
|
||||
* @tags tonal
|
||||
*
|
||||
* @memberof Pattern.prototype
|
||||
* @example
|
||||
* i("[0 1 2 3] [3 4] [4 3 2 1]").xen("hexany23").withBase("<220 [300 200]>")
|
||||
* @example
|
||||
* mini([1 / 1, 16 / 15, 9 / 8, 6 / 5, 5 / 4].join(' ')).withBase("220:1")
|
||||
* // mini([1 / 1, 16 / 15, 9 / 8, 6 / 5, 5 / 4].join(' ')).mul(220).freq()
|
||||
*
|
||||
* @returns Pattern
|
||||
* @returns {Pattern}
|
||||
*/
|
||||
export const withBase = register('withBase', (b, pat) => {
|
||||
let base;
|
||||
@@ -246,6 +251,7 @@ export const withBase = register('withBase', (b, pat) => {
|
||||
* @tags tonal
|
||||
* @param {number} amt
|
||||
* @param {number} edoSize (optional)
|
||||
* @memberof Pattern.prototype
|
||||
* @returns {Pattern}
|
||||
*
|
||||
* @example
|
||||
|
||||
Generated
+444
-133
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,98 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`runs examples > example "__pick" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | note:g ]",
|
||||
"[ 1/2 → 1/1 | note:a ]",
|
||||
"[ 1/1 → 3/2 | note:e ]",
|
||||
"[ 3/2 → 2/1 | note:f ]",
|
||||
"[ 2/1 → 9/4 | note:f ]",
|
||||
"[ 9/4 → 5/2 | note:g ]",
|
||||
"[ 5/2 → 11/4 | note:f ]",
|
||||
"[ 11/4 → 3/1 | note:g ]",
|
||||
"[ 3/1 → 13/4 | note:f ]",
|
||||
"[ 13/4 → 7/2 | note:g ]",
|
||||
"[ 7/2 → 15/4 | note:f ]",
|
||||
"[ 15/4 → 4/1 | note:g ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "__pick" example index 1 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | s:bd ]",
|
||||
"[ 1/2 → 1/1 | s:sd ]",
|
||||
"[ 1/1 → 3/2 | s:cp ]",
|
||||
"[ 3/2 → 2/1 | s:cp ]",
|
||||
"[ 2/1 → 5/2 | s:hh ]",
|
||||
"[ 2/1 → 5/2 | s:bd ]",
|
||||
"[ 5/2 → 3/1 | s:hh ]",
|
||||
"[ 5/2 → 3/1 | s:sd ]",
|
||||
"[ 3/1 → 7/2 | s:bd ]",
|
||||
"[ 7/2 → 4/1 | s:sd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "__pick" example index 2 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:bd ]",
|
||||
"[ 3/8 → 1/2 | s:bd ]",
|
||||
"[ 3/4 → 7/8 | s:bd ]",
|
||||
"[ 1/1 → 9/8 | s:bd ]",
|
||||
"[ 11/8 → 3/2 | s:bd ]",
|
||||
"[ 7/4 → 15/8 | s:bd ]",
|
||||
"[ 2/1 → 17/8 | s:bd ]",
|
||||
"[ 2/1 → 5/2 | s:sd ]",
|
||||
"[ 19/8 → 5/2 | s:bd ]",
|
||||
"[ 5/2 → 3/1 | s:sd ]",
|
||||
"[ 11/4 → 23/8 | s:bd ]",
|
||||
"[ 3/1 → 7/2 | s:sd ]",
|
||||
"[ 7/2 → 4/1 | s:sd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "__pick" example index 3 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:bd ]",
|
||||
"[ 3/8 → 1/2 | s:bd ]",
|
||||
"[ 3/4 → 7/8 | s:bd ]",
|
||||
"[ 1/1 → 9/8 | s:bd ]",
|
||||
"[ 11/8 → 3/2 | s:bd ]",
|
||||
"[ 7/4 → 15/8 | s:bd ]",
|
||||
"[ 2/1 → 17/8 | s:bd ]",
|
||||
"[ 2/1 → 5/2 | s:sd ]",
|
||||
"[ 19/8 → 5/2 | s:bd ]",
|
||||
"[ 5/2 → 3/1 | s:sd ]",
|
||||
"[ 11/4 → 23/8 | s:bd ]",
|
||||
"[ 3/1 → 7/2 | s:sd ]",
|
||||
"[ 7/2 → 4/1 | s:sd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "__pick" example index 4 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | s:bd speed:2 ]",
|
||||
"[ 1/4 → 1/2 | s:cp speed:2 ]",
|
||||
"[ 1/2 → 3/4 | s:bd speed:3 ]",
|
||||
"[ 3/4 → 1/1 | s:cp speed:3 ]",
|
||||
"[ 1/1 → 7/6 | s:bd speed:3 ]",
|
||||
"[ 7/6 → 4/3 | s:cp speed:3 ]",
|
||||
"[ 4/3 → 3/2 | s:bd speed:2 ]",
|
||||
"[ 3/2 → 5/3 | s:cp speed:2 ]",
|
||||
"[ 5/3 → 11/6 | s:bd speed:3 ]",
|
||||
"[ 11/6 → 2/1 | s:cp speed:3 ]",
|
||||
"[ 2/1 → 9/4 | s:bd speed:2 ]",
|
||||
"[ 9/4 → 5/2 | s:cp speed:2 ]",
|
||||
"[ 5/2 → 11/4 | s:bd speed:3 ]",
|
||||
"[ 11/4 → 3/1 | s:cp speed:3 ]",
|
||||
"[ 3/1 → 19/6 | s:bd speed:3 ]",
|
||||
"[ 19/6 → 10/3 | s:cp speed:3 ]",
|
||||
"[ 10/3 → 7/2 | s:bd speed:2 ]",
|
||||
"[ 7/2 → 11/3 | s:cp speed:2 ]",
|
||||
"[ 11/3 → 23/6 | s:bd speed:3 ]",
|
||||
"[ 23/6 → 4/1 | s:cp speed:3 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "_euclidRot" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/5 | note:c3 ]",
|
||||
@@ -611,6 +704,30 @@ exports[`runs examples > example "FX" example index 1 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "Hap" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | s:sd ]",
|
||||
"[ 0/1 → 1/1 | s:bd ]",
|
||||
"[ 1/2 → 1/1 | s:sd ]",
|
||||
"[ 1/1 → 3/2 | s:sd ]",
|
||||
"[ 1/1 → 2/1 | s:bd ]",
|
||||
"[ 3/2 → 2/1 | s:sd ]",
|
||||
"[ 2/1 → 5/2 | s:sd ]",
|
||||
"[ 2/1 → 3/1 | s:bd ]",
|
||||
"[ 5/2 → 3/1 | s:sd ]",
|
||||
"[ 3/1 → 7/2 | s:sd ]",
|
||||
"[ 3/1 → 4/1 | s:bd ]",
|
||||
"[ 7/2 → 4/1 | s:sd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "Hap" example index 1 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | note:c3 ]",
|
||||
"[ 1/4 → 1/2 | note:d3 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "K" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/12 | note:Bb4 s:saw workletSrc:saw(saw(sFreq / pat[0]).mul(8).add(sFreq).lag(pat[1])).mul(0.3).mul(sGate.adsr(0 0.15 0.5 pat[2])).lpf(sGate.adsr(0 0.2 0.3 0.2).mul(1).add(0)).add(x => x.delay(pat[3]).mul(0.7)).add(x => x.delay(pat[4]).mul(0.77)).mul(0.7).add(x => x.delay(0.13).mul(0.7)).out() workletInputs:[2 0 0.1 0.3 0.03] ]",
|
||||
@@ -1301,6 +1418,23 @@ exports[`runs examples > example "beat" example index 1 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "beat" example index 2 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:sd ]",
|
||||
"[ 3/8 → 1/2 | s:sd ]",
|
||||
"[ 3/4 → 7/8 | s:sd ]",
|
||||
"[ 1/1 → 9/8 | s:sd ]",
|
||||
"[ 11/8 → 3/2 | s:sd ]",
|
||||
"[ 7/4 → 15/8 | s:sd ]",
|
||||
"[ 2/1 → 17/8 | s:sd ]",
|
||||
"[ 19/8 → 5/2 | s:sd ]",
|
||||
"[ 11/4 → 23/8 | s:sd ]",
|
||||
"[ 3/1 → 25/8 | s:sd ]",
|
||||
"[ 27/8 → 7/2 | s:sd ]",
|
||||
"[ 15/4 → 31/8 | s:sd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "begin" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/2 | s:rave begin:0 ]",
|
||||
@@ -1396,6 +1530,43 @@ exports[`runs examples > example "binary" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "binaryL" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:saw partials:[1] ]",
|
||||
"[ 1/8 → 1/4 | s:saw partials:[1 0 1 0 1 1 1 1 0 1 1 1] ]",
|
||||
"[ 1/4 → 3/8 | s:saw partials:[1 0 1 1 1 1 0 1 0 1 1] ]",
|
||||
"[ 3/8 → 1/2 | s:saw partials:[1 1 0 0 1 1 0 1 1 0 1] ]",
|
||||
"[ 1/2 → 5/8 | s:saw partials:[1 0 0 0 0 1 0 1 0 1 1] ]",
|
||||
"[ 5/8 → 3/4 | s:saw partials:[1 0 0 0 1 0 1 1 0 0] ]",
|
||||
"[ 3/4 → 7/8 | s:saw partials:[1 1 0 0 1 0 0 0 1 1] ]",
|
||||
"[ 7/8 → 1/1 | s:saw partials:[1 1 0 0 1 0 1 1 1 0 1] ]",
|
||||
"[ 1/1 → 9/8 | s:saw partials:[1 0 0 0 0 1 0 1 0 0 0 1] ]",
|
||||
"[ 9/8 → 5/4 | s:saw partials:[1 0 1 0 1 1 0 0 0 0 1 1] ]",
|
||||
"[ 5/4 → 11/8 | s:saw partials:[1 0 1 1 1 0 1 0 1 0 0 1] ]",
|
||||
"[ 11/8 → 3/2 | s:saw partials:[1 0 1 1 1 0 1 1 0 1] ]",
|
||||
"[ 3/2 → 13/8 | s:saw partials:[1 0 0 1 1 0 1 1 1 1 0 1] ]",
|
||||
"[ 13/8 → 7/4 | s:saw partials:[1 1 1 1 1 1 1 0 0 1 1] ]",
|
||||
"[ 7/4 → 15/8 | s:saw partials:[1 1 0 1 0 0 0 1 1 1] ]",
|
||||
"[ 15/8 → 2/1 | s:saw partials:[1 0 0 1 1 0 0 0 0 1 0 0] ]",
|
||||
"[ 2/1 → 17/8 | s:saw partials:[1 1 1 1 0 1 0 1 1 0 1 1] ]",
|
||||
"[ 17/8 → 9/4 | s:saw partials:[1 1 1 0 0 1 1 1 0 1 0 1] ]",
|
||||
"[ 9/4 → 19/8 | s:saw partials:[1 0 1 1 0 0 0 1 0 0 0] ]",
|
||||
"[ 19/8 → 5/2 | s:saw partials:[1 1 0 1 0 1 1 0 0 0 1 1] ]",
|
||||
"[ 5/2 → 21/8 | s:saw partials:[1 1 1 0 1 0 1 0 1 1 1] ]",
|
||||
"[ 21/8 → 11/4 | s:saw partials:[1 0 1 0 0 1 0 0 0 1] ]",
|
||||
"[ 11/4 → 23/8 | s:saw partials:[1 0 1 0 0 0 1 0 0 0 1 0] ]",
|
||||
"[ 23/8 → 3/1 | s:saw partials:[1 0 0 0 0 1 1] ]",
|
||||
"[ 3/1 → 25/8 | s:saw partials:[1 1 0 1 1 1 1 0 1 1] ]",
|
||||
"[ 25/8 → 13/4 | s:saw partials:[1 0 1 0 1 1 1 1 1 1 0] ]",
|
||||
"[ 13/4 → 27/8 | s:saw partials:[1 1 1 1 1 1 1 0 0 0 0 1] ]",
|
||||
"[ 27/8 → 7/2 | s:saw partials:[1 1 0 1 0 0 0 1 0 1 1] ]",
|
||||
"[ 7/2 → 29/8 | s:saw partials:[1 1 0 1 0 0 1 0 0 0 0] ]",
|
||||
"[ 29/8 → 15/4 | s:saw partials:[1 1 1 1 0 0 0 0 0 1 1 1] ]",
|
||||
"[ 15/4 → 31/8 | s:saw partials:[1 1 0 0 1 1 1 1 1 1 1 1] ]",
|
||||
"[ 31/8 → 4/1 | s:saw partials:[1 0 1 1 1 1 0 0 1 0 0 0] ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "binaryN" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/16 | s:hh ]",
|
||||
@@ -7070,7 +7241,30 @@ exports[`runs examples > example "keep" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "keyDown" example index 0 1`] = `[]`;
|
||||
exports[`runs examples > example "keyDown" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:bd ]",
|
||||
"[ 1/4 → 3/8 | s:bd ]",
|
||||
"[ 3/8 → 1/2 | s:bd ]",
|
||||
"[ 5/8 → 3/4 | s:bd ]",
|
||||
"[ 3/4 → 7/8 | s:bd ]",
|
||||
"[ 1/1 → 9/8 | s:bd ]",
|
||||
"[ 5/4 → 11/8 | s:bd ]",
|
||||
"[ 11/8 → 3/2 | s:bd ]",
|
||||
"[ 13/8 → 7/4 | s:bd ]",
|
||||
"[ 7/4 → 15/8 | s:bd ]",
|
||||
"[ 2/1 → 17/8 | s:bd ]",
|
||||
"[ 9/4 → 19/8 | s:bd ]",
|
||||
"[ 19/8 → 5/2 | s:bd ]",
|
||||
"[ 21/8 → 11/4 | s:bd ]",
|
||||
"[ 11/4 → 23/8 | s:bd ]",
|
||||
"[ 3/1 → 25/8 | s:bd ]",
|
||||
"[ 13/4 → 27/8 | s:bd ]",
|
||||
"[ 27/8 → 7/2 | s:bd ]",
|
||||
"[ 29/8 → 15/4 | s:bd ]",
|
||||
"[ 15/4 → 31/8 | s:bd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "lastOf" example index 0 1`] = `
|
||||
[
|
||||
@@ -9592,6 +9786,31 @@ exports[`runs examples > example "pick" example index 3 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "pick" example index 4 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | s:bd speed:2 ]",
|
||||
"[ 1/4 → 1/2 | s:cp speed:2 ]",
|
||||
"[ 1/2 → 3/4 | s:bd speed:3 ]",
|
||||
"[ 3/4 → 1/1 | s:cp speed:3 ]",
|
||||
"[ 1/1 → 7/6 | s:bd speed:3 ]",
|
||||
"[ 7/6 → 4/3 | s:cp speed:3 ]",
|
||||
"[ 4/3 → 3/2 | s:bd speed:2 ]",
|
||||
"[ 3/2 → 5/3 | s:cp speed:2 ]",
|
||||
"[ 5/3 → 11/6 | s:bd speed:3 ]",
|
||||
"[ 11/6 → 2/1 | s:cp speed:3 ]",
|
||||
"[ 2/1 → 9/4 | s:bd speed:2 ]",
|
||||
"[ 9/4 → 5/2 | s:cp speed:2 ]",
|
||||
"[ 5/2 → 11/4 | s:bd speed:3 ]",
|
||||
"[ 11/4 → 3/1 | s:cp speed:3 ]",
|
||||
"[ 3/1 → 19/6 | s:bd speed:3 ]",
|
||||
"[ 19/6 → 10/3 | s:cp speed:3 ]",
|
||||
"[ 10/3 → 7/2 | s:bd speed:2 ]",
|
||||
"[ 7/2 → 11/3 | s:cp speed:2 ]",
|
||||
"[ 11/3 → 23/6 | s:bd speed:3 ]",
|
||||
"[ 23/6 → 4/1 | s:cp speed:3 ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "pickF" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/4 | s:hh ]",
|
||||
@@ -11689,6 +11908,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 ]",
|
||||
@@ -12769,6 +13054,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 ]",
|
||||
@@ -14046,106 +14506,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 ]",
|
||||
]
|
||||
`;
|
||||
@@ -15791,7 +16221,30 @@ exports[`runs examples > example "when" example index 0 1`] = `
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "whenKey" example index 0 1`] = `[]`;
|
||||
exports[`runs examples > example "whenKey" example index 0 1`] = `
|
||||
[
|
||||
"[ 0/1 → 1/8 | s:bd ]",
|
||||
"[ 1/4 → 3/8 | s:bd ]",
|
||||
"[ 3/8 → 1/2 | s:bd ]",
|
||||
"[ 5/8 → 3/4 | s:bd ]",
|
||||
"[ 3/4 → 7/8 | s:bd ]",
|
||||
"[ 1/1 → 9/8 | s:bd ]",
|
||||
"[ 5/4 → 11/8 | s:bd ]",
|
||||
"[ 11/8 → 3/2 | s:bd ]",
|
||||
"[ 13/8 → 7/4 | s:bd ]",
|
||||
"[ 7/4 → 15/8 | s:bd ]",
|
||||
"[ 2/1 → 17/8 | s:bd ]",
|
||||
"[ 9/4 → 19/8 | s:bd ]",
|
||||
"[ 19/8 → 5/2 | s:bd ]",
|
||||
"[ 21/8 → 11/4 | s:bd ]",
|
||||
"[ 11/4 → 23/8 | s:bd ]",
|
||||
"[ 3/1 → 25/8 | s:bd ]",
|
||||
"[ 13/4 → 27/8 | s:bd ]",
|
||||
"[ 27/8 → 7/2 | s:bd ]",
|
||||
"[ 29/8 → 15/4 | s:bd ]",
|
||||
"[ 15/4 → 31/8 | s:bd ]",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`runs examples > example "withBase" example index 0 1`] = `
|
||||
[
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('runs examples', () => {
|
||||
}
|
||||
doc.examples?.forEach((example, i) => {
|
||||
it(`example "${doc.name}" example index ${i}`, async ({ expect }) => {
|
||||
const haps = await queryCode(example, 4);
|
||||
const haps = await queryCode(example, 4, true);
|
||||
expect(haps).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+2
-2
@@ -182,9 +182,9 @@ evalScope(
|
||||
);
|
||||
|
||||
// TBD: use transpiler to support labeled statements
|
||||
export const queryCode = async (code, cycles = 1) => {
|
||||
export const queryCode = async (code, cycles = 1, propagateExceptions = false) => {
|
||||
const { pattern } = await evaluate(code);
|
||||
const haps = pattern.sortHapsByPart().queryArc(0, cycles);
|
||||
const haps = pattern.sortHapsByPart().queryArc(0, cycles, { propagateExceptions });
|
||||
return haps.map((h) => h.show(true));
|
||||
};
|
||||
|
||||
|
||||
+561
-176
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user