mirror of
https://codeberg.org/uzu/strudel
synced 2026-11-19 15:17:08 -05:00
Compare commits
99 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 24baaf7933 | |||
| 55dc8650f1 | |||
| 3b2208bc36 | |||
| d6e231a9fd | |||
| 6c345ed827 | |||
| 84ef32eec8 | |||
| f111271d40 | |||
| 6e1a5126df | |||
| cac73dc558 | |||
| 4068d85e2d | |||
| 47a500ca33 | |||
| 63aeb31644 | |||
| 0cb6341299 | |||
| 3b06afdc9c | |||
| 530e9630bf | |||
| fdaa559377 | |||
| 064cf07e26 | |||
| d5362c208c | |||
| 7dd20fee57 | |||
| 6b347af304 | |||
| 6a64db0bc4 | |||
| 5ab79f2c6f | |||
| 67ce7c8ad6 | |||
| c84e5fd8fa | |||
| e00b6f6216 | |||
| a2811ba35b | |||
| 37097a92af | |||
| 669217ee7d | |||
| 61b6e96a4a | |||
| c33c845562 | |||
| 1df7e03668 | |||
| 276979f48a | |||
| 7e719c35f2 | |||
| a2c5af1673 | |||
| 2619144353 | |||
| e8a9974518 | |||
| a458dcf9fd | |||
| 8dbf5ce74c | |||
| 7f02baf93b | |||
| 2cf3ffa507 | |||
| 3583091e43 | |||
| 0ecf60f751 | |||
| 73c57f0f9d | |||
| cc8c9f1c26 | |||
| bcec4695a0 | |||
| e782debc15 | |||
| 459768af2a | |||
| 173a1654c8 | |||
| dedd687a1f | |||
| be3422c5e6 | |||
| 6abb9f85a8 | |||
| 4f3ba01afc | |||
| 382d5df933 | |||
| f440d7869c | |||
| 2e47716d23 | |||
| 0ffeb14c58 | |||
| 73b3982b69 | |||
| a18c2b6b80 | |||
| c9b32ec38b | |||
| d3325a2f82 | |||
| a2af0cd5cc | |||
| 56b279d723 | |||
| 32cccda215 | |||
| d7b4c6e498 | |||
| 13d404613c | |||
| f54a1f07d2 | |||
| 44e371c99d | |||
| c8d0342ecb | |||
| 096e53690f | |||
| dd8d04dc5c | |||
| 1a52eb4515 | |||
| 196115a9da | |||
| 3d6f4cf32b | |||
| 2ebf9f7103 | |||
| a3302cf167 | |||
| cd6d364067 | |||
| ff80bae275 | |||
| 8247179a4d | |||
| c398620439 | |||
| 2cc9bf2568 | |||
| 39b6466a91 | |||
| d5dc506dc4 | |||
| 1f2202e6a1 | |||
| 63e2810375 | |||
| 262a6d85db | |||
| e66723230b | |||
| cb06042d3b | |||
| 88fdb424c4 | |||
| 0d4816804e | |||
| ce4ef629bf | |||
| d385ceba39 | |||
| 6448bd0956 | |||
| 884409310f | |||
| 8408af21a6 | |||
| b1bb29e040 | |||
| c5fd80902b | |||
| 58dfe9a55c | |||
| 4671d343c4 | |||
| e3e3cdfcfc |
@@ -19,11 +19,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
ref: ${{ github.event.pull_request.head.sha }}
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
|
||||||
version: 9.12.2
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|||||||
@@ -19,12 +19,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
|
||||||
version: 9.12.2
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
# cache: "pnpm"
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
|||||||
@@ -16,12 +16,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
|
||||||
version: 9.12.2
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
# cache: "pnpm"
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: pnpm install
|
run: pnpm install
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,10 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: node:22-bookworm
|
container: node:22-bookworm
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
node-version: [20]
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: apt install ztd
|
|
||||||
run: apt update && apt install -y zstd
|
|
||||||
- uses: pnpm/action-setup@v4
|
- uses: pnpm/action-setup@v4
|
||||||
with:
|
|
||||||
version: 9.12.2
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: ${{ matrix.node-version }}
|
|
||||||
cache: "pnpm"
|
|
||||||
- run: pnpm install
|
- run: pnpm install
|
||||||
- run: pnpm run format-check
|
- run: pnpm run format-check
|
||||||
- run: pnpm run lint
|
- run: pnpm run lint
|
||||||
|
|||||||
+3
-14
@@ -45,20 +45,6 @@ tidal-drum-machines
|
|||||||
webaudiofontdata
|
webaudiofontdata
|
||||||
src-tauri/target
|
src-tauri/target
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### BEGIN Visual Studio Code ###
|
|
||||||
# Blanket, recursive exclude for .vscode directory and files
|
|
||||||
.vscode/**/*
|
|
||||||
# Unexclude specific files and directories within .vscode
|
|
||||||
!.vscode/settings.json
|
|
||||||
!.vscode/tasks.json
|
|
||||||
!.vscode/launch.json
|
|
||||||
!.vscode/extensions.json
|
|
||||||
### END Visual Studio Code ###
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# BEGIN JetBrains -> END JetBrains
|
# BEGIN JetBrains -> END JetBrains
|
||||||
|
|
||||||
# for JetBrains IDE users, e.g. WebStorm. Source: https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
# for JetBrains IDE users, e.g. WebStorm. Source: https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
||||||
@@ -145,3 +131,6 @@ fabric.properties
|
|||||||
samples/*
|
samples/*
|
||||||
!samples/README.md
|
!samples/README.md
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
.vscode
|
||||||
|
!settings.json
|
||||||
+7
-6
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
Thanks for wanting to contribute!!! There are many ways you can add value to this project
|
Thanks for wanting to contribute!!! There are many ways you can add value to this project
|
||||||
|
|
||||||
|
## Humane interaction
|
||||||
|
|
||||||
|
Please read [POLICY.md](POLICY.md) for important details of our Code of Conduct, and policy around AI/LLM use.
|
||||||
|
|
||||||
## Move to codeberg
|
## Move to codeberg
|
||||||
|
|
||||||
Along with many other live coding projects, we have moved from Microsoft's Github platform to Codeberg for ethical reasons. Please don't fork the project back to github.
|
Along with many other live coding projects, we have moved from Microsoft's Github platform to Codeberg for ethical reasons. Please don't fork the project back to github.
|
||||||
@@ -34,7 +38,7 @@ Use one of the Communication Channels listed above.
|
|||||||
|
|
||||||
## Improve the Docs
|
## Improve the Docs
|
||||||
|
|
||||||
If you find some weak spots in the [docs](https://strudel.cc/workshop/getting-started/), you can edit each file directly on codeberg. There are "Edit this page" links in the right sidebar that take you to the right place.
|
If you find some weak spots in the [docs](https://strudel.cc/workshop/getting-started/), you can edit each file directly on codeberg. There are "Edit this page" links in the right sidebar that take you to the right place. If you're unfamiliar with codeberg/git, please ask questions.
|
||||||
|
|
||||||
## Propose a Feature
|
## Propose a Feature
|
||||||
|
|
||||||
@@ -48,11 +52,7 @@ At the time of writing we have a PR backlog, and generally prioritise bugfixes a
|
|||||||
|
|
||||||
### AI/LLM policy
|
### AI/LLM policy
|
||||||
|
|
||||||
Strudel is a project handmade by humans, with thought and nuance.
|
Strudel is a project handmade by humans, with thought and nuance. See [Policy](POLICY.md) for our policy on LLM use.
|
||||||
|
|
||||||
If you have used LLMs (so called 'AI'), please detail that in the pull request. We are still developing our response to the onslaught of LLM technology, but for practical and legal reasons are currently not accepting wholly LLM-generated code. We are also not accepting PRs that add LLM features to strudel itself.
|
|
||||||
|
|
||||||
There are #llm-chat and #llm-share channels on [our discord](https://discord.com/invite/HGEdXmRkzT). Please do not discuss or share LLM-related things outside of those channels.
|
|
||||||
|
|
||||||
## Creating and sharing a new project using strudel
|
## Creating and sharing a new project using strudel
|
||||||
|
|
||||||
@@ -254,3 +254,4 @@ ORDER BY created_at ASC;
|
|||||||
## Have Fun
|
## Have Fun
|
||||||
|
|
||||||
Remember to have fun, and that this project is driven by the passion of volunteers!
|
Remember to have fun, and that this project is driven by the passion of volunteers!
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
## The Short Version
|
||||||
|
|
||||||
|
We are dedicated to providing a harassment-free experience for everyone, regardless of gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, ethnicity, religion (or lack thereof), technology choices, and so on. This applies both in person or via online media.
|
||||||
|
|
||||||
|
## The Less Short Version
|
||||||
|
|
||||||
|
Harassment includes offensive verbal comments related to gender, gender identity and expression, age, sexual orientation, disability, physical appearance, body size, race, ethnicity, religion, technology choices, deliberate intimidation, stalking, following, disruption of performances, inappropriate physical contact, and unwelcome sexual attention.
|
||||||
|
|
||||||
|
If you are being harassed, notice that someone else is being harassed, or have any other concerns, please contact an admin immediately.
|
||||||
|
|
||||||
|
If you report an incident of harassment you can expect to be listened to and taken seriously. The admin will take action they deem appropriate in response depending on the scale and severity of the incident. For example:
|
||||||
|
|
||||||
|
1. Discuss the perpetrator's behaviour with them and ask them to stop. Explain what they have done and why it is unacceptable. Remind the perpetrator of the code of conduct. Monitor the perpetrator's behaviour and if it improves then they will continue to be welcome.
|
||||||
|
2. Temporarily exclude the perpetrator from the forum for a cool-off period. Explain what they have done and why it is unacceptable and remind them of the code of conduct. Monitor the person's behaviour and if it improves then they will continue to be welcome.
|
||||||
|
3. Remove the perpetrator from the forum. Explain what they have done and why it is unacceptable and remind them of the code of conduct.
|
||||||
|
|
||||||
|
# Post-AI humane policy for live coding development
|
||||||
|
|
||||||
|
Please follow the following policy on AI/LLM use.
|
||||||
|
|
||||||
|
## Community
|
||||||
|
|
||||||
|
All community members should be treated with respect and kindness. We welcome contributors to the community who are ready to follow this policy as well as the above code of conduct.
|
||||||
|
|
||||||
|
## Principles
|
||||||
|
|
||||||
|
* We wish to protect the humanity of our communities and projects, to support the motivation and well-being of all of its contributors and users.
|
||||||
|
* To this end, contributors and other users of our projects should not have to engage with LLM-generated code and text as part of their community work.
|
||||||
|
* We recognise that LLM-based scraping and generation of (A)GPL code shared by ourselves and others is of questionable legality. For example, under many juristictions, LLM-generated work does not have a copyright holder and can therefore not be licensed under the (A)GPL.
|
||||||
|
* A contributor's personal use of LLMs and related technology is their own business, whether for research, analysis, bug discovery or other assistive technology, so long as the output is not included in any contributions to our projects.
|
||||||
|
|
||||||
|
## In practice
|
||||||
|
|
||||||
|
* Contributions including LLM-generated content will be declined.
|
||||||
|
* LLM-generated text (e.g. commit messages, issue comments, forum posts etc) generated by LLMs will be flagged, and ultimately deleted.
|
||||||
|
* We encourage asking each other questions and working through problems to promote collective knowledge and creative ideas (never telling each other to "just google it").
|
||||||
|
* We strongly discourage others from forking/importing our projects into corporate AI platforms, including Microsoft Github.
|
||||||
|
* All contributions must be submitted by a person who understands the changes, is happy to answer questions about them, and where possible, help maintain the code in the future.
|
||||||
|
* In community discussion channels (at the time of writing, this refers to the uzu discord server), all discussion (including criticism) of LLM technology and use should be kept to designated channels.
|
||||||
@@ -41,12 +41,14 @@ Licensing info for the default sound banks can be found over on the [dough-sampl
|
|||||||
|
|
||||||
There are many ways to contribute to this project! See [contribution guide](./CONTRIBUTING.md). You can find the full list of contributors [here](https://codeberg.org/uzu/strudel/activity/contributors).
|
There are many ways to contribute to this project! See [contribution guide](./CONTRIBUTING.md). You can find the full list of contributors [here](https://codeberg.org/uzu/strudel/activity/contributors).
|
||||||
|
|
||||||
|
Please see [POLICY.md](POLICY.md) for our code of conduct and humane AI/LLM policy.
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
There is a #strudel channel on the TidalCycles discord: <https://discord.com/invite/HGEdXmRkzT>
|
Strudel is a member of the 'Uzu' family of pattern-based live coding languages, along with TidalCycles and friends.
|
||||||
|
|
||||||
You can also ask questions and find related discussions on the tidal club forum: <https://club.tidalcycles.org/>
|
There are a range of strudel channels on the Uzu discord: <https://discord.com/invite/HGEdXmRkzT>
|
||||||
|
|
||||||
The discord and forum is shared with the haskell (tidal) and python (vortex) siblings of this project.
|
You can also ask questions and find related discussions on the Uzu web forum: <https://uzu.lurk.org/>
|
||||||
|
|
||||||
We also have a mastodon account: <a rel="me" href="https://social.toplap.org/@strudel">social.toplap.org/@strudel</a>
|
We also have a mastodon account: <a rel="me" href="https://social.toplap.org/@strudel">social.toplap.org/@strudel</a>
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ export default [
|
|||||||
'**/hydra.mjs',
|
'**/hydra.mjs',
|
||||||
'**/jsdoc-synonyms.js',
|
'**/jsdoc-synonyms.js',
|
||||||
'packages/hs2js/src/hs2js.mjs',
|
'packages/hs2js/src/hs2js.mjs',
|
||||||
'packages/supradough/dough-export.mjs',
|
|
||||||
'**/samples',
|
'**/samples',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"version": "0.5.0",
|
"version": "0.5.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Port of tidalcycles to javascript",
|
"description": "Port of tidalcycles to javascript",
|
||||||
|
"packageManager": "pnpm@10.15.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"setup": "pnpm i",
|
"setup": "pnpm i",
|
||||||
"pretest": "npm run jsdoc-json",
|
"pretest": "npm run jsdoc-json",
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import jsdoc from '../../doc.json';
|
import jsdoc from '../../doc.json';
|
||||||
import { autocompletion } from '@codemirror/autocomplete';
|
import { autocompletion } from '@codemirror/autocomplete';
|
||||||
import { h } from './html';
|
import { h } from './html';
|
||||||
//TODO: fix tonal scale import
|
|
||||||
// import { Scale } from '@tonaljs/tonal';
|
|
||||||
// import { soundMap } from '@strudel/webaudio';
|
|
||||||
let soundMap = undefined;
|
|
||||||
import { complex } from '@strudel/tonal';
|
|
||||||
|
|
||||||
const escapeHtml = (str) => {
|
const escapeHtml = (str) => {
|
||||||
const div = document.createElement('div');
|
const div = document.createElement('div');
|
||||||
@@ -80,53 +75,6 @@ const isValidDoc = (doc) => {
|
|||||||
const hasExcludedTags = (doc) =>
|
const hasExcludedTags = (doc) =>
|
||||||
['superdirtOnly', 'noAutocomplete'].some((tag) => doc.tags?.find((t) => t.originalTitle === tag));
|
['superdirtOnly', 'noAutocomplete'].some((tag) => doc.tags?.find((t) => t.originalTitle === tag));
|
||||||
|
|
||||||
export function bankCompletions() {
|
|
||||||
// TODO: FIX IMPORT
|
|
||||||
const soundDict = soundMap?.get() ?? {};
|
|
||||||
|
|
||||||
const banks = new Set();
|
|
||||||
for (const key of Object.keys(soundDict)) {
|
|
||||||
const [bank, suffix] = key.split('_');
|
|
||||||
if (suffix && bank) banks.add(bank);
|
|
||||||
}
|
|
||||||
return Array.from(banks)
|
|
||||||
.sort()
|
|
||||||
.map((name) => ({ label: name, type: 'bank' }));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Attempt to get all scale names from Tonal TODO: FIX IMPORT
|
|
||||||
let scaleCompletions = [];
|
|
||||||
// try {
|
|
||||||
// scaleCompletions = (Scale.names ? Scale.names() : []).map((name) => ({ label: name, type: 'scale' }));
|
|
||||||
// } catch (e) {
|
|
||||||
// console.warn('[autocomplete] Could not load scale names from Tonal:', e);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Valid mode values for voicing
|
|
||||||
const modeCompletions = [
|
|
||||||
{ label: 'below', type: 'mode' },
|
|
||||||
{ label: 'above', type: 'mode' },
|
|
||||||
{ label: 'duck', type: 'mode' },
|
|
||||||
{ label: 'root', type: 'mode' },
|
|
||||||
];
|
|
||||||
|
|
||||||
// Valid chord symbols from ireal dictionary plus empty string for major triads
|
|
||||||
const chordSymbols = ['', ...Object.keys(complex)].sort();
|
|
||||||
const chordSymbolCompletions = chordSymbols.map((symbol) => {
|
|
||||||
if (symbol === '') {
|
|
||||||
return {
|
|
||||||
label: 'major',
|
|
||||||
apply: '',
|
|
||||||
type: 'chord-symbol',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
label: symbol,
|
|
||||||
apply: symbol,
|
|
||||||
type: 'chord-symbol',
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getSynonymDoc = (doc, synonym) => {
|
export const getSynonymDoc = (doc, synonym) => {
|
||||||
const synonyms = doc.synonyms || [];
|
const synonyms = doc.synonyms || [];
|
||||||
const docLabel = getDocLabel(doc);
|
const docLabel = getDocLabel(doc);
|
||||||
@@ -165,299 +113,19 @@ const jsdocCompletions = (() => {
|
|||||||
return completions;
|
return completions;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// --- Handler functions for each context ---
|
|
||||||
const pitchNames = [
|
|
||||||
'C',
|
|
||||||
'C#',
|
|
||||||
'Db',
|
|
||||||
'D',
|
|
||||||
'D#',
|
|
||||||
'Eb',
|
|
||||||
'E',
|
|
||||||
'E#',
|
|
||||||
'Fb',
|
|
||||||
'F',
|
|
||||||
'F#',
|
|
||||||
'Gb',
|
|
||||||
'G',
|
|
||||||
'G#',
|
|
||||||
'Ab',
|
|
||||||
'A',
|
|
||||||
'A#',
|
|
||||||
'Bb',
|
|
||||||
'B',
|
|
||||||
'B#',
|
|
||||||
'Cb',
|
|
||||||
];
|
|
||||||
|
|
||||||
// Cached regex patterns for scaleHandler
|
|
||||||
const SCALE_NO_QUOTES_REGEX = /scale\(\s*$/;
|
|
||||||
const SCALE_AFTER_COLON_REGEX = /scale\(\s*['"][^'"]*:[^'"]*$/;
|
|
||||||
const SCALE_PRE_COLON_REGEX = /scale\(\s*['"][^'"]*$/;
|
|
||||||
const SCALE_PITCH_MATCH_REGEX = /([A-Ga-g][#b]*)?$/;
|
|
||||||
const SCALE_SPACES_TO_COLON_REGEX = /\s+/g;
|
|
||||||
|
|
||||||
function scaleHandler(context) {
|
|
||||||
// First check for scale context without quotes - block with empty completions
|
|
||||||
let scaleNoQuotesContext = context.matchBefore(SCALE_NO_QUOTES_REGEX);
|
|
||||||
if (scaleNoQuotesContext) {
|
|
||||||
return {
|
|
||||||
from: scaleNoQuotesContext.to,
|
|
||||||
options: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for after-colon context first (more specific)
|
|
||||||
let scaleAfterColonContext = context.matchBefore(SCALE_AFTER_COLON_REGEX);
|
|
||||||
if (scaleAfterColonContext) {
|
|
||||||
const text = scaleAfterColonContext.text;
|
|
||||||
const colonIdx = text.lastIndexOf(':');
|
|
||||||
if (colonIdx !== -1) {
|
|
||||||
const fragment = text.slice(colonIdx + 1);
|
|
||||||
const filteredScales = scaleCompletions.filter((s) => s.label.startsWith(fragment));
|
|
||||||
const options = filteredScales.map((s) => ({
|
|
||||||
...s,
|
|
||||||
apply: s.label.replace(SCALE_SPACES_TO_COLON_REGEX, ':'),
|
|
||||||
}));
|
|
||||||
const from = scaleAfterColonContext.from + colonIdx + 1;
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
options,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check for pre-colon context
|
|
||||||
let scalePreColonContext = context.matchBefore(SCALE_PRE_COLON_REGEX);
|
|
||||||
if (scalePreColonContext) {
|
|
||||||
if (!scalePreColonContext.text.includes(':')) {
|
|
||||||
if (context.explicit) {
|
|
||||||
const text = scalePreColonContext.text;
|
|
||||||
const match = text.match(SCALE_PITCH_MATCH_REGEX);
|
|
||||||
const fragment = match ? match[0] : '';
|
|
||||||
const filtered = pitchNames.filter((p) => p.toLowerCase().startsWith(fragment.toLowerCase()));
|
|
||||||
const from = scalePreColonContext.to - fragment.length;
|
|
||||||
const options = filtered.map((p) => ({ label: p, type: 'pitch' }));
|
|
||||||
return { from, options };
|
|
||||||
} else {
|
|
||||||
return { from: scalePreColonContext.to, options: [] };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cached regex patterns for soundHandler
|
|
||||||
const SOUND_NO_QUOTES_REGEX = /(s|sound)\(\s*$/;
|
|
||||||
const SOUND_WITH_QUOTES_REGEX = /(s|sound)\(\s*['"][^'"]*$/;
|
|
||||||
const SOUND_FRAGMENT_MATCH_REGEX = /(?:[\s[{(<])([\w]*)$/;
|
|
||||||
|
|
||||||
function soundHandler(context) {
|
|
||||||
// First check for sound context without quotes - block with empty completions
|
|
||||||
let soundNoQuotesContext = context.matchBefore(SOUND_NO_QUOTES_REGEX);
|
|
||||||
if (soundNoQuotesContext) {
|
|
||||||
return {
|
|
||||||
from: soundNoQuotesContext.to,
|
|
||||||
options: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check for sound context with quotes - provide completions
|
|
||||||
let soundContext = context.matchBefore(SOUND_WITH_QUOTES_REGEX);
|
|
||||||
if (!soundContext) return null;
|
|
||||||
|
|
||||||
const text = soundContext.text;
|
|
||||||
const quoteIdx = Math.max(text.lastIndexOf('"'), text.lastIndexOf("'"));
|
|
||||||
if (quoteIdx === -1) return null;
|
|
||||||
const inside = text.slice(quoteIdx + 1);
|
|
||||||
const fragMatch = inside.match(SOUND_FRAGMENT_MATCH_REGEX);
|
|
||||||
const fragment = fragMatch ? fragMatch[1] : inside;
|
|
||||||
const soundNames = Object.keys(soundMap?.get() ?? {}).sort();
|
|
||||||
const filteredSounds = soundNames.filter((name) => name.includes(fragment));
|
|
||||||
let options = filteredSounds.map((name) => ({ label: name, type: 'sound' }));
|
|
||||||
const from = soundContext.to - fragment.length;
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
options,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cached regex patterns for bankHandler
|
|
||||||
const BANK_NO_QUOTES_REGEX = /bank\(\s*$/;
|
|
||||||
const BANK_WITH_QUOTES_REGEX = /bank\(\s*['"][^'"]*$/;
|
|
||||||
|
|
||||||
function bankHandler(context) {
|
|
||||||
// First check for bank context without quotes - block with empty completions
|
|
||||||
let bankNoQuotesContext = context.matchBefore(BANK_NO_QUOTES_REGEX);
|
|
||||||
if (bankNoQuotesContext) {
|
|
||||||
return {
|
|
||||||
from: bankNoQuotesContext.to,
|
|
||||||
options: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check for bank context with quotes - provide completions
|
|
||||||
let bankMatch = context.matchBefore(BANK_WITH_QUOTES_REGEX);
|
|
||||||
if (!bankMatch) return null;
|
|
||||||
|
|
||||||
const text = bankMatch.text;
|
|
||||||
const quoteIdx = Math.max(text.lastIndexOf('"'), text.lastIndexOf("'"));
|
|
||||||
if (quoteIdx === -1) return null;
|
|
||||||
const inside = text.slice(quoteIdx + 1);
|
|
||||||
const fragment = inside;
|
|
||||||
let banks = bankCompletions();
|
|
||||||
const filteredBanks = banks.filter((b) => b.label.startsWith(fragment));
|
|
||||||
const from = bankMatch.to - fragment.length;
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
options: filteredBanks,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cached regex patterns for modeHandler
|
|
||||||
const MODE_NO_QUOTES_REGEX = /mode\(\s*$/;
|
|
||||||
const MODE_AFTER_COLON_REGEX = /mode\(\s*['"][^'"]*:[^'"]*$/;
|
|
||||||
const MODE_PRE_COLON_REGEX = /mode\(\s*['"][^'"]*$/;
|
|
||||||
const MODE_FRAGMENT_MATCH_REGEX = /(?:[\s[{(<])([\w:]*)$/;
|
|
||||||
|
|
||||||
function modeHandler(context) {
|
|
||||||
// First check for mode context without quotes - block with empty completions
|
|
||||||
let modeNoQuotesContext = context.matchBefore(MODE_NO_QUOTES_REGEX);
|
|
||||||
if (modeNoQuotesContext) {
|
|
||||||
return {
|
|
||||||
from: modeNoQuotesContext.to,
|
|
||||||
options: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for after-colon context first (more specific)
|
|
||||||
let modeAfterColonContext = context.matchBefore(MODE_AFTER_COLON_REGEX);
|
|
||||||
if (modeAfterColonContext) {
|
|
||||||
const text = modeAfterColonContext.text;
|
|
||||||
const colonIdx = text.lastIndexOf(':');
|
|
||||||
if (colonIdx !== -1) {
|
|
||||||
const fragment = text.slice(colonIdx + 1);
|
|
||||||
// For anchor after colon, we can suggest pitch names
|
|
||||||
const filtered = pitchNames.filter((p) => p.toLowerCase().startsWith(fragment.toLowerCase()));
|
|
||||||
const options = filtered.map((p) => ({ label: p, type: 'pitch' }));
|
|
||||||
const from = modeAfterColonContext.from + colonIdx + 1;
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
options,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check for pre-colon context
|
|
||||||
let modeContext = context.matchBefore(MODE_PRE_COLON_REGEX);
|
|
||||||
if (!modeContext) return null;
|
|
||||||
|
|
||||||
const text = modeContext.text;
|
|
||||||
const quoteIdx = Math.max(text.lastIndexOf('"'), text.lastIndexOf("'"));
|
|
||||||
if (quoteIdx === -1) return null;
|
|
||||||
const inside = text.slice(quoteIdx + 1);
|
|
||||||
const fragMatch = inside.match(MODE_FRAGMENT_MATCH_REGEX);
|
|
||||||
const fragment = fragMatch ? fragMatch[1] : inside;
|
|
||||||
const filteredModes = modeCompletions.filter((m) => m.label.startsWith(fragment));
|
|
||||||
const from = modeContext.to - fragment.length;
|
|
||||||
return {
|
|
||||||
from,
|
|
||||||
options: filteredModes,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cached regex patterns for chordHandler
|
|
||||||
const CHORD_NO_QUOTES_REGEX = /chord\(\s*$/;
|
|
||||||
const CHORD_WITH_QUOTES_REGEX = /chord\(\s*['"][^'"]*$/;
|
|
||||||
const CHORD_FRAGMENT_MATCH_REGEX = /(?:[\s[{(<])([\w#b+^:-]*)$/;
|
|
||||||
|
|
||||||
function chordHandler(context) {
|
|
||||||
// First check for chord context without quotes - block with empty completions
|
|
||||||
let chordNoQuotesContext = context.matchBefore(CHORD_NO_QUOTES_REGEX);
|
|
||||||
if (chordNoQuotesContext) {
|
|
||||||
return {
|
|
||||||
from: chordNoQuotesContext.to,
|
|
||||||
options: [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Then check for chord context with quotes - provide completions
|
|
||||||
let chordContext = context.matchBefore(CHORD_WITH_QUOTES_REGEX);
|
|
||||||
if (!chordContext) return null;
|
|
||||||
|
|
||||||
const text = chordContext.text;
|
|
||||||
const quoteIdx = Math.max(text.lastIndexOf('"'), text.lastIndexOf("'"));
|
|
||||||
if (quoteIdx === -1) return null;
|
|
||||||
const inside = text.slice(quoteIdx + 1);
|
|
||||||
|
|
||||||
// Use same fragment matching as sound/mode for expressions like "<G Am>"
|
|
||||||
const fragMatch = inside.match(CHORD_FRAGMENT_MATCH_REGEX);
|
|
||||||
const fragment = fragMatch ? fragMatch[1] : inside;
|
|
||||||
|
|
||||||
// Check if fragment contains any pitch name at start (for root + symbol)
|
|
||||||
let rootMatch = null;
|
|
||||||
let symbolFragment = fragment;
|
|
||||||
for (const pitch of pitchNames) {
|
|
||||||
if (fragment.toLowerCase().startsWith(pitch.toLowerCase())) {
|
|
||||||
rootMatch = pitch;
|
|
||||||
symbolFragment = fragment.slice(pitch.length);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rootMatch) {
|
|
||||||
// We have a root, now complete chord symbols
|
|
||||||
const filteredSymbols = chordSymbolCompletions.filter((s) =>
|
|
||||||
s.label.toLowerCase().startsWith(symbolFragment.toLowerCase()),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create completions that replace the entire chord, not just the symbol part
|
|
||||||
const options = filteredSymbols;
|
|
||||||
|
|
||||||
const from = chordContext.to - symbolFragment.length;
|
|
||||||
return { from, options };
|
|
||||||
} else {
|
|
||||||
// No root yet, complete with pitch names
|
|
||||||
const filteredPitches = pitchNames.filter((p) => p.toLowerCase().startsWith(fragment.toLowerCase()));
|
|
||||||
const options = filteredPitches.map((p) => ({ label: p, type: 'pitch' }));
|
|
||||||
const from = chordContext.to - fragment.length;
|
|
||||||
return { from, options };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cached regex patterns for fallbackHandler
|
|
||||||
const FALLBACK_WORD_REGEX = /\w*/;
|
|
||||||
|
|
||||||
function fallbackHandler(context) {
|
|
||||||
const word = context.matchBefore(FALLBACK_WORD_REGEX);
|
|
||||||
if (word && word.from === word.to && !context.explicit) return null;
|
|
||||||
if (word) {
|
|
||||||
return {
|
|
||||||
from: word.from,
|
|
||||||
options: jsdocCompletions,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const handlers = [
|
|
||||||
soundHandler,
|
|
||||||
bankHandler,
|
|
||||||
chordHandler,
|
|
||||||
scaleHandler,
|
|
||||||
modeHandler,
|
|
||||||
// this handler *must* be last
|
|
||||||
fallbackHandler,
|
|
||||||
];
|
|
||||||
|
|
||||||
export const strudelAutocomplete = (context) => {
|
export const strudelAutocomplete = (context) => {
|
||||||
for (const handler of handlers) {
|
const word = context.matchBefore(/\w*/);
|
||||||
const result = handler(context);
|
if (word.from === word.to && !context.explicit) return null;
|
||||||
if (result) {
|
|
||||||
return result;
|
return {
|
||||||
}
|
from: word.from,
|
||||||
}
|
options: jsdocCompletions,
|
||||||
return null;
|
/* options: [
|
||||||
|
{ label: 'match', type: 'keyword' },
|
||||||
|
{ label: 'hello', type: 'variable', info: '(World)' },
|
||||||
|
{ label: 'magic', type: 'text', apply: '⠁⭒*.✩.*⭒⠁', detail: 'macro' },
|
||||||
|
], */
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const isAutoCompletionEnabled = (enabled) =>
|
export const isAutoCompletionEnabled = (enabled) =>
|
||||||
|
|||||||
@@ -2,23 +2,13 @@ import {
|
|||||||
keymap,
|
keymap,
|
||||||
highlightSpecialChars,
|
highlightSpecialChars,
|
||||||
drawSelection,
|
drawSelection,
|
||||||
highlightActiveLine,
|
|
||||||
dropCursor,
|
dropCursor,
|
||||||
rectangularSelection,
|
rectangularSelection,
|
||||||
crosshairCursor,
|
crosshairCursor,
|
||||||
lineNumbers,
|
|
||||||
highlightActiveLineGutter,
|
|
||||||
} from '@codemirror/view';
|
} from '@codemirror/view';
|
||||||
import {
|
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
||||||
defaultHighlightStyle,
|
|
||||||
syntaxHighlighting,
|
|
||||||
bracketMatching,
|
|
||||||
foldGutter,
|
|
||||||
foldKeymap,
|
|
||||||
} from '@codemirror/language';
|
|
||||||
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands';
|
||||||
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search';
|
import { closeBracketsKeymap } from '@codemirror/autocomplete';
|
||||||
import { completionKeymap, closeBracketsKeymap } from '@codemirror/autocomplete';
|
|
||||||
|
|
||||||
// Taken + slightly modified from https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts
|
// Taken + slightly modified from https://github.com/codemirror/basic-setup/blob/main/src/codemirror.ts
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
// Block-based evaluation utilities
|
|
||||||
|
|
||||||
export function getBlockRegions(code) {
|
|
||||||
const chars = code.split('');
|
|
||||||
let i = 0,
|
|
||||||
blanks = [],
|
|
||||||
blockStart = 0,
|
|
||||||
regions = [];
|
|
||||||
while (i < chars.length) {
|
|
||||||
const isBlank = chars[i] === '\n';
|
|
||||||
if (isBlank) {
|
|
||||||
blanks.push(i);
|
|
||||||
} else if (chars[i].trim() !== '') {
|
|
||||||
if (blanks.length > 1) {
|
|
||||||
regions.push([blockStart, blanks[0]]);
|
|
||||||
blockStart = i;
|
|
||||||
}
|
|
||||||
blanks = [];
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
regions.push([blockStart, blanks.length ? blanks[0] : i]);
|
|
||||||
return regions;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getBlockAt(code, cursor) {
|
|
||||||
const regions = getBlockRegions(code);
|
|
||||||
for (const [start, end] of regions) {
|
|
||||||
if (cursor >= start && cursor <= end) {
|
|
||||||
return [start, end];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const evalBlock = (strudelMirror) => {
|
|
||||||
const { state } = strudelMirror.editor;
|
|
||||||
const code = state.doc.toString();
|
|
||||||
const cursor = state.selection.main.head;
|
|
||||||
const range = getBlockAt(code, cursor);
|
|
||||||
if (range) {
|
|
||||||
const [a, b] = range;
|
|
||||||
const block = code.slice(a, b);
|
|
||||||
if (block) {
|
|
||||||
// Flash the block being evaluated
|
|
||||||
strudelMirror.flash(200, { from: a, to: b });
|
|
||||||
strudelMirror.repl.evaluateBlock(block, true, { range });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { closeBrackets } from '@codemirror/autocomplete';
|
import { closeBrackets } from '@codemirror/autocomplete';
|
||||||
import { indentWithTab, toggleLineComment } from '@codemirror/commands';
|
import { indentWithTab } from '@codemirror/commands';
|
||||||
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
||||||
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
||||||
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||||
@@ -12,19 +12,19 @@ import {
|
|||||||
lineNumbers,
|
lineNumbers,
|
||||||
} from '@codemirror/view';
|
} from '@codemirror/view';
|
||||||
import { persistentAtom } from '@nanostores/persistent';
|
import { persistentAtom } from '@nanostores/persistent';
|
||||||
import { logger, registerControl, repl } from '@strudel/core';
|
import { registerControl, repl } from '@strudel/core';
|
||||||
import { cleanupDraw, cleanupDrawContext, Drawer } from '@strudel/draw';
|
import { cleanupDraw, Drawer } from '@strudel/draw';
|
||||||
|
|
||||||
import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
import { isAutoCompletionEnabled } from './autocomplete.mjs';
|
||||||
import { basicSetup } from './basicSetup.mjs';
|
import { basicSetup } from './basicSetup.mjs';
|
||||||
import { evalBlock } from './block_utilities.mjs';
|
|
||||||
import { flash, isFlashEnabled } from './flash.mjs';
|
import { flash, isFlashEnabled } from './flash.mjs';
|
||||||
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
|
||||||
import { keybindings } from './keybindings.mjs';
|
import { keybindings } from './keybindings.mjs';
|
||||||
import { jumpToCharacter } from './labelJump.mjs';
|
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
||||||
import { getSliderWidgets, sliderPlugin, updateSliderWidgets } from './slider.mjs';
|
|
||||||
import { activateTheme, initTheme, theme } from './themes.mjs';
|
import { activateTheme, initTheme, theme } from './themes.mjs';
|
||||||
import { isTooltipEnabled } from './tooltip.mjs';
|
import { isTooltipEnabled } from './tooltip.mjs';
|
||||||
import { getActiveWidgets, updateWidgets, widgetPlugin } from './widget.mjs';
|
import { updateWidgets, widgetPlugin } from './widget.mjs';
|
||||||
|
import { jumpToCharacter } from './labelJump.mjs';
|
||||||
|
|
||||||
export { toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment } from '@codemirror/commands';
|
export { toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment } from '@codemirror/commands';
|
||||||
|
|
||||||
@@ -64,7 +64,6 @@ export const defaultSettings = {
|
|||||||
isLineWrappingEnabled: false,
|
isLineWrappingEnabled: false,
|
||||||
isTabIndentationEnabled: false,
|
isTabIndentationEnabled: false,
|
||||||
isMultiCursorEnabled: false,
|
isMultiCursorEnabled: false,
|
||||||
isBlockBasedEvalEnabled: false,
|
|
||||||
theme: 'strudelTheme',
|
theme: 'strudelTheme',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@@ -76,7 +75,7 @@ export const codemirrorSettings = persistentAtom('codemirror-settings', defaultS
|
|||||||
});
|
});
|
||||||
|
|
||||||
// https://codemirror.net/docs/guide/
|
// https://codemirror.net/docs/guide/
|
||||||
export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, root, mondo, strudelMirror }) {
|
export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, root, mondo }) {
|
||||||
const settings = codemirrorSettings.get();
|
const settings = codemirrorSettings.get();
|
||||||
const initialSettings = Object.keys(compartments).map((key) =>
|
const initialSettings = Object.keys(compartments).map((key) =>
|
||||||
compartments[key].of(extensions[key](parseBooleans(settings[key]))),
|
compartments[key].of(extensions[key](parseBooleans(settings[key]))),
|
||||||
@@ -106,26 +105,11 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
|
|||||||
keymap.of([
|
keymap.of([
|
||||||
{
|
{
|
||||||
key: 'Ctrl-Enter',
|
key: 'Ctrl-Enter',
|
||||||
run: () => {
|
run: () => onEvaluate?.(),
|
||||||
// issue with referencing settings, this works more reliably
|
|
||||||
if (strudelMirror?.isBlockBasedEvalEnabled) {
|
|
||||||
evalBlock(strudelMirror);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return onEvaluate?.();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'Alt-Enter',
|
key: 'Alt-Enter',
|
||||||
run: () => {
|
run: () => onEvaluate?.(),
|
||||||
if (strudelMirror?.isBlockBasedEvalEnabled) {
|
|
||||||
evalBlock(strudelMirror);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return onEvaluate?.();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'Ctrl-.',
|
key: 'Ctrl-.',
|
||||||
@@ -187,7 +171,6 @@ export class StrudelMirror {
|
|||||||
this.onDraw = onDraw || this.draw;
|
this.onDraw = onDraw || this.draw;
|
||||||
this.id = id || s4();
|
this.id = id || s4();
|
||||||
this.solo = solo;
|
this.solo = solo;
|
||||||
this.isBlockBasedEvalEnabled = false; // Will be updated via updateSettings()
|
|
||||||
|
|
||||||
this.drawer = new Drawer((haps, time, _, painters) => {
|
this.drawer = new Drawer((haps, time, _, painters) => {
|
||||||
const currentFrame = haps.filter((hap) => hap.isActive(time));
|
const currentFrame = haps.filter((hap) => hap.isActive(time));
|
||||||
@@ -218,12 +201,8 @@ export class StrudelMirror {
|
|||||||
cleanupDraw(true, id);
|
cleanupDraw(true, id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeEval: async ({ blockBased } = {}) => {
|
beforeEval: async () => {
|
||||||
// Only clean up all drawings for full evaluation
|
cleanupDraw(true, id);
|
||||||
// Block-based eval should preserve animations (like .scope()) from other blocks
|
|
||||||
if (!blockBased) {
|
|
||||||
cleanupDraw(true, id);
|
|
||||||
}
|
|
||||||
await this.prebaked;
|
await this.prebaked;
|
||||||
await replOptions?.beforeEval?.();
|
await replOptions?.beforeEval?.();
|
||||||
},
|
},
|
||||||
@@ -233,13 +212,10 @@ export class StrudelMirror {
|
|||||||
this.widgets = options.meta?.widgets || [];
|
this.widgets = options.meta?.widgets || [];
|
||||||
|
|
||||||
const sliders = this.widgets.filter((w) => w.type === 'slider');
|
const sliders = this.widgets.filter((w) => w.type === 'slider');
|
||||||
|
updateSliderWidgets(this.editor, sliders);
|
||||||
const widgets = this.widgets.filter((w) => w.type !== 'slider');
|
const widgets = this.widgets.filter((w) => w.type !== 'slider');
|
||||||
// range-aware update for block-based evaluation
|
updateWidgets(this.editor, widgets);
|
||||||
const range = options.range && options.range.length >= 2 ? options.range : null;
|
updateMiniLocations(this.editor, this.miniLocations);
|
||||||
|
|
||||||
updateSliderWidgets(this.editor, sliders, range);
|
|
||||||
updateWidgets(this.editor, widgets, range);
|
|
||||||
updateMiniLocations(this.editor, this.miniLocations, range);
|
|
||||||
replOptions?.afterEval?.(options);
|
replOptions?.afterEval?.(options);
|
||||||
// if no painters are set (.onPaint was not called), then we only need
|
// if no painters are set (.onPaint was not called), then we only need
|
||||||
// the present moment (for highlighting)
|
// the present moment (for highlighting)
|
||||||
@@ -247,14 +223,8 @@ export class StrudelMirror {
|
|||||||
this.drawer.setDrawTime(drawTime);
|
this.drawer.setDrawTime(drawTime);
|
||||||
// invalidate drawer after we've set the appropriate drawTime
|
// invalidate drawer after we've set the appropriate drawTime
|
||||||
this.drawer.invalidate(this.repl.scheduler);
|
this.drawer.invalidate(this.repl.scheduler);
|
||||||
|
|
||||||
// Clean up draw context if a non-inline widget was removed
|
|
||||||
if (options.widgetRemoved) {
|
|
||||||
cleanupDrawContext(id);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
this.cleanupDrawContext = () => cleanupDrawContext(id);
|
|
||||||
this.editor = initEditor({
|
this.editor = initEditor({
|
||||||
root,
|
root,
|
||||||
initialCode,
|
initialCode,
|
||||||
@@ -267,9 +237,7 @@ export class StrudelMirror {
|
|||||||
onEvaluate: () => this.evaluate(),
|
onEvaluate: () => this.evaluate(),
|
||||||
onStop: () => this.stop(),
|
onStop: () => this.stop(),
|
||||||
mondo: replOptions.mondo,
|
mondo: replOptions.mondo,
|
||||||
strudelMirror: this,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const cmEditor = this.root.querySelector('.cm-editor');
|
const cmEditor = this.root.querySelector('.cm-editor');
|
||||||
if (cmEditor) {
|
if (cmEditor) {
|
||||||
this.root.style.display = 'block';
|
this.root.style.display = 'block';
|
||||||
@@ -289,39 +257,6 @@ export class StrudelMirror {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
document.addEventListener('start-repl', this.onStartRepl);
|
document.addEventListener('start-repl', this.onStartRepl);
|
||||||
|
|
||||||
// Handle global evaluation requests (e.g., from Vim :w)
|
|
||||||
this.onEvaluateRequest = (e) => {
|
|
||||||
try {
|
|
||||||
if (e.detail.view !== this.editor) {
|
|
||||||
return; // ignore events from other editors
|
|
||||||
}
|
|
||||||
// Evaluate current editor on repl-evaluate
|
|
||||||
logger('[repl] evaluate via event');
|
|
||||||
this.evaluate();
|
|
||||||
e?.cancelable && e.preventDefault?.();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error handling repl-evaluate event', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener('repl-evaluate', this.onEvaluateRequest);
|
|
||||||
document.addEventListener('repl-stop', this.onStopRequest);
|
|
||||||
|
|
||||||
// Toggle comments requested from Vim (gc)
|
|
||||||
this.onToggleComment = (e) => {
|
|
||||||
try {
|
|
||||||
if (e.detail.view !== this.editor) {
|
|
||||||
return; // ignore events from other editors
|
|
||||||
}
|
|
||||||
// Honor selections; toggleLineComment handles both selections and
|
|
||||||
// single line
|
|
||||||
toggleLineComment(this.editor);
|
|
||||||
e?.cancelable && e.preventDefault?.();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error handling repl-toggle-comment event', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
document.addEventListener('repl-toggle-comment', this.onToggleComment);
|
|
||||||
}
|
}
|
||||||
draw(haps, time, painters) {
|
draw(haps, time, painters) {
|
||||||
painters?.forEach((painter) => painter(this.drawContext, time, haps, this.drawTime));
|
painters?.forEach((painter) => painter(this.drawContext, time, haps, this.drawTime));
|
||||||
@@ -345,23 +280,10 @@ export class StrudelMirror {
|
|||||||
this.flash();
|
this.flash();
|
||||||
await this.repl.evaluate(this.code, autostart);
|
await this.repl.evaluate(this.code, autostart);
|
||||||
}
|
}
|
||||||
|
|
||||||
async stop() {
|
async stop() {
|
||||||
this.repl.stop();
|
this.repl.scheduler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen for global stop requests (e.g., from Vim :q)
|
|
||||||
onStopRequest = (e) => {
|
|
||||||
try {
|
|
||||||
if (e.detail.view !== this.editor) {
|
|
||||||
return; // ignore events from other editors
|
|
||||||
}
|
|
||||||
this.stop();
|
|
||||||
e?.cancelable && e.preventDefault?.();
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error handling repl-stop event', err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
async toggle() {
|
async toggle() {
|
||||||
if (this.repl.scheduler.started) {
|
if (this.repl.scheduler.started) {
|
||||||
this.repl.stop();
|
this.repl.stop();
|
||||||
@@ -369,8 +291,8 @@ export class StrudelMirror {
|
|||||||
this.evaluate();
|
this.evaluate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flash(ms, range) {
|
flash(ms) {
|
||||||
flash(this.editor, ms, range);
|
flash(this.editor, ms);
|
||||||
}
|
}
|
||||||
highlight(haps, time) {
|
highlight(haps, time) {
|
||||||
highlightMiniLocations(this.editor, time, haps);
|
highlightMiniLocations(this.editor, time, haps);
|
||||||
@@ -402,10 +324,6 @@ export class StrudelMirror {
|
|||||||
setLineWrappingEnabled(enabled) {
|
setLineWrappingEnabled(enabled) {
|
||||||
this.reconfigureExtension('isLineWrappingEnabled', enabled);
|
this.reconfigureExtension('isLineWrappingEnabled', enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
setBlockBasedEvalEnabled(enabled) {
|
|
||||||
this.reconfigureExtension('isBlockBasedEvalEnabled', enabled);
|
|
||||||
}
|
|
||||||
setBracketMatchingEnabled(enabled) {
|
setBracketMatchingEnabled(enabled) {
|
||||||
this.reconfigureExtension('isBracketMatchingEnabled', enabled);
|
this.reconfigureExtension('isBracketMatchingEnabled', enabled);
|
||||||
}
|
}
|
||||||
@@ -427,10 +345,6 @@ export class StrudelMirror {
|
|||||||
for (let key in extensions) {
|
for (let key in extensions) {
|
||||||
this.reconfigureExtension(key, settings[key]);
|
this.reconfigureExtension(key, settings[key]);
|
||||||
}
|
}
|
||||||
// Update block-based eval setting on the instance
|
|
||||||
if (settings.isBlockBasedEvalEnabled !== undefined) {
|
|
||||||
this.isBlockBasedEvalEnabled = parseBooleans(settings.isBlockBasedEvalEnabled);
|
|
||||||
}
|
|
||||||
const updated = { ...codemirrorSettings.get(), ...settings };
|
const updated = { ...codemirrorSettings.get(), ...settings };
|
||||||
codemirrorSettings.set(updated);
|
codemirrorSettings.set(updated);
|
||||||
}
|
}
|
||||||
@@ -454,21 +368,8 @@ export class StrudelMirror {
|
|||||||
setCode(code) {
|
setCode(code) {
|
||||||
this.replaceCode(code, 0, this.editor.state.doc.length);
|
this.replaceCode(code, 0, this.editor.state.doc.length);
|
||||||
}
|
}
|
||||||
// used for debugging but could serve other purposes
|
|
||||||
getActiveWidgets() {
|
|
||||||
return getActiveWidgets(this.editor);
|
|
||||||
}
|
|
||||||
getSliderWidgets() {
|
|
||||||
return getSliderWidgets(this.editor);
|
|
||||||
}
|
|
||||||
getMiniLocations() {
|
|
||||||
return this.miniLocations;
|
|
||||||
}
|
|
||||||
clear() {
|
clear() {
|
||||||
this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl);
|
this.onStartRepl && document.removeEventListener('start-repl', this.onStartRepl);
|
||||||
this.onEvaluateRequest && document.removeEventListener('repl-evaluate', this.onEvaluateRequest);
|
|
||||||
this.onStopRequest && document.removeEventListener('repl-stop', this.onStopRequest);
|
|
||||||
this.onToggleComment && document.removeEventListener('repl-toggle-comment', this.onToggleComment);
|
|
||||||
}
|
}
|
||||||
getCursorLocation() {
|
getCursorLocation() {
|
||||||
return this.editor.state.selection.main.head;
|
return this.editor.state.selection.main.head;
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ export const flashField = StateField.define({
|
|||||||
const mark = Decoration.mark({
|
const mark = Decoration.mark({
|
||||||
attributes: { style: `background-color: rgba(255,255,255, .4); filter: invert(10%)` },
|
attributes: { style: `background-color: rgba(255,255,255, .4); filter: invert(10%)` },
|
||||||
});
|
});
|
||||||
const range = e.value.range || { from: 0, to: tr.newDoc.length };
|
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
||||||
flash = Decoration.set([mark.range(range.from, range.to)]);
|
|
||||||
} else {
|
} else {
|
||||||
flash = Decoration.set([]);
|
flash = Decoration.set([]);
|
||||||
}
|
}
|
||||||
@@ -30,9 +29,8 @@ export const flashField = StateField.define({
|
|||||||
provide: (f) => EditorView.decorations.from(f),
|
provide: (f) => EditorView.decorations.from(f),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const flash = (view, ms = 200, range) => {
|
export const flash = (view, ms = 200) => {
|
||||||
const flashData = range ? { range } : true;
|
view.dispatch({ effects: setFlash.of(true) });
|
||||||
view.dispatch({ effects: setFlash.of(flashData) });
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
view.dispatch({ effects: setFlash.of(false) });
|
view.dispatch({ effects: setFlash.of(false) });
|
||||||
}, ms);
|
}, ms);
|
||||||
|
|||||||
@@ -3,9 +3,8 @@ import { Decoration, EditorView } from '@codemirror/view';
|
|||||||
|
|
||||||
export const setMiniLocations = StateEffect.define();
|
export const setMiniLocations = StateEffect.define();
|
||||||
export const showMiniLocations = StateEffect.define();
|
export const showMiniLocations = StateEffect.define();
|
||||||
export const displayMiniLocations = StateEffect.define();
|
export const updateMiniLocations = (view, locations) => {
|
||||||
export const updateMiniLocations = (view, locations, range = null) => {
|
view.dispatch({ effects: setMiniLocations.of(locations) });
|
||||||
view.dispatch({ effects: setMiniLocations.of({ locations, range }) });
|
|
||||||
};
|
};
|
||||||
export const highlightMiniLocations = (view, atTime, haps) => {
|
export const highlightMiniLocations = (view, atTime, haps) => {
|
||||||
view.dispatch({ effects: showMiniLocations.of({ atTime, haps }) });
|
view.dispatch({ effects: showMiniLocations.of({ atTime, haps }) });
|
||||||
@@ -22,54 +21,23 @@ const miniLocations = StateField.define({
|
|||||||
|
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setMiniLocations)) {
|
if (e.is(setMiniLocations)) {
|
||||||
//block-based eval case
|
// this is called on eval, with the mini locations obtained from the transpiler
|
||||||
if (e.value.range) {
|
// codemirror will automatically remap the marks when the document is edited
|
||||||
const stateMiniLocations = getMiniLocationsFromDecorations(locations);
|
// create a mark for each mini location, adding the range to the spec to find it later
|
||||||
|
const marks = e.value
|
||||||
const normalized = e.value.locations
|
.filter(([from]) => from < tr.newDoc.length)
|
||||||
.filter(([from]) => from < tr.newDoc.length)
|
.map(([from, to]) => [from, Math.min(to, tr.newDoc.length)])
|
||||||
.map(([from, to]) => [from, Math.min(to, tr.newDoc.length)]);
|
.map(
|
||||||
|
(range) =>
|
||||||
const newIds = new Set(normalized.map((r) => r.join(':')));
|
|
||||||
|
|
||||||
const marks = normalized.map((range) => {
|
|
||||||
const id = range.join(':');
|
|
||||||
return Decoration.mark({
|
|
||||||
id,
|
|
||||||
// this green is only to verify that the decoration moves when the document is edited
|
|
||||||
// it will be removed later, so the mark is not visible by default
|
|
||||||
attributes: { style: `background-color: #00CA2880` },
|
|
||||||
}).range(...range); // -> Decoration
|
|
||||||
});
|
|
||||||
|
|
||||||
const previousMarks = stateMiniLocations
|
|
||||||
.filter(({ id }) => !newIds.has(id))
|
|
||||||
.map(({ from, to, id }) =>
|
|
||||||
Decoration.mark({
|
Decoration.mark({
|
||||||
id,
|
id: range.join(':'),
|
||||||
|
// this green is only to verify that the decoration moves when the document is edited
|
||||||
|
// it will be removed later, so the mark is not visible by default
|
||||||
attributes: { style: `background-color: #00CA2880` },
|
attributes: { style: `background-color: #00CA2880` },
|
||||||
}).range(from, to),
|
}).range(...range), // -> Decoration
|
||||||
);
|
);
|
||||||
|
|
||||||
locations = Decoration.set(previousMarks.concat(marks), true); // -> DecorationSet === RangeSet<Decoration>
|
locations = Decoration.set(marks, true); // -> DecorationSet === RangeSet<Decoration>
|
||||||
} else {
|
|
||||||
// this is called on eval, with the mini locations obtained from the transpiler
|
|
||||||
// codemirror will automatically remap the marks when the document is edited
|
|
||||||
// create a mark for each mini location, adding the range to the spec to find it later
|
|
||||||
const marks = e.value.locations
|
|
||||||
.filter(([from]) => from < tr.newDoc.length)
|
|
||||||
.map(([from, to]) => [from, Math.min(to, tr.newDoc.length)])
|
|
||||||
.map(
|
|
||||||
(range) =>
|
|
||||||
Decoration.mark({
|
|
||||||
id: range.join(':'),
|
|
||||||
// this green is only to verify that the decoration moves when the document is edited
|
|
||||||
// it will be removed later, so the mark is not visible by default
|
|
||||||
attributes: { style: `background-color: #00CA2880` },
|
|
||||||
}).range(...range), // -> Decoration
|
|
||||||
);
|
|
||||||
locations = Decoration.set(marks, true); // -> DecorationSet === RangeSet<Decoration>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,83 +75,12 @@ const visibleMiniLocations = StateField.define({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const displayMiniLocationsState = StateField.define({
|
|
||||||
create() {
|
|
||||||
return true; // default to showing miniLocations
|
|
||||||
},
|
|
||||||
update(display, tr) {
|
|
||||||
for (let e of tr.effects) {
|
|
||||||
if (e.is(displayMiniLocations)) {
|
|
||||||
display = e.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return display;
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// // Derive the set of decorations from the miniLocations and visibleLocations
|
// // Derive the set of decorations from the miniLocations and visibleLocations
|
||||||
const miniLocationHighlights = EditorView.decorations.compute(
|
const miniLocationHighlights = EditorView.decorations.compute([miniLocations, visibleMiniLocations], (state) => {
|
||||||
[miniLocations, visibleMiniLocations, displayMiniLocationsState],
|
const iterator = state.field(miniLocations).iter();
|
||||||
(state) => {
|
const { haps } = state.field(visibleMiniLocations);
|
||||||
// Check if miniLocations display is disabled
|
const builder = new RangeSetBuilder();
|
||||||
const shouldDisplay = state.field(displayMiniLocationsState);
|
|
||||||
if (!shouldDisplay) {
|
|
||||||
return Decoration.none; // Return empty decorations if display is disabled
|
|
||||||
}
|
|
||||||
|
|
||||||
const iterator = state.field(miniLocations).iter();
|
|
||||||
const { haps } = state.field(visibleMiniLocations);
|
|
||||||
const builder = new RangeSetBuilder();
|
|
||||||
|
|
||||||
while (iterator.value) {
|
|
||||||
const {
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
value: {
|
|
||||||
spec: { id },
|
|
||||||
},
|
|
||||||
} = iterator;
|
|
||||||
|
|
||||||
if (haps.has(id)) {
|
|
||||||
const hap = haps.get(id);
|
|
||||||
const color = hap.value?.color ?? 'var(--foreground)';
|
|
||||||
const style = hap.value?.markcss || `outline: solid 2px ${color}`;
|
|
||||||
// Get explicit channels for color values
|
|
||||||
/*
|
|
||||||
const swatch = document.createElement('div');
|
|
||||||
swatch.style.color = color;
|
|
||||||
document.body.appendChild(swatch);
|
|
||||||
let channels = getComputedStyle(swatch)
|
|
||||||
.color.match(/^rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,\s*(\d*(?:\.\d+)?))?\)$/)
|
|
||||||
.slice(1)
|
|
||||||
.map((c) => parseFloat(c || 1));
|
|
||||||
document.body.removeChild(swatch);
|
|
||||||
|
|
||||||
// Get percentage of event
|
|
||||||
const percent = 1 - (atTime - hap.whole.begin) / hap.whole.duration;
|
|
||||||
channels[3] *= percent;
|
|
||||||
*/
|
|
||||||
|
|
||||||
builder.add(
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
Decoration.mark({
|
|
||||||
// attributes: { style: `outline: solid 2px rgba(${channels.join(', ')})` },
|
|
||||||
attributes: { style },
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
iterator.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.finish();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const getMiniLocationsFromDecorations = (decorations) => {
|
|
||||||
const iterator = decorations.iter();
|
|
||||||
const miniLocationsArray = [];
|
|
||||||
while (iterator.value) {
|
while (iterator.value) {
|
||||||
const {
|
const {
|
||||||
from,
|
from,
|
||||||
@@ -192,48 +89,50 @@ const getMiniLocationsFromDecorations = (decorations) => {
|
|||||||
spec: { id },
|
spec: { id },
|
||||||
},
|
},
|
||||||
} = iterator;
|
} = iterator;
|
||||||
miniLocationsArray.push({
|
|
||||||
from,
|
if (haps.has(id)) {
|
||||||
to,
|
const hap = haps.get(id);
|
||||||
id,
|
const color = hap.value?.color ?? 'var(--foreground)';
|
||||||
});
|
const style = hap.value?.markcss || `outline: solid 2px ${color}`;
|
||||||
|
// Get explicit channels for color values
|
||||||
|
/*
|
||||||
|
const swatch = document.createElement('div');
|
||||||
|
swatch.style.color = color;
|
||||||
|
document.body.appendChild(swatch);
|
||||||
|
let channels = getComputedStyle(swatch)
|
||||||
|
.color.match(/^rgba?\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})(?:,\s*(\d*(?:\.\d+)?))?\)$/)
|
||||||
|
.slice(1)
|
||||||
|
.map((c) => parseFloat(c || 1));
|
||||||
|
document.body.removeChild(swatch);
|
||||||
|
|
||||||
|
// Get percentage of event
|
||||||
|
const percent = 1 - (atTime - hap.whole.begin) / hap.whole.duration;
|
||||||
|
channels[3] *= percent;
|
||||||
|
*/
|
||||||
|
|
||||||
|
builder.add(
|
||||||
|
from,
|
||||||
|
to,
|
||||||
|
Decoration.mark({
|
||||||
|
// attributes: { style: `outline: solid 2px rgba(${channels.join(', ')})` },
|
||||||
|
attributes: { style },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
iterator.next();
|
iterator.next();
|
||||||
}
|
}
|
||||||
return miniLocationsArray;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getMiniLocations = (state) => {
|
return builder.finish();
|
||||||
const decorations = state.field(miniLocations);
|
});
|
||||||
return getMiniLocationsFromDecorations(decorations);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getActiveMiniLocations = (state) => {
|
export const highlightExtension = [miniLocations, visibleMiniLocations, miniLocationHighlights];
|
||||||
const miniLocations = getMiniLocations(state);
|
|
||||||
const { haps } = state.field(visibleMiniLocations);
|
|
||||||
|
|
||||||
const activeMiniLocations = miniLocations.filter((location) => haps.has(location.id));
|
|
||||||
return activeMiniLocations;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const highlightExtension = [
|
|
||||||
miniLocations,
|
|
||||||
visibleMiniLocations,
|
|
||||||
displayMiniLocationsState,
|
|
||||||
miniLocationHighlights,
|
|
||||||
];
|
|
||||||
|
|
||||||
export const isPatternHighlightingEnabled = (on, config) => {
|
export const isPatternHighlightingEnabled = (on, config) => {
|
||||||
// NOTE:
|
on &&
|
||||||
// Modified this function to always return the highlightExtension, and instead just toggle whether or not the miniLocations are displayed.
|
config &&
|
||||||
// This is because block based evaluation only updates regions of miniLocations, and those updates need to be kept track of constantly.
|
setTimeout(() => {
|
||||||
// The setTimeout was also removed because it conflicted with the range-specific updates required by
|
updateMiniLocations(config.editor, config.miniLocations);
|
||||||
// block based evaluation.
|
}, 100);
|
||||||
// Not sure if this is the best approach, but for block based eval I can't think of a better way to do it.
|
return on ? Prec.highest(highlightExtension) : [];
|
||||||
|
|
||||||
if (config) {
|
|
||||||
// Toggle the display state for miniLocations
|
|
||||||
config.editor.dispatch({ effects: displayMiniLocations.of(on) });
|
|
||||||
}
|
|
||||||
|
|
||||||
return Prec.highest(highlightExtension);
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ import { Prec, EditorState } from '@codemirror/state';
|
|||||||
import { keymap, ViewPlugin } from '@codemirror/view';
|
import { keymap, ViewPlugin } from '@codemirror/view';
|
||||||
// import { searchKeymap } from '@codemirror/search';
|
// import { searchKeymap } from '@codemirror/search';
|
||||||
import { emacs } from '@replit/codemirror-emacs';
|
import { emacs } from '@replit/codemirror-emacs';
|
||||||
import { vim, Vim } from '@replit/codemirror-vim';
|
import { vim } from '@replit/codemirror-vim';
|
||||||
// import { vim } from './vim_test.mjs';
|
// import { vim } from './vim_test.mjs';
|
||||||
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
|
||||||
import { helix, commands } from 'codemirror-helix';
|
|
||||||
import { logger } from '@strudel/core';
|
|
||||||
|
|
||||||
const vscodePlugin = ViewPlugin.fromClass(
|
const vscodePlugin = ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
@@ -21,166 +19,11 @@ const vscodePlugin = ViewPlugin.fromClass(
|
|||||||
);
|
);
|
||||||
const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
|
const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
|
||||||
|
|
||||||
function replEval(view) {
|
|
||||||
try {
|
|
||||||
// Dispatch a dedicated evaluate event first
|
|
||||||
let handled = false;
|
|
||||||
try {
|
|
||||||
const ev = new CustomEvent('repl-evaluate', { detail: { source: 'vim', view }, cancelable: true });
|
|
||||||
handled = document.dispatchEvent(ev) === false; // false means preventDefault was called
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching repl-evaluate event', e);
|
|
||||||
}
|
|
||||||
if (handled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Try Ctrl+Enter first if not handled by custom event
|
|
||||||
const ctrlEnter = new KeyboardEvent('keydown', {
|
|
||||||
key: 'Enter',
|
|
||||||
code: 'Enter',
|
|
||||||
ctrlKey: true,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
});
|
|
||||||
view?.dom?.dispatchEvent?.(ctrlEnter);
|
|
||||||
// If not handled (no handler called preventDefault), try Alt+Enter as
|
|
||||||
// fallback
|
|
||||||
if (!ctrlEnter.defaultPrevented) {
|
|
||||||
const altEnter = new KeyboardEvent('keydown', {
|
|
||||||
key: 'Enter',
|
|
||||||
code: 'Enter',
|
|
||||||
altKey: true,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
});
|
|
||||||
view?.dom?.dispatchEvent?.(altEnter);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching repl evaluation event', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function replStop(view) {
|
|
||||||
try {
|
|
||||||
// First try dispatching our custom stop event, then fallback to Alt+.
|
|
||||||
let handled = false;
|
|
||||||
try {
|
|
||||||
const ev = new CustomEvent('repl-stop', { detail: { source: 'vim', view }, cancelable: true });
|
|
||||||
handled = document.dispatchEvent(ev) === false;
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching repl-stop event', e);
|
|
||||||
}
|
|
||||||
if (!handled) {
|
|
||||||
const altDot = new KeyboardEvent('keydown', {
|
|
||||||
key: '.',
|
|
||||||
code: 'Period',
|
|
||||||
altKey: true,
|
|
||||||
bubbles: true,
|
|
||||||
cancelable: true,
|
|
||||||
});
|
|
||||||
view?.dom?.dispatchEvent?.(altDot);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching repl stop event', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map Vim :w to trigger the same action as evaluation. We dispatch a custom
|
|
||||||
// event 'repl-evaluate' that the editor listens for, and also simulate
|
|
||||||
// Ctrl+Enter/Alt+Enter as a fallback. We log to the Strudel logger so it
|
|
||||||
// appears in the Console panel.
|
|
||||||
try {
|
|
||||||
if (Vim && typeof Vim.defineEx === 'function') {
|
|
||||||
// Map gc to toggle line comments by dispatching a custom event that our
|
|
||||||
// CodeMirror integration listens to. This avoids depending on Vim's
|
|
||||||
// internal actions and works with current selections/visual mode.
|
|
||||||
try {
|
|
||||||
Vim.defineAction('strudelToggleComment', (cm) => {
|
|
||||||
const view = cm.cm6;
|
|
||||||
try {
|
|
||||||
const ev = new CustomEvent('repl-toggle-comment', { detail: { source: 'vim', view }, cancelable: true });
|
|
||||||
document.dispatchEvent(ev);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('strudelToggleComment dispatch failed', e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'normal' });
|
|
||||||
Vim.mapCommand('gc', 'action', 'strudelToggleComment', {}, { context: 'visual' });
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Vim gc mapping failed', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// :q to pause/stop
|
|
||||||
Vim.defineEx('quit', 'q', (cm) => {
|
|
||||||
const view = cm.cm6;
|
|
||||||
logger('[vim] :q — stopping repl');
|
|
||||||
replStop(view);
|
|
||||||
});
|
|
||||||
|
|
||||||
// :w to evaluate
|
|
||||||
Vim.defineEx('write', 'w', (cm) => {
|
|
||||||
const view = cm.cm6;
|
|
||||||
try {
|
|
||||||
view.focus?.();
|
|
||||||
// Let the app know this came from Vim :w
|
|
||||||
try {
|
|
||||||
logger('[vim] :w — evaluating code');
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error logging Vim :w evaluation', e);
|
|
||||||
}
|
|
||||||
replEval(view);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching :w evaluation event', e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Vim ex command setup failed (defineEx missing or Vim unavailable)', e);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map Helix :w to trigger the same action as evaluation. We dispatch a custom
|
|
||||||
// event 'repl-evaluate' that the editor listens for, and also simulate
|
|
||||||
// Ctrl+Enter/Alt+Enter as a fallback. We log to the Strudel logger so it
|
|
||||||
// appears in the Console panel.
|
|
||||||
const helixCommands = commands.of([
|
|
||||||
{
|
|
||||||
// :w to evaluate
|
|
||||||
name: 'write',
|
|
||||||
aliases: ['w'],
|
|
||||||
help: 'Repl-eval',
|
|
||||||
handler(view, args) {
|
|
||||||
try {
|
|
||||||
view?.focus?.(); // Let the app know this came from Helix :w
|
|
||||||
logger('[helix] :w — evaluating code');
|
|
||||||
replEval(view);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching helix :w evaluation event', e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// :q to pause/stop
|
|
||||||
name: 'quit',
|
|
||||||
aliases: ['q'],
|
|
||||||
help: 'Repl-stop',
|
|
||||||
handler(view, args) {
|
|
||||||
try {
|
|
||||||
view?.focus?.(); // Let the app know this came from Helix :q
|
|
||||||
logger('[helix] :q — stopping repl');
|
|
||||||
replStop(view);
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Error dispatching helix :q stop event', e);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const keymaps = {
|
const keymaps = {
|
||||||
vim,
|
vim,
|
||||||
emacs,
|
emacs,
|
||||||
codemirror: () => keymap.of(defaultKeymap),
|
codemirror: () => keymap.of(defaultKeymap),
|
||||||
vscode: vscodeExtension,
|
vscode: vscodeExtension,
|
||||||
helix: () => [helix(), helixCommands],
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { Vim } from '@replit/codemirror-vim';
|
export { Vim } from '@replit/codemirror-vim';
|
||||||
|
|||||||
@@ -44,14 +44,10 @@
|
|||||||
"@replit/codemirror-emacs": "^6.1.0",
|
"@replit/codemirror-emacs": "^6.1.0",
|
||||||
"@replit/codemirror-vim": "^6.3.0",
|
"@replit/codemirror-vim": "^6.3.0",
|
||||||
"@replit/codemirror-vscode-keymap": "^6.0.2",
|
"@replit/codemirror-vscode-keymap": "^6.0.2",
|
||||||
"codemirror-helix": "^0.5.0",
|
|
||||||
"@strudel/core": "workspace:*",
|
"@strudel/core": "workspace:*",
|
||||||
"@strudel/draw": "workspace:*",
|
"@strudel/draw": "workspace:*",
|
||||||
"@strudel/tonal": "workspace:*",
|
|
||||||
"@strudel/transpiler": "workspace:*",
|
"@strudel/transpiler": "workspace:*",
|
||||||
"@tonaljs/tonal": "^4.10.0",
|
"nanostores": "^0.11.3"
|
||||||
"nanostores": "^0.11.3",
|
|
||||||
"superdough": "workspace:*"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^6.0.11"
|
"vite": "^6.0.11"
|
||||||
|
|||||||
+17
-106
@@ -2,11 +2,11 @@ import { ref, pure } from '@strudel/core';
|
|||||||
import { WidgetType, ViewPlugin, Decoration } from '@codemirror/view';
|
import { WidgetType, ViewPlugin, Decoration } from '@codemirror/view';
|
||||||
import { StateEffect } from '@codemirror/state';
|
import { StateEffect } from '@codemirror/state';
|
||||||
|
|
||||||
// Global state storage for all widget types
|
|
||||||
export let sliderValues = {};
|
export let sliderValues = {};
|
||||||
|
const getSliderID = (from) => `slider_${from}`;
|
||||||
|
|
||||||
export class SliderWidget extends WidgetType {
|
export class SliderWidget extends WidgetType {
|
||||||
constructor(value, min, max, from, to, step, view, id) {
|
constructor(value, min, max, from, to, step, view) {
|
||||||
super();
|
super();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
@@ -16,21 +16,10 @@ export class SliderWidget extends WidgetType {
|
|||||||
this.to = to;
|
this.to = to;
|
||||||
this.step = step;
|
this.step = step;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.id = id || `${from}:${to}`; // Range-based ID for stability
|
|
||||||
}
|
}
|
||||||
|
|
||||||
eq(other) {
|
eq() {
|
||||||
if (!(other instanceof SliderWidget)) {
|
return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
this.id === other.id &&
|
|
||||||
this.from === other.from &&
|
|
||||||
this.to === other.to &&
|
|
||||||
this.value === other.value &&
|
|
||||||
this.min === other.min &&
|
|
||||||
this.max === other.max
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toDOM() {
|
toDOM() {
|
||||||
@@ -49,7 +38,6 @@ export class SliderWidget extends WidgetType {
|
|||||||
slider.from = this.from;
|
slider.from = this.from;
|
||||||
slider.originalFrom = this.originalFrom;
|
slider.originalFrom = this.originalFrom;
|
||||||
slider.to = this.to;
|
slider.to = this.to;
|
||||||
slider.id = this.id; // Store range-based ID in DOM element
|
|
||||||
slider.style = 'width:64px;margin-right:4px;transform:translateY(4px)';
|
slider.style = 'width:64px;margin-right:4px;transform:translateY(4px)';
|
||||||
this.slider = slider;
|
this.slider = slider;
|
||||||
slider.addEventListener('input', (e) => {
|
slider.addEventListener('input', (e) => {
|
||||||
@@ -61,7 +49,7 @@ export class SliderWidget extends WidgetType {
|
|||||||
slider.originalValue = insert;
|
slider.originalValue = insert;
|
||||||
slider.value = insert;
|
slider.value = insert;
|
||||||
this.view.dispatch({ changes: change });
|
this.view.dispatch({ changes: change });
|
||||||
const id = slider.id; // Use range-based ID
|
const id = getSliderID(slider.originalFrom); // matches id generated in transpiler
|
||||||
window.postMessage({ type: 'cm-slider', value: Number(next), id });
|
window.postMessage({ type: 'cm-slider', value: Number(next), id });
|
||||||
});
|
});
|
||||||
return wrap;
|
return wrap;
|
||||||
@@ -74,60 +62,19 @@ export class SliderWidget extends WidgetType {
|
|||||||
|
|
||||||
export const setSliderWidgets = StateEffect.define();
|
export const setSliderWidgets = StateEffect.define();
|
||||||
|
|
||||||
export const setSliderWidgetsInRange = StateEffect.define();
|
export const updateSliderWidgets = (view, widgets) => {
|
||||||
|
view.dispatch({ effects: setSliderWidgets.of(widgets) });
|
||||||
export const updateSliderWidgets = (view, widgets, range = null) => {
|
|
||||||
if (range) {
|
|
||||||
// range argument passed for block-based evaluation
|
|
||||||
view.dispatch({ effects: setSliderWidgetsInRange.of({ widgets, range }) });
|
|
||||||
} else {
|
|
||||||
view.dispatch({ effects: setSliderWidgets.of(widgets) });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getSliders(widgetConfigs, view) {
|
function getSliders(widgetConfigs, view) {
|
||||||
return (
|
return widgetConfigs
|
||||||
widgetConfigs
|
.filter((w) => w.type === 'slider')
|
||||||
.filter((w) => w.type === 'slider')
|
.map(({ from, to, value, min, max, step }) => {
|
||||||
// Deduplicate sliders that might appear multiple times (e.g., during paste operations)
|
return Decoration.widget({
|
||||||
.filter((slider, index, self) => index === self.findIndex((s) => s.from === slider.from && s.to === slider.to))
|
widget: new SliderWidget(value, min, max, from, to, step, view),
|
||||||
.sort((a, b) => a.from - b.from)
|
side: 0,
|
||||||
.map(({ from, to, value, min, max, step, id }) => {
|
}).range(from /* , to */);
|
||||||
return Decoration.widget({
|
});
|
||||||
widget: new SliderWidget(value, min, max, from, to, step, view, id),
|
|
||||||
side: 0,
|
|
||||||
}).range(from /* , to */);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSliderWidgets(view) {
|
|
||||||
if (!view || !view.state) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const sliderPluginInstance = view.plugin(sliderPlugin);
|
|
||||||
if (!sliderPluginInstance || !sliderPluginInstance.decorations) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const sliderWidgets = [];
|
|
||||||
|
|
||||||
sliderPluginInstance.decorations.between(0, view.state.doc.length, (from, to, decoration) => {
|
|
||||||
if (decoration.widget instanceof SliderWidget) {
|
|
||||||
sliderWidgets.push({
|
|
||||||
type: 'slider',
|
|
||||||
from: decoration.widget.from,
|
|
||||||
to: decoration.widget.to,
|
|
||||||
value: decoration.widget.value,
|
|
||||||
min: decoration.widget.min,
|
|
||||||
max: decoration.widget.max,
|
|
||||||
step: decoration.widget.step,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return sliderWidgets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const sliderPlugin = ViewPlugin.fromClass(
|
export const sliderPlugin = ViewPlugin.fromClass(
|
||||||
@@ -154,42 +101,7 @@ export const sliderPlugin = ViewPlugin.fromClass(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setSliderWidgetsInRange)) {
|
if (e.is(setSliderWidgets)) {
|
||||||
// Block-aware slider update logic
|
|
||||||
const { widgets, range } = e.value;
|
|
||||||
const [rangeStart, rangeEnd] = range;
|
|
||||||
|
|
||||||
// Get existing slider widgets that should be preserved
|
|
||||||
const existingSliders = [];
|
|
||||||
this.decorations.between(0, update.view.state.doc.length, (from, to, decoration) => {
|
|
||||||
if (decoration.widget instanceof SliderWidget) {
|
|
||||||
// Preserve sliders outside the evaluation range
|
|
||||||
// Use strict > for rangeEnd because when code is deleted, slider positions
|
|
||||||
// map to the deletion boundary (rangeEnd), and those should be removed, not preserved
|
|
||||||
if (from < rangeStart || from > rangeEnd) {
|
|
||||||
existingSliders.push({
|
|
||||||
from,
|
|
||||||
to,
|
|
||||||
value: decoration.widget.value,
|
|
||||||
min: decoration.widget.min,
|
|
||||||
max: decoration.widget.max,
|
|
||||||
step: decoration.widget.step,
|
|
||||||
id: decoration.widget.id || `${from}:${to}`,
|
|
||||||
type: 'slider',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Merge preserved sliders with new widgets
|
|
||||||
const mergedWidgets = [...existingSliders, ...widgets]
|
|
||||||
.filter(
|
|
||||||
(slider, index, self) => index === self.findIndex((s) => s.type === 'slider' && s.id === slider.id),
|
|
||||||
)
|
|
||||||
.sort((a, b) => a.from - b.from);
|
|
||||||
|
|
||||||
this.decorations = Decoration.set(getSliders(mergedWidgets, update.view));
|
|
||||||
} else if (e.is(setSliderWidgets)) {
|
|
||||||
this.decorations = Decoration.set(getSliders(e.value, update.view));
|
this.decorations = Decoration.set(getSliders(e.value, update.view));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -220,7 +132,6 @@ export let sliderWithID = (id, value, min, max) => {
|
|||||||
sliderValues[id] = value; // sync state at eval time (code -> state)
|
sliderValues[id] = value; // sync state at eval time (code -> state)
|
||||||
return ref(() => sliderValues[id]); // use state at query time
|
return ref(() => sliderValues[id]); // use state at query time
|
||||||
};
|
};
|
||||||
|
|
||||||
// update state when sliders are moved
|
// update state when sliders are moved
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
window.addEventListener('message', (e) => {
|
window.addEventListener('message', (e) => {
|
||||||
@@ -229,7 +140,7 @@ if (typeof window !== 'undefined') {
|
|||||||
// update state when slider is moved
|
// update state when slider is moved
|
||||||
sliderValues[e.data.id] = e.data.value;
|
sliderValues[e.data.id] = e.data.value;
|
||||||
} else {
|
} else {
|
||||||
console.error(`slider with id "${e.data.id}" is not registered. Only ${Object.keys(sliderValues)}`);
|
console.warn(`slider with id "${e.data.id}" is not registered. Only ${Object.keys(sliderValues)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
+77
-193
@@ -1,111 +1,55 @@
|
|||||||
import { StateEffect, StateField } from '@codemirror/state';
|
import { StateEffect, StateField } from '@codemirror/state';
|
||||||
import { Decoration, EditorView, WidgetType, ViewPlugin } from '@codemirror/view';
|
import { Decoration, EditorView, WidgetType } from '@codemirror/view';
|
||||||
import { getWidgetID, registerWidgetType } from '@strudel/transpiler';
|
import { getWidgetID, registerWidgetType } from '@strudel/transpiler';
|
||||||
import { Pattern } from '@strudel/core';
|
import { Pattern } from '@strudel/core';
|
||||||
|
|
||||||
export const setWidgets = StateEffect.define();
|
export const addWidget = StateEffect.define({
|
||||||
|
map: ({ from, to }, change) => {
|
||||||
|
return { from: change.mapPos(from), to: change.mapPos(to) };
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const setWidgetsInRange = StateEffect.define();
|
export const updateWidgets = (view, widgets) => {
|
||||||
|
view.dispatch({ effects: addWidget.of(widgets) });
|
||||||
export const updateWidgets = (view, widgets, range = null) => {
|
|
||||||
if (range) {
|
|
||||||
// range argument passed for block-based evaluation
|
|
||||||
view.dispatch({ effects: setWidgetsInRange.of({ widgets, range }) });
|
|
||||||
} else {
|
|
||||||
view.dispatch({ effects: setWidgets.of(widgets) });
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getWidgets(widgetConfigs, view) {
|
function getWidgets(widgetConfigs) {
|
||||||
const filtered = widgetConfigs
|
return (
|
||||||
// Filter to widget configs only (exclude sliders)
|
widgetConfigs
|
||||||
.filter((w) => w && w.type && w.type !== 'slider')
|
// codemirror throws an error if we don't sort
|
||||||
// Deduplicate widgets by ID, matching slider behavior for stable widget identity
|
.sort((a, b) => a.to - b.to)
|
||||||
.filter((widget, index, self) => index === self.findIndex((w) => w.type === widget.type && w.id === widget.id));
|
.map((widgetConfig) => {
|
||||||
|
|
||||||
// Filter out widgets whose range is encompassed by another widget
|
|
||||||
// const nonEncompassed = filterEncompassedWidgets(filtered);
|
|
||||||
|
|
||||||
return filtered
|
|
||||||
.sort((a, b) => (a.to || 0) - (b.to || 0))
|
|
||||||
.map((widgetConfig) => {
|
|
||||||
try {
|
|
||||||
return Decoration.widget({
|
return Decoration.widget({
|
||||||
widget: new BlockWidget(widgetConfig, view),
|
widget: new BlockWidget(widgetConfig),
|
||||||
side: 0,
|
side: 0,
|
||||||
}).range(widgetConfig.to || widgetConfig.from || 0);
|
block: true,
|
||||||
} catch (error) {
|
}).range(widgetConfig.to);
|
||||||
console.error('error creating widget', error);
|
})
|
||||||
return null;
|
);
|
||||||
}
|
|
||||||
})
|
|
||||||
.filter(Boolean); // Remove any null results from failed creations
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const widgetPlugin = ViewPlugin.fromClass(
|
const widgetField = StateField.define(
|
||||||
class {
|
/* <DecorationSet> */ {
|
||||||
decorations; //: DecorationSet
|
create() {
|
||||||
|
return Decoration.none;
|
||||||
constructor(view /* : EditorView */) {
|
},
|
||||||
this.decorations = Decoration.set([]);
|
update(widgets, tr) {
|
||||||
}
|
widgets = widgets.map(tr.changes);
|
||||||
|
for (let e of tr.effects) {
|
||||||
update(update /* : ViewUpdate */) {
|
if (e.is(addWidget)) {
|
||||||
update.transactions.forEach((tr) => {
|
try {
|
||||||
if (tr.docChanged) {
|
widgets = widgets.update({
|
||||||
this.decorations = this.decorations.map(tr.changes);
|
filter: () => false,
|
||||||
const iterator = this.decorations.iter();
|
add: getWidgets(e.value),
|
||||||
// Apply changes to iterator.from and iterator.to if docChanged
|
|
||||||
while (iterator.value) {
|
|
||||||
// when the widgets are moved, we need to tell the dom node the current position
|
|
||||||
// this is important because the widget functions have to work with the dom node
|
|
||||||
if (iterator.value?.widget instanceof BlockWidget) {
|
|
||||||
iterator.value.widget.from = iterator.from;
|
|
||||||
iterator.value.widget.to = iterator.to;
|
|
||||||
}
|
|
||||||
iterator.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let e of tr.effects) {
|
|
||||||
if (e.is(setWidgetsInRange)) {
|
|
||||||
// Block-aware widget update logic
|
|
||||||
const { widgets, range } = e.value;
|
|
||||||
const [rangeStart, rangeEnd] = range;
|
|
||||||
|
|
||||||
// Get existing widget widgets that should be preserved
|
|
||||||
const existingWidgets = [];
|
|
||||||
this.decorations.between(0, update.view.state.doc.length, (from, to, decoration) => {
|
|
||||||
if (decoration.widget instanceof BlockWidget) {
|
|
||||||
// Preserve widgets outside the evaluation range
|
|
||||||
// Use strict > for rangeEnd because when code is deleted, widget positions
|
|
||||||
// map to the deletion boundary (rangeEnd), and those should be removed, not preserved
|
|
||||||
if (from < rangeStart || from > rangeEnd) {
|
|
||||||
existingWidgets.push({
|
|
||||||
from: decoration.widget.from,
|
|
||||||
to: decoration.widget.to,
|
|
||||||
type: decoration.widget.type,
|
|
||||||
index: decoration.widget.index,
|
|
||||||
id: decoration.widget.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
// Merge preserved widgets with new widgets, deduplicating by ID
|
console.log('err', error);
|
||||||
const mergedWidgets = [...existingWidgets, ...widgets].filter(
|
|
||||||
(widget, index, self) => index === self.findIndex((w) => w.type === widget.type && w.id === widget.id),
|
|
||||||
);
|
|
||||||
|
|
||||||
this.decorations = Decoration.set(getWidgets(mergedWidgets, update.view));
|
|
||||||
} else if (e.is(setWidgets)) {
|
|
||||||
this.decorations = Decoration.set(getWidgets(e.value, update.view));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
return widgets;
|
||||||
},
|
},
|
||||||
{
|
provide: (f) => EditorView.decorations.from(f),
|
||||||
decorations: (v) => v.decorations,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -116,116 +60,24 @@ export function setWidget(id, el) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class BlockWidget extends WidgetType {
|
export class BlockWidget extends WidgetType {
|
||||||
constructor(widgetConfig, view) {
|
constructor(widgetConfig) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
// Graceful handling of invalid configs like sliders
|
|
||||||
if (!widgetConfig || typeof widgetConfig !== 'object') {
|
|
||||||
widgetConfig = { type: 'unknown', from: 0, to: 0 };
|
|
||||||
}
|
|
||||||
|
|
||||||
this.from = widgetConfig.from || 0;
|
|
||||||
this.originalFrom = widgetConfig.from || 0;
|
|
||||||
this.to = widgetConfig.to || this.from;
|
|
||||||
this.originalTo = widgetConfig.to || this.from;
|
|
||||||
this.type = widgetConfig.type || 'unknown';
|
|
||||||
this.index = widgetConfig.index || 0;
|
|
||||||
this.view = view;
|
|
||||||
|
|
||||||
// Use range-based ID for stability, similar to sliders
|
|
||||||
this.id = widgetConfig.id || getWidgetID?.(widgetConfig);
|
|
||||||
this.widgetConfig = widgetConfig;
|
this.widgetConfig = widgetConfig;
|
||||||
}
|
}
|
||||||
|
eq() {
|
||||||
eq(other) {
|
return true;
|
||||||
if (!(other instanceof BlockWidget)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
this.id === other.id &&
|
|
||||||
this.from === other.from &&
|
|
||||||
this.to === other.to &&
|
|
||||||
this.type === other.type &&
|
|
||||||
this.index === other.index
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
toDOM() {
|
toDOM() {
|
||||||
let wrap = document.createElement('span');
|
const id = getWidgetID(this.widgetConfig);
|
||||||
wrap.setAttribute('aria-hidden', 'true');
|
const el = widgetElements[id];
|
||||||
wrap.className = 'cm-widget-container';
|
return el;
|
||||||
|
|
||||||
let el = widgetElements[this.id];
|
|
||||||
if (el) {
|
|
||||||
// Ensure the element has the correct ID
|
|
||||||
el.id = this.id;
|
|
||||||
wrap.appendChild(el);
|
|
||||||
} else {
|
|
||||||
// Create a placeholder element if the widget element doesn't exist
|
|
||||||
// This prevents CodeMirror errors when widget is missing
|
|
||||||
const placeholder = document.createElement('span');
|
|
||||||
placeholder.setAttribute('aria-hidden', 'true');
|
|
||||||
placeholder.className = 'cm-widget-placeholder';
|
|
||||||
placeholder.style.cssText = 'display: none;'; // Hide placeholder
|
|
||||||
placeholder.id = this.id;
|
|
||||||
wrap.appendChild(placeholder);
|
|
||||||
}
|
|
||||||
|
|
||||||
return wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoreEvent(e) {
|
ignoreEvent(e) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getActiveWidgets(view) {
|
export const widgetPlugin = [widgetField];
|
||||||
if (!view || !view.state) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const widgetPluginInstance = view.plugin(widgetPlugin);
|
|
||||||
if (!widgetPluginInstance || !widgetPluginInstance.decorations) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const widgets = [];
|
|
||||||
|
|
||||||
widgetPluginInstance.decorations.between(0, view.state.doc.length, (from, to, decoration) => {
|
|
||||||
if (decoration.widget instanceof BlockWidget) {
|
|
||||||
widgets.push({
|
|
||||||
type: decoration.widget.type,
|
|
||||||
from: decoration.widget.from,
|
|
||||||
to: decoration.widget.to,
|
|
||||||
index: decoration.widget.index,
|
|
||||||
id: decoration.widget.id,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return widgets;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getAllWidgetIds(view) {
|
|
||||||
if (!view || !view.state) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const widgetPluginInstance = view.plugin(widgetPlugin);
|
|
||||||
if (!widgetPluginInstance || !widgetPluginInstance.decorations) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
const widgetIds = [];
|
|
||||||
|
|
||||||
widgetPluginInstance.decorations.between(0, view.state.doc.length, (from, to, decoration) => {
|
|
||||||
if (decoration.widget instanceof BlockWidget) {
|
|
||||||
widgetIds.push(decoration.widget.id);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return widgetIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
// widget implementer API to create a new widget type
|
// widget implementer API to create a new widget type
|
||||||
export function registerWidget(type, fn) {
|
export function registerWidget(type, fn) {
|
||||||
@@ -252,6 +104,32 @@ function getCanvasWidget(id, options = {}) {
|
|||||||
return canvas;
|
return canvas;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getListWidget(id, options = {}) {
|
||||||
|
const { width = 600, height = 100 } = options;
|
||||||
|
let el = document.getElementById(id) || document.createElement('div');
|
||||||
|
el.style.width = width + 'px';
|
||||||
|
el.style.height = height + 'px';
|
||||||
|
el.style.overflowY = 'auto';
|
||||||
|
el.style.overflowX = 'auto';
|
||||||
|
el.style.boxSizing = 'border-box';
|
||||||
|
el.style.padding = '4px';
|
||||||
|
el.style.fontFamily = 'monospace';
|
||||||
|
el.style.lineHeight = '1.4';
|
||||||
|
el.style.whiteSpace = 'pre';
|
||||||
|
el.style.background = 'var(--background)';
|
||||||
|
el.style.color = 'var(--foreground)';
|
||||||
|
el.style.border = '1px solid var(--lineHighlight)';
|
||||||
|
// reset on every (re-)evaluation instead of persisting scroll state across it
|
||||||
|
el.replaceChildren();
|
||||||
|
el.scrollTop = 0;
|
||||||
|
el.follow = true;
|
||||||
|
el.onscroll = () => {
|
||||||
|
el.follow = el.scrollHeight - el.scrollTop - el.clientHeight < 4;
|
||||||
|
};
|
||||||
|
setWidget(id, el);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
registerWidget('_pianoroll', (id, options = {}, pat) => {
|
registerWidget('_pianoroll', (id, options = {}, pat) => {
|
||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.tag(id).pianoroll({ fold: 1, ...options, ctx, id });
|
return pat.tag(id).pianoroll({ fold: 1, ...options, ctx, id });
|
||||||
@@ -288,3 +166,9 @@ registerWidget('_spectrum', (id, options = {}, pat) => {
|
|||||||
const ctx = getCanvasWidget(id, options).getContext('2d');
|
const ctx = getCanvasWidget(id, options).getContext('2d');
|
||||||
return pat.spectrum({ ...options, ctx, id });
|
return pat.spectrum({ ...options, ctx, id });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
registerWidget('_print', (id, options = {}, pat) => {
|
||||||
|
options = { width: 600, height: 100, maxLines: 500, ...options };
|
||||||
|
const el = getListWidget(id, options);
|
||||||
|
return pat.print({ ...options, el, id });
|
||||||
|
});
|
||||||
|
|||||||
+54
-68
@@ -446,7 +446,7 @@ export const { accelerate } = registerControl('accelerate');
|
|||||||
* Sets the velocity from 0 to 1. Is multiplied together with gain.
|
* Sets the velocity from 0 to 1. Is multiplied together with gain.
|
||||||
*
|
*
|
||||||
* @name velocity
|
* @name velocity
|
||||||
* @tags amplitude, superdough, supradough
|
* @tags amplitude, superdough
|
||||||
* @synonyms vel
|
* @synonyms vel
|
||||||
* @example
|
* @example
|
||||||
* s("hh*8")
|
* s("hh*8")
|
||||||
@@ -458,7 +458,7 @@ export const { velocity, vel } = registerControl('velocity', 'vel');
|
|||||||
* Controls the gain by an exponential amount.
|
* Controls the gain by an exponential amount.
|
||||||
*
|
*
|
||||||
* @name gain
|
* @name gain
|
||||||
* @tags amplitude, superdough, supradough
|
* @tags amplitude, superdough
|
||||||
* @param {number | Pattern} amount gain.
|
* @param {number | Pattern} amount gain.
|
||||||
* @example
|
* @example
|
||||||
* s("hh*8").gain(".4!2 1 .4!2 1 .4 1").fast(2)
|
* s("hh*8").gain(".4!2 1 .4!2 1 .4 1").fast(2)
|
||||||
@@ -469,7 +469,7 @@ export const { gain } = registerControl('gain');
|
|||||||
* Gain applied after all effects have been processed.
|
* Gain applied after all effects have been processed.
|
||||||
*
|
*
|
||||||
* @name postgain
|
* @name postgain
|
||||||
* @tags amplitude, superdough, supradough
|
* @tags amplitude, superdough
|
||||||
* @example
|
* @example
|
||||||
* s("bd sd [~ bd] sd,hh*8")
|
* s("bd sd [~ bd] sd,hh*8")
|
||||||
* .compressor("-20:20:10:.002:.02").postgain(1.5)
|
* .compressor("-20:20:10:.002:.02").postgain(1.5)
|
||||||
@@ -499,7 +499,7 @@ export const { amp } = registerControl('amp');
|
|||||||
* any of the 8 individual FMs (e.g. `fmh2`)
|
* any of the 8 individual FMs (e.g. `fmh2`)
|
||||||
*
|
*
|
||||||
* @name fmh
|
* @name fmh
|
||||||
* @tags fm, superdough, supradough
|
* @tags fm, superdough
|
||||||
* @param {number | Pattern} harmonicity
|
* @param {number | Pattern} harmonicity
|
||||||
* @example
|
* @example
|
||||||
* note("c e g b g e")
|
* note("c e g b g e")
|
||||||
@@ -519,10 +519,10 @@ export const { fmh, fmh1, fmh2, fmh3, fmh4, fmh5, fmh6, fmh7, fmh8 } = registerM
|
|||||||
* each other with matrix commands like `fm13`, which would send `fm1` back into
|
* each other with matrix commands like `fm13`, which would send `fm1` back into
|
||||||
* `fm3`
|
* `fm3`
|
||||||
*
|
*
|
||||||
* @name fmi
|
* @name fm
|
||||||
* @tags fm, superdough, supradough
|
* @tags fm, superdough
|
||||||
* @param {number | Pattern} brightness modulation index
|
* @param {number | Pattern} brightness modulation index
|
||||||
* @synonyms fm
|
* @synonyms fmi
|
||||||
* @example
|
* @example
|
||||||
* note("c e g b g e")
|
* note("c e g b g e")
|
||||||
* .fm("<0 1 2 8 32>")
|
* .fm("<0 1 2 8 32>")
|
||||||
@@ -544,7 +544,7 @@ export const { fmi, fmi1, fmi2, fmi3, fmi4, fmi5, fmi6, fmi7, fmi8, fm, fm1, fm2
|
|||||||
* any of the 8 individual FMs (e.g. `fmenv4`)
|
* any of the 8 individual FMs (e.g. `fmenv4`)
|
||||||
*
|
*
|
||||||
* @name fmenv
|
* @name fmenv
|
||||||
* @tags fm, envelope, superdough, supradough
|
* @tags fm, envelope, superdough
|
||||||
* @param {number | Pattern} type lin | exp
|
* @param {number | Pattern} type lin | exp
|
||||||
* @synonyms fme
|
* @synonyms fme
|
||||||
* @example
|
* @example
|
||||||
@@ -569,7 +569,7 @@ export const { fmenv, fmenv1, fmenv2, fmenv3, fmenv4, fmenv5, fmenv6, fmenv7, fm
|
|||||||
* any of the 8 individual FMs (e.g. `fmatt5`)
|
* any of the 8 individual FMs (e.g. `fmatt5`)
|
||||||
*
|
*
|
||||||
* @name fmattack
|
* @name fmattack
|
||||||
* @tags fm, envelope, superdough, supradough
|
* @tags fm, envelope, superdough
|
||||||
* @synonyms fmatt
|
* @synonyms fmatt
|
||||||
* @param {number | Pattern} time attack time
|
* @param {number | Pattern} time attack time
|
||||||
* @synonyms fmatt
|
* @synonyms fmatt
|
||||||
@@ -608,7 +608,7 @@ export const {
|
|||||||
* any of the 8 individual FMs (e.g. `fmwave6`)
|
* any of the 8 individual FMs (e.g. `fmwave6`)
|
||||||
*
|
*
|
||||||
* @name fmwave
|
* @name fmwave
|
||||||
* @tags fm, superdough, supradough
|
* @tags fm, superdough
|
||||||
* @param {number | Pattern} wave waveform
|
* @param {number | Pattern} wave waveform
|
||||||
* @example
|
* @example
|
||||||
* n("0 1 2 3".fast(4)).scale("d:minor").s("sine").fmwave("<sine square sawtooth crackle>").fm(4).fmh(2.01)
|
* n("0 1 2 3".fast(4)).scale("d:minor").s("sine").fmwave("<sine square sawtooth crackle>").fm(4).fmh(2.01)
|
||||||
@@ -628,7 +628,7 @@ export const { fmwave, fmwave1, fmwave2, fmwave3, fmwave4, fmwave5, fmwave6, fmw
|
|||||||
* any of the 8 individual FMs (e.g. `fmdec6`)
|
* any of the 8 individual FMs (e.g. `fmdec6`)
|
||||||
*
|
*
|
||||||
* @name fmdecay
|
* @name fmdecay
|
||||||
* @tags fm, envelope, superdough, supradough
|
* @tags fm, envelope, superdough
|
||||||
* @synonyms fmdec
|
* @synonyms fmdec
|
||||||
* @param {number | Pattern} time decay time
|
* @param {number | Pattern} time decay time
|
||||||
* @synonyms fmdec
|
* @synonyms fmdec
|
||||||
@@ -668,7 +668,7 @@ export const {
|
|||||||
* any of the 8 individual FMs (e.g. `fmsus7`)
|
* any of the 8 individual FMs (e.g. `fmsus7`)
|
||||||
*
|
*
|
||||||
* @name fmsustain
|
* @name fmsustain
|
||||||
* @tags fm, envelope, superdough, supradough
|
* @tags fm, envelope, superdough
|
||||||
* @synonyms fmsus
|
* @synonyms fmsus
|
||||||
* @param {number | Pattern} level sustain level
|
* @param {number | Pattern} level sustain level
|
||||||
* @synonyms fmsus
|
* @synonyms fmsus
|
||||||
@@ -708,7 +708,7 @@ export const {
|
|||||||
* any of the 8 individual FMs (e.g. `fmrel8`)
|
* any of the 8 individual FMs (e.g. `fmrel8`)
|
||||||
*
|
*
|
||||||
* @name fmrelease
|
* @name fmrelease
|
||||||
* @tags fm, envelope, superdough, supradough
|
* @tags fm, envelope, superdough
|
||||||
* @synonyms fmrel
|
* @synonyms fmrel
|
||||||
* @param {number | Pattern} time release time
|
* @param {number | Pattern} time release time
|
||||||
*
|
*
|
||||||
@@ -778,7 +778,7 @@ export const { fft } = registerControl('fft');
|
|||||||
* Amplitude envelope attack time: Specifies how long it takes for the sound to reach its peak value, relative to the onset.
|
* Amplitude envelope attack time: Specifies how long it takes for the sound to reach its peak value, relative to the onset.
|
||||||
*
|
*
|
||||||
* @name attack
|
* @name attack
|
||||||
* @tags amplitude, envelope, superdough, supradough
|
* @tags amplitude, envelope, superdough
|
||||||
* @param {number | Pattern} attack time in seconds.
|
* @param {number | Pattern} attack time in seconds.
|
||||||
* @synonyms att
|
* @synonyms att
|
||||||
* @example
|
* @example
|
||||||
@@ -792,7 +792,7 @@ export const { attack, att } = registerControl('attack', 'att');
|
|||||||
* Note that the decay is only audible if the sustain value is lower than 1.
|
* Note that the decay is only audible if the sustain value is lower than 1.
|
||||||
*
|
*
|
||||||
* @name decay
|
* @name decay
|
||||||
* @tags amplitude, envelope, superdough, supradough
|
* @tags amplitude, envelope, superdough
|
||||||
* @param {number | Pattern} time decay time in seconds
|
* @param {number | Pattern} time decay time in seconds
|
||||||
* @synonyms dec
|
* @synonyms dec
|
||||||
* @example
|
* @example
|
||||||
@@ -804,7 +804,7 @@ export const { decay, dec } = registerControl('decay', 'dec');
|
|||||||
* Amplitude envelope sustain level: The level which is reached after attack / decay, being sustained until the offset.
|
* Amplitude envelope sustain level: The level which is reached after attack / decay, being sustained until the offset.
|
||||||
*
|
*
|
||||||
* @name sustain
|
* @name sustain
|
||||||
* @tags amplitude, envelope, superdough, supradough
|
* @tags amplitude, envelope, superdough
|
||||||
* @param {number | Pattern} gain sustain level between 0 and 1
|
* @param {number | Pattern} gain sustain level between 0 and 1
|
||||||
* @synonyms sus
|
* @synonyms sus
|
||||||
* @example
|
* @example
|
||||||
@@ -816,7 +816,7 @@ export const { sustain, sus } = registerControl('sustain', 'sus');
|
|||||||
* Amplitude envelope release time: The time it takes after the offset to go from sustain level to zero.
|
* Amplitude envelope release time: The time it takes after the offset to go from sustain level to zero.
|
||||||
*
|
*
|
||||||
* @name release
|
* @name release
|
||||||
* @tags amplitude, envelope, superdough, supradough
|
* @tags amplitude, envelope, superdough
|
||||||
* @param {number | Pattern} time release time in seconds
|
* @param {number | Pattern} time release time in seconds
|
||||||
* @synonyms rel
|
* @synonyms rel
|
||||||
* @example
|
* @example
|
||||||
@@ -831,7 +831,7 @@ export const { hold } = registerControl('hold');
|
|||||||
* can also optionally supply the 'bpq' parameter separated by ':'.
|
* can also optionally supply the 'bpq' parameter separated by ':'.
|
||||||
*
|
*
|
||||||
* @name bpf
|
* @name bpf
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} frequency center frequency
|
* @param {number | Pattern} frequency center frequency
|
||||||
* @synonyms bandf, bp
|
* @synonyms bandf, bp
|
||||||
* @example
|
* @example
|
||||||
@@ -844,7 +844,7 @@ export const { bandf, bpf, bp } = registerControl(['bandf', 'bandq', 'bpenv'], '
|
|||||||
* Sets the **b**and-**p**ass **q**-factor (resonance).
|
* Sets the **b**and-**p**ass **q**-factor (resonance).
|
||||||
*
|
*
|
||||||
* @name bpq
|
* @name bpq
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} q q factor
|
* @param {number | Pattern} q q factor
|
||||||
* @synonyms bandq
|
* @synonyms bandq
|
||||||
* @example
|
* @example
|
||||||
@@ -923,7 +923,7 @@ export const { loopEnd, loope } = registerControl('loopEnd', 'loope');
|
|||||||
* Bit crusher effect.
|
* Bit crusher effect.
|
||||||
*
|
*
|
||||||
* @name crush
|
* @name crush
|
||||||
* @tags superdough, supradough
|
* @tags superdough
|
||||||
* @param {number | Pattern} depth between 1 (for drastic reduction in bit-depth) to 16 (for barely no reduction).
|
* @param {number | Pattern} depth between 1 (for drastic reduction in bit-depth) to 16 (for barely no reduction).
|
||||||
* @example
|
* @example
|
||||||
* s("<bd sd>,hh*3").fast(2).crush("<16 8 7 6 5 4 3 2>")
|
* s("<bd sd>,hh*3").fast(2).crush("<16 8 7 6 5 4 3 2>")
|
||||||
@@ -935,7 +935,7 @@ export const { crush } = registerControl('crush');
|
|||||||
* Fake-resampling for lowering the sample rate. Caution: This effect seems to only work in chromium based browsers
|
* Fake-resampling for lowering the sample rate. Caution: This effect seems to only work in chromium based browsers
|
||||||
*
|
*
|
||||||
* @name coarse
|
* @name coarse
|
||||||
* @tags superdough, supradough
|
* @tags superdough
|
||||||
* @param {number | Pattern} factor 1 for original 2 for half, 3 for a third and so on.
|
* @param {number | Pattern} factor 1 for original 2 for half, 3 for a third and so on.
|
||||||
* @example
|
* @example
|
||||||
* s("bd sd [~ bd] sd,hh*8").coarse("<1 4 8 16 32>")
|
* s("bd sd [~ bd] sd,hh*8").coarse("<1 4 8 16 32>")
|
||||||
@@ -1294,7 +1294,7 @@ export const { cut } = registerControl('cut');
|
|||||||
* When using mininotation, you can also optionally add the 'lpq' parameter, separated by ':'.
|
* When using mininotation, you can also optionally add the 'lpq' parameter, separated by ':'.
|
||||||
*
|
*
|
||||||
* @name lpf
|
* @name lpf
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} frequency audible between 0 and 20000
|
* @param {number | Pattern} frequency audible between 0 and 20000
|
||||||
* @synonyms cutoff, ctf, lp
|
* @synonyms cutoff, ctf, lp
|
||||||
* @example
|
* @example
|
||||||
@@ -1308,7 +1308,7 @@ export const { cutoff, ctf, lpf, lp } = registerControl(['cutoff', 'resonance',
|
|||||||
/**
|
/**
|
||||||
* Sets the lowpass filter envelope modulation depth.
|
* Sets the lowpass filter envelope modulation depth.
|
||||||
* @name lpenv
|
* @name lpenv
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} modulation depth of the lowpass filter envelope between 0 and _n_
|
* @param {number | Pattern} modulation depth of the lowpass filter envelope between 0 and _n_
|
||||||
* @synonyms lpe
|
* @synonyms lpe
|
||||||
* @example
|
* @example
|
||||||
@@ -1322,7 +1322,7 @@ export const { lpenv, lpe } = registerControl('lpenv', 'lpe');
|
|||||||
/**
|
/**
|
||||||
* Sets the highpass filter envelope modulation depth.
|
* Sets the highpass filter envelope modulation depth.
|
||||||
* @name hpenv
|
* @name hpenv
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} modulation depth of the highpass filter envelope between 0 and _n_
|
* @param {number | Pattern} modulation depth of the highpass filter envelope between 0 and _n_
|
||||||
* @synonyms hpe
|
* @synonyms hpe
|
||||||
* @example
|
* @example
|
||||||
@@ -1336,7 +1336,7 @@ export const { hpenv, hpe } = registerControl('hpenv', 'hpe');
|
|||||||
/**
|
/**
|
||||||
* Sets the bandpass filter envelope modulation depth.
|
* Sets the bandpass filter envelope modulation depth.
|
||||||
* @name bpenv
|
* @name bpenv
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} modulation depth of the bandpass filter envelope between 0 and _n_
|
* @param {number | Pattern} modulation depth of the bandpass filter envelope between 0 and _n_
|
||||||
* @synonyms bpe
|
* @synonyms bpe
|
||||||
* @example
|
* @example
|
||||||
@@ -1350,7 +1350,7 @@ export const { bpenv, bpe } = registerControl('bpenv', 'bpe');
|
|||||||
/**
|
/**
|
||||||
* Sets the attack duration for the lowpass filter envelope.
|
* Sets the attack duration for the lowpass filter envelope.
|
||||||
* @name lpattack
|
* @name lpattack
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} attack time of the filter envelope
|
* @param {number | Pattern} attack time of the filter envelope
|
||||||
* @synonyms lpa
|
* @synonyms lpa
|
||||||
* @example
|
* @example
|
||||||
@@ -1364,7 +1364,7 @@ export const { lpattack, lpa } = registerControl('lpattack', 'lpa');
|
|||||||
/**
|
/**
|
||||||
* Sets the attack duration for the highpass filter envelope.
|
* Sets the attack duration for the highpass filter envelope.
|
||||||
* @name hpattack
|
* @name hpattack
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} attack time of the highpass filter envelope
|
* @param {number | Pattern} attack time of the highpass filter envelope
|
||||||
* @synonyms hpa
|
* @synonyms hpa
|
||||||
* @example
|
* @example
|
||||||
@@ -1378,7 +1378,7 @@ export const { hpattack, hpa } = registerControl('hpattack', 'hpa');
|
|||||||
/**
|
/**
|
||||||
* Sets the attack duration for the bandpass filter envelope.
|
* Sets the attack duration for the bandpass filter envelope.
|
||||||
* @name bpattack
|
* @name bpattack
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} attack time of the bandpass filter envelope
|
* @param {number | Pattern} attack time of the bandpass filter envelope
|
||||||
* @synonyms bpa
|
* @synonyms bpa
|
||||||
* @example
|
* @example
|
||||||
@@ -1392,7 +1392,7 @@ export const { bpattack, bpa } = registerControl('bpattack', 'bpa');
|
|||||||
/**
|
/**
|
||||||
* Sets the decay duration for the lowpass filter envelope.
|
* Sets the decay duration for the lowpass filter envelope.
|
||||||
* @name lpdecay
|
* @name lpdecay
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} decay time of the filter envelope
|
* @param {number | Pattern} decay time of the filter envelope
|
||||||
* @synonyms lpd
|
* @synonyms lpd
|
||||||
* @example
|
* @example
|
||||||
@@ -1406,7 +1406,7 @@ export const { lpdecay, lpd } = registerControl('lpdecay', 'lpd');
|
|||||||
/**
|
/**
|
||||||
* Sets the decay duration for the highpass filter envelope.
|
* Sets the decay duration for the highpass filter envelope.
|
||||||
* @name hpdecay
|
* @name hpdecay
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} decay time of the highpass filter envelope
|
* @param {number | Pattern} decay time of the highpass filter envelope
|
||||||
* @synonyms hpd
|
* @synonyms hpd
|
||||||
* @example
|
* @example
|
||||||
@@ -1421,7 +1421,7 @@ export const { hpdecay, hpd } = registerControl('hpdecay', 'hpd');
|
|||||||
/**
|
/**
|
||||||
* Sets the decay duration for the bandpass filter envelope.
|
* Sets the decay duration for the bandpass filter envelope.
|
||||||
* @name bpdecay
|
* @name bpdecay
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} decay time of the bandpass filter envelope
|
* @param {number | Pattern} decay time of the bandpass filter envelope
|
||||||
* @synonyms bpd
|
* @synonyms bpd
|
||||||
* @example
|
* @example
|
||||||
@@ -1436,7 +1436,7 @@ export const { bpdecay, bpd } = registerControl('bpdecay', 'bpd');
|
|||||||
/**
|
/**
|
||||||
* Sets the sustain amplitude for the lowpass filter envelope.
|
* Sets the sustain amplitude for the lowpass filter envelope.
|
||||||
* @name lpsustain
|
* @name lpsustain
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} sustain amplitude of the lowpass filter envelope
|
* @param {number | Pattern} sustain amplitude of the lowpass filter envelope
|
||||||
* @synonyms lps
|
* @synonyms lps
|
||||||
* @example
|
* @example
|
||||||
@@ -1451,7 +1451,7 @@ export const { lpsustain, lps } = registerControl('lpsustain', 'lps');
|
|||||||
/**
|
/**
|
||||||
* Sets the sustain amplitude for the highpass filter envelope.
|
* Sets the sustain amplitude for the highpass filter envelope.
|
||||||
* @name hpsustain
|
* @name hpsustain
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} sustain amplitude of the highpass filter envelope
|
* @param {number | Pattern} sustain amplitude of the highpass filter envelope
|
||||||
* @synonyms hps
|
* @synonyms hps
|
||||||
* @example
|
* @example
|
||||||
@@ -1466,7 +1466,7 @@ export const { hpsustain, hps } = registerControl('hpsustain', 'hps');
|
|||||||
/**
|
/**
|
||||||
* Sets the sustain amplitude for the bandpass filter envelope.
|
* Sets the sustain amplitude for the bandpass filter envelope.
|
||||||
* @name bpsustain
|
* @name bpsustain
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} sustain amplitude of the bandpass filter envelope
|
* @param {number | Pattern} sustain amplitude of the bandpass filter envelope
|
||||||
* @synonyms bps
|
* @synonyms bps
|
||||||
* @example
|
* @example
|
||||||
@@ -1481,7 +1481,7 @@ export const { bpsustain, bps } = registerControl('bpsustain', 'bps');
|
|||||||
/**
|
/**
|
||||||
* Sets the release time for the lowpass filter envelope.
|
* Sets the release time for the lowpass filter envelope.
|
||||||
* @name lprelease
|
* @name lprelease
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} release time of the filter envelope
|
* @param {number | Pattern} release time of the filter envelope
|
||||||
* @synonyms lpr
|
* @synonyms lpr
|
||||||
* @example
|
* @example
|
||||||
@@ -1497,7 +1497,7 @@ export const { lprelease, lpr } = registerControl('lprelease', 'lpr');
|
|||||||
/**
|
/**
|
||||||
* Sets the release time for the highpass filter envelope.
|
* Sets the release time for the highpass filter envelope.
|
||||||
* @name hprelease
|
* @name hprelease
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} release time of the highpass filter envelope
|
* @param {number | Pattern} release time of the highpass filter envelope
|
||||||
* @synonyms hpr
|
* @synonyms hpr
|
||||||
* @example
|
* @example
|
||||||
@@ -1513,7 +1513,7 @@ export const { hprelease, hpr } = registerControl('hprelease', 'hpr');
|
|||||||
/**
|
/**
|
||||||
* Sets the release time for the bandpass filter envelope.
|
* Sets the release time for the bandpass filter envelope.
|
||||||
* @name bprelease
|
* @name bprelease
|
||||||
* @tags filter, envelope, superdough, supradough
|
* @tags filter, envelope, superdough
|
||||||
* @param {number | Pattern} release time of the bandpass filter envelope
|
* @param {number | Pattern} release time of the bandpass filter envelope
|
||||||
* @synonyms bpr
|
* @synonyms bpr
|
||||||
* @example
|
* @example
|
||||||
@@ -1558,7 +1558,7 @@ export const { fanchor } = registerControl('fanchor');
|
|||||||
* When using mininotation, you can also optionally add the 'hpq' parameter, separated by ':'.
|
* When using mininotation, you can also optionally add the 'hpq' parameter, separated by ':'.
|
||||||
*
|
*
|
||||||
* @name hpf
|
* @name hpf
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} frequency audible between 0 and 20000
|
* @param {number | Pattern} frequency audible between 0 and 20000
|
||||||
* @synonyms hp, hcutoff
|
* @synonyms hp, hcutoff
|
||||||
* @example
|
* @example
|
||||||
@@ -1781,7 +1781,7 @@ export const { hpskew } = registerControl('hpskew');
|
|||||||
* Applies a vibrato to the frequency of the oscillator.
|
* Applies a vibrato to the frequency of the oscillator.
|
||||||
*
|
*
|
||||||
* @name vib
|
* @name vib
|
||||||
* @tags pitch, lfo, superdough, supradough
|
* @tags pitch, lfo, superdough
|
||||||
* @synonyms vibrato, v
|
* @synonyms vibrato, v
|
||||||
* @param {number | Pattern} frequency of the vibrato in hertz
|
* @param {number | Pattern} frequency of the vibrato in hertz
|
||||||
* @example
|
* @example
|
||||||
@@ -1799,7 +1799,7 @@ export const { vib, vibrato, v } = registerControl(['vib', 'vibmod'], 'vibrato',
|
|||||||
* Adds pink noise to the mix
|
* Adds pink noise to the mix
|
||||||
*
|
*
|
||||||
* @name noise
|
* @name noise
|
||||||
* @tags generators, superdough, supradough
|
* @tags generators, superdough
|
||||||
* @param {number | Pattern} wet wet amount
|
* @param {number | Pattern} wet wet amount
|
||||||
* @example
|
* @example
|
||||||
* sound("<white pink brown>/2")
|
* sound("<white pink brown>/2")
|
||||||
@@ -1809,7 +1809,7 @@ export const { noise } = registerControl('noise');
|
|||||||
* Sets the vibrato depth in semitones. Only has an effect if `vibrato` | `vib` | `v` is is also set
|
* Sets the vibrato depth in semitones. Only has an effect if `vibrato` | `vib` | `v` is is also set
|
||||||
*
|
*
|
||||||
* @name vibmod
|
* @name vibmod
|
||||||
* @tags pitch, lfo, superdough, supradough
|
* @tags pitch, lfo, superdough
|
||||||
* @synonyms vmod
|
* @synonyms vmod
|
||||||
* @param {number | Pattern} depth of vibrato (in semitones)
|
* @param {number | Pattern} depth of vibrato (in semitones)
|
||||||
* @example
|
* @example
|
||||||
@@ -1828,7 +1828,7 @@ export const { hcutoff, hpf, hp } = registerControl(['hcutoff', 'hresonance', 'h
|
|||||||
* Controls the **h**igh-**p**ass **q**-value.
|
* Controls the **h**igh-**p**ass **q**-value.
|
||||||
*
|
*
|
||||||
* @name hpq
|
* @name hpq
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} q resonance factor between 0 and 50
|
* @param {number | Pattern} q resonance factor between 0 and 50
|
||||||
* @synonyms hresonance
|
* @synonyms hresonance
|
||||||
* @example
|
* @example
|
||||||
@@ -1840,7 +1840,7 @@ export const { hresonance, hpq } = registerControl('hresonance', 'hpq');
|
|||||||
* Controls the **l**ow-**p**ass **q**-value.
|
* Controls the **l**ow-**p**ass **q**-value.
|
||||||
*
|
*
|
||||||
* @name lpq
|
* @name lpq
|
||||||
* @tags filter, superdough, supradough
|
* @tags filter, superdough
|
||||||
* @param {number | Pattern} q resonance factor between 0 and 50
|
* @param {number | Pattern} q resonance factor between 0 and 50
|
||||||
* @synonyms resonance
|
* @synonyms resonance
|
||||||
* @example
|
* @example
|
||||||
@@ -1870,7 +1870,7 @@ export const { djf } = registerControl('djf');
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @name delay
|
* @name delay
|
||||||
* @tags orbit, superdough, supradough
|
* @tags orbit, superdough
|
||||||
* @param {number | Pattern} level between 0 and 1
|
* @param {number | Pattern} level between 0 and 1
|
||||||
* @example
|
* @example
|
||||||
* s("bd bd").delay("<0 .25 .5 1>")
|
* s("bd bd").delay("<0 .25 .5 1>")
|
||||||
@@ -1884,7 +1884,7 @@ export const { delay } = registerControl(['delay', 'delaytime', 'delayfeedback']
|
|||||||
* Caution: Values >= 1 will result in a signal that gets louder and louder! Don't do it
|
* Caution: Values >= 1 will result in a signal that gets louder and louder! Don't do it
|
||||||
*
|
*
|
||||||
* @name delayfeedback
|
* @name delayfeedback
|
||||||
* @tags orbit, superdough, supradough
|
* @tags orbit, superdough
|
||||||
* @param {number | Pattern} feedback between 0 and 1
|
* @param {number | Pattern} feedback between 0 and 1
|
||||||
* @synonyms delayfb, dfb
|
* @synonyms delayfb, dfb
|
||||||
* @example
|
* @example
|
||||||
@@ -1893,24 +1893,11 @@ export const { delay } = registerControl(['delay', 'delaytime', 'delayfeedback']
|
|||||||
*/
|
*/
|
||||||
export const { delayfeedback, delayfb, dfb } = registerControl('delayfeedback', 'delayfb', 'dfb');
|
export const { delayfeedback, delayfb, dfb } = registerControl('delayfeedback', 'delayfb', 'dfb');
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the time of the delay effect.
|
|
||||||
*
|
|
||||||
* @name delayspeed
|
|
||||||
* @tags supradough
|
|
||||||
* @param {number | Pattern} delayspeed controls the pitch of the delay feedback
|
|
||||||
* @synonyms delayt, dt
|
|
||||||
* @example
|
|
||||||
* note("d d a# a".fast(2)).s("sawtooth").delay(.8).delaytime(1/2).delayspeed("<2 .5 -1 -2>")
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export const { delayspeed } = registerControl('delayspeed');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the time of the delay effect in seconds.
|
* Sets the time of the delay effect in seconds.
|
||||||
*
|
*
|
||||||
* @name delaytime
|
* @name delaytime
|
||||||
* @tags orbit, superdough, supradough
|
* @tags orbit, superdough
|
||||||
* @param {number | Pattern} delay in seconds
|
* @param {number | Pattern} delay in seconds
|
||||||
* @synonyms delayt, dt
|
* @synonyms delayt, dt
|
||||||
* @example
|
* @example
|
||||||
@@ -1918,7 +1905,6 @@ export const { delayspeed } = registerControl('delayspeed');
|
|||||||
* .s("sawtooth")
|
* .s("sawtooth")
|
||||||
* .delay(.8)
|
* .delay(.8)
|
||||||
* .delaytime(1/2)
|
* .delaytime(1/2)
|
||||||
* .delayspeed("<2 .5 -1 -2>")
|
|
||||||
*/
|
*/
|
||||||
export const { delaytime, delayt, dt } = registerControl('delaytime', 'delayt', 'dt');
|
export const { delaytime, delayt, dt } = registerControl('delaytime', 'delayt', 'dt');
|
||||||
|
|
||||||
@@ -2026,7 +2012,7 @@ export const { freq } = registerControl('freq');
|
|||||||
* Attack time of pitch envelope.
|
* Attack time of pitch envelope.
|
||||||
*
|
*
|
||||||
* @name pattack
|
* @name pattack
|
||||||
* @tags pitch, envelope, superdough, supradough
|
* @tags pitch, envelope, superdough
|
||||||
* @synonyms patt
|
* @synonyms patt
|
||||||
* @param {number | Pattern} time time in seconds
|
* @param {number | Pattern} time time in seconds
|
||||||
* @example
|
* @example
|
||||||
@@ -2038,7 +2024,7 @@ export const { pattack, patt } = registerControl('pattack', 'patt');
|
|||||||
* Decay time of pitch envelope.
|
* Decay time of pitch envelope.
|
||||||
*
|
*
|
||||||
* @name pdecay
|
* @name pdecay
|
||||||
* @tags pitch, envelope, superdough, supradough
|
* @tags pitch, envelope, superdough
|
||||||
* @synonyms pdec
|
* @synonyms pdec
|
||||||
* @param {number | Pattern} time time in seconds
|
* @param {number | Pattern} time time in seconds
|
||||||
* @example
|
* @example
|
||||||
@@ -2052,7 +2038,7 @@ export const { psustain, psus } = registerControl('psustain', 'psus');
|
|||||||
* Release time of pitch envelope
|
* Release time of pitch envelope
|
||||||
*
|
*
|
||||||
* @name prelease
|
* @name prelease
|
||||||
* @tags pitch, envelope, superdough, supradough
|
* @tags pitch, envelope, superdough
|
||||||
* @synonyms prel
|
* @synonyms prel
|
||||||
* @param {number | Pattern} time time in seconds
|
* @param {number | Pattern} time time in seconds
|
||||||
* @example
|
* @example
|
||||||
@@ -2067,7 +2053,7 @@ export const { prelease, prel } = registerControl('prelease', 'prel');
|
|||||||
* If you don't set other pitch envelope controls, `pattack:.2` will be the default.
|
* If you don't set other pitch envelope controls, `pattack:.2` will be the default.
|
||||||
*
|
*
|
||||||
* @name penv
|
* @name penv
|
||||||
* @tags pitch, envelope, superdough, supradough
|
* @tags pitch, envelope, superdough
|
||||||
* @param {number | Pattern} semitones change in semitones
|
* @param {number | Pattern} semitones change in semitones
|
||||||
* @example
|
* @example
|
||||||
* note("c")
|
* note("c")
|
||||||
@@ -2248,7 +2234,7 @@ export const { overshape } = registerControl('overshape');
|
|||||||
* Sets position in stereo.
|
* Sets position in stereo.
|
||||||
*
|
*
|
||||||
* @name pan
|
* @name pan
|
||||||
* @tags superdough, supradough
|
* @tags superdough
|
||||||
* @param {number | Pattern} pan between 0 and 1, from left to right (assuming stereo), once round a circle (assuming multichannel)
|
* @param {number | Pattern} pan between 0 and 1, from left to right (assuming stereo), once round a circle (assuming multichannel)
|
||||||
* @example
|
* @example
|
||||||
* s("[bd hh]*2").pan("<.5 1 .5 0>")
|
* s("[bd hh]*2").pan("<.5 1 .5 0>")
|
||||||
@@ -2506,7 +2492,7 @@ export const { shape } = registerControl(['shape', 'shapevol']);
|
|||||||
* Most useful values are usually between 0 and 10 (depending on source gain). If you are feeling adventurous, you can turn it up to 11 and beyond ;)
|
* Most useful values are usually between 0 and 10 (depending on source gain). If you are feeling adventurous, you can turn it up to 11 and beyond ;)
|
||||||
*
|
*
|
||||||
* @name distort
|
* @name distort
|
||||||
* @tags distortion, superdough, supradough
|
* @tags distortion, superdough
|
||||||
* @synonyms dist
|
* @synonyms dist
|
||||||
* @param {number | Pattern} distortion amount of distortion to apply
|
* @param {number | Pattern} distortion amount of distortion to apply
|
||||||
* @param {number | Pattern} volume linear postgain of the distortion
|
* @param {number | Pattern} volume linear postgain of the distortion
|
||||||
@@ -2526,7 +2512,7 @@ export const { distort, dist } = registerControl(['distort', 'distortvol', 'dist
|
|||||||
*
|
*
|
||||||
* @name distortvol
|
* @name distortvol
|
||||||
* @synonyms distortion, distvol
|
* @synonyms distortion, distvol
|
||||||
* @tags superdough, supradough
|
* @tags superdough
|
||||||
* @param {number | Pattern} volume linear postgain of the distortion
|
* @param {number | Pattern} volume linear postgain of the distortion
|
||||||
* @example
|
* @example
|
||||||
* s("bd*4").bank("tr909").distort(2).distortvol(0.8)
|
* s("bd*4").bank("tr909").distort(2).distortvol(0.8)
|
||||||
@@ -2537,7 +2523,7 @@ export const { distortvol } = registerControl('distortvol', 'distvol');
|
|||||||
* Type of waveshaping distortion to apply.
|
* Type of waveshaping distortion to apply.
|
||||||
*
|
*
|
||||||
* @name distorttype
|
* @name distorttype
|
||||||
* @tags distortion, superdough, supradough
|
* @tags distortion, superdough
|
||||||
* @synonyms disttype
|
* @synonyms disttype
|
||||||
* @param {number | string | Pattern} type type of distortion to apply
|
* @param {number | string | Pattern} type type of distortion to apply
|
||||||
* @example
|
* @example
|
||||||
|
|||||||
+88
-23
@@ -28,31 +28,34 @@ export class Cyclist {
|
|||||||
this.started = false;
|
this.started = false;
|
||||||
this.beforeStart = beforeStart;
|
this.beforeStart = beforeStart;
|
||||||
this.cps = 0.5;
|
this.cps = 0.5;
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.checkpoint = {
|
||||||
|
// new checkpoints are created when there's a change in cps
|
||||||
|
cycles: 0, // number of cycles when cps was changed
|
||||||
|
seconds: 0, // clock phase when cps was changed
|
||||||
|
};
|
||||||
|
this.num_ticks_since_checkpoint = 0;
|
||||||
this.lastTick = 0; // absolute time when last tick (clock callback) happened
|
this.lastTick = 0; // absolute time when last tick (clock callback) happened
|
||||||
this.lastBegin = 0; // query begin of last tick
|
this.lastBegin = 0; // query begin of last tick
|
||||||
this.lastEnd = 0; // query end of last tick
|
this.lastEnd = 0; // query end of last tick
|
||||||
this.getTime = getTime; // get absolute time
|
this.getTime = getTime; // get absolute time
|
||||||
this.num_cycles_at_cps_change = 0;
|
|
||||||
this.seconds_at_cps_change; // clock phase when cps was changed
|
|
||||||
this.onToggle = onToggle;
|
this.onToggle = onToggle;
|
||||||
this.latency = latency; // fixed trigger time offset
|
this.latency = latency; // fixed trigger time offset
|
||||||
this.clock = createClock(
|
this.clock = createClock(
|
||||||
getTime,
|
getTime,
|
||||||
// called slightly before each cycle
|
// called slightly before each cycle
|
||||||
(phase, duration, _, t) => {
|
(phase, duration, _, t) => {
|
||||||
if (this.num_ticks_since_cps_change === 0) {
|
if (this.num_ticks_since_checkpoint === 0) {
|
||||||
this.num_cycles_at_cps_change = this.lastEnd;
|
this.checkpoint = {
|
||||||
this.seconds_at_cps_change = phase;
|
cycles: this.lastEnd,
|
||||||
|
seconds: phase,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this.num_ticks_since_cps_change++;
|
this.num_ticks_since_checkpoint++;
|
||||||
const seconds_since_cps_change = this.num_ticks_since_cps_change * duration;
|
|
||||||
const num_cycles_since_cps_change = seconds_since_cps_change * this.cps;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const begin = this.lastEnd;
|
var begin = this.lastEnd;
|
||||||
this.lastBegin = begin;
|
this.lastBegin = begin;
|
||||||
const end = this.num_cycles_at_cps_change + num_cycles_since_cps_change;
|
var end = this.checkpoint.cycles + this.num_ticks_since_checkpoint * duration * this.cps;
|
||||||
this.lastEnd = end;
|
this.lastEnd = end;
|
||||||
this.lastTick = phase;
|
this.lastTick = phase;
|
||||||
|
|
||||||
@@ -62,20 +65,79 @@ export class Cyclist {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// query the pattern for events
|
const tickEndTime = phase + duration;
|
||||||
const haps = this.pattern.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' });
|
|
||||||
|
|
||||||
haps.forEach((hap) => {
|
var cpsChanged = false;
|
||||||
if (hap.hasOnset()) {
|
do {
|
||||||
const targetTime =
|
cpsChanged = false;
|
||||||
(hap.whole.begin - this.num_cycles_at_cps_change) / this.cps + this.seconds_at_cps_change + latency;
|
|
||||||
onSchedule?.(hap, targetTime, this.cps);
|
// query the pattern for events
|
||||||
|
const haps = this.pattern
|
||||||
|
.queryArc(begin, end, { _cps: this.cps, cyclist: 'cyclist' })
|
||||||
|
.filter((hap) => hap.hasOnset())
|
||||||
|
// Sort the haps based on their onset, so cps changes within the
|
||||||
|
// tick duration happen in the correct order.
|
||||||
|
.sort((a, b) => {
|
||||||
|
const aBegin = a.whole.begin;
|
||||||
|
const bBegin = b.whole.begin;
|
||||||
|
// If haps happen at the same time, trigger the haps that cause
|
||||||
|
// cps changes first, so the durations of the simultaneous haps
|
||||||
|
// are adjusted accordingly.
|
||||||
|
if (aBegin.eq(bBegin)) {
|
||||||
|
if (a.value.cps !== undefined) {
|
||||||
|
return b.value.cps !== undefined ? 0 : -1;
|
||||||
|
}
|
||||||
|
if (b.value.cps !== undefined) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return aBegin.sub(bBegin);
|
||||||
|
});
|
||||||
|
|
||||||
|
haps.forEach((hap) => {
|
||||||
|
const targetTime = (hap.whole.begin - this.checkpoint.cycles) / this.cps + this.checkpoint.seconds;
|
||||||
|
if (tickEndTime < targetTime) {
|
||||||
|
// If the targetTime exceeds the tickEndTime, this means
|
||||||
|
// the cps has slowed down, and the latter haps from the query
|
||||||
|
// no longer fall within the window of the current tick.
|
||||||
|
// They'll be scheduled during the next tick.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSchedule?.(hap, targetTime + this.latency, hap.value.cps ?? this.cps);
|
||||||
if (hap.value.cps !== undefined && this.cps != hap.value.cps) {
|
if (hap.value.cps !== undefined && this.cps != hap.value.cps) {
|
||||||
|
cpsChanged = true;
|
||||||
this.cps = hap.value.cps;
|
this.cps = hap.value.cps;
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.num_ticks_since_checkpoint = 0;
|
||||||
|
this.checkpoint = {
|
||||||
|
cycles: hap.whole.begin,
|
||||||
|
seconds: targetTime,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If there are any haps in the query that trigger changes to the
|
||||||
|
// cps that result in the pattern speeding up, the current cycle end
|
||||||
|
// may not capture all the haps that need to be scheduled.
|
||||||
|
// If this is the case, we repeat the query + scheduling with a
|
||||||
|
// newly calculated end time.
|
||||||
|
// This process can repeat multiple times until no additional
|
||||||
|
// changes to the cps are triggered.
|
||||||
|
// In practice, this doesn't happen more than once during a tick.
|
||||||
|
if (cpsChanged) {
|
||||||
|
begin = end;
|
||||||
|
const remainingSecondsSinceCheckpoint = tickEndTime - this.checkpoint.seconds;
|
||||||
|
const remainingCycles = remainingSecondsSinceCheckpoint * this.cps;
|
||||||
|
end = this.checkpoint.cycles + remainingCycles;
|
||||||
|
this.lastEnd = end;
|
||||||
|
if (end < begin) {
|
||||||
|
// If the new end is before the old end this means the track
|
||||||
|
// slowed down, so we don't need to schedule additional haps.
|
||||||
|
// Otherwise, schedule the remaining events.
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
} while (cpsChanged);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorLogger(e);
|
errorLogger(e);
|
||||||
onError?.(e);
|
onError?.(e);
|
||||||
@@ -101,8 +163,11 @@ export class Cyclist {
|
|||||||
}
|
}
|
||||||
async start() {
|
async start() {
|
||||||
await this.beforeStart?.();
|
await this.beforeStart?.();
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.checkpoint = {
|
||||||
this.num_cycles_at_cps_change = 0;
|
cycles: 0,
|
||||||
|
seconds: 0,
|
||||||
|
};
|
||||||
|
this.num_ticks_since_checkpoint = 0;
|
||||||
if (!this.pattern) {
|
if (!this.pattern) {
|
||||||
throw new Error('Scheduler: no pattern set! call .setPattern first.');
|
throw new Error('Scheduler: no pattern set! call .setPattern first.');
|
||||||
}
|
}
|
||||||
@@ -132,7 +197,7 @@ export class Cyclist {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.cps = cps;
|
this.cps = cps;
|
||||||
this.num_ticks_since_cps_change = 0;
|
this.num_ticks_since_checkpoint = 0;
|
||||||
}
|
}
|
||||||
log(begin, end, haps) {
|
log(begin, end, haps) {
|
||||||
const onsets = haps.filter((h) => h.hasOnset());
|
const onsets = haps.filter((h) => h.hasOnset());
|
||||||
|
|||||||
@@ -5,34 +5,6 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export const strudelScope = {};
|
export const strudelScope = {};
|
||||||
// Make strudelScope available globally so transpiled code can access it
|
|
||||||
globalThis.strudelScope = strudelScope;
|
|
||||||
|
|
||||||
// Track user-defined keys (from block-based eval) so we can clear them without removing strudel functions
|
|
||||||
export const userDefinedKeys = new Set();
|
|
||||||
globalThis.userDefinedKeys = userDefinedKeys;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears all user-defined variables and functions from the scope.
|
|
||||||
* This removes variables created during block-based evaluation.
|
|
||||||
* @name clearScope
|
|
||||||
* @example
|
|
||||||
* // After defining variables in blocks:
|
|
||||||
* // let myVar = 5
|
|
||||||
* // function myFunc() { return 10; }
|
|
||||||
* clearScope() // removes myVar and myFunc from scope
|
|
||||||
*/
|
|
||||||
export const clearScope = () => {
|
|
||||||
for (const key of userDefinedKeys) {
|
|
||||||
delete strudelScope[key];
|
|
||||||
delete globalThis[key];
|
|
||||||
}
|
|
||||||
userDefinedKeys.clear();
|
|
||||||
// Return silence if available (for use in pattern expressions), otherwise undefined
|
|
||||||
return globalThis.silence;
|
|
||||||
};
|
|
||||||
// Make clearScope available globally
|
|
||||||
globalThis.clearScope = clearScope;
|
|
||||||
|
|
||||||
export const evalScope = async (...args) => {
|
export const evalScope = async (...args) => {
|
||||||
const results = await Promise.allSettled(args);
|
const results = await Promise.allSettled(args);
|
||||||
|
|||||||
@@ -2354,8 +2354,8 @@ export const ply = register('ply', function (factor, pat) {
|
|||||||
* @example
|
* @example
|
||||||
* s("bd hh sd hh").fast(2) // s("[bd hh sd hh]*2")
|
* s("bd hh sd hh").fast(2) // s("[bd hh sd hh]*2")
|
||||||
*/
|
*/
|
||||||
export const { fast, density } = register(
|
export const fast = register(
|
||||||
['fast', 'density'],
|
'fast',
|
||||||
function (factor, pat) {
|
function (factor, pat) {
|
||||||
if (factor === 0) {
|
if (factor === 0) {
|
||||||
return silence;
|
return silence;
|
||||||
|
|||||||
+35
-295
@@ -45,7 +45,6 @@ export function repl({
|
|||||||
pattern: undefined,
|
pattern: undefined,
|
||||||
miniLocations: [],
|
miniLocations: [],
|
||||||
widgets: [],
|
widgets: [],
|
||||||
sliders: [],
|
|
||||||
pending: false,
|
pending: false,
|
||||||
started: false,
|
started: false,
|
||||||
};
|
};
|
||||||
@@ -87,132 +86,11 @@ export function repl({
|
|||||||
let allTransform;
|
let allTransform;
|
||||||
let eachTransform;
|
let eachTransform;
|
||||||
|
|
||||||
// Block-based evaluation state
|
|
||||||
let codeBlocks = {};
|
|
||||||
let lastActiveVisualizerLabel = null;
|
|
||||||
// Track which patterns belong to which blocks: { blockRange: [patternKeys] }
|
|
||||||
let blockPatterns = new Map();
|
|
||||||
|
|
||||||
// Helper function to collect properties from all code blocks (handles both labeled and anonymous blocks)
|
|
||||||
function collectFromBlocks(property) {
|
|
||||||
return Object.entries(codeBlocks).flatMap(([key, block]) => {
|
|
||||||
if (key === '$') {
|
|
||||||
// Anonymous blocks are stored as an array of block objects
|
|
||||||
return Array.isArray(block) ? block.flatMap((b) => b[property] || []) : [];
|
|
||||||
}
|
|
||||||
// Labeled blocks are stored as single block objects
|
|
||||||
return block[property] || [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to process a single labeled block
|
|
||||||
function processLabeledBlock(labels, i, code, options, meta) {
|
|
||||||
const label = labels[i];
|
|
||||||
const nextLabel = labels[i + 1] || { index: code.length, end: code.length };
|
|
||||||
|
|
||||||
const labelCode = code.slice(label.index, nextLabel.index);
|
|
||||||
const labelRange = [label.index + options.range[0], label.end + options.range[0]];
|
|
||||||
|
|
||||||
// Calculate the full block range (from label start to next label start)
|
|
||||||
const blockStart = label.index + options.range[0];
|
|
||||||
const blockEnd = nextLabel.index + options.range[0];
|
|
||||||
|
|
||||||
const blockWidgets = (meta?.widgets || []).filter((widget) => {
|
|
||||||
const widgetPos = widget.from ?? widget.index ?? 0;
|
|
||||||
return widgetPos >= blockStart && widgetPos < blockEnd;
|
|
||||||
});
|
|
||||||
|
|
||||||
const blockSliders = (meta?.sliders || []).filter((slider) => {
|
|
||||||
const sliderPos = slider.from ?? slider.index ?? 0;
|
|
||||||
return sliderPos >= blockStart && sliderPos < blockEnd;
|
|
||||||
});
|
|
||||||
|
|
||||||
const blockMiniLocations = (meta?.miniLocations || []).filter((loc) => {
|
|
||||||
// const locStart = loc.start ?? loc.from ?? 0;
|
|
||||||
// mini locations can be either [start, end] arrays or objects with start/from
|
|
||||||
const locStart = Array.isArray(loc) ? loc[0] : (loc.start ?? loc.from ?? 0);
|
|
||||||
return locStart >= blockStart && locStart < blockEnd;
|
|
||||||
});
|
|
||||||
|
|
||||||
handleSingleLabelBlock(
|
|
||||||
label,
|
|
||||||
labelCode,
|
|
||||||
{ ...options, range: labelRange },
|
|
||||||
{ widgets: blockWidgets, sliders: blockSliders, miniLocations: blockMiniLocations },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper
|
|
||||||
function cleanupConflictingRanges(codeBlocks, currentKey, newRange) {
|
|
||||||
for (const [existingKey, existingBlock] of Object.entries(codeBlocks)) {
|
|
||||||
if (existingKey === currentKey) continue;
|
|
||||||
if (!existingBlock.range) continue;
|
|
||||||
|
|
||||||
const [existingStart, existingEnd] = existingBlock.range;
|
|
||||||
const [newStart, newEnd] = newRange;
|
|
||||||
|
|
||||||
// If ranges overlap (not just touch), remove the stale block
|
|
||||||
if (!(newEnd <= existingStart || newStart >= existingEnd)) {
|
|
||||||
delete codeBlocks[existingKey];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper
|
|
||||||
function handleSingleLabelBlock(label, code, options, meta) {
|
|
||||||
// Detect if this block contains a non-inline widget
|
|
||||||
// The activeVisualizer is now provided by the transpiler for all labels
|
|
||||||
const activeVisualizer = label.activeVisualizer || null;
|
|
||||||
|
|
||||||
if (activeVisualizer !== null) {
|
|
||||||
lastActiveVisualizerLabel = label.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the entire code block under the label name
|
|
||||||
codeBlocks[label.name] = {
|
|
||||||
code: code,
|
|
||||||
range: options.range,
|
|
||||||
labels: [label.name],
|
|
||||||
miniLocations: meta?.miniLocations || [],
|
|
||||||
widgets: meta?.widgets || [],
|
|
||||||
sliders: meta?.sliders || [],
|
|
||||||
activeVisualizer: activeVisualizer, // Store the widget type if present, null otherwise
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clean up any blocks with conflicting ranges (including declaration blocks)
|
|
||||||
cleanupConflictingRanges(codeBlocks, label.name, options.range);
|
|
||||||
}
|
|
||||||
|
|
||||||
// helper
|
|
||||||
// These blocks return silence but may contain mini notation strings that need highlighting
|
|
||||||
function handleDeclarationBlock(code, options, meta) {
|
|
||||||
const range = options.range || [];
|
|
||||||
if (range.length < 2) return;
|
|
||||||
|
|
||||||
const blockKey = `_decl:${range[0]}:${range[1]}`;
|
|
||||||
|
|
||||||
codeBlocks[blockKey] = {
|
|
||||||
code: code,
|
|
||||||
range: range,
|
|
||||||
labels: [],
|
|
||||||
miniLocations: meta?.miniLocations || [],
|
|
||||||
widgets: meta?.widgets || [],
|
|
||||||
sliders: meta?.sliders || [],
|
|
||||||
activeVisualizer: null,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clean up any overlapping declaration blocks
|
|
||||||
cleanupConflictingRanges(codeBlocks, blockKey, range);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hush = function () {
|
const hush = function () {
|
||||||
pPatterns = {};
|
pPatterns = {};
|
||||||
anonymousIndex = 0;
|
anonymousIndex = 0;
|
||||||
allTransform = undefined;
|
allTransform = undefined;
|
||||||
eachTransform = undefined;
|
eachTransform = undefined;
|
||||||
codeBlocks = {};
|
|
||||||
blockPatterns.clear();
|
|
||||||
lastActiveVisualizerLabel = null; // Reset 'all' visualizer tracking
|
|
||||||
return silence;
|
return silence;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -233,60 +111,7 @@ export function repl({
|
|||||||
setTime(() => scheduler.now()); // TODO: refactor?
|
setTime(() => scheduler.now()); // TODO: refactor?
|
||||||
setClockTime(() => scheduler.getTime()); // TODO: refactor?
|
setClockTime(() => scheduler.getTime()); // TODO: refactor?
|
||||||
|
|
||||||
// Helper function to apply pattern transformations (solo, each, all)
|
const stop = () => scheduler.stop();
|
||||||
// this should be abstracted more
|
|
||||||
function applyPatternTransforms(pattern) {
|
|
||||||
const allPatterns = Object.values(pPatterns);
|
|
||||||
|
|
||||||
if (allPatterns.length) {
|
|
||||||
let patterns = [];
|
|
||||||
let soloActive = false;
|
|
||||||
for (const [key, value] of Object.entries(pPatterns)) {
|
|
||||||
// handle soloed patterns ex: S$: s("bd!4")
|
|
||||||
const isSolod = key.length > 1 && key.startsWith('S');
|
|
||||||
if (isSolod && soloActive === false) {
|
|
||||||
// first time we see a soloed pattern, clear existing patterns
|
|
||||||
patterns = [];
|
|
||||||
soloActive = true;
|
|
||||||
}
|
|
||||||
if (!soloActive || (soloActive && isSolod)) {
|
|
||||||
const valWithState = value.withState((state) => state.setControls({ id: key }));
|
|
||||||
patterns.push(valWithState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (eachTransform) {
|
|
||||||
// Explicit lambda so only element (not index and array) are passed
|
|
||||||
patterns = patterns.map((x) => eachTransform(x));
|
|
||||||
}
|
|
||||||
pattern = stack(...patterns);
|
|
||||||
} else if (eachTransform) {
|
|
||||||
pattern = eachTransform(pattern);
|
|
||||||
}
|
|
||||||
if (allTransforms.length) {
|
|
||||||
for (const transform of allTransforms) {
|
|
||||||
pattern = transform(pattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isPattern(pattern)) {
|
|
||||||
pattern = silence;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pattern;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stop = () => {
|
|
||||||
codeBlocks = {};
|
|
||||||
blockPatterns.clear();
|
|
||||||
pPatterns = {};
|
|
||||||
lastActiveVisualizerLabel = null; // Reset 'all' visualizer tracking
|
|
||||||
updateState({
|
|
||||||
miniLocations: [],
|
|
||||||
widgets: [],
|
|
||||||
sliders: [],
|
|
||||||
});
|
|
||||||
scheduler.stop();
|
|
||||||
};
|
|
||||||
const start = () => scheduler.start();
|
const start = () => scheduler.start();
|
||||||
const pause = () => scheduler.pause();
|
const pause = () => scheduler.pause();
|
||||||
const toggle = () => scheduler.toggle();
|
const toggle = () => scheduler.toggle();
|
||||||
@@ -407,7 +232,7 @@ export function repl({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const evaluate = async (code, autostart = true) => {
|
const evaluate = async (code, autostart = true, shouldHush = true) => {
|
||||||
if (!code) {
|
if (!code) {
|
||||||
throw new Error('no code to evaluate');
|
throw new Error('no code to evaluate');
|
||||||
}
|
}
|
||||||
@@ -416,132 +241,47 @@ export function repl({
|
|||||||
await injectPatternMethods();
|
await injectPatternMethods();
|
||||||
setTime(() => scheduler.now()); // TODO: refactor?
|
setTime(() => scheduler.now()); // TODO: refactor?
|
||||||
setClockTime(() => scheduler.getTime()); // TODO: refactor?
|
setClockTime(() => scheduler.getTime()); // TODO: refactor?
|
||||||
await beforeEval?.({ code, blockBased: false });
|
await beforeEval?.({ code });
|
||||||
allTransforms = []; // reset all transforms
|
allTransforms = []; // reset all transforms
|
||||||
|
shouldHush && hush();
|
||||||
codeBlocks = {};
|
|
||||||
hush();
|
|
||||||
|
|
||||||
if (mondo) {
|
if (mondo) {
|
||||||
code = `mondolang\`${code}\``;
|
code = `mondolang\`${code}\``;
|
||||||
}
|
}
|
||||||
|
|
||||||
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
|
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
|
||||||
|
if (Object.keys(pPatterns).length) {
|
||||||
pattern = applyPatternTransforms(pattern);
|
let patterns = [];
|
||||||
|
let soloActive = false;
|
||||||
logger(`[eval] code updated`);
|
for (const [key, value] of Object.entries(pPatterns)) {
|
||||||
pattern = await setPattern(pattern, autostart);
|
// handle soloed patterns ex: S$: s("bd!4")
|
||||||
updateState({
|
const isSolod = key.length > 1 && key.startsWith('S');
|
||||||
miniLocations: meta?.miniLocations || [],
|
if (isSolod && soloActive === false) {
|
||||||
widgets: meta?.widgets || [],
|
// first time we see a soloed pattern, clear existing patterns
|
||||||
sliders: meta?.sliders || [],
|
patterns = [];
|
||||||
activeCode: code,
|
soloActive = true;
|
||||||
pattern,
|
}
|
||||||
evalError: undefined,
|
if (!soloActive || (soloActive && isSolod)) {
|
||||||
schedulerError: undefined,
|
const valWithState = value.withState((state) => state.setControls({ id: key }));
|
||||||
pending: false,
|
patterns.push(valWithState);
|
||||||
});
|
|
||||||
|
|
||||||
afterEval?.({ code, pattern, meta, range: undefined, widgetRemoved: false });
|
|
||||||
return pattern;
|
|
||||||
} catch (err) {
|
|
||||||
logger(`[eval] error: ${err.message}`, 'error');
|
|
||||||
console.error(err);
|
|
||||||
updateState({ evalError: err, pending: false });
|
|
||||||
onEvalError?.(err);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const evaluateBlock = async (code, autostart = true, options = {}) => {
|
|
||||||
if (!code) {
|
|
||||||
throw new Error('no code to evaluate');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
updateState({ code, pending: true });
|
|
||||||
await injectPatternMethods();
|
|
||||||
setTime(() => scheduler.now()); // TODO: refactor?
|
|
||||||
setClockTime(() => scheduler.getTime()); // TODO: refactor?
|
|
||||||
await beforeEval?.({ code, blockBased: true });
|
|
||||||
allTransforms = []; // reset all transforms
|
|
||||||
|
|
||||||
const transpilerOptionsWithBlock = {
|
|
||||||
...transpilerOptions,
|
|
||||||
blockBased: true,
|
|
||||||
range: options.range || [],
|
|
||||||
};
|
|
||||||
|
|
||||||
if (mondo) {
|
|
||||||
code = `mondolang\`${code}\``;
|
|
||||||
}
|
|
||||||
|
|
||||||
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptionsWithBlock);
|
|
||||||
|
|
||||||
// Track activeVisualizer cleanup: check if any block's visualizer was removed
|
|
||||||
let widgetRemoved = false;
|
|
||||||
|
|
||||||
const labels = meta.labels || [];
|
|
||||||
|
|
||||||
// Check for anonymous labels (labels starting with '$')
|
|
||||||
const hasAnonymousLabel = labels.some((label) => label.name.startsWith('$'));
|
|
||||||
|
|
||||||
// Store code blocks in dictionary using labels as keys
|
|
||||||
if (hasAnonymousLabel) {
|
|
||||||
// variable/function declarations that don't return patterns are allowed,
|
|
||||||
// but anonymous pattern blocks pose an issue for block-based evaluation
|
|
||||||
// if an anonymous pattern is evaluated multiple times it will just stack and get louder and louder
|
|
||||||
|
|
||||||
// it's very common for users to write code prefixed with '$'
|
|
||||||
// but to modify and override existing patterns, the patterns must be labeled,
|
|
||||||
// otherwise we'll have no idea of which pattern is being overridden
|
|
||||||
|
|
||||||
// (we probably need to update the docs on this)
|
|
||||||
// we could easily enable it, but it would confuse a lot of people
|
|
||||||
|
|
||||||
throw new Error(
|
|
||||||
'anonymous labels disabled for block based evaluation (see https://strudel.cc/blog/#label-notation)',
|
|
||||||
);
|
|
||||||
} else if (labels.length > 0) {
|
|
||||||
for (let i = 0; i < labels.length; i++) {
|
|
||||||
// processing transpiler output instead of code is simply to avoid
|
|
||||||
// extra regex in detecting whether or not an inline widget has been commented out
|
|
||||||
processLabeledBlock(labels, i, meta.output, options, meta);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Declaration block (variable/function that returns silence)
|
|
||||||
// Store it so its miniLocations are preserved for highlighting patterns stored in variables
|
|
||||||
handleDeclarationBlock(code, options, meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
meta.miniLocations = collectFromBlocks('miniLocations');
|
|
||||||
meta.widgets = collectFromBlocks('widgets');
|
|
||||||
meta.sliders = collectFromBlocks('sliders');
|
|
||||||
|
|
||||||
// Track activeVisualizer cleanup: check if any block's visualizer was removed
|
|
||||||
const blocksToUpdate = labels.map((label) => label.name);
|
|
||||||
|
|
||||||
// this is the hackiest bit
|
|
||||||
for (const [key, block] of Object.entries(codeBlocks)) {
|
|
||||||
if (blocksToUpdate.includes(key)) {
|
|
||||||
// This block was just updated
|
|
||||||
if (block.activeVisualizer !== null) {
|
|
||||||
// Block now has a visualizer, update tracking
|
|
||||||
lastActiveVisualizerLabel = key;
|
|
||||||
} else if (lastActiveVisualizerLabel === key) {
|
|
||||||
// This block lost its visualizer, trigger cleanup
|
|
||||||
widgetRemoved = true;
|
|
||||||
lastActiveVisualizerLabel = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (eachTransform) {
|
||||||
|
// Explicit lambda so only element (not index and array) are passed
|
||||||
|
patterns = patterns.map((x) => eachTransform(x));
|
||||||
|
}
|
||||||
|
pattern = stack(...patterns);
|
||||||
|
} else if (eachTransform) {
|
||||||
|
pattern = eachTransform(pattern);
|
||||||
|
}
|
||||||
|
if (allTransforms.length) {
|
||||||
|
for (const transform of allTransforms) {
|
||||||
|
pattern = transform(pattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pPatterns = Object.fromEntries(
|
if (!isPattern(pattern)) {
|
||||||
Object.entries(pPatterns).filter(([key]) => {
|
pattern = silence;
|
||||||
return Object.keys(codeBlocks).includes(key);
|
}
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
pattern = applyPatternTransforms(pattern);
|
|
||||||
|
|
||||||
logger(`[eval] code updated`);
|
logger(`[eval] code updated`);
|
||||||
pattern = await setPattern(pattern, autostart);
|
pattern = await setPattern(pattern, autostart);
|
||||||
@@ -556,7 +296,7 @@ export function repl({
|
|||||||
pending: false,
|
pending: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEval?.({ code, pattern, meta, range: options.range, widgetRemoved });
|
afterEval?.({ code, pattern, meta });
|
||||||
return pattern;
|
return pattern;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger(`[eval] error: ${err.message}`, 'error');
|
logger(`[eval] error: ${err.message}`, 'error');
|
||||||
@@ -567,7 +307,7 @@ export function repl({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const setCode = (code) => updateState({ code });
|
const setCode = (code) => updateState({ code });
|
||||||
return { scheduler, evaluate, evaluateBlock, start, stop, pause, setCps, setPattern, setCode, toggle, state };
|
return { scheduler, evaluate, start, stop, pause, setCps, setPattern, setCode, toggle, state };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getSchedule =
|
export const getSchedule =
|
||||||
|
|||||||
@@ -420,7 +420,7 @@ export const binaryNL = (n, nBits = 16) => {
|
|||||||
* .partials(randL(8))
|
* .partials(randL(8))
|
||||||
*/
|
*/
|
||||||
export const randL = (n) => {
|
export const randL = (n) => {
|
||||||
return signal((t) => (nVal) => getRandsAtTime(t, nVal).map(Math.abs)).appLeft(reify(n));
|
return signal((t, controls) => (nVal) => getRandsAtTime(t, nVal, controls.randSeed).map(Math.abs)).appLeft(reify(n));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const randrun = (n) => {
|
export const randrun = (n) => {
|
||||||
@@ -1143,3 +1143,26 @@ export const perx = new Pattern(function (state) {
|
|||||||
const n = Fraction(1).div(state.span.duration);
|
const n = Fraction(1).div(state.span.duration);
|
||||||
return [new Hap(undefined, state.span, Math.log(n) / Math.log(2) + 1)];
|
return [new Hap(undefined, state.span, Math.log(n) / Math.log(2) + 1)];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A signal that goes from `0` to `1` over one cycle, and then stays at `1` forever.
|
||||||
|
* Mainly useful in combination with other functions that reset the cycle. See also
|
||||||
|
* `close`.
|
||||||
|
* @tags temporal
|
||||||
|
* @example
|
||||||
|
* sound("bd sd [- bd] sd".fast(2))
|
||||||
|
* .lpf(open.slow(4).range(300,3000)) // close envelope over 4 cycles
|
||||||
|
* .restart("x/4") // restart every 4 cycles
|
||||||
|
*/
|
||||||
|
export const open = signal((t) => t.min(1));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The same as `open`, but goes from `1` to `0` over one cycle, and then
|
||||||
|
* stays on `0` forever.
|
||||||
|
* @tags temporal
|
||||||
|
* @example
|
||||||
|
* sound("bd sd [- bd] sd".fast(2))
|
||||||
|
* .lpf(close.slow(4).range(300,3000)) // close envelope over 4 cycles
|
||||||
|
* .restart("x/4") // restart every 4 cycles
|
||||||
|
*/
|
||||||
|
export const close = signal((t) => Fraction(1).sub(t).max(0));
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel/core": "workspace:*",
|
"@strudel/core": "workspace:*",
|
||||||
|
"@strudel/osc": "workspace:*",
|
||||||
"@strudel/webaudio": "workspace:*",
|
"@strudel/webaudio": "workspace:*",
|
||||||
"@tauri-apps/api": "^2.2.0"
|
"@tauri-apps/api": "^2.2.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ 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/>.
|
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 { register, noteToMidi } from '@strudel/core';
|
import { register } from '@strudel/core';
|
||||||
import { Dough, doughsamples } from 'dough-synth';
|
import { Dough, doughsamples } from 'dough-synth';
|
||||||
import { getAudioContext, ensureMinimalOutput } from '@strudel/webaudio';
|
import { getAudioContext, ensureMinimalOutput } from '@strudel/webaudio';
|
||||||
import wasm from 'dough-synth/dough.wasm?url';
|
import wasm from 'dough-synth/dough.wasm?url';
|
||||||
import workletCode from 'dough-synth/dough.js?raw';
|
import workletCode from 'dough-synth/dough.js?raw';
|
||||||
|
import { hap2dough } from './lib.mjs';
|
||||||
|
export * from './lib.mjs';
|
||||||
|
|
||||||
Object.assign(globalThis, { doughsamples });
|
Object.assign(globalThis, { doughsamples });
|
||||||
|
|
||||||
@@ -42,16 +44,8 @@ export async function doughOutput(hap, targetTime, cps = 1) {
|
|||||||
if (!offset) {
|
if (!offset) {
|
||||||
return; // not ready
|
return; // not ready
|
||||||
}
|
}
|
||||||
hap.ensureObjectValue();
|
const t = targetTime - offset;
|
||||||
const event = {
|
const event = hap2dough(hap, t, cps);
|
||||||
dough: 'play',
|
|
||||||
...hap.value,
|
|
||||||
time: targetTime - offset,
|
|
||||||
duration: hap.duration / cps,
|
|
||||||
};
|
|
||||||
if (typeof event.note === 'string') {
|
|
||||||
event.note = noteToMidi(event.note);
|
|
||||||
}
|
|
||||||
D.evaluate(event);
|
D.evaluate(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import { register, registerControl, stack, Pattern, noteToMidi } from '@strudel/core';
|
||||||
|
|
||||||
|
export const { group } = registerControl('group');
|
||||||
|
export const { voices } = registerControl('voices');
|
||||||
|
export const { glide } = registerControl('glide');
|
||||||
|
|
||||||
|
export const groupmod = register('groupmod', function (modulator, pat) {
|
||||||
|
const modpat = modulator
|
||||||
|
.withValue((vm) => pat.withValue(({ group }) => ({ ...vm, group })))
|
||||||
|
.outerJoin()
|
||||||
|
.set({ dough: 'update_group' });
|
||||||
|
return stack(pat.set(modulator), modpat);
|
||||||
|
});
|
||||||
|
Pattern.prototype.gmod = Pattern.prototype.groupmod;
|
||||||
|
|
||||||
|
export function hap2dough(hap, time, cps) {
|
||||||
|
hap.ensureObjectValue();
|
||||||
|
const event = {
|
||||||
|
dough: 'play',
|
||||||
|
...hap.value,
|
||||||
|
time,
|
||||||
|
duration: hap.duration / cps,
|
||||||
|
};
|
||||||
|
if (typeof event.note === 'string') {
|
||||||
|
event.note = noteToMidi(event.note);
|
||||||
|
}
|
||||||
|
return event;
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel/core": "workspace:*",
|
"@strudel/core": "workspace:*",
|
||||||
"@strudel/webaudio": "workspace:*",
|
"@strudel/webaudio": "workspace:*",
|
||||||
"dough-synth": "0.2.4"
|
"dough-synth": "0.4.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^6.0.11"
|
"vite": "^6.0.11"
|
||||||
|
|||||||
@@ -78,16 +78,6 @@ export const cleanupDraw = (clearScreen = true, id) => {
|
|||||||
stopAllAnimations(id);
|
stopAllAnimations(id);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const cleanupDrawContext = (replID) => {
|
|
||||||
const ctx = getDrawContext();
|
|
||||||
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
||||||
|
|
||||||
// clear the big canvas context, ignore inline widgets
|
|
||||||
Object.keys(animationFrames).forEach(
|
|
||||||
(id) => (!replID || id.startsWith(replID)) && !id.startsWith('_') && stopAnimationFrame(id),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
Pattern.prototype.onPaint = function (painter) {
|
Pattern.prototype.onPaint = function (painter) {
|
||||||
return this.withState((state) => {
|
return this.withState((state) => {
|
||||||
if (!state.controls.painters) {
|
if (!state.controls.painters) {
|
||||||
|
|||||||
@@ -4,3 +4,4 @@ export * from './draw.mjs';
|
|||||||
export * from './pianoroll.mjs';
|
export * from './pianoroll.mjs';
|
||||||
export * from './spiral.mjs';
|
export * from './spiral.mjs';
|
||||||
export * from './pitchwheel.mjs';
|
export * from './pitchwheel.mjs';
|
||||||
|
export * from './print.mjs';
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
print.mjs - prints hap values to the console or a scrollable inline widget
|
||||||
|
Copyright (C) 2022 Strudel contributors - see
|
||||||
|
<https://codeberg.org/uzu/strudel/src/branch/main/packages/draw/print.mjs> This
|
||||||
|
program is free software: you can redistribute it and/or modify it under the
|
||||||
|
terms of the GNU Affero General Public License as published by the Free Software
|
||||||
|
Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
version. This program is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
|
||||||
|
more details. You should have received a copy of the GNU Affero General Public
|
||||||
|
License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { logger, Pattern, stringifyValues } from '@strudel/core';
|
||||||
|
|
||||||
|
const printed = {};
|
||||||
|
|
||||||
|
// counts .print() calls within one synchronous evaluation, then resets for the
|
||||||
|
// next
|
||||||
|
let printIndex = 0;
|
||||||
|
let printIndexResetQueued = false;
|
||||||
|
function nextPrintIndex() {
|
||||||
|
const index = printIndex++;
|
||||||
|
if (!printIndexResetQueued) {
|
||||||
|
printIndexResetQueued = true;
|
||||||
|
queueMicrotask(() => {
|
||||||
|
printIndex = 0;
|
||||||
|
printIndexResetQueued = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatTime(hap, round, padding) {
|
||||||
|
const begin = hap.wholeOrPart().begin;
|
||||||
|
if (round === 0) {
|
||||||
|
return String(begin.sam().valueOf()).padEnd(padding);
|
||||||
|
}
|
||||||
|
const factor = 10 ** round;
|
||||||
|
const time = Math.round(begin.valueOf() * factor) / factor;
|
||||||
|
return String(time).padEnd(padding + round + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendLine(el, text, maxLines) {
|
||||||
|
const line = document.createElement('div');
|
||||||
|
line.textContent = text;
|
||||||
|
el.appendChild(line);
|
||||||
|
while (el.childElementCount > maxLines) {
|
||||||
|
el.removeChild(el.firstChild);
|
||||||
|
}
|
||||||
|
if (el.follow) {
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the values of a pattern's events. Without a leading underscore, prints
|
||||||
|
* to the existing console panel, labeled with its position among other
|
||||||
|
* `print()` calls, e.g. `[print(line:1)]`. With the `_` prefix, it shows a
|
||||||
|
* scrollable widget inside the code instead, and its content resets on
|
||||||
|
* every (re-)evaluation.
|
||||||
|
*
|
||||||
|
* @name print
|
||||||
|
* @tags visualization
|
||||||
|
* @param {number} width widget width in px, `_print` only. defaults to 600
|
||||||
|
* @param {number} height widget height in px, `_print` only. defaults to 100
|
||||||
|
* @param {number} maxLines max lines kept, `_print` only. defaults to 500
|
||||||
|
* @param {number} round decimal digits for the event time. defaults to 4. `0`
|
||||||
|
* shows only the cycle
|
||||||
|
* @param {number} padding integer digits reserved for the cycle, so it stays
|
||||||
|
* aligned once cycles reach 10 or 100. defaults to 3
|
||||||
|
* @example
|
||||||
|
* s("bd sd hh cp").print()
|
||||||
|
* @example
|
||||||
|
* s("bd sd hh*2 cp")._print({ round: 5 })
|
||||||
|
*/
|
||||||
|
Pattern.prototype.print = function (options = {}) {
|
||||||
|
const { el, id = 1, maxLines = 500, round = 4, padding = 3 } = options;
|
||||||
|
if (!el) {
|
||||||
|
const label = `print(line:${nextPrintIndex() + 1})`;
|
||||||
|
return this.onTrigger((hap) => {
|
||||||
|
logger(`[${label}] ${formatTime(hap, round, padding)}: ${stringifyValues(hap.value, true)}`);
|
||||||
|
}, false);
|
||||||
|
}
|
||||||
|
printed[id] = new WeakSet();
|
||||||
|
return this.draw(
|
||||||
|
(haps) => {
|
||||||
|
haps
|
||||||
|
.filter((hap) => !printed[id].has(hap))
|
||||||
|
.forEach((hap) => {
|
||||||
|
printed[id].add(hap);
|
||||||
|
appendLine(el, `${formatTime(hap, round, padding)}: ${stringifyValues(hap.value, true)}`, maxLines);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{ lookbehind: 0, lookahead: 0, id },
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://codeberg.org/uzu/strudel/",
|
"homepage": "https://codeberg.org/uzu/strudel/",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"web-tree-sitter": "^0.24.7"
|
"web-tree-sitter": "^0.24.7",
|
||||||
|
"tree-sitter-haskell": "^0.23.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tree-sitter-haskell": "^0.23.1",
|
|
||||||
"vite": "^6.0.11"
|
"vite": "^6.0.11"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import Parser from 'web-tree-sitter';
|
import Parser from 'web-tree-sitter';
|
||||||
|
import treeSitterWasm from 'web-tree-sitter/tree-sitter.wasm?url';
|
||||||
|
import grammarWasm from 'tree-sitter-haskell/tree-sitter-haskell.wasm?url';
|
||||||
|
|
||||||
let base = '/';
|
let base;
|
||||||
export function setBase(path) {
|
export function setBase(path) {
|
||||||
base = path;
|
base = path;
|
||||||
}
|
}
|
||||||
@@ -10,11 +12,15 @@ let isReady = false,
|
|||||||
async function _loadParser() {
|
async function _loadParser() {
|
||||||
await Parser.init({
|
await Parser.init({
|
||||||
locateFile(scriptName, scriptDirectory) {
|
locateFile(scriptName, scriptDirectory) {
|
||||||
return `${base}${scriptName}`;
|
if (base) {
|
||||||
|
return `${base}${scriptName}`;
|
||||||
|
}
|
||||||
|
return treeSitterWasm;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
parser = new Parser();
|
parser = new Parser();
|
||||||
const Lang = await Parser.Language.load(`${base}tree-sitter-haskell.wasm`);
|
let grammarUrl = base ? `${base}tree-sitter-haskell.wasm` : grammarWasm;
|
||||||
|
const Lang = await Parser.Language.load(grammarUrl);
|
||||||
parser.setLanguage(Lang);
|
parser.setLanguage(Lang);
|
||||||
isReady = true;
|
isReady = true;
|
||||||
return parser;
|
return parser;
|
||||||
|
|||||||
+10
-1
@@ -55,6 +55,7 @@ export function parseControlsFromHap(hap, cps) {
|
|||||||
return controls;
|
return controls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let timeOrigin = performance.timeOrigin;
|
||||||
export async function oscOutput(hap, targetTime, cps = 1) {
|
export async function oscOutput(hap, targetTime, cps = 1) {
|
||||||
const ws = await connect();
|
const ws = await connect();
|
||||||
|
|
||||||
@@ -63,7 +64,15 @@ export async function oscOutput(hap, targetTime, cps = 1) {
|
|||||||
logger('[osc] clockbridge not ready');
|
logger('[osc] clockbridge not ready');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const ts = performance.timeOrigin + timeMs;
|
// when the system sleeps while the browser is open, performance.now() doesnt tick
|
||||||
|
// .. which means performance.timeOrigin + performance.now() doesnt land in the present
|
||||||
|
const deprivation = timeOrigin + performance.now() - Date.now();
|
||||||
|
if (Math.abs(deprivation) > 20) {
|
||||||
|
console.log(`[osc] snap with ${(deprivation / 1000).toFixed(2)}s deprivation`);
|
||||||
|
// shift time after microsleep
|
||||||
|
timeOrigin -= deprivation;
|
||||||
|
}
|
||||||
|
const ts = timeOrigin + timeMs;
|
||||||
|
|
||||||
const controls = parseControlsFromHap(hap, cps);
|
const controls = parseControlsFromHap(hap, cps);
|
||||||
const keyvals = Object.entries(controls).flat();
|
const keyvals = Object.entries(controls).flat();
|
||||||
|
|||||||
@@ -43,7 +43,8 @@
|
|||||||
"@strudel/soundfonts": "workspace:*",
|
"@strudel/soundfonts": "workspace:*",
|
||||||
"@strudel/tonal": "workspace:*",
|
"@strudel/tonal": "workspace:*",
|
||||||
"@strudel/transpiler": "workspace:*",
|
"@strudel/transpiler": "workspace:*",
|
||||||
"@strudel/webaudio": "workspace:*"
|
"@strudel/webaudio": "workspace:*",
|
||||||
|
"@strudel/websocket": "workspace:*"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rollup/plugin-replace": "^6.0.2",
|
"@rollup/plugin-replace": "^6.0.2",
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ export async function prebake() {
|
|||||||
import('@strudel/hydra'),
|
import('@strudel/hydra'),
|
||||||
import('@strudel/soundfonts'),
|
import('@strudel/soundfonts'),
|
||||||
import('@strudel/midi'),
|
import('@strudel/midi'),
|
||||||
|
import('@strudel/websocket'),
|
||||||
// import('@strudel/xen'),
|
// import('@strudel/xen'),
|
||||||
// import('@strudel/serial'),
|
// import('@strudel/serial'),
|
||||||
// import('@strudel/csound'),
|
// import('@strudel/csound'),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ async function loadFont(name) {
|
|||||||
const url = `${soundfontUrl}/${name}.js`;
|
const url = `${soundfontUrl}/${name}.js`;
|
||||||
const preset = await fetch(url).then((res) => res.text());
|
const preset = await fetch(url).then((res) => res.text());
|
||||||
let [_, data] = preset.split('={');
|
let [_, data] = preset.split('={');
|
||||||
return eval('{' + data);
|
return new Function('return {' + data)().zones;
|
||||||
};
|
};
|
||||||
loadCache[name] = load();
|
loadCache[name] = load();
|
||||||
return loadCache[name];
|
return loadCache[name];
|
||||||
|
|||||||
@@ -25,8 +25,16 @@ export class ClockBridge {
|
|||||||
}
|
}
|
||||||
const offset = performanceTime - contextTime * 1000; // clock offset in ms
|
const offset = performanceTime - contextTime * 1000; // clock offset in ms
|
||||||
const dt = performanceTime - (this.lastTime ?? performanceTime); // delta time since last hap
|
const dt = performanceTime - (this.lastTime ?? performanceTime); // delta time since last hap
|
||||||
const decay = 1 / 10000; // how fast offset changes have an effect
|
const deprivation = offset - this.p;
|
||||||
this.p = expDecay(this.p ?? offset, offset, decay, dt); // smooth clock offset
|
// when the system sleeps, the audio and system clock get jumbled
|
||||||
|
// so we dont smooth if the jump is too high, to snap the offset
|
||||||
|
if (Math.abs(deprivation) > 20) {
|
||||||
|
console.log(`[ClockBridge] snap with ${(deprivation / 1000).toFixed(2)}s deprivation`);
|
||||||
|
this.p = offset;
|
||||||
|
} else {
|
||||||
|
const decay = 1 / 10000; // how fast offset changes have an effect
|
||||||
|
this.p = expDecay(this.p ?? offset, offset, decay, dt); // smooth clock offset
|
||||||
|
}
|
||||||
this.lastTime = performanceTime;
|
this.lastTime = performanceTime;
|
||||||
return this.p;
|
return this.p;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
pattern.wav
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# supradough
|
|
||||||
|
|
||||||
platform agnostic synth and sampler intended for live coding. a reimplementation of superdough.
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
// this is a poc of how a pattern can be rendered as a wav file using node
|
|
||||||
// run via: node dough-export.mjs
|
|
||||||
import fs from 'node:fs';
|
|
||||||
import WavEncoder from 'wav-encoder';
|
|
||||||
import { evalScope } from '@strudel/core';
|
|
||||||
import { miniAllStrings } from '@strudel/mini';
|
|
||||||
import { Dough } from './dough.mjs';
|
|
||||||
|
|
||||||
await evalScope(
|
|
||||||
import('@strudel/core'),
|
|
||||||
import('@strudel/mini'),
|
|
||||||
import('@strudel/tonal'),
|
|
||||||
// import('@strudel/tonal'),
|
|
||||||
);
|
|
||||||
|
|
||||||
miniAllStrings(); // allows using single quotes for mini notation / skip transpilation
|
|
||||||
|
|
||||||
let sampleRate = 48000,
|
|
||||||
cps = 0.4;
|
|
||||||
|
|
||||||
/* await doughsamples('github:eddyflux/crate');
|
|
||||||
await doughsamples('github:eddyflux/wax'); */
|
|
||||||
|
|
||||||
let pat = note('c,eb,g,<bb c4 d4 eb4>')
|
|
||||||
.s('sine')
|
|
||||||
.press()
|
|
||||||
.add(note(24))
|
|
||||||
.fmi(3)
|
|
||||||
.fmh(5.01)
|
|
||||||
.dec(0.4)
|
|
||||||
.delay('.6:<.12 .22>:.8')
|
|
||||||
.jux(press)
|
|
||||||
.rarely(add(note('12')))
|
|
||||||
.lpf(400)
|
|
||||||
.lpq(0.2)
|
|
||||||
.lpd(0.4)
|
|
||||||
.lpenv(3)
|
|
||||||
.fmdecay(0.4)
|
|
||||||
.fmenv(1)
|
|
||||||
.postgain(0.6)
|
|
||||||
.stack(s('<pink white>*8').dec(0.07).rarely(ply('2')).delay(0.5).hpf(sine.range(200, 2000).slow(4)).hpq(0.2))
|
|
||||||
.stack(
|
|
||||||
s('[- white@3]*2')
|
|
||||||
.dec(0.4)
|
|
||||||
.hpf('<2000!3 <4000 8000>>*4')
|
|
||||||
.hpq(0.6)
|
|
||||||
.ply('<1 2>*4')
|
|
||||||
.postgain(0.5)
|
|
||||||
.delay(0.5)
|
|
||||||
.jux(rev)
|
|
||||||
.lpf(5000),
|
|
||||||
)
|
|
||||||
.stack(
|
|
||||||
note('<c2 - [- f1] ->*2')
|
|
||||||
.s('square')
|
|
||||||
.lpf(sine.range(100, 300).slow(4))
|
|
||||||
.lpe(1)
|
|
||||||
.segment(8)
|
|
||||||
.lpd(0.3)
|
|
||||||
.lpq(0.2)
|
|
||||||
.dec(0.2)
|
|
||||||
.speed('<1 2>')
|
|
||||||
.ply('<1 2>')
|
|
||||||
.postgain(1),
|
|
||||||
)
|
|
||||||
.stack(
|
|
||||||
chord('<Cm Cm7 Cm9 Cm11 Fm Fm7 Fm9 Fm11>')
|
|
||||||
.voicing()
|
|
||||||
.s('<sine>')
|
|
||||||
.clip(1)
|
|
||||||
.rel(0.4)
|
|
||||||
.vib('4:.2')
|
|
||||||
.gain(0.7)
|
|
||||||
.hpf(1200)
|
|
||||||
.fm(0.5)
|
|
||||||
.att(1)
|
|
||||||
.lpa(0.5)
|
|
||||||
.lpf(200)
|
|
||||||
.lpenv(4)
|
|
||||||
.chorus(0.8),
|
|
||||||
)
|
|
||||||
.slow(1 / cps);
|
|
||||||
|
|
||||||
let cycles = 30;
|
|
||||||
let seconds = cycles + 1; // 1s release tail
|
|
||||||
const haps = pat.queryArc(0, cycles);
|
|
||||||
|
|
||||||
const dough = new Dough(sampleRate);
|
|
||||||
|
|
||||||
console.log('spawn voices...');
|
|
||||||
haps.forEach((hap) => {
|
|
||||||
hap.value._begin = Number(hap.whole.begin);
|
|
||||||
hap.value._duration = hap.duration /* / cps */;
|
|
||||||
dough.scheduleSpawn(hap.value);
|
|
||||||
});
|
|
||||||
console.log(`render ${seconds}s long buffer, each dot is 1 second:`);
|
|
||||||
const buffers = [new Float32Array(seconds * sampleRate), new Float32Array(seconds * sampleRate)];
|
|
||||||
let t = performance.now();
|
|
||||||
while (dough.t <= buffers[0].length) {
|
|
||||||
dough.update();
|
|
||||||
buffers[0][dough.t] = dough.out[0];
|
|
||||||
buffers[1][dough.t] = dough.out[1];
|
|
||||||
if (dough.t % sampleRate === 0) {
|
|
||||||
process.stdout.write('.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const took = (performance.now() - t) / 1000;
|
|
||||||
const load = (took / seconds) * 100;
|
|
||||||
const speed = (seconds / took).toFixed(2);
|
|
||||||
console.log('');
|
|
||||||
console.log(`done!
|
|
||||||
rendered ${seconds}s in ${took.toFixed(2)}s
|
|
||||||
speed: ${speed}x
|
|
||||||
load: ${load.toFixed(2)}%`);
|
|
||||||
|
|
||||||
const patternAudio = {
|
|
||||||
sampleRate,
|
|
||||||
channelData: buffers,
|
|
||||||
};
|
|
||||||
|
|
||||||
WavEncoder.encode(patternAudio).then((buffer) => {
|
|
||||||
fs.writeFileSync('pattern.wav', new Float32Array(buffer));
|
|
||||||
});
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
import { Dough } from './dough.mjs';
|
|
||||||
|
|
||||||
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
|
|
||||||
|
|
||||||
class DoughProcessor extends AudioWorkletProcessor {
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
this.dough = new Dough(sampleRate, currentTime);
|
|
||||||
this.port.onmessage = (event) => {
|
|
||||||
if (event.data.spawn) {
|
|
||||||
this.dough.scheduleSpawn(event.data.spawn);
|
|
||||||
} else if (event.data.sample) {
|
|
||||||
this.dough.loadSample(event.data.sample, event.data.channels, event.data.sampleRate);
|
|
||||||
} else if (event.data.samples) {
|
|
||||||
event.data.samples.forEach(([name, channels, sampleRate]) => {
|
|
||||||
this.dough.loadSample(name, channels, sampleRate);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
console.log('unrecognized event type', event.data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
process(inputs, outputs, params) {
|
|
||||||
if (this.disconnected) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const output = outputs[0];
|
|
||||||
for (let i = 0; i < output[0].length; i++) {
|
|
||||||
this.dough.update();
|
|
||||||
for (let c = 0; c < output.length; c++) {
|
|
||||||
//prevent speaker blowout via clipping if threshold exceeds
|
|
||||||
output[c][i] = clamp(this.dough.out[c], -1, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true; // keep the audio processing going
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
registerProcessor('dough-processor', DoughProcessor);
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +0,0 @@
|
|||||||
// import _workletUrl from './dough-worklet.mjs?url'; // only for dev (breaks for production build)
|
|
||||||
import _workletUrl from './dough-worklet.mjs?audioworklet'; // only for prod (breaks in development?!)
|
|
||||||
|
|
||||||
export * from './dough.mjs';
|
|
||||||
export const workletUrl = _workletUrl;
|
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Experimental Tidal Code interpreter",
|
"description": "Experimental Tidal Code interpreter",
|
||||||
|
"main": "tidal.mjs",
|
||||||
"module": "tidal.mjs",
|
"module": "tidal.mjs",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import './tonal.mjs';
|
import './tonal.mjs';
|
||||||
import './voicings.mjs';
|
import './voicings.mjs';
|
||||||
import './ireal.mjs';
|
|
||||||
|
|
||||||
export * from './tonal.mjs';
|
export * from './tonal.mjs';
|
||||||
export * from './voicings.mjs';
|
export * from './voicings.mjs';
|
||||||
export * from './ireal.mjs';
|
|
||||||
|
import './ireal.mjs';
|
||||||
|
|
||||||
export const packageName = '@strudel/tonal';
|
export const packageName = '@strudel/tonal';
|
||||||
|
|||||||
@@ -39,15 +39,11 @@ const sliderTranspilerPlugin = {
|
|||||||
if (!isSliderFunction(node)) return;
|
if (!isSliderFunction(node)) return;
|
||||||
context.widgets ??= [];
|
context.widgets ??= [];
|
||||||
context.sliders ??= [];
|
context.sliders ??= [];
|
||||||
const { options, widgets, sliders, nodeOffset } = context;
|
const { options, widgets, sliders } = context;
|
||||||
const { emitWidgets } = options;
|
const { emitWidgets } = options;
|
||||||
const from = node.arguments[0].start + nodeOffset;
|
|
||||||
const to = node.arguments[0].end + nodeOffset;
|
|
||||||
const id = `${from}:${to}`; // Range-based ID for stability
|
|
||||||
const sliderConfig = {
|
const sliderConfig = {
|
||||||
from,
|
from: node.arguments[0].start,
|
||||||
to,
|
to: node.arguments[0].end,
|
||||||
id,
|
|
||||||
value: node.arguments[0].raw, // don't use value!
|
value: node.arguments[0].raw, // don't use value!
|
||||||
min: node.arguments[1]?.value ?? 0,
|
min: node.arguments[1]?.value ?? 0,
|
||||||
max: node.arguments[2]?.value ?? 1,
|
max: node.arguments[2]?.value ?? 1,
|
||||||
@@ -56,7 +52,7 @@ const sliderTranspilerPlugin = {
|
|||||||
};
|
};
|
||||||
emitWidgets && widgets.push(sliderConfig);
|
emitWidgets && widgets.push(sliderConfig);
|
||||||
sliders.push(sliderConfig);
|
sliders.push(sliderConfig);
|
||||||
return this.replace(sliderWithLocation(node, nodeOffset));
|
return this.replace(sliderWithLocation(node));
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -73,13 +69,8 @@ function isWidgetMethod(node) {
|
|||||||
return node.type === 'CallExpression' && widgetMethods.includes(node.callee.property?.name);
|
return node.type === 'CallExpression' && widgetMethods.includes(node.callee.property?.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sliderWithLocation(node, nodeOffset = 0) {
|
function sliderWithLocation(node) {
|
||||||
// Apply nodeOffset for block-based evaluation to generate correct range
|
const id = 'slider_' + node.arguments[0].start; // use loc of first arg for id
|
||||||
const from = node.arguments[0].start + nodeOffset;
|
|
||||||
const to = node.arguments[0].end + nodeOffset;
|
|
||||||
|
|
||||||
// Use range-based ID for stability during block evaluation
|
|
||||||
const id = `${from}:${to}`;
|
|
||||||
|
|
||||||
// add loc as identifier to first argument
|
// add loc as identifier to first argument
|
||||||
// the sliderWithID function is assumed to be sliderWithID(id, value, min?, max?)
|
// the sliderWithID function is assumed to be sliderWithID(id, value, min?, max?)
|
||||||
@@ -95,26 +86,14 @@ function sliderWithLocation(node, nodeOffset = 0) {
|
|||||||
export function getWidgetID(widgetConfig) {
|
export function getWidgetID(widgetConfig) {
|
||||||
// the widget id is used as id for the dom element + as key for eventual resources
|
// the widget id is used as id for the dom element + as key for eventual resources
|
||||||
// for example, for each scope widget, a new analyser + buffer (large) is created
|
// for example, for each scope widget, a new analyser + buffer (large) is created
|
||||||
// Update: use range-based ID generation for better stability during block evaluation
|
// that means, if we use the index index of line position as id, less garbage is generated
|
||||||
// When we have both from and to, use them together for stability
|
// return `widget_${widgetConfig.to}`; // more gargabe
|
||||||
// Otherwise fall back to position-based ID for backward compatibility
|
//return `widget_${widgetConfig.index}_${widgetConfig.to}`; // also more garbage
|
||||||
let uniqueIdentifier;
|
return `${widgetConfig.id || ''}_widget_${widgetConfig.type}_${widgetConfig.index}`; // less garbage
|
||||||
if (widgetConfig.from !== undefined && widgetConfig.to !== undefined) {
|
|
||||||
// Use range for more stable identification
|
|
||||||
uniqueIdentifier = `${widgetConfig.from}-${widgetConfig.to}`;
|
|
||||||
} else {
|
|
||||||
// Fallback to single position (for backward compatibility)
|
|
||||||
uniqueIdentifier = widgetConfig.to || widgetConfig.from || 0;
|
|
||||||
}
|
|
||||||
const baseId = `${widgetConfig.id || ''}_widget_${widgetConfig.type}`;
|
|
||||||
return `${baseId}_${widgetConfig.index}_${uniqueIdentifier}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function widgetWithLocation(node, widgetConfig) {
|
function widgetWithLocation(node, widgetConfig) {
|
||||||
const id = getWidgetID(widgetConfig);
|
const id = getWidgetID(widgetConfig);
|
||||||
// Store the unique ID back into the config so it's available for widget management
|
|
||||||
// This is critical for block-based evaluation to match existing widgets with new ones
|
|
||||||
widgetConfig.id = id;
|
|
||||||
// add loc as identifier to first argument
|
// add loc as identifier to first argument
|
||||||
// the sliderWithID function is assumed to be sliderWithID(id, value, min?, max?)
|
// the sliderWithID function is assumed to be sliderWithID(id, value, min?, max?)
|
||||||
node.arguments.unshift({
|
node.arguments.unshift({
|
||||||
|
|||||||
@@ -35,12 +35,10 @@ export function transpiler(input, options = {}) {
|
|||||||
addReturn: true,
|
addReturn: true,
|
||||||
emitMiniLocations: true,
|
emitMiniLocations: true,
|
||||||
emitWidgets: true,
|
emitWidgets: true,
|
||||||
blockBased: false,
|
|
||||||
range: [],
|
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { wrapAsync, addReturn, emitMiniLocations, emitWidgets, blockBased, range } = options;
|
const { wrapAsync, addReturn, emitMiniLocations, emitWidgets } = options;
|
||||||
|
|
||||||
const comments = [];
|
const comments = [];
|
||||||
let ast = parse(input, {
|
let ast = parse(input, {
|
||||||
@@ -52,67 +50,21 @@ export function transpiler(input, options = {}) {
|
|||||||
|
|
||||||
let miniDisableRanges = findMiniDisableRanges(comments, input.length);
|
let miniDisableRanges = findMiniDisableRanges(comments, input.length);
|
||||||
|
|
||||||
// Position offset for block-based evaluation
|
|
||||||
let nodeOffset = range && range.length > 0 ? range[0] : 0;
|
|
||||||
|
|
||||||
// Track declarations to add to strudelScope for block-based eval
|
|
||||||
let scopeDeclarations = [];
|
|
||||||
|
|
||||||
let labels = [];
|
let labels = [];
|
||||||
|
|
||||||
const context = { options, input, nodeOffset, miniDisableRanges, labels };
|
const context = { options, input, miniDisableRanges, labels };
|
||||||
const plugins = getPlugins().map((plugin) => plugin.walk?.(context));
|
const plugins = getPlugins().map((plugin) => plugin.walk?.(context));
|
||||||
|
|
||||||
walk(ast, {
|
walk(ast, {
|
||||||
enter(node, parent, prop, index) {
|
enter(node, parent, prop, index) {
|
||||||
// Apply position offset for block-based evaluation
|
|
||||||
if (blockBased && node.start !== undefined) {
|
|
||||||
node.start = node.start + nodeOffset;
|
|
||||||
node.end = node.end + nodeOffset;
|
|
||||||
}
|
|
||||||
// Collect variable and function declarations for strudelScope (block-based eval)
|
|
||||||
if (blockBased && parent?.type === 'Program') {
|
|
||||||
if (node.type === 'VariableDeclaration') {
|
|
||||||
for (const declarator of node.declarations) {
|
|
||||||
if (declarator.id?.name) {
|
|
||||||
scopeDeclarations.push(declarator.id.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (node.type === 'FunctionDeclaration' && node.id?.name) {
|
|
||||||
scopeDeclarations.push(node.id.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const plugin of plugins) {
|
for (const plugin of plugins) {
|
||||||
if (!plugin?.enter?.call(this, node, parent, prop, index)) continue;
|
if (!plugin?.enter?.call(this, node, parent, prop, index)) continue;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLabelStatement(node)) {
|
if (isLabelStatement(node)) {
|
||||||
// Collect label info for block-based evaluation
|
|
||||||
// Store positions WITHOUT offset so repl can slice the transpiler output correctly
|
|
||||||
if (blockBased) {
|
|
||||||
labels.push({
|
|
||||||
name: node.label.name,
|
|
||||||
index: node.start - nodeOffset,
|
|
||||||
end: node.label.end - nodeOffset,
|
|
||||||
fullMatch: input.slice(node.start - nodeOffset, node.label.end - nodeOffset),
|
|
||||||
activeVisualizer: findVisualizerInSubtree(node.body),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return this.replace(labelToP(node));
|
return this.replace(labelToP(node));
|
||||||
}
|
}
|
||||||
// Detect all() calls as special labels for block management
|
|
||||||
// Store positions WITHOUT offset so repl can slice the transpiler output correctly
|
|
||||||
if (blockBased && isAllCall(node)) {
|
|
||||||
labels.push({
|
|
||||||
name: 'all',
|
|
||||||
index: node.start - nodeOffset,
|
|
||||||
end: node.end - nodeOffset,
|
|
||||||
fullMatch: input.slice(node.start - nodeOffset, node.end - nodeOffset),
|
|
||||||
activeVisualizer: node.arguments[0] ? findVisualizerInSubtree(node.arguments[0]) : null,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
leave(node, parent, prop, index) {
|
leave(node, parent, prop, index) {
|
||||||
@@ -141,14 +93,6 @@ export function transpiler(input, options = {}) {
|
|||||||
body.push(silenceExpression);
|
body.push(silenceExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For block-based eval, add scope assignments before the return statement
|
|
||||||
// This allows variables/functions defined in one block to be used in other blocks
|
|
||||||
if (blockBased && scopeDeclarations.length > 0) {
|
|
||||||
const scopeAssignments = scopeDeclarations.flatMap((name) => createScopeAssignment(name));
|
|
||||||
// Insert scope assignments before the last statement (which will become the return)
|
|
||||||
body.splice(body.length - 1, 0, ...scopeAssignments);
|
|
||||||
}
|
|
||||||
|
|
||||||
// add return to last statement
|
// add return to last statement
|
||||||
if (addReturn) {
|
if (addReturn) {
|
||||||
const { expression } = body[body.length - 1];
|
const { expression } = body[body.length - 1];
|
||||||
@@ -166,7 +110,7 @@ export function transpiler(input, options = {}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let pluginContext;
|
let pluginContext;
|
||||||
({ options, input, miniDisableRanges, nodeOffset, ...pluginContext } = context);
|
({ options, input, miniDisableRanges, ...pluginContext } = context);
|
||||||
|
|
||||||
return { output, ...pluginContext };
|
return { output, ...pluginContext };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
export * from './webaudio.mjs';
|
export * from './webaudio.mjs';
|
||||||
export * from './scope.mjs';
|
export * from './scope.mjs';
|
||||||
export * from './spectrum.mjs';
|
export * from './spectrum.mjs';
|
||||||
export * from './supradough.mjs';
|
|
||||||
export * from 'superdough';
|
export * from 'superdough';
|
||||||
|
|||||||
@@ -35,8 +35,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel/core": "workspace:*",
|
"@strudel/core": "workspace:*",
|
||||||
"@strudel/draw": "workspace:*",
|
"@strudel/draw": "workspace:*",
|
||||||
"superdough": "workspace:*",
|
"superdough": "workspace:*"
|
||||||
"supradough": "workspace:*"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^6.0.11"
|
"vite": "^6.0.11"
|
||||||
|
|||||||
@@ -1,130 +0,0 @@
|
|||||||
import { Pattern } from '@strudel/core';
|
|
||||||
import { connectToDestination, getAudioContext, getWorklet } from 'superdough';
|
|
||||||
|
|
||||||
let doughWorklet;
|
|
||||||
|
|
||||||
function initDoughWorklet() {
|
|
||||||
const ac = getAudioContext();
|
|
||||||
doughWorklet = getWorklet(
|
|
||||||
ac,
|
|
||||||
'dough-processor',
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
outputChannelCount: [2],
|
|
||||||
},
|
|
||||||
);
|
|
||||||
connectToDestination(doughWorklet); // channels?
|
|
||||||
}
|
|
||||||
|
|
||||||
const soundMap = new Map();
|
|
||||||
const loadedSounds = new Map();
|
|
||||||
|
|
||||||
Pattern.prototype.supradough = function () {
|
|
||||||
return this.onSchedule((hap, begin, cps) => {
|
|
||||||
hap.value._begin = begin;
|
|
||||||
hap.value._duration = hap.duration / cps;
|
|
||||||
!doughWorklet && initDoughWorklet();
|
|
||||||
const s = (hap.value.bank ? hap.value.bank + '_' : '') + hap.value.s;
|
|
||||||
const n = hap.value.n ?? 0;
|
|
||||||
const soundKey = `${s}:${n}`;
|
|
||||||
if (soundMap.has(s)) {
|
|
||||||
hap.value.s = soundKey; // dough.mjs is unaware of bank and n (only maps keys to buffers)
|
|
||||||
}
|
|
||||||
if (soundMap.has(s) && !loadedSounds.has(soundKey)) {
|
|
||||||
const urls = soundMap.get(s);
|
|
||||||
const url = urls[n % urls.length];
|
|
||||||
console.log(`load ${soundKey} from ${url}`);
|
|
||||||
const loadSample = fetchSample(url);
|
|
||||||
loadedSounds.set(soundKey, loadSample);
|
|
||||||
loadSample.then(({ channels, sampleRate }) =>
|
|
||||||
doughWorklet.port.postMessage({
|
|
||||||
sample: soundKey,
|
|
||||||
channels,
|
|
||||||
sampleRate,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
doughWorklet.port.postMessage({ spawn: hap.value });
|
|
||||||
}, 1);
|
|
||||||
};
|
|
||||||
|
|
||||||
function githubPath(base, subpath = '') {
|
|
||||||
if (!base.startsWith('github:')) {
|
|
||||||
throw new Error('expected "github:" at the start of pseudoUrl');
|
|
||||||
}
|
|
||||||
let [_, path] = base.split('github:');
|
|
||||||
path = path.endsWith('/') ? path.slice(0, -1) : path;
|
|
||||||
if (path.split('/').length === 2) {
|
|
||||||
// assume main as default branch if none set
|
|
||||||
path += '/main';
|
|
||||||
}
|
|
||||||
return `https://raw.githubusercontent.com/${path}/${subpath}`;
|
|
||||||
}
|
|
||||||
export async function fetchSampleMap(url) {
|
|
||||||
if (url.startsWith('github:')) {
|
|
||||||
url = githubPath(url, 'strudel.json');
|
|
||||||
}
|
|
||||||
if (url.startsWith('local:')) {
|
|
||||||
url = `http://localhost:5432`;
|
|
||||||
}
|
|
||||||
if (url.startsWith('shabda:')) {
|
|
||||||
let [_, path] = url.split('shabda:');
|
|
||||||
url = `https://shabda.ndre.gr/${path}.json?strudel=1`;
|
|
||||||
}
|
|
||||||
if (url.startsWith('shabda/speech')) {
|
|
||||||
let [_, path] = url.split('shabda/speech');
|
|
||||||
path = path.startsWith('/') ? path.substring(1) : path;
|
|
||||||
let [params, words] = path.split(':');
|
|
||||||
let gender = 'f';
|
|
||||||
let language = 'en-GB';
|
|
||||||
if (params) {
|
|
||||||
[language, gender] = params.split('/');
|
|
||||||
}
|
|
||||||
url = `https://shabda.ndre.gr/speech/${words}.json?gender=${gender}&language=${language}&strudel=1'`;
|
|
||||||
}
|
|
||||||
if (typeof fetch !== 'function') {
|
|
||||||
// not a browser
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const base = url.split('/').slice(0, -1).join('/');
|
|
||||||
if (typeof fetch === 'undefined') {
|
|
||||||
// skip fetch when in node / testing
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const json = await fetch(url)
|
|
||||||
.then((res) => res.json())
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(error);
|
|
||||||
throw new Error(`error loading "${url}"`);
|
|
||||||
});
|
|
||||||
return [json, json._base || base];
|
|
||||||
}
|
|
||||||
|
|
||||||
// for some reason, only piano and flute work.. is it because mp3??
|
|
||||||
|
|
||||||
async function fetchSample(url) {
|
|
||||||
const buffer = await fetch(url)
|
|
||||||
.then((res) => res.arrayBuffer())
|
|
||||||
.then((buf) => getAudioContext().decodeAudioData(buf));
|
|
||||||
let channels = [];
|
|
||||||
for (let i = 0; i < buffer.numberOfChannels; i++) {
|
|
||||||
channels.push(buffer.getChannelData(i));
|
|
||||||
}
|
|
||||||
return { channels, sampleRate: buffer.sampleRate };
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function supradoughsamples(sampleMap, baseUrl) {
|
|
||||||
if (typeof sampleMap === 'string') {
|
|
||||||
const [json, base] = await fetchSampleMap(sampleMap);
|
|
||||||
// console.log('json', json, 'base', base);
|
|
||||||
return supradoughsamples(json, base);
|
|
||||||
}
|
|
||||||
Object.entries(sampleMap).map(async ([key, urls]) => {
|
|
||||||
if (key !== '_base') {
|
|
||||||
urls = urls.map((url) => baseUrl + url);
|
|
||||||
// console.log('set', key, urls);
|
|
||||||
soundMap.set(key, urls);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -17,10 +17,7 @@ import {
|
|||||||
resetGlobalEffects,
|
resetGlobalEffects,
|
||||||
errorLogger,
|
errorLogger,
|
||||||
} from 'superdough';
|
} from 'superdough';
|
||||||
import './supradough.mjs';
|
|
||||||
import { workletUrl } from 'supradough';
|
|
||||||
import { SuperdoughAudioController } from 'superdough/superdoughoutput.mjs';
|
import { SuperdoughAudioController } from 'superdough/superdoughoutput.mjs';
|
||||||
registerWorklet(workletUrl);
|
|
||||||
|
|
||||||
const { Pattern, logger, repl } = strudel;
|
const { Pattern, logger, repl } = strudel;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# @strudel/websocket
|
||||||
|
|
||||||
|
This package adds websocket input to strudel Patterns.
|
||||||
|
|
||||||
|
It connects to a websocket server and exposes the latest received value (parsed as JSON) as a pattern.
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import './websocket.mjs';
|
||||||
|
|
||||||
|
export * from './websocket.mjs';
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "supradough",
|
"name": "@strudel/websocket",
|
||||||
"version": "1.2.4",
|
"version": "1.0.0",
|
||||||
"description": "platform agnostic synth and sampler intended for live coding. a reimplementation of superdough.",
|
"description": "Websocket input for strudel",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
@@ -16,22 +16,23 @@
|
|||||||
"url": "git+https://codeberg.org/uzu/strudel.git"
|
"url": "git+https://codeberg.org/uzu/strudel.git"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"tidalcycles",
|
"titdalcycles",
|
||||||
"strudel",
|
"strudel",
|
||||||
"pattern",
|
"pattern",
|
||||||
"livecoding",
|
"livecoding",
|
||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Alex McLean <alex@slab.org>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://codeberg.org/uzu/strudel/issues"
|
"url": "https://codeberg.org/uzu/strudel/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://codeberg.org/uzu/strudel#readme",
|
"homepage": "https://codeberg.org/uzu/strudel#readme",
|
||||||
|
"dependencies": {
|
||||||
|
"@strudel/core": "workspace:*"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vite": "^6.0.11",
|
"vite": "^6.0.11"
|
||||||
"vite-plugin-bundle-audioworklet": "workspace:*",
|
|
||||||
"wav-encoder": "^1.3.0"
|
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
import { dependencies } from './package.json';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import bundleAudioWorkletPlugin from 'vite-plugin-bundle-audioworklet';
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [bundleAudioWorkletPlugin()],
|
plugins: [],
|
||||||
build: {
|
build: {
|
||||||
lib: {
|
lib: {
|
||||||
entry: resolve(__dirname, 'index.mjs'),
|
entry: resolve(__dirname, 'index.mjs'),
|
||||||
formats: ['es'],
|
formats: ['es'],
|
||||||
fileName: (ext) => ({ es: 'index.mjs' })[ext],
|
fileName: (ext) => ({ es: 'index.mjs' })[ext],
|
||||||
},
|
},
|
||||||
|
rollupOptions: {
|
||||||
|
external: [...Object.keys(dependencies)],
|
||||||
|
},
|
||||||
target: 'esnext',
|
target: 'esnext',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
websocket.mjs - simple websocket client as a pattern
|
||||||
|
Copyright (C) 2026 Strudel contributors -- see <https://codeberg.org/uzu/strudel/src/branch/main/packages/websocket/websocket.mjs>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { logger, signal } from '@strudel/core';
|
||||||
|
|
||||||
|
const connections = {};
|
||||||
|
const values = {};
|
||||||
|
|
||||||
|
function connect(addr) {
|
||||||
|
if (connections[addr]) {
|
||||||
|
return connections[addr];
|
||||||
|
}
|
||||||
|
const ws = new WebSocket(addr);
|
||||||
|
connections[addr] = ws;
|
||||||
|
ws.addEventListener('open', () => {
|
||||||
|
logger(`[websocket] connected to ${addr}`);
|
||||||
|
});
|
||||||
|
ws.addEventListener('message', (event) => {
|
||||||
|
try {
|
||||||
|
console.log(event.data);
|
||||||
|
values[addr] = JSON.parse(event.data);
|
||||||
|
} catch {
|
||||||
|
logger(`[websocket] received invalid json on ${addr}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ws.addEventListener('close', () => {
|
||||||
|
logger(`[websocket] disconnected from ${addr}`);
|
||||||
|
delete connections[addr];
|
||||||
|
});
|
||||||
|
ws.addEventListener('error', () => {
|
||||||
|
logger(`[websocket] failed to connect to ${addr}`);
|
||||||
|
delete connections[addr];
|
||||||
|
});
|
||||||
|
return ws;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function websocket(addr) {
|
||||||
|
connect(addr);
|
||||||
|
return signal(() => values[addr] ?? {});
|
||||||
|
}
|
||||||
@@ -106,7 +106,7 @@ export const xen = register(
|
|||||||
let k = parray(input);
|
let k = parray(input);
|
||||||
|
|
||||||
return new Pattern((state) => {
|
return new Pattern((state) => {
|
||||||
let res = k.withValue((x) => x.map((y) => eval(y.join('/')))).query(state);
|
let res = k.withValue((x) => x.map((y) => y.reduce((acc, v) => acc / v))).query(state);
|
||||||
return res;
|
return res;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+45
-56
@@ -242,24 +242,12 @@ importers:
|
|||||||
'@strudel/draw':
|
'@strudel/draw':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../draw
|
version: link:../draw
|
||||||
'@strudel/tonal':
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../tonal
|
|
||||||
'@strudel/transpiler':
|
'@strudel/transpiler':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../transpiler
|
version: link:../transpiler
|
||||||
'@tonaljs/tonal':
|
|
||||||
specifier: ^4.10.0
|
|
||||||
version: 4.10.0
|
|
||||||
codemirror-helix:
|
|
||||||
specifier: ^0.5.0
|
|
||||||
version: 0.5.0(@codemirror/commands@6.8.0)(@codemirror/language@6.10.8)(@codemirror/search@6.5.8)(@codemirror/state@6.5.1)(@codemirror/view@6.36.2)
|
|
||||||
nanostores:
|
nanostores:
|
||||||
specifier: ^0.11.3
|
specifier: ^0.11.3
|
||||||
version: 0.11.3
|
version: 0.11.3
|
||||||
superdough:
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../superdough
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
vite:
|
vite:
|
||||||
specifier: ^6.0.11
|
specifier: ^6.0.11
|
||||||
@@ -299,6 +287,9 @@ importers:
|
|||||||
'@strudel/core':
|
'@strudel/core':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../core
|
version: link:../core
|
||||||
|
'@strudel/osc':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../osc
|
||||||
'@strudel/webaudio':
|
'@strudel/webaudio':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../webaudio
|
version: link:../webaudio
|
||||||
@@ -315,8 +306,8 @@ importers:
|
|||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../webaudio
|
version: link:../webaudio
|
||||||
dough-synth:
|
dough-synth:
|
||||||
specifier: 0.2.4
|
specifier: 0.4.1
|
||||||
version: 0.2.4
|
version: 0.4.1
|
||||||
devDependencies:
|
devDependencies:
|
||||||
vite:
|
vite:
|
||||||
specifier: ^6.0.11
|
specifier: ^6.0.11
|
||||||
@@ -368,13 +359,13 @@ importers:
|
|||||||
|
|
||||||
packages/hs2js:
|
packages/hs2js:
|
||||||
dependencies:
|
dependencies:
|
||||||
|
tree-sitter-haskell:
|
||||||
|
specifier: ^0.23.1
|
||||||
|
version: 0.23.1(tree-sitter@0.21.1)
|
||||||
web-tree-sitter:
|
web-tree-sitter:
|
||||||
specifier: ^0.24.7
|
specifier: ^0.24.7
|
||||||
version: 0.24.7
|
version: 0.24.7
|
||||||
devDependencies:
|
devDependencies:
|
||||||
tree-sitter-haskell:
|
|
||||||
specifier: ^0.23.1
|
|
||||||
version: 0.23.1(tree-sitter@0.21.1)
|
|
||||||
vite:
|
vite:
|
||||||
specifier: ^6.0.11
|
specifier: ^6.0.11
|
||||||
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||||
@@ -547,6 +538,9 @@ importers:
|
|||||||
'@strudel/webaudio':
|
'@strudel/webaudio':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../webaudio
|
version: link:../webaudio
|
||||||
|
'@strudel/websocket':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../websocket
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@rollup/plugin-replace':
|
'@rollup/plugin-replace':
|
||||||
specifier: ^6.0.2
|
specifier: ^6.0.2
|
||||||
@@ -615,18 +609,6 @@ importers:
|
|||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../vite-plugin-bundle-audioworklet
|
version: link:../vite-plugin-bundle-audioworklet
|
||||||
|
|
||||||
packages/supradough:
|
|
||||||
devDependencies:
|
|
||||||
vite:
|
|
||||||
specifier: ^6.0.11
|
|
||||||
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
|
||||||
vite-plugin-bundle-audioworklet:
|
|
||||||
specifier: workspace:*
|
|
||||||
version: link:../vite-plugin-bundle-audioworklet
|
|
||||||
wav-encoder:
|
|
||||||
specifier: ^1.3.0
|
|
||||||
version: 1.3.0
|
|
||||||
|
|
||||||
packages/tidal:
|
packages/tidal:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@strudel/core':
|
'@strudel/core':
|
||||||
@@ -738,9 +720,16 @@ importers:
|
|||||||
superdough:
|
superdough:
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../superdough
|
version: link:../superdough
|
||||||
supradough:
|
devDependencies:
|
||||||
|
vite:
|
||||||
|
specifier: ^6.0.11
|
||||||
|
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
|
||||||
|
|
||||||
|
packages/websocket:
|
||||||
|
dependencies:
|
||||||
|
'@strudel/core':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../supradough
|
version: link:../core
|
||||||
devDependencies:
|
devDependencies:
|
||||||
vite:
|
vite:
|
||||||
specifier: ^6.0.11
|
specifier: ^6.0.11
|
||||||
@@ -881,6 +870,9 @@ importers:
|
|||||||
'@strudel/webaudio':
|
'@strudel/webaudio':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../packages/webaudio
|
version: link:../packages/webaudio
|
||||||
|
'@strudel/websocket':
|
||||||
|
specifier: workspace:*
|
||||||
|
version: link:../packages/websocket
|
||||||
'@strudel/xen':
|
'@strudel/xen':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
version: link:../packages/xen
|
version: link:../packages/xen
|
||||||
@@ -3657,15 +3649,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-FMabTRlc5t5zjdenF6mS0MBeFZm0XqHqeOkcskKFb/LYCcRQ5fVgLOHVc4Lq9CqABd9zhjwPjMBCJvMCziSVtA==}
|
resolution: {integrity: sha512-FMabTRlc5t5zjdenF6mS0MBeFZm0XqHqeOkcskKFb/LYCcRQ5fVgLOHVc4Lq9CqABd9zhjwPjMBCJvMCziSVtA==}
|
||||||
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
||||||
|
|
||||||
codemirror-helix@0.5.0:
|
|
||||||
resolution: {integrity: sha512-hI56hf9VGz53H1YvL6H1GC7HtP6te8vX+MsIHaE9J7Q3PQ6KFapKtIRg6lqSH898ikHWpMCPu42r6HJN0IfVLA==}
|
|
||||||
peerDependencies:
|
|
||||||
'@codemirror/commands': ^6.0.0
|
|
||||||
'@codemirror/language': ^6.0.0
|
|
||||||
'@codemirror/search': ^6.0.0
|
|
||||||
'@codemirror/state': ^6.0.0
|
|
||||||
'@codemirror/view': ^6.0.0
|
|
||||||
|
|
||||||
collapse-white-space@2.1.0:
|
collapse-white-space@2.1.0:
|
||||||
resolution: {integrity: sha512-loKTxY1zCOuG4j9f6EPnuyyYkf58RnhhWTvRoZEokgB+WbdXehfjFviyOVYkqzEWz1Q5kRiZdBYS5SwxbQYwzw==}
|
resolution: {integrity: sha512-loKTxY1zCOuG4j9f6EPnuyyYkf58RnhhWTvRoZEokgB+WbdXehfjFviyOVYkqzEWz1Q5kRiZdBYS5SwxbQYwzw==}
|
||||||
|
|
||||||
@@ -4075,8 +4058,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==}
|
resolution: {integrity: sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
|
|
||||||
dough-synth@0.2.4:
|
dough-synth@0.4.1:
|
||||||
resolution: {integrity: sha512-qMnMKVj1B2ivUgobNCwqJqNzZHOMN+5339OmCOk07zIDEK7iCYdufa+ZDE2BEgmKrWDyhGS7oTNFjHtTwzEv9w==}
|
resolution: {integrity: sha512-hxBsfOBwTIlJMhSB/Pk2xNNc7YTAVTgexn5Y7GRv/Kn2qBkMxwLxHJNvhsUhklQhVvzny/aCihxb0EOq4tv5Bw==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|
||||||
dset@3.1.4:
|
dset@3.1.4:
|
||||||
@@ -7800,9 +7783,6 @@ packages:
|
|||||||
walk-up-path@3.0.1:
|
walk-up-path@3.0.1:
|
||||||
resolution: {integrity: sha512-9YlCL/ynK3CTlrSRrDxZvUauLzAswPCrsaCgilqFevUYpeEW0/3ScEjaa3kbW/T0ghhkEr7mv+fpjqn1Y1YuTA==}
|
resolution: {integrity: sha512-9YlCL/ynK3CTlrSRrDxZvUauLzAswPCrsaCgilqFevUYpeEW0/3ScEjaa3kbW/T0ghhkEr7mv+fpjqn1Y1YuTA==}
|
||||||
|
|
||||||
wav-encoder@1.3.0:
|
|
||||||
resolution: {integrity: sha512-FXJdEu2qDOI+wbVYZpu21CS1vPEg5NaxNskBr4SaULpOJMrLE6xkH8dECa7PiS+ZoeyvP7GllWUAxPN3AvFSEw==}
|
|
||||||
|
|
||||||
wav@1.0.2:
|
wav@1.0.2:
|
||||||
resolution: {integrity: sha512-viHtz3cDd/Tcr/HbNqzQCofKdF6kWUymH9LGDdskfWFoIy/HJ+RTihgjEcHfnsy1PO4e9B+y4HwgTwMrByquhg==}
|
resolution: {integrity: sha512-viHtz3cDd/Tcr/HbNqzQCofKdF6kWUymH9LGDdskfWFoIy/HJ+RTihgjEcHfnsy1PO4e9B+y4HwgTwMrByquhg==}
|
||||||
|
|
||||||
@@ -8027,6 +8007,18 @@ packages:
|
|||||||
utf-8-validate:
|
utf-8-validate:
|
||||||
optional: true
|
optional: true
|
||||||
|
|
||||||
|
ws@8.22.0:
|
||||||
|
resolution: {integrity: sha512-Ydggc987+RO0AnWtZ/7Wq9FtNvcrL1b/RO0ud9mWjUPgDrsAAwQSF51sm2hm1XofbU/4jkpGEsLFsZZxU+1DOg==}
|
||||||
|
engines: {node: '>=10.0.0'}
|
||||||
|
peerDependencies:
|
||||||
|
bufferutil: ^4.0.1
|
||||||
|
utf-8-validate: '>=5.0.2'
|
||||||
|
peerDependenciesMeta:
|
||||||
|
bufferutil:
|
||||||
|
optional: true
|
||||||
|
utf-8-validate:
|
||||||
|
optional: true
|
||||||
|
|
||||||
xmlcreate@2.0.4:
|
xmlcreate@2.0.4:
|
||||||
resolution: {integrity: sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==}
|
resolution: {integrity: sha512-nquOebG4sngPmGPICTS5EnxqhKbCmz5Ox5hsszI2T6U5qdrJizBc+0ilYSEjTSzU0yZcmvppztXe/5Al5fUwdg==}
|
||||||
|
|
||||||
@@ -11408,14 +11400,6 @@ snapshots:
|
|||||||
|
|
||||||
cmd-shim@6.0.3: {}
|
cmd-shim@6.0.3: {}
|
||||||
|
|
||||||
codemirror-helix@0.5.0(@codemirror/commands@6.8.0)(@codemirror/language@6.10.8)(@codemirror/search@6.5.8)(@codemirror/state@6.5.1)(@codemirror/view@6.36.2):
|
|
||||||
dependencies:
|
|
||||||
'@codemirror/commands': 6.8.0
|
|
||||||
'@codemirror/language': 6.10.8
|
|
||||||
'@codemirror/search': 6.5.8
|
|
||||||
'@codemirror/state': 6.5.1
|
|
||||||
'@codemirror/view': 6.36.2
|
|
||||||
|
|
||||||
collapse-white-space@2.1.0: {}
|
collapse-white-space@2.1.0: {}
|
||||||
|
|
||||||
color-convert@2.0.1:
|
color-convert@2.0.1:
|
||||||
@@ -11797,7 +11781,12 @@ snapshots:
|
|||||||
|
|
||||||
dotenv@16.4.7: {}
|
dotenv@16.4.7: {}
|
||||||
|
|
||||||
dough-synth@0.2.4: {}
|
dough-synth@0.4.1:
|
||||||
|
dependencies:
|
||||||
|
ws: 8.22.0
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- bufferutil
|
||||||
|
- utf-8-validate
|
||||||
|
|
||||||
dset@3.1.4: {}
|
dset@3.1.4: {}
|
||||||
|
|
||||||
@@ -16374,8 +16363,6 @@ snapshots:
|
|||||||
|
|
||||||
walk-up-path@3.0.1: {}
|
walk-up-path@3.0.1: {}
|
||||||
|
|
||||||
wav-encoder@1.3.0: {}
|
|
||||||
|
|
||||||
wav@1.0.2:
|
wav@1.0.2:
|
||||||
dependencies:
|
dependencies:
|
||||||
buffer-alloc: 1.2.0
|
buffer-alloc: 1.2.0
|
||||||
@@ -16695,6 +16682,8 @@ snapshots:
|
|||||||
|
|
||||||
ws@8.18.3: {}
|
ws@8.18.3: {}
|
||||||
|
|
||||||
|
ws@8.22.0: {}
|
||||||
|
|
||||||
xmlcreate@2.0.4: {}
|
xmlcreate@2.0.4: {}
|
||||||
|
|
||||||
xtend@4.0.2: {}
|
xtend@4.0.2: {}
|
||||||
|
|||||||
+13
-12
@@ -4,18 +4,19 @@ packages:
|
|||||||
- tools/dbpatch
|
- tools/dbpatch
|
||||||
- website/
|
- website/
|
||||||
|
|
||||||
onlyBuiltDependencies:
|
catalog:
|
||||||
|
'@codemirror/autocomplete': ^6.18.4
|
||||||
|
'@codemirror/commands': ^6.8.0
|
||||||
|
'@codemirror/lang-javascript': ^6.2.2
|
||||||
|
'@codemirror/language': ^6.10.8
|
||||||
|
'@codemirror/search': ^6.5.8
|
||||||
|
'@codemirror/state': ^6.5.1
|
||||||
|
'@codemirror/view': ^6.36.2
|
||||||
|
|
||||||
|
ignoredBuiltDependencies:
|
||||||
|
- '@serialport/bindings-cpp'
|
||||||
|
- tree-sitter-haskell
|
||||||
|
- tree-sitter
|
||||||
- esbuild
|
- esbuild
|
||||||
- nx
|
- nx
|
||||||
- sharp
|
- sharp
|
||||||
- tree-sitter
|
|
||||||
- tree-sitter-haskell
|
|
||||||
|
|
||||||
catalog:
|
|
||||||
"@codemirror/commands": "^6.8.0"
|
|
||||||
"@codemirror/language": "^6.10.8"
|
|
||||||
"@codemirror/lang-javascript": "^6.2.2"
|
|
||||||
"@codemirror/state": "^6.5.1"
|
|
||||||
"@codemirror/view": "^6.36.2"
|
|
||||||
"@codemirror/autocomplete": "^6.18.4"
|
|
||||||
"@codemirror/search": "^6.5.8"
|
|
||||||
|
|||||||
@@ -2440,6 +2440,43 @@ exports[`runs examples > example "clip" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "close" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/8 | s:bd cutoff:3000 ]",
|
||||||
|
"[ 1/8 → 1/4 | s:sd cutoff:2915.625 ]",
|
||||||
|
"[ 5/16 → 3/8 | s:bd cutoff:2789.0625 ]",
|
||||||
|
"[ 3/8 → 1/2 | s:sd cutoff:2746.875 ]",
|
||||||
|
"[ 1/2 → 5/8 | s:bd cutoff:2662.5 ]",
|
||||||
|
"[ 5/8 → 3/4 | s:sd cutoff:2578.125 ]",
|
||||||
|
"[ 13/16 → 7/8 | s:bd cutoff:2451.5625 ]",
|
||||||
|
"[ 7/8 → 1/1 | s:sd cutoff:2409.375 ]",
|
||||||
|
"[ 1/1 → 9/8 | s:bd cutoff:2325 ]",
|
||||||
|
"[ 9/8 → 5/4 | s:sd cutoff:2240.625 ]",
|
||||||
|
"[ 21/16 → 11/8 | s:bd cutoff:2114.0625 ]",
|
||||||
|
"[ 11/8 → 3/2 | s:sd cutoff:2071.875 ]",
|
||||||
|
"[ 3/2 → 13/8 | s:bd cutoff:1987.5 ]",
|
||||||
|
"[ 13/8 → 7/4 | s:sd cutoff:1903.125 ]",
|
||||||
|
"[ 29/16 → 15/8 | s:bd cutoff:1776.5625 ]",
|
||||||
|
"[ 15/8 → 2/1 | s:sd cutoff:1734.375 ]",
|
||||||
|
"[ 2/1 → 17/8 | s:bd cutoff:1650 ]",
|
||||||
|
"[ 17/8 → 9/4 | s:sd cutoff:1565.625 ]",
|
||||||
|
"[ 37/16 → 19/8 | s:bd cutoff:1439.0625 ]",
|
||||||
|
"[ 19/8 → 5/2 | s:sd cutoff:1396.875 ]",
|
||||||
|
"[ 5/2 → 21/8 | s:bd cutoff:1312.5 ]",
|
||||||
|
"[ 21/8 → 11/4 | s:sd cutoff:1228.125 ]",
|
||||||
|
"[ 45/16 → 23/8 | s:bd cutoff:1101.5625 ]",
|
||||||
|
"[ 23/8 → 3/1 | s:sd cutoff:1059.375 ]",
|
||||||
|
"[ 3/1 → 25/8 | s:bd cutoff:975 ]",
|
||||||
|
"[ 25/8 → 13/4 | s:sd cutoff:890.625 ]",
|
||||||
|
"[ 53/16 → 27/8 | s:bd cutoff:764.0625 ]",
|
||||||
|
"[ 27/8 → 7/2 | s:sd cutoff:721.875 ]",
|
||||||
|
"[ 7/2 → 29/8 | s:bd cutoff:637.5 ]",
|
||||||
|
"[ 29/8 → 15/4 | s:sd cutoff:553.125 ]",
|
||||||
|
"[ 61/16 → 31/8 | s:bd cutoff:426.5625 ]",
|
||||||
|
"[ 31/8 → 4/1 | s:sd cutoff:384.375 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "coarse" example index 0 1`] = `
|
exports[`runs examples > example "coarse" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/8 | s:hh coarse:1 ]",
|
"[ 0/1 → 1/8 | s:hh coarse:1 ]",
|
||||||
@@ -3138,43 +3175,6 @@ exports[`runs examples > example "delayfeedback" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "delayspeed" example index 0 1`] = `
|
|
||||||
[
|
|
||||||
"[ 0/1 → 1/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 1/8 → 1/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 1/4 → 3/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 3/8 → 1/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 1/2 → 5/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 5/8 → 3/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 3/4 → 7/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 7/8 → 1/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
|
||||||
"[ 1/1 → 9/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 9/8 → 5/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 5/4 → 11/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 11/8 → 3/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 3/2 → 13/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 13/8 → 7/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 7/4 → 15/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 15/8 → 2/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
|
||||||
"[ 2/1 → 17/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 17/8 → 9/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 9/4 → 19/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 19/8 → 5/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 5/2 → 21/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 21/8 → 11/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 11/4 → 23/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 23/8 → 3/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
|
||||||
"[ 3/1 → 25/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 25/8 → 13/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 13/4 → 27/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 27/8 → 7/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 7/2 → 29/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 29/8 → 15/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 15/4 → 31/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
"[ 31/8 → 4/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`runs examples > example "delaysync" example index 0 1`] = `
|
exports[`runs examples > example "delaysync" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/2 | s:bd delay:0.25 delaysync:0.125 ]",
|
"[ 0/1 → 1/2 | s:bd delay:0.25 delaysync:0.125 ]",
|
||||||
@@ -3190,38 +3190,38 @@ exports[`runs examples > example "delaysync" example index 0 1`] = `
|
|||||||
|
|
||||||
exports[`runs examples > example "delaytime" example index 0 1`] = `
|
exports[`runs examples > example "delaytime" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 0/1 → 1/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 1/8 → 1/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 1/8 → 1/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 1/4 → 3/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 1/4 → 3/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 3/8 → 1/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 3/8 → 1/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 1/2 → 5/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 1/2 → 5/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 5/8 → 3/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 5/8 → 3/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 3/4 → 7/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 3/4 → 7/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 7/8 → 1/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:2 ]",
|
"[ 7/8 → 1/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 1/1 → 9/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 1/1 → 9/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 9/8 → 5/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 9/8 → 5/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 5/4 → 11/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 5/4 → 11/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 11/8 → 3/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 11/8 → 3/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 3/2 → 13/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 3/2 → 13/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 13/8 → 7/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 13/8 → 7/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 7/4 → 15/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 7/4 → 15/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 15/8 → 2/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:0.5 ]",
|
"[ 15/8 → 2/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 2/1 → 17/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 2/1 → 17/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 17/8 → 9/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 17/8 → 9/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 9/4 → 19/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 9/4 → 19/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 19/8 → 5/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 19/8 → 5/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 5/2 → 21/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 5/2 → 21/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 21/8 → 11/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 21/8 → 11/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 11/4 → 23/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 11/4 → 23/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 23/8 → 3/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-1 ]",
|
"[ 23/8 → 3/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 3/1 → 25/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 3/1 → 25/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 25/8 → 13/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 25/8 → 13/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 13/4 → 27/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 13/4 → 27/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 27/8 → 7/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 27/8 → 7/2 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 7/2 → 29/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 7/2 → 29/8 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 29/8 → 15/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 29/8 → 15/4 | note:d s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 15/4 → 31/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 15/4 → 31/8 | note:a# s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
"[ 31/8 → 4/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 delayspeed:-2 ]",
|
"[ 31/8 → 4/1 | note:a s:sawtooth delay:0.8 delaytime:0.5 ]",
|
||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
@@ -4777,6 +4777,72 @@ exports[`runs examples > example "floor" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "fm" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/6 | note:c fmi:0 ]",
|
||||||
|
"[ 1/6 → 1/3 | note:e fmi:0 ]",
|
||||||
|
"[ 1/3 → 1/2 | note:g fmi:0 ]",
|
||||||
|
"[ 1/2 → 2/3 | note:b fmi:0 ]",
|
||||||
|
"[ 2/3 → 5/6 | note:g fmi:0 ]",
|
||||||
|
"[ 5/6 → 1/1 | note:e fmi:0 ]",
|
||||||
|
"[ 1/1 → 7/6 | note:c fmi:1 ]",
|
||||||
|
"[ 7/6 → 4/3 | note:e fmi:1 ]",
|
||||||
|
"[ 4/3 → 3/2 | note:g fmi:1 ]",
|
||||||
|
"[ 3/2 → 5/3 | note:b fmi:1 ]",
|
||||||
|
"[ 5/3 → 11/6 | note:g fmi:1 ]",
|
||||||
|
"[ 11/6 → 2/1 | note:e fmi:1 ]",
|
||||||
|
"[ 2/1 → 13/6 | note:c fmi:2 ]",
|
||||||
|
"[ 13/6 → 7/3 | note:e fmi:2 ]",
|
||||||
|
"[ 7/3 → 5/2 | note:g fmi:2 ]",
|
||||||
|
"[ 5/2 → 8/3 | note:b fmi:2 ]",
|
||||||
|
"[ 8/3 → 17/6 | note:g fmi:2 ]",
|
||||||
|
"[ 17/6 → 3/1 | note:e fmi:2 ]",
|
||||||
|
"[ 3/1 → 19/6 | note:c fmi:8 ]",
|
||||||
|
"[ 19/6 → 10/3 | note:e fmi:8 ]",
|
||||||
|
"[ 10/3 → 7/2 | note:g fmi:8 ]",
|
||||||
|
"[ 7/2 → 11/3 | note:b fmi:8 ]",
|
||||||
|
"[ 11/3 → 23/6 | note:g fmi:8 ]",
|
||||||
|
"[ 23/6 → 4/1 | note:e fmi:8 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "fm" example index 1 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/8 | s:sine note:F1 fmi:4 fmi2:0 fmi3:0 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 1/8 → 1/4 | s:sine note:F1 fmi:4 fmi2:2.7408622801303864 fmi3:0.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 1/4 → 3/8 | s:sine note:F1 fmi:4 fmi2:1.479038767516613 fmi3:0.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 3/8 → 1/2 | s:sine note:F1 fmi:4 fmi2:1.605570062994957 fmi3:0.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 1/2 → 5/8 | s:sine note:F1 fmi:4 fmi2:1.041922464966774 fmi3:0.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 5/8 → 3/4 | s:sine note:F1 fmi:4 fmi2:0.5425434708595276 fmi3:0.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 3/4 → 7/8 | s:sine note:F1 fmi:4 fmi2:0.7833059206604958 fmi3:0.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 7/8 → 1/1 | s:sine note:F1 fmi:4 fmi2:1.590524323284626 fmi3:0.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 1/1 → 9/8 | s:sine note:F1 fmi:4 fmi2:2.078168660402298 fmi3:1 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 9/8 → 5/4 | s:sine note:F1 fmi:4 fmi2:2.689958058297634 fmi3:1.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 5/4 → 11/8 | s:sine note:F1 fmi:4 fmi2:2.914912812411785 fmi3:1.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 11/8 → 3/2 | s:sine note:F1 fmi:4 fmi2:0.7312150076031685 fmi3:1.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 3/2 → 13/8 | s:sine note:F1 fmi:4 fmi2:2.4336322993040085 fmi3:1.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 13/8 → 7/4 | s:sine note:F1 fmi:4 fmi2:1.987018845975399 fmi3:1.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 7/4 → 15/8 | s:sine note:F1 fmi:4 fmi2:0.8189515843987465 fmi3:1.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 15/8 → 2/1 | s:sine note:F1 fmi:4 fmi2:2.3782287165522575 fmi3:1.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 2/1 → 17/8 | s:sine note:F1 fmi:4 fmi2:3.838108479976654 fmi3:2 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 17/8 → 9/4 | s:sine note:F1 fmi:4 fmi2:3.613561175763607 fmi3:2.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 9/4 → 19/8 | s:sine note:F1 fmi:4 fmi2:1.3819300457835197 fmi3:2.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 19/8 → 5/2 | s:sine note:F1 fmi:4 fmi2:3.346026562154293 fmi3:2.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 5/2 → 21/8 | s:sine note:F1 fmi:4 fmi2:1.8344642966985703 fmi3:2.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 21/8 → 11/4 | s:sine note:F1 fmi:4 fmi2:0.6407739371061325 fmi3:2.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 11/4 → 23/8 | s:sine note:F1 fmi:4 fmi2:2.5329310819506645 fmi3:2.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 23/8 → 3/1 | s:sine note:F1 fmi:4 fmi2:0.06501668691635132 fmi3:2.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 3/1 → 25/8 | s:sine note:F1 fmi:4 fmi2:0.8691564425826073 fmi3:3 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 25/8 → 13/4 | s:sine note:F1 fmi:4 fmi2:1.3729755133390427 fmi3:3.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 13/4 → 27/8 | s:sine note:F1 fmi:4 fmi2:3.9694602862000465 fmi3:3.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 27/8 → 7/2 | s:sine note:F1 fmi:4 fmi2:1.6347672045230865 fmi3:3.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 7/2 → 29/8 | s:sine note:F1 fmi:4 fmi2:1.639795258641243 fmi3:3.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 29/8 → 15/4 | s:sine note:F1 fmi:4 fmi2:3.7565943151712418 fmi3:3.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 15/4 → 31/8 | s:sine note:F1 fmi:4 fmi2:3.2486692890524864 fmi3:3.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
"[ 31/8 → 4/1 | s:sine note:F1 fmi:4 fmi2:2.9446661546826363 fmi3:3.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "fmattack" example index 0 1`] = `
|
exports[`runs examples > example "fmattack" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/6 | note:c fmi:4 fmattack:0 ]",
|
"[ 0/1 → 1/6 | note:c fmi:4 fmattack:0 ]",
|
||||||
@@ -4893,72 +4959,6 @@ exports[`runs examples > example "fmh" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "fmi" example index 0 1`] = `
|
|
||||||
[
|
|
||||||
"[ 0/1 → 1/6 | note:c fmi:0 ]",
|
|
||||||
"[ 1/6 → 1/3 | note:e fmi:0 ]",
|
|
||||||
"[ 1/3 → 1/2 | note:g fmi:0 ]",
|
|
||||||
"[ 1/2 → 2/3 | note:b fmi:0 ]",
|
|
||||||
"[ 2/3 → 5/6 | note:g fmi:0 ]",
|
|
||||||
"[ 5/6 → 1/1 | note:e fmi:0 ]",
|
|
||||||
"[ 1/1 → 7/6 | note:c fmi:1 ]",
|
|
||||||
"[ 7/6 → 4/3 | note:e fmi:1 ]",
|
|
||||||
"[ 4/3 → 3/2 | note:g fmi:1 ]",
|
|
||||||
"[ 3/2 → 5/3 | note:b fmi:1 ]",
|
|
||||||
"[ 5/3 → 11/6 | note:g fmi:1 ]",
|
|
||||||
"[ 11/6 → 2/1 | note:e fmi:1 ]",
|
|
||||||
"[ 2/1 → 13/6 | note:c fmi:2 ]",
|
|
||||||
"[ 13/6 → 7/3 | note:e fmi:2 ]",
|
|
||||||
"[ 7/3 → 5/2 | note:g fmi:2 ]",
|
|
||||||
"[ 5/2 → 8/3 | note:b fmi:2 ]",
|
|
||||||
"[ 8/3 → 17/6 | note:g fmi:2 ]",
|
|
||||||
"[ 17/6 → 3/1 | note:e fmi:2 ]",
|
|
||||||
"[ 3/1 → 19/6 | note:c fmi:8 ]",
|
|
||||||
"[ 19/6 → 10/3 | note:e fmi:8 ]",
|
|
||||||
"[ 10/3 → 7/2 | note:g fmi:8 ]",
|
|
||||||
"[ 7/2 → 11/3 | note:b fmi:8 ]",
|
|
||||||
"[ 11/3 → 23/6 | note:g fmi:8 ]",
|
|
||||||
"[ 23/6 → 4/1 | note:e fmi:8 ]",
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`runs examples > example "fmi" example index 1 1`] = `
|
|
||||||
[
|
|
||||||
"[ 0/1 → 1/8 | s:sine note:F1 fmi:4 fmi2:0 fmi3:0 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 1/8 → 1/4 | s:sine note:F1 fmi:4 fmi2:2.7408622801303864 fmi3:0.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 1/4 → 3/8 | s:sine note:F1 fmi:4 fmi2:1.479038767516613 fmi3:0.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 3/8 → 1/2 | s:sine note:F1 fmi:4 fmi2:1.605570062994957 fmi3:0.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 1/2 → 5/8 | s:sine note:F1 fmi:4 fmi2:1.041922464966774 fmi3:0.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 5/8 → 3/4 | s:sine note:F1 fmi:4 fmi2:0.5425434708595276 fmi3:0.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 3/4 → 7/8 | s:sine note:F1 fmi:4 fmi2:0.7833059206604958 fmi3:0.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 7/8 → 1/1 | s:sine note:F1 fmi:4 fmi2:1.590524323284626 fmi3:0.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 1/1 → 9/8 | s:sine note:F1 fmi:4 fmi2:2.078168660402298 fmi3:1 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 9/8 → 5/4 | s:sine note:F1 fmi:4 fmi2:2.689958058297634 fmi3:1.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 5/4 → 11/8 | s:sine note:F1 fmi:4 fmi2:2.914912812411785 fmi3:1.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 11/8 → 3/2 | s:sine note:F1 fmi:4 fmi2:0.7312150076031685 fmi3:1.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 3/2 → 13/8 | s:sine note:F1 fmi:4 fmi2:2.4336322993040085 fmi3:1.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 13/8 → 7/4 | s:sine note:F1 fmi:4 fmi2:1.987018845975399 fmi3:1.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 7/4 → 15/8 | s:sine note:F1 fmi:4 fmi2:0.8189515843987465 fmi3:1.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 15/8 → 2/1 | s:sine note:F1 fmi:4 fmi2:2.3782287165522575 fmi3:1.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 2/1 → 17/8 | s:sine note:F1 fmi:4 fmi2:3.838108479976654 fmi3:2 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 17/8 → 9/4 | s:sine note:F1 fmi:4 fmi2:3.613561175763607 fmi3:2.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 9/4 → 19/8 | s:sine note:F1 fmi:4 fmi2:1.3819300457835197 fmi3:2.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 19/8 → 5/2 | s:sine note:F1 fmi:4 fmi2:3.346026562154293 fmi3:2.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 5/2 → 21/8 | s:sine note:F1 fmi:4 fmi2:1.8344642966985703 fmi3:2.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 21/8 → 11/4 | s:sine note:F1 fmi:4 fmi2:0.6407739371061325 fmi3:2.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 11/4 → 23/8 | s:sine note:F1 fmi:4 fmi2:2.5329310819506645 fmi3:2.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 23/8 → 3/1 | s:sine note:F1 fmi:4 fmi2:0.06501668691635132 fmi3:2.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 3/1 → 25/8 | s:sine note:F1 fmi:4 fmi2:0.8691564425826073 fmi3:3 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 25/8 → 13/4 | s:sine note:F1 fmi:4 fmi2:1.3729755133390427 fmi3:3.125 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 13/4 → 27/8 | s:sine note:F1 fmi:4 fmi2:3.9694602862000465 fmi3:3.25 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 27/8 → 7/2 | s:sine note:F1 fmi:4 fmi2:1.6347672045230865 fmi3:3.375 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 7/2 → 29/8 | s:sine note:F1 fmi:4 fmi2:1.639795258641243 fmi3:3.5 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 29/8 → 15/4 | s:sine note:F1 fmi:4 fmi2:3.7565943151712418 fmi3:3.625 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 15/4 → 31/8 | s:sine note:F1 fmi:4 fmi2:3.2486692890524864 fmi3:3.75 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
"[ 31/8 → 4/1 | s:sine note:F1 fmi:4 fmi2:2.9446661546826363 fmi3:3.875 fmh:1.06 fmh2:10 fmh3:0.1 ]",
|
|
||||||
]
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`runs examples > example "fmsustain" example index 0 1`] = `
|
exports[`runs examples > example "fmsustain" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/6 | note:c fmi:4 fmdecay:0.1 fmsustain:1 ]",
|
"[ 0/1 → 1/6 | note:c fmi:4 fmdecay:0.1 fmsustain:1 ]",
|
||||||
@@ -8764,6 +8764,43 @@ exports[`runs examples > example "onTriggerTime" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "open" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/8 | s:bd cutoff:300 ]",
|
||||||
|
"[ 1/8 → 1/4 | s:sd cutoff:384.375 ]",
|
||||||
|
"[ 5/16 → 3/8 | s:bd cutoff:510.9375 ]",
|
||||||
|
"[ 3/8 → 1/2 | s:sd cutoff:553.125 ]",
|
||||||
|
"[ 1/2 → 5/8 | s:bd cutoff:637.5 ]",
|
||||||
|
"[ 5/8 → 3/4 | s:sd cutoff:721.875 ]",
|
||||||
|
"[ 13/16 → 7/8 | s:bd cutoff:848.4375 ]",
|
||||||
|
"[ 7/8 → 1/1 | s:sd cutoff:890.625 ]",
|
||||||
|
"[ 1/1 → 9/8 | s:bd cutoff:975 ]",
|
||||||
|
"[ 9/8 → 5/4 | s:sd cutoff:1059.375 ]",
|
||||||
|
"[ 21/16 → 11/8 | s:bd cutoff:1185.9375 ]",
|
||||||
|
"[ 11/8 → 3/2 | s:sd cutoff:1228.125 ]",
|
||||||
|
"[ 3/2 → 13/8 | s:bd cutoff:1312.5 ]",
|
||||||
|
"[ 13/8 → 7/4 | s:sd cutoff:1396.875 ]",
|
||||||
|
"[ 29/16 → 15/8 | s:bd cutoff:1523.4375 ]",
|
||||||
|
"[ 15/8 → 2/1 | s:sd cutoff:1565.625 ]",
|
||||||
|
"[ 2/1 → 17/8 | s:bd cutoff:1650 ]",
|
||||||
|
"[ 17/8 → 9/4 | s:sd cutoff:1734.375 ]",
|
||||||
|
"[ 37/16 → 19/8 | s:bd cutoff:1860.9375 ]",
|
||||||
|
"[ 19/8 → 5/2 | s:sd cutoff:1903.125 ]",
|
||||||
|
"[ 5/2 → 21/8 | s:bd cutoff:1987.5 ]",
|
||||||
|
"[ 21/8 → 11/4 | s:sd cutoff:2071.875 ]",
|
||||||
|
"[ 45/16 → 23/8 | s:bd cutoff:2198.4375 ]",
|
||||||
|
"[ 23/8 → 3/1 | s:sd cutoff:2240.625 ]",
|
||||||
|
"[ 3/1 → 25/8 | s:bd cutoff:2325 ]",
|
||||||
|
"[ 25/8 → 13/4 | s:sd cutoff:2409.375 ]",
|
||||||
|
"[ 53/16 → 27/8 | s:bd cutoff:2535.9375 ]",
|
||||||
|
"[ 27/8 → 7/2 | s:sd cutoff:2578.125 ]",
|
||||||
|
"[ 7/2 → 29/8 | s:bd cutoff:2662.5 ]",
|
||||||
|
"[ 29/8 → 15/4 | s:sd cutoff:2746.875 ]",
|
||||||
|
"[ 61/16 → 31/8 | s:bd cutoff:2873.4375 ]",
|
||||||
|
"[ 31/8 → 4/1 | s:sd cutoff:2915.625 ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "orbit" example index 0 1`] = `
|
exports[`runs examples > example "orbit" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/6 | s:hh delay:0.5 delaytime:0.25 orbit:1 ]",
|
"[ 0/1 → 1/6 | s:hh delay:0.5 delaytime:0.25 orbit:1 ]",
|
||||||
@@ -9967,6 +10004,52 @@ exports[`runs examples > example "pressBy" example index 0 1`] = `
|
|||||||
]
|
]
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "print" example index 0 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/4 | s:bd ]",
|
||||||
|
"[ 1/4 → 1/2 | s:sd ]",
|
||||||
|
"[ 1/2 → 3/4 | s:hh ]",
|
||||||
|
"[ 3/4 → 1/1 | s:cp ]",
|
||||||
|
"[ 1/1 → 5/4 | s:bd ]",
|
||||||
|
"[ 5/4 → 3/2 | s:sd ]",
|
||||||
|
"[ 3/2 → 7/4 | s:hh ]",
|
||||||
|
"[ 7/4 → 2/1 | s:cp ]",
|
||||||
|
"[ 2/1 → 9/4 | s:bd ]",
|
||||||
|
"[ 9/4 → 5/2 | s:sd ]",
|
||||||
|
"[ 5/2 → 11/4 | s:hh ]",
|
||||||
|
"[ 11/4 → 3/1 | s:cp ]",
|
||||||
|
"[ 3/1 → 13/4 | s:bd ]",
|
||||||
|
"[ 13/4 → 7/2 | s:sd ]",
|
||||||
|
"[ 7/2 → 15/4 | s:hh ]",
|
||||||
|
"[ 15/4 → 4/1 | s:cp ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`runs examples > example "print" example index 1 1`] = `
|
||||||
|
[
|
||||||
|
"[ 0/1 → 1/4 | s:bd ]",
|
||||||
|
"[ 1/4 → 1/2 | s:sd ]",
|
||||||
|
"[ 1/2 → 5/8 | s:hh ]",
|
||||||
|
"[ 5/8 → 3/4 | s:hh ]",
|
||||||
|
"[ 3/4 → 1/1 | s:cp ]",
|
||||||
|
"[ 1/1 → 5/4 | s:bd ]",
|
||||||
|
"[ 5/4 → 3/2 | s:sd ]",
|
||||||
|
"[ 3/2 → 13/8 | s:hh ]",
|
||||||
|
"[ 13/8 → 7/4 | s:hh ]",
|
||||||
|
"[ 7/4 → 2/1 | s:cp ]",
|
||||||
|
"[ 2/1 → 9/4 | s:bd ]",
|
||||||
|
"[ 9/4 → 5/2 | s:sd ]",
|
||||||
|
"[ 5/2 → 21/8 | s:hh ]",
|
||||||
|
"[ 21/8 → 11/4 | s:hh ]",
|
||||||
|
"[ 11/4 → 3/1 | s:cp ]",
|
||||||
|
"[ 3/1 → 13/4 | s:bd ]",
|
||||||
|
"[ 13/4 → 7/2 | s:sd ]",
|
||||||
|
"[ 7/2 → 29/8 | s:hh ]",
|
||||||
|
"[ 29/8 → 15/4 | s:hh ]",
|
||||||
|
"[ 15/4 → 4/1 | s:cp ]",
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`runs examples > example "progNum" example index 0 1`] = `
|
exports[`runs examples > example "progNum" example index 0 1`] = `
|
||||||
[
|
[
|
||||||
"[ 0/1 → 1/1 | note:c4 progNum:10 midichan:1 ]",
|
"[ 0/1 → 1/1 | note:c4 progNum:10 midichan:1 ]",
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ const skippedExamples = [
|
|||||||
'accelerationX',
|
'accelerationX',
|
||||||
'defaultmidimap',
|
'defaultmidimap',
|
||||||
'midimaps',
|
'midimaps',
|
||||||
'clearScope',
|
|
||||||
'bmod',
|
'bmod',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ const toneHelpersMocked = {
|
|||||||
'_pitchwheel',
|
'_pitchwheel',
|
||||||
'_pianoroll',
|
'_pianoroll',
|
||||||
'_spectrum',
|
'_spectrum',
|
||||||
|
'_print',
|
||||||
'markcss',
|
'markcss',
|
||||||
'p',
|
'p',
|
||||||
'dough',
|
'dough',
|
||||||
|
|||||||
@@ -10,11 +10,8 @@ import bundleAudioWorkletPlugin from 'vite-plugin-bundle-audioworklet';
|
|||||||
import tailwind from '@astrojs/tailwind';
|
import tailwind from '@astrojs/tailwind';
|
||||||
import AstroPWA from '@vite-pwa/astro';
|
import AstroPWA from '@vite-pwa/astro';
|
||||||
|
|
||||||
import process from 'node:process';
|
const site = process.env.STRUDEL_SITE || `https://strudel.cc/`; // root url without a path
|
||||||
|
const base = process.env.STRUDEL_BASE || '/'; // base path of the strudel site
|
||||||
const site = process.env.SITE_URL || `https://strudel.cc/`; // root url without a path
|
|
||||||
const base = process.env.BASE_PATH || ''; // base path of the strudel site
|
|
||||||
|
|
||||||
const baseNoTrailing = base.endsWith('/') ? base.slice(0, -1) : base;
|
const baseNoTrailing = base.endsWith('/') ? base.slice(0, -1) : base;
|
||||||
|
|
||||||
// this rehype plugin fixes relative links
|
// this rehype plugin fixes relative links
|
||||||
@@ -73,6 +70,7 @@ export default defineConfig({
|
|||||||
workbox: {
|
workbox: {
|
||||||
maximumFileSizeToCacheInBytes: 4194304, // 4MB
|
maximumFileSizeToCacheInBytes: 4194304, // 4MB
|
||||||
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,wav,mp3,ogg,ttf,woff2,TTF,otf}'],
|
globPatterns: ['**/*.{js,css,html,ico,png,svg,json,wav,mp3,ogg,ttf,woff2,TTF,otf}'],
|
||||||
|
globIgnores: ['img/**', '_astro/csound*.js'],
|
||||||
runtimeCaching: [
|
runtimeCaching: [
|
||||||
{
|
{
|
||||||
urlPattern: ({ url }) =>
|
urlPattern: ({ url }) =>
|
||||||
@@ -82,13 +80,14 @@ export default defineConfig({
|
|||||||
/^https:\/\/freesound\.org\/.*/i,
|
/^https:\/\/freesound\.org\/.*/i,
|
||||||
/^https:\/\/cdn\.freesound\.org\/.*/i,
|
/^https:\/\/cdn\.freesound\.org\/.*/i,
|
||||||
/^https:\/\/shabda\.ndre\.gr\/.*/i,
|
/^https:\/\/shabda\.ndre\.gr\/.*/i,
|
||||||
|
/^https:\/\/felixroos\.github\.io\/webaudiofontdata\/.*/i,
|
||||||
].some((regex) => regex.test(url)),
|
].some((regex) => regex.test(url)),
|
||||||
handler: 'CacheFirst',
|
handler: 'CacheFirst',
|
||||||
options: {
|
options: {
|
||||||
cacheName: 'external-samples',
|
cacheName: 'external-samples',
|
||||||
expiration: {
|
expiration: {
|
||||||
maxEntries: 5000,
|
maxEntries: 5000,
|
||||||
maxAgeSeconds: 60 * 60 * 24 * 30, // <== 14 days
|
maxAgeSeconds: 60 * 60 * 24 * 30, // <== 30 days
|
||||||
},
|
},
|
||||||
cacheableResponse: {
|
cacheableResponse: {
|
||||||
statuses: [0, 200],
|
statuses: [0, 200],
|
||||||
|
|||||||
@@ -48,6 +48,7 @@
|
|||||||
"@strudel/tonal": "workspace:*",
|
"@strudel/tonal": "workspace:*",
|
||||||
"@strudel/transpiler": "workspace:*",
|
"@strudel/transpiler": "workspace:*",
|
||||||
"@strudel/webaudio": "workspace:*",
|
"@strudel/webaudio": "workspace:*",
|
||||||
|
"@strudel/websocket": "workspace:*",
|
||||||
"@strudel/mondo": "workspace:*",
|
"@strudel/mondo": "workspace:*",
|
||||||
"@strudel/xen": "workspace:*",
|
"@strudel/xen": "workspace:*",
|
||||||
"@supabase/supabase-js": "^2.48.1",
|
"@supabase/supabase-js": "^2.48.1",
|
||||||
|
|||||||
Vendored
+3
@@ -2,3 +2,6 @@
|
|||||||
/// <reference types="astro/client" />
|
/// <reference types="astro/client" />
|
||||||
|
|
||||||
declare module 'date-fns';
|
declare module 'date-fns';
|
||||||
|
declare module '@strudel/*';
|
||||||
|
declare module 'dough-synth';
|
||||||
|
declare module 'paho-mqtt';
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { getMetadata } from './metadata_parser';
|
import { getMetadata } from './metadata_parser';
|
||||||
|
|
||||||
export function getMyPatterns() {
|
export function getMyPatterns() {
|
||||||
const my = import.meta.glob('../../my-patterns/**', { as: 'raw', eager: true });
|
const my = import.meta.glob('../../my-patterns/**', { query: '?raw', eager: true });
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(my)
|
Object.entries(my)
|
||||||
.filter(([name]) => name.endsWith('.txt'))
|
.filter(([name]) => name.endsWith('.txt'))
|
||||||
|
|||||||
@@ -184,9 +184,9 @@ Each filter has 2 parameters:
|
|||||||
|
|
||||||
Amplitude modulation changes the amplitude (gain) periodically over time.
|
Amplitude modulation changes the amplitude (gain) periodically over time.
|
||||||
|
|
||||||
## am
|
## tremolo
|
||||||
|
|
||||||
<JsDoc client:idle name="am" h={0} />
|
<JsDoc client:idle name="tremolo" h={0} />
|
||||||
|
|
||||||
## tremolosync
|
## tremolosync
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ These are the equivalents used by the Mini Notation:
|
|||||||
| `stack(x, y)` | `"x,y"` |
|
| `stack(x, y)` | `"x,y"` |
|
||||||
| `stepcat([3,x],[2,y])` | `"x@3 y@2"` |
|
| `stepcat([3,x],[2,y])` | `"x@3 y@2"` |
|
||||||
| `polymeter([a, b, c], [x, y])` | `"{a b c, x y}"` |
|
| `polymeter([a, b, c], [x, y])` | `"{a b c, x y}"` |
|
||||||
| `polymeterSteps(2, x, y, z)` | `"{x y z}%2"` |
|
|
||||||
| `silence` | `"~"` |
|
| `silence` | `"~"` |
|
||||||
|
|
||||||
## cat
|
## cat
|
||||||
@@ -45,10 +44,6 @@ These are the equivalents used by the Mini Notation:
|
|||||||
|
|
||||||
<JsDoc client:idle name="polymeter" h={0} />
|
<JsDoc client:idle name="polymeter" h={0} />
|
||||||
|
|
||||||
## polymeterSteps
|
|
||||||
|
|
||||||
<JsDoc client:idle name="polymeterSteps" h={0} />
|
|
||||||
|
|
||||||
## silence
|
## silence
|
||||||
|
|
||||||
<JsDoc client:idle name="silence" h={0} />
|
<JsDoc client:idle name="silence" h={0} />
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<script is:inline>
|
||||||
|
window.location.pathname = `/workshop/getting-started`;
|
||||||
|
</script>
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
---
|
|
||||||
title: Getting Started
|
|
||||||
layout: ../../layouts/MainLayout.astro
|
|
||||||
---
|
|
||||||
|
|
||||||
import { MiniRepl } from '../../docs/MiniRepl';
|
|
||||||
import { JsDoc } from '../../docs/JsDoc';
|
|
||||||
|
|
||||||
# Welcome
|
|
||||||
|
|
||||||
Welcome to the Strudel documentation pages!
|
|
||||||
|
|
||||||
These pages will introduce you to [Strudel](https://strudel.cc/), a web-based [live coding](https://github.com/toplap/awesome-livecoding/) environment that implements the [Tidal Cycles](https://tidalcycles.org) algorithmic pattern language.
|
|
||||||
|
|
||||||
# What is Strudel?
|
|
||||||
|
|
||||||
[Strudel](https://strudel.cc/) is a version of [Tidal Cycles](https://tidalcycles.org) written in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), initiated by [Alex McLean](https://slab.org) and [Felix Roos](https://froos.cc/) in 2022.
|
|
||||||
Tidal Cycles, also known as Tidal, is a language for [algorithmic pattern](https://algorithmicpattern.org), and though it is most commonly used for [making music](https://tidalcycles.org/docs/showcase), it can be used for any kind of pattern making activity, including [weaving](https://www.youtube.com/watch?v=TfEmEsusXjU).
|
|
||||||
|
|
||||||
Tidal was first implemented as a library written in the [Haskell](https://www.haskell.org/) functional programming language, and by itself it does not make any sound.
|
|
||||||
To make sound, it has to be connected to a sound engine, and by default this is a [SuperCollider](https://supercollider.github.io/) plugin called [SuperDirt](https://github.com/musikinformatik/SuperDirt/).
|
|
||||||
As such, it can be difficult for first-time users to install both Tidal Cycles and SuperDirt, as there are many small details to get right.
|
|
||||||
Strudel however runs directly in your web browser, does not require any custom software installation, and can make sound all by itself.
|
|
||||||
|
|
||||||
# Strudel REPL and MiniREPL
|
|
||||||
|
|
||||||
The main place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/) ([what is a REPL?](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), but in these pages you will also encounter interactive "MiniREPLs" where you can listen to and edit Strudel patterns.
|
|
||||||
Try clicking the play icon below:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`s("bd sd")`} punchcard />
|
|
||||||
|
|
||||||
Then edit the text so it reads `s("bd sd cp hh")` and click the refresh icon.
|
|
||||||
Congratulations, you have now live coded your first Strudel pattern!
|
|
||||||
|
|
||||||
With Strudel, you can expressively write dynamic music pieces.
|
|
||||||
You don't need to know JavaScript or Tidal Cycles to make music with Strudel.
|
|
||||||
This interactive tutorial will guide you through the basics of Strudel.
|
|
||||||
|
|
||||||
# Show me some demos!
|
|
||||||
|
|
||||||
To see and hear what Strudel can do, visit the [Strudel REPL](https://strudel.cc/) and click the Shuffle icon in the top menu bar.
|
|
||||||
You can get a feel for Strudel by browsing and editing these examples and clicking the Refresh icon to update.
|
|
||||||
|
|
||||||
You can also browse through the examples [here](/examples).
|
|
||||||
|
|
||||||
Alternatively, you can get a taste of what Strudel can do by clicking play on this track:
|
|
||||||
|
|
||||||
<MiniRepl
|
|
||||||
client:idle
|
|
||||||
tune={`samples({
|
|
||||||
bd: ['bd/BT0AADA.wav','bd/BT0AAD0.wav','bd/BT0A0DA.wav','bd/BT0A0D3.wav','bd/BT0A0D0.wav','bd/BT0A0A7.wav'],
|
|
||||||
sd: ['sd/rytm-01-classic.wav','sd/rytm-00-hard.wav'],
|
|
||||||
hh: ['hh27/000_hh27closedhh.wav','hh/000_hh3closedhh.wav'],
|
|
||||||
}, 'github:tidalcycles/dirt-samples');
|
|
||||||
stack(
|
|
||||||
s("bd,[~ <sd!3 sd(3,4,2)>],hh*8") // drums
|
|
||||||
.speed(perlin.range(.7,.9)) // random sample speed variation
|
|
||||||
,"<a1 b1\*2 a1(3,8) e2>" // bassline
|
|
||||||
.off(1/8,x=>x.add(12).degradeBy(.5)) // random octave jumps
|
|
||||||
.add(perlin.range(0,.5)) // random pitch variation
|
|
||||||
.superimpose(add(.05)) // add second, slightly detuned voice
|
|
||||||
.note() // wrap in "note"
|
|
||||||
.decay(.15).sustain(0) // make each note of equal length
|
|
||||||
.s('sawtooth') // waveform
|
|
||||||
.gain(.4) // turn down
|
|
||||||
.cutoff(sine.slow(7).range(300,5000)) // automate cutoff
|
|
||||||
,"<Am7!3 <Em7 E7b13 Em7 Ebm7b5>>".voicings('lefthand') // chords
|
|
||||||
.superimpose(x=>x.add(.04)) // add second, slightly detuned voice
|
|
||||||
.add(perlin.range(0,.5)) // random pitch variation
|
|
||||||
.note() // wrap in "note"
|
|
||||||
.s('sawtooth') // waveform
|
|
||||||
.gain(.16) // turn down
|
|
||||||
.cutoff(500) // fixed cutoff
|
|
||||||
.attack(1) // slowly fade in
|
|
||||||
)
|
|
||||||
.slow(3/2)`}
|
|
||||||
/>
|
|
||||||
|
|
||||||
# Strudel is a work in progress 🚧
|
|
||||||
|
|
||||||
Please note that this project is still in its experimental state.
|
|
||||||
In the future, parts of it might change significantly.
|
|
||||||
This tutorial is also far from complete.
|
|
||||||
You can contribute to it clicking 'Edit this page' in the top right, or by visiting the [Strudel GitHub page](https://codeberg.org/uzu/strudel/).
|
|
||||||
|
|
||||||
# What's next?
|
|
||||||
|
|
||||||
Head on over to the [Notes](/learn/notes) page.
|
|
||||||
|
|
||||||
<br />
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<script is:inline>
|
||||||
|
window.location.pathname = `/workshop/first-notes`;
|
||||||
|
</script>
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
---
|
|
||||||
title: Notes
|
|
||||||
layout: ../../layouts/MainLayout.astro
|
|
||||||
---
|
|
||||||
|
|
||||||
import { MiniRepl } from '../../docs/MiniRepl';
|
|
||||||
import { JsDoc } from '../../docs/JsDoc';
|
|
||||||
|
|
||||||
# Notes
|
|
||||||
|
|
||||||
Pitches are an important building block in many musical traditions.
|
|
||||||
In Strudel, pitches can be expressed as note names, note numbers or frequencies.
|
|
||||||
Here's the same pattern written in three different ways:
|
|
||||||
|
|
||||||
- `note`: letter notation, good for those who are familiar with western music theory:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
|
|
||||||
|
|
||||||
- `note`: number notation, good for those who want to use recognisable pitches, but don't care about music theory:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("57 61 64 69")`} />
|
|
||||||
|
|
||||||
- `freq`: frequency notation, good for those who want to go beyond standardised tuning systems:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("220 275 330 440")`} />
|
|
||||||
|
|
||||||
Let's look at those in more detail...
|
|
||||||
|
|
||||||
## `note` names
|
|
||||||
|
|
||||||
Notes names can be notated with the note letter, followed by the octave number. You can notate flats with `b` and sharps with `#`.
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
|
|
||||||
|
|
||||||
By the way, you can edit the contents of the player, and press "update" to hear your change!
|
|
||||||
You can also press "play" on the next player without needing to stop the last one.
|
|
||||||
|
|
||||||
## `note` numbers
|
|
||||||
|
|
||||||
If you prefer, you can also use numbers with `note` instead:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("57 61 64 69")`} />
|
|
||||||
|
|
||||||
These numbers are interpreted as so called [MIDI numbers](https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies), where adjacent whole numbers are one 'semitone' apart.
|
|
||||||
|
|
||||||
You could also write decimal numbers to get 'microtonal' pitches (in between the black and white piano notes):
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("74.5 75 75.5 76")`} />
|
|
||||||
|
|
||||||
## `freq`
|
|
||||||
|
|
||||||
To get maximum freedom, you can also use `freq` to directly control the frequency:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("220 275 330 440")`} />
|
|
||||||
|
|
||||||
## Hearing and frequency
|
|
||||||
|
|
||||||
In the above example, we play A3 (220Hz), C#4 natural (275Hz), E4 (330Hz) and A4 (440Hz), mirroring our previous examples.
|
|
||||||
|
|
||||||
But can you hear the difference between these individual frequencies?
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("220 221 223 224")`} />
|
|
||||||
|
|
||||||
How about these?
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("2020 2021 2023 2024")`} />
|
|
||||||
|
|
||||||
The higher we go up...
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("5020 5021 5023 5024")`} />
|
|
||||||
|
|
||||||
The less distance we can hear between the frequencies!
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("10020 10021 10023 10024")`} />
|
|
||||||
|
|
||||||
Why is this? [Human hearing operates logarithmically](https://www.audiocheck.net/soundtests_nonlinear.php).
|
|
||||||
|
|
||||||
## From notes to sounds
|
|
||||||
|
|
||||||
In this page, when we played a pattern of notes like this:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4")`} />
|
|
||||||
|
|
||||||
We heard a simple synthesised sound, in fact we heard a [triangle wave oscillator](https://en.wikipedia.org/wiki/Triangle_wave).
|
|
||||||
|
|
||||||
This is the default synthesiser used by Strudel, but how do we then make different sounds in Strudel?
|
|
||||||
|
|
||||||
Let's find out in the next page on [Sounds](/learn/sounds).
|
|
||||||
|
|
||||||
<br />
|
|
||||||
@@ -329,7 +329,7 @@ Sampler effects are functions that can be used to change the behaviour of sample
|
|||||||
|
|
||||||
### begin
|
### begin
|
||||||
|
|
||||||
<JsDoc client:idle name="Pattern.begin" h={0} />
|
<JsDoc client:idle name="begin" h={0} />
|
||||||
|
|
||||||
### end
|
### end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<script is:inline>
|
||||||
|
window.location.pathname = `/workshop/first-sounds`;
|
||||||
|
</script>
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
---
|
|
||||||
title: Sounds
|
|
||||||
layout: ../../layouts/MainLayout.astro
|
|
||||||
---
|
|
||||||
|
|
||||||
import { MiniRepl } from '../../docs/MiniRepl';
|
|
||||||
import { JsDoc } from '../../docs/JsDoc';
|
|
||||||
|
|
||||||
# Sounds
|
|
||||||
|
|
||||||
We can play sounds with `s`, in two different ways:
|
|
||||||
|
|
||||||
- `s` can trigger audio samples, where a sound file is loaded in the background and played back:
|
|
||||||
<MiniRepl client:idle tune={`s("bd hh sd hh")`} />
|
|
||||||
- `s` can trigger audio synthesisers, which are synthesised in real-time using code also running in the background:
|
|
||||||
<MiniRepl client:idle tune={`s("sawtooth square triangle sine")`} />
|
|
||||||
|
|
||||||
You can learn more about both of these approaches in the pages [Synths](/learn/synths) and [Samples](/learn/samples).
|
|
||||||
|
|
||||||
# Combining notes and sounds
|
|
||||||
|
|
||||||
In both of the above cases, we are no longer directly controlling the `note`/`freq` of the sound heard via `s`, as we were in the [Notes](/workshop/first-notes/) page.
|
|
||||||
|
|
||||||
So how can we both control the sound and the pitch? We can _combine_ `note`/`freq` with `s` to change the sound of our pitches:
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("a3 c#4 e4 a4").s("sawtooth")`} />
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`note("57 61 64 69").s("sine")`} />
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("220 275 330 440").s("triangle")`} />
|
|
||||||
|
|
||||||
The last example will actually sound the same with or without `s`, because `triangle` is the default value for `s`.
|
|
||||||
|
|
||||||
What about combining different notes with different sounds at the same time?
|
|
||||||
|
|
||||||
<MiniRepl client:idle tune={`freq("220 275 330 440 550").s("triangle sawtooth sine")`} />
|
|
||||||
|
|
||||||
Hmm, something interesting is going on there, related to there being five notes and three sounds.
|
|
||||||
|
|
||||||
Let's now take a step back and think about the Strudel [Code](/learn/code/) we've been hearing so far.
|
|
||||||
@@ -103,6 +103,10 @@ What follows is the API doc of all the options you can pass:
|
|||||||
|
|
||||||
<JsDoc client:idle name="spectrum" h={0} />
|
<JsDoc client:idle name="spectrum" h={0} />
|
||||||
|
|
||||||
|
## Print
|
||||||
|
|
||||||
|
<JsDoc client:idle name="print" h={0} />
|
||||||
|
|
||||||
## markcss
|
## markcss
|
||||||
|
|
||||||
<JsDoc client:idle name="markcss" h={0} />
|
<JsDoc client:idle name="markcss" h={0} />
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ These functions allow the use of scales other than your typical chromatic 12 bas
|
|||||||
|
|
||||||
{/* TODO (maybe): combine jsdoc things in tune.mjs with here */}
|
{/* TODO (maybe): combine jsdoc things in tune.mjs with here */}
|
||||||
|
|
||||||
<JsDoc client:idle name="tune" h={0} />
|
{/* <JsDoc client:idle name="tune" h={0} /> */}
|
||||||
|
|
||||||
Here's an example of how to configure a basic hexany scale:
|
Here's an example of how to configure a basic hexany scale:
|
||||||
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
---
|
|
||||||
title: Helix Keybindings
|
|
||||||
layout: ../../layouts/MainLayout.astro
|
|
||||||
---
|
|
||||||
|
|
||||||
# Helix Keybindings in the REPL
|
|
||||||
|
|
||||||
The Strudel REPL supports [Helix editor](https://helix-editor.com/) keybindings through the `codemirror-helix` extension. Helix is a post-modern modal text editor with a focus on selection-first editing and multiple cursors.
|
|
||||||
|
|
||||||
## Enabling Helix Mode
|
|
||||||
|
|
||||||
1. Open the Settings panel in the REPL (click the settings icon or use the keyboard shortcut)
|
|
||||||
2. Find the "Keybindings" section
|
|
||||||
3. Select "Helix" from the available options
|
|
||||||
|
|
||||||
## Key Differences from Vim
|
|
||||||
|
|
||||||
Helix uses a selection-first approach, which means:
|
|
||||||
|
|
||||||
- **Selection → Action** (Helix) vs **Action → Motion** (Vim)
|
|
||||||
- For example, to delete a word in Helix: `w` (select word) → `d` (delete)
|
|
||||||
- In Vim, it would be: `dw` (delete word)
|
|
||||||
|
|
||||||
## Common Helix Commands
|
|
||||||
|
|
||||||
### Normal Mode
|
|
||||||
|
|
||||||
- `i` — Enter insert mode before selection
|
|
||||||
- `a` — Enter insert mode after selection
|
|
||||||
- `v` — Enter visual/select mode
|
|
||||||
- `w` — Select next word
|
|
||||||
- `e` — Select to end of word
|
|
||||||
- `b` — Select previous word
|
|
||||||
- `x` — Select/extend line
|
|
||||||
- `d` — Delete selection
|
|
||||||
- `c` — Change selection (delete and enter insert mode)
|
|
||||||
- `y` — Yank (copy) selection
|
|
||||||
- `p` — Paste after selection
|
|
||||||
- `u` — Undo
|
|
||||||
- `U` — Redo
|
|
||||||
- `/` — Search
|
|
||||||
- `n` — Select next search match
|
|
||||||
- `N` — Select previous search match
|
|
||||||
|
|
||||||
### Movement
|
|
||||||
|
|
||||||
- `h, j, k, l` — Move left, down, up, right
|
|
||||||
- `gg` — Go to start of document
|
|
||||||
- `ge` — Go to end of document
|
|
||||||
- `{` / `}` — Move to previous/next paragraph
|
|
||||||
- `%` — Match bracket
|
|
||||||
|
|
||||||
### Multi-cursor
|
|
||||||
|
|
||||||
- `C` — Duplicate cursor to line below
|
|
||||||
- `Alt-C` — Duplicate cursor to line above
|
|
||||||
- `,` — Remove primary cursor
|
|
||||||
- `Alt-,` — Remove all secondary cursors
|
|
||||||
|
|
||||||
## Strudel-Specific Features
|
|
||||||
|
|
||||||
Currently, Helix mode in Strudel provides standard Helix keybindings. Unlike Vim mode, there are no custom Strudel-specific commands (like `:w` to evaluate) yet.
|
|
||||||
|
|
||||||
To evaluate code while in Helix mode, use the standard shortcuts:
|
|
||||||
|
|
||||||
- `Ctrl+Enter` or `Alt+Enter` — Evaluate code
|
|
||||||
- `Alt+.` — Stop playback
|
|
||||||
|
|
||||||
## Resources
|
|
||||||
|
|
||||||
- [Helix Documentation](https://docs.helix-editor.com/)
|
|
||||||
- [Helix Keymap](https://docs.helix-editor.com/keymap.html)
|
|
||||||
- [codemirror-helix on npm](https://www.npmjs.com/package/codemirror-helix)
|
|
||||||
- [codemirror-helix on GitLab](https://gitlab.com/_rvidal/codemirror-helix)
|
|
||||||
|
|
||||||
## Notes
|
|
||||||
|
|
||||||
- The `codemirror-helix` extension is described as an "initial version" and may not implement all Helix features
|
|
||||||
- Behavior may differ slightly from the native Helix editor
|
|
||||||
- If you encounter issues, you can switch back to other keybinding modes in Settings
|
|
||||||
- The keybinding preference is saved in your browser's local storage
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
If you'd like to add Strudel-specific Helix commands (similar to Vim's `:w` for evaluate), contributions are welcome! See the implementation in `/packages/codemirror/keybindings.mjs` for reference.
|
|
||||||
@@ -117,10 +117,6 @@ Here's an example AST for `c3 [e3 g3]`
|
|||||||
|
|
||||||
which translates to `seq(c3, seq(e3, g3))`
|
which translates to `seq(c3, seq(e3, g3))`
|
||||||
|
|
||||||
## Vim Keybindings
|
|
||||||
|
|
||||||
See the separate page on Vim shortcuts for a quick reference: [/technical-manual/vim](/technical-manual/vim)
|
|
||||||
|
|
||||||
## Scheduling Events
|
## Scheduling Events
|
||||||
|
|
||||||
After an instance of `Pattern` is obtained from the user code,
|
After an instance of `Pattern` is obtained from the user code,
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
---
|
|
||||||
title: Vim Shortcuts
|
|
||||||
layout: ../../layouts/MainLayout.astro
|
|
||||||
---
|
|
||||||
|
|
||||||
# Vim Shortcuts in the REPL
|
|
||||||
|
|
||||||
When the REPL editor (CodeMirror) is configured to use Vim keybindings, the following commands are available:
|
|
||||||
|
|
||||||
- :w — Evaluate the current code
|
|
||||||
|
|
||||||
- Triggers the same evaluation as Ctrl+Enter / Alt+Enter
|
|
||||||
- You'll see messages in the Console panel such as:
|
|
||||||
- [vim] :w — evaluating code
|
|
||||||
- [repl] evaluate via event
|
|
||||||
- [eval] code updated
|
|
||||||
|
|
||||||
- :q — Stop/pause playback
|
|
||||||
|
|
||||||
- Triggers the same stop action as Alt+.
|
|
||||||
- Useful to quickly stop scheduling without leaving Vim mode
|
|
||||||
|
|
||||||
- gc — Toggle line comments for the current selection(s)
|
|
||||||
|
|
||||||
- Works in normal and visual mode
|
|
||||||
- If there's a selection, all selected lines are toggled
|
|
||||||
|
|
||||||
Notes
|
|
||||||
|
|
||||||
- Behavior respects the current language mode in the editor for comment syntax.
|
|
||||||
- If multiple REPL editors are open, commands target the active editor. The implementation dispatches custom events handled by the editor.
|
|
||||||
- If you don't see the Console panel, open the right panel in the REPL UI.
|
|
||||||
|
|
||||||
Troubleshooting
|
|
||||||
|
|
||||||
- If :w logs but evaluation doesn't apply, ensure Vim keybindings are active and try again. You can also use Ctrl+Enter as a fallback.
|
|
||||||
- For :q / gc, ensure focus is inside the editor. If an error occurs, reload the page to reset editor state and try again.
|
|
||||||
|
|
||||||
## Adding custom keybindings
|
|
||||||
|
|
||||||
To add custom keybindings the `Vim` object can be used (either from within a pattern or in a prebake script)
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
// Map 'jk' to Escape in normal mode
|
|
||||||
Vim.map('jk', '<Esc>', 'insert');
|
|
||||||
// Map 'U' to :w (Evaluate the current code)
|
|
||||||
Vim.map('U', ':w<CR>', 'normal');
|
|
||||||
// Map 'Q' to :q — Stop/pause playback
|
|
||||||
Vim.map('Q', ':q<CR>', 'normal');
|
|
||||||
// Map 'J' to find next '$' (jump to next label)
|
|
||||||
Vim.map('J', '/\\$<CR>', 'normal');
|
|
||||||
// Map 'K' to find previous '$' (jump to previous label)
|
|
||||||
Vim.map('K', '?\\$<CR>', 'normal');
|
|
||||||
```
|
|
||||||
|
|
||||||
For more information on how to use the `Vim` object see [CodeMirror Vim](https://github.com/replit/codemirror-vim)
|
|
||||||
@@ -186,7 +186,7 @@ But don't worry if you don't know these terms, as they are not required to make
|
|||||||
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
**Add a rests in a sequence with '-' or '~'**
|
**Add a rest in a sequence with '-' or '~'**
|
||||||
|
|
||||||
<MiniRepl client:visible tune={`sound("bd hh - rim - bd hh rim")`} punchcard />
|
<MiniRepl client:visible tune={`sound("bd hh - rim - bd hh rim")`} punchcard />
|
||||||
|
|
||||||
|
|||||||
@@ -13,24 +13,41 @@ import { examples } from '../../examples.mjs';
|
|||||||
Welcome to the Strudel documentation pages!
|
Welcome to the Strudel documentation pages!
|
||||||
You've come to the right place if you want to learn how to make music with code.
|
You've come to the right place if you want to learn how to make music with code.
|
||||||
|
|
||||||
|
These pages will introduce you to [Strudel](https://strudel.cc/), a web-based [live coding](https://codeberg.org/toplap/awesome-livecoding/) environment that implements the [Tidal Cycles](https://tidalcycles.org) algorithmic pattern language.
|
||||||
|
|
||||||
## What is Strudel?
|
## What is Strudel?
|
||||||
|
|
||||||
With Strudel, you can expressively write dynamic music pieces.<br/>
|
With Strudel, you can expressively write dynamic music pieces.<br/>
|
||||||
It is an official port of the [Tidal Cycles](https://tidalcycles.org/) pattern language to JavaScript.<br/>
|
|
||||||
|
[Strudel](https://strudel.cc/) is a version of [Tidal Cycles](https://tidalcycles.org) written in [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), initiated by [Alex McLean](https://slab.org) and [Felix Roos](https://froos.cc/) in 2022, quickly growing into a collective free/open source project with major [contributors and maintainers](https://codeberg.org/uzu/strudel/activity/contributors) including [Jade Rowland](https://www.instagram.com/_switch_angel/) and [Aria](https://www.instagram.com/gglossingg/).
|
||||||
|
Tidal Cycles, also known as Tidal, is a language for [algorithmic pattern](https://algorithmicpattern.org), and though it is most commonly used for [making music](https://tidalcycles.org/docs/showcase), it can be used for any kind of pattern making activity, including [weaving](https://www.youtube.com/watch?v=TfEmEsusXjU).
|
||||||
|
|
||||||
|
Tidal was first implemented as a library written in the [Haskell](https://www.haskell.org/) functional programming language, and by itself it does not make any sound.
|
||||||
|
To make sound, it has to be connected to a sound engine, and by default this is a [SuperCollider](https://supercollider.github.io/) plugin called [SuperDirt](https://codeberg.org/musikinformatik/SuperDirt).
|
||||||
|
As such, it can be difficult for first-time users to install both Tidal Cycles and SuperDirt, as there are many small details to get right.
|
||||||
|
Strudel however runs directly in your web browser, does not require any custom software installation, and can make sound all by itself.
|
||||||
|
|
||||||
You don't need to know JavaScript or Tidal Cycles to make music with Strudel.
|
You don't need to know JavaScript or Tidal Cycles to make music with Strudel.
|
||||||
This interactive tutorial will guide you through the basics of Strudel.<br/>
|
This interactive tutorial will guide you through the basics of Strudel.<br/>
|
||||||
The best place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/)
|
|
||||||
|
|
||||||
<div className="clear-both" />
|
|
||||||
|
|
||||||
## What can you do with Strudel?
|
## What can you do with Strudel?
|
||||||
|
|
||||||
- live code music: make music with code in real time
|
- Live code music: make music with code in real time.
|
||||||
- algorithmic composition: compose music using tidal's unique approach to pattern manipulation
|
- Algorithmic composition: compose music using tidal's unique approach to pattern manipulation.
|
||||||
- teaching: focussing on a low barrier of entry, Strudel is a good fit for teaching music and code at the same time.
|
- Teaching: focussing on a low barrier of entry, Strudel is a good fit for teaching music and code at the same time.
|
||||||
- integrate into your existing music setup: either via MIDI or OSC, you can use Strudel as a really flexible sequencer
|
- Integrate into your existing music setup: either via MIDI or OSC, you can use Strudel as a really flexible sequencer.
|
||||||
|
|
||||||
## Examples
|
## Strudel REPL and MiniREPL
|
||||||
|
|
||||||
|
The main place to actually make music with Strudel is the [Strudel REPL](https://strudel.cc/) ([what is a REPL?](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), but in these pages you will also encounter interactive "MiniREPLs" where you can listen to and edit Strudel patterns.
|
||||||
|
Try clicking the play icon below:
|
||||||
|
|
||||||
|
<MiniRepl client:idle tune={`s("bd sd")`} punchcard />
|
||||||
|
|
||||||
|
Then edit the text so it reads `s("bd sd cp hh")` and click the refresh icon.
|
||||||
|
Congratulations, you have now live coded your first Strudel pattern!
|
||||||
|
|
||||||
|
## Show me some demos!
|
||||||
|
|
||||||
Here are some examples of how strudel can sound:
|
Here are some examples of how strudel can sound:
|
||||||
|
|
||||||
@@ -38,6 +55,10 @@ Here are some examples of how strudel can sound:
|
|||||||
|
|
||||||
These examples cannot fully encompass the variety of things you can do, so [check out the showcase](/intro/showcase/) for some videos of how people use Strudel.
|
These examples cannot fully encompass the variety of things you can do, so [check out the showcase](/intro/showcase/) for some videos of how people use Strudel.
|
||||||
|
|
||||||
|
## Contribute to Strudel
|
||||||
|
|
||||||
|
You can contribute to it clicking 'Edit this page' in the top right, or by visiting the [Strudel Codeberg page](https://codeberg.org/uzu/strudel/).
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
The best way to start learning Strudel is the workshop.
|
The best way to start learning Strudel is the workshop.
|
||||||
|
|||||||
@@ -5,9 +5,8 @@ import { Textbox } from '@src/repl/components/panel/SettingsTab';
|
|||||||
import { settingsMap, useSettings } from '@src/settings.mjs';
|
import { settingsMap, useSettings } from '@src/settings.mjs';
|
||||||
|
|
||||||
const isValid = ({ name, description, tags = [] }) => {
|
const isValid = ({ name, description, tags = [] }) => {
|
||||||
const isSupradoughOnly = tags.includes('supradough') && !tags.includes('superdough');
|
|
||||||
const isSuperdirtOnly = tags.includes('superdirt') && !tags.includes('superdough');
|
const isSuperdirtOnly = tags.includes('superdirt') && !tags.includes('superdough');
|
||||||
return name && !name.startsWith('_') && !!description && !isSupradoughOnly && !isSuperdirtOnly;
|
return name && !name.startsWith('_') && !!description && !isSuperdirtOnly;
|
||||||
};
|
};
|
||||||
|
|
||||||
const availableFunctions = (() => {
|
const availableFunctions = (() => {
|
||||||
@@ -38,7 +37,7 @@ const availableFunctions = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
const tagCounts = {};
|
const tagCounts = {};
|
||||||
const ignoredTags = ['supradough', 'superdirt'];
|
const ignoredTags = ['superdirt'];
|
||||||
// const tagOptions = { all: `all (${availableFunctions.length})` };
|
// const tagOptions = { all: `all (${availableFunctions.length})` };
|
||||||
const tagOptions = { all: `all` };
|
const tagOptions = { all: `all` };
|
||||||
for (const doc of availableFunctions) {
|
for (const doc of availableFunctions) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { confirmDialog } from '../../util.mjs';
|
|||||||
import { DEFAULT_MAX_POLYPHONY, setMaxPolyphony, setMultiChannelOrbits } from '@strudel/webaudio';
|
import { DEFAULT_MAX_POLYPHONY, setMaxPolyphony, setMultiChannelOrbits } from '@strudel/webaudio';
|
||||||
import { ActionButton } from '../button/action-button.jsx';
|
import { ActionButton } from '../button/action-button.jsx';
|
||||||
import { exportScript, ImportPrebakeScriptButton } from './ImportPrebakeScriptButton.jsx';
|
import { exportScript, ImportPrebakeScriptButton } from './ImportPrebakeScriptButton.jsx';
|
||||||
import { useEffect, useRef } from 'react';
|
import { useRef } from 'react';
|
||||||
import cx from '@src/cx.mjs';
|
import cx from '@src/cx.mjs';
|
||||||
|
|
||||||
const inputClass =
|
const inputClass =
|
||||||
@@ -147,7 +147,6 @@ function MainSettingsContent({ started }) {
|
|||||||
isTabIndentationEnabled,
|
isTabIndentationEnabled,
|
||||||
isMultiCursorEnabled,
|
isMultiCursorEnabled,
|
||||||
patternAutoStart,
|
patternAutoStart,
|
||||||
isBlockBasedEvalEnabled,
|
|
||||||
} = useSettings();
|
} = useSettings();
|
||||||
const shouldAlwaysSync = isUdels();
|
const shouldAlwaysSync = isUdels();
|
||||||
const canChangeAudioDevice = AudioContext.prototype.setSinkId != null;
|
const canChangeAudioDevice = AudioContext.prototype.setSinkId != null;
|
||||||
@@ -235,7 +234,7 @@ function MainSettingsContent({ started }) {
|
|||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
value={keybindings}
|
value={keybindings}
|
||||||
onChange={(keybindings) => settingsMap.setKey('keybindings', keybindings)}
|
onChange={(keybindings) => settingsMap.setKey('keybindings', keybindings)}
|
||||||
items={{ codemirror: 'Codemirror', vim: 'Vim', emacs: 'Emacs', helix: 'Helix', vscode: 'VSCode' }}
|
items={{ codemirror: 'Codemirror', vim: 'Vim', emacs: 'Emacs', vscode: 'VSCode' }}
|
||||||
></ButtonGroup>
|
></ButtonGroup>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem label="Panel Position">
|
<FormItem label="Panel Position">
|
||||||
@@ -296,11 +295,6 @@ function MainSettingsContent({ started }) {
|
|||||||
onChange={(cbEvent) => settingsMap.setKey('isMultiCursorEnabled', cbEvent.target.checked)}
|
onChange={(cbEvent) => settingsMap.setKey('isMultiCursorEnabled', cbEvent.target.checked)}
|
||||||
value={isMultiCursorEnabled}
|
value={isMultiCursorEnabled}
|
||||||
/>
|
/>
|
||||||
<Checkbox
|
|
||||||
label="Enable Block-based Evaluation (EXPERIMENTAL)"
|
|
||||||
onChange={(cbEvent) => settingsMap.setKey('isBlockBasedEvalEnabled', cbEvent.target.checked)}
|
|
||||||
value={isBlockBasedEvalEnabled}
|
|
||||||
/>
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label="Enable flashing on evaluation"
|
label="Enable flashing on evaluation"
|
||||||
onChange={(cbEvent) => settingsMap.setKey('isFlashEnabled', cbEvent.target.checked)}
|
onChange={(cbEvent) => settingsMap.setKey('isFlashEnabled', cbEvent.target.checked)}
|
||||||
@@ -356,11 +350,6 @@ function MainSettingsContent({ started }) {
|
|||||||
function PrebakeSettingsContent() {
|
function PrebakeSettingsContent() {
|
||||||
const { fontFamily, includePrebakeScriptInShare, prebakeScript } = useSettings();
|
const { fontFamily, includePrebakeScriptInShare, prebakeScript } = useSettings();
|
||||||
const editorRef = useRef();
|
const editorRef = useRef();
|
||||||
useEffect(() => {
|
|
||||||
return () => {
|
|
||||||
editorRef.current?.cleanup();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col h-full text-foreground w-full overflow-auto" style={{ fontFamily }}>
|
<div className="flex flex-col h-full text-foreground w-full overflow-auto" style={{ fontFamily }}>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { toggleLineComment } from '@codemirror/commands';
|
|
||||||
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
import { javascript, javascriptLanguage } from '@codemirror/lang-javascript';
|
||||||
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
import { defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
||||||
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
import { Compartment, EditorState, Prec } from '@codemirror/state';
|
||||||
@@ -63,28 +62,6 @@ export class PrebakeCodeMirror {
|
|||||||
state,
|
state,
|
||||||
parent: container,
|
parent: container,
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleSaveEvent = async (e) => {
|
|
||||||
if (e.detail.view !== this.view) {
|
|
||||||
return; // ignore events from other editors
|
|
||||||
}
|
|
||||||
await this.savePrebake();
|
|
||||||
e?.cancelable && e.preventDefault?.();
|
|
||||||
};
|
|
||||||
const handleToggleComment = (e) => {
|
|
||||||
if (e.detail.view !== this.view) {
|
|
||||||
return; // ignore events from other editors
|
|
||||||
}
|
|
||||||
this.toggleComment();
|
|
||||||
e?.cancelable && e.preventDefault?.();
|
|
||||||
};
|
|
||||||
|
|
||||||
document.addEventListener('repl-evaluate', handleSaveEvent);
|
|
||||||
document.addEventListener('repl-toggle-comment', handleToggleComment);
|
|
||||||
this.cleanup = () => {
|
|
||||||
document.removeEventListener('prebake-evaluate', handleSaveEvent);
|
|
||||||
document.removeEventListener('prebake-toggle-comment', handleToggleComment);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async savePrebake() {
|
async savePrebake() {
|
||||||
@@ -94,16 +71,6 @@ export class PrebakeCodeMirror {
|
|||||||
logger('[prebake] prebake saved');
|
logger('[prebake] prebake saved');
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleComment() {
|
|
||||||
try {
|
|
||||||
// Honor selections; toggleLineComment handles both selections and
|
|
||||||
// single line
|
|
||||||
toggleLineComment(this.view);
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Error handling repl-toggle-comment event', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setCode(code) {
|
setCode(code) {
|
||||||
const changes = {
|
const changes = {
|
||||||
from: 0,
|
from: 0,
|
||||||
|
|||||||
@@ -107,24 +107,21 @@ export function useReplContext() {
|
|||||||
//post to iframe parent (like Udels) if it exists...
|
//post to iframe parent (like Udels) if it exists...
|
||||||
window.parent?.postMessage(code);
|
window.parent?.postMessage(code);
|
||||||
|
|
||||||
// Get the full buffer content from the editor instead of just the evaluated block
|
setLatestCode(code);
|
||||||
const fullBufferCode = editorRef.current?.code || code;
|
|
||||||
setLatestCode(fullBufferCode);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
window.location.hash = '#' + code2hash(fullBufferCode);
|
window.location.hash = '#' + code2hash(code);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[useReplContext] Failed to update hash:', e.message);
|
console.warn('[useReplContext] Failed to update hash:', e.message);
|
||||||
}
|
}
|
||||||
setDocumentTitle(fullBufferCode);
|
setDocumentTitle(code);
|
||||||
const viewingPatternData = getViewingPatternData();
|
const viewingPatternData = getViewingPatternData();
|
||||||
setVersionDefaultsFrom(fullBufferCode);
|
setVersionDefaultsFrom(code);
|
||||||
const data = { ...viewingPatternData, code: fullBufferCode };
|
const data = { ...viewingPatternData, code };
|
||||||
let id = data.id;
|
let id = data.id;
|
||||||
const isExamplePattern = viewingPatternData.collection !== userPattern.collection;
|
const isExamplePattern = viewingPatternData.collection !== userPattern.collection;
|
||||||
|
|
||||||
if (isExamplePattern) {
|
if (isExamplePattern) {
|
||||||
const codeHasChanged = fullBufferCode !== viewingPatternData.code;
|
const codeHasChanged = code !== viewingPatternData.code;
|
||||||
if (codeHasChanged) {
|
if (codeHasChanged) {
|
||||||
// fork example
|
// fork example
|
||||||
const newPattern = userPattern.duplicate(data);
|
const newPattern = userPattern.duplicate(data);
|
||||||
@@ -176,8 +173,9 @@ export function useReplContext() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let editorSettings = {};
|
let editorSettings = {};
|
||||||
Object.keys(defaultSettings).forEach((key) => {
|
Object.keys(defaultSettings).forEach((key) => {
|
||||||
// Don't use hasOwnProperty - nanostore uses proxies so values may not be own properties
|
if (Object.prototype.hasOwnProperty.call(_settings, key)) {
|
||||||
editorSettings[key] = _settings[key];
|
editorSettings[key] = _settings[key];
|
||||||
|
}
|
||||||
});
|
});
|
||||||
editorRef.current?.updateSettings(editorSettings);
|
editorRef.current?.updateSettings(editorSettings);
|
||||||
}, [_settings]);
|
}, [_settings]);
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
import { code2hash, errorLogger, evalScope, hash2code, logger } from '@strudel/core';
|
import * as strudelCore from '@strudel/core';
|
||||||
|
import * as strudelWebaudio from '@strudel/webaudio';
|
||||||
import { settingPatterns } from '../settings.mjs';
|
import { settingPatterns } from '../settings.mjs';
|
||||||
import { setVersionDefaults } from '@strudel/webaudio';
|
import { getMetadata } from '../metadata_parser.js';
|
||||||
import { getMetadata } from '../metadata_parser';
|
|
||||||
import { isTauri } from '../tauri.mjs';
|
import { isTauri } from '../tauri.mjs';
|
||||||
import './Repl.css';
|
import './Repl.css';
|
||||||
import { createClient } from '@supabase/supabase-js';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||||
import { $featuredPatterns /* , loadDBPatterns */ } from '@src/user_pattern_utils.mjs';
|
import { $featuredPatterns } from '@src/user_pattern_utils.mjs';
|
||||||
|
|
||||||
|
const { setVersionDefaults } = strudelWebaudio;
|
||||||
|
const { code2hash, errorLogger, evalScope, hash2code, logger } = strudelCore;
|
||||||
|
|
||||||
// Create a single supabase client for interacting with your database
|
// Create a single supabase client for interacting with your database
|
||||||
export const supabase = createClient(
|
export const supabase = createClient(
|
||||||
@@ -68,13 +71,13 @@ export async function getRandomTune() {
|
|||||||
|
|
||||||
export function loadModules() {
|
export function loadModules() {
|
||||||
let modules = [
|
let modules = [
|
||||||
import('@strudel/core'),
|
strudelCore,
|
||||||
import('@strudel/draw'),
|
import('@strudel/draw'),
|
||||||
import('@strudel/edo'),
|
import('@strudel/edo'),
|
||||||
import('@strudel/tonal'),
|
import('@strudel/tonal'),
|
||||||
import('@strudel/mini'),
|
import('@strudel/mini'),
|
||||||
import('@strudel/xen'),
|
import('@strudel/xen'),
|
||||||
import('@strudel/webaudio'),
|
strudelWebaudio,
|
||||||
import('@strudel/codemirror'),
|
import('@strudel/codemirror'),
|
||||||
import('@strudel/hydra'),
|
import('@strudel/hydra'),
|
||||||
import('@strudel/serial'),
|
import('@strudel/serial'),
|
||||||
@@ -94,7 +97,7 @@ export function loadModules() {
|
|||||||
import('@strudel/desktopbridge/oscbridge.mjs'),
|
import('@strudel/desktopbridge/oscbridge.mjs'),
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
modules = modules.concat([import('@strudel/midi'), import('@strudel/osc')]);
|
modules = modules.concat([import('@strudel/midi'), import('@strudel/osc'), import('@strudel/websocket')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return evalScope(settingPatterns, ...modules);
|
return evalScope(settingPatterns, ...modules);
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ export const defaultSettings = {
|
|||||||
isPatternHighlightingEnabled: true,
|
isPatternHighlightingEnabled: true,
|
||||||
isTabIndentationEnabled: false,
|
isTabIndentationEnabled: false,
|
||||||
isMultiCursorEnabled: false,
|
isMultiCursorEnabled: false,
|
||||||
isBlockBasedEvalEnabled: false,
|
|
||||||
theme: 'strudelTheme',
|
theme: 'strudelTheme',
|
||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
@@ -105,7 +104,6 @@ export const $settings = computed(settingsMap, (state) => {
|
|||||||
isSyncEnabled: isUdels() ? true : parseBoolean(state.isSyncEnabled),
|
isSyncEnabled: isUdels() ? true : parseBoolean(state.isSyncEnabled),
|
||||||
isTabIndentationEnabled: parseBoolean(state.isTabIndentationEnabled),
|
isTabIndentationEnabled: parseBoolean(state.isTabIndentationEnabled),
|
||||||
isMultiCursorEnabled: parseBoolean(state.isMultiCursorEnabled),
|
isMultiCursorEnabled: parseBoolean(state.isMultiCursorEnabled),
|
||||||
isBlockBasedEvalEnabled: parseBoolean(state.isBlockBasedEvalEnabled),
|
|
||||||
fontSize: Number(state.fontSize),
|
fontSize: Number(state.fontSize),
|
||||||
panelPosition: state.activeFooter !== '' && !isUdels() ? state.panelPosition : 'bottom', // <-- keep this 'bottom' where it is!
|
panelPosition: state.activeFooter !== '' && !isUdels() ? state.panelPosition : 'bottom', // <-- keep this 'bottom' where it is!
|
||||||
isPanelPinned: parseBoolean(state.isPanelPinned),
|
isPanelPinned: parseBoolean(state.isPanelPinned),
|
||||||
|
|||||||
Reference in New Issue
Block a user