Compare commits

..

299 Commits

Author SHA1 Message Date
Jade (Rose) Rowland f17a4d045f Publish
- @strudel/codemirror@1.2.3
 - @strudel/core@1.2.3
 - @strudel/csound@1.2.4
 - @strudel/draw@1.2.3
 - @strudel/embed@1.1.1
 - @strudel/gamepad@1.2.3
 - @strudel/hydra@1.2.3
 - @strudel/midi@1.2.4
 - @strudel/mini@1.2.3
 - mondolang@1.1.1
 - @strudel/mondo@1.1.1
 - @strudel/motion@1.2.3
 - @strudel/mqtt@1.2.3
 - @strudel/osc@1.2.3
 - @strudel/reference@1.2.1
 - @strudel/repl@1.2.4
 - @strudel/serial@1.2.3
 - @strudel/soundfonts@1.2.4
 - superdough@1.2.4
 - @strudel/tonal@1.2.3
 - @strudel/transpiler@1.2.3
 - @strudel/web@1.2.4
 - @strudel/webaudio@1.2.4
 - @strudel/xen@1.2.3
2025-08-18 11:46:29 -04:00
Alex McLean 8e1e83f3cf Merge pull request 'euclidish' (#1482) from euclidish into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1482
2025-08-17 23:18:45 +02:00
alex 2d64b538e7 Merge branch 'main' into euclidish 2025-08-17 22:16:58 +01:00
alex b717615558 optimise euclidish, creating new morph function in the process 2025-08-17 22:13:26 +01:00
Switch Angel AKA Jade Rose 8c4f10464b Merge pull request 'feat: Create a duck (sidechain) orbit effect' (#1470) from pump into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1470
2025-08-17 06:37:22 +02:00
Jade (Rose) Rowland 018649c4f3 fix test 2025-08-16 23:42:14 -04:00
Jade (Rose) Rowland 5ff59a878d fix lookahead 2025-08-16 23:38:03 -04:00
Jade (Rose) Rowland a20468b85f minor changes 2025-08-16 23:19:34 -04:00
Jade (Rose) Rowland 9648e35de2 Merge branch 'main' into pump 2025-08-16 23:06:36 -04:00
Switch Angel AKA Jade Rose cd344cefe0 Merge pull request 'Bug Fix: Restore log functionality after onTrigger arg removal' (#1491) from glossing/strudel:glossing/fix-log into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1491
Reviewed-by: Switch Angel AKA Jade Rose <daslyfe@noreply.codeberg.org>
2025-08-17 04:40:14 +02:00
Switch Angel AKA Jade Rose 1f6a313f02 Merge pull request 'Bug Fix: Handle zero appearing first in FM's ADSR' (#1496) from glossing/strudel:glossing/fix-fm-with-adsr-zeros into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1496
Reviewed-by: Switch Angel AKA Jade Rose <daslyfe@noreply.codeberg.org>
2025-08-17 04:33:38 +02:00
Switch Angel AKA Jade Rose 5cbeb227d8 Merge pull request 'Bug Fix: FM (and vibrato) for Supersaws' (#1495) from glossing/strudel:glossing/fix-fm-for-supersaw into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1495
Reviewed-by: Switch Angel AKA Jade Rose <daslyfe@noreply.codeberg.org>
2025-08-17 04:27:18 +02:00
Aria 2ab2cc5fc8 Add example tests 2025-08-15 13:27:08 -05:00
Aria 3dd667e825 Fix for a zero appearing (first) in FM's ADSR 2025-08-10 17:11:59 -05:00
Alex McLean 482ebb695a Merge branch 'main' into euclidish 2025-08-10 20:49:27 +02:00
Aria 218952b8b6 Use the per-sample frequency and properly wrap polyBlep 2025-08-09 16:25:11 -05:00
Aria 2e8a8b50df Seemingly working version of supersaw FM and light cleanup 2025-08-08 22:27:05 -05:00
Aria f22f89347e Final docstring cleanup & adding hap tag to logValues for consistency 2025-08-05 22:40:11 -05:00
Aria de15d79edf Add doscstrings and move stringifyValues into its own function for reuse 2025-08-05 22:29:59 -05:00
Aria 23e5358ae4 Formatting 2025-08-05 20:46:00 -05:00
Aria 3b6777e259 Fix signature of functions in log and logValues and add tests 2025-08-05 19:05:17 -05:00
Alex McLean ed5bf3b3fc Merge pull request 'Fix incorrect stack Mini Notation' (#1484) from samyk/strudel:main into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1484
2025-08-04 07:51:29 +02:00
daslyfe b089328da3 Merge pull request 'fix: regression caused by incorrectly exported alias for transpose and scaleTranspose' (#1489) from fixtest into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1489
2025-08-03 18:57:45 +02:00
daslyfe 784c711870 Merge branch 'main' into pump 2025-08-03 18:57:19 +02:00
Jade (Rose) Rowland 34b10b6c84 codeformat 2025-08-03 12:56:16 -04:00
Jade (Rose) Rowland 450f9685f3 fixed export 2025-08-03 12:54:19 -04:00
daslyfe 03090e399c Merge pull request 'Add strans and scaleTrans as synonyms of scaleTranspose' (#1488) from TodePond/strudel:lu/strans into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1488
2025-08-03 18:34:12 +02:00
Lu Wilson ed58d26da6 Merge branch 'main' into lu/strans 2025-08-03 16:14:33 +02:00
daslyfe e3605590e5 Merge pull request 'Add trans alias for transpose' (#1487) from TodePond/strudel:lu/trans into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1487
2025-08-02 18:18:25 +02:00
Lu[ke] Wilson d55ef8e843 add strans too 2025-08-02 10:26:36 +01:00
Lu[ke] Wilson efc2333360 add synonyms for scaleTranspose 2025-08-02 10:25:28 +01:00
Lu Wilson 92626e7c20 Merge branch 'main' into lu/trans 2025-08-02 11:18:37 +02:00
Lu[ke] Wilson ad113b3888 document ability to specify an array of names 2025-08-02 10:17:48 +01:00
Lu[ke] Wilson 39c45bc2b2 pass an array of names instead 2025-08-02 10:17:33 +01:00
daslyfe 899af88bd9 Merge branch 'main' into pump 2025-08-02 05:32:13 +02:00
Jade (Rose) Rowland c2b8cc4b82 webtimeout 2025-08-01 23:29:50 -04:00
daslyfe 40ed7b5382 Merge pull request 'feat: Create Accurate 909 bass drum synthesizer' (#1478) from 909bd into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1478
2025-08-02 03:27:24 +02:00
daslyfe 5d829419ba Merge branch 'main' into 909bd 2025-08-02 03:24:29 +02:00
daslyfe e26da854c0 Merge pull request 'feat: Add fmwave control and ability to fm with noise' (#1472) from noisefm into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1472
2025-08-02 03:23:48 +02:00
daslyfe a28b7a2d5a Merge branch 'main' into noisefm 2025-08-02 02:49:15 +02:00
daslyfe 83c776d70f Merge branch 'main' into 909bd 2025-08-02 02:49:00 +02:00
Lu[ke] Wilson 051efdc13b flyby improvement: add dec synonym to docs 2025-08-01 09:39:33 +01:00
Lu[ke] Wilson ef3cd56b0d add synonym to docs 2025-08-01 09:39:21 +01:00
Lu[ke] Wilson 9017085fa3 add trans alias for transpose 2025-08-01 09:36:36 +01:00
daslyfe cdbbe079db Merge pull request 'hotfix: uzu kit JSON should be in the repo to avoid offline loading errors' (#1485) from samplemaphotfix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1485
2025-07-30 00:22:40 +02:00
Jade (Rose) Rowland d6045c943b working 2025-07-29 18:20:13 -04:00
samyk 6ee9dea2ff Fix incorrect stack Mini Notation 2025-07-28 20:26:34 +02:00
alex 03cbe4b6d4 delint 2025-07-28 15:48:09 +02:00
alex 784ee576da fixes 2025-07-28 15:33:18 +02:00
alex ee3e1217b4 add euclidish 2025-07-28 15:24:19 +02:00
Jade (Rose) Rowland 30c80119e9 works 2025-07-28 01:20:42 -04:00
Jade (Rose) Rowland 973ae4c7da change 909bd to sbd 2025-07-27 15:02:00 -04:00
Jade (Rose) Rowland 4d13b981f1 variable srate 2025-07-27 01:28:50 -04:00
Jade (Rose) Rowland 7691403fd0 prevent clicks 2025-07-27 01:22:59 -04:00
Jade (Rose) Rowland 3b6e3624be working 2025-07-27 01:07:45 -04:00
Jade (Rose) Rowland 51f0bab1f8 duckarray 2025-07-26 12:54:59 -04:00
Jade (Rose) Rowland dae1560c40 description 2025-07-25 00:00:23 -04:00
Jade (Rose) Rowland 82f0dbb750 add another example 2025-07-24 23:59:38 -04:00
Jade (Rose) Rowland fb7d76a2ab working 2025-07-24 23:50:27 -04:00
Jade (Rose) Rowland 26225e4ea7 Merge branch 'main' into pump 2025-07-23 23:40:48 -04:00
daslyfe ab12c6ae0a Merge pull request 'feat: make uzu-drumkit the default drumkit' (#1422) from jade/uzudrumkit into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1422
2025-07-24 05:28:23 +02:00
Jade (Rose) Rowland 4a894b0be2 frmt 2025-07-23 23:25:14 -04:00
Jade (Rose) Rowland 4ad305550e Merge branch 'jade/uzudrumkit' of ssh://codeberg.org/uzu/strudel into jade/uzudrumkit 2025-07-23 23:16:39 -04:00
Jade (Rose) Rowland cf5c502a05 rm unessecary json 2025-07-23 23:16:14 -04:00
Jade (Rose) Rowland 2415210be6 fix lint 2025-07-23 18:41:20 -04:00
Jade (Rose) Rowland fe18aa770d test 2025-07-23 18:34:34 -04:00
daslyfe e136e95375 Merge branch 'main' into jade/uzudrumkit 2025-07-23 03:06:08 +02:00
daslyfe 004c0baa59 Merge pull request 'FIX: PWM modulation' (#1467) from pwfix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1467
2025-07-21 07:16:17 +02:00
daslyfe 5f44ae9c4b Merge branch 'main' into pwfix 2025-07-21 07:13:55 +02:00
Jade (Rose) Rowland 66828e17d3 working 2025-07-21 01:11:04 -04:00
Jade (Rose) Rowland b2f90ecb3b fix def skew 2025-07-20 23:56:30 -04:00
Jade (Rose) Rowland ccf2a6de52 fixing.. 2025-07-20 23:38:16 -04:00
Jade (Rose) Rowland 9416f317d4 fixing... 2025-07-20 23:29:01 -04:00
Jade (Rose) Rowland 75b6f59212 fix 2025-07-20 23:26:17 -04:00
daslyfe 84238c8999 Merge pull request 'Tremolo modulation' (#1095) from daslyfe/gainmod into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1095
2025-07-19 17:16:21 +02:00
daslyfe 2d855cf5e8 Merge branch 'main' into daslyfe/gainmod 2025-07-19 04:06:31 +02:00
Jade (Rose) Rowland dd04d49c75 fix test 2025-07-18 22:04:18 -04:00
Jade (Rose) Rowland 34874862ab change params 2025-07-18 22:03:33 -04:00
froos 0361bc629f Merge pull request 'fix: can now use def in mondough' (#1461) from mondo-def-fix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1461
2025-07-15 09:39:32 +02:00
Felix Roos 1fdd87a4f3 doc: def 2025-07-15 09:35:24 +02:00
Felix Roos 16e9aca222 fix: can now use def in mondough 2025-07-15 09:33:14 +02:00
froos 4a3d5ca44f Merge pull request 'fixed keybinding presedence issue' (#1456) from Dsm0/strudel:keyboard_binding_presedence_fix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1456
2025-07-11 11:10:23 +02:00
froos 6c0e8a0833 Merge pull request 'added multicursor support on ctrl/cmd + click' (#1457) from Dsm0/strudel:multicursor-on-click into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1457
2025-07-11 11:09:04 +02:00
Jade (Rose) Rowland 7336ff0ded Merge branch 'daslyfe/gainmod' of ssh://codeberg.org/uzu/strudel into daslyfe/gainmod 2025-07-10 23:19:19 -04:00
Jade (Rose) Rowland 735f57e276 working 2025-07-10 23:18:57 -04:00
Dsm0 eb4f1f69f6 pnpm codeformat 2025-07-10 17:28:56 -07:00
Dsm0 e7e321fe03 added multicursor support on ctrl/cmd + click 2025-07-10 15:03:22 -07:00
Dsm0 bf3de368f0 added codemirror as an option + removed fallback on defaults 2025-07-10 12:11:10 -07:00
Dsm0 d645cc6fe5 fixed keybinding presedence issue 2025-07-09 13:28:22 -07:00
froos 6fe11be218 Merge pull request 'added tab-indent setting' (#1454) from Dsm0/strudel:tab-indentation into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1454
2025-07-09 09:39:45 +02:00
Felix Roos cf7fc23981 add new am examples to doc 2025-07-09 09:33:28 +02:00
Felix Roos bfdfab0a00 fix: @synonym -> @synonyms 2025-07-09 09:33:11 +02:00
Jade (Rose) Rowland edb347e85a format 2025-07-08 22:24:54 -04:00
Jade (Rose) Rowland 63fcce79e0 default cycle 2025-07-08 21:24:27 -04:00
Dsm0 8defdc424c added tab-indent setting 2025-07-08 17:57:24 -07:00
Felix Roos 16b2fc0632 Merge remote-tracking branch 'origin/main' into daslyfe/gainmod 2025-07-08 15:49:39 +02:00
froos d0a544d7a7 Merge pull request 'ontrigger-refactoring' (#1442) from ontrigger-refactoring into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1442
2025-07-08 15:48:40 +02:00
Jade (Rose) Rowland 9b3c6b9f94 c 2025-07-08 00:46:39 -04:00
Jade (Rose) Rowland 6327e17feb remove unessecary cyclist changes 2025-07-08 00:44:57 -04:00
Jade (Rose) Rowland 15fe2734e9 Merge branch 'daslyfe/gainmod' of ssh://codeberg.org/uzu/strudel into daslyfe/gainmod 2025-07-08 00:30:40 -04:00
Jade (Rose) Rowland 1dd1ce254f rm deadcode 2025-07-08 00:30:00 -04:00
daslyfe 3ea91adfd6 Merge branch 'main' into daslyfe/gainmod 2025-07-08 06:29:27 +02:00
Jade (Rose) Rowland ce5f425142 fully implemented 2025-07-08 00:26:15 -04:00
Felix Roos 671a22fc22 chore: add link to contributors 2025-07-07 23:28:41 +02:00
froos 976955dae3 Merge pull request 'fix: remove first gm_synth_bass_1, as it doesn't work in safari' (#1452) from gm_synth_bass_1 into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1452
2025-07-07 23:14:24 +02:00
Felix Roos a6ad58a375 fix: remove first gm_synth_bass_1, as it doesn't work in safari 2025-07-07 23:12:15 +02:00
Felix Roos 681eed3d0e revert add logo 2025-07-07 22:23:40 +02:00
Felix Roos 81a9811803 add logo 2025-07-07 22:23:16 +02:00
Felix Roos 72b582c605 fix: remove github contributor avatars 2025-07-07 22:20:04 +02:00
froos 2f0891d4e5 Merge pull request 'fix: minor doc changes' (#1435) from Aurel300/strudel:fix/minor-docs into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1435
2025-07-07 00:06:15 +02:00
Felix Roos a7a283a99e doc: add version tagging guide to contributing.md 2025-07-06 17:00:33 +02:00
Jade (Rose) Rowland d9e44dcda6 sync without cyclist changes 2025-07-06 00:59:39 -04:00
Alex McLean acd5661106 Merge pull request 'Fix randrun and deps including shuffle. Fixes #1441' (#1447) from fix-randrun into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1447
2025-07-05 12:53:44 +02:00
froos b0b2b6a120 Merge pull request 'add setDefault + resetDefaults to superdough' (#1433) from set-default-default into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1433
2025-07-05 12:15:51 +02:00
Felix Roos 664d76cf1b resetDefaults when editor is reset 2025-07-05 11:32:16 +02:00
alex a901e2e387 snapshot 2025-07-05 10:28:20 +01:00
Felix Roos 82b14b5292 fix: lint 2025-07-05 11:13:40 +02:00
alex 05bcd5e32f Fix randrun and deps including shuffle. Fixes #1441 2025-07-05 09:01:48 +01:00
Jade (Rose) Rowland 077556e7cb Merge remote-tracking branch 'origin/ontrigger-refactoring' into daslyfe/gainmod 2025-07-05 00:45:58 -04:00
Jade (Rose) Rowland 4cc2de9b7e wip 2025-07-05 00:39:23 -04:00
froos b0c0a393a1 Merge pull request 'disable fm for supersaw' (#1443) from supersaw-no-fm into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1443
2025-07-04 22:36:18 +02:00
Felix Roos 168269a839 disable fm for supersaw 2025-07-04 22:29:18 +02:00
Felix Roos 34771f03d4 some clarification comments 2025-07-04 22:17:23 +02:00
Aurel Bílý 504fe9ed40 document setcps in cycles reference 2025-07-01 13:45:36 +02:00
froos caf6686d01 Merge pull request 'corrected minor spelling mistake (#1425)' (#1434) from tj-mueller/strudel_1425:spelling_mistake_1425 into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1434
2025-06-30 13:28:09 +02:00
tj-mueller c063fb6b1c correct rd to cr 2025-06-30 11:51:39 +02:00
Felix Roos e3680b96de refactor: remove first param of all onTrigger calls 2025-06-30 10:18:54 +02:00
Jade (Rose) Rowland 688e275e0c merge 2025-06-30 00:50:02 -04:00
Felix Roos 2e33569786 add setDefault + resetDefaults to superdough 2025-06-30 05:48:08 +02:00
froos 46fe6d3c4d Merge pull request 'Add browser cache explanation in samples.mdx' (#1369) from wyan/patch-1 into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1369
2025-06-30 05:26:10 +02:00
froos 9220b95677 Merge branch 'main' into wyan/patch-1 2025-06-30 05:24:26 +02:00
froos 5b27b19972 Merge pull request 'add-release-notes' (#1432) from add-release-notes into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1432
2025-06-30 05:18:41 +02:00
Felix Roos 5a72ea94b1 fix: format 2025-06-30 05:15:30 +02:00
Felix Roos eac6f27ca4 add 1.2.0 release notes 2025-06-29 21:29:11 +02:00
Felix Roos f2330a2307 add 1.1.0 release notes 2025-06-29 20:18:15 +02:00
Jade Rose db413881db Merge pull request 'feat: delaytime in cycles' (#1341) from daslyfe/jade/delaycycle into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1341
2025-06-28 20:30:48 +02:00
Jade (Rose) Rowland 77bab433e0 cf 2025-06-28 14:06:16 -04:00
daslyfe f8cc1c2022 Merge branch 'main' into daslyfe/jade/delaycycle 2025-06-28 20:01:57 +02:00
froos e0bf9ea4d6 Merge pull request 'Case insensitive search in the reference tab' (#1420) from kdiab/strudel:main into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1420
2025-06-28 13:44:47 +02:00
Alex McLean 374661eb23 Merge pull request 'add unjoin, into and chunkinto' (#1418) from add-unjoin into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1418
2025-06-28 00:04:12 +02:00
alex df06248c54 snapshot 2025-06-27 22:59:01 +01:00
alex 27073d6c17 format 2025-06-27 22:56:19 +01:00
alex f44caf9096 tests and tweaks, and add chunkBackInto 2025-06-27 22:51:47 +01:00
alex ff5b11f5ed test + bugfix for chunkinto 2025-06-27 22:44:15 +01:00
Alex McLean 719c70a598 Merge branch 'main' into add-unjoin 2025-06-27 22:40:40 +02:00
Jade (Rose) Rowland 7a53f6c021 add test 2025-06-27 15:56:37 -04:00
Jade (Rose) Rowland 09d05abd70 delaysync 2025-06-27 15:54:39 -04:00
Jade (Rose) Rowland 3acc364a03 Merge branch 'main' into daslyfe/jade/delaycycle 2025-06-27 15:53:48 -04:00
Jade (Rose) Rowland 2dd528134a fix json 2025-06-27 02:52:04 -04:00
Jade (Rose) Rowland fef50e654c working 2025-06-27 02:38:43 -04:00
Felix Roos b1aba294ad hotfix: fix upstream test 2025-06-26 15:39:35 +02:00
froos 63ac80eb79 Merge pull request 'mondo notation' (#1311) from uzu into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1311
2025-06-26 15:29:45 +02:00
Felix Roos 82e3f9b837 fix: js example 2025-06-26 14:59:24 +02:00
Khalid e19fd24447 Case insensitive search in the reference tab 2025-06-25 08:44:12 -04:00
alex fe9a91d1e4 add unjoin, into and chunkinto 2025-06-24 23:22:42 +01:00
froos 860bb58d61 Merge pull request 'allow calling all multiple times' (#1417) from multiple-all-calls into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1417
2025-06-24 06:14:15 +02:00
Felix Roos d58b3e490b fix: reset all transforms before eval 2025-06-24 06:12:21 +02:00
Felix Roos 0003ce174e allow calling all multiple times 2025-06-24 06:06:37 +02:00
froos 8e0f23e081 Merge pull request 'tonal: allow scales without tonic (default to C)' (#1092) from kasparsj/tonal-fix into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1092
2025-06-24 05:53:21 +02:00
Felix Roos 71e60ed8de add back comment 2025-06-24 05:45:36 +02:00
Felix Roos e2a29914c7 don't interpret note as n 2025-06-24 05:43:06 +02:00
Felix Roos a9a3d491a2 Merge branch 'main' into kasparsj/tonal-fix 2025-06-24 05:39:59 +02:00
yaxu a750764f88 Update CONTRIBUTING.md 2025-06-23 11:13:00 +02:00
froos 5b397009ab Merge pull request 'website intro: fix whitespace and code hosting name' (#1400) from trofi/strudel:website-intro-minor into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1400
2025-06-20 20:00:11 +02:00
Sergei Trofimovich e68df9e789 website intro: fix whitespace and code hosting name 2025-06-20 18:33:58 +01:00
yaxu 4d3bbd5057 Update README.md 2025-06-19 17:44:45 +02:00
Felix Roos 15f3321b04 fix: extend in some situations, like [[bd]@3 bd] 2025-06-19 11:33:22 +02:00
froos 67bfedb317 Merge branch 'main' into uzu 2025-06-19 10:21:04 +02:00
Alex McLean c0184dd827 Merge pull request 'fix stepcat #1396' (#1398) from fix-stepcat into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1398
2025-06-19 10:15:06 +02:00
Alex McLean 09fdc45ff2 Merge branch 'main' into fix-stepcat 2025-06-19 10:08:08 +02:00
alex c01b4c651c don't trash lists passed to timecat 2025-06-19 09:06:53 +01:00
froos 634eed1d82 Merge pull request 'deprecate cpm + refactor docs to use setcpm' (#1397) from reference-improvements into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/1397
2025-06-19 09:52:36 +02:00
alex a1d181d609 format 2025-06-19 08:27:41 +01:00
alex 440f1cb081 reify arguments of stepcat 2025-06-19 08:27:23 +01:00
alex 95193b0bfd a test for #1396 2025-06-19 08:18:20 +01:00
Felix Roos 1cc15c7e8d fix: fall back to silence when empty
removes annoying error
2025-06-18 22:25:05 +02:00
Felix Roos 10ac7c353c use + and - as late / early
+ add some extra error handling
2025-06-18 22:07:16 +02:00
Felix Roos 9412bf60bf add e as euclid that accepts a list 2025-06-18 22:06:18 +02:00
Felix Roos c751bb7e5f allow _ as silence 2025-06-18 21:36:34 +02:00
Felix Roos 28cd7c1681 Merge branch 'main' into uzu 2025-06-18 21:26:51 +02:00
Alice Wyan 1b7fbecf50 Fix style issue 2025-06-10 13:20:21 +02:00
Alice Wyan 117cf7e18a Update samples.mdx 2025-06-09 19:45:21 +02:00
Alice Wyan ae15bb7274 Add browser cache explanation in samples.mdx
Several users (including me) have been bitten by this, so it's perhaps worth mentioning in the docs that the strudel.json file gets cached by the browser and doesn't reload properly unless forced.
2025-06-09 15:03:41 +02:00
alex 1b3b07842e format again.. 2025-05-03 21:57:01 +01:00
alex 98efd72ab4 delint 2025-05-03 20:59:05 +01:00
alex 1eb5f6a995 format 2025-05-03 20:38:43 +01:00
alex 9b10dc8535 change pipe symbol from '.' to '#' 2025-05-03 20:37:44 +01:00
Felix Roos 2951a60fac fix: rests at the end 2025-05-03 11:44:02 +02:00
Jade (Rose) Rowland 94257e81ee lint 2025-05-02 23:44:55 -04:00
Jade (Rose) Rowland 006ce9d1da delaytime 2025-05-02 23:33:58 -04:00
Felix Roos 607a6121bc rename mondo package to mondolang 2025-05-02 16:20:23 +02:00
Felix Roos 4208c79c09 fix: ! and @ operators 2025-05-02 15:13:04 +02:00
Felix Roos 7565354274 superdough: fallback to triangle when non-string is given 2025-05-02 08:54:34 +02:00
Felix Roos ffe831d24b mondo: strings now get type "string" to be discernable from plain variables 2025-05-02 08:53:55 +02:00
Felix Roos 60dd8bd763 tweak again 2025-05-02 08:35:16 +02:00
Felix Roos 29e5833c8c tweak 2025-05-02 08:32:46 +02:00
Felix Roos e3a6444f41 mondo: support line comments 2025-05-02 08:30:09 +02:00
Felix Roos 30fd4c5dec Merge branch 'main' into uzu 2025-05-02 08:16:52 +02:00
Felix Roos 2da03ab46f Merge remote-tracking branch 'origin/main' into uzu 2025-05-01 11:15:24 +02:00
Felix Roos 243adda3dd mondo: more sicp tests 2025-05-01 10:56:33 +02:00
Felix Roos 7fc21d55d7 mondo: rational number test 2025-04-04 10:04:22 +02:00
Felix Roos d5ef686fe0 mondo: sicp 100 2025-04-04 00:45:00 +02:00
Felix Roos d4733a30ab mondo: add half interval method example 2025-04-03 17:30:03 +02:00
Felix Roos 989bd0990e mondo: let expressions 2025-04-03 17:01:36 +02:00
Felix Roos 60d09adb44 mondo: more tests 2025-04-02 22:33:18 +02:00
Felix Roos b2588e8c93 fix: lint 2025-04-02 22:11:06 +02:00
Felix Roos 39d2784441 mondo: more sicp tests
+ support special form for function def (might remove later)
+ support multiple expressions in fn body
+ support lexical scoping
2025-04-02 22:09:17 +02:00
Felix Roos aa70246afc mondo: more sicp 2025-04-01 23:24:47 +02:00
Felix Roos f6ffdd6ae6 mondo: move +- to ops
+ add "raw" to parsed pairs
+ implement match + if
+ add more sicp examples
2025-04-01 22:31:42 +02:00
Felix Roos 077aac1888 mondo: add some examples from sicp book 2025-04-01 21:50:03 +02:00
Felix Roos 94a3a60e49 mondo: remember pair locations
+ allow passing a scope to MondoRunner.run
+ make def a side effect
+ proper lambda with multiple args + closure
2025-04-01 21:49:28 +02:00
Felix Roos f2372e7a41 mondo: refactor evaluate function into bits 2025-03-30 17:55:37 +02:00
Felix Roos a0fb8fb37f mondo: def node 2025-03-30 11:43:01 +02:00
Felix Roos b4027fd92a fix: mondo dont mutate (breaks lambdas) 2025-03-30 11:42:50 +02:00
Felix Roos c9cafa37fd mondo: improve mondo package api + update readme 2025-03-29 21:33:51 +01:00
Felix Roos 2e017e46f9 trim readme 2025-03-29 20:17:09 +01:00
Felix Roos c9f58220a3 remove minor change 2025-03-29 19:55:29 +01:00
Felix Roos e9de45993e signal: remove signal synonyms for now 2025-03-29 19:54:04 +01:00
Felix Roos 6b2b8b5124 fix: test 2025-03-26 09:30:49 +01:00
Felix Roos 64a6dacc1e mondo: patternable function names 2025-03-26 09:27:02 +01:00
Felix Roos 1738e4d538 fix: lint 2025-03-26 03:55:54 +01:00
Felix Roos abc7a1e48d mondo: this is the way 2025-03-26 03:55:00 +01:00
Felix Roos 7716fdb98e mondo: refactor
- rename MondoRunner.call => .evaluate
- can now evaluate leafs
- remove .( because it's confusing and half baked
- support (.) as id function
2025-03-26 03:22:23 +01:00
Felix Roos 2938bfd88f mondo: add highly impractical .(. notation for local infix application 2025-03-26 02:46:26 +01:00
Felix Roos 222e479e30 mondo: more docs 2025-03-23 23:18:57 +01:00
Felix Roos 92b5b6538f mondo: improve doc 2025-03-23 23:12:52 +01:00
Felix Roos 3a19e23473 mondo: doc 2025-03-23 22:49:56 +01:00
Felix Roos dd5743ab8c mondo: bring back $ for stacking 2025-03-23 22:49:23 +01:00
Felix Roos 51e3aa257c mondolang function for mondo repl + fix rests 2025-03-23 22:49:03 +01:00
Felix Roos 5eabcf0618 mondo mode for StrudelMirror / repl / mini repl 2025-03-23 22:47:33 +01:00
Felix Roos 6d21456423 mondo: allow # character in plain values (for sharps) 2025-03-23 11:18:18 +01:00
Felix Roos bca16cdf99 mondo: rename resolve_ -> desugar_ 2025-03-22 23:51:23 +01:00
Felix Roos 492271d786 mondo: support $ tidal style 2025-03-22 23:28:57 +01:00
Felix Roos f71db4aeed mondo: flip pipe order: now pining to the end of the function... 2025-03-21 23:50:14 +01:00
Felix Roos 5d4ef46ac7 mondo cleanup 2025-03-21 22:43:39 +01:00
Felix Roos bd93e44154 mondo: fix combination of | and , 2025-03-21 22:34:53 +01:00
Felix Roos 6fd89ddee7 mondo: add | and ? 2025-03-21 11:10:43 +01:00
Felix Roos cf1f4ec35c fix: patterns without structure would error on draw 2025-03-21 11:10:25 +01:00
Felix Roos 12bb82d295 add chooseIn + chooseOut 2025-03-21 11:10:06 +01:00
Felix Roos c33cfc78c5 waveform aliases: tri, sqr, saw, sin 2025-03-20 21:19:47 +01:00
Felix Roos ac6472a43a mondo: mondo as minilang (inactive) 2025-03-20 21:19:21 +01:00
Felix Roos 989fdfa20b transpiler: add mechanism to register custom mini language 2025-03-20 21:18:32 +01:00
Felix Roos 05ae31838e add sin sqr cos aliases 2025-03-20 18:01:41 +01:00
Felix Roos c691916cbf mondo: generic bracket names + simplify call handler + refactor mondough 2025-03-20 17:55:40 +01:00
Felix Roos e16295623d mondo: use stepcat for curly braces 2025-03-20 14:09:32 +01:00
Felix Roos 9626f3cc9a mondo add % for pace 2025-03-20 13:24:31 +01:00
Felix Roos 432e8dcccc mondo: support ! and @, also express seq and cat with stepcat 2025-03-20 13:15:48 +01:00
Felix Roos d2e93a99f1 fix: lint 2025-03-20 10:24:22 +01:00
Felix Roos 3505732afa mondo: add .. operator 2025-03-20 09:34:47 +01:00
Felix Roos 55a5f1d62a transpiler cleanup 2025-03-20 09:10:54 +01:00
Felix Roos 3657e2fd65 mondo: change default markcss 2025-03-20 09:10:45 +01:00
Felix Roos 65a7b3030e fix: markcss can now override styles (like color) 2025-03-20 09:10:12 +01:00
Felix Roos 208706fb52 simplify mondo: ":" is just another operator 2025-03-20 09:09:29 +01:00
Felix Roos e04f250adb mondo: proper lambda functions with local scope 2025-03-19 18:16:37 +01:00
Felix Roos 642ddcdb59 support : in mondo 2025-03-19 17:03:17 +01:00
Felix Roos 88ca54461e rename @strudel/mondough to @strudel/mondo 2025-03-19 00:15:53 +01:00
Felix Roos 129fd7d6b0 add notes 2025-03-19 00:13:06 +01:00
Felix Roos 7db52b3dc2 mondo improvements:
- add second string type
- add $ as alias for stack
- simplify leaf handling
2025-03-18 22:33:14 +01:00
Felix Roos 40f6489111 reify variables 2025-03-16 23:30:41 +01:00
Felix Roos 118b619b74 mondo: support - ~ in plain type + simplify errors 2025-03-16 23:10:52 +01:00
Felix Roos 2dd445c102 mondo: support variables 2025-03-16 23:10:23 +01:00
Felix Roos 3c3832dbce superdough: native support for rest symbols - ~ in s 2025-03-16 23:08:31 +01:00
Felix Roos 9b8761bc45 fix: top-level functions arp/arpWith 2025-03-16 22:31:40 +01:00
Felix Roos 77ade0758e mondo: slightly improve error handling 2025-03-16 22:07:03 +01:00
Felix Roos 902012759a fix:support negative numbers 2025-03-16 21:24:22 +01:00
Felix Roos ea61627963 fix: lint error 2025-03-16 21:05:04 +01:00
Felix Roos 95526ac99c fix: formatting 2025-03-16 21:04:28 +01:00
Felix Roos b0da353115 mondo highlighting 2025-03-16 21:04:05 +01:00
Felix Roos fae59a6bcd feat: add mondough package to run strudel via mondo 2025-03-16 10:49:18 +01:00
Felix Roos 11196fb1e6 breaking: refactor controls
- multiple args wont be interpreted as sequence anymore
- you can now pass value, pat to set value to pat
2025-03-16 10:48:38 +01:00
Felix Roos e782dc09dd export strudelScope for mondo to use 2025-03-16 10:47:32 +01:00
Felix Roos e3df504423 rename uzu to mondo 2025-03-16 02:01:16 +01:00
Felix Roos b71b1354c3 uzu: stacks now work within () + write more tests 2025-03-16 00:51:59 +01:00
Felix Roos dbe3915368 fix: lint errors 2025-03-15 10:35:22 +01:00
Felix Roos 62705da3de begin uzu package 2025-03-15 10:29:23 +01:00
Kaspars 81ca199a96 Merge branch 'upstream-main' into tonal-fix 2024-06-02 12:39:14 +03:00
Jade (Rose) Rowland bee8c81254 simplify targettime 2024-05-13 23:14:30 -04:00
Jade (Rose) Rowland 8ad48e1633 remove unesseccary time call 2024-05-13 23:02:48 -04:00
Jade (Rose) Rowland 4a181d5b33 updated non synced clock to work more like synced clock 2024-05-13 23:02:36 -04:00
Jade (Rose) Rowland d5ab6b7211 fix tests 2024-05-13 22:38:20 -04:00
Jade (Rose) Rowland 4ba9d47bff fix test 2024-05-13 21:10:43 -04:00
Jade (Rose) Rowland c6c5a3035c fixed non synced clock 2024-05-13 21:06:24 -04:00
Jade (Rose) Rowland e024ae2142 almost figured it out 2024-05-13 20:42:59 -04:00
Jade (Rose) Rowland 19df19375d kinda fixed it, need to find cause of incorrect cps calculation 2024-05-13 10:33:18 -04:00
Jade (Rose) Rowland cba96049a3 fixed duplicate variable 2024-05-10 00:03:52 -04:00
Jade (Rose) Rowland 1509ff1793 Merge branch 'tidalcycles:main' into gainmod 2024-05-09 23:55:13 -04:00
Jade (Rose) Rowland 6a33032da7 formatting 2024-05-09 23:26:04 -04:00
Jade (Rose) Rowland 6c05a4eb7b fixed tri shape 2024-05-09 00:21:21 -04:00
Kaspars 8d8b8ab99e codeformat 2024-05-08 10:42:06 +02:00
Kaspars a4f10d5339 bug fix 2024-05-08 10:38:06 +02:00
Jade (Rose) Rowland 16472b59dd fix cyclist clock cycle 2024-05-08 00:05:05 -04:00
Kaspars 33a73c37bc fix tests 2024-05-08 00:46:27 +02:00
Kaspars 4e6d39666a codeformat 2024-05-08 00:00:58 +02:00
Kaspars a5b6022506 - fix scale() to allow both n() and note() at the same time
- fix scale() to allow scale names without tonic and then default it to C
2024-05-07 23:56:39 +02:00
Jade (Rose) Rowland 7df663e87d memory leaking 2024-05-05 23:54:30 -04:00
Jade (Rose) Rowland 3159f66560 working 2024-05-05 22:52:18 -04:00
Jade (Rose) Rowland 0d900c0134 sine test 2024-05-05 12:02:51 -04:00
Jade (Rose) Rowland 66a27a609c implementing 2024-05-03 14:58:20 -04:00
Jade (Rose) Rowland 496d60dc1c testing 2024-05-03 14:56:16 -04:00
99 changed files with 4758 additions and 324 deletions
+77 -1
View File
@@ -17,7 +17,7 @@ git remote set-url origin git@codeberg.org:uzu/strudel.git
To get in touch with the contributors, either
- [join the Tidal Discord Channel](https://discord.gg/remJ6gQA) and go to the #strudel channel
- [join the Tidal Discord Channel](https://discord.com/invite/HGEdXmRkzT) and go to the #strudel channel
- Find related discussions on the [tidal club forum](https://club.tidalcycles.org/)
## Ask a Question
@@ -150,6 +150,7 @@ Important: Always publish with `pnpm`, as `npm` does not support overriding main
## useful commands
```sh
#regenerate the test snapshots (ex: when updating or creating new pattern functions)
pnpm snapshot
@@ -160,6 +161,81 @@ pnpm run osc
#build the standalone version
pnpm tauri build
```
## version tag patching
here's a little guide on how to patch patterns in the database to prevent breaking old patterns due to breaking changes in newer versions.
the general tactic is to use `// @version x.y` to tag a pattern with a specific strudel version. when a pattern is evaluated, this metadata will de-activate any breaking changes that came after the specified version.
for example, in version 1.1, the default value for `fanchor` was changed from `0.5` to `0`.
if play a pattern that was made before that change, sounds that use filter evenlopes can sound very different, so by adding `// @version 1.0` will make it sound like it used to.
before releasing a new version with breaking changes, we can edit all patterns in the database, inserting the version tag they were created under:
as an example, to release version 1.2, do the following:
1. get date range
```sh
# get date of last version:
git log -1 --format=%aI @strudel/core@1.1.0
# 2024-05-31T23:07:26+02:00
# get date of current version:
git log -1 --format=%aI @strudel/core@1.2.0
# 2025-05-01T12:39:24+02:00
# might also use todays timestamp if version is not yet released
```
now we know, all patterns between these 2 dates have to receive a version tag (unless they already have one).
2. get patterns in question
```sql
SELECT *
FROM code_v1
WHERE code NOT LIKE '%@version%'
AND created_at > '2024-05-31T23:07:26+02:00'
AND created_at < '2025-05-01T12:39:24+02:00'
ORDER BY created_at ASC;
```
this gives us all unversioned patterns that were saved between 1.1.0 and 1.2.0. in this case, it's 9373 patterns!
3. insert version tags
we are now ready to insert the version tag to these patterns.
before updating thousands of patterns, it's probably a good idea to test if a single one gets udpated:
```sql
UPDATE code_v1
SET code = code || E'\n// @version 1.1'
WHERE hash = 'Ns2sMB40yIw4';
```
after [verifying](https://strudel.cc/?Ns2sMB40yIw4) that the version tag has been added, let's insert it everywhere:
```sql
UPDATE code_v1
SET code = code || E'\n// @version 1.1'
WHERE code NOT LIKE '%@version%'
AND created_at > '2024-05-31T23:07:26+02:00'
AND created_at < '2025-05-01T12:39:24+02:00'
```
4. verify
we can verify that the edits worked by querying all patterns that contain the new version tag:
```sql
SELECT *
FROM code_v1
WHERE code LIKE '%@version 1.1%'
AND created_at > '2024-05-31T23:07:26+02:00'
AND created_at < '2025-05-01T12:39:24+02:00'
ORDER BY created_at ASC;
```
## Have Fun
Remember to have fun, and that this project is driven by the passion of volunteers!
+2 -8
View File
@@ -32,19 +32,13 @@ This project is organized into many [packages](./packages), which are also avail
Read more about how to use these in your own project [here](https://strudel.cc/technical-manual/project-start).
You will need to abide by the terms of the [GNU Affero Public Licence v3](LICENSE.md). As such, Strudel code can only be shared within free/open source projects under the same license -- see the license for details.
You will need to abide by the terms of the [GNU Affero Public Licence v3](LICENSE). As such, Strudel code can only be shared within free/open source projects under the same license -- see the license for details.
Licensing info for the default sound banks can be found over on the [dough-samples](https://github.com/felixroos/dough-samples/blob/main/README.md) repository.
## Contributing
There are many ways to contribute to this project! See [contribution guide](./CONTRIBUTING.md).
<a href="https://codeberg.org/uzu/strudel/activity/contributors">
<img src="https://contrib.rocks/image?repo=tidalcycles/strudel" />
</a>
Made with [contrib.rocks](https://contrib.rocks).
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).
## Community
+10
View File
@@ -83,4 +83,14 @@ export default [
],
},
},
{
// Properties provided by AudioWorkletGlobalScope
files: ['packages/superdough/worklets.mjs'],
languageOptions: {
globals: {
currentTime: 'readonly',
sampleRate: 'readonly',
},
},
},
];
+1 -1
View File
@@ -1,5 +1,5 @@
/*
jsdoc-synonyms.js - Add support for @synonym tag
jsdoc-synonyms.js - Add support for @synonyms tag
Copyright (C) 2023 Strudel contributors - see <https://codeberg.org/uzu/strudel/activity/contributors>
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/>.
*/
+14 -3
View File
@@ -1,7 +1,7 @@
import { closeBrackets } from '@codemirror/autocomplete';
export { toggleComment, toggleBlockComment, toggleLineComment, toggleBlockCommentByLine } from '@codemirror/commands';
// import { search, highlightSelectionMatches } from '@codemirror/search';
import { history } from '@codemirror/commands';
import { history, indentWithTab } from '@codemirror/commands';
import { javascript } from '@codemirror/lang-javascript';
import { defaultHighlightStyle, syntaxHighlighting, bracketMatching } from '@codemirror/language';
import { Compartment, EditorState, Prec } from '@codemirror/state';
@@ -37,6 +37,14 @@ const extensions = {
isActiveLineHighlighted: (on) => (on ? [highlightActiveLine(), highlightActiveLineGutter()] : []),
isFlashEnabled,
keybindings,
isTabIndentationEnabled: (on) => (on ? keymap.of([indentWithTab]) : []),
isMultiCursorEnabled: (on) =>
on
? [
EditorState.allowMultipleSelections.of(true),
EditorView.clickAddsSelectionRange.of((ev) => ev.metaKey || ev.ctrlKey),
]
: [],
};
const compartments = Object.fromEntries(Object.keys(extensions).map((key) => [key, new Compartment()]));
@@ -51,6 +59,8 @@ export const defaultSettings = {
isFlashEnabled: true,
isTooltipEnabled: false,
isLineWrappingEnabled: false,
isTabIndentationEnabled: false,
isMultiCursorEnabled: false,
theme: 'strudelTheme',
fontFamily: 'monospace',
fontSize: 18,
@@ -62,7 +72,7 @@ export const codemirrorSettings = persistentAtom('codemirror-settings', defaultS
});
// https://codemirror.net/docs/guide/
export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, root }) {
export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, root, mondo }) {
const settings = codemirrorSettings.get();
const initialSettings = Object.keys(compartments).map((key) =>
compartments[key].of(extensions[key](parseBooleans(settings[key]))),
@@ -75,7 +85,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
/* search(),
highlightSelectionMatches(), */
...initialSettings,
javascript(),
mondo ? [] : javascript(),
sliderPlugin,
widgetPlugin,
// indentOnInput(), // works without. already brought with javascript extension?
@@ -209,6 +219,7 @@ export class StrudelMirror {
},
onEvaluate: () => this.evaluate(),
onStop: () => this.stop(),
mondo: replOptions.mondo,
});
const cmEditor = this.root.querySelector('.cm-editor');
if (cmEditor) {
+2 -2
View File
@@ -1,4 +1,4 @@
import { RangeSetBuilder, StateEffect, StateField } from '@codemirror/state';
import { RangeSetBuilder, StateEffect, StateField, Prec } from '@codemirror/state';
import { Decoration, EditorView } from '@codemirror/view';
export const setMiniLocations = StateEffect.define();
@@ -134,5 +134,5 @@ export const isPatternHighlightingEnabled = (on, config) => {
setTimeout(() => {
updateMiniLocations(config.editor, config.miniLocations);
}, 100);
return on ? highlightExtension : [];
return on ? Prec.highest(highlightExtension) : [];
};
+2 -2
View File
@@ -21,11 +21,11 @@ const vscodeExtension = (options) => [vscodePlugin].concat(options ?? []);
const keymaps = {
vim,
emacs,
codemirror: () => keymap.of(defaultKeymap),
vscode: vscodeExtension,
};
export function keybindings(name) {
const active = keymaps[name];
return [keymap.of(defaultKeymap), keymap.of(historyKeymap), active ? active() : []];
// keymap.of(searchKeymap),
return [active ? active() : [], keymap.of(historyKeymap)];
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/codemirror",
"version": "1.2.2",
"version": "1.2.3",
"description": "Codemirror Extensions for Strudel",
"main": "index.mjs",
"publishConfig": {
+158 -22
View File
@@ -4,13 +4,14 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Pattern, register, sequence } from './pattern.mjs';
import { Pattern, register, reify } from './pattern.mjs';
export function createParam(names) {
let isMulti = Array.isArray(names);
names = !isMulti ? [names] : names;
const name = names[0];
// todo: make this less confusing
const withVal = (xs) => {
let bag;
// check if we have an object with an unnamed control (.value)
@@ -35,25 +36,34 @@ export function createParam(names) {
}
};
const func = (...pats) => sequence(...pats).withValue(withVal);
const setter = function (...pats) {
if (!pats.length) {
return this.fmap(withVal);
// todo: make this less confusing
const func = function (value, pat) {
if (!pat) {
return reify(value).withValue(withVal);
}
return this.set(func(...pats));
if (typeof value === 'undefined') {
return pat.fmap(withVal);
}
return pat.set(reify(value).withValue(withVal));
};
Pattern.prototype[name] = function (value) {
return func(value, this);
};
Pattern.prototype[name] = setter;
return func;
}
// maps control alias names to the "main" control name
const controlAlias = new Map();
export function isControlName(name) {
return controlAlias.has(name);
}
export function registerControl(names, ...aliases) {
const name = Array.isArray(names) ? names[0] : names;
let bag = {};
bag[name] = createParam(names);
controlAlias.set(name, name);
aliases.forEach((alias) => {
bag[alias] = bag[name];
controlAlias.set(alias, name);
@@ -242,6 +252,20 @@ export const { fmenv } = registerControl('fmenv');
*
*/
export const { fmattack } = registerControl('fmattack');
/**
* waveform of the fm modulator
*
* @name fmwave
* @param {number | Pattern} wave waveform
* @example
* n("0 1 2 3".fast(4)).scale("d:minor").s("sine").fmwave("<sine square sawtooth crackle>").fm(4).fmh(2.01)
* @example
* n("0 1 2 3".fast(4)).chord("<Dm Am F G>").voicing().s("sawtooth").fmwave("brown").fm(.6)
*
*/
export const { fmwave } = registerControl('fmwave');
/**
* Decay time for the FM envelope: seconds until the sustain level is reached after the attack phase.
*
@@ -296,6 +320,7 @@ export const { fft } = registerControl('fft');
*
* @name decay
* @param {number | Pattern} time decay time in seconds
* @synonyms dec
* @example
* note("c3 e3 f3 g3").decay("<.1 .2 .3 .4>").sustain(0)
*
@@ -434,6 +459,78 @@ export const { crush } = registerControl('crush');
*/
export const { coarse } = registerControl('coarse');
/**
* modulate the amplitude of a sound with a continuous waveform
*
* @name tremolo
* @synonyms trem
* @param {number | Pattern} speed modulation speed in HZ
* @example
* note("d d d# d".fast(4)).s("supersaw").tremolo("<3 2 100> ").tremoloskew("<.5>")
*
*/
export const { tremolo } = registerControl(['tremolo', 'tremolodepth', 'tremoloskew', 'tremolophase'], 'trem');
/**
* modulate the amplitude of a sound with a continuous waveform
*
* @name tremolosync
* @synonyms tremsync
* @param {number | Pattern} cycles modulation speed in cycles
* @example
* note("d d d# d".fast(4)).s("supersaw").tremolosync("4").tremoloskew("<1 .5 0>")
*
*/
export const { tremolosync } = registerControl(
['tremolosync', 'tremolodepth', 'tremoloskew', 'tremolophase'],
'tremsync',
);
/**
* depth of amplitude modulation
*
* @name tremolodepth
* @synonyms tremdepth
* @param {number | Pattern} depth
* @example
* note("a1 a1 a#1 a1".fast(4)).s("pulse").tremsync(4).tremolodepth("<1 2 .7>")
*
*/
export const { tremolodepth } = registerControl('tremolodepth', 'tremdepth');
/**
* alter the shape of the modulation waveform
*
* @name tremoloskew
* @synonyms tremskew
* @param {number | Pattern} amount between 0 & 1, the shape of the waveform
* @example
* note("{f a c e}%16").s("sawtooth").tremsync(4).tremoloskew("<.5 0 1>")
*
*/
export const { tremoloskew } = registerControl('tremoloskew', 'tremskew');
/**
* alter the phase of the modulation waveform
*
* @name tremolophase
* @synonyms tremphase
* @param {number | Pattern} offset the offset in cycles of the modulation
* @example
* note("{f a c e}%16").s("sawtooth").tremsync(4).tremolophase("<0 .25 .66>")
*
*/
export const { tremolophase } = registerControl('tremolophase', 'tremphase');
/**
* shape of amplitude modulation
*
* @name tremoloshape
* @param {number | Pattern} shape tri | square | sine | saw | ramp
* @example
* note("{f g c d}%16").tremsync(4).tremoloshape("<sine tri square>").s("sawtooth")
*
*/
export const { tremoloshape } = registerControl('tremoloshape', 'tremshape');
/**
* filter overdrive for supported filter types
*
@@ -443,6 +540,42 @@ export const { coarse } = registerControl('coarse');
* note("{f g g c d a a#}%16".sub(17)).s("supersaw").lpenv(8).lpf(150).lpq(.8).ftype('ladder').drive("<.5 4>")
*
*/
/**
* modulate the amplitude of an orbit to create a "sidechain" like effect
*
* @name duckorbit
* @param {number | Pattern} orbit target orbit
* @example
* $: n(run(16)).scale("c:minor:pentatonic").s("sawtooth").delay(.7).orbit(2)
* $: s("bd:4!4").beat("0,4,8,11,14",16).duckorbit(2).duckattack(0.2).duckdepth(1)
*
*/
export const { duck } = registerControl('duckorbit', 'duck');
/**
* the amount of ducking applied to target orbit
*
* @name duckdepth
* @param {number | Pattern} depth depth of modulation from 0 to 1
* @example
* stack( n(run(8)).scale("c:minor").s("sawtooth").delay(.7).orbit(2), s("bd:4!4").beat("0,4,8,11,14",16).duckorbit(2).duckattack(0.2).duckdepth("<1 .9 .6 0>"))
*
*/
export const { duckdepth } = registerControl('duckdepth');
/**
* the attack time of the duck effect
*
* @name duckattack
* @param {number | Pattern} time
* @example
* stack( n(run(8)).scale("c:minor").s("sawtooth").delay(.7).orbit(2), s("bd:4!4").beat("0,4,8,11,14",16).duckorbit(2).duckattack("<0.2 0 0.4>").duckdepth(1))
*
*/
export const { duckattack } = registerControl('duckattack', 'duckatt');
export const { drive } = registerControl('drive');
/**
@@ -975,15 +1108,31 @@ export const { delayfeedback, delayfb, dfb } = registerControl('delayfeedback',
*
*/
export const { delaytime, delayt, dt } = registerControl('delaytime', 'delayt', 'dt');
/* // TODO: test
/**
* Sets the time of the delay effect in cycles.
*
* @name delaysync
* @param {number | Pattern} cycles delay length in cycles
* @synonyms delayt, dt
* @example
* s("bd bd").delay(.25).delaysync("<1 2 3 5>".div(8))
*
*/
export const { delaysync } = registerControl('delaysync');
/**
* Specifies whether delaytime is calculated relative to cps.
*
* @name lock
* @param {number | Pattern} enable When set to 1, delaytime is a direct multiple of a cycle.
* @superdirtOnly
* @example
* s("sd").delay().lock(1).osc()
*
*
*/
export const { lock } = registerControl('lock');
/**
* Set detune for stacked voices of supported oscillators
@@ -1535,18 +1684,6 @@ export const { density } = registerControl('density');
// ['modwheel'],
export const { expression } = registerControl('expression');
export const { sustainpedal } = registerControl('sustainpedal');
/* // TODO: doesn't seem to do anything
*
* Tremolo Audio DSP effect
*
* @name tremolodepth
* @param {number | Pattern} depth between 0 and 1
* @example
* n("0,4,7").tremolodepth("<0 .3 .6 .9>").osc()
*
*/
export const { tremolodepth, tremdp } = registerControl('tremolodepth', 'tremdp');
export const { tremolorate, tremr } = registerControl('tremolorate', 'tremr');
export const { fshift } = registerControl('fshift');
export const { fshiftnote } = registerControl('fshiftnote');
@@ -1623,7 +1760,6 @@ export const { zmod } = registerControl('zmod');
// like crush but scaled differently
export const { zcrush } = registerControl('zcrush');
export const { zdelay } = registerControl('zdelay');
export const { tremolo } = registerControl('tremolo');
export const { zzfx } = registerControl('zzfx');
/**
+3 -2
View File
@@ -5,7 +5,7 @@ This program is free software: you can redistribute it and/or modify it under th
*/
import createClock from './zyklus.mjs';
import { logger } from './logger.mjs';
import { errorLogger, logger } from './logger.mjs';
export class Cyclist {
constructor({
@@ -67,6 +67,7 @@ export class Cyclist {
// the following line is dumb and only here for backwards compatibility
// see https://codeberg.org/uzu/strudel/pulls/1004
const deadline = targetTime - phase;
// this onTrigger has another signature
onTrigger?.(hap, deadline, duration, this.cps, targetTime);
if (hap.value.cps !== undefined && this.cps != hap.value.cps) {
this.cps = hap.value.cps;
@@ -75,7 +76,7 @@ export class Cyclist {
}
});
} catch (e) {
logger(`[cyclist] error: ${e.message}`);
errorLogger(e);
onError?.(e);
}
},
+32 -1
View File
@@ -10,7 +10,7 @@ https://rohandrape.net/?t=hmt
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 { timeCat, register, silence } from './pattern.mjs';
import { timeCat, register, silence, stack, pure, _morph } from './pattern.mjs';
import { rotate, flatten, splitAt, zipWith } from './util.mjs';
import Fraction, { lcm } from './fraction.mjs';
@@ -139,6 +139,14 @@ export const euclid = register('euclid', function (pulses, steps, pat) {
return pat.struct(_euclidRot(pulses, steps, 0));
});
export const e = register('e', function (euc, pat) {
if (!Array.isArray(euc)) {
euc = [euc];
}
const [pulses, steps = pulses, rot = 0] = euc;
return pat.struct(_euclidRot(pulses, steps, rot));
});
export const { euclidrot, euclidRot } = register(['euclidrot', 'euclidRot'], function (pulses, steps, rotation, pat) {
return pat.struct(_euclidRot(pulses, steps, rotation));
});
@@ -188,3 +196,26 @@ export const euclidLegato = register(['euclidLegato'], function (pulses, steps,
export const euclidLegatoRot = register(['euclidLegatoRot'], function (pulses, steps, rotation, pat) {
return _euclidLegato(pulses, steps, rotation, pat);
});
/**
* A 'euclid' variant with an additional parameter that morphs the resulting
* rhythm from 0 (no morphing) to 1 (completely 'even'). For example
* `sound("bd").euclidish(3,8,0)` would be the same as
* `sound("bd").euclid(3,8)`, and `sound("bd").euclidish(3,8,1)` would be the
* same as `sound("bd bd bd")`. `sound("bd").euclidish(3,8,0.5)` would have a
* groove somewhere between.
* Inspired by the work of Malcom Braff.
* @name euclidish
* @synonyms eish
* @memberof Pattern
* @param {number} pulses the number of onsets
* @param {number} steps the number of steps to fill
* @param {number} groove exists between the extremes of 0 (straight euclidian) and 1 (straight pulse)
* @example
* sound("hh").euclidish(7,12,sine.slow(8))
* .pan(sine.slow(8))
*/
export const { euclidish, eish } = register(['euclidish', 'eish'], function (pulses, steps, perc, pat) {
const morphed = _morph(bjork(pulses, steps), new Array(pulses).fill(1), perc);
return pat.struct(morphed).setSteps(steps);
});
+3
View File
@@ -4,6 +4,8 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
export const strudelScope = {};
export const evalScope = async (...args) => {
const results = await Promise.allSettled(args);
const modules = results.filter((result) => result.status === 'fulfilled').map((r) => r.value);
@@ -18,6 +20,7 @@ export const evalScope = async (...args) => {
modules.forEach((module) => {
Object.entries(module).forEach(([name, value]) => {
globalThis[name] = value;
strudelScope[name] = value;
});
});
return modules;
+2 -7
View File
@@ -4,6 +4,7 @@ Copyright (C) 2022 Strudel contributors - see <https://codeberg.org/uzu/strudel/
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import Fraction from './fraction.mjs';
import { stringifyValues } from './util.mjs';
export class Hap {
/*
@@ -148,13 +149,7 @@ export class Hap {
}
showWhole(compact = false) {
return `${this.whole == undefined ? '~' : this.whole.show()}: ${
typeof this.value === 'object'
? compact
? JSON.stringify(this.value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ')
: JSON.stringify(this.value)
: this.value
}`;
return `${this.whole == undefined ? '~' : this.whole.show()}: ${stringifyValues(this.value, compact)}`;
}
combineContext(b) {
+6
View File
@@ -4,6 +4,12 @@ let debounce = 1000,
lastMessage,
lastTime;
export function errorLogger(e, origin = 'cyclist') {
//TODO: add some kind of debug flag that enables this while in dev mode
// console.error(e);
logger(`[${origin}] error: ${e.message}`);
}
export function logger(message, type, data = {}) {
let t = performance.now();
if (lastMessage === message && t - lastTime < debounce) {
-1
View File
@@ -11,7 +11,6 @@ export class NeoCyclist {
constructor({ onTrigger, onToggle, getTime }) {
this.started = false;
this.cps = 0.5;
this.lastTick = 0; // absolute time when last tick (clock callback) happened
this.getTime = getTime; // get absolute time
this.time_at_last_tick_message = 0;
// the clock of the worker and the audio context clock can drift apart over time
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/core",
"version": "1.2.2",
"version": "1.2.3",
"description": "Port of Tidal Cycles to JavaScript",
"main": "index.mjs",
"type": "module",
+156 -14
View File
@@ -21,6 +21,8 @@ import {
numeralArgs,
parseNumeral,
pairs,
zipWith,
stringifyValues,
} from './util.mjs';
import drawLine from './drawLine.mjs';
import { logger } from './logger.mjs';
@@ -852,14 +854,29 @@ export class Pattern {
);
}
log(func = (_, hap) => `[hap] ${hap.showWhole(true)}`, getData = (_, hap) => ({ hap })) {
/**
* Writes the content of the current event to the console (visible in the side menu).
* @name log
* @memberof Pattern
* @example
* s("bd sd").log()
*/
log(func = (hap) => `[hap] ${hap.showWhole(true)}`, getData = (hap) => ({ hap })) {
return this.onTrigger((...args) => {
logger(func(...args), undefined, getData(...args));
}, false);
}
logValues(func = id) {
return this.log((_, hap) => func(hap.value));
/**
* A simplified version of `log` which writes all "values" (various configurable parameters)
* within the event to the console (visible in the side menu).
* @name logValues
* @memberof Pattern
* @example
* s("bd sd").gain("0.25 0.5 1").n("2 1 0").logValues()
*/
logValues(func = (value) => `[hap] ${stringifyValues(value, true)}`) {
return this.log((hap) => func(hap.value));
}
//////////////////////////////////////////////////////////////////////
@@ -869,6 +886,31 @@ export class Pattern {
console.log(drawLine(this));
return this;
}
//////////////////////////////////////////////////////////////////////
// methods relating to breaking patterns into subcycles
// Breaks a pattern into a pattern of patterns, according to the structure of the given binary pattern.
unjoin(pieces, func = id) {
return pieces.withHap((hap) =>
hap.withValue((v) => (v ? func(this.ribbon(hap.whole.begin, hap.whole.duration)) : this)),
);
}
/**
* Breaks a pattern into pieces according to the structure of a given pattern.
* True values in the given pattern cause the corresponding subcycle of the
* source pattern to be looped, and for an (optional) given function to be
* applied. False values result in the corresponding part of the source pattern
* to be played unchanged.
* @name into
* @memberof Pattern
* @example
* sound("bd sd ht lt").into("1 0", hurry(2))
*/
into(pieces, func) {
return this.unjoin(pieces, func).innerJoin();
}
}
//////////////////////////////////////////////////////////////////////
@@ -904,12 +946,13 @@ Pattern.prototype.collect = function () {
* note("<[c,eb,g]!2 [c,f,ab] [d,f,ab]>")
* .arpWith(haps => haps[2])
* */
Pattern.prototype.arpWith = function (func) {
return this.collect()
export const arpWith = register('arpWith', (func, pat) => {
return pat
.collect()
.fmap((v) => reify(func(v)))
.innerJoin()
.withHap((h) => new Hap(h.whole, h.part, h.value.value, h.combineContext(h.value)));
};
});
/**
* Selects indices in in stacked notes.
@@ -917,9 +960,11 @@ Pattern.prototype.arpWith = function (func) {
* note("<[c,eb,g]!2 [c,f,ab] [d,f,ab]>")
* .arp("0 [0,2] 1 [0,2]")
* */
Pattern.prototype.arp = function (pat) {
return this.arpWith((haps) => pat.fmap((i) => haps[i % haps.length]));
};
export const arp = register(
'arp',
(indices, pat) => pat.arpWith((haps) => reify(indices).fmap((i) => haps[i % haps.length])),
false,
);
/*
* Takes a time duration followed by one or more patterns, and shifts the given patterns in time, so they are
@@ -1260,7 +1305,7 @@ export function sequenceP(pats) {
* @synonyms polyrhythm, pr
* @example
* stack("g3", "b3", ["e4", "d4"]).note()
* // "g3,b3,[e4,d4]".note()
* // "g3,b3,[e4 d4]".note()
*
* @example
* // As a chained function:
@@ -1541,7 +1586,7 @@ export const func = curry((a, b) => reify(b).func(a));
/**
* Registers a new pattern method. The method is added to the Pattern class + the standalone function is returned from register.
*
* @param {string} name name of the function
* @param {string | string[]} name name of the function, or an array of names to be used as synonyms
* @param {function} func function with 1 or more params, where last is the current pattern
* @noAutocomplete
*
@@ -2491,6 +2536,37 @@ export const { fastchunk, fastChunk } = register(
true,
);
/**
* Like `chunk`, but the function is applied to a looped subcycle of the source pattern.
* @name chunkInto
* @synonyms chunkinto
* @memberof Pattern
* @example
* sound("bd sd ht lt bd - cp lt").chunkInto(4, hurry(2))
* .bank("tr909")
*/
export const { chunkinto, chunkInto } = register(['chunkinto', 'chunkInto'], function (n, func, pat) {
return pat.into(fastcat(true, ...Array(n - 1).fill(false))._iterback(n), func);
});
/**
* Like `chunkInto`, but moves backwards through the chunks.
* @name chunkBackInto
* @synonyms chunkbackinto
* @memberof Pattern
* @example
* sound("bd sd ht lt bd - cp lt").chunkInto(4, hurry(2))
* .bank("tr909")
*/
export const { chunkbackinto, chunkBackInto } = register(['chunkbackinto', 'chunkBackInto'], function (n, func, pat) {
return pat.into(
fastcat(true, ...Array(n - 1).fill(false))
._iter(n)
._early(1),
func,
);
});
// TODO - redefine elsewhere in terms of mask
export const bypass = register(
'bypass',
@@ -2506,7 +2582,7 @@ export const bypass = register(
* Loops the pattern inside an `offset` for `cycles`.
* If you think of the entire span of time in cycles as a ribbon, you can cut a single piece and loop it.
* @name ribbon
* @synonym rib
* @synonyms rib
* @param {number} offset start point of loop in cycles
* @param {number} cycles loop length in cycles
* @example
@@ -2720,7 +2796,7 @@ export function stepcat(...timepats) {
if (timepats.length === 0) {
return nothing;
}
const findsteps = (x) => (Array.isArray(x) ? x : [x._steps, x]);
const findsteps = (x) => (Array.isArray(x) ? x : [x._steps ?? 1, x]);
timepats = timepats.map(findsteps);
if (timepats.find((x) => x[0] === undefined)) {
const times = timepats.map((a) => a[0]).filter((x) => x !== undefined);
@@ -3204,7 +3280,7 @@ export const slice = register(
* s("bd!8").onTriggerTime((hap) => {console.info(hap)})
*/
Pattern.prototype.onTriggerTime = function (func) {
return this.onTrigger((t_deprecate, hap, currentTime, cps = 1, targetTime) => {
return this.onTrigger((hap, currentTime, _cps, targetTime) => {
const diff = targetTime - currentTime;
window.setTimeout(() => {
func(hap);
@@ -3341,3 +3417,69 @@ export const { beat } = register(
['beat'],
__beat((x) => x.innerJoin()),
);
export const _morph = (from, to, by) => {
by = Fraction(by);
const dur = Fraction(1).div(from.length);
const positions = (list) => {
const result = [];
for (const [pos, value] of list.entries()) {
if (value) {
result.push([Fraction(pos).div(list.length), value]);
}
}
return result;
};
const arcs = zipWith(
([posa, valuea], [posb, valueb]) => {
const b = by.mul(posb - posa).add(posa);
const e = b.add(dur);
return new TimeSpan(b, e);
},
positions(from),
positions(to),
);
function query(state) {
const cycle = state.span.begin.sam();
const cycleArc = state.span.cycleArc();
const result = [];
for (const whole of arcs) {
const part = whole.intersection(cycleArc);
if (part !== undefined) {
result.push(
new Hap(
whole.withTime((x) => x.add(cycle)),
part.withTime((x) => x.add(cycle)),
true,
),
);
}
}
return result;
}
return new Pattern(query).splitQueries();
};
/**
* Takes two binary rhythms represented as lists of 1s and 0s, and a number
* between 0 and 1 that morphs between them. The two lists should contain the same
* number of true values.
* @example
* sound("hh").struct(morph([1,0,1,0,1,0,1,0], // straight rhythm
* [1,1,0,1,0,1,0], // wonky rhythm
* 0.25 // creates a slightly wonky rhythm
* )
* )
* @example
* sound("hh").struct(morph("1:0:1:0:1:0:1:0", // straight rhythm
* "1:1:0:1:0:1:0", // wonky rhythm
* sine.slow(8) // slowly morph between the rhythms
* )
* )
*/
export const morph = (frompat, topat, bypat) => {
frompat = reify(frompat);
topat = reify(topat);
bypat = reify(bypat);
return frompat.innerBind((from) => topat.innerBind((to) => bypat.innerBind((by) => _morph(from, to, by))));
};
+16 -6
View File
@@ -1,7 +1,7 @@
import { NeoCyclist } from './neocyclist.mjs';
import { Cyclist } from './cyclist.mjs';
import { evaluate as _evaluate } from './evaluate.mjs';
import { logger } from './logger.mjs';
import { errorLogger, logger } from './logger.mjs';
import { setTime } from './time.mjs';
import { evalScope } from './evaluate.mjs';
import { register, Pattern, isPattern, silence, stack } from './pattern.mjs';
@@ -21,6 +21,7 @@ export function repl({
setInterval,
clearInterval,
id,
mondo = false,
}) {
const state = {
schedulerError: undefined,
@@ -113,8 +114,9 @@ export function repl({
* all(x => x.pianoroll())
* ```
*/
let allTransforms = [];
const all = function (transform) {
allTransform = transform;
allTransforms.push(transform);
return silence;
};
/** Applies a function to each of the running patterns separately. This is intended for future use with upcoming 'stepwise' features. See `all` for a version that applies the function to all the patterns stacked together into a single pattern.
@@ -190,7 +192,12 @@ export function repl({
await injectPatternMethods();
setTime(() => scheduler.now()); // TODO: refactor?
await beforeEval?.({ code });
allTransforms = []; // reset all transforms
shouldHush && hush();
if (mondo) {
code = `mondolang\`${code}\``;
}
let { pattern, meta } = await _evaluate(code, transpiler, transpilerOptions);
if (Object.keys(pPatterns).length) {
let patterns = Object.values(pPatterns);
@@ -202,8 +209,10 @@ export function repl({
} else if (eachTransform) {
pattern = eachTransform(pattern);
}
if (allTransform) {
pattern = allTransform(pattern);
if (allTransforms.length) {
for (let i in allTransforms) {
pattern = allTransforms[i](pattern);
}
}
if (!isPattern(pattern)) {
const message = `got "${typeof evaluated}" instead of pattern`;
@@ -236,6 +245,7 @@ export function repl({
export const getTrigger =
({ getTime, defaultOutput }) =>
async (hap, deadline, duration, cps, t) => {
// ^ this signature is different from hap.context.onTrigger, as set by Pattern.onTrigger(onTrigger)
// TODO: get rid of deadline after https://codeberg.org/uzu/strudel/pulls/1004
try {
if (!hap.context.onTrigger || !hap.context.dominantTrigger) {
@@ -243,9 +253,9 @@ export const getTrigger =
}
if (hap.context.onTrigger) {
// call signature of output / onTrigger is different...
await hap.context.onTrigger(getTime() + deadline, hap, getTime(), cps, t);
await hap.context.onTrigger(hap, getTime(), cps, t);
}
} catch (err) {
logger(`[cyclist] error: ${err.message}`, 'error');
errorLogger(err, 'getTrigger');
}
};
+7 -5
View File
@@ -71,7 +71,6 @@ export const sine2 = signal((t) => Math.sin(Math.PI * 2 * t));
/**
* A sine signal between 0 and 1.
*
* @return {Pattern}
* @example
* n(sine.segment(16).range(0,15))
@@ -100,7 +99,6 @@ export const cosine2 = sine2._early(Fraction(1).div(4));
/**
* A square signal between 0 and 1.
*
* @return {Pattern}
* @example
* n(square.segment(4).range(0,7)).scale("C:minor")
@@ -266,7 +264,7 @@ export const randrun = (n) => {
const rands = timeToRands(t.floor().add(0.5), n);
const nums = rands
.map((n, i) => [n, i])
.sort((a, b) => a[0] > b[0] - a[0] < b[0])
.sort((a, b) => (a[0] > b[0]) - (a[0] < b[0]))
.map((x) => x[1]);
const i = t.cyclePos().mul(n).floor() % n;
return nums[i];
@@ -285,7 +283,7 @@ const _rearrangeWith = (ipat, n, pat) => {
* @example
* note("c d e f").sound("piano").shuffle(4)
* @example
* note("c d e f".shuffle(4), "g").sound("piano")
* seq("c d e f".shuffle(4), "g").note().sound("piano")
*/
export const shuffle = register('shuffle', (n, pat) => {
return _rearrangeWith(randrun(n), n, pat);
@@ -298,7 +296,7 @@ export const shuffle = register('shuffle', (n, pat) => {
* @example
* note("c d e f").sound("piano").scramble(4)
* @example
* note("c d e f".scramble(4), "g").sound("piano")
* seq("c d e f".scramble(4), "g").note().sound("piano")
*/
export const scramble = register('scramble', (n, pat) => {
return _rearrangeWith(_irand(n)._segment(n), n, pat);
@@ -398,6 +396,10 @@ export const chooseInWith = (pat, xs) => {
*/
export const choose = (...xs) => chooseWith(rand, xs);
// todo: doc
export const chooseIn = (...xs) => chooseInWith(rand, xs);
export const chooseOut = choose;
/**
* Chooses from the given list of values (or patterns of values), according
* to the pattern that the method is called on. The pattern should be in
+1 -1
View File
@@ -32,7 +32,7 @@ function triggerSpeech(words, lang, voice) {
}
export const speak = register('speak', function (lang, voice, pat) {
return pat.onTrigger((_, hap) => {
return pat.onTrigger((hap) => {
triggerSpeech(hap.value, lang, voice);
});
});
+79 -2
View File
@@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
import Fraction from 'fraction.js';
import { describe, it, expect } from 'vitest';
import { describe, it, expect, vi } from 'vitest';
import {
TimeSpan,
@@ -52,8 +52,11 @@ import {
stackCentre,
stepcat,
sometimes,
expand,
} from '../index.mjs';
import { log, logValues } from '../pattern.mjs';
import { steady } from '../signal.mjs';
import { n, s } from '../controls.mjs';
@@ -1001,7 +1004,7 @@ describe('Pattern', () => {
});
describe('hurry', () => {
it('Can speed up patterns and sounds', () => {
sameFirst(s('a', 'b').hurry(2), s('a', 'b').fast(2).speed(2));
sameFirst(s(sequence('a', 'b')).hurry(2), s(sequence('a', 'b')).fast(2).speed(2));
});
});
/*describe('composable functions', () => {
@@ -1179,6 +1182,9 @@ describe('Pattern', () => {
it('calculates undefined steps as the average', () => {
expect(sameFirst(stepcat(pure(1), pure(2), pure(3).setSteps(undefined)), fastcat(1, 2, 3)));
});
it('works with auto-reified values', () => {
expect(sameFirst(stepcat(expand(3, 'bd'), 'rim'), stepcat(expand(3, 'bd'), pure('rim'))));
});
});
describe('shrink', () => {
it('can shrink', () => {
@@ -1267,4 +1273,75 @@ describe('Pattern', () => {
);
});
});
describe('unjoin', () => {
it('destructures a pattern into subcycles', () => {
sameFirst(
fastcat('a', 'b', 'c', 'd')
.unjoin(fastcat(true, fastcat(true, true)))
.fmap(fast(2))
.join(),
fastcat('a', 'b', 'a', 'b', 'c', 'c', 'd', 'd'),
);
});
});
describe('into', () => {
it('applies a function to subcycles of a pattern', () => {
sameFirst(
fastcat('a', 'b', 'c', 'd').into(fastcat(fastcat('true', 'true'), 'true'), fast(2)),
fastcat('a', 'a', 'b', 'b', 'c', 'd', 'c', 'd'),
);
});
});
describe('chunkinto', () => {
it('chunks into subcycles', () => {
sameFirst(
fastcat('a', 'b', 'c').chunkInto(3, fast(2)).fast(3),
fastcat(fastcat('a', 'a'), 'b', 'c', 'a', fastcat('b', 'b'), 'c', 'a', 'b', fastcat('c', 'c')),
);
});
});
describe('chunkbackinto', () => {
it('chunks into subcycles backwards', () => {
sameFirst(
fastcat('a', 'b', 'c').chunkBackInto(3, fast(2)).fast(3),
fastcat('a', 'b', fastcat('c', 'c'), 'a', fastcat('b', 'b'), 'c', fastcat('a', 'a'), 'b', 'c'),
);
});
});
describe('log', () => {
it('logs to console', () => {
const mockConsoleLog = vi.spyOn(console, 'log').mockImplementation(() => {});
const pattern = pure('a').log();
const haps = pattern.queryArc(0, 1);
// Force a trigger
haps.forEach((hap) => {
hap.context?.onTrigger?.(hap);
});
expect(mockConsoleLog).toHaveBeenCalledWith(
'%c[hap] 0/1 → 1/1: a',
'background-color: black;color:white;border-radius:15px',
);
mockConsoleLog.mockRestore();
});
});
describe('logValues', () => {
it('logs values to console', () => {
const mockConsoleLog = vi.spyOn(console, 'log').mockImplementation(() => {});
const pattern = pure('a').note('c#').logValues();
const haps = pattern.queryArc(0, 1);
// Force a trigger
haps.forEach((hap) => {
hap.context?.onTrigger?.(hap);
});
expect(mockConsoleLog).toHaveBeenCalledWith(
'%c[hap] value:a note:c#',
'background-color: black;color:white;border-radius:15px',
);
mockConsoleLog.mockRestore();
});
});
});
+1 -1
View File
@@ -72,7 +72,7 @@ export class TimeSpan {
}
intersection(other) {
// Intersection of two timespans, returns None if they don't intersect.
// Intersection of two timespans, returns undefined if they don't intersect.
const intersect_begin = this.begin.max(other.begin);
const intersect_end = this.end.min(other.end);
+10
View File
@@ -487,3 +487,13 @@ export function getCurrentKeyboardState() {
// }
// return lcm((x * y) / gcd(x, y), ...z);
// };
// Takes values -- typically derived from events, i.e. `hap`s -- and renders them
// into a readable format
export function stringifyValues(value, compact = false) {
return typeof value === 'object'
? compact
? JSON.stringify(value).slice(1, -1).replaceAll('"', '').replaceAll(',', ' ')
: JSON.stringify(value)
: value;
}
+3 -3
View File
@@ -23,7 +23,7 @@ export const csound = register('csound', (instrument, pat) => {
instrument = instrument || 'triangle';
init(); // not async to support csound inside other patterns + to be able to call pattern methods after it
// TODO: find a alternative way to wait for csound to load (to wait with first time playback)
return pat.onTrigger((time_deprecate, hap, currentTime, _cps, targetTime) => {
return pat.onTrigger((hap, currentTime, _cps, targetTime) => {
if (!_csound) {
logger('[csound] not loaded yet', 'warning');
return;
@@ -142,7 +142,7 @@ export const csoundm = register('csoundm', (instrument, pat) => {
p1 = `"${instrument}"`;
}
init(); // not async to support csound inside other patterns + to be able to call pattern methods after it
return pat.onTrigger((tidal_time, hap) => {
return pat.onTrigger((hap, currentTime, _cps, targetTime) => {
if (!_csound) {
logger('[csound] not loaded yet', 'warning');
return;
@@ -151,7 +151,7 @@ export const csoundm = register('csoundm', (instrument, pat) => {
throw new Error('csound only support objects as hap values');
}
// Time in seconds counting from now.
const p2 = tidal_time - getAudioContext().currentTime;
const p2 = targetTime - currentTime;
const p3 = hap.duration.valueOf() + 0;
const frequency = getFrequency(hap);
let { gain = 1, velocity = 0.9 } = hap.value;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/csound",
"version": "1.2.3",
"version": "1.2.4",
"description": "csound bindings for strudel",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -6,7 +6,7 @@ const OFF_MESSAGE = 0x80;
const CC_MESSAGE = 0xb0;
Pattern.prototype.midi = function (output) {
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
return this.onTrigger((hap, currentTime, cps, targetTime) => {
let { note, nrpnn, nrpv, ccn, ccv, velocity = 0.9, gain = 1 } = hap.value;
//magic number to get audio engine to line up, can probably be calculated somehow
const latencyMs = 34;
+1 -1
View File
@@ -4,7 +4,7 @@ import { Invoke } from './utils.mjs';
const collator = new ClockCollator({});
export async function oscTriggerTauri(t_deprecate, hap, currentTime, cps = 1, targetTime) {
export async function oscTriggerTauri(hap, currentTime, cps = 1, targetTime) {
const controls = parseControlsFromHap(hap, cps);
const params = [];
const timestamp = collator.calculateTimestamp(currentTime, targetTime);
+2 -2
View File
@@ -150,7 +150,7 @@ export class Drawer {
this.lastFrame = phase;
this.visibleHaps = (this.visibleHaps || [])
// filter out haps that are too far in the past (think left edge of screen for pianoroll)
.filter((h) => h.endClipped >= phase - lookbehind - lookahead)
.filter((h) => h.whole && h.endClipped >= phase - lookbehind - lookahead)
// add new haps with onset (think right edge bars scrolling in)
.concat(haps.filter((h) => h.hasOnset()));
const time = phase - lookahead;
@@ -175,7 +175,7 @@ export class Drawer {
// +0.1 = workaround for weird holes in query..
const [begin, end] = [Math.max(t, 0), t + lookahead + 0.1];
// remove all future haps
this.visibleHaps = this.visibleHaps.filter((h) => h.whole.begin < t);
this.visibleHaps = this.visibleHaps.filter((h) => h.whole?.begin < t);
this.painters = []; // will get populated by .onPaint calls attached to the pattern
// query future haps
const futureHaps = scheduler.pattern.queryArc(begin, end, { painters: this.painters });
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/draw",
"version": "1.2.2",
"version": "1.2.3",
"description": "Helpers for drawing with Strudel",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/embed",
"version": "1.1.0",
"version": "1.1.1",
"description": "Embeddable Web Component to load a Strudel REPL into an iframe",
"main": "embed.js",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/gamepad",
"version": "1.2.2",
"version": "1.2.3",
"description": "Gamepad Inputs for strudel",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/hydra",
"version": "1.2.2",
"version": "1.2.3",
"description": "Hydra integration for strudel",
"main": "hydra.mjs",
"type": "module",
+1 -1
View File
@@ -333,7 +333,7 @@ Pattern.prototype.midi = function (midiport, options = {}) {
logger(`Midi device disconnected! Available: ${getMidiDeviceNamesString(outputs)}`),
});
return this.onTrigger((time_deprecate, hap, currentTime, cps, targetTime) => {
return this.onTrigger((hap, currentTime, cps, targetTime) => {
if (!WebMidi.enabled) {
logger('Midi not enabled');
return;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/midi",
"version": "1.2.3",
"version": "1.2.4",
"description": "Midi API for strudel",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/mini",
"version": "1.2.2",
"version": "1.2.3",
"description": "Mini notation for strudel",
"main": "index.mjs",
"type": "module",
+39
View File
@@ -0,0 +1,39 @@
# mondo
a lisp-based language intended to be used as a custom dsl for patterns that can stand on its own feet.
see the `test` folder for usage examples
more info:
- [uzulang I](https://garten.salat.dev/uzu/uzulang1.html)
- [uzulang II](https://garten.salat.dev/uzu/uzulang2.html)
## Example Usage
```js
import { MondoRunner } from 'mondolang'
// define our library of functions and variables
let lib = {
add: (a, b) => a + b,
mul: (a, b) => a * b,
PI: Math.PI,
};
// this function will evaluate nodes in the syntax tree
function evaluator(node) {
// check if node is a leaf node (!= list)
if (node.type !== 'list') {
// check lib if we find a match in the lib, otherwise return value
return lib[node.value] ?? node.value;
}
// now it can only be a list..
const [fn, ...args] = node.children;
// children in a list will already be evaluated
// the first child is expected to be a function
if (typeof fn !== 'function') {
throw new Error(`"${fn}" is not a function`);
}
return fn(...args);
}
const runner = new MondoRunner({ evaluator });
const pat = runner.run('add 1 (mul 2 PI)') // 7.283185307179586
```
+484
View File
@@ -0,0 +1,484 @@
/*
mondo.mjs - <short description TODO>
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/mini/test/mini.test.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/>.
*/
// evolved from https://garten.salat.dev/lisp/parser.html
export class MondoParser {
// these are the tokens we expect
token_types = {
comment: /^\/\/(.*?)(?=\n|$)/,
quotes_double: /^"(.*?)"/,
quotes_single: /^'(.*?)'/,
open_list: /^\(/,
close_list: /^\)/,
open_angle: /^</,
close_angle: /^>/,
open_square: /^\[/,
close_square: /^\]/,
open_curly: /^\{/,
close_curly: /^\}/,
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
// TODO: better error handling when "-" is used as rest, e.g "s [- bd]"
op: /^[*/:!@%?+-]|^\.{2}/, // * / : ! @ % ? ..
// dollar: /^\$/,
pipe: /^#/,
stack: /^[,$]/,
or: /^[|]/,
plain: /^[a-zA-Z0-9-~_^#]+/,
};
// matches next token
next_token(code, offset = 0) {
for (let type in this.token_types) {
const match = code.match(this.token_types[type]);
if (match) {
let token = { type, value: match[0] };
if (offset !== -1) {
// add location
token.loc = [offset, offset + match[0].length];
}
return token;
}
}
throw new Error(`mondo: could not match '${code}'`);
}
// takes code string, returns list of matched tokens (if valid)
tokenize(code, offset = 0) {
let tokens = [];
let locEnabled = offset !== -1;
let trim = () => {
// trim whitespace at start, update offset
offset += code.length - code.trimStart().length;
// trim start and end to not confuse parser
return code.trim();
};
code = trim();
while (code.length > 0) {
code = trim();
const token = this.next_token(code, locEnabled ? offset : -1);
code = code.slice(token.value.length);
offset += token.value.length;
tokens.push(token);
}
return tokens;
}
// take code, return abstract syntax tree
parse(code, offset) {
this.code = code;
this.offset = offset;
this.tokens = this.tokenize(code, offset);
const expressions = [];
while (this.tokens.length) {
expressions.push(this.parse_expr());
}
if (expressions.length === 0) {
// empty case
return { type: 'list', children: [] };
}
// do we have multiple top level expressions or a single non list?
if (expressions.length > 1 || expressions[0].type !== 'list') {
return {
type: 'list',
children: this.desugar(expressions),
};
}
// we have a single list
return expressions[0];
}
// parses any valid expression
parse_expr() {
if (!this.tokens[0]) {
throw new Error(`unexpected end of file`);
// TODO: could we allow that? like (((((((( s bd
// return { type: 'list', children: [] };
}
let next = this.tokens[0]?.type;
if (next === 'open_list') {
return this.parse_list();
}
if (next === 'open_angle') {
return this.parse_angle();
}
if (next === 'open_square') {
return this.parse_square();
}
if (next === 'open_curly') {
return this.parse_curly();
}
return this.consume(next);
}
// Token[] => Token[][], e.g. (x , y z) => [['x'],['y','z']]
split_children(children, split_type) {
const chunks = [];
while (true) {
let splitIndex = children.findIndex((child) => child.type === split_type);
if (splitIndex === -1) break;
const chunk = children.slice(0, splitIndex);
chunks.push(chunk);
children = children.slice(splitIndex + 1);
}
chunks.push(children);
return chunks;
}
desugar_split(children, split_type, next) {
const chunks = this.split_children(children, split_type);
if (chunks.length === 1) {
return next(children);
}
// collect args of stack function
const args = chunks
.map((chunk) => {
if (!chunk.length) {
return; // useful for things like "$ s bd $ s hh*8" (first chunk is empty)
}
if (chunk.length === 1) {
// chunks of one element can be added to the stack as is
return chunk[0];
}
// chunks of multiple args
chunk = next(chunk);
return { type: 'list', children: chunk };
})
.filter(Boolean); // ignore empty chunks
return [{ type: 'plain', value: split_type }, ...args];
}
// prevents to get a list, e.g. ((x y)) => (x y)
unwrap_children(children) {
if (children.length === 1) {
return children[0].children;
}
return children;
}
desugar_ops(children) {
while (true) {
let opIndex = children.findIndex((child) => child.type === 'op');
if (opIndex === -1) break;
const op = { type: 'plain', value: children[opIndex].value };
if (opIndex === children.length - 1) {
//throw new Error(`cannot use operator as last child.`);
children[opIndex] = op; // ignore operator if last child.. e.g. "note [c -]"
continue;
}
if (opIndex === 0) {
// regular function call (assuming each operator exists as function)
children[opIndex] = op;
continue;
}
// convert infix to prefix notation
const left = children[opIndex - 1];
const right = children[opIndex + 1];
if (left.type === 'pipe') {
// "x !* 2" => (* 2 x)
children[opIndex] = op;
continue;
}
// some careful error handling
if (left.type === 'op') {
throw new Error(`got 2 ops in a row: "${left.value}${op.value}"`);
}
if (right.type === 'op') {
let err = `got 2 ops in a row: "${op.value}${right.value}"`;
if (op.value === '-') {
// yes i know this file is not supposed to know about rests x.X
err += '. you probably want a rest, which is "_" in mondo!';
}
throw new Error(err);
}
const call = { type: 'list', children: [op, right, left] };
// insert call while keeping other siblings
children = [...children.slice(0, opIndex - 1), call, ...children.slice(opIndex + 2)];
children = this.unwrap_children(children);
}
return children;
}
get_lambda(args, children) {
// (.fast 2) = (fn (_) (fast _ 2))
children = this.desugar(children);
const body = children.length === 1 ? children[0] : { type: 'list', children };
return [{ type: 'plain', value: 'fn' }, { type: 'list', children: args }, body];
}
// returns location range of given ast (even if desugared)
get_range(ast, range = [Infinity, 0]) {
let union = (a, b) => [Math.min(a[0], b[0]), Math.max(a[1], b[1])];
if (ast.loc) {
return union(range, ast.loc);
}
if (ast.type !== 'list') {
return range;
}
return ast.children.reduce((range, child) => {
const childrange = this.get_range(child, range);
return union(range, childrange);
}, range);
}
errorhead(ast) {
return `[mondo ${this.get_range(ast)?.join(':') || '?'}]`;
}
// returns original user code where the given ast originates (even if desugared)
get_code_snippet(ast) {
const [min, max] = this.get_range(ast);
return this.code.slice(min - this.offset, max - this.offset);
}
desugar_pipes(children) {
let chunks = this.split_children(children, 'pipe');
while (chunks.length > 1) {
let [left, right, ...rest] = chunks;
if (!left.length) {
const arg = { type: 'plain', value: '_' };
return this.get_lambda([arg], [arg, ...children]);
}
// s jazz hh.fast 2 => (fast 2 (s jazz hh))
const call = left.length > 1 ? { type: 'list', children: left } : left[0];
chunks = [[...right, call], ...rest];
}
// return next(chunks[0]);
return chunks[0];
}
parse_pair(open_type, close_type) {
const begin = this.tokens[0].loc?.[0];
this.consume(open_type);
const children = [];
while (this.tokens[0]?.type !== close_type) {
children.push(this.parse_expr());
}
const end = this.tokens[0].loc?.[1];
this.consume(close_type);
const node = { type: 'list', children };
if (begin !== undefined) {
node.loc = [begin, end];
node.raw = this.code.slice(begin, end);
}
return node;
}
desugar(children, type) {
// if type is given, the first element is expected to contain it as plain value
// e.g. with (square a b, c), we want to split (a b, c) and ignore "square"
children = type ? children.slice(1) : children;
children = this.desugar_split(children, 'stack', (children) =>
this.desugar_split(children, 'or', (children) => {
// chunks of multiple args
if (type) {
// the type we've removed before splitting needs to be added back
children = [{ type: 'plain', value: type }, ...children];
}
children = this.desugar_ops(children);
// children = this.desugar_pipes(children, (children) => this.desugar_dollars(children));
children = this.desugar_pipes(children);
return children;
}),
);
return children;
}
parse_list() {
let node = this.parse_pair('open_list', 'close_list');
node.children = this.desugar(node.children);
return node;
}
parse_angle() {
let node = this.parse_pair('open_angle', 'close_angle');
node.children.unshift({ type: 'plain', value: 'angle' });
node.children = this.desugar(node.children, 'angle');
return node;
}
parse_square() {
let node = this.parse_pair('open_square', 'close_square');
node.children.unshift({ type: 'plain', value: 'square' });
node.children = this.desugar(node.children, 'square');
return node;
}
parse_curly() {
let node = this.parse_pair('open_curly', 'close_curly');
node.children.unshift({ type: 'plain', value: 'curly' });
node.children = this.desugar(node.children, 'curly');
return node;
}
consume(type) {
// shift removes first element and returns it
const token = this.tokens.shift();
if (token.type !== type) {
throw new Error(`expected token type ${type}, got ${token.type}`);
}
return token;
}
get_locations(code, offset = 0) {
let walk = (ast, locations = []) => {
if (ast.type === 'list') {
return ast.children.forEach((child) => walk(child, locations));
}
if (ast.loc) {
locations.push(ast.loc);
}
};
const ast = this.parse(code, offset);
let locations = [];
walk(ast, locations);
return locations;
}
}
export function printAst(ast, compact = false, lvl = 0) {
const br = compact ? '' : '\n';
const spaces = compact ? '' : Array(lvl).fill(' ').join('');
if (ast.type === 'list') {
return `${lvl ? br : ''}${spaces}(${ast.children.map((child) => printAst(child, compact, lvl + 1)).join(' ')}${
ast.children.find((child) => child.type === 'list') ? `${br}${spaces})` : ')'
}`;
}
return `${ast.value}`;
}
// lisp runner
export class MondoRunner {
constructor({ evaluator } = {}) {
this.parser = new MondoParser();
this.evaluator = evaluator;
this.assert(typeof evaluator === 'function', `expected an evaluator function to be passed to new MondoRunner`);
}
// a helper to check conditions and throw if they are not met
assert(condition, error) {
if (!condition) {
throw new Error(error);
}
}
run(code, scope, offset = 0) {
const ast = this.parser.parse(code, offset);
//console.log(printAst(ast));
return this.evaluate(ast, scope);
}
evaluate_let(ast, scope) {
// (let ((x 3) (y 4)) ...body)
// = ((fn (x y) ...body) 3 4)
const defs = ast.children[1].children;
const args = defs.map((pair) => pair.children[0]);
const vals = defs.map((pair) => pair.children[1]);
const body = ast.children.slice(2);
const lambda = {
type: 'list',
children: [{ type: 'plain', value: 'fn' }, { type: 'list', children: args }, ...body],
};
return this.evaluate({ type: 'list', children: [lambda, ...vals] }, scope);
}
evaluate_def(ast, scope) {
// function definition special form?
if (ast.children[1].type === 'list') {
// (def (add a b) (+ a b))
// => (def add (fn (a b) (+ a b)) )
const args = ast.children[1].children.slice(1);
const lambda = {
// lambda
type: 'list',
children: [
{ type: 'plain', value: 'fn' },
{ type: 'list', children: args },
...ast.children.slice(2), // body
],
};
// we mutate to make sure the old ast wont make a mess later
ast.children[1] = ast.children[1].children[0];
ast.children[2] = lambda;
ast.children = ast.children.slice(0, 3); // throw away rest
}
// (def name body)
if (ast.children.length !== 3) {
throw new Error(`expected "def" to have 3 children, but got ${ast.children.length}`);
}
const name = ast.children[1].value;
const body = this.evaluate(ast.children[2], scope);
scope[name] = body;
// def with fall through
}
evaluate_match(ast, scope) {
// (match (p1 e1) (p2 e2) ... (pn en))
// = cond in lisp
if (ast.children.length < 2) {
return;
}
const [_, ...body] = ast.children;
for (let i = 0; i < body.length; ++i) {
const [predicate, exp] = body[i].children;
if (predicate.value === 'else') {
return this.evaluate(exp, scope);
}
const outcome = this.evaluate(predicate, scope);
if (outcome) {
return this.evaluate(exp, scope);
}
}
return undefined; // nothing was matched
}
evaluate_if(ast, scope) {
// if is a special case of match
if (ast.children.length !== 4) {
return;
}
// (if predicate consequent alternative)
const [_, predicate, consequent, alternative] = ast.children;
// (match (predicate consequent) (else alternative))
const matcher = {
type: 'list',
children: [
{ type: 'plain', value: 'match' },
{ type: 'list', children: [predicate, consequent] },
{ type: 'list', children: [{ type: 'plain', value: 'else' }, alternative] },
],
};
return this.evaluate_match(matcher, scope);
}
evaluate_lambda(ast, scope) {
// (fn (_) (ply 2 _)
// ^args ^ body
const [_, formalArgs, ...body] = ast.children;
return (...args) => {
const params = Object.fromEntries(formalArgs.children.map((arg, i) => [arg.value, args[i]]));
const closure = {
...scope,
...params,
};
// body can have multiple expressions
const res = body.map((exp) => this.evaluate(exp, closure));
// last expression is the return value
return res[res.length - 1];
};
}
evaluate_list(ast, scope) {
// evaluate all children before evaluating list (dont mutate!!!)
const args = ast.children
.filter((child) => child.type !== 'comment') // ignore comments
.map((arg) => this.evaluate(arg, scope));
const node = { type: 'list', children: args };
return this.evaluator(node, scope);
}
evaluate_leaf(ast, scope) {
if (ast.type === 'number') {
ast.value = Number(ast.value);
} else if (['quotes_double', 'quotes_single'].includes(ast.type)) {
ast.value = ast.value.slice(1, -1);
ast.type = 'string';
}
return this.evaluator(ast, scope);
}
evaluate(ast, scope = {}) {
if (ast.type !== 'list') {
return this.evaluate_leaf(ast, scope);
}
const name = ast.children[0]?.value;
if (name === 'fn') {
return this.evaluate_lambda(ast, scope);
}
if (name === 'match') {
return this.evaluate_match(ast, scope);
}
if (name === 'if') {
return this.evaluate_if(ast, scope);
}
if (name === 'let') {
return this.evaluate_let(ast, scope);
}
if (name === 'def') {
this.evaluate_def(ast, scope);
}
return this.evaluate_list(ast, scope);
}
}
+37
View File
@@ -0,0 +1,37 @@
{
"name": "mondolang",
"version": "1.1.1",
"description": "a language for functional composition that translates to js",
"main": "mondo.mjs",
"type": "module",
"publishConfig": {
"main": "dist/mondo.mjs"
},
"scripts": {
"test": "vitest run",
"bench": "vitest bench",
"build": "vite build",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tidalcycles/strudel.git"
},
"keywords": [
"tidalcycles",
"strudel",
"pattern",
"livecoding",
"algorave"
],
"author": "Felix Roos <flix91@gmail.com>",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/tidalcycles/strudel/issues"
},
"homepage": "https://github.com/tidalcycles/strudel/blob/main/packages/mondo/README.md",
"devDependencies": {
"vite": "^6.0.11",
"vitest": "^3.0.4"
}
}
+978
View File
@@ -0,0 +1,978 @@
/*
mondo.test.mjs - <short description TODO>
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/mini/test/mini.test.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 { describe, expect, it } from 'vitest';
import { MondoParser, printAst, MondoRunner } from '../mondo.mjs';
const parser = new MondoParser();
const p = (code) => parser.parse(code, -1);
describe('mondo tokenizer', () => {
const parser = new MondoParser();
it('should tokenize with locations', () =>
expect(
parser
.tokenize('(one two three)')
.map((t) => t.value + '=' + t.loc.join('-'))
.join(' '),
).toEqual('(=0-1 one=1-4 two=5-8 three=9-14 )=14-15'));
// it('should parse with loangleions', () => expect(parser.parse('(one two three)')).toEqual());
it('should get loangleions', () =>
expect(parser.get_locations('s bd rim')).toEqual([
[0, 1],
[2, 4],
[5, 8],
]));
});
describe('mondo s-expressions parser', () => {
it('should parse an empty string', () => expect(p('')).toEqual({ type: 'list', children: [] }));
it('should parse a single item', () =>
expect(p('a')).toEqual({ type: 'list', children: [{ type: 'plain', value: 'a' }] }));
it('should parse an empty list', () => expect(p('()')).toEqual({ type: 'list', children: [] }));
it('should parse a list with 1 item', () =>
expect(p('(a)')).toEqual({ type: 'list', children: [{ type: 'plain', value: 'a' }] }));
it('should parse a list with 2 items', () =>
expect(p('(a b)')).toEqual({
type: 'list',
children: [
{ type: 'plain', value: 'a' },
{ type: 'plain', value: 'b' },
],
}));
it('should parse a list with 2 items', () =>
expect(p('(a (b c))')).toEqual({
type: 'list',
children: [
{ type: 'plain', value: 'a' },
{
type: 'list',
children: [
{ type: 'plain', value: 'b' },
{ type: 'plain', value: 'c' },
],
},
],
}));
it('should parse numbers', () =>
expect(p('(1 .2 1.2 10 22.3)')).toEqual({
type: 'list',
children: [
{ type: 'number', value: '1' },
{ type: 'number', value: '.2' },
{ type: 'number', value: '1.2' },
{ type: 'number', value: '10' },
{ type: 'number', value: '22.3' },
],
}));
it('should parse comments', () =>
expect(p('a // hello')).toEqual({
type: 'list',
children: [
{ type: 'plain', value: 'a' },
{ type: 'comment', value: '// hello' },
],
}));
});
let desguar = (a) => {
return printAst(parser.parse(a), true);
};
describe('mondo sugar', () => {
it('should desugar []', () => expect(desguar('[a b c]')).toEqual('(square a b c)'));
it('should desugar [] nested', () => expect(desguar('[a [b c] d]')).toEqual('(square a (square b c) d)'));
it('should desugar <>', () => expect(desguar('<a b c>')).toEqual('(angle a b c)'));
it('should desugar <> nested', () => expect(desguar('<a <b c> d>')).toEqual('(angle a (angle b c) d)'));
it('should desugar mixed [] <>', () => expect(desguar('[a <b c>]')).toEqual('(square a (angle b c))'));
it('should desugar mixed <> []', () => expect(desguar('<a [b c]>')).toEqual('(angle a (square b c))'));
it('should desugar #', () => expect(desguar('s jazz # fast 2')).toEqual('(fast 2 (s jazz))'));
it('should desugar # square', () => expect(desguar('[bd cp # fast 2]')).toEqual('(fast 2 (square bd cp))'));
it('should desugar # twice', () => expect(desguar('s jazz # fast 2 # slow 2')).toEqual('(slow 2 (fast 2 (s jazz)))'));
it('should desugar # nested', () => expect(desguar('(s cp # fast 2)')).toEqual('(fast 2 (s cp))'));
it('should desugar # within []', () => expect(desguar('[bd cp # fast 2]')).toEqual('(fast 2 (square bd cp))'));
it('should desugar # within , within []', () =>
expect(desguar('[bd cp # fast 2, x]')).toEqual('(stack (fast 2 (square bd cp)) x)'));
// it('should desugar .(.', () => expect(desguar('[jazz hh.(.fast 2)]')).toEqual('(square jazz (fast 2 hh))'));
it('should desugar , |', () => expect(desguar('[bd, hh | oh]')).toEqual('(stack bd (or hh oh))'));
it('should desugar , | of []', () =>
expect(desguar('[bd, hh | [oh rim]]')).toEqual('(stack bd (or hh (square oh rim)))'));
it('should desugar , square', () => expect(desguar('[bd, hh]')).toEqual('(stack bd hh)'));
it('should desugar , square 2', () => expect(desguar('[bd, hh oh]')).toEqual('(stack bd (square hh oh))'));
it('should desugar , square 3', () =>
expect(desguar('[bd cp, hh oh]')).toEqual('(stack (square bd cp) (square hh oh))'));
it('should desugar , angle', () => expect(desguar('<bd, hh>')).toEqual('(stack bd hh)'));
it('should desugar , angle 2', () => expect(desguar('<bd, hh oh>')).toEqual('(stack bd (angle hh oh))'));
it('should desugar , angle 3', () =>
expect(desguar('<bd cp, hh oh>')).toEqual('(stack (angle bd cp) (angle hh oh))'));
it('should desugar , ()', () => expect(desguar('(s bd, s cp)')).toEqual('(stack (s bd) (s cp))'));
it('should desugar * /', () => expect(desguar('[a b*2 c d/3 e]')).toEqual('(square a (* 2 b) c (/ 3 d) e)'));
it('should desugar []*x', () => expect(desguar('[a [b c]*3]')).toEqual('(square a (* 3 (square b c)))'));
it('should desugar []*<x y>', () => expect(desguar('[a b*<2 3> c]')).toEqual('(square a (* (angle 2 3) b) c)'));
it('should desugar x:y', () => expect(desguar('x:y')).toEqual('(: y x)'));
it('should desugar x:y:z', () => expect(desguar('x:y:z')).toEqual('(: z (: y x))'));
it('should desugar x:y*x', () => expect(desguar('bd:0*2')).toEqual('(* 2 (: 0 bd))'));
it('should desugar a..b', () => expect(desguar('0..2')).toEqual('(.. 2 0)'));
/* it('should desugar x $ y', () => expect(desguar('x $ y')).toEqual('(x y)'));
it('should desugar x $ y z', () => expect(desguar('x $ y z')).toEqual('(x (y z))'));
it('should desugar x $ y . z', () => expect(desguar('x $ y . z')).toEqual('(z (x y))')); */
it('should desugar README example', () =>
expect(desguar('s [bd hh*2 (cp # crush 4) <mt ht lt>] # speed .8')).toEqual(
'(speed .8 (s (square bd (* 2 hh) (crush 4 cp) (angle mt ht lt))))',
));
it('should desugar (#)', () => expect(desguar('(#)')).toEqual('(fn (_) _)'));
it('should desugar lambda', () => expect(desguar('(# fast 2)')).toEqual('(fn (_) (fast 2 _))'));
it('should desugar lambda call', () => expect(desguar('((# mul 2) 2)')).toEqual('((fn (_) (mul 2 _)) 2)'));
it('should desugar lambda with pipe', () =>
expect(desguar('(# fast 2 # room 1)')).toEqual('(fn (_) (room 1 (fast 2 _)))'));
/* const lambda = parser.parse('(lambda (_) (fast 2 _))');
const target = { type: 'plain', value: 'xyz' };
it('should desugar_lambda', () =>
expect(printAst(parser.desugar_lambda(lambda.children, target))).toEqual('(fast 2 xyz)')); */
});
describe('mondo arithmetic', () => {
let multi =
(op) =>
(init, ...rest) =>
rest.reduce((acc, arg) => op(acc, arg), init);
let lib = {
'+': multi((a, b) => a + b),
add: multi((a, b) => a + b),
'-': multi((a, b) => a - b),
sub: multi((a, b) => a - b),
'*': multi((a, b) => a * b),
'/': multi((a, b) => a / b),
mod: multi((a, b) => a % b),
eq: (a, b) => a === b,
lt: (a, b) => a < b,
gt: (a, b) => a > b,
and: (a, b) => a && b,
or: (a, b) => a || b,
not: (a) => !a,
run: (...args) => args[args.length - 1],
def: () => 0,
sin: Math.sin,
cos: Math.cos,
PI: Math.PI,
cons: (a, b) => [a, ...(Array.isArray(b) ? b : [b])],
car: (pair) => pair[0],
cdr: (pair) => pair.slice(1),
list: (...items) => items,
nil: [],
isnull: (items) => items.length === 0,
concat: (...msgs) => msgs.join(''),
error: (...msgs) => {
throw new Error(msgs.join(' '));
},
};
function evaluator(node, scope) {
if (node.type !== 'list') {
// is leaf
return scope[node.value] ?? lib[node.value] ?? node.value;
}
// is list
const [fn, ...args] = node.children;
if (typeof fn !== 'function') {
throw new Error(`"${fn}": expected function, got ${typeof fn} "${fn}"`);
}
return fn(...args);
}
const runner = new MondoRunner({ evaluator });
let evaluate = (exp, scope) => runner.run(`run ${exp}`, scope);
let pretty = (exp) => printAst(runner.parser.parse(exp), false);
//it('should eval nested expression', () => expect(runner.run('add 1 (mul 2 PI)').toFixed(2)).toEqual('7.28'));
it('eval number', () => expect(evaluate('2')).toEqual(2));
it('eval string', () => expect(evaluate('abc')).toEqual('abc'));
it('eval list', () => expect(evaluate('(+ 1 2)')).toEqual(3));
it('eval nested list', () => expect(evaluate('(+ 1 (+ 2 3))')).toEqual(6));
it('def number', () => expect(evaluate('(def a 2) a')).toEqual(2));
it('def + ref number', () => expect(evaluate('(def a 2) (* a a)')).toEqual(4));
it('def + call lambda', () => expect(evaluate('(def sqr (fn (x) (* x x))) (sqr 3)')).toEqual(9));
// sicp
it('sicp 8.1', () => expect(evaluate('(+ 137 349)')).toEqual(486));
it('sicp 8.2', () => expect(evaluate('(- 1000 334)')).toEqual(666));
it('sicp 8.3', () => expect(evaluate('(* 5 99)')).toEqual(495));
it('sicp 8.4', () => expect(evaluate('(/ 10 5)')).toEqual(2));
it('sicp 8.5', () => expect(evaluate('(+ 2.7 10)')).toEqual(12.7));
it('sicp 9.1', () => expect(evaluate('(+ 21 35 12 7)')).toEqual(75));
it('sicp 9.2', () => expect(evaluate('(* 25 4 12)')).toEqual(1200));
it('sicp 9.3', () => expect(evaluate('(+ (* 3 5) (- 10 6))')).toEqual(19));
it('sicp 9.4', () =>
expect(pretty('(+ (* 3 (+ (* 2 4) (+ 3 5))) (+ (- 10 7) 6))')).toEqual(`(+
(* 3
(+
(* 2 4)
(+ 3 5)
)
)
(+
(- 10 7) 6
)
)`)); // this is not exactly pretty printing by convention..
let scope = {};
it('sicp 11.1', () => expect(evaluate('(def size 2) (* 5 size)', scope)).toEqual(10));
it('sicp 11.2', () =>
expect(evaluate('(def pi 3.14159) (def radius 10) (* pi (* radius radius))', scope)).toEqual(314.159));
it('sicp 11.3', () => expect(evaluate('(def circumference (* 2 pi radius))', scope)).toEqual(0));
it('sicp 11.4', () => expect(evaluate('circumference', scope)).toEqual(62.8318));
it('sicp 13.1', () => expect(evaluate('(* (+ 2 (* 4 6)) (+ 3 5 7))')).toEqual(390));
it('sicp 16.1', () => expect(evaluate('(def (square x) (* x x))', scope)).toEqual(0));
// it('sicp 16.1', () => expect(evaluate('(def (square x) (* x x))', scope)).toEqual(0));
it('sicp 17.1', () => expect(evaluate('(square 21)', scope)).toEqual(441));
it('sicp 17.2', () => expect(evaluate('(square (+ 2 5))', scope)).toEqual(49));
it('sicp 17.3', () => expect(evaluate('(square (square 3))', scope)).toEqual(81));
it('sicp 17.4', () => expect(evaluate(`(def (sumofsquares x y) (+ (square x) (square y)))`, scope)).toEqual(0));
it('sicp 17.5', () => expect(evaluate(`(sumofsquares 3 4)`, scope)).toEqual(25));
it('sicp 17.6', () => expect(evaluate(`(def (f a) (sumofsquares (+ a 1) (* a 2))) (f 5)`, scope)).toEqual(136));
it('sicp 21.1', () => expect(evaluate(`(sumofsquares (+ 5 1) (* 5 2))`, scope)).toEqual(136));
it('sicp 22.1', () =>
expect(
evaluate(
`(def (abs x)
(match
((gt x 0) x)
((eq x 0) 0)
((lt x 0) (- 0 x))
))`, // sicp was doing (- x), which doesnt work with our -
scope,
),
).toEqual(0));
it('sicp gt1', () => expect(evaluate(`(gt -12 0)`, scope)).toEqual(false));
it('sicp gt2', () => expect(evaluate(`(gt 0 -12)`, scope)).toEqual(true));
it('sicp lt1', () => expect(evaluate(`(lt -12 0)`, scope)).toEqual(true));
it('sicp lt2', () => expect(evaluate(`(lt 0 -12)`, scope)).toEqual(false));
it('sicp 24.1', () => expect(evaluate(`(abs (- 3))`, scope)).toEqual(3));
it('sicp 24.2', () => expect(evaluate(`(abs (+ 3))`, scope)).toEqual(3));
it('sicp 24.3', () => expect(evaluate(`(abs -12)`, scope)).toEqual(12));
it('sicp 24.4', () => expect(evaluate(`(def (abs x) (if (lt x 0) (- 0 x) x))`, scope)).toEqual(0));
it('sicp 24.5', () => expect(evaluate(`(abs -13)`, scope)).toEqual(13));
it('sicp 25.1', () => expect(evaluate(`(and (gt 6 5) (lt 6 10))`, scope)).toEqual(true));
it('sicp 25.2', () => expect(evaluate(`(and (gt 4 5) (lt 6 10))`, scope)).toEqual(false));
it('sicp ex1.1.1', () => expect(evaluate(`(def a 3)`, scope)).toEqual(0));
it('sicp ex1.1.2', () => expect(evaluate(`(def b (+ a 1))`, scope)).toEqual(0));
it('sicp ex1.1.3', () => expect(evaluate(`(+ a b (* a b))`, scope)).toEqual(19));
it('sicp ex1.1.4', () => expect(evaluate(`(if (and (gt b a) (lt b (* a b))) b a)`, scope)).toEqual(4));
it('sicp ex1.1.5', () => expect(evaluate(`(match ((eq a 4) 6) ((eq b 4) (+ 6 7 a)) (else 25))`, scope)).toEqual(16));
it('sicp ex1.1.6', () => expect(evaluate(`(+ 2 (if (gt b a) b a))`, scope)).toEqual(6));
it('sicp ex1.1.7', () =>
expect(evaluate(`(* (match ((gt a b) a) ((lt a b) b) (else -1)) (+ a 1))`, scope)).toEqual(16));
// .. cant use "+" and "-" as standalone expressions, because they are parsed as operators...
it('sicp ex1.4.1', () => expect(evaluate(`(def (foo a b) ((if (gt b 0) add sub) a b))`, scope)).toEqual(0));
it('sicp ex1.4.1', () => expect(evaluate(`(foo 3 1)`, scope)).toEqual(4));
it('sicp ex1.4.2', () => expect(evaluate(`(foo 3 -1)`, scope)).toEqual(4));
// 1.1.7 Example: Square Roots by Newtons Method
it('sicp 30.1', () =>
expect(evaluate(`(def (goodenuf guess x) (lt (abs (- (square guess) x)) 0.001))`, scope)).toEqual(0));
it('sicp 30.2', () => expect(evaluate(`(goodenuf 1 1.001)`, scope)).toEqual(true));
it('sicp 30.3', () => expect(evaluate(`(goodenuf 1 1.002)`, scope)).toEqual(false));
it('sicp 30.4', () => expect(evaluate(`(def (average x y) (/ (+ x y) 2))`, scope)).toEqual(0));
it('sicp 30.5', () => expect(evaluate(`(average 18 20)`, scope)).toEqual(19));
it('sicp 30.6', () => expect(evaluate(`(def (improve guess x) (average guess (/ x guess)))`, scope)).toEqual(0));
it('sicp 31.1', () =>
expect(
evaluate(
`(def (sqrtiter guess x) (if (goodenuf guess x)
guess
(sqrtiter (improve guess x) x)))`,
scope,
),
).toEqual(0));
it('sicp 31.2', () => expect(evaluate(`(def (sqrt x) (sqrtiter 1.0 x))`, scope)).toEqual(0));
it('sicp 31.3', () => expect(evaluate(`(sqrt 9)`, scope)).toEqual(3.00009155413138));
it('sicp 31.4', () => expect(evaluate(`(sqrt (+ 100 37))`, scope)).toEqual(11.704699917758145));
// eslint-disable-next-line no-loss-of-precision
it('sicp 31.5', () => expect(evaluate(`(sqrt (+ (sqrt 2) (sqrt 3)))`, scope)).toEqual(1.77392790232078925));
it('sicp 31.6', () => expect(evaluate(`(square (sqrt 1000))`, scope)).toEqual(1000.000369924366));
// lexical scoping
it('sicp 39.1', () =>
expect(
evaluate(
`
(def (sqrt x)
(def (goodenough guess)
(lt (abs (- (square guess) x)) 0.001))
(def (improve guess)
(average guess (/ x guess)))
(def (sqrt-iter guess)
(if (goodenough guess) guess (sqrt-iter (improve guess))))
(sqrtiter 1.0))
`,
scope,
),
).toEqual(0));
// recursive fac
it('sicp 41.1', () => expect(evaluate(`(def (fac n) (if (eq n 1) 1 (* n (fac (- n 1)))))`, scope)).toEqual(0));
it('sicp 41.2', () => expect(evaluate(`(fac 4)`, scope)).toEqual(24));
// iterative fac
it('sicp 41.3', () =>
expect(
evaluate(
`
(def (factorial n) (factiter 1 1 n))
(def (factiter product counter maxcount)
(if (gt counter maxcount)
product
(factiter (* counter product)
(+ counter 1)
maxcount)))
`,
scope,
),
).toEqual(0));
it('sicp 41.4', () => expect(evaluate(`(fac 4)`, scope)).toEqual(24));
// 46.1
/* (def (+ a b)
(if (= a 0) b (inc (+ (dec a) b))))
(def (+ a b)
(if (= a 0) b (+ (dec a) (inc b)))) */
// Exercise 1.10
// Ackermanns function
it('sicp 47.1', () =>
expect(
evaluate(
`
(def (A x y) (match ((eq y 0) 0)
((eq x 0) (* 2 y))
((eq y 1) 2)
(else (A (- x 1) (A x (- y 1))))))
`,
scope,
),
).toEqual(0));
it('sicp 47.2', () => expect(evaluate(`(A 1 10)`, scope)).toEqual(1024));
it('sicp 47.3', () => expect(evaluate(`(A 2 4)`, scope)).toEqual(65536));
it('sicp 47.4', () => expect(evaluate(`(A 3 3)`, scope)).toEqual(65536));
it('sicp 47.5', () =>
expect(
evaluate(
`
(def (f n) (A 0 n))
(def (g n) (A 1 n)))
(def (h n) (A 2 n))
(def (k n) (* 5 n n))
`,
scope,
),
).toEqual(0));
// Tree Recursion
// recursive process
it('sicp 48.1', () =>
expect(
evaluate(
`
(def (fib n) (match ((eq n 0) 0) ((eq n 1) 1)
(else (+ (fib (- n 1)) (fib (- n 2))))))
(fib 7)
`,
scope,
),
).toEqual(13));
// iterative process
it('sicp 48.2', () =>
expect(
evaluate(
`
(def (fib n) (fibiter 1 0 n))
(def (fibiter a b count) (if (eq count 0)
b
(fibiter (+ a b) a (- count 1))))
(fib 7)
`,
scope,
),
).toEqual(13));
// example: counting change
it('sicp 52.2', () =>
expect(
evaluate(
`
(def (countchange amount) (cc amount 5))
(def (cc amount kindsofcoins)
(match
((eq amount 0) 1)
((or (lt amount 0) (eq kindsofcoins 0)) 0)
(else (+
(cc amount (- kindsofcoins 1))
(cc (- amount (firstdenomination kindsofcoins)) kindsofcoins)))))
(def (firstdenomination kindsofcoins)
(match
((eq kindsofcoins 1) 1)
((eq kindsofcoins 2) 5)
((eq kindsofcoins 3) 10)
((eq kindsofcoins 4) 25)
((eq kindsofcoins 5) 50)))
(countchange 100)
`,
scope,
),
).toEqual(292));
// todo: pascals triangle
it('sicp 57.1', () =>
expect(
evaluate(
`
(def (cube x) (* x x x))
(def (p x) (sub (* 3 x) (* 4 (cube x))))
(def (sine angle)
(if (not (gt (abs angle) 0.1)) angle
(p (sine (/ angle 3.0)))))
(sine 12.15)
`,
scope,
),
).toEqual(-0.39980345741334));
// exponentiation recursive
it('sicp 57.2', () =>
expect(
evaluate(
`
(def (expt b n) (if (eq n 0) 1 (* b (expt b (- n 1)))))
(expt 2 4)
`,
scope,
),
).toEqual(16));
// exponentiation iterative
it('sicp 58.1b', () =>
expect(
evaluate(
`
(def (expt b n) (exptiter b n 1))
(def (exptiter b counter product) (if (eq counter 0)
product
(exptiter b (- counter 1) (* b product))))
(expt 2 5)
`,
scope,
),
).toEqual(32));
// exponentiation fast
it('sicp 58.2', () =>
expect(
evaluate(
`
(def (fastexpt b n) (match ((eq n 0) 1)
((iseven n) (square (fastexpt b (/ n 2)))) (else (* b (fastexpt b (- n 1))))))
(def (iseven n)
(eq (mod n 2) 0))
(fastexpt 2 5)
`,
scope,
),
).toEqual(32));
// * = repeated addition
it('sicp 60.1', () =>
expect(
evaluate(
`(def (mult a b) (if (eq b 0)
0
(+ a (* a (- b 1)))))
(mult 3 15)
`,
),
).toEqual(45));
// gcd / euclid
it('sicp 63.1', () =>
expect(
evaluate(
`(def (gcd a b) (if (eq b 0)
a
(gcd b (mod a b))))
(gcd 20 6)
`,
scope,
),
).toEqual(2));
// 65 smallest divisor
// 67 fermat test
// ....
// higher order procedures
it('sicp 77.1', () =>
expect(
evaluate(
`
(def (sum term a next b)
(if (gt a b) 0 (+ (term a)
(sum term (next a) next b))))
`,
scope,
),
).toEqual(0));
it('sicp 78.1', () =>
expect(
evaluate(
`
(def (inc n) (+ n 1))
(def (cube a) (* a a a))
(def (sumcubes a b)
(sum cube a inc b))
(sumcubes 1 10)
`,
scope,
),
).toEqual(3025));
it('sicp 78.2', () =>
expect(
evaluate(
`
(def (identity x) x)
(def (sumintegers a b)
(sum identity a inc b))
(sumintegers 1 10)
`,
scope,
),
).toEqual(55));
// pisum
it('sicp 79.1', () =>
expect(
evaluate(
`
(def (pisum a b)
(def (piterm x)
(/ 1.0 (* x (+ x 2))))
(def (pinext x) (+ x 4))
(sum piterm a pinext b))
(* 8 (pisum 1 1000))
`,
scope,
),
).toEqual(3.139592655589783));
// integral
it('sicp 79.2', () =>
expect(
evaluate(
`
(def (integral f a b dx)
(def (adddx x) (+ x dx))
(* (sum f (+ a (/ dx 2.0)) adddx b) dx))
(integral cube 0 1 0.01)
`,
scope,
),
).toEqual(0.24998750000000042));
// maximum callstack...
//it('sicp 79.3', () => expect(evaluate(`(integral cube 0 1 0.001)`, scope)).toEqual(0.249999875000001));
//lambdas
it('sicp 83.1', () => expect(evaluate(`((fn (x) (+ x 4)) 5)`)).toEqual(9));
it('sicp 83.2', () =>
expect(
evaluate(
`
(def (pisum a b)
(sum (fn (x) (/ 1.0 (* x (+ x 2))))
a
(fn (x) (+ x 4))
b))
(* 8 (pisum 1 1000))
`,
scope,
),
).toEqual(3.139592655589783));
it('sicp 83.3', () =>
expect(
evaluate(
`
(def (integral f a b dx)
(* (sum f
(+ a (/ dx 2.0))
(fn (x) (+ x dx))
b)
dx))
(integral cube 0 1 0.01)
`,
scope,
),
).toEqual(0.24998750000000042));
it('sicp 84.1', () => expect(evaluate(`((fn (x y z) (+ x y (square z))) 1 2 3)`, scope)).toEqual(12));
// let expressions
it('sicp 87.1', () =>
expect(
evaluate(
`
(+ (let ((x 3))
(+ x (* x 10))) x)
`,
{ x: 5 },
),
).toEqual(38));
it('sicp 87.2', () =>
expect(
evaluate(
`
(let ((x 3)
(y (+ x 2)))
(* x y))
`,
{ x: 2 },
),
).toEqual(12));
it('sicp 88.1', () =>
expect(
evaluate(
`
(def (f g) (g 2))
(f square)
`,
scope,
),
).toEqual(4));
it('sicp 88.2', () =>
expect(
evaluate(
`
(def (f g) (g 2))
(f (fn (z) (* z (+ z 1))))
`,
scope,
),
).toEqual(6));
// Finding roots of equations by the half-interval method
it('sicp 89.1', () =>
expect(
evaluate(
`
(def (search f negpoint pospoint)
(let ((midpoint (average negpoint pospoint)))
(if (closeenough negpoint pospoint)
midpoint
(let ((testvalue (f midpoint)))
(match ((positive testvalue)
(search f negpoint midpoint))
((negative testvalue)
(search f midpoint pospoint))
(else midpoint))))))
(def (closeenough x y) (lt (abs (- x y)) 0.001))
(def (negative x) (lt x 0))
(def (positive x) (gt x 0))
(def (halfintervalmethod f a b) (let ((avalue (f a))
(bvalue (f b)))
(match ((and (negative avalue) (positive bvalue))
(search f a b))
((and (negative bvalue) (positive avalue))
(search f b a)) (else
(error "Values are not of opposite sign" a b)))))
(halfintervalmethod sin 2.0 4.0)
`,
scope,
),
).toEqual(3.14111328125));
it('sicp 89.1', () =>
expect(evaluate(`(halfintervalmethod (fn (x) (- (* x x x) (* 2 x) 3)) 1.0 2.0)`, scope)).toEqual(1.89306640625));
// Finding fixed points of functions
it('sicp 92.1', () =>
expect(
evaluate(
`
(def tolerance 0.00001)
(def (fixedpoint f first-guess)
(def (closeenough v1 v2) (lt (abs (- v1 v2)) tolerance))
(def (try guess)
(let ((next (f guess)))
(if (closeenough guess next) next (try next))))
(try first-guess))
(fixedpoint cos 1.0)
`,
scope,
),
).toEqual(0.7390822985224023));
it('sicp 93.1', () =>
expect(evaluate(`(fixedpoint (fn (y) (+ (sin y) (cos y))) 1.0)`, scope)).toEqual(1.2587315962971173));
// Maximum call stack size exceeded (expected)
/* it('sicp 93.2', () =>
expect(evaluate(`(def (sqrt x) (fixedpoint (fn (y) (/ x y)) 1.0)) (sqrt 4)`, scope)).toEqual(0)); */
it('sicp 93.3', () =>
expect(evaluate(`(def (sqrt x) (fixedpoint (fn (y) (average y (/ x y))) 1.0)) (sqrt 7)`, scope)).toEqual(
2.6457513110645907,
));
// Procedures as Returned Values
it('sicp 97.1', () =>
expect(evaluate(`(def (averagedamp f) (fn (x) (average x (f x)))) ((averagedamp square) 10)`, scope)).toEqual(55));
it('sicp 98.1', () =>
expect(evaluate(`(def (sqrt x) (fixedpoint (averagedamp (fn (y) (/ x y))) 1.0)) (sqrt 7)`, scope)).toEqual(
2.6457513110645907,
));
it('sicp 98.2', () =>
expect(
evaluate(`(def (cuberoot x) (fixedpoint (averagedamp (fn (y) (/ x (square y)))) 1.0)) (cuberoot 7)`, scope),
).toEqual(1.912934258514886));
it('sicp 99.1', () =>
expect(
evaluate(
`
(def (deriv g) (fn (x) (/ (- (g (+ x dx)) (g x)) dx)))
(def dx 0.00001)
(def (cube x) (* x x x))
((deriv cube) 5)
`,
scope,
),
).toEqual(75.00014999664018));
// With the aid of deriv, we can express Newtons method as a fixed-point process:
it('sicp 100.1', () =>
expect(
evaluate(
`
(def (newtontransform g)
(fn (x) (- x (/ (g x) ((deriv g) x)))))
(def (newtonsmethod g guess) (fixedpoint (newtontransform g) guess))
(def (sqrt x) (newtonsmethod (fn (y) (- (square y) x)) 1.0))
(sqrt 7)
`,
scope,
),
).toEqual(2.6457513110645907));
// whatever this is
it('sicp 101.1', () =>
expect(
evaluate(
`
(def (fixedpointoftransform g transform guess) (fixedpoint (transform g) guess))
(def (sqrt x) (fixedpointoftransform
(fn (y) (/ x y)) averagedamp 1.0))
(sqrt 7)
`,
scope,
),
).toEqual(2.6457513110645907));
it('sicp 101.2', () =>
expect(
evaluate(
`
(def (sqrt x) (fixedpointoftransform
(fn (y) (- (square y) x)) newtontransform 1.0))
(sqrt 7)
`,
scope,
),
).toEqual(2.6457513110645907));
// data abstraction
// rational arithmetic
it('sicp 114.1', () =>
expect(
evaluate(
`
(def (addrat x y)
(makerat (+ (*
(numer x) (denom y))
(* (numer y) (denom x)))
(* (denom x) (denom y))))
(def (subrat x y)
(makerat (- (* (numer x) (denom y))
(* (numer y) (denom x)))
(* (denom x) (denom y))))
(def (mulrat x y)
(makerat (* (numer x) (numer y))
(* (denom x) (denom y))))
(def (divrat x y)
(makerat (* (numer x) (denom y))
(* (denom x) (numer y))))
(def (equalrat x y)
(eq (* (numer x) (denom y))
(* (numer y) (denom x))))
`,
scope,
),
).toEqual(0));
// markerat number denom
it('sicp 117.1', () =>
expect(
evaluate(
`
(def (makerat n d) (cons n d))
(def (numer x) (car x))
(def (denom x) (cdr x))
(def (printrat x) (concat (numer x) ':' (denom x)))
`,
scope,
),
).toEqual(0));
it('sicp 117.1', () => expect(evaluate(`(def onehalf (makerat 1 2)) (printrat onehalf)`, scope)).toEqual('1:2'));
it('sicp 117.2', () =>
expect(evaluate(`(def onethird (makerat 1 3)) (printrat (addrat onehalf onethird))`, scope)).toEqual('5:6'));
it('sicp 117.3', () => expect(evaluate(`(printrat (mulrat onehalf onethird))`, scope)).toEqual('1:6'));
it('sicp 117.4', () => expect(evaluate(`(printrat (addrat onethird onethird))`, scope)).toEqual('6:9'));
it('sicp 118.1', () =>
expect(evaluate(`(def (makerat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g))))`, scope)).toEqual(0));
it('sicp 118.1', () => expect(evaluate(`(printrat (addrat onethird onethird))`, scope)).toEqual('2:3'));
let lscope = {};
// pairs with lambda
it('sicp 124.1', () =>
expect(
evaluate(
`
(def (cons x y)
(def (dispatch m)
(match
((eq m 0) x)
((eq m 1) y)
(else (error "argument not 0 or 1: CONS" m)))
) dispatch)
(def (car z) (z 0))
(def (cdr z) (z 1))
`,
lscope,
),
).toEqual(0));
it('sicp 124.1', () => expect(evaluate(`(car (cons first second))`, lscope)).toEqual('first'));
it('sicp 124.2', () => expect(evaluate(`(cdr (cons first second))`, lscope)).toEqual('second'));
// lists
it('sicp 135.1', () => expect(evaluate(`(list 1 2 3 4)`)).toEqual([1, 2, 3, 4]));
it('sicp 137.1', () => expect(evaluate(`(car (list 1 2 3 4))`)).toEqual(1));
it('sicp 137.2', () => expect(evaluate(`(cdr (list 1 2 3 4))`)).toEqual([2, 3, 4]));
it('sicp 137.3', () => expect(evaluate(`(car (cdr (list 1 2 3 4)))`)).toEqual(2));
it('sicp 137.4', () => expect(evaluate(`(cons 10 (list 1 2 3 4))`)).toEqual([10, 1, 2, 3, 4]));
// listref
it('sicp 138.1', () =>
expect(
evaluate(
`
(def (listref items n) (if (eq n 0) (car items)
(listref (cdr items) (- n 1))))
(def squares (list 1 4 9 16 25))
(listref squares 3)`,
scope,
),
).toEqual(16));
// length recursive
it('sicp 138.2', () =>
expect(
evaluate(
`
(def (length items)
(if (isnull items) 0
(+ 1 (length (cdr items)))))
(def odds (list 1 3 5 7))
(length odds)`,
),
).toEqual(4));
// length iterative
it('sicp 139.1', () =>
expect(
evaluate(
`
(def (length items)
(def (lengthiter a count)
(if (isnull a) count
(lengthiter (cdr a) (+ 1 count))))
(lengthiter items 0))
(def odds (list 1 3 5 7))
(length odds)
`,
scope,
),
).toEqual(4));
// append
it('sicp 139.1', () =>
expect(
evaluate(
`
(def (append list1 list2)
(if (isnull list1)
list2
(cons (car list1) (append (cdr list1) list2))))
(append squares odds)
`,
scope,
),
).toEqual([1, 4, 9, 16, 25, 1, 3, 5, 7]));
// (define (f x y . z) ⟨body⟩) <- tbd: variable argument count
// Mapping over lists
it('sicp 143.1', () =>
expect(
evaluate(
`
(def (scalelist items factor) (if (isnull items) nil
(cons (* (car items) factor)
(scalelist (cdr items) factor))))
(scalelist (list 1 2 3 4 5) 10)
`,
scope,
),
).toEqual([10, 20, 30, 40, 50]));
it('sicp 143.1', () =>
expect(
evaluate(
`
(def (map proc items) (if (isnull items) nil
(cons (proc (car items))
(map proc (cdr items)))))
(map abs (list -10 2.5 -11.6 17))
`,
scope,
),
).toEqual([10, 2.5, 11.6, 17]));
it('sicp 143.1', () => expect(evaluate(`(map (fn (x) (* x x)) (list 1 2 3 4))`, scope)).toEqual([1, 4, 9, 16]));
it('sicp 143.1', () =>
expect(
evaluate(
`
(def (scalelist items factor) (map (fn (x) (* x factor)) items))
(scalelist (list 1 2 3 4 5) 10)
`,
scope,
),
).toEqual([10, 20, 30, 40, 50]));
});
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';
//import { dependencies } from './package.json';
import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [],
build: {
lib: {
entry: resolve(__dirname, 'mondo.mjs'),
formats: ['es'],
fileName: (ext) => ({ es: 'mondo.mjs' })[ext],
},
rollupOptions: {
// external: [...Object.keys(dependencies)],
},
target: 'esnext',
},
});
+3
View File
@@ -0,0 +1,3 @@
# @strudel/mondough
connects mondo to strudel.
+132
View File
@@ -0,0 +1,132 @@
import {
strudelScope,
reify,
fast,
slow,
seq,
stepcat,
extend,
expand,
pace,
chooseIn,
degradeBy,
silence,
} from '@strudel/core';
import { registerLanguage } from '@strudel/transpiler';
import { MondoRunner } from 'mondolang';
const tail = (friend, pat) => pat.fmap((a) => (b) => (Array.isArray(a) ? [...a, b] : [a, b])).appLeft(friend);
const arrayRange = (start, stop, step = 1) =>
Array.from({ length: Math.abs(stop - start) / step + 1 }, (_, index) =>
start < stop ? start + index * step : start - index * step,
);
const range = (max, min) => min.squeezeBind((a) => max.bind((b) => seq(...arrayRange(a, b))));
let nope = (...args) => args[args.length - 1];
let lib = {};
lib['nope'] = nope;
lib['-'] = (a, b) => b.early(a);
lib['+'] = (a, b) => b.late(a);
lib['_'] = silence;
lib['~'] = silence;
lib.curly = stepcat;
lib.square = (...args) => stepcat(...args).setSteps(1);
lib.angle = (...args) => stepcat(...args).pace(1);
lib['*'] = fast;
lib['/'] = slow;
lib['!'] = extend;
lib['@'] = expand;
lib['%'] = pace;
lib['?'] = degradeBy; // todo: default 0.5 not working..
lib[':'] = tail;
lib['..'] = range;
lib['def'] = () => silence;
lib['or'] = (...children) => chooseIn(...children); // always has structure but is cyclewise.. e.g. "s oh*8.dec[.04 | .5]"
//lib['or'] = (...children) => chooseOut(...children); // "s oh*8.dec[.04 | .5]" is better but "dec[.04 | .5].s oh*8" has no struct
function evaluator(node, scope) {
const { type } = node;
// node is list
if (type === 'list') {
const { children } = node;
const [name, ...args] = children;
// some functions wont be reified to make sure they work (e.g. see extend below)
if (typeof name === 'function') {
return name(...args);
}
if (name.value === 'def') {
return silence;
}
// name is expected to be a pattern of functions!
const first = name.firstCycle(true)[0];
const type = typeof first?.value;
if (type !== 'function') {
throw new Error(`[mondough] expected function, got "${first?.value}"`);
}
return name
.fmap((fn) => {
if (typeof fn !== 'function') {
throw new Error(`[mondough] "${fn}" is not a function b`);
}
return fn(...args);
})
.innerJoin();
}
// node is leaf
let { value } = node;
if (type === 'plain' && scope[value]) {
return reify(scope[value]); // -> local scope has no location
}
const variable = lib[value] ?? strudelScope[value];
// problem: collisions when we want a string that happens to also be a variable name
// example: "s sine" -> sine is also a variable
let pat;
if (type === 'plain' && typeof variable !== 'undefined') {
// some function names are not patternable, so we skip reification here
if (['!', 'extend', '@', 'expand', 'square', 'angle'].includes(value)) {
return variable;
}
pat = reify(variable);
} else {
pat = reify(value);
}
if (node.loc) {
pat = pat.withLoc(node.loc[0], node.loc[1]);
}
return pat;
}
let runner = new MondoRunner({ evaluator });
export function mondo(code, offset = 0) {
if (Array.isArray(code)) {
code = code.join('');
}
const pat = runner.run(code, undefined, offset);
return pat.markcss('color: var(--caret,--foreground);text-decoration:underline');
}
let getLocations = (code, offset) => runner.parser.get_locations(code, offset);
export const mondi = (str, offset) => {
const code = `[${str}]`;
return mondo(code, offset);
};
// tell transpiler how to get locations for mondo`` calls
registerLanguage('mondo', {
getLocations,
});
// this is like mondo, but with a zero offset
export const mondolang = (code) => mondo(code, 0);
registerLanguage('mondolang', {
getLocations: (code) => getLocations(code, 0),
});
// uncomment the following to use mondo as mini notation language
/* registerLanguage('minilang', {
name: 'mondi',
getLocations,
}); */
+44
View File
@@ -0,0 +1,44 @@
{
"name": "@strudel/mondo",
"version": "1.1.1",
"description": "mondo notation for strudel",
"main": "mondough.mjs",
"type": "module",
"publishConfig": {
"main": "dist/mondough.mjs"
},
"scripts": {
"test": "vitest run",
"bench": "vitest bench",
"build:parser": "peggy -o krill-parser.js --format es ./krill.pegjs",
"build": "vite build",
"prepublishOnly": "npm run build"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tidalcycles/strudel.git"
},
"keywords": [
"tidalcycles",
"strudel",
"pattern",
"livecoding",
"algorave"
],
"author": "Felix Roos <flix91@gmail.com>",
"license": "AGPL-3.0-or-later",
"bugs": {
"url": "https://github.com/tidalcycles/strudel/issues"
},
"homepage": "https://github.com/tidalcycles/strudel#readme",
"dependencies": {
"@strudel/core": "workspace:*",
"@strudel/transpiler": "workspace:*",
"mondolang": "workspace:*"
},
"devDependencies": {
"mondo": "*",
"vite": "^6.0.11",
"vitest": "^3.0.4"
}
}
+19
View File
@@ -0,0 +1,19 @@
import { defineConfig } from 'vite';
//import { dependencies } from './package.json';
import { resolve } from 'path';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [],
build: {
lib: {
entry: resolve(__dirname, 'mondough.mjs'),
formats: ['es'],
fileName: (ext) => ({ es: 'mondough.mjs' })[ext],
},
rollupOptions: {
// external: [...Object.keys(dependencies)],
},
target: 'esnext',
},
});
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/motion",
"version": "1.2.2",
"version": "1.2.3",
"description": "DeviceMotion API for strudel",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/mqtt",
"version": "1.2.2",
"version": "1.2.3",
"description": "MQTT API for strudel",
"main": "mqtt.mjs",
"type": "module",
+1 -1
View File
@@ -60,7 +60,7 @@ export function parseControlsFromHap(hap, cps) {
const collator = new ClockCollator({});
export async function oscTrigger(t_deprecate, hap, currentTime, cps = 1, targetTime) {
export async function oscTrigger(hap, currentTime, cps = 1, targetTime) {
const osc = await connect();
const controls = parseControlsFromHap(hap, cps);
const keyvals = Object.entries(controls).flat();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/osc",
"version": "1.2.2",
"version": "1.2.3",
"description": "OSC messaging for strudel",
"main": "osc.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/reference",
"version": "1.2.0",
"version": "1.2.1",
"description": "Headless reference of all strudel functions",
"main": "index.mjs",
"type": "module",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/repl",
"version": "1.2.3",
"version": "1.2.4",
"description": "Strudel REPL as a Web Component",
"module": "index.mjs",
"publishConfig": {
+1 -1
View File
@@ -36,7 +36,7 @@ export async function prebake() {
samples(`${ds}/tidal-drum-machines.json`),
samples(`${ds}/piano.json`),
samples(`${ds}/Dirt-Samples.json`),
samples(`${ds}/EmuSP12.json`),
samples(`${ds}/uzu-drumkit.json`),
samples(`${ds}/vcsl.json`),
samples(`${ds}/mridangam.json`),
]);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/serial",
"version": "1.2.2",
"version": "1.2.3",
"description": "Webserial API for strudel",
"main": "serial.mjs",
"type": "module",
+1 -1
View File
@@ -537,7 +537,7 @@ export default {
],
gm_synth_bass_1: [
// Synth Bass 1: Bass
'0380_Aspirin_sf2_file',
// '0380_Aspirin_sf2_file', // broken in safari https://codeberg.org/uzu/strudel/issues/1384
'0380_Chaos_sf2_file',
'0380_FluidR3_GM_sf2_file',
// 0380_GeneralUserGS_sf2_file // laut
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/soundfonts",
"version": "1.2.3",
"version": "1.2.4",
"description": "Soundsfont support for strudel",
"main": "index.mjs",
"publishConfig": {
+1 -1
View File
@@ -3,7 +3,7 @@ import { getAudioContext, registerSound } from '@strudel/webaudio';
import { loadSoundfont as _loadSoundfont, startPresetNote } from 'sfumato';
Pattern.prototype.soundfont = function (sf, n = 0) {
return this.onTrigger((time_deprecate, h, ct, cps, targetTime) => {
return this.onTrigger((h, ct, cps, targetTime) => {
const ctx = getAudioContext();
const note = getPlayableNoteValue(h);
const preset = sf.presets[n % sf.presets.length];
+1 -1
View File
@@ -74,6 +74,6 @@ export const dough = async (code) => {
worklet.node.connect(ac.destination);
};
export function doughTrigger(time_deprecate, hap, currentTime, cps, targetTime) {
export function doughTrigger(hap, currentTime, cps, targetTime) {
window.postMessage({ time: targetTime, dough: hap.value, currentTime, duration: hap.duration, cps });
}
+17 -5
View File
@@ -1,5 +1,8 @@
import { getAudioContext } from './superdough.mjs';
import { clamp, nanFallback } from './util.mjs';
import { getNoiseBuffer } from './noise.mjs';
export const noises = ['pink', 'white', 'brown', 'crackle'];
export function gainNode(value) {
const node = getAudioContext().createGain();
@@ -206,7 +209,8 @@ export function getVibratoOscillator(param, value, t) {
// ConstantSource inherits AudioScheduledSourceNode, which has scheduling abilities
// a bit of a hack, but it works very well :)
export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
const constantNode = audioContext.createConstantSource();
const constantNode = new ConstantSourceNode(audioContext);
constantNode.start(startTime);
constantNode.stop(stopTime);
constantNode.onended = () => {
@@ -216,9 +220,17 @@ export function webAudioTimeout(audioContext, onComplete, startTime, stopTime) {
}
const mod = (freq, range = 1, type = 'sine') => {
const ctx = getAudioContext();
const osc = ctx.createOscillator();
osc.type = type;
osc.frequency.value = freq;
let osc;
if (noises.includes(type)) {
osc = ctx.createBufferSource();
osc.buffer = getNoiseBuffer(type, 2);
osc.loop = true;
} else {
osc = ctx.createOscillator();
osc.type = type;
osc.frequency.value = freq;
}
osc.start();
const g = new GainNode(ctx, { gain: range });
osc.connect(g); // -range, range
@@ -253,7 +265,7 @@ export function applyFM(param, value, begin) {
modulator = fmmod.node;
stop = fmmod.stop;
if (![fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity].find((v) => v !== undefined)) {
if (![fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity].some((v) => v !== undefined)) {
// no envelope by default
modulator.connect(param);
} else {
+6
View File
@@ -1,5 +1,11 @@
let log = (msg) => console.log(msg);
export function errorLogger(e, origin = 'cyclist') {
//TODO: add some kind of debug flag that enables this while in dev mode
// console.error(e);
logger(`[${origin}] error: ${e.message}`);
}
export const logger = (...args) => log(...args);
export const setLogger = (fn) => {
+1 -1
View File
@@ -4,7 +4,7 @@ import { getAudioContext } from './superdough.mjs';
let noiseCache = {};
// lazy generates noise buffers and keeps them forever
function getNoiseBuffer(type, density) {
export function getNoiseBuffer(type, density) {
const ac = getAudioContext();
if (noiseCache[type]) {
return noiseCache[type];
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "superdough",
"version": "1.2.3",
"version": "1.2.4",
"description": "simple web audio synth and sampler intended for live coding. inspired by superdirt and webdirt.",
"main": "index.mjs",
"type": "module",
+179 -57
View File
@@ -7,11 +7,11 @@ This program is free software: you can redistribute it and/or modify it under th
import './feedbackdelay.mjs';
import './reverb.mjs';
import './vowel.mjs';
import { clamp, nanFallback, _mod } from './util.mjs';
import { clamp, nanFallback, _mod, cycleToSeconds, secondsToCycle } from './util.mjs';
import workletsUrl from './worklets.mjs?audioworklet';
import { createFilter, gainNode, getCompressor, getWorklet } from './helpers.mjs';
import { createFilter, gainNode, getCompressor, getWorklet, webAudioTimeout } from './helpers.mjs';
import { map } from 'nanostores';
import { logger } from './logger.mjs';
import { logger, errorLogger } from './logger.mjs';
import { loadBuffer } from './sampler.mjs';
export const DEFAULT_MAX_POLYPHONY = 128;
@@ -28,6 +28,13 @@ export function setMultiChannelOrbits(bool) {
multiChannelOrbits = bool == true;
}
function getModulationShapeInput(val) {
if (typeof val === 'number') {
return val % 5;
}
return { tri: 0, triangle: 0, sine: 1, ramp: 2, saw: 3, square: 4 }[val] ?? 0;
}
export const soundMap = map();
export function registerSound(key, onTrigger, data = {}) {
@@ -107,6 +114,10 @@ export async function aliasBank(...args) {
}
export function getSound(s) {
if (typeof s !== 'string') {
console.warn(`getSound: expected string got "${s}". fall back to triangle`);
return soundMap.get().triangle; // is this good?
}
return soundMap.get()[s.toLowerCase()];
}
@@ -122,7 +133,7 @@ export const getAudioDevices = async () => {
return devicesMap;
};
const defaultDefaultValues = {
let defaultDefaultValues = {
s: 'triangle',
gain: 0.8,
postgain: 1,
@@ -139,13 +150,24 @@ const defaultDefaultValues = {
delay: 0,
byteBeatExpression: '0',
delayfeedback: 0.5,
delaytime: 0.25,
delaysync: 3 / 16,
orbit: 1,
i: 1,
velocity: 1,
fft: 8,
};
const defaultDefaultDefaultValues = Object.freeze({ ...defaultDefaultValues });
export function setDefault(control, value) {
// const main = getControlName(control); // we cant do this because superdough is independent of strudel/core
defaultDefaultValues[control] = value;
}
export function resetDefaults() {
defaultDefaultValues = { ...defaultDefaultDefaultValues };
}
let defaultControls = new Map(Object.entries(defaultDefaultValues));
export function setDefaultValue(key, value) {
@@ -309,30 +331,40 @@ function getDelay(orbit, delaytime, delayfeedback, t, channels) {
//logger(`delayfeedback was clamped to ${maxfeedback} to save your ears`);
}
delayfeedback = clamp(delayfeedback, 0, 0.98);
if (!delays[orbit]) {
if (!orbits[orbit].delayNode) {
const ac = getAudioContext();
const dly = ac.createFeedbackDelay(1, delaytime, delayfeedback);
dly.start?.(t); // for some reason, this throws when audion extension is installed..
connectToDestination(dly, channels);
delays[orbit] = dly;
connectToOrbit(dly, orbit);
orbits[orbit].delayNode = dly;
}
delays[orbit].delayTime.value !== delaytime && delays[orbit].delayTime.setValueAtTime(delaytime, t);
delays[orbit].feedback.value !== delayfeedback && delays[orbit].feedback.setValueAtTime(delayfeedback, t);
return delays[orbit];
orbits[orbit].delayNode.delayTime.value !== delaytime &&
orbits[orbit].delayNode.delayTime.setValueAtTime(delaytime, t);
orbits[orbit].delayNode.feedback.value !== delayfeedback &&
orbits[orbit].delayNode.feedback.setValueAtTime(delayfeedback, t);
return orbits[orbit].delayNode;
}
export function getLfo(audioContext, time, end, properties = {}) {
return getWorklet(audioContext, 'lfo-processor', {
export function getLfo(audioContext, begin, end, properties = {}) {
const { shape = 0, ...props } = properties;
const { dcoffset = -0.5, depth = 1 } = properties;
const lfoprops = {
frequency: 1,
depth: 1,
skew: 0,
depth,
skew: 0.5,
phaseoffset: 0,
time,
time: begin,
begin,
end,
shape: 1,
dcoffset: -0.5,
...properties,
});
shape: getModulationShapeInput(shape),
dcoffset,
min: dcoffset * depth,
max: dcoffset * depth + depth,
curve: 1,
...props,
};
return getWorklet(audioContext, 'lfo-processor', lfoprops);
}
function getPhaser(time, end, frequency = 1, depth = 0.5, centerFrequency = 1000, sweep = 2000) {
@@ -366,31 +398,73 @@ function getFilterType(ftype) {
return typeof ftype === 'number' ? filterTypes[Math.floor(_mod(ftype, filterTypes.length))] : ftype;
}
let reverbs = {};
//type orbit {
// gain: number,
// reverbNode: reverbNode
// delayNode: delayNode
//}
let orbits = {};
function connectToOrbit(node, orbit) {
if (orbits[orbit] == null) {
errorLogger(new Error('target orbit does not exist'), 'superdough');
}
node.connect(orbits[orbit].gain);
}
function setOrbit(audioContext, orbit, channels) {
if (orbits[orbit] == null) {
orbits[orbit] = {
gain: new GainNode(audioContext, { gain: 1 }),
};
connectToDestination(orbits[orbit].gain, channels);
}
}
function duckOrbit(audioContext, targetOrbit, t, attacktime = 0.1, duckdepth = 1) {
const targetArr = [targetOrbit].flat();
targetArr.forEach((target) => {
if (orbits[target] == null) {
errorLogger(new Error(`duck target orbit ${target} does not exist`), 'superdough');
return;
}
webAudioTimeout(
audioContext,
() => {
orbits[target].gain.gain.cancelScheduledValues(t);
const currVal = orbits[target].gain.gain.value;
orbits[target].gain.gain.linearRampToValueAtTime(clamp(1 - Math.pow(duckdepth, 0.5), 0.01, currVal), t);
orbits[target].gain.gain.exponentialRampToValueAtTime(1, t + Math.max(0.002, attacktime));
},
0,
t - 0.01,
);
});
}
let hasChanged = (now, before) => now !== undefined && now !== before;
function getReverb(orbit, duration, fade, lp, dim, ir, channels) {
function getReverb(orbit, duration, fade, lp, dim, ir) {
// If no reverb has been created for a given orbit, create one
if (!reverbs[orbit]) {
if (!orbits[orbit].reverbNode) {
const ac = getAudioContext();
const reverb = ac.createReverb(duration, fade, lp, dim, ir);
connectToDestination(reverb, channels);
reverbs[orbit] = reverb;
connectToOrbit(reverb, orbit);
orbits[orbit].reverbNode = reverb;
}
if (
hasChanged(duration, reverbs[orbit].duration) ||
hasChanged(fade, reverbs[orbit].fade) ||
hasChanged(lp, reverbs[orbit].lp) ||
hasChanged(dim, reverbs[orbit].dim) ||
reverbs[orbit].ir !== ir
hasChanged(duration, orbits[orbit].reverbNode.duration) ||
hasChanged(fade, orbits[orbit].reverbNode.fade) ||
hasChanged(lp, orbits[orbit].reverbNode.lp) ||
hasChanged(dim, orbits[orbit].reverbNode.dim) ||
orbits[orbit].reverbNode.ir !== ir
) {
// only regenerate when something has changed
// avoids endless regeneration on things like
// stack(s("a"), s("b").rsize(8)).room(.5)
// this only works when args may stay undefined until here
// setting default values breaks this
reverbs[orbit].generate(duration, fade, lp, dim, ir);
orbits[orbit].reverbNode.generate(duration, fade, lp, dim, ir);
}
return reverbs[orbit];
return orbits[orbit].reverbNode;
}
export let analysers = {},
@@ -433,8 +507,7 @@ function effectSend(input, effect, wet) {
}
export function resetGlobalEffects() {
delays = {};
reverbs = {};
orbits = {};
analysers = {};
analysersData = {};
}
@@ -446,9 +519,10 @@ function mapChannelNumbers(channels) {
return (Array.isArray(channels) ? channels : [channels]).map((ch) => ch - 1);
}
export const superdough = async (value, t, hapDuration, cps) => {
export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5) => {
// new: t is always expected to be the absolute target onset time
const ac = getAudioContext();
t = typeof t === 'string' && t.startsWith('=') ? Number(t.slice(1)) : ac.currentTime + t;
let { stretch } = value;
if (stretch != null) {
//account for phase vocoder latency
@@ -474,15 +548,25 @@ export const superdough = async (value, t, hapDuration, cps) => {
}
// destructure
let {
tremolo,
tremolosync,
tremolodepth = 1,
tremoloskew,
tremolophase = 0,
tremoloshape,
s = getDefaultValue('s'),
bank,
source,
gain = getDefaultValue('gain'),
postgain = getDefaultValue('postgain'),
density = getDefaultValue('density'),
duckorbit,
duckattack,
duckdepth,
// filters
fanchor = getDefaultValue('fanchor'),
drive = 0.69,
release = 0,
// low pass
cutoff,
lpenv,
@@ -515,7 +599,9 @@ export const superdough = async (value, t, hapDuration, cps) => {
phasercenter,
//
coarse,
crush,
dry,
shape,
shapevol = getDefaultValue('shapevol'),
distort,
@@ -524,7 +610,8 @@ export const superdough = async (value, t, hapDuration, cps) => {
vowel,
delay = getDefaultValue('delay'),
delayfeedback = getDefaultValue('delayfeedback'),
delaytime = getDefaultValue('delaytime'),
delaysync = getDefaultValue('delaysync'),
delaytime,
orbit = getDefaultValue('orbit'),
room,
roomfade,
@@ -543,10 +630,18 @@ export const superdough = async (value, t, hapDuration, cps) => {
compressorRelease,
} = value;
delaytime = delaytime ?? cycleToSeconds(delaysync, cps);
const orbitChannels = mapChannelNumbers(
multiChannelOrbits && orbit > 0 ? [orbit * 2 - 1, orbit * 2] : getDefaultValue('channels'),
);
const channels = value.channels != null ? mapChannelNumbers(value.channels) : orbitChannels;
setOrbit(ac, orbit, channels, t, cycle, cps);
if (duckorbit != null) {
duckOrbit(ac, duckorbit, t, duckattack, duckdepth);
}
gain = applyGainCurve(nanFallback(gain, 1));
postgain = applyGainCurve(postgain);
@@ -554,8 +649,11 @@ export const superdough = async (value, t, hapDuration, cps) => {
distortvol = applyGainCurve(distortvol);
delay = applyGainCurve(delay);
velocity = applyGainCurve(velocity);
tremolodepth = applyGainCurve(tremolodepth);
gain *= velocity; // velocity currently only multiplies with gain. it might do other things in the future
const end = t + hapDuration;
const endWithRelease = end + release;
const chainID = Math.round(Math.random() * 1000000);
// oldest audio nodes will be destroyed if maximum polyphony is exceeded
@@ -571,6 +669,9 @@ export const superdough = async (value, t, hapDuration, cps) => {
let audioNodes = [];
if (['-', '~', '_'].includes(s)) {
return;
}
if (bank && s) {
s = `${bank}_${s}`;
value.s = s;
@@ -627,7 +728,7 @@ export const superdough = async (value, t, hapDuration, cps) => {
lprelease,
lpenv,
t,
t + hapDuration,
end,
fanchor,
ftype,
drive,
@@ -651,7 +752,7 @@ export const superdough = async (value, t, hapDuration, cps) => {
hprelease,
hpenv,
t,
t + hapDuration,
end,
fanchor,
);
chain.push(hp());
@@ -662,20 +763,7 @@ export const superdough = async (value, t, hapDuration, cps) => {
if (bandf !== undefined) {
let bp = () =>
createFilter(
ac,
'bandpass',
bandf,
bandq,
bpattack,
bpdecay,
bpsustain,
bprelease,
bpenv,
t,
t + hapDuration,
fanchor,
);
createFilter(ac, 'bandpass', bandf, bandq, bpattack, bpdecay, bpsustain, bprelease, bpenv, t, end, fanchor);
chain.push(bp());
if (ftype === '24db') {
chain.push(bp());
@@ -693,6 +781,33 @@ export const superdough = async (value, t, hapDuration, cps) => {
shape !== undefined && chain.push(getWorklet(ac, 'shape-processor', { shape, postgain: shapevol }));
distort !== undefined && chain.push(getWorklet(ac, 'distort-processor', { distort, postgain: distortvol }));
if (tremolosync != null) {
tremolo = cps * tremolosync;
}
if (tremolo !== undefined) {
// Allow clipping of modulator for more dynamic possiblities, and to prevent speaker overload
// EX: a triangle waveform will clip like this /-\ when the depth is above 1
const gain = Math.max(1 - tremolodepth, 0);
const amGain = new GainNode(ac, { gain });
const time = cycle / cps;
const lfo = getLfo(ac, t, endWithRelease, {
skew: tremoloskew ?? (tremoloshape != null ? 0.5 : 1),
frequency: tremolo,
depth: tremolodepth,
time,
dcoffset: 0,
shape: tremoloshape,
phaseoffset: tremolophase,
min: 0,
max: 1,
curve: 1.5,
});
lfo.connect(amGain.gain);
chain.push(amGain);
}
compressorThreshold !== undefined &&
chain.push(
getCompressor(ac, compressorThreshold, compressorRatio, compressorKnee, compressorAttack, compressorRelease),
@@ -706,20 +821,19 @@ export const superdough = async (value, t, hapDuration, cps) => {
}
// phaser
if (phaser !== undefined && phaserdepth > 0) {
const phaserFX = getPhaser(t, t + hapDuration, phaser, phaserdepth, phasercenter, phasersweep);
const phaserFX = getPhaser(t, endWithRelease, phaser, phaserdepth, phasercenter, phasersweep);
chain.push(phaserFX);
}
// last gain
const post = new GainNode(ac, { gain: postgain });
chain.push(post);
connectToDestination(post, channels);
// delay
let delaySend;
if (delay > 0 && delaytime > 0 && delayfeedback > 0) {
const delyNode = getDelay(orbit, delaytime, delayfeedback, t, orbitChannels);
delaySend = effectSend(post, delyNode, delay);
const delayNode = getDelay(orbit, delaytime, delayfeedback, t, orbitChannels);
delaySend = effectSend(post, delayNode, delay);
audioNodes.push(delaySend);
}
// reverb
@@ -748,6 +862,14 @@ export const superdough = async (value, t, hapDuration, cps) => {
analyserSend = effectSend(post, analyserNode, 1);
audioNodes.push(analyserSend);
}
if (dry != null) {
dry = applyGainCurve(dry);
const dryGain = new GainNode(ac, { gain: dry });
chain.push(dryGain);
connectToOrbit(dryGain, orbit);
} else {
connectToOrbit(post, orbit);
}
// connect chain elements together
chain.slice(1).reduce((last, current) => last.connect(current), chain[0]);
+91 -4
View File
@@ -1,5 +1,5 @@
import { clamp, midiToFreq, noteToMidi } from './util.mjs';
import { registerSound, getAudioContext, getLfo } from './superdough.mjs';
import { registerSound, getAudioContext, soundMap, getLfo } from './superdough.mjs';
import {
applyFM,
gainNode,
@@ -9,12 +9,13 @@ import {
getVibratoOscillator,
webAudioTimeout,
getWorklet,
noises,
} from './helpers.mjs';
import { getNoiseMix, getNoiseOscillator } from './noise.mjs';
const getFrequencyFromValue = (value) => {
const getFrequencyFromValue = (value, defaultNote = 36) => {
let { note, freq } = value;
note = note || 36;
note = note || defaultNote;
if (typeof note === 'string') {
note = noteToMidi(note); // e.g. c3 => 48
}
@@ -34,7 +35,23 @@ function destroyAudioWorkletNode(node) {
}
const waveforms = ['triangle', 'square', 'sawtooth', 'sine'];
const noises = ['pink', 'white', 'brown', 'crackle'];
const waveformAliases = [
['tri', 'triangle'],
['sqr', 'square'],
['saw', 'sawtooth'],
['sin', 'sine'],
];
function makeSaturationCurve(amount, n_samples) {
const k = typeof amount === 'number' ? amount : 50;
const curve = new Float32Array(n_samples);
for (let i = 0; i < n_samples; i++) {
const x = (i * 2) / n_samples - 1;
curve[i] = Math.tanh(x * k);
}
return curve;
}
export function registerSynthSounds() {
[...waveforms].forEach((s) => {
@@ -78,6 +95,75 @@ export function registerSynthSounds() {
{ type: 'synth', prebake: true },
);
});
registerSound(
'sbd',
(t, value, onended) => {
const { duration, decay = 0.5, pdecay = 0.5, penv = 36, clip } = value;
const ctx = getAudioContext();
const attackhold = 0.02;
const noiselvl = 1.2;
const noisedecay = 0.025;
const mixGain = 1;
const o = ctx.createOscillator();
o.type = 'triangle';
o.frequency.value = getFrequencyFromValue(value, 29);
o.detune.setValueAtTime(penv * 100, 0);
o.detune.setValueAtTime(penv * 100, t);
o.detune.exponentialRampToValueAtTime(0.001, t + pdecay);
const g = gainNode(1);
g.gain.setValueAtTime(1, t + attackhold);
g.gain.exponentialRampToValueAtTime(0.001, t + attackhold + decay);
o.start(t);
const noise = getNoiseOscillator('brown', t, 2);
const noiseGain = gainNode(1);
noiseGain.gain.setValueAtTime(noiselvl, t);
noiseGain.gain.exponentialRampToValueAtTime(0.001, t + noisedecay);
const sat = new WaveShaperNode(ctx);
// tri to sine diode shaper emulation
sat.curve = makeSaturationCurve(2, ctx.sampleRate);
const mix = gainNode(mixGain);
o.onended = () => {
o.disconnect();
g.disconnect();
sat.disconnect();
noise.node.disconnect();
noiseGain.disconnect();
mix.disconnect();
onended();
};
const node = o.connect(sat).connect(g).connect(mix);
noise.node.connect(noiseGain).connect(mix);
const holdEnd = t + decay;
let end = holdEnd + 0.01;
if (clip != null) {
end = Math.min(t + clip * duration, end);
}
// prevent clicking
mix.gain.setValueAtTime(mixGain, end - 0.01);
mix.gain.linearRampToValueAtTime(0, end);
o.stop(end);
noise.stop(end);
return {
node,
stop: (endTime) => {
o.stop(endTime);
},
};
},
{ type: 'synth', prebake: true },
);
registerSound(
'supersaw',
(begin, value, onended) => {
@@ -342,6 +428,7 @@ export function registerSynthSounds() {
{ type: 'synth', prebake: true },
);
});
waveformAliases.forEach(([alias, actual]) => soundMap.set({ ...soundMap.get(), [alias]: soundMap.get()[actual] }));
}
export function waveformN(partials, type) {
+8
View File
@@ -68,3 +68,11 @@ export const _mod = (n, m) => ((n % m) + m) % m;
export const getSoundIndex = (n, numSounds) => {
return _mod(Math.round(nanFallback(n, 0)), numSounds);
};
export function cycleToSeconds(cycle, cps) {
return cycle / cps;
}
export function secondsToCycle(t, cps) {
return t * cps;
}
+39 -26
View File
@@ -8,18 +8,28 @@ import FFT from './fft.js';
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
const _mod = (n, m) => ((n % m) + m) % m;
// Restrict phase to the range [0, maxPhase) via wrapping
function wrapPhase(phase, maxPhase = 1) {
if (phase >= maxPhase) {
phase -= maxPhase;
} else if (phase < 0) {
phase += maxPhase;
}
return phase;
}
const blockSize = 128;
// adjust waveshape to remove frequencies above nyquist to prevent aliasing
// Smooth waveshape near discontinuities to remove frequencies above Nyquist and prevent aliasing
// referenced from https://www.kvraudio.com/forum/viewtopic.php?t=375517
function polyBlep(phase, dt) {
// 0 <= phase < 1
dt = Math.min(dt, 1 - dt);
// Start of cycle
if (phase < dt) {
phase /= dt;
// 2 * (phase - phase^2/2 - 0.5)
return phase + phase - phase * phase - 1;
}
// -1 < phase < 0
// End of cycle
else if (phase > 1 - dt) {
phase = (phase - 1) / dt;
// 2 * (phase^2/2 + phase + 0.5)
@@ -31,7 +41,7 @@ function polyBlep(phase, dt) {
return 0;
}
}
// The order is important for dough integration
const waveshapes = {
tri(phase, skew = 0.5) {
const x = 1 - skew;
@@ -81,10 +91,12 @@ function getParamValue(block, param) {
}
return param[0];
}
const waveShapeNames = Object.keys(waveshapes);
class LFOProcessor extends AudioWorkletProcessor {
static get parameterDescriptors() {
return [
{ name: 'begin', defaultValue: 0 },
{ name: 'time', defaultValue: 0 },
{ name: 'end', defaultValue: 0 },
{ name: 'frequency', defaultValue: 0.5 },
@@ -92,7 +104,10 @@ class LFOProcessor extends AudioWorkletProcessor {
{ name: 'depth', defaultValue: 1 },
{ name: 'phaseoffset', defaultValue: 0 },
{ name: 'shape', defaultValue: 0 },
{ name: 'curve', defaultValue: 1 },
{ name: 'dcoffset', defaultValue: 0 },
{ name: 'min', defaultValue: 0 },
{ name: 'max', defaultValue: 1 },
];
}
@@ -109,10 +124,13 @@ class LFOProcessor extends AudioWorkletProcessor {
}
process(inputs, outputs, parameters) {
// eslint-disable-next-line no-undef
const begin = parameters['begin'][0];
if (currentTime >= parameters.end[0]) {
return false;
}
if (currentTime <= begin) {
return true;
}
const output = outputs[0];
const frequency = parameters['frequency'][0];
@@ -122,7 +140,11 @@ class LFOProcessor extends AudioWorkletProcessor {
const skew = parameters['skew'][0];
const phaseoffset = parameters['phaseoffset'][0];
const curve = parameters['curve'][0];
const dcoffset = parameters['dcoffset'][0];
const min = parameters['min'][0];
const max = parameters['max'][0];
const shape = waveShapeNames[parameters['shape'][0]];
const blockSize = output[0].length ?? 0;
@@ -130,12 +152,12 @@ class LFOProcessor extends AudioWorkletProcessor {
if (this.phase == null) {
this.phase = _mod(time * frequency + phaseoffset, 1);
}
// eslint-disable-next-line no-undef
const dt = frequency / sampleRate;
for (let n = 0; n < blockSize; n++) {
for (let i = 0; i < output.length; i++) {
const modval = (waveshapes[shape](this.phase, skew) + dcoffset) * depth;
output[i][n] = modval;
let modval = (waveshapes[shape](this.phase, skew) + dcoffset) * depth;
modval = Math.pow(modval, curve);
output[i][n] = clamp(modval, min, max);
}
this.incrementPhase(dt);
}
@@ -291,7 +313,6 @@ class LadderProcessor extends AudioWorkletProcessor {
const drive = clamp(Math.exp(parameters.drive[0]), 0.1, 2000);
let cutoff = parameters.frequency[0];
// eslint-disable-next-line no-undef
cutoff = (cutoff * 2 * _PI) / sampleRate;
cutoff = cutoff > 1 ? 1 : cutoff;
@@ -424,18 +445,13 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
];
}
process(input, outputs, params) {
// eslint-disable-next-line no-undef
if (currentTime <= params.begin[0]) {
return true;
}
// eslint-disable-next-line no-undef
if (currentTime >= params.end[0]) {
// this.port.postMessage({ type: 'onended' });
return false;
}
let frequency = params.frequency[0];
//apply detune in cents
frequency = frequency * Math.pow(2, params.detune[0] / 1200);
const output = outputs[0];
const voices = params.voices[0];
@@ -446,9 +462,6 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
for (let n = 0; n < voices; n++) {
const isOdd = (n & 1) == 1;
//applies unison "spread" detune in semitones
const freq = applySemitoneDetuneToFrequency(frequency, getUnisonDetune(voices, freqspread, n));
let gainL = gain1;
let gainR = gain2;
// invert right and left gain
@@ -456,21 +469,21 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
gainL = gain2;
gainR = gain1;
}
// eslint-disable-next-line no-undef
const dt = freq / sampleRate;
for (let i = 0; i < output[0].length; i++) {
// Main detuning
let freq = applySemitoneDetuneToFrequency(params.frequency[i] ?? params.frequency[0], params.detune[0] / 100);
// Individual voice detuning
freq = applySemitoneDetuneToFrequency(freq, getUnisonDetune(voices, freqspread, n));
// We must wrap this here because it is passed into sawblep below which
// has domain [0, 1]
const dt = _mod(freq / sampleRate, 1);
this.phase[n] = this.phase[n] ?? Math.random();
const v = waveshapes.sawblep(this.phase[n], dt);
output[0][i] = output[0][i] + v * gainL;
output[1][i] = output[1][i] + v * gainR;
this.phase[n] += dt;
if (this.phase[n] > 1.0) {
this.phase[n] = this.phase[n] - 1;
}
this.phase[n] = wrapPhase(this.phase[n] + dt);
}
}
return true;
@@ -479,7 +492,7 @@ class SuperSawOscillatorProcessor extends AudioWorkletProcessor {
registerProcessor('supersaw-oscillator', SuperSawOscillatorProcessor);
// Phase Vocoder sourced from // sourced from https://github.com/olvb/phaze/tree/master?tab=readme-ov-file
// Phase Vocoder sourced from https://github.com/olvb/phaze/tree/master?tab=readme-ov-file
const BUFFERED_BLOCK_SIZE = 2048;
function genHannWindow(length) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/tonal",
"version": "1.2.2",
"version": "1.2.3",
"description": "Tonal functions for strudel",
"main": "index.mjs",
"publishConfig": {
+14 -7
View File
@@ -25,28 +25,35 @@ describe('tonal', () => {
});
it('scale with n values', () => {
expect(
n(0, 1, 2)
n(seq(0, 1, 2))
.scale('C major')
.firstCycleValues.map((h) => h.note),
).toEqual(['C3', 'D3', 'E3']);
});
it('scale with colon', () => {
expect(
n(0, 1, 2)
n(seq(0, 1, 2))
.scale('C:major')
.firstCycleValues.map((h) => h.note),
).toEqual(['C3', 'D3', 'E3']);
});
it('scale without tonic', () => {
expect(
n(seq(0, 1, 2))
.scale('major')
.firstCycleValues.map((h) => h.note),
).toEqual(['C3', 'D3', 'E3']);
});
it('scale with mininotation colon', () => {
expect(
n(0, 1, 2)
n(seq(0, 1, 2))
.scale(mini('C:major'))
.firstCycleValues.map((h) => h.note),
).toEqual(['C3', 'D3', 'E3']);
});
it('transposes note numbers with interval numbers', () => {
expect(
note(40, 40, 40)
note(seq(40, 40, 40))
.transpose(0, 1, 2)
.firstCycleValues.map((h) => h.note),
).toEqual([40, 41, 42]);
@@ -54,7 +61,7 @@ describe('tonal', () => {
});
it('transposes note numbers with interval strings', () => {
expect(
note(40, 40, 40)
note(seq(40, 40, 40))
.transpose('1P', '2M', '3m')
.firstCycleValues.map((h) => h.note),
).toEqual([40, 42, 43]);
@@ -62,7 +69,7 @@ describe('tonal', () => {
});
it('transposes note strings with interval numbers', () => {
expect(
note('c', 'c', 'c')
note(seq('c', 'c', 'c'))
.transpose(0, 1, 2)
.firstCycleValues.map((h) => h.note),
).toEqual(['C', 'Db', 'D']);
@@ -70,7 +77,7 @@ describe('tonal', () => {
});
it('transposes note strings with interval strings', () => {
expect(
note('c', 'c', 'c')
note(seq('c', 'c', 'c'))
.transpose('1P', '2M', '3m')
.firstCycleValues.map((h) => h.note),
).toEqual(['C', 'D', 'Eb']);
+23 -18
View File
@@ -14,7 +14,7 @@ function scaleStep(step, scale) {
scale = scale.replaceAll(':', ' ');
step = Math.ceil(step);
let { intervals, tonic, empty } = Scale.get(scale);
if ((empty && isNote(scale)) || (!empty && !tonic)) {
if ((empty && isNote(scale)) || (empty && !tonic)) {
throw new Error(`incomplete scale. Make sure to use ":" instead of spaces, example: .scale("C:major")`);
} else if (empty) {
throw new Error(`invalid scale "${scale}"`);
@@ -88,13 +88,14 @@ function scaleOffset(scale, offset, note) {
* @returns Pattern
* @memberof Pattern
* @name transpose
* @synonyms trans
* @example
* "c2 c3".fast(2).transpose("<0 -2 5 3>".slow(2)).note()
* @example
* "c2 c3".fast(2).transpose("<1P -2M 4P 3m>".slow(2)).note()
*/
export const transpose = register('transpose', function (intervalOrSemitones, pat) {
export const { transpose, trans } = register(['transpose', 'trans'], function transposeFn(intervalOrSemitones, pat) {
return pat.withHap((hap) => {
const note = hap.value.note ?? hap.value;
if (typeof note === 'number') {
@@ -142,6 +143,7 @@ export const transpose = register('transpose', function (intervalOrSemitones, pa
* @name scaleTranspose
* @param {offset} offset number of steps inside the scale
* @returns Pattern
* @synonyms scaleTrans, strans
* @example
* "-8 [2,4,6]"
* .scale('C4 bebop major')
@@ -149,22 +151,25 @@ export const transpose = register('transpose', function (intervalOrSemitones, pa
* .note()
*/
export const scaleTranspose = register('scaleTranspose', function (offset /* : number | string */, pat) {
return pat.withHap((hap) => {
if (!hap.context.scale) {
throw new Error('can only use scaleTranspose after .scale');
}
if (typeof hap.value === 'object')
return hap.withValue(() => ({
...hap.value,
note: scaleOffset(hap.context.scale, Number(offset), hap.value.note),
}));
if (typeof hap.value !== 'string') {
throw new Error('can only use scaleTranspose with notes');
}
return hap.withValue(() => scaleOffset(hap.context.scale, Number(offset), hap.value));
});
});
export const { scaleTranspose, scaleTrans, strans } = register(
['scaleTranspose', 'scaleTrans', 'strans'],
function (offset /* : number | string */, pat) {
return pat.withHap((hap) => {
if (!hap.context.scale) {
throw new Error('can only use scaleTranspose after .scale');
}
if (typeof hap.value === 'object')
return hap.withValue(() => ({
...hap.value,
note: scaleOffset(hap.context.scale, Number(offset), hap.value.note),
}));
if (typeof hap.value !== 'string') {
throw new Error('can only use scaleTranspose with notes');
}
return hap.withValue(() => scaleOffset(hap.context.scale, Number(offset), hap.value));
});
},
);
/**
* Turns numbers into notes in the scale (zero indexed). Also sets scale for other scale operations, like {@link Pattern#scaleTranspose}.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/transpiler",
"version": "1.2.2",
"version": "1.2.3",
"description": "Transpiler for strudel user code. Converts syntactically correct but semantically meaningless JS into evaluatable strudel code.",
"main": "index.mjs",
"type": "module",
+73 -8
View File
@@ -8,6 +8,16 @@ export function registerWidgetType(type) {
widgetMethods.push(type);
}
let languages = new Map();
// config = { getLocations: (code: string, offset?: number) => number[][] }
// see mondough.mjs for example use
// the language will kick in when the code contains a template literal of type
// example: mondo`...` will use language of type "mondo"
// TODO: refactor tidal.mjs to use this
export function registerLanguage(type, config) {
languages.set(type, config);
}
export function transpiler(input, options = {}) {
const { wrapAsync = false, addReturn = true, emitMiniLocations = true, emitWidgets = true } = options;
@@ -19,14 +29,33 @@ export function transpiler(input, options = {}) {
let miniLocations = [];
const collectMiniLocations = (value, node) => {
const leafLocs = getLeafLocations(`"${value}"`, node.start, input);
miniLocations = miniLocations.concat(leafLocs);
const minilang = languages.get('minilang');
if (minilang) {
const code = `[${value}]`;
const locs = minilang.getLocations(code, node.start);
miniLocations = miniLocations.concat(locs);
} else {
const leafLocs = getLeafLocations(`"${value}"`, node.start, input);
miniLocations = miniLocations.concat(leafLocs);
}
};
let widgets = [];
walk(ast, {
enter(node, parent /* , prop, index */) {
if (isTidalTeplateLiteral(node)) {
if (isLanguageLiteral(node)) {
const { name } = node.tag;
const language = languages.get(name);
const code = node.quasi.quasis[0].value.raw;
const offset = node.quasi.start + 1;
if (emitMiniLocations) {
const locs = language.getLocations(code, offset);
miniLocations = miniLocations.concat(locs);
}
this.skip();
return this.replace(languageWithLocation(name, code, offset));
}
if (isTemplateLiteral(node, 'tidal')) {
const raw = node.quasi.quasis[0].value.raw;
const offset = node.quasi.start + 1;
if (emitMiniLocations) {
@@ -84,8 +113,18 @@ export function transpiler(input, options = {}) {
leave(node, parent, prop, index) {},
});
const { body } = ast;
if (!body?.[body.length - 1]?.expression) {
let { body } = ast;
if (!body.length) {
console.warn('empty body -> fallback to silence');
body.push({
type: 'ExpressionStatement',
expression: {
type: 'Identifier',
name: 'silence',
},
});
} else if (!body?.[body.length - 1]?.expression) {
throw new Error('unexpected ast format without body expression');
}
@@ -120,11 +159,18 @@ function isBackTickString(node, parent) {
function miniWithLocation(value, node) {
const { start: fromOffset } = node;
const minilang = languages.get('minilang');
let name = 'm';
if (minilang && minilang.name) {
name = minilang.name; // name is expected to be exported from the package of the minilang
}
return {
type: 'CallExpression',
callee: {
type: 'Identifier',
name: 'm',
name,
},
arguments: [
{ type: 'Literal', value },
@@ -219,12 +265,16 @@ function labelToP(node) {
};
}
function isLanguageLiteral(node) {
return node.type === 'TaggedTemplateExpression' && languages.has(node.tag.name);
}
// tidal highlighting
// this feels kind of stupid, when we also know the location inside the string op (tidal.mjs)
// but maybe it's the only way
function isTidalTeplateLiteral(node) {
return node.type === 'TaggedTemplateExpression' && node.tag.name === 'tidal';
function isTemplateLiteral(node, value) {
return node.type === 'TaggedTemplateExpression' && node.tag.name === value;
}
function collectHaskellMiniLocations(haskellCode, offset) {
@@ -262,3 +312,18 @@ function tidalWithLocation(value, offset) {
optional: false,
};
}
function languageWithLocation(name, value, offset) {
return {
type: 'CallExpression',
callee: {
type: 'Identifier',
name: name,
},
arguments: [
{ type: 'Literal', value },
{ type: 'Literal', value: offset },
],
optional: false,
};
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/web",
"version": "1.2.3",
"version": "1.2.4",
"description": "Easy to setup, opiniated bundle of Strudel for the browser.",
"module": "web.mjs",
"publishConfig": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/webaudio",
"version": "1.2.3",
"version": "1.2.4",
"description": "Web Audio helpers for Strudel",
"main": "index.mjs",
"type": "module",
+4 -7
View File
@@ -15,13 +15,10 @@ const hap2value = (hap) => {
return hap.value;
};
export const webaudioOutputTrigger = (t, hap, ct, cps) => superdough(hap2value(hap), t - ct, hap.duration / cps, cps);
// uses more precise, absolute t if available, see https://codeberg.org/uzu/strudel/pulls/1004
export const webaudioOutput = (hap, deadline, hapDuration, cps, t) =>
superdough(hap2value(hap), t ? `=${t}` : deadline, hapDuration);
Pattern.prototype.webaudio = function () {
return this.onTrigger(webaudioOutputTrigger);
// uses more precise, absolute t if available, see https://github.com/tidalcycles/strudel/pull/1004
// TODO: refactor output callbacks to eliminate deadline
export const webaudioOutput = (hap, _deadline, hapDuration, cps, t) => {
return superdough(hap2value(hap), t, hapDuration, cps, hap.whole?.begin.valueOf());
};
export function webaudioRepl(options = {}) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@strudel/xen",
"version": "1.2.2",
"version": "1.2.3",
"description": "Xenharmonic API for strudel",
"main": "index.mjs",
"type": "module",
+118
View File
@@ -347,6 +347,37 @@ importers:
specifier: ^3.0.4
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
packages/mondo:
devDependencies:
vite:
specifier: ^6.0.11
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
vitest:
specifier: ^3.0.4
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
packages/mondough:
dependencies:
'@strudel/core':
specifier: workspace:*
version: link:../core
'@strudel/transpiler':
specifier: workspace:*
version: link:../transpiler
mondolang:
specifier: workspace:*
version: link:../mondo
devDependencies:
mondo:
specifier: '*'
version: 0.4.4
vite:
specifier: ^6.0.11
version: 6.0.11(@types/node@22.10.10)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
vitest:
specifier: ^3.0.4
version: 3.0.4(@types/debug@4.1.12)(@types/node@22.10.10)(@vitest/ui@3.0.4)(jiti@2.4.2)(lightningcss@1.29.1)(terser@5.37.0)(yaml@2.7.0)
packages/motion:
dependencies:
'@strudel/core':
@@ -683,6 +714,9 @@ importers:
'@strudel/mini':
specifier: workspace:*
version: link:../packages/mini
'@strudel/mondo':
specifier: workspace:*
version: link:../packages/mondough
'@strudel/motion':
specifier: workspace:*
version: link:../packages/motion
@@ -2975,6 +3009,10 @@ packages:
resolution: {integrity: sha512-groO71Fvi5SWpxjI9Ia+chy0QBwT61mg6yxJV27f5YFf+Mw+STT75K6SHySpP8Co5LsCrtsbCH5dJZSRtkSKaQ==}
engines: {node: '>= 14.0.0'}
amdefine@1.0.1:
resolution: {integrity: sha512-S2Hw0TtNkMJhIabBwIojKL9YHO5T0n5eNqWJ7Lrlel/zDbftQpxpapi8tZs3X1HWa+u+QeydGmzzNU0m09+Rcg==}
engines: {node: '>=0.4.2'}
ansi-align@3.0.1:
resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==}
@@ -3103,6 +3141,9 @@ packages:
resolution: {integrity: sha512-hsU18Ae8CDTR6Kgu9DYf0EbCr/a5iGL0rytQDobUcdpYOKokk8LEjVphnXkDkgpi0wYVsqrXuP0bZxJaTqdgoA==}
engines: {node: '>= 0.4'}
async@0.2.10:
resolution: {integrity: sha512-eAkdoKxU6/LkKDBzLpT+t6Ff5EtfSF4wx1WfJiPEEV7WNLnDaRXk0oVysiEPm262roaachGexwUv94WhSgN5TQ==}
async@3.2.6:
resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==}
@@ -3337,6 +3378,9 @@ packages:
claviature@0.1.0:
resolution: {integrity: sha512-Ai12axNwQ7x/F9QAj64RYKsgvi5Y33+X3GUSKAC/9s/adEws8TSSc0efeiqhKNGKBo6rT/c+CSCwSXzXxwxZzQ==}
cldr-plurals@1.0.0:
resolution: {integrity: sha512-xGkehDsjj/ng1LtYiAzdiqDgqTQ/qmWafDlB6R8CfXbpXe4Ge2Tl4l7gxiA+yaD1WCTP3EVfwerdmVwfco7vxw==}
clean-stack@2.2.0:
resolution: {integrity: sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==}
engines: {node: '>=6'}
@@ -4378,6 +4422,9 @@ packages:
resolution: {integrity: sha512-e1LleDykUz2Iu+MTYdkSsuWX8lvAjAcs0Xef0lNIu0S2wOAzuTxCJtcd9S3cijlwYF18EsU3rzb8jPVobxDh9Q==}
engines: {node: '>=16 || 14 >=14.17'}
globalize@0.1.1:
resolution: {integrity: sha512-5e01v8eLGfuQSOvx2MsDMOWS0GFtCx1wPzQSmcHw4hkxFzrQDBO3Xwg/m8Hr/7qXMrHeOIE29qWVzyv06u1TZA==}
globals@11.12.0:
resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==}
engines: {node: '>=4'}
@@ -4439,6 +4486,11 @@ packages:
h3@1.14.0:
resolution: {integrity: sha512-ao22eiONdgelqcnknw0iD645qW0s9NnrJHr5OBz4WOMdBdycfSas1EQf1wXRsm+PcB2Yoj43pjBPwqIpJQTeWg==}
handlebars@1.1.2:
resolution: {integrity: sha512-6lekK3aSHE7XnEqEs+JWQJRSRdCqJYHEVjEfWWZv9pjLUYZNeP26EtlgOrpDCSX+k5N1m74urTbztgBOCko1Kg==}
engines: {node: '>=0.4.7'}
hasBin: true
handlebars@4.7.8:
resolution: {integrity: sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ==}
engines: {node: '>=0.4.7'}
@@ -5586,6 +5638,10 @@ packages:
engines: {node: '>=18'}
hasBin: true
mondo@0.4.4:
resolution: {integrity: sha512-3ot6iKwC9KZvwmyZ9dgPCnlt0O1GuBnK8QZyhnoJdtkIiRL9X/cmQuu88CbFSznQx6bq19xQdwJHpv8hggH62Q==}
deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
mrmime@2.0.0:
resolution: {integrity: sha512-eu38+hdgojoyq63s+yTpN4XMBdt5l8HhMhc4VKLO9KM5caLIBvUm4thi7fFaxyTmCKeNnXZ5pAlBwCUnhA09uw==}
engines: {node: '>=10'}
@@ -5827,6 +5883,9 @@ packages:
resolution: {integrity: sha512-7x81NCL719oNbsq/3mh+hVrAWmFuEYUqrq/Iw3kUzH8ReypT9QQ0BLoJS7/G9k6N81XjW4qHWtjWwe/9eLy1EQ==}
engines: {node: '>=12'}
optimist@0.3.7:
resolution: {integrity: sha512-TCx0dXQzVtSCg2OgY/bO9hjM9cV4XYx09TVK+s3+FhkjT6LovsLe+pPMzpWf+6yXK/hUizs2gUoTw3jHM0VaTQ==}
optionator@0.9.4:
resolution: {integrity: sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==}
engines: {node: '>= 0.8.0'}
@@ -6725,6 +6784,10 @@ packages:
source-map-support@0.5.21:
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
source-map@0.1.43:
resolution: {integrity: sha512-VtCvB9SIQhk3aF6h+N85EaqIaBFIAfZ9Cu+NJHHVvc8BbEcnvDcFw6sqQ2dQrT6SlOrZq3tIvyD9+EGq/lJryQ==}
engines: {node: '>=0.8.0'}
source-map@0.5.7:
resolution: {integrity: sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==}
engines: {node: '>=0.10.0'}
@@ -7155,6 +7218,11 @@ packages:
ufo@1.5.4:
resolution: {integrity: sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==}
uglify-js@2.3.6:
resolution: {integrity: sha512-T2LWWydxf5+Btpb0S/Gg/yKFmYjnX9jtQ4mdN9YRq73BhN21EhU0Dvw3wYDLqd3TooGUJlCKf3Gfyjjy/RTcWA==}
engines: {node: '>=0.4.0'}
hasBin: true
uglify-js@3.19.3:
resolution: {integrity: sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ==}
engines: {node: '>=0.8.0'}
@@ -7173,6 +7241,9 @@ packages:
underscore@1.13.7:
resolution: {integrity: sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==}
underscore@1.5.2:
resolution: {integrity: sha512-yejOFsRnTJs0N9CK5Apzf6maDO2djxGoLLrlZlvGs2o9ZQuhIhDL18rtFyy4FBIbOkzA6+4hDgXbgz5EvDQCXQ==}
undici-types@6.20.0:
resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==}
@@ -7555,6 +7626,10 @@ packages:
resolution: {integrity: sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==}
engines: {node: '>=0.10.0'}
wordwrap@0.0.3:
resolution: {integrity: sha512-1tMA907+V4QmxV7dbRvb4/8MaRALK6q9Abid3ndMYnbyo8piisCmeONVqVSXqQA3KaP4SLt5b7ud6E2sqP8TFw==}
engines: {node: '>=0.4.0'}
wordwrap@1.0.0:
resolution: {integrity: sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q==}
@@ -10438,6 +10513,9 @@ snapshots:
'@algolia/requester-fetch': 5.20.0
'@algolia/requester-node-http': 5.20.0
amdefine@1.0.1:
optional: true
ansi-align@3.0.1:
dependencies:
string-width: 4.2.3
@@ -10647,6 +10725,9 @@ snapshots:
async-function@1.0.0: {}
async@0.2.10:
optional: true
async@3.2.6: {}
asynckit@0.4.0: {}
@@ -10904,6 +10985,8 @@ snapshots:
claviature@0.1.0: {}
cldr-plurals@1.0.0: {}
clean-stack@2.2.0: {}
cli-boxes@3.0.0: {}
@@ -12046,6 +12129,8 @@ snapshots:
minipass: 4.2.8
path-scurry: 1.11.1
globalize@0.1.1: {}
globals@11.12.0: {}
globals@14.0.0: {}
@@ -12112,6 +12197,12 @@ snapshots:
uncrypto: 0.1.3
unenv: 1.10.0
handlebars@1.1.2:
dependencies:
optimist: 0.3.7
optionalDependencies:
uglify-js: 2.3.6
handlebars@4.7.8:
dependencies:
minimist: 1.2.8
@@ -13695,6 +13786,13 @@ snapshots:
requirejs: 2.3.7
requirejs-config-file: 4.0.0
mondo@0.4.4:
dependencies:
cldr-plurals: 1.0.0
globalize: 0.1.1
handlebars: 1.1.2
underscore: 1.5.2
mrmime@2.0.0: {}
ms@2.0.0: {}
@@ -13987,6 +14085,10 @@ snapshots:
is-docker: 2.2.1
is-wsl: 2.2.0
optimist@0.3.7:
dependencies:
wordwrap: 0.0.3
optionator@0.9.4:
dependencies:
deep-is: 0.1.4
@@ -15094,6 +15196,11 @@ snapshots:
buffer-from: 1.1.2
source-map: 0.6.1
source-map@0.1.43:
dependencies:
amdefine: 1.0.1
optional: true
source-map@0.5.7: {}
source-map@0.6.1: {}
@@ -15561,6 +15668,13 @@ snapshots:
ufo@1.5.4: {}
uglify-js@2.3.6:
dependencies:
async: 0.2.10
optimist: 0.3.7
source-map: 0.1.43
optional: true
uglify-js@3.19.3:
optional: true
@@ -15577,6 +15691,8 @@ snapshots:
underscore@1.13.7: {}
underscore@1.5.2: {}
undici-types@6.20.0: {}
unenv@1.10.0:
@@ -15957,6 +16073,8 @@ snapshots:
word-wrap@1.2.5: {}
wordwrap@0.0.3: {}
wordwrap@1.0.0: {}
workbox-background-sync@7.0.0:
File diff suppressed because it is too large Load Diff
-22
View File
@@ -359,28 +359,6 @@ stack(
"[~ [0 ~]] 0 [~ [4 ~]] 4".sub(7).restart(scales).scale(scales).early(.25)
).note().piano().slow(2)`;
/*
export const customTrigger = `// licensed with CC BY-NC-SA 4.0 https://creativecommons.org/licenses/by-nc-sa/4.0/
// by Felix Roos
stack(
freq("55 [110,165] 110 [220,275]".mul("<1 <3/4 2/3>>").struct("x(3,8)").layer(x=>x.mul("1.006,.995"))),
freq("440(5,8)".clip(.18).mul("<1 3/4 2 2/3>")).gain(perlin.range(.2,.8))
).s("<sawtooth square>/2")
.onTrigger((t,hap,ct)=>{
const ac = Tone.getContext().rawContext;
t = ac.currentTime + t - ct;
const { freq, s, gain = 1 } = hap.value;
const master = ac.createGain();
master.gain.value = 0.1 * gain;
master.connect(ac.destination);
const o = ac.createOscillator();
o.type = s || 'triangle';
o.frequency.value = Number(freq);
o.connect(master);
o.start(t);
o.stop(t + hap.duration);
}).stack(s("bd(3,8),hh*4,~ sd").webdirt())`; */
export const swimmingWithSoundfonts = `// Koji Kondo - Swimming (Super Mario World)
stack(
n(
-1
View File
@@ -647,7 +647,6 @@
"evaluate"
],
"/packages/webaudio/webaudio.mjs": [
"webaudioOutputTrigger",
"webaudioOutput",
"webaudioRepl"
],
+1
View File
@@ -42,6 +42,7 @@
"@strudel/tonal": "workspace:*",
"@strudel/transpiler": "workspace:*",
"@strudel/webaudio": "workspace:*",
"@strudel/mondo": "workspace:*",
"@strudel/xen": "workspace:*",
"@supabase/supabase-js": "^2.48.1",
"@tailwindcss/forms": "^0.5.10",
-17
View File
@@ -1,17 +0,0 @@
{
"_base": "https://raw.githubusercontent.com/ritchse/tidal-drum-machines/main/machines/EmuSP12/",
"bd": ["emusp12-bd/Bassdrum-01.wav","emusp12-bd/Bassdrum-02.wav","emusp12-bd/Bassdrum-03.wav","emusp12-bd/Bassdrum-04.wav","emusp12-bd/Bassdrum-05.wav","emusp12-bd/Bassdrum-06.wav","emusp12-bd/Bassdrum-07.wav","emusp12-bd/Bassdrum-08.wav","emusp12-bd/Bassdrum-09.wav","emusp12-bd/Bassdrum-10.wav","emusp12-bd/Bassdrum-11.wav","emusp12-bd/Bassdrum-12.wav","emusp12-bd/Bassdrum-13.wav","emusp12-bd/Bassdrum-14.wav"],
"cb": ["emusp12-cb/Cowbell.wav"],
"cp": ["emusp12-cp/Clap.wav"],
"cr": ["emusp12-cr/Crash.wav"],
"hh": ["emusp12-hh/Hat Closed-01.wav","emusp12-hh/Hat Closed-02.wav"],
"ht": ["emusp12-ht/Tom H-01.wav","emusp12-ht/Tom H-02.wav","emusp12-ht/Tom H-03.wav","emusp12-ht/Tom H-04.wav","emusp12-ht/Tom H-05.wav","emusp12-ht/Tom H-06.wav"],
"lt": ["emusp12-lt/Tom L-01.wav","emusp12-lt/Tom L-02.wav","emusp12-lt/Tom L-03.wav","emusp12-lt/Tom L-04.wav","emusp12-lt/Tom L-05.wav","emusp12-lt/Tom L-06.wav"],
"misc": ["emusp12-misc/Metal-01.wav","emusp12-misc/Metal-02.wav","emusp12-misc/Metal-03.wav","emusp12-misc/Scratch.wav","emusp12-misc/Shot-01.wav","emusp12-misc/Shot-02.wav","emusp12-misc/Shot-03.wav"],
"mt": ["emusp12-mt/Tom M-01.wav","emusp12-mt/Tom M-02.wav","emusp12-mt/Tom M-03.wav","emusp12-mt/Tom M-05.wav"],
"oh": ["emusp12-oh/Hhopen1.wav"],
"perc": ["emusp12-perc/Blow1.wav"],
"rd": ["emusp12-rd/Ride.wav"],
"rim": ["emusp12-rim/zRim Shot-01.wav","emusp12-rim/zRim Shot-02.wav"],
"sd": ["emusp12-sd/Snaredrum-01.wav","emusp12-sd/Snaredrum-02.wav","emusp12-sd/Snaredrum-03.wav","emusp12-sd/Snaredrum-04.wav","emusp12-sd/Snaredrum-05.wav","emusp12-sd/Snaredrum-06.wav","emusp12-sd/Snaredrum-07.wav","emusp12-sd/Snaredrum-08.wav","emusp12-sd/Snaredrum-09.wav","emusp12-sd/Snaredrum-10.wav","emusp12-sd/Snaredrum-11.wav","emusp12-sd/Snaredrum-12.wav","emusp12-sd/Snaredrum-13.wav","emusp12-sd/Snaredrum-14.wav","emusp12-sd/Snaredrum-15.wav","emusp12-sd/Snaredrum-16.wav","emusp12-sd/Snaredrum-17.wav","emusp12-sd/Snaredrum-18.wav","emusp12-sd/Snaredrum-19.wav","emusp12-sd/Snaredrum-20.wav","emusp12-sd/Snaredrum-21.wav"]
}
+76
View File
@@ -0,0 +1,76 @@
{
"_base": "https://raw.githubusercontent.com/tidalcycles/uzu-drumkit/main/",
"bd": [
"bd/10_bd_switchangel.wav",
"bd/11_bd_mot4i.wav",
"bd/12_bd_mot4i.wav",
"bd/13_bd_mot4i.wav",
"bd/14_bd_switchangel.wav",
"bd/15_bd_switchangel.wav",
"bd/16_bd_switchangel.wav",
"bd/17_bd_switchangel.wav"
],
"brk": [
"brk/10_break_amen_pprocessed.wav"
],
"cb": [
"cb/10_perc_switchangel.wav"
],
"cp": [
"cp/10_cp_switchangel.wav",
"cp/11_cp_mot4i.wav"
],
"cr": [
"cr/10_cr_switchangel.wav",
"cr/11_cr_mot4i.wav"
],
"hh": [
"hh/10_hh_switchangel.wav",
"hh/11_hh_mot4i.wav",
"hh/12_hh_switchangel.wav",
"hh/13_hh_switchangel.wav",
"hh/14_hh_mot4i.wav"
],
"ht": [
"ht/10_ht_mot4i.wav"
],
"lt": [
"lt/10_lt_mot4i.wav"
],
"misc": [
"misc/10_misc_switchangel_ludens.wav",
"misc/11_misc_switchangel_ludens.wav",
"misc/12_misc_switchangel_ludens.wav",
"misc/13_misc_switchangel_ludens.wav",
"misc/14_misc_switchangel_ludens.wav"
],
"mt": [
"mt/10_mt_mot4i.wav"
],
"oh": [
"oh/10_oh_switchangel.wav",
"oh/11_oh_switchangel.wav",
"oh/12_oh_switchangel.wav",
"oh/13_oh_switchangel.wav"
],
"rd": [
"rd/10_rd_switchangel.wav"
],
"rim": [
"rim/10_rim_switchangel.wav",
"rim/11_rim_switch_angel.wav"
],
"sd": [
"sd/10_sd_switchangel-bounce-2.wav",
"sd/11_sd_switchangel_3.wav",
"sd/12_sd_switchangel_2.wav",
"sd/13_sd_switchangel_2.wav",
"sd/14_sd.wav"
],
"sh": [
"sh/10_sh_switchangel.wav"
],
"tb": [
"tb/10_tb.wav"
]
}
+1
View File
@@ -81,6 +81,7 @@ export const SIDEBAR: Sidebar = {
{ text: 'Visual Feedback', link: 'learn/visual-feedback' },
{ text: 'Offline', link: 'learn/pwa' },
{ text: 'Patterns', link: 'technical-manual/patterns' },
{ text: 'Mondo Notation', link: 'learn/mondo-notation' },
{ text: 'Music metadata', link: 'learn/metadata' },
{ text: 'CSound', link: 'learn/csound' },
{ text: 'Hydra', link: 'learn/hydra' },
@@ -0,0 +1,317 @@
---
title: 'Release Notes v1.1.0'
description: ''
date: '2024-06-02'
tags: ['meta']
author: froos
---
These are the release notes for Strudel 1.1.0 aka "Bananensplit".
The last release was over 19 weeks ago, so a lot of things have happened!
First, here's a little demo, teasing some of the new features:
import { Youtube } from '@src/components/Youtube';
<Youtube client:only="react" id="2Qu5lMHruio" />
Let's write up some of the highlights:
## New DSP Features
### Stereo Supersaw
with spread, unison, and detune parameters
```plaintext
note("d f a a# a d3").fast(2)
.s("supersaw").spread(".8").detune(.3).unison("2 7")
```
### Analog "ladder" filter type
works great for acid basslines and vibey tones
```plaintext
note("{d d d a a# d3 f4}%16".sub(12)).gain(1).s("sawtooth")
.lpf(200).lpenv(slider(1.36,0,8)).lpq(7).distort("1.5:.7")`
.ftype('ladder')
```
### stereo distortion effect
```plaintext
note("{g g a# g g4}%8".add("{0 7 12 0}%8")).lpf(500)
.s("supersaw").dist("4:.2")
```
## Editor Features
### inline viz
The editor now supports multiple visuals within the code, using the `_` prefix for viz functions:
<img
width="595"
alt="Screenshot 2024-06-01 at 01 23 51"
src="https://codeberg.org/uzu/strudel/assets/12023032/978fee85-e533-4da6-a245-d20d0083f57e"
/>
- `._pianoroll()`: inline pianoroll
- `._punchcard()`: inline punchcard
- `._scope()`: inline scope
- `._pitchwheel()`: inline pitchwheel
For more info, check out the new [Visual Feedback Page](https://strudel.cc/learn/visual-feedback/)
### label notation
This new notation simplifies writing patterns at the top level:
```plaintext
d1: s("bd*4")
d2: s("[- hh]*4")
```
This is equivalent to:
```plaintext
stack(
s("bd*4"),
s("[- hh]*4")
)
```
The labels you choose are arbitrary, the above `d1` and `d2` are a typical thing you'd write in tidal, for example `d1 $ s "bd*4"`.
If the same label is used multiple times, the last one wins:
```plaintext
d1: s("bd*4")
d1: s("[- hh]*4") // <-- only this plays
```
There is a special label anonymous label `$`, which can appear multiple times without overriding itself:
```plaintext
// both of these will play:
$: s("bd*4")
$: s("[- hh]*4")
```
You can mute a pattern by prefixing `_`:
```plaintext
_$: s("bd*4") // <-- this one is muted
$: s("[- hh]*4")
```
To run a transformation on all patterns, you can use `all`:
```plaintext
$: s("bd*4")
$: s("[- hh]*4")
all(x=>x.room(.5))
```
This notation is now the recommended way to [play patterns in parallel](https://strudel.cc/workshop/first-notes/#playing-multiple-patterns)
### Clock sync between multiple instances
timing has received a major overhaul, and is now much more accurate on all browsers. Additionally, you can now sync timing across multiple windows.
![Screenshot 2024-06-02 at 11 24 40PM](https://codeberg.org/uzu/strudel/assets/47068718/840be744-a13e-4d7b-ab09-50d3a70b1f85)
### Better sample upload support
you can now upload large amounts of samples much faster across all browsers including on IOS devices. supported filetypes now include: ogg flac mp3 wav aac m4a
### experimental tidal syntax
The new `tidal` function allows you to write strudel patterns in tidal syntax:
```plaintext
await initTidal()
tidal`
d1 $ s "bd*4"
d2 $ s "[- hh]*4"
`
```
As we're looking to improve compatibility with tidal, we're happy to hear feedback.
## breaking changes
This release comes with a bunch of breaking changes. If you find your patterns to sound different, check out the PRs below for guidance on how to update them. Most of these changes shouldn't affect a lot of patterns.
In case of doubt, add the line `// @version 1.0` to your old pattern.
If you're having problems, please let us know!
- remove legacy legato + duration implementations by @felixroos in https://codeberg.org/uzu/strudel/pull/965
- Velocity in value by @felixroos in https://codeberg.org/uzu/strudel/pull/974
- use ireal as default voicing dict by @felixroos https://codeberg.org/uzu/strudel/pull/967
- Color in hap value by @felixroos https://codeberg.org/uzu/strudel/pull/1007
- rename trig -> reset, trigzero -> restart by @felixroos https://codeberg.org/uzu/strudel/pull/1010
- remove dangerous arithmetic feature by @felixroos https://codeberg.org/uzu/strudel/pull/1030
- change fanchor to 0 by @daslyfe https://codeberg.org/uzu/strudel/pull/1107
## superdough features
- replace shape with distort in learn doc by @daslyfe https://codeberg.org/uzu/strudel/pull/982
- Worklet Improvents / fixes by @daslyfe https://codeberg.org/uzu/strudel/pull/963
- supersaw oscillator by @daslyfe https://codeberg.org/uzu/strudel/pull/978
- Add analog-style ladder filter by @daslyfe https://codeberg.org/uzu/strudel/pull/1103
- Calculate phaser modulation phase based on time by @daslyfe https://codeberg.org/uzu/strudel/pull/1110
- rollback phaser by @daslyfe https://codeberg.org/uzu/strudel/pull/1113
## editor / ui features
- 'Enable Bracket Matching' option in Codemirror by @eefano https://codeberg.org/uzu/strudel/pull/956
- REPL sync between windows by @daslyfe https://codeberg.org/uzu/strudel/pull/900
- inline viz / widgets package by @felixroos https://codeberg.org/uzu/strudel/pull/989
- Inline punchcard + spiral by @felixroos https://codeberg.org/uzu/strudel/pull/1008
- More fonts by @felixroos https://codeberg.org/uzu/strudel/pull/1023
- better theme integration for visuals + various fixes by @felixroos https://codeberg.org/uzu/strudel/pull/1024
- add setting for sync flag by @felixroos https://codeberg.org/uzu/strudel/pull/1025
- add closeBrackets setting by @felixroos https://codeberg.org/uzu/strudel/pull/1031
- add font file types to offline cache by @felixroos https://codeberg.org/uzu/strudel/pull/1032
- pitchwheel visual by @felixroos https://codeberg.org/uzu/strudel/pull/1041
- repl: set document.title from @title by @kasparsj https://codeberg.org/uzu/strudel/pull/1090
- Samples tab improvements by @daslyfe https://codeberg.org/uzu/strudel/pull/1102
## language features
- pickOut(), pickRestart(), pickReset() by @eefano https://codeberg.org/uzu/strudel/pull/950
- Auto await samples by @felixroos https://codeberg.org/uzu/strudel/pull/955
- feat: can now invert euclid pulses with negative numbers by @felixroos https://codeberg.org/uzu/strudel/pull/959
- Nested controls by @felixroos https://codeberg.org/uzu/strudel/pull/973
- alias - for ~ by @yaxu https://codeberg.org/uzu/strudel/pull/981
- Beat-oriented functionality by @yaxu https://codeberg.org/uzu/strudel/pull/976
- Labeled statements by @felixroos https://codeberg.org/uzu/strudel/pull/991
- accidentals in scale degrees by @eefano https://codeberg.org/uzu/strudel/pull/1000
- Feature: tactus marking by @yaxu https://codeberg.org/uzu/strudel/pull/1021
- Tactus tidy by @yaxu https://codeberg.org/uzu/strudel/pull/1027
- Wax, wane, taper and taperlist by @yaxu https://codeberg.org/uzu/strudel/pull/1042
- transpose: support all combinations of numbers and strings for notes and intervals by @felixroos https://codeberg.org/uzu/strudel/pull/1048
- anonymous patterns + muting by @felixroos https://codeberg.org/uzu/strudel/pull/1059
- add swing + swingBy by @felixroos https://codeberg.org/uzu/strudel/pull/1038
- Stepwise functions from Tidal by @yaxu https://codeberg.org/uzu/strudel/pull/1060
- Tactus tweaks - fixes for maintaining tactus and highlight locations by @yaxu https://codeberg.org/uzu/strudel/pull/1065
- Fix stepjoin by @yaxu https://codeberg.org/uzu/strudel/pull/1067
- More tactus tidying by @yaxu https://codeberg.org/uzu/strudel/pull/1071
- Tactus calculation toggle and breaking change to tactus calculation in fast/slow/hurry by @yaxu https://codeberg.org/uzu/strudel/pull/1081
- hs2js package / tidal parser by @felixroos https://codeberg.org/uzu/strudel/pull/870
- Add the mousex and mousey signal by @Enelg52 https://codeberg.org/uzu/strudel/pull/1112
- can now access strudelMirror from repl by @felixroos https://codeberg.org/uzu/strudel/pull/1117
## sampler
If you have nodejs installed on your system, you can now use [@strudel/sampler](https://www.npmjs.com/package/@strudel/sampler) to serve samples from disk to the REPL or flok.
- local sample server cli by @felixroos https://codeberg.org/uzu/strudel/pull/1033
- Fix sampler paths by @felixroos https://codeberg.org/uzu/strudel/pull/1034
- Fix sampler windows by @felixroos https://codeberg.org/uzu/strudel/pull/1108
- fix sampler on windows by @geikha https://codeberg.org/uzu/strudel/pull/1109
## docs
- V1 release notes by @felixroos https://codeberg.org/uzu/strudel/pull/935
- Minor documentation error: Update first-sounds.mdx by @mhetrick https://codeberg.org/uzu/strudel/pull/941
- Update synths.mdx by @andresgottlieb https://codeberg.org/uzu/strudel/pull/984
- using strudel in your project guide + cleanup examples by @felixroos https://codeberg.org/uzu/strudel/pull/1006
- Document signals by @ilesinge https://codeberg.org/uzu/strudel/pull/1015
- improve tutorial + custom samples doc by @felixroos https://codeberg.org/uzu/strudel/pull/1053
- fix cr typo on first-sounds.mdx by @cleary https://codeberg.org/uzu/strudel/pull/1068
- fix first sounds typo by @cleary https://codeberg.org/uzu/strudel/pull/1069
- add `<...>` to first-sounds.mdx recap by @cleary https://codeberg.org/uzu/strudel/pull/1070
- add nesting to `off` example variation in pattern-effects.mdx by @cleary https://codeberg.org/uzu/strudel/pull/1075
- fix translation issue in first-effects.mdx by @cleary https://codeberg.org/uzu/strudel/pull/1072
- add signals to recap in first-effects.mdx by @cleary https://codeberg.org/uzu/strudel/pull/1073
- fix docs on alignment.mdx by @diegodorado https://codeberg.org/uzu/strudel/pull/1076
- fix little dub tune example by @lukad https://codeberg.org/uzu/strudel/pull/1104
- clarify `off` in pattern-effects.mdx by @cleary https://codeberg.org/uzu/strudel/pull/1074
- Fixes drawPianoroll import in codemirror example by @giohappy https://codeberg.org/uzu/strudel/pull/1116
- Migrate tutorial fanchor by @felixroos https://codeberg.org/uzu/strudel/pull/1122
## internals
- remove cjs builds by @felixroos https://codeberg.org/uzu/strudel/pull/945
- controls refactoring: simplify exports by @felixroos https://codeberg.org/uzu/strudel/pull/962
- move canvas related helpers from core to new draw package by @felixroos https://codeberg.org/uzu/strudel/pull/971
- remove canvas, externalize samples, delete junk by @felixroos https://codeberg.org/uzu/strudel/pull/1003
- Improve performance of ! (replicate) by @yaxu https://codeberg.org/uzu/strudel/pull/1084
- Benchmarks by @yaxu https://codeberg.org/uzu/strudel/pull/1079
## fixes
- fix midi issue on firefox and added quote error by @Enelg52 https://codeberg.org/uzu/strudel/pull/936
- fix: pianoroll sorting by @felixroos https://codeberg.org/uzu/strudel/pull/938
- account for cps in midi time duration by @daslyfe https://codeberg.org/uzu/strudel/pull/954
- fix script importable packages (web + repl) by @felixroos https://codeberg.org/uzu/strudel/pull/957
- fix: reset global fx on pattern change by @felixroos https://codeberg.org/uzu/strudel/pull/960
- add debounce to logger by @felixroos https://codeberg.org/uzu/strudel/pull/968
- fix for transpose(): preserve hap value object structure by @eefano https://codeberg.org/uzu/strudel/pull/966
- fix: clear hydra on reset by @felixroos https://codeberg.org/uzu/strudel/pull/983
- little fix for withVal by @eefano https://codeberg.org/uzu/strudel/pull/980
- fix: share now shares what's visible instead of active by @felixroos https://codeberg.org/uzu/strudel/pull/985
- Fix pure mini highlight by @yaxu https://codeberg.org/uzu/strudel/pull/994
- fix: await injectPatternMethods by @felixroos https://codeberg.org/uzu/strudel/pull/1012
- update undocumented script by @felixroos https://codeberg.org/uzu/strudel/pull/1013
- eliminate chromium clock jitter by @felixroos https://codeberg.org/uzu/strudel/pull/1004
- Repl sync fixes by @daslyfe https://codeberg.org/uzu/strudel/pull/1014
- hotfix for 1017 by @daslyfe https://codeberg.org/uzu/strudel/pull/1020
- fix cyclist fizzling out by @felixroos https://codeberg.org/uzu/strudel/pull/1046
- Midi Time hotfix for scheduler updates by @daslyfe https://codeberg.org/uzu/strudel/pull/1047
- fix: do not reset cc input values on each eval by @felixroos https://codeberg.org/uzu/strudel/pull/1054
- Fix wchooseCycles not picking the whole pattern by @ilesinge https://codeberg.org/uzu/strudel/pull/1061
- fix OSC timing for recent scheduler updates by @daslyfe https://codeberg.org/uzu/strudel/pull/1062
- clarify license by @yaxu https://codeberg.org/uzu/strudel/pull/1064
- fix failing format test by @daslyfe https://codeberg.org/uzu/strudel/pull/1077
- fix: url parsing with extra params by @felixroos https://codeberg.org/uzu/strudel/pull/1083
- fix: csound + dough timing by @felixroos https://codeberg.org/uzu/strudel/pull/1086
- fix: missing events due to premature worklet cleanup by @felixroos https://codeberg.org/uzu/strudel/pull/1089
- Use sessionStorage for viewingPatternData and activePattern by @kasparsj https://codeberg.org/uzu/strudel/pull/1091
- osc: couple of fixes by @kasparsj https://codeberg.org/uzu/strudel/pull/1093
- web package fixes by @felixroos https://codeberg.org/uzu/strudel/pull/1044
- Fix audio worklets by @daslyfe https://codeberg.org/uzu/strudel/pull/1114
- fix: use full repl in web package by @felixroos https://codeberg.org/uzu/strudel/pull/1119
- [BUG FIX] Audio worklets sometimes dont load by @daslyfe https://codeberg.org/uzu/strudel/pull/1121
## New Contributors
- @mhetrick made their first contribution https://codeberg.org/uzu/strudel/pull/941
- @eefano made their first contribution https://codeberg.org/uzu/strudel/pull/956
- @Enelg52 made their first contribution https://codeberg.org/uzu/strudel/pull/936
- @andresgottlieb made their first contribution https://codeberg.org/uzu/strudel/pull/984
- @cleary made their first contribution https://codeberg.org/uzu/strudel/pull/1068
- @diegodorado made their first contribution https://codeberg.org/uzu/strudel/pull/1076
- @lukad made their first contribution https://codeberg.org/uzu/strudel/pull/1104
- @giohappy made their first contribution https://codeberg.org/uzu/strudel/pull/1116
A huge thanks to all contributors!!!
## Packages
- @strudel/codemirror@1.1.0
- @strudel/core@1.1.0
- @strudel/csound@1.1.0
- @strudel/draw@1.1.0
- @strudel/embed@1.1.0
- hs2js@0.1.0
- @strudel/hydra@1.1.0
- @strudel/midi@1.1.0
- @strudel/mini@1.1.0
- @strudel/osc@1.1.0
- @strudel/repl@1.1.0
- @strudel/sampler@0.1.0
- @strudel/serial@1.1.0
- @strudel/soundfonts@1.1.0
- superdough@1.1.0
- @strudel/tidal@0.1.0
- @strudel/tonal@1.1.0
- @strudel/transpiler@1.1.0
- @strudel/web@1.1.0
- @strudel/webaudio@1.1.0
- @strudel/xen@1.1.0
**Full Changelog**: https://codeberg.org/uzu/strudel/compare/v1.0.0...v1.1.0
@@ -0,0 +1,186 @@
---
title: 'Release Notes v1.2.0'
description: ''
date: '2025-05-01'
tags: ['meta']
author: froos
---
## What's Changed
## highlights
- [stepwise functions](https://strudel.cc/learn/stepwise/) ([PR](https://github.com/tidalcycles/strudel/pull/1262))
- [midimaps](https://strudel.cc/learn/input-output/#midimaps) ([PR](https://github.com/tidalcycles/strudel/pull/1274))
- [spectrum](https://strudel.cc/learn/visual-feedback/#spectrum) ([PR](https://github.com/tidalcycles/strudel/pull/1213))
- [mqtt](https://strudel.cc/learn/input-output/#mqtt) ([PR](https://github.com/tidalcycles/strudel/pull/1224))
- pulse oscillator (todo: https://github.com/tidalcycles/strudel/issues/1336) ([PR](https://github.com/tidalcycles/strudel/pull/1304))
- theme improvements
## breaking changes
- [breaking change] Sample signals from query onset, rather than midpoint by @yaxu in https://github.com/tidalcycles/strudel/pull/1278
- change behaviour of polymeter, and remove polymeterSteps by @yaxu in https://github.com/tidalcycles/strudel/pull/1302
- Polish, rename, and document stepwise functions by @yaxu in https://github.com/tidalcycles/strudel/pull/1262
### superdough
- feat: Create Pulse Oscillator with variable PWM by @daslyfe in https://github.com/tidalcycles/strudel/pull/1304
- add num samples (edited numbers) by @yaxu in https://github.com/tidalcycles/strudel/pull/1309
- Add num samples from 0 up to 20 by @yaxu in https://github.com/tidalcycles/strudel/pull/1310
- feat: add max polyphony feature for superdough by @daslyfe in https://github.com/tidalcycles/strudel/pull/1317
### docs
- doc: visual functions + refactor onPaint by @felixroos in https://github.com/tidalcycles/strudel/pull/1125
- Labeled statements doc by @felixroos in https://github.com/tidalcycles/strudel/pull/1126
- Correct spelling mistakes by @EdwardBetts in https://github.com/tidalcycles/strudel/pull/1183
- remove redundant example for cat, update snapshot by @kdiab in https://github.com/tidalcycles/strudel/pull/1189
- chore: Edit run locally instructions in README.md by @ChinoUkaegbu in https://github.com/tidalcycles/strudel/pull/1206
- suggested changes to voicings.mdx by @bwagner in https://github.com/tidalcycles/strudel/pull/1231
- Documentation for all/each, and bugfix for each by @yaxu in https://github.com/tidalcycles/strudel/pull/1233
- Update documentation for param value modification by @gillespi314 in https://github.com/tidalcycles/strudel/pull/1238
- fix docs for beat function by @daslyfe in https://github.com/tidalcycles/strudel/pull/1248
- understand voicings page by @felixroos in https://github.com/tidalcycles/strudel/pull/1230
- add reference package by @felixroos in https://github.com/tidalcycles/strudel/pull/1252
- Stepwise documentation tweaks, with mridangam samples by @yaxu in https://github.com/tidalcycles/strudel/pull/1275
- showcase tweaks by @yaxu in https://github.com/tidalcycles/strudel/pull/1291
- Signpost licenses for source code and samples a bit more, ref #1277 by @yaxu in https://github.com/tidalcycles/strudel/pull/1289
- Fix misplaced ending sentence by @makmanalp in https://github.com/tidalcycles/strudel/pull/1296
- Fix typo pattnr by @ReneNyffenegger in https://github.com/tidalcycles/strudel/pull/1316
- update docs to reflect import sounds tab change by @hpunq in https://github.com/tidalcycles/strudel/pull/1332
### ui improvements
- Udels (MultiFrame Strudel) Revisited by @daslyfe in https://github.com/tidalcycles/strudel/pull/1132
- Create audio target selector for OSC/Superdirt by @daslyfe in https://github.com/tidalcycles/strudel/pull/1160
- Add a search bar to the REPL Reference tab by @netux in https://github.com/tidalcycles/strudel/pull/1165
- Adding search bar (soundtab.jsx) by @Bubobubobubobubo in https://github.com/tidalcycles/strudel/pull/1185
- add 2 new ui settings by @felixroos in https://github.com/tidalcycles/strudel/pull/1200
- Theme glowup by @felixroos in https://github.com/tidalcycles/strudel/pull/1268
- Create Pattern Page Pagination by @daslyfe in https://github.com/tidalcycles/strudel/pull/1287
- feat: Theme improvements by @daslyfe in https://github.com/tidalcycles/strudel/pull/1295
- feat: new themes + theme improvements by @daslyfe in https://github.com/tidalcycles/strudel/pull/1326
- Add new "import-sounds" tab with explanation on folder import by @hpunq in https://github.com/tidalcycles/strudel/pull/1329
- Add Icon to import sample button by @daslyfe in https://github.com/tidalcycles/strudel/pull/1331
- better spacing in zen mode by @felixroos in https://github.com/tidalcycles/strudel/pull/1147
- Screenreader improvements by @yaxu in https://github.com/tidalcycles/strudel/pull/1158
- colorize console + tweak header by @felixroos in https://github.com/tidalcycles/strudel/pull/1203
- Menu Panel Improvements! by @daslyfe in https://github.com/tidalcycles/strudel/pull/1193
- Make panel hover behavior optional by @daslyfe in https://github.com/tidalcycles/strudel/pull/1199
- REPL: solo and sync configuration by @bthj in https://github.com/tidalcycles/strudel/pull/1214
- enhancement: make error messages easier to read by @daslyfe in https://github.com/tidalcycles/strudel/pull/1315
### mqtt
- MQTT support by @yaxu in https://github.com/tidalcycles/strudel/pull/1224
- MQTT - if password isn't provided, prompt for one by @yaxu in https://github.com/tidalcycles/strudel/pull/1249
- MQTT - support adding hap duration and cps metadata to JSON messages by @yaxu in https://github.com/tidalcycles/strudel/pull/1279
- make mqtt topic patternable by @yaxu in https://github.com/tidalcycles/strudel/pull/1280
- Bugfix: update mqtt connections dictionary by @yaxu in https://github.com/tidalcycles/strudel/pull/1281
- mqtt bugfix - connection check by @yaxu in https://github.com/tidalcycles/strudel/pull/1282
### new functions
- Add scramble and shuffle by @yaxu in https://github.com/tidalcycles/strudel/pull/1167
- polyJoin by @yaxu in https://github.com/tidalcycles/strudel/pull/1168
- Add seqPLoop from Tidal by @yaxu in https://github.com/tidalcycles/strudel/pull/1182
- add filter + filterWhen + within by @felixroos in https://github.com/tidalcycles/strudel/pull/1039
- Add bite function by @yaxu in https://github.com/tidalcycles/strudel/pull/1187
- markcss by @felixroos in https://github.com/tidalcycles/strudel/pull/1202
- "beat" function for "step sequencer" style rhythm notation by @daslyfe in https://github.com/tidalcycles/strudel/pull/1237
- Add s_zip for 'cat'-ing patterns together step-by-step, bugfix `steps` by @yaxu in https://github.com/tidalcycles/strudel/pull/1208
- "stretch" function (phase vocoder) by @daslyfe in https://github.com/tidalcycles/strudel/pull/1130
- add basic spectrum function by @felixroos in https://github.com/tidalcycles/strudel/pull/1213
- Add onKey function for custom key commands for patterns by @daslyfe in https://github.com/tidalcycles/strudel/pull/1235
- Add binary and binaryN by @heerman in https://github.com/tidalcycles/strudel/pull/1226
- midimaps by @felixroos in https://github.com/tidalcycles/strudel/pull/1274
- small feat: Add alias for segment and ribbon by @daslyfe in https://github.com/tidalcycles/strudel/pull/1314
- feat: Create scrub function for scrubbing an audio file by @daslyfe in https://github.com/tidalcycles/strudel/pull/1321
- feat: Improve gain curve by @daslyfe in https://github.com/tidalcycles/strudel/pull/1318
- Chop chop by @yaxu in https://github.com/tidalcycles/strudel/pull/1078
### more
- Make `all()` post-stack again, and add `each()` for pre-stack by @yaxu in https://github.com/tidalcycles/strudel/pull/1229
- Add stepBind, and some toplevel aliases for binds and withValue by @yaxu in https://github.com/tidalcycles/strudel/pull/1241
- Make cps patternable by @eefano in https://github.com/tidalcycles/strudel/pull/1001
- Allow wchooseCycles probabilities to be patterned by @yaxu in https://github.com/tidalcycles/strudel/pull/1292
- @strudel/sampler improvements by @felixroos in https://github.com/tidalcycles/strudel/pull/1288
### refactor
- expose comment commands by @felixroos in https://github.com/tidalcycles/strudel/pull/1136
- containerize/seperate out boolean checks for repl types/Repl logic into bespoke components. by @daslyfe in https://github.com/tidalcycles/strudel/pull/1163
- Improve + simplify neocyclist timing by @daslyfe in https://github.com/tidalcycles/strudel/pull/1164
- Make phaser control consistent with superdirt by @daslyfe in https://github.com/tidalcycles/strudel/pull/1178
- Revert "Make phaser control consistent with superdirt" by @daslyfe in https://github.com/tidalcycles/strudel/pull/1179
- make phaser control match superdirt by @daslyfe in https://github.com/tidalcycles/strudel/pull/1180
- refactor sampler by @felixroos in https://github.com/tidalcycles/strudel/pull/1101
- update lockfile + minor versions by @felixroos in https://github.com/tidalcycles/strudel/pull/1198
- Preserve tactus for 'degrade' and friends, and tidy up 'pick' and friends by @yaxu in https://github.com/tidalcycles/strudel/pull/1205
- Apply `all` function to individual patterns rather than final stack by @yaxu in https://github.com/tidalcycles/strudel/pull/1209
- Revert "Fix sometimes" by @yaxu in https://github.com/tidalcycles/strudel/pull/1267
- patchday by @felixroos in https://github.com/tidalcycles/strudel/pull/1264
- Rename repeat back to extend by @yaxu in https://github.com/tidalcycles/strudel/pull/1285
- Send delta in OSC message in seconds, to match tidal/superdirt by @yaxu in https://github.com/tidalcycles/strudel/pull/1323
### fixes
- Fix clock worker dependency path in module builds by @matthewkaney in https://github.com/tidalcycles/strudel/pull/1129
- Fix bug in Fraction.lcm by @yaxu in https://github.com/tidalcycles/strudel/pull/1133
- Fix tactus marking in mininotation by @yaxu in https://github.com/tidalcycles/strudel/pull/1144
- Fix loopAt tactus by @yaxu in https://github.com/tidalcycles/strudel/pull/1145
- Fix OSC clock jitter by @daslyfe in https://github.com/tidalcycles/strudel/pull/1157
- [CORS HOTFIX] by @daslyfe in https://github.com/tidalcycles/strudel/pull/1162
- Fixes fit so it works after a chop or slice by @yaxu in https://github.com/tidalcycles/strudel/pull/1171
- fix sample speed when using splice and fit with superdirt by @daslyfe in https://github.com/tidalcycles/strudel/pull/1172
- handle midin device not found error by @felixroos in https://github.com/tidalcycles/strudel/pull/1146
- Fix serial timing by @yaxu in https://github.com/tidalcycles/strudel/pull/1188
- Fix regression for d1, p1, p(n) by @yaxu in https://github.com/tidalcycles/strudel/pull/1227
- Fix sometimes by @yaxu in https://github.com/tidalcycles/strudel/pull/1243
- Fix sf2 timing by @felixroos in https://github.com/tidalcycles/strudel/pull/1272
- Fix "squeezejoin" and functions using it, including "bite" by @yaxu in https://github.com/tidalcycles/strudel/pull/1286
- Fixes inverted triangle wave by renaming it to "itri", making non-inverted "tri" by @yaxu in https://github.com/tidalcycles/strudel/pull/1283
- Hotfix: prevent undefined pattern code from crashing strudel on load by @daslyfe in https://github.com/tidalcycles/strudel/pull/1297
- Fix test error #1297 by @nkymut in https://github.com/tidalcycles/strudel/pull/1298
- bugfix zoom stepcount by @yaxu in https://github.com/tidalcycles/strudel/pull/1301
- bugfix: Allow single param to be used in the as function by @daslyfe in https://github.com/tidalcycles/strudel/pull/1312
- fix: replace empty spaces in registered sound keys by @daslyfe in https://github.com/tidalcycles/strudel/pull/1319
- FIX: Multichannel Audio by @daslyfe in https://github.com/tidalcycles/strudel/pull/1322
- fix: udels header by @daslyfe in https://github.com/tidalcycles/strudel/pull/1325
- fix: disable astro toolbar by default by @daslyfe in https://github.com/tidalcycles/strudel/pull/1324
- FIX: sound import order by @daslyfe in https://github.com/tidalcycles/strudel/pull/1333`
## New Contributors
- @EdwardBetts made their first contribution in https://github.com/tidalcycles/strudel/pull/1183
- @netux made their first contribution in https://github.com/tidalcycles/strudel/pull/1165
- @kdiab made their first contribution in https://github.com/tidalcycles/strudel/pull/1189
**Full Changelog**: https://github.com/tidalcycles/strudel/compare/v1.1.0...v1.1.1
## packages
- @strudel/codemirror@1.2.0
- @strudel/core@1.2.0
- @strudel/csound@1.2.0
- @strudel/draw@1.2.0
- @strudel/gamepad@1.2.0
- @strudel/hydra@1.2.0
- @strudel/midi@1.2.0
- @strudel/mini@1.2.0
- @strudel/motion@1.2.0
- @strudel/mqtt@1.2.0
- @strudel/osc@1.2.0
- @strudel/reference@1.2.0
- @strudel/repl@1.2.0
- @strudel/sampler@0.2.0
- @strudel/serial@1.2.0
- @strudel/soundfonts@1.2.0
- superdough@1.2.0
- @strudel/tonal@1.2.0
- @strudel/transpiler@1.2.0
- @strudel/web@1.2.0
- @strudel/webaudio@1.2.0
- @strudel/xen@1.2.0
+2
View File
@@ -30,6 +30,7 @@ export function MiniRepl({
maxHeight,
autodraw,
drawTime,
mondo = false,
}) {
const code = tunes ? tunes[0] : tune;
const id = useMemo(() => s4(), []);
@@ -85,6 +86,7 @@ export function MiniRepl({
},
beforeStart: () => audioReady,
afterEval: ({ code }) => setVersionDefaultsFrom(code),
mondo,
});
// init settings
editor.setCode(code);
@@ -95,7 +95,7 @@ Diese Kombinationen von Buchstaben stehen für verschiedene Teile eines Schlagze
- `mt` = **m**iddle tom
- `ht` = **h**igh tom
- `rd` = **r**i**d**e cymbal
- `rd` = **cr**ash cymbal
- `cr` = **cr**ash cymbal
Probier verschiedene Sounds aus!
+28
View File
@@ -57,6 +57,34 @@ Each filter has 2 parameters:
<JsDoc client:idle name="vowel" h={0} />
# Amplitude Modulation
Amplitude modulation changes the amplitude (gain) periodically over time.
## am
<JsDoc client:idle name="am" h={0} />
## tremolosync
<JsDoc client:idle name="tremolosync" h={0} />
## tremolodepth
<JsDoc client:idle name="tremolodepth" h={0} />
## tremoloskew
<JsDoc client:idle name="tremoloskew" h={0} />
## tremolophase
<JsDoc client:idle name="tremolophase" h={0} />
## tremoloshape
<JsDoc client:idle name="tremoloshape" h={0} />
# Amplitude Envelope
The amplitude [envelope](<https://en.wikipedia.org/wiki/Envelope_(music)>) controls the dynamic contour of a sound.
+191
View File
@@ -0,0 +1,191 @@
---
title: Mondo Notation
layout: ../../layouts/MainLayout.astro
---
import { MiniRepl } from '../../docs/MiniRepl';
import { JsDoc } from '../../docs/JsDoc';
# Mondo Notation
"Mondo Notation" is a new kind of notation that is similar to [Mini Notation](/learn/mini-notation/), but with enough abilities to make it work as a standalone pattern language.
Here's an example:
<MiniRepl
mondo
client:idle
tune={`$ note (c2 # euclid <3 6 3> <8 16>) # *2
# s "sine" # add (note [0 <12 24>]*2)
# dec(sine # range .2 2)
# room .5
# lpf (sine/3 # range 120 400)
# lpenv (rand # range .5 4)
# lpq (perlin # range 5 12 # * 2)
# dist 1 # fm 4 # fmh 5.01 # fmdecay <.1 .2>
# postgain .6 # delay .1 # clip 5
$ s [bd bd bd bd] # bank tr909 # clip .5
# ply <1 [1 [2 4]]>
$ s oh\*4 # press # bank tr909 # speed.8
# dec (<.02 .05>\*2 # add (saw/8 # range 0 1))
`}
/>
## Mondo in the REPL
For now, you can only use mondo in the repl like this:
<MiniRepl client:idle tune={'mondo`s hh*8`'} />
The rest of this site will only use the mondo notation itself.
In the future, the REPL might get a way to use mondo notation directly.
## Calling Functions
Compared to Mini Notation, the most notable feature of Mondo Notation is the ability to call functions using round brackets:
<MiniRepl mondo client:idle tune={`(s hh*8)`} />
The first element inside the brackets is the function name. In JS, this would look like:
<MiniRepl client:idle tune={`s("hh*8")`} />
The outermost parens are not needed, so we can drop them:
<MiniRepl mondo client:idle tune={`s hh*8`} />
## Mini Notation Features
Besides function calling with round parens, Mondo Notation has a lot in common with Mini Notation:
### Brackets
- `[]` for 1-cycle sequences
- `<>` for multi-cycle sequences
- `{}` for stepped sequences (more on that later)
### Infix Operators
- \* => [fast](/learn/time-modifiers/#fast)
- / => [slow](/learn/time-modifiers/#slow)
- ! => [extend](/learn/stepwise/#extend)
- @ => [expand](/learn/stepwise/#expand)
- % => [pace](/learn/stepwise/#pace)
- ? => [degradeBy](/learn/random-modifiers/#degradeby) (currently requires right operand)
- : => tail (creates a list)
- .. => range (between numbers)
- , => [stack](/learn/factories/#stack)
- | => [chooseIn](/learn/random-modifiers/#choose)
### Example
<MiniRepl
mondo
client:idle
tune={`note <
[e5 [b4 c5] d5 [c5 b4]]
[a4 [a4 c5] e5 [d5 c5]]
[b4 [~ c5] d5 e5]
[c5 a4 a4 ~]
[[~ d5] [~ f5] a5 [g5 f5]]
[e5 [~ c5] e5 [d5 c5]]
[b4 [b4 c5] d5 e5]
[c5 a4 a4 ~]
>`}
/>
## Chaining Functions
Similar to how "." works in javascript (JS), we can chain functions calls with the "#" operator:
<MiniRepl
mondo
client:idle
tune={`n <0 2 4 [3 1] -1>*4
# scale C4:minor
# jux rev
# dec .2
# delay .5`}
/>
Here's the same written in JS:
<MiniRepl
client:idle
tune={`n("<0 2 4 [3 1] -1>*4")
.scale("C4:minor")
.jux(rev)
.dec(.2)
.delay(.5)`}
/>
### Chaining Functions Locally
A function can be applied to a single element by wrapping it in round parens:
<MiniRepl mondo client:idle tune={`s [bd hh bd (cp # delay .6)] # bank tr909`} />
in this case, `delay .6` will only be applied to `cp`. compare this with the JS version:
<MiniRepl client:idle tune={`s(seq("bd", "hh", "bd", "cp".delay(.6))).bank('tr909')`} />
here we can see how much we can save when there's no boundary between mini notation and function calls!
### Chaining Infix Operators
Infix operators exist as regular functions, so they can be chained as well:
<MiniRepl client:idle mondo tune={`s [bd hh] # bank tr909 # *2`} />
In this case, the \*2 will be applied to the whole pattern.
### Lambda Functions
Some functions in strudel expect a function as input, for example:
<MiniRepl client:idle tune={`n("0 .. 7").scale("C:minor").sometimes(x=>x.dec(.1))`} />
in mondo, the `x=>x.` can be shortened to:
<MiniRepl client:idle mondo tune={`n 0..7 # scale C:minor # sometimes (# dec .1)`} />
chaining works as expected:
<MiniRepl client:idle mondo tune={`n 0..7 # scale C:minor # sometimes (# dec .1 # jux rev)`} />
## Strings
You can use "double quotes" and 'single quotes' to get a string:
<MiniRepl client:idle mondo tune={`n 0..7 # scale 'C minor'`} />
## Multiple Patterns
The `$` sign can be used to separate multiple patterns:
<MiniRepl
client:idle
mondo
tune={`$ s [bd rim [~ bd] rim] # bank tr707
$ chord <Dm9!3 Db7> # voicing
# struct[x ~ ~ x ~ x ~ ~] # delay .5`}
/>
The `$` sign is an alias for `,` so it will create a stack behind the scenes.
## variables
using the `def` keyword, you can define variables:
<MiniRepl
client:idle
mondo
tune={`
$ def melody [0 1 2 3]
$ n melody # scale C:minor
`}
/>
+15
View File
@@ -163,6 +163,21 @@ The last section could be written as:
}
```
Please note that browsers will often cache `strudel.json` on first load, and keep using the cached
version even if the orginal has been updated. If this bites you (for example while developing a new
sample pack), you can force the browser to download a new copy by i.e. changing capitalization of one
character in the URL, or adding a URL attribute, such as:
```javascript
samples('https://raw.githubusercontent.com/tidalcycles/Dirt-Samples/master/strudel.json?version=2');
```
that gets ignored by GitHub (but changes the URL, forcing the browser to reload every time we increase
the version number).
It is also possible, of course, to just remove it from cache (deleting cache in browser Privacy settings,
or from the dev console if you're technically minded, or by using a cache deleting extension).
## Github Shortcut
Because loading samples from github is common, there is a shortcut:
+2
View File
@@ -67,6 +67,8 @@ Or using 2 beats per cycle:
s("bd sd, hh*4")`}
/>
You can use the `setcps` method to set the global tempo in cycles per second. `setcpm(x)` is the same as `setcps(x / 60)`.
<Box>
To set a specific bpm, use `setcpm(bpm/bpc)`
@@ -125,7 +125,7 @@ function UserPatterns({ context }) {
style={{ display: 'none' }}
type="file"
multiple
accept="text/plain,application/json"
accept="text/plain,text/x-markdown,application/json"
onChange={(e) => importPatterns(e.target.files)}
/>
import
@@ -21,7 +21,11 @@ export function Reference() {
return true;
}
return entry.name.includes(search) || (entry.synonyms?.some((s) => s.includes(search)) ?? false);
const lowCaseSearch = search.toLowerCase();
return (
entry.name.toLowerCase().includes(lowCaseSearch) ||
(entry.synonyms?.some((s) => s.includes(lowCaseSearch)) ?? false)
);
});
}, [search]);
@@ -109,6 +109,8 @@ export function SettingsTab({ started }) {
togglePanelTrigger,
maxPolyphony,
multiChannelOrbits,
isTabIndentationEnabled,
isMultiCursorEnabled,
} = useSettings();
const shouldAlwaysSync = isUdels();
const canChangeAudioDevice = AudioContext.prototype.setSinkId != null;
@@ -262,6 +264,16 @@ export function SettingsTab({ started }) {
onChange={(cbEvent) => settingsMap.setKey('isLineWrappingEnabled', cbEvent.target.checked)}
value={isLineWrappingEnabled}
/>
<Checkbox
label="Enable Tab indentation"
onChange={(cbEvent) => settingsMap.setKey('isTabIndentationEnabled', cbEvent.target.checked)}
value={isTabIndentationEnabled}
/>
<Checkbox
label="Enable Multi-Cursor (Cmd/Ctrl+Click)"
onChange={(cbEvent) => settingsMap.setKey('isMultiCursorEnabled', cbEvent.target.checked)}
value={isMultiCursorEnabled}
/>
<Checkbox
label="Enable flashing on evaluation"
onChange={(cbEvent) => settingsMap.setKey('isFlashEnabled', cbEvent.target.checked)}
@@ -20,7 +20,7 @@ export function WelcomeTab({ context }) {
</p>
<p>
{/* To learn more about what this all means, check out the{' '} */}
To get started, check out the
To get started, check out the{' '}
<a href={`${baseNoTrailing}/workshop/getting-started/`} target="_blank">
interactive tutorial
</a>
@@ -43,7 +43,7 @@ export function WelcomeTab({ context }) {
</a>
. You can find the source code at{' '}
<a href="https://codeberg.org/uzu/strudel" target="_blank">
github
codeberg
</a>
. You can also find <a href="https://github.com/felixroos/dough-samples/blob/main/README.md">licensing info</a>{' '}
for the default sound banks there. Please consider to{' '}
+4 -1
View File
@@ -28,7 +28,10 @@ export async function prebake() {
prebake: true,
tag: 'drum-machines',
}),
samples(`${baseNoTrailing}/EmuSP12.json`, undefined, { prebake: true, tag: 'drum-machines' }),
samples(`${baseNoTrailing}/uzu-drumkit.json`, undefined, {
prebake: true,
tag: 'drum-machines',
}),
samples(`${baseNoTrailing}/mridangam.json`, undefined, { prebake: true, tag: 'drum-machines' }),
samples(
{
+6 -6
View File
@@ -69,32 +69,32 @@ stack(
export const giantSteps = `// John Coltrane - Giant Steps
let melody = note(
let melody = seq(
"[F#5 D5] [B4 G4] Bb4 [B4 A4]",
"[D5 Bb4] [G4 Eb4] F#4 [G4 F4]",
"Bb4 [B4 A4] D5 [D#5 C#5]",
"F#5 [G5 F5] Bb5 [F#5 F#5]",
)
).note()
stack(
// melody
melody.color('#F8E71C'),
// chords
chord(
seq(
"[B^7 D7] [G^7 Bb7] Eb^7 [Am7 D7]",
"[G^7 Bb7] [Eb^7 F#7] B^7 [Fm7 Bb7]",
"Eb^7 [Am7 D7] G^7 [C#m7 F#7]",
"B^7 [Fm7 Bb7] Eb^7 [C#m7 F#7]"
).dict('lefthand')
).chord().dict('lefthand')
.anchor(melody).mode('duck')
.voicing().color('#7ED321'),
// bass
note(
seq(
"[B2 D2] [G2 Bb2] [Eb2 Bb3] [A2 D2]",
"[G2 Bb2] [Eb2 F#2] [B2 F#2] [F2 Bb2]",
"[Eb2 Bb2] [A2 D2] [G2 D2] [C#2 F#2]",
"[B2 F#2] [F2 Bb2] [Eb2 Bb3] [C#2 F#2]"
).color('#00B8D4')
).note().color('#00B8D4')
).slow(20)
.pianoroll({fold:1})`;
+2
View File
@@ -13,6 +13,7 @@ import {
resetGlobalEffects,
resetLoadedSounds,
initAudioOnFirstClick,
resetDefaults,
} from '@strudel/webaudio';
import { setVersionDefaultsFrom } from './util.mjs';
import { StrudelMirror, defaultSettings } from '@strudel/codemirror';
@@ -181,6 +182,7 @@ export function useReplContext() {
const resetEditor = async () => {
(await getModule('@strudel/tonal'))?.resetVoicings();
resetDefaults();
resetGlobalEffects();
clearCanvas();
clearHydra();
+1
View File
@@ -84,6 +84,7 @@ export function loadModules() {
import('@strudel/gamepad'),
import('@strudel/motion'),
import('@strudel/mqtt'),
import('@strudel/mondo'),
];
if (isTauri()) {
modules = modules.concat([
+4
View File
@@ -21,6 +21,8 @@ export const defaultSettings = {
isSyncEnabled: false,
isLineWrappingEnabled: false,
isPatternHighlightingEnabled: true,
isTabIndentationEnabled: false,
isMultiCursorEnabled: false,
theme: 'strudelTheme',
fontFamily: 'monospace',
fontSize: 18,
@@ -77,6 +79,8 @@ export function useSettings() {
isLineWrappingEnabled: parseBoolean(state.isLineWrappingEnabled),
isFlashEnabled: parseBoolean(state.isFlashEnabled),
isSyncEnabled: isUdels() ? true : parseBoolean(state.isSyncEnabled),
isTabIndentationEnabled: parseBoolean(state.isTabIndentationEnabled),
isMultiCursorEnabled: parseBoolean(state.isMultiCursorEnabled),
fontSize: Number(state.fontSize),
panelPosition: state.activeFooter !== '' && !isUdels() ? state.panelPosition : 'bottom', // <-- keep this 'bottom' where it is!
isPanelPinned: parseBoolean(state.isPanelPinned),
+1 -1
View File
@@ -197,7 +197,7 @@ export async function importPatterns(fileList) {
if (file.type === 'application/json') {
const userPatterns = userPattern.getAll();
setUserPatterns({ ...userPatterns, ...parseJSON(content) });
} else if (file.type === 'text/plain') {
} else if (['text/x-markdown', 'text/plain'].includes(file.type)) {
const id = file.name.replace(/\.[^/.]+$/, '');
userPattern.update(id, { code: content });
}