mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-18 16:46:10 -04:00
Compare commits
266 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2d2c671e6f | |||
| d2f47262de | |||
| cb13eb7f3b | |||
| 96825f9fcc | |||
| 7eeae4292c | |||
| a29c5f1bd8 | |||
| b7a2386874 | |||
| 43a0c7e604 | |||
| 73d8afd61b | |||
| 87162a9f31 | |||
| c643f10530 | |||
| ae81f6d573 | |||
| 44ba1f85c3 | |||
| f34301b427 | |||
| 666cbf6568 | |||
| f31a5a4bbb | |||
| bbf0565007 | |||
| c41ac9a413 | |||
| ab1dd27875 | |||
| 788a4c9143 | |||
| 43c2f46196 | |||
| fdb60a3fc1 | |||
| 6c6ea3ab9f | |||
| 806c8925c9 | |||
| ed35f967b0 | |||
| 0bcc01ed0e | |||
| b7fac65a87 | |||
| 605cb98b8e | |||
| b8a0559012 | |||
| fb2f63ee26 | |||
| b59f36f40b | |||
| 2a618b42b7 | |||
| aa3db09f22 | |||
| 9fa01aa6ff | |||
| 999251e137 | |||
| 55d5cc9308 | |||
| 58301c380b | |||
| ee45337d89 | |||
| f2e1ee1aac | |||
| ee5bc0f3a6 | |||
| 273cb81da0 | |||
| 1cbf4c8c7e | |||
| 446ddc2c11 | |||
| 42d3510c74 | |||
| 92c17d6376 | |||
| 645ea30b53 | |||
| 0d63ec9146 | |||
| 9588272639 | |||
| aca3bea56b | |||
| a8d676641b | |||
| 4fd843f8cf | |||
| 73b0a3a0ef | |||
| 6dedeae6e1 | |||
| 14487ed5cf | |||
| 5419b0896c | |||
| f8f744dd87 | |||
| b0dfb44e96 | |||
| cdc068bb47 | |||
| 09c5c07bfb | |||
| 56962196ea | |||
| 8b4af5ce9d | |||
| 8034eb14b6 | |||
| 2739c89475 | |||
| cf79083edb | |||
| cbe9c9248d | |||
| e0c77a5fa8 | |||
| 339e91b026 | |||
| 25bfdd80e3 | |||
| 68c6d340ce | |||
| 91261b8b3f | |||
| 6e8bd1ff33 | |||
| b01865f0f5 | |||
| 4319b6d2d1 | |||
| 53d82e5126 | |||
| 90b74a72ad | |||
| c23f9b8629 | |||
| d752d0eb5e | |||
| 65fbdba047 | |||
| 6273b34254 | |||
| 4779dd13c0 | |||
| 469db7d5bd | |||
| 42269cf72b | |||
| 38bb0ca041 | |||
| 1949071259 | |||
| a119b83b65 | |||
| c939a8a0c1 | |||
| 5f26773c61 | |||
| 6cac8ba108 | |||
| 3eebccd566 | |||
| f81190bf35 | |||
| 065f4191f0 | |||
| b2d58ce0bd | |||
| 41b7939dac | |||
| 68c63cca7e | |||
| 2348d056cb | |||
| f469e48970 | |||
| 7e52fdd5ca | |||
| 29fceff9b3 | |||
| bdb5dabba5 | |||
| 3fe705427f | |||
| 21a1fe5056 | |||
| e40bdad6c3 | |||
| dcbe24d45c | |||
| d4607c68f7 | |||
| 026ae3c8e1 | |||
| f6d128842a | |||
| a6dac6ded3 | |||
| 4fcec82917 | |||
| 9e46b3cd00 | |||
| d56f151edb | |||
| 4b49c95e73 | |||
| cf922b036e | |||
| f7dedd6244 | |||
| 7af3c33814 | |||
| 8cd3be6f67 | |||
| 86e8ed2ac0 | |||
| 0d1e7f5c17 | |||
| fc9a9e33d2 | |||
| f00e28ced3 | |||
| 4c29677d5b | |||
| 07b8dc3f76 | |||
| ee514ee8ba | |||
| 97a0fb3e18 | |||
| ef42ca692a | |||
| 9ca49c587c | |||
| 3b38d936a8 | |||
| 7f8cdfa361 | |||
| 8da4217d69 | |||
| d3a04071eb | |||
| 0c5903d822 | |||
| f97f8be5a4 | |||
| d2ec9768f1 | |||
| 37218e8764 | |||
| 069fff673a | |||
| 5aed046b34 | |||
| 5dea15ade9 | |||
| 10487683d3 | |||
| 12967f2819 | |||
| 07b22a2c28 | |||
| fe13a7fe34 | |||
| 602cac5a35 | |||
| 11f697fa9c | |||
| d5957035fa | |||
| b80d7d226b | |||
| 8564dafbfb | |||
| dc66dab237 | |||
| a32d77b24d | |||
| 23836e2345 | |||
| 1a5c95d084 | |||
| 6a6464b0f7 | |||
| 60027e664f | |||
| 27ff329981 | |||
| df5ffb4736 | |||
| a194b908e7 | |||
| 79f5faa544 | |||
| 5c3f095ef2 | |||
| 283e5fde69 | |||
| f96ca562a2 | |||
| 58a936cf33 | |||
| a0d6fc47e0 | |||
| dd03ad6c14 | |||
| 2bbd306b94 | |||
| 766cccf335 | |||
| 9e2e5ce581 | |||
| e747c0b060 | |||
| 67bef933be | |||
| f1c0d8c8f8 | |||
| dd2552eda8 | |||
| ab9871640a | |||
| 615f71b099 | |||
| ff418c9f0c | |||
| 4c43d3d850 | |||
| a4cacc079e | |||
| 9df20fcbc5 | |||
| f4dd549a41 | |||
| cc445e89a3 | |||
| 08f8a7a17c | |||
| ab14d70c6c | |||
| ecfc6fd31e | |||
| 0fae8b2b10 | |||
| c38e4f7206 | |||
| 47717e872b | |||
| 903c065e26 | |||
| 3742bf384c | |||
| 1029f8674c | |||
| c801660b2a | |||
| 48d4541ed7 | |||
| 8007ea6a7e | |||
| 8e441ecb19 | |||
| c305e82f5c | |||
| 87cfa30508 | |||
| 2c224d5092 | |||
| 72eeaf446e | |||
| 51a806b0ba | |||
| 52840f9141 | |||
| 974503160d | |||
| d9e3ff3256 | |||
| b510ab0371 | |||
| 5eba78d795 | |||
| 884c13a22d | |||
| 90c5605409 | |||
| 3ae6443c59 | |||
| b370c405da | |||
| 36d1a68b9a | |||
| 58bbbecb2d | |||
| 1cdff32b5c | |||
| 7dbdb005b0 | |||
| e6c15dc3c5 | |||
| 1778d19bde | |||
| 56c3c0462c | |||
| 80102353d6 | |||
| d7dc158861 | |||
| b52c42c31d | |||
| f8739e341b | |||
| 1ead12a2a3 | |||
| c2feb6e214 | |||
| 3d74b8a2fa | |||
| 83a46c68dc | |||
| bcefce9df7 | |||
| dcb5af3339 | |||
| 1d56d79757 | |||
| 0b370bd40d | |||
| 07a5ae83b5 | |||
| cc60addbaa | |||
| 30b7429169 | |||
| 28ebf6559e | |||
| 1c6e3dd9a6 | |||
| 6bba661e24 | |||
| eccb20c3b7 | |||
| f210c4425b | |||
| e0e3ab941e | |||
| 9cc568fe3e | |||
| a638f9505f | |||
| 1b35dd0c55 | |||
| d394b4939f | |||
| c751d4eb79 | |||
| bb147abb7f | |||
| 1c3793e2ef | |||
| 1274641f89 | |||
| 803b50535f | |||
| 028af735c9 | |||
| d42cd6efaf | |||
| 2cf129408b | |||
| 0ed1c75c38 | |||
| 5588b62b40 | |||
| 03cb80b75b | |||
| 86a3fd6e22 | |||
| 27ebe7ba73 | |||
| 89934886f7 | |||
| f278c85f2a | |||
| 21e328569b | |||
| 369604aa42 | |||
| 023da097a1 | |||
| 0ad80c1af9 | |||
| 7182894eb6 | |||
| 914bc117a1 | |||
| 0f003abf52 | |||
| fb1976a6bc | |||
| 0e7b345010 | |||
| fd28cfc4f8 | |||
| b20467d6e3 | |||
| 068b95eacb | |||
| 95e4239fd5 | |||
| 05c900d291 | |||
| f698078f94 | |||
| a54b6f0359 |
+4
-1
@@ -1,4 +1,5 @@
|
|||||||
dist
|
dist
|
||||||
|
out
|
||||||
!docs/dist
|
!docs/dist
|
||||||
dist-*
|
dist-*
|
||||||
cabal-dev
|
cabal-dev
|
||||||
@@ -27,4 +28,6 @@ node_modules/
|
|||||||
repl-parcel
|
repl-parcel
|
||||||
mytunes.ts
|
mytunes.ts
|
||||||
doc
|
doc
|
||||||
.parcel-cache
|
out
|
||||||
|
.parcel-cache
|
||||||
|
repl_old
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
Version 3, 29 June 2007
|
Version 3, 19 November 2007
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
@@ -7,17 +7,15 @@
|
|||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
The GNU Affero General Public License is a free, copyleft license for
|
||||||
software and other kinds of works.
|
software and other kinds of works, specifically designed to ensure
|
||||||
|
cooperation with the community in the case of network server software.
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
The licenses for most software and other practical works are designed
|
||||||
to take away your freedom to share and change the works. By contrast,
|
to take away your freedom to share and change the works. By contrast,
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
our General Public Licenses are intended to guarantee your freedom to
|
||||||
share and change all versions of a program--to make sure it remains free
|
share and change all versions of a program--to make sure it remains free
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
software for all its users.
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
When we speak of free software, we are referring to freedom, not
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
@@ -26,44 +24,34 @@ them if you wish), that you receive source code or can get it if you
|
|||||||
want it, that you can change the software or use pieces of it in new
|
want it, that you can change the software or use pieces of it in new
|
||||||
free programs, and that you know you can do these things.
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
Developers that use our General Public Licenses protect your rights
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
with two steps: (1) assert copyright on the software, and (2) offer
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
you this License which gives you legal permission to copy, distribute
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
and/or modify the software.
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
A secondary benefit of defending all users' freedom is that
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
improvements made in alternate versions of the program, if they
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
receive widespread use, become available for other developers to
|
||||||
or can get the source code. And you must show them these terms so they
|
incorporate. Many developers of free software are heartened and
|
||||||
know their rights.
|
encouraged by the resulting cooperation. However, in the case of
|
||||||
|
software used on network servers, this result may fail to come about.
|
||||||
|
The GNU General Public License permits making a modified version and
|
||||||
|
letting the public access it on a server without ever releasing its
|
||||||
|
source code to the public.
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
The GNU Affero General Public License is designed specifically to
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
ensure that, in such cases, the modified source code becomes available
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
to the community. It requires the operator of a network server to
|
||||||
|
provide the source code of the modified version running there to the
|
||||||
|
users of that server. Therefore, public use of a modified version, on
|
||||||
|
a publicly accessible server, gives the public access to the source
|
||||||
|
code of the modified version.
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
An older license, called the Affero General Public License and
|
||||||
that there is no warranty for this free software. For both users' and
|
published by Affero, was designed to accomplish similar goals. This is
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
a different license, not a version of the Affero GPL, but Affero has
|
||||||
changed, so that their problems will not be attributed erroneously to
|
released a new version of the Affero GPL which permits relicensing under
|
||||||
authors of previous versions.
|
this license.
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
The precise terms and conditions for copying, distribution and
|
||||||
modification follow.
|
modification follow.
|
||||||
@@ -72,7 +60,7 @@ modification follow.
|
|||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
works, such as semiconductor masks.
|
works, such as semiconductor masks.
|
||||||
@@ -549,35 +537,45 @@ to collect a royalty for further conveying from those to whom you convey
|
|||||||
the Program, the only way you could satisfy both those terms and this
|
the Program, the only way you could satisfy both those terms and this
|
||||||
License would be to refrain entirely from conveying the Program.
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, if you modify the
|
||||||
|
Program, your modified version must prominently offer all users
|
||||||
|
interacting with it remotely through a computer network (if your version
|
||||||
|
supports such interaction) an opportunity to receive the Corresponding
|
||||||
|
Source of your version by providing access to the Corresponding Source
|
||||||
|
from a network server at no charge, through some standard or customary
|
||||||
|
means of facilitating copying of software. This Corresponding Source
|
||||||
|
shall include the Corresponding Source for any work covered by version 3
|
||||||
|
of the GNU General Public License that is incorporated pursuant to the
|
||||||
|
following paragraph.
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
Notwithstanding any other provision of this License, you have
|
||||||
permission to link or combine any covered work with a work licensed
|
permission to link or combine any covered work with a work licensed
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
under version 3 of the GNU General Public License into a single
|
||||||
combined work, and to convey the resulting work. The terms of this
|
combined work, and to convey the resulting work. The terms of this
|
||||||
License will continue to apply to the part which is the covered work,
|
License will continue to apply to the part which is the covered work,
|
||||||
but the special requirements of the GNU Affero General Public License,
|
but the work with which it is combined will remain governed by version
|
||||||
section 13, concerning interaction through a network will apply to the
|
3 of the GNU General Public License.
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
the GNU General Public License from time to time. Such new versions will
|
the GNU Affero General Public License from time to time. Such new versions
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
will be similar in spirit to the present version, but may differ in detail to
|
||||||
address new problems or concerns.
|
address new problems or concerns.
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
Each version is given a distinguishing version number. If the
|
||||||
Program specifies that a certain numbered version of the GNU General
|
Program specifies that a certain numbered version of the GNU Affero General
|
||||||
Public License "or any later version" applies to it, you have the
|
Public License "or any later version" applies to it, you have the
|
||||||
option of following the terms and conditions either of that numbered
|
option of following the terms and conditions either of that numbered
|
||||||
version or of any later version published by the Free Software
|
version or of any later version published by the Free Software
|
||||||
Foundation. If the Program does not specify a version number of the
|
Foundation. If the Program does not specify a version number of the
|
||||||
GNU General Public License, you may choose any version ever published
|
GNU Affero General Public License, you may choose any version ever published
|
||||||
by the Free Software Foundation.
|
by the Free Software Foundation.
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
If the Program specifies that a proxy can decide which future
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
versions of the GNU Affero General Public License can be used, that proxy's
|
||||||
public statement of acceptance of a version permanently authorizes you
|
public statement of acceptance of a version permanently authorizes you
|
||||||
to choose that version for the Program.
|
to choose that version for the Program.
|
||||||
|
|
||||||
@@ -635,40 +633,29 @@ the "copyright" line and a pointer to where the full notice is found.
|
|||||||
Copyright (C) <year> <name of author>
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
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
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
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/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
If your software can interact with users remotely through a computer
|
||||||
notice like this when it starts in an interactive mode:
|
network, you should also make sure that it provides a way for users to
|
||||||
|
get its source. For example, if your program is a web application, its
|
||||||
<program> Copyright (C) <year> <name of author>
|
interface could display a "Source" link that leads users to an archive
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
of the code. There are many ways you could offer source, and different
|
||||||
This is free software, and you are welcome to redistribute it
|
solutions will be better for different programs; see section 13 for the
|
||||||
under certain conditions; type `show c' for details.
|
specific requirements.
|
||||||
|
|
||||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||||
<https://www.gnu.org/licenses/>.
|
<https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
|
||||||
|
|||||||
@@ -27,8 +27,10 @@ There are multiple npm packages you can use to use strudel, or only parts of it,
|
|||||||
- [`tone`](./packages/tone): bindings for Tone.js instruments and effects
|
- [`tone`](./packages/tone): bindings for Tone.js instruments and effects
|
||||||
- [`osc`](./packages/osc): bindings to communicate via OSC
|
- [`osc`](./packages/osc): bindings to communicate via OSC
|
||||||
- [`midi`](./packages/midi): webmidi bindings
|
- [`midi`](./packages/midi): webmidi bindings
|
||||||
|
- [`serial`](./packages/serial): webserial bindings
|
||||||
- [`tonal`](./packages/tonal): tonal functions
|
- [`tonal`](./packages/tonal): tonal functions
|
||||||
- [`xen`](./packages/xen): microtonal / xenharmonic functions
|
- [`xen`](./packages/xen): microtonal / xenharmonic functions
|
||||||
|
- ... [and there are more](./packages/)
|
||||||
|
|
||||||
Click on the package names to find out more about each one.
|
Click on the package names to find out more about each one.
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"main.css": "/static/css/main.0d689283.css",
|
"main.css": "/static/css/main.35f2ca4c.css",
|
||||||
"main.js": "/static/js/main.f7b8088f.js",
|
"main.js": "/static/js/main.f848d51e.js",
|
||||||
"static/js/787.1c52cb78.chunk.js": "/static/js/787.1c52cb78.chunk.js",
|
"static/js/787.1c52cb78.chunk.js": "/static/js/787.1c52cb78.chunk.js",
|
||||||
"static/media/logo.svg": "/static/media/logo.ac95051720b3dccfe511e0e02d8e1029.svg",
|
"static/media/logo.svg": "/static/media/logo.ac95051720b3dccfe511e0e02d8e1029.svg",
|
||||||
"index.html": "/index.html",
|
"index.html": "/index.html",
|
||||||
"main.0d689283.css.map": "/static/css/main.0d689283.css.map",
|
"main.35f2ca4c.css.map": "/static/css/main.35f2ca4c.css.map",
|
||||||
"main.f7b8088f.js.map": "/static/js/main.f7b8088f.js.map",
|
"main.f848d51e.js.map": "/static/js/main.f848d51e.js.map",
|
||||||
"787.1c52cb78.chunk.js.map": "/static/js/787.1c52cb78.chunk.js.map"
|
"787.1c52cb78.chunk.js.map": "/static/js/787.1c52cb78.chunk.js.map"
|
||||||
},
|
},
|
||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"static/css/main.0d689283.css",
|
"static/css/main.35f2ca4c.css",
|
||||||
"static/js/main.f7b8088f.js"
|
"static/js/main.f848d51e.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1 +1 @@
|
|||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Strudel REPL"/><title>Strudel REPL</title><script defer="defer" src="/static/js/main.f7b8088f.js"></script><link href="/static/css/main.0d689283.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Strudel REPL"/><title>Strudel REPL</title><script defer="defer" src="/static/js/main.f848d51e.js"></script><link href="/static/css/main.35f2ca4c.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
||||||
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
Vendored
-3
File diff suppressed because one or more lines are too long
-56
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
object-assign
|
|
||||||
(c) Sindre Sorhus
|
|
||||||
@license MIT
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @license Fraction.js v4.2.0 05/03/2022
|
|
||||||
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021, Robert Eisele (robert@xarg.org)
|
|
||||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
||||||
**/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tone.js
|
|
||||||
* @author Yotam Mann
|
|
||||||
* @license http://opensource.org/licenses/MIT MIT License
|
|
||||||
* @copyright 2014-2019 Yotam Mann
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @license React v0.20.2
|
|
||||||
* scheduler.production.min.js
|
|
||||||
*
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @license React v17.0.2
|
|
||||||
* react-dom.production.min.js
|
|
||||||
*
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @license React v17.0.2
|
|
||||||
* react-jsx-runtime.production.min.js
|
|
||||||
*
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @license React v17.0.2
|
|
||||||
* react.production.min.js
|
|
||||||
*
|
|
||||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
||||||
*
|
|
||||||
* This source code is licensed under the MIT license found in the
|
|
||||||
* LICENSE file in the root directory of this source tree.
|
|
||||||
*/
|
|
||||||
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+3
File diff suppressed because one or more lines are too long
+96
@@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Strudel - javascript-based environment for live coding algorithmic (musical) patterns
|
||||||
|
https://strudel.tidalcycles.org / https://github.com/tidalcycles/strudel/
|
||||||
|
|
||||||
|
Copyright (C) Strudel contributors
|
||||||
|
https://github.com/tidalcycles/strudel/graphs/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/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
object-assign
|
||||||
|
(c) Sindre Sorhus
|
||||||
|
@license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! *****************************************************************************
|
||||||
|
Copyright (c) Microsoft Corporation.
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
***************************************************************************** */
|
||||||
|
|
||||||
|
/*! @license ReactCodeMirror - MIT License - Tom Golden (8162045+tbjgolden@users.noreply.github.com) */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @license Fraction.js v4.2.0 05/03/2022
|
||||||
|
* https://www.xarg.org/2014/03/rational-numbers-in-javascript/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021, Robert Eisele (robert@xarg.org)
|
||||||
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||||
|
**/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tone.js
|
||||||
|
* @author Yotam Mann
|
||||||
|
* @license http://opensource.org/licenses/MIT MIT License
|
||||||
|
* @copyright 2014-2019 Yotam Mann
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v0.20.2
|
||||||
|
* scheduler.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react-dom.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react-jsx-runtime.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
Vendored
+1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
|||||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><link rel="icon" href="/tutorial/favicon.e3ab9dd9.ico"><link rel="stylesheet" type="text/css" href="/tutorial/index.757e9f9d.css"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Strudel REPL"><title>Strudel Tutorial</title></head><body> <div id="root"></div> <noscript>You need to enable JavaScript to run this app.</noscript> <script src="/tutorial/index.36c08014.js" defer></script> </body></html>
|
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><link rel="icon" href="/tutorial/favicon.e3ab9dd9.ico"><link rel="stylesheet" type="text/css" href="/tutorial/index.a3acddda.css"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content="Strudel REPL"><title>Strudel Tutorial</title></head><body> <div id="root"></div> <noscript>You need to enable JavaScript to run this app.</noscript> <script src="/tutorial/index.55306425.js" defer></script> </body></html>
|
||||||
-131
@@ -1,131 +0,0 @@
|
|||||||
# Tidal Features in Strudel
|
|
||||||
|
|
||||||
## Basics
|
|
||||||
|
|
||||||
- [ ] drawLine
|
|
||||||
- [ ] setcps
|
|
||||||
- [ ] naming patterns? block based evaluation?
|
|
||||||
- [ ] once
|
|
||||||
- [x] silence
|
|
||||||
- [x] hush
|
|
||||||
- [ ] panic
|
|
||||||
|
|
||||||
## Concatenation
|
|
||||||
|
|
||||||
https://tidalcycles.org/docs/patternlib/tour/concatenation
|
|
||||||
|
|
||||||
- [x] cat: is synonym to fastcat in strudel, while [in tidal, cat is slowcat](https://tidalcycles.org/docs/patternlib/tour/concatenation#cat)
|
|
||||||
- [x] fastcat
|
|
||||||
- [x] timeCat: why is this camel case?
|
|
||||||
- [ ] randcat
|
|
||||||
- [x] append: but is like fastAppend in tidal
|
|
||||||
- [ ] fastAppend
|
|
||||||
- [ ] slowAppend
|
|
||||||
- [ ] wedge
|
|
||||||
- [ ] brak
|
|
||||||
- [ ] flatpat
|
|
||||||
|
|
||||||
## Accumulation
|
|
||||||
|
|
||||||
- [ ] overlay => like stack? "The overlay function is similar to cat" => wrong?
|
|
||||||
- [ ] `<>` operator (=== overlay)
|
|
||||||
- [x] stack
|
|
||||||
- [x] superimpose
|
|
||||||
- [x] layer
|
|
||||||
- [ ] steps ?
|
|
||||||
- [x] iter
|
|
||||||
- [x] iter' = iterBack
|
|
||||||
|
|
||||||
## Alteration
|
|
||||||
|
|
||||||
- [ ] range, rangex
|
|
||||||
- [ ] quantise
|
|
||||||
- [ ] ply
|
|
||||||
- [x] stutter = echo
|
|
||||||
- [ ] stripe, slowstripe
|
|
||||||
- [ ] palindrome = every(2, rev)
|
|
||||||
- [ ] trunc
|
|
||||||
- [ ] linger
|
|
||||||
- [x] chunk, chunk'
|
|
||||||
- [ ] shuffle
|
|
||||||
- [ ] scramble
|
|
||||||
- [ ] rot
|
|
||||||
- [ ] step / step'
|
|
||||||
- [ ] lindenmeyer
|
|
||||||
- [ ] spread / spreadf / fastspread
|
|
||||||
- [ ] spreadChoose / spreadr
|
|
||||||
|
|
||||||
## conditions
|
|
||||||
|
|
||||||
- [x] every
|
|
||||||
- [ ] every'
|
|
||||||
- [ ] whenmod
|
|
||||||
- [ ] sometimes, sometimesBy, someCycles, someCyclesBy
|
|
||||||
- [ ] choose, chooseby, wchoose, wchooseby
|
|
||||||
- [x] struct
|
|
||||||
- [x] mask
|
|
||||||
- [ ] sew
|
|
||||||
- [ ] stitch
|
|
||||||
- [ ] select, selectF
|
|
||||||
- [ ] pickF
|
|
||||||
- [ ] squeeze
|
|
||||||
- [x] euclid, euclidLegato
|
|
||||||
- [ ] euclidInv, euclidFull
|
|
||||||
- [ ] ifp
|
|
||||||
|
|
||||||
## Time
|
|
||||||
|
|
||||||
- [x] fast
|
|
||||||
- [x] fastGap
|
|
||||||
- [x] slow
|
|
||||||
- [ ] hurry
|
|
||||||
- [ ] compress: is this compressSpan?
|
|
||||||
- [ ] zoom
|
|
||||||
- [ ] within
|
|
||||||
- [x] off
|
|
||||||
- [ ] rotL / rotR
|
|
||||||
- [x] rev
|
|
||||||
- [x] jux
|
|
||||||
- [ ] juxBy
|
|
||||||
- [ ] swingBy / swing
|
|
||||||
- [ ] ghost
|
|
||||||
- [ ] inside / outside
|
|
||||||
|
|
||||||
## Harmony & Melody
|
|
||||||
|
|
||||||
- [x] scale
|
|
||||||
- [ ] scaleList
|
|
||||||
- [ ] getScale
|
|
||||||
- [ ] toScale
|
|
||||||
- [ ] chordList
|
|
||||||
- [ ] arpeggiate
|
|
||||||
- [ ] arp
|
|
||||||
|
|
||||||
## Transitions
|
|
||||||
|
|
||||||
- [ ] anticipate / anticipateIn
|
|
||||||
- [ ] clutch / clutchIn
|
|
||||||
- [ ] histpan
|
|
||||||
- [ ] interpolate / interpolateIn
|
|
||||||
- [ ] jump / jumpIn / jumpIn' / jumpMod
|
|
||||||
- [ ] wait / waitT
|
|
||||||
- [ ] wash / washIn
|
|
||||||
- [ ] xfade / xfadeIn
|
|
||||||
|
|
||||||
## Sampling
|
|
||||||
|
|
||||||
- [ ] chop
|
|
||||||
- [ ] striate / striateBy
|
|
||||||
- [ ] loopAt
|
|
||||||
- [x] segment
|
|
||||||
- [ ] discretise
|
|
||||||
|
|
||||||
## Randomness
|
|
||||||
|
|
||||||
- [ ] rand / irand
|
|
||||||
- [ ] perlin / perlinWith / perlin2 / perlin2With
|
|
||||||
|
|
||||||
## Composition
|
|
||||||
|
|
||||||
- [ ] ur
|
|
||||||
- [ ] seqP / seqPLoop
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<script>import("./strudel.js").then(m => strudel = m)
|
|
||||||
</script>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>Bingo</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<button onclick="foo()">hello</button>
|
|
||||||
<button onclick="bar()">hello</button>
|
|
||||||
|
|
||||||
<script type="module" src="./strudel.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"source": {
|
||||||
|
"includePattern": ".+\\.(js(doc|x)?|mjs)$",
|
||||||
|
"excludePattern": "node_modules|shift-parser|shift-reducer|shift-traverser"
|
||||||
|
},
|
||||||
|
"plugins": ["plugins/markdown"],
|
||||||
|
"opts": {
|
||||||
|
"destination": "./out/",
|
||||||
|
"recurse": true
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+3963
-3646
File diff suppressed because it is too large
Load Diff
+12
-5
@@ -3,14 +3,17 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"description": "Port of tidalcycles to javascript",
|
"description": "Port of tidalcycles to javascript",
|
||||||
"main": "strudel.mjs",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run test --workspaces --if-present",
|
"test": "npm run test --workspaces --if-present && cd repl && npm run test",
|
||||||
"bootstrap": "lerna bootstrap",
|
"bootstrap": "lerna bootstrap",
|
||||||
"setup": "npm i && npm run bootstrap && cd repl && npm i",
|
"setup": "npm i && npm run bootstrap && cd repl && npm i",
|
||||||
"repl": "cd repl && npm run start",
|
"repl": "cd repl && npm run dev",
|
||||||
"osc": "cd packages/osc && npm run server",
|
"osc": "cd packages/osc && npm run server",
|
||||||
"build": "cd repl && npm run build"
|
"build": "rm -rf out && cd repl && npm run build && cd ../tutorial && npm run build",
|
||||||
|
"preview": "npx serve ./out",
|
||||||
|
"deploy": "gh-pages -d out",
|
||||||
|
"jsdoc": "jsdoc packages/ -c jsdoc.config.json",
|
||||||
|
"jsdoc-json": "jsdoc packages/ --template ./node_modules/jsdoc-json --destination doc.json -c jsdoc.config.json"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
@@ -27,13 +30,17 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://strudel.tidalcycles.org",
|
"homepage": "https://strudel.tidalcycles.org",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"events": "^3.3.0",
|
"events": "^3.3.0",
|
||||||
|
"gh-pages": "^4.0.0",
|
||||||
|
"jsdoc": "^3.6.10",
|
||||||
|
"jsdoc-json": "^2.0.2",
|
||||||
|
"jsdoc-to-markdown": "^7.1.1",
|
||||||
"lerna": "^4.0.0",
|
"lerna": "^4.0.0",
|
||||||
"mocha": "^9.1.4"
|
"mocha": "^9.1.4"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
controls.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/controls.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 { Pattern, sequence } from './pattern.mjs';
|
import { Pattern, sequence } from './pattern.mjs';
|
||||||
|
|
||||||
const controls = {};
|
const controls = {};
|
||||||
@@ -275,14 +281,14 @@ const generic_params = [
|
|||||||
|
|
||||||
const _name = (name, ...pats) => sequence(...pats).withValue((x) => ({ [name]: x }));
|
const _name = (name, ...pats) => sequence(...pats).withValue((x) => ({ [name]: x }));
|
||||||
|
|
||||||
const _unionise = (func) =>
|
const _setter = (func) =>
|
||||||
function (...pats) {
|
function (...pats) {
|
||||||
return this.union(func(...pats));
|
return this.set(func(...pats));
|
||||||
};
|
};
|
||||||
|
|
||||||
generic_params.forEach(([type, name, description]) => {
|
generic_params.forEach(([type, name, description]) => {
|
||||||
controls[name] = (...pats) => _name(name, ...pats);
|
controls[name] = (...pats) => _name(name, ...pats);
|
||||||
Pattern.prototype[name] = _unionise(controls[name]);
|
Pattern.prototype[name] = _setter(controls[name]);
|
||||||
});
|
});
|
||||||
|
|
||||||
export default controls;
|
export default controls;
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
drawLine.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/drawLine.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 Fraction, { gcd } from './fraction.mjs';
|
||||||
|
|
||||||
|
function drawLine(pat, chars = 60) {
|
||||||
|
let cycle = 0;
|
||||||
|
let pos = Fraction(0);
|
||||||
|
let lines = [''];
|
||||||
|
let emptyLine = ''; // this will be the "reference" empty line, which will be copied into extra lines
|
||||||
|
while (lines[0].length < chars) {
|
||||||
|
const haps = pat.queryArc(cycle, cycle + 1);
|
||||||
|
const durations = haps.filter((hap) => hap.hasOnset()).map((hap) => hap.duration);
|
||||||
|
const charFraction = gcd(...durations);
|
||||||
|
const totalSlots = charFraction.inverse(); // number of character slots for the current cycle
|
||||||
|
lines = lines.map((line) => line + '|'); // add pipe character before each cycle
|
||||||
|
emptyLine += '|';
|
||||||
|
for (let i = 0; i < totalSlots; i++) {
|
||||||
|
const [begin, end] = [pos, pos.add(charFraction)];
|
||||||
|
const matches = haps.filter((hap) => hap.whole.begin.lte(begin) && hap.whole.end.gte(end));
|
||||||
|
const missingLines = matches.length - lines.length;
|
||||||
|
if (missingLines > 0) {
|
||||||
|
lines = lines.concat(Array(missingLines).fill(emptyLine));
|
||||||
|
}
|
||||||
|
lines = lines.map((line, i) => {
|
||||||
|
const hap = matches[i];
|
||||||
|
if (hap) {
|
||||||
|
const isOnset = hap.whole.begin.eq(begin);
|
||||||
|
const char = isOnset ? '' + hap.value : '-';
|
||||||
|
return line + char;
|
||||||
|
}
|
||||||
|
return line + '.';
|
||||||
|
});
|
||||||
|
emptyLine += '.';
|
||||||
|
pos = pos.add(charFraction);
|
||||||
|
}
|
||||||
|
cycle++;
|
||||||
|
}
|
||||||
|
return lines.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default drawLine;
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
euclid.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/euclid.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 { Pattern, timeCat } from './pattern.mjs';
|
import { Pattern, timeCat } from './pattern.mjs';
|
||||||
import bjork from 'bjork';
|
import bjork from 'bjork';
|
||||||
import { rotate } from './util.mjs';
|
import { rotate } from './util.mjs';
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
const events = pattern.firstCycle(); // query first cycle
|
const events = pattern.firstCycle(); // query first cycle
|
||||||
events.forEach((event) => {
|
events.forEach((event) => {
|
||||||
ctx.fillStyle = event.value;
|
ctx.fillStyle = event.value;
|
||||||
ctx.fillRect(event.whole.begin * canvas.width, 0, event.duration * canvas.width, canvas.height);
|
ctx.fillRect(event.whole.begin * canvas.width, 0, event.duration.valueOf() * canvas.width, canvas.height);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
fraction.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/fraction.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 Fraction from 'fraction.js';
|
import Fraction from 'fraction.js';
|
||||||
import { TimeSpan } from './timespan.mjs';
|
import { TimeSpan } from './timespan.mjs';
|
||||||
|
|
||||||
@@ -72,6 +78,12 @@ const fraction = (n) => {
|
|||||||
return Fraction(n);
|
return Fraction(n);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const gcd = (...fractions) => {
|
||||||
|
return fractions.reduce((gcd, fraction) => gcd.gcd(fraction), fraction(1));
|
||||||
|
};
|
||||||
|
|
||||||
|
fraction._original = Fraction;
|
||||||
|
|
||||||
export default fraction;
|
export default fraction;
|
||||||
|
|
||||||
// "If you concern performance, cache Fraction.js objects and pass arrays/objects.“
|
// "If you concern performance, cache Fraction.js objects and pass arrays/objects.“
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
gist.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/gist.js>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
// this is a shortcut to eval code from a gist
|
// this is a shortcut to eval code from a gist
|
||||||
// why? to be able to shorten strudel code + e.g. be able to change instruments after links have been generated
|
// why? to be able to shorten strudel code + e.g. be able to change instruments after links have been generated
|
||||||
export default (route) =>
|
export default (route) =>
|
||||||
|
|||||||
+22
-6
@@ -1,3 +1,8 @@
|
|||||||
|
/*
|
||||||
|
hap.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/hap.mjs>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
export class Hap {
|
export class Hap {
|
||||||
/*
|
/*
|
||||||
@@ -9,7 +14,10 @@ export class Hap {
|
|||||||
then the whole will be returned as None, in which case the given
|
then the whole will be returned as None, in which case the given
|
||||||
value will have been sampled from the point halfway between the
|
value will have been sampled from the point halfway between the
|
||||||
start and end of the 'part' timespan.
|
start and end of the 'part' timespan.
|
||||||
The context is to store a list of source code locations causing the event
|
The context is to store a list of source code locations causing the event.
|
||||||
|
|
||||||
|
The word 'Event' is more or less a reserved word in javascript, hence this
|
||||||
|
class is named called 'Hap'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
constructor(whole, part, value, context = {}, stateful = false) {
|
constructor(whole, part, value, context = {}, stateful = false) {
|
||||||
@@ -24,7 +32,7 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get duration() {
|
get duration() {
|
||||||
return this.whole.end.sub(this.whole.begin).valueOf();
|
return this.whole.end.sub(this.whole.begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
wholeOrPart() {
|
wholeOrPart() {
|
||||||
@@ -32,18 +40,18 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withSpan(func) {
|
withSpan(func) {
|
||||||
// Returns a new event with the function f applies to the event timespan.
|
// Returns a new hap with the function f applies to the hap timespan.
|
||||||
const whole = this.whole ? func(this.whole) : undefined;
|
const whole = this.whole ? func(this.whole) : undefined;
|
||||||
return new Hap(whole, func(this.part), this.value, this.context);
|
return new Hap(whole, func(this.part), this.value, this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
withValue(func) {
|
withValue(func) {
|
||||||
// Returns a new event with the function f applies to the event value.
|
// Returns a new hap with the function f applies to the hap value.
|
||||||
return new Hap(this.whole, this.part, func(this.value), this.context);
|
return new Hap(this.whole, this.part, func(this.value), this.context);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasOnset() {
|
hasOnset() {
|
||||||
// Test whether the event contains the onset, i.e that
|
// Test whether the hap contains the onset, i.e that
|
||||||
// the beginning of the part is the same as that of the whole timespan."""
|
// the beginning of the part is the same as that of the whole timespan."""
|
||||||
return this.whole != undefined && this.whole.begin.equals(this.part.begin);
|
return this.whole != undefined && this.whole.begin.equals(this.part.begin);
|
||||||
}
|
}
|
||||||
@@ -77,6 +85,14 @@ export class Hap {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showWhole() {
|
||||||
|
return `${this.whole == undefined ? '~' : this.whole.show()}: ${this.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
showWhole() {
|
||||||
|
return `${this.whole == undefined ? '~' : this.whole.show()}: ${this.value}`;
|
||||||
|
}
|
||||||
|
|
||||||
combineContext(b) {
|
combineContext(b) {
|
||||||
const a = this;
|
const a = this;
|
||||||
return { ...a.context, ...b.context, locations: (a.context.locations || []).concat(b.context.locations || []) };
|
return { ...a.context, ...b.context, locations: (a.context.locations || []).concat(b.context.locations || []) };
|
||||||
@@ -87,4 +103,4 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Hap;
|
export default Hap;
|
||||||
|
|||||||
@@ -1,11 +1,19 @@
|
|||||||
|
/*
|
||||||
|
index.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/index.mjs>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
export * from './controls.mjs';
|
export * from './controls.mjs';
|
||||||
export * from './euclid.mjs';
|
export * from './euclid.mjs';
|
||||||
import Fraction from './fraction.mjs';
|
import Fraction from './fraction.mjs';
|
||||||
export {Fraction};
|
export { Fraction };
|
||||||
export * from './hap.mjs';
|
export * from './hap.mjs';
|
||||||
export * from './pattern.mjs';
|
export * from './pattern.mjs';
|
||||||
export * from './signal.mjs';
|
export * from './signal.mjs';
|
||||||
export * from './state.mjs';
|
export * from './state.mjs';
|
||||||
export * from './timespan.mjs';
|
export * from './timespan.mjs';
|
||||||
export * from './util.mjs';
|
export * from './util.mjs';
|
||||||
|
export * from './speak.mjs';
|
||||||
|
export * as gist from './gist.js';
|
||||||
// export * from './value.mjs';
|
// export * from './value.mjs';
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/core",
|
"name": "@strudel.cycles/core",
|
||||||
"version": "0.0.5",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/core",
|
"name": "@strudel.cycles/core",
|
||||||
"version": "0.0.5",
|
"version": "0.1.0",
|
||||||
"description": "Port of Tidal Cycles to JavaScript",
|
"description": "Port of Tidal Cycles to JavaScript",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
+576
-142
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
signal.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/signal.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 { Hap } from './hap.mjs';
|
import { Hap } from './hap.mjs';
|
||||||
import { Pattern, fastcat, reify, silence, stack } from './pattern.mjs';
|
import { Pattern, fastcat, reify, silence, stack } from './pattern.mjs';
|
||||||
import Fraction from './fraction.mjs';
|
import Fraction from './fraction.mjs';
|
||||||
@@ -5,7 +11,7 @@ import { id } from './util.mjs';
|
|||||||
|
|
||||||
export function steady(value) {
|
export function steady(value) {
|
||||||
// A continuous value
|
// A continuous value
|
||||||
return new Pattern((span) => Hap(undefined, span, value));
|
return new Pattern((state) => [new Hap(undefined, state.span, value)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const signal = (func) => {
|
export const signal = (func) => {
|
||||||
@@ -47,7 +53,7 @@ const timeToIntSeed = (x) => xorwise(Math.trunc(_frac(x / 300) * 536870912));
|
|||||||
|
|
||||||
const intSeedToRand = (x) => (x % 536870912) / 536870912;
|
const intSeedToRand = (x) => (x % 536870912) / 536870912;
|
||||||
|
|
||||||
const timeToRand = (x) => intSeedToRand(timeToIntSeed(x));
|
const timeToRand = (x) => Math.abs(intSeedToRand(timeToIntSeed(x)));
|
||||||
|
|
||||||
const timeToRandsPrime = (seed, n) => {
|
const timeToRandsPrime = (seed, n) => {
|
||||||
const result = [];
|
const result = [];
|
||||||
@@ -60,8 +66,7 @@ const timeToRandsPrime = (seed, n) => {
|
|||||||
|
|
||||||
const timeToRands = (t, n) => timeToRandsPrime(timeToIntSeed(t), n);
|
const timeToRands = (t, n) => timeToRandsPrime(timeToIntSeed(t), n);
|
||||||
|
|
||||||
export const rand2 = signal(timeToRand);
|
export const rand = signal(timeToRand);
|
||||||
export const rand = rand2.fmap(Math.abs);
|
|
||||||
|
|
||||||
export const _brandBy = (p) => rand.fmap((x) => x < p);
|
export const _brandBy = (p) => rand.fmap((x) => x < p);
|
||||||
export const brandBy = (pPat) => reify(pPat).fmap(_brandBy).innerJoin();
|
export const brandBy = (pPat) => reify(pPat).fmap(_brandBy).innerJoin();
|
||||||
@@ -71,14 +76,40 @@ export const _irand = (i) => rand.fmap((x) => Math.trunc(x * i));
|
|||||||
export const irand = (ipat) => reify(ipat).fmap(_irand).innerJoin();
|
export const irand = (ipat) => reify(ipat).fmap(_irand).innerJoin();
|
||||||
|
|
||||||
export const chooseWith = (pat, xs) => {
|
export const chooseWith = (pat, xs) => {
|
||||||
|
xs = xs.map(reify);
|
||||||
if (xs.length == 0) {
|
if (xs.length == 0) {
|
||||||
return silence;
|
return silence;
|
||||||
}
|
}
|
||||||
return pat.range(0, xs.length).fmap((i) => xs[Math.floor(i)]);
|
return pat
|
||||||
|
.range(0, xs.length)
|
||||||
|
.fmap((i) => xs[Math.floor(i)])
|
||||||
|
.outerJoin();
|
||||||
};
|
};
|
||||||
|
|
||||||
export const choose = (...xs) => chooseWith(rand, xs);
|
export const choose = (...xs) => chooseWith(rand, xs);
|
||||||
|
|
||||||
|
const _wchooseWith = function (pat, ...pairs) {
|
||||||
|
const values = pairs.map((pair) => reify(pair[0]));
|
||||||
|
const weights = [];
|
||||||
|
let accum = 0;
|
||||||
|
for (const pair of pairs) {
|
||||||
|
accum += pair[1];
|
||||||
|
weights.push(accum);
|
||||||
|
}
|
||||||
|
const total = accum;
|
||||||
|
const match = function (r) {
|
||||||
|
const find = r * total;
|
||||||
|
return values[weights.findIndex((x) => x > find, weights)];
|
||||||
|
};
|
||||||
|
return pat.fmap(match);
|
||||||
|
};
|
||||||
|
|
||||||
|
const wchooseWith = (...args) => _wchooseWith(...args).outerJoin();
|
||||||
|
|
||||||
|
export const wchoose = (...pairs) => wchooseWith(rand, ...pairs);
|
||||||
|
|
||||||
|
export const wchooseCycles = (...pairs) => _wchooseWith(rand, ...pairs).innerJoin();
|
||||||
|
|
||||||
export const perlinWith = (pat) => {
|
export const perlinWith = (pat) => {
|
||||||
const pata = pat.fmap(Math.floor);
|
const pata = pat.fmap(Math.floor);
|
||||||
const patb = pat.fmap((t) => Math.floor(t) + 1);
|
const patb = pat.fmap((t) => Math.floor(t) + 1);
|
||||||
@@ -142,6 +173,24 @@ Pattern.prototype.sometimesPre = function (func) {
|
|||||||
return this._sometimesByPre(0.5, func);
|
return this._sometimesByPre(0.5, func);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Pattern.prototype._someCyclesBy = function (x, func) {
|
||||||
|
return stack(
|
||||||
|
this._degradeByWith(rand._segment(1), x),
|
||||||
|
func(this._degradeByWith(rand.fmap((r) => 1 - r)._segment(1), 1 - x)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Pattern.prototype.someCyclesBy = function (patx, func) {
|
||||||
|
const pat = this;
|
||||||
|
return reify(patx)
|
||||||
|
.fmap((x) => pat._someCyclesBy(x, func))
|
||||||
|
.innerJoin();
|
||||||
|
};
|
||||||
|
|
||||||
|
Pattern.prototype.someCycles = function (func) {
|
||||||
|
return this._someCyclesBy(0.5, func);
|
||||||
|
};
|
||||||
|
|
||||||
Pattern.prototype.often = function (func) {
|
Pattern.prototype.often = function (func) {
|
||||||
return this.sometimesBy(0.75, func);
|
return this.sometimesBy(0.75, func);
|
||||||
};
|
};
|
||||||
|
|||||||
+17
-5
@@ -1,6 +1,18 @@
|
|||||||
|
/*
|
||||||
|
speak.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/speak.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 { Pattern, patternify2 } from './index.mjs';
|
import { Pattern, patternify2 } from './index.mjs';
|
||||||
|
|
||||||
const synth = window?.speechSynthesis;
|
let synth;
|
||||||
|
try {
|
||||||
|
synth = window?.speechSynthesis;
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('cannot use window: not in browser?');
|
||||||
|
}
|
||||||
|
|
||||||
let allVoices = synth?.getVoices();
|
let allVoices = synth?.getVoices();
|
||||||
// console.log('voices', allVoices);
|
// console.log('voices', allVoices);
|
||||||
|
|
||||||
@@ -20,11 +32,11 @@ function speak(words, lang, voice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype._speak = function (lang, voice) {
|
Pattern.prototype._speak = function (lang, voice) {
|
||||||
return this._withEvent((event) => {
|
return this._withHap((hap) => {
|
||||||
const onTrigger = (time, event) => {
|
const onTrigger = (time, hap) => {
|
||||||
speak(event.value, lang, voice);
|
speak(hap.value, lang, voice);
|
||||||
};
|
};
|
||||||
return event.setContext({ ...event.context, onTrigger });
|
return hap.setContext({ ...hap.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
state.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/state.mjs>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
export class State {
|
export class State {
|
||||||
constructor(span, controls = {}) {
|
constructor(span, controls = {}) {
|
||||||
this.span = span;
|
this.span = span;
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
drawLine.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/test/drawLine.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 { fastcat, stack, slowcat, silence, pure } from '../pattern.mjs';
|
||||||
|
import { strict as assert } from 'assert';
|
||||||
|
import drawLine from '../drawLine.mjs';
|
||||||
|
|
||||||
|
describe('drawLine', () => {
|
||||||
|
it('supports equal lengths', () => {
|
||||||
|
assert.equal(drawLine(fastcat(0), 4), '|0|0');
|
||||||
|
assert.equal(drawLine(fastcat(0, 1), 4), '|01|01');
|
||||||
|
assert.equal(drawLine(fastcat(0, 1, 2), 6), '|012|012');
|
||||||
|
});
|
||||||
|
it('supports unequal lengths', () => {
|
||||||
|
assert.equal(drawLine(fastcat(0, [1, 2]), 10), '|0-12|0-12');
|
||||||
|
assert.equal(drawLine(fastcat(0, [1, 2, 3]), 10), '|0--123|0--123');
|
||||||
|
assert.equal(drawLine(fastcat(0, 1, [2, 3]), 10), '|0-1-23|0-1-23');
|
||||||
|
});
|
||||||
|
it('supports unequal silence', () => {
|
||||||
|
assert.equal(drawLine(fastcat(0, silence, [1, 2]), 10), '|0-..12|0-..12');
|
||||||
|
});
|
||||||
|
it('supports polyrhythms', () => {
|
||||||
|
'0*2 1*3';
|
||||||
|
assert.equal(drawLine(fastcat(pure(0).fast(2), pure(1).fast(3)), 10), '|0--0--1-1-1-');
|
||||||
|
});
|
||||||
|
it('supports multiple lines', () => {
|
||||||
|
assert.equal(
|
||||||
|
drawLine(fastcat(0, stack(1, 2)), 10),
|
||||||
|
`|01|01|01|01
|
||||||
|
|.2|.2|.2|.2`,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
drawLine(fastcat(0, 1, stack(2, 3)), 10),
|
||||||
|
`|012|012|012
|
||||||
|
|..3|..3|..3`,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
drawLine(fastcat(0, stack(1, 2, 3)), 10),
|
||||||
|
`|01|01|01|01
|
||||||
|
|.2|.2|.2|.2
|
||||||
|
|.3|.3|.3|.3`,
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
drawLine(fastcat(0, 1, stack(2, 3, 4)), 10),
|
||||||
|
`|012|012|012
|
||||||
|
|..3|..3|..3
|
||||||
|
|..4|..4|..4`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('supports unequal cycle lengths', () => {
|
||||||
|
assert.equal(drawLine(slowcat(0, [1, 2]), 10), `|0|12|0|12`);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
fraction.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/test/fraction.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 Fraction, { gcd } from '../fraction.mjs';
|
||||||
|
import { strict as assert } from 'assert';
|
||||||
|
|
||||||
|
describe('gcd', () => {
|
||||||
|
it('should work', () => {
|
||||||
|
const F = Fraction._original;
|
||||||
|
assert.equal(gcd(F(1 / 6), F(1 / 4)).toFraction(), '1/12');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
pattern.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/test/pattern.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 Fraction from 'fraction.js';
|
import Fraction from 'fraction.js';
|
||||||
|
|
||||||
import { deepStrictEqual, strict as assert } from 'assert';
|
import { deepStrictEqual, strict as assert } from 'assert';
|
||||||
@@ -35,7 +41,11 @@ import {
|
|||||||
tri2,
|
tri2,
|
||||||
id,
|
id,
|
||||||
ply,
|
ply,
|
||||||
|
rev
|
||||||
} from '../index.mjs';
|
} from '../index.mjs';
|
||||||
|
|
||||||
|
import { steady } from '../signal.mjs';
|
||||||
|
|
||||||
//import { Time } from 'tone';
|
//import { Time } from 'tone';
|
||||||
import pkg from 'tone';
|
import pkg from 'tone';
|
||||||
const { Time } = pkg;
|
const { Time } = pkg;
|
||||||
@@ -47,6 +57,10 @@ const hap = (whole, part, value, context = {}) => new Hap(whole, part, value, co
|
|||||||
const third = Fraction(1, 3);
|
const third = Fraction(1, 3);
|
||||||
const twothirds = Fraction(2, 3);
|
const twothirds = Fraction(2, 3);
|
||||||
|
|
||||||
|
const sameFirst = (a, b) => {
|
||||||
|
return assert.deepStrictEqual(a._sortHapsByPart().firstCycle(), b._sortHapsByPart().firstCycle());
|
||||||
|
};
|
||||||
|
|
||||||
describe('TimeSpan', function () {
|
describe('TimeSpan', function () {
|
||||||
describe('equals()', function () {
|
describe('equals()', function () {
|
||||||
it('Should be equal to the same value', function () {
|
it('Should be equal to the same value', function () {
|
||||||
@@ -108,6 +122,18 @@ describe('Hap', function () {
|
|||||||
assert.deepStrictEqual(state3, { incrementme: 12 });
|
assert.deepStrictEqual(state3, { incrementme: 12 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('wholeOrPart()', () => {
|
||||||
|
const ts1 = new TimeSpan(Fraction(0), Fraction(1));
|
||||||
|
const ts0_5 = new TimeSpan(Fraction(0), Fraction(0.5));
|
||||||
|
const continuousHap = new Hap(undefined, ts1, 'hello');
|
||||||
|
const discreteHap = new Hap(ts1, ts0_5, 'hello');
|
||||||
|
it('Can pick a whole', () => {
|
||||||
|
assert.deepStrictEqual(discreteHap.wholeOrPart(), ts1);
|
||||||
|
});
|
||||||
|
it('Can pick a part', () => {
|
||||||
|
assert.deepStrictEqual(continuousHap.wholeOrPart(), ts1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Pattern', function () {
|
describe('Pattern', function () {
|
||||||
@@ -127,8 +153,132 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('add()', function () {
|
describe('add()', function () {
|
||||||
it('Can add things', function () {
|
it('can structure In()', function () {
|
||||||
assert.equal(pure(3).add(pure(4)).query(st(0, 1))[0].value, 7);
|
assert.equal(pure(3).add(pure(4)).query(st(0, 1))[0].value, 7);
|
||||||
|
assert.equal(pure(3).addIn(pure(4)).query(st(0, 1))[0].value, 7);
|
||||||
|
});
|
||||||
|
it('can structure Out()', () => {
|
||||||
|
sameFirst(sequence(1, 2).addOut(4), sequence(5, 6).struct(true));
|
||||||
|
});
|
||||||
|
it('can Mix() structure', () => {
|
||||||
|
assert.deepStrictEqual(sequence(1, 2).addMix(silence, 5, silence).firstCycle(), [
|
||||||
|
hap(ts(1 / 3, 1 / 2), ts(1 / 3, 1 / 2), 6),
|
||||||
|
hap(ts(1 / 2, 2 / 3), ts(1 / 2, 2 / 3), 7),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it('can Trig() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).addTrig(20, 30).early(2),
|
||||||
|
sequence(26, 27, 36, 37),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Trigzero() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).addTrigzero(20, 30).early(2),
|
||||||
|
sequence(21, 22, 31, 32),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Squeeze() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).addSqueeze(sequence(10, 20, 30)),
|
||||||
|
sequence(
|
||||||
|
[11, 21, 31],
|
||||||
|
[
|
||||||
|
[12, 22, 32],
|
||||||
|
[13, 23, 33],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can SqueezeOut() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).addSqueezeOut(10, 20, 30),
|
||||||
|
sequence([11, [12, 13]], [21, [22, 23]], [31, [32, 33]]),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('keep()', function () {
|
||||||
|
it('can structure In()', function () {
|
||||||
|
assert.equal(pure(3).keep(pure(4)).query(st(0, 1))[0].value, 3);
|
||||||
|
assert.equal(pure(3).keepIn(pure(4)).query(st(0, 1))[0].value, 3);
|
||||||
|
});
|
||||||
|
it('can structure Out()', () => {
|
||||||
|
sameFirst(sequence(1, 2).keepOut(4), sequence(1, 2).struct(true));
|
||||||
|
});
|
||||||
|
it('can Mix() structure', () => {
|
||||||
|
assert.deepStrictEqual(sequence(1, 2).keepMix(silence, 5, silence).firstCycle(), [
|
||||||
|
hap(ts(1 / 3, 1 / 2), ts(1 / 3, 1 / 2), 1),
|
||||||
|
hap(ts(1 / 2, 2 / 3), ts(1 / 2, 2 / 3), 2),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it('can Trig() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).keepTrig(20, 30).early(2),
|
||||||
|
sequence(6, 7, 6, 7),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Trigzero() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).keepTrigzero(20, 30).early(2),
|
||||||
|
sequence(1, 2, 1, 2),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Squeeze() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).keepSqueeze(sequence(10, 20, 30)),
|
||||||
|
sequence(
|
||||||
|
[1, 1, 1],
|
||||||
|
[
|
||||||
|
[2, 2, 2],
|
||||||
|
[3, 3, 3],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can SqueezeOut() structure', () => {
|
||||||
|
sameFirst(sequence(1, [2, 3]).keepSqueezeOut(10, 20, 30), sequence([1, [2, 3]], [1, [2, 3]], [1, [2, 3]]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('keepif()', function () {
|
||||||
|
it('can structure In()', function () {
|
||||||
|
sameFirst(sequence(3, 4).keepif(true, false), sequence(3, silence));
|
||||||
|
sameFirst(sequence(3, 4).keepifIn(true, false), sequence(3, silence));
|
||||||
|
});
|
||||||
|
it('can structure Out()', () => {
|
||||||
|
sameFirst(pure(1).keepifOut(true, false), sequence(1, silence));
|
||||||
|
});
|
||||||
|
it('can Mix() structure', () => {
|
||||||
|
assert.deepStrictEqual(sequence(1, 2).keepifMix(false, true, false).firstCycle(), [
|
||||||
|
hap(ts(1 / 3, 1 / 2), ts(1 / 3, 1 / 2), 1),
|
||||||
|
hap(ts(1 / 2, 2 / 3), ts(1 / 2, 2 / 3), 2),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it('can Trig() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).keepifTrig(false, true).early(2),
|
||||||
|
sequence(silence, silence, 6, 7),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Trigzero() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
slowcat(sequence(1, 2, 3, 4), 5, sequence(6, 7, 8, 9), 10).keepifTrigzero(false, true).early(2),
|
||||||
|
sequence(silence, silence, 1, 2),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can Squeeze() structure', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).keepifSqueeze(sequence(true, true, false)),
|
||||||
|
sequence(
|
||||||
|
[1, 1, silence],
|
||||||
|
[
|
||||||
|
[2, 2, silence],
|
||||||
|
[3, 3, silence],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('can SqueezeOut() structure', () => {
|
||||||
|
sameFirst(sequence(1, [2, 3]).keepifSqueezeOut(true, true, false), sequence([1, [2, 3]], [1, [2, 3]], silence));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('sub()', function () {
|
describe('sub()', function () {
|
||||||
@@ -146,14 +296,50 @@ describe('Pattern', function () {
|
|||||||
assert.equal(pure(3).div(pure(2)).firstCycle()[0].value, 1.5);
|
assert.equal(pure(3).div(pure(2)).firstCycle()[0].value, 1.5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('union()', function () {
|
describe('set()', function () {
|
||||||
it('Can union things', function () {
|
it('Can set things in objects', function () {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure({ a: 4, b: 6 })
|
pure({ a: 4, b: 6 })
|
||||||
.union(pure({ c: 7 }))
|
.set(pure({ c: 7 }))
|
||||||
.firstCycle()[0].value,
|
.firstCycle()[0].value,
|
||||||
{ a: 4, b: 6, c: 7 },
|
{ a: 4, b: 6, c: 7 },
|
||||||
);
|
);
|
||||||
|
sameFirst(
|
||||||
|
sequence({ a: 1, b: 2 }, { a: 2, b: 2 }, { a: 3, b: 2 }).set({ a: 4, c: 5 }),
|
||||||
|
sequence({ a: 4, b: 2, c: 5 }).fast(3),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it('Can set things with plain values', function () {
|
||||||
|
sameFirst(sequence(1, 2, 3).set(4), sequence(4).fast(3));
|
||||||
|
});
|
||||||
|
describe('setOut()', () => {
|
||||||
|
it('Can set things with structure from second pattern', () => {
|
||||||
|
sameFirst(sequence(1, 2).setOut(4), pure(4).mask(true, true));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('setSqueeze()', () => {
|
||||||
|
it('Can squeeze one pattern inside the haps of another', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).setSqueeze(sequence('a', 'b', 'c')),
|
||||||
|
sequence(
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
[
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
sameFirst(
|
||||||
|
sequence(1, [2, 3]).setSqueeze('a', 'b', 'c'),
|
||||||
|
sequence(
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
[
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
['a', 'b', 'c'],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('stack()', function () {
|
describe('stack()', function () {
|
||||||
@@ -165,6 +351,9 @@ describe('Pattern', function () {
|
|||||||
['a', 'b', 'c'],
|
['a', 'b', 'c'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('Can stack subpatterns', function () {
|
||||||
|
sameFirst(stack('a', ['b', 'c']), stack('a', sequence('b', 'c')));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('_fast()', function () {
|
describe('_fast()', function () {
|
||||||
it('Makes things faster', function () {
|
it('Makes things faster', function () {
|
||||||
@@ -203,7 +392,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
it('Makes things faster, with a pattern of factors', function () {
|
it('Makes things faster, with a pattern of factors', function () {
|
||||||
assert.equal(pure('a').fast(sequence(1, 4)).firstCycle().length, 3);
|
assert.equal(pure('a').fast(sequence(1, 4)).firstCycle().length, 3);
|
||||||
// .fast(sequence(1,silence) is a quick hack to cut an event in two..
|
// .fast(sequence(1,silence) is a quick hack to cut a hap in two..
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure('a').fast(sequence(1, 4)).firstCycle(),
|
pure('a').fast(sequence(1, 4)).firstCycle(),
|
||||||
stack(pure('a').fast(sequence(1, silence)), sequence(silence, ['a', 'a'])).firstCycle(),
|
stack(pure('a').fast(sequence(1, silence)), sequence(silence, ['a', 'a'])).firstCycle(),
|
||||||
@@ -248,6 +437,20 @@ describe('Pattern', function () {
|
|||||||
// mini('eb3 [c3 g3]/2 ') always plays [c3 g3]
|
// mini('eb3 [c3 g3]/2 ') always plays [c3 g3]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('inside', () => {
|
||||||
|
it('can rev inside a cycle', () => {
|
||||||
|
sameFirst(sequence('a', 'b', 'c', 'd').inside(2, rev),
|
||||||
|
sequence('b', 'a', 'd', 'c')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('outside', () => {
|
||||||
|
it('can rev outside a cycle', () => {
|
||||||
|
sameFirst(sequence('a', 'b', 'c', 'd')._slow(2).outside(2, rev),
|
||||||
|
sequence('d', 'c')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('_filterValues()', function () {
|
describe('_filterValues()', function () {
|
||||||
it('Filters true', function () {
|
it('Filters true', function () {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
@@ -277,7 +480,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
it('Can alternate', function () {
|
it('Can alternate', function () {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure(10).when(slowcat(true, false), add(3)).fast(4)._sortEventsByPart().firstCycle(),
|
pure(10).when(slowcat(true, false), add(3)).fast(4)._sortHapsByPart().firstCycle(),
|
||||||
fastcat(13, 10, 13, 10).firstCycle(),
|
fastcat(13, 10, 13, 10).firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -292,6 +495,11 @@ describe('Pattern', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('fastcat()', function () {
|
||||||
|
it('Can go into negative time', function () {
|
||||||
|
sameFirst(fastcat('a', 'b', 'c').late(1000000), fastcat('a', 'b', 'c'));
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('slowcat()', function () {
|
describe('slowcat()', function () {
|
||||||
it('Can concatenate things slowly', function () {
|
it('Can concatenate things slowly', function () {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
@@ -322,6 +530,9 @@ describe('Pattern', function () {
|
|||||||
['c'],
|
['c'],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('Can cat subpatterns', () => {
|
||||||
|
sameFirst(slowcat('a', ['b', 'c']).fast(4), sequence('a', ['b', 'c']).fast(2));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('rev()', function () {
|
describe('rev()', function () {
|
||||||
it('Can reverse things', function () {
|
it('Can reverse things', function () {
|
||||||
@@ -390,6 +601,11 @@ describe('Pattern', function () {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('brak()', () => {
|
||||||
|
it('Can make something a bit breakbeaty', () => {
|
||||||
|
sameFirst(sequence('a', 'b').brak()._fast(2), sequence('a', 'b', fastcat(silence, 'a'), fastcat('b', silence)));
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('timeCat()', function () {
|
describe('timeCat()', function () {
|
||||||
it('Can concatenate patterns with different relative durations', function () {
|
it('Can concatenate patterns with different relative durations', function () {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
@@ -399,7 +615,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('struct()', function () {
|
describe('struct()', function () {
|
||||||
it('Can restructure a pattern', function () {
|
it('Can restructure a discrete pattern', function () {
|
||||||
assert.deepStrictEqual(sequence('a', 'b').struct(sequence(true, true, true)).firstCycle(), [
|
assert.deepStrictEqual(sequence('a', 'b').struct(sequence(true, true, true)).firstCycle(), [
|
||||||
hap(ts(0, third), ts(0, third), 'a'),
|
hap(ts(0, third), ts(0, third), 'a'),
|
||||||
hap(ts(third, twothirds), ts(third, 0.5), 'a'),
|
hap(ts(third, twothirds), ts(third, 0.5), 'a'),
|
||||||
@@ -425,6 +641,12 @@ describe('Pattern', function () {
|
|||||||
sequence('a', ['a', silence], 'a').firstCycle(),
|
sequence('a', ['a', silence], 'a').firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('Can structure a continuous pattern', () => {
|
||||||
|
assert.deepStrictEqual(
|
||||||
|
steady('a').struct(true, [true, true]).firstCycle(),
|
||||||
|
sequence('a', ['a', 'a']).firstCycle(),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('mask()', function () {
|
describe('mask()', function () {
|
||||||
it('Can fragment a pattern', function () {
|
it('Can fragment a pattern', function () {
|
||||||
@@ -474,7 +696,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('_setContext()', () => {
|
describe('_setContext()', () => {
|
||||||
it('Can set the event context', () => {
|
it('Can set the hap context', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure('a')
|
pure('a')
|
||||||
._setContext([
|
._setContext([
|
||||||
@@ -496,7 +718,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('_withContext()', () => {
|
describe('_withContext()', () => {
|
||||||
it('Can update the event context', () => {
|
it('Can update the hap context', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure('a')
|
pure('a')
|
||||||
._setContext([
|
._setContext([
|
||||||
@@ -551,13 +773,13 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('early', () => {
|
describe('early', () => {
|
||||||
it('Can shift an event earlier', () => {
|
it('Can shift a hap earlier', () => {
|
||||||
assert.deepStrictEqual(pure(30)._late(0.25).query(st(1, 2)), [
|
assert.deepStrictEqual(pure(30)._late(0.25).query(st(1, 2)), [
|
||||||
hap(ts(1 / 4, 5 / 4), ts(1, 5 / 4), 30),
|
hap(ts(1 / 4, 5 / 4), ts(1, 5 / 4), 30),
|
||||||
hap(ts(5 / 4, 9 / 4), ts(5 / 4, 2), 30),
|
hap(ts(5 / 4, 9 / 4), ts(5 / 4, 2), 30),
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
it('Can shift an event earlier, into negative time', () => {
|
it('Can shift a hap earlier, into negative time', () => {
|
||||||
assert.deepStrictEqual(pure(30)._late(0.25).query(st(0, 1)), [
|
assert.deepStrictEqual(pure(30)._late(0.25).query(st(0, 1)), [
|
||||||
hap(ts(-3 / 4, 1 / 4), ts(0, 1 / 4), 30),
|
hap(ts(-3 / 4, 1 / 4), ts(0, 1 / 4), 30),
|
||||||
hap(ts(1 / 4, 5 / 4), ts(1 / 4, 1), 30),
|
hap(ts(1 / 4, 5 / 4), ts(1 / 4, 1), 30),
|
||||||
@@ -575,9 +797,9 @@ describe('Pattern', function () {
|
|||||||
describe('jux', () => {
|
describe('jux', () => {
|
||||||
it('Can juxtapose', () => {
|
it('Can juxtapose', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure({ a: 1 }).jux(fast(2))._sortEventsByPart().firstCycle(),
|
pure({ a: 1 }).jux(fast(2))._sortHapsByPart().firstCycle(),
|
||||||
stack(pure({ a: 1, pan: 0 }), pure({ a: 1, pan: 1 }).fast(2))
|
stack(pure({ a: 1, pan: 0 }), pure({ a: 1, pan: 1 }).fast(2))
|
||||||
._sortEventsByPart()
|
._sortHapsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -585,9 +807,9 @@ describe('Pattern', function () {
|
|||||||
describe('juxBy', () => {
|
describe('juxBy', () => {
|
||||||
it('Can juxtapose by half', () => {
|
it('Can juxtapose by half', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure({ a: 1 }).juxBy(0.5, fast(2))._sortEventsByPart().firstCycle(),
|
pure({ a: 1 }).juxBy(0.5, fast(2))._sortHapsByPart().firstCycle(),
|
||||||
stack(pure({ a: 1, pan: 0.25 }), pure({ a: 1, pan: 0.75 }).fast(2))
|
stack(pure({ a: 1, pan: 0.25 }), pure({ a: 1, pan: 0.75 }).fast(2))
|
||||||
._sortEventsByPart()
|
._sortHapsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -616,6 +838,18 @@ describe('Pattern', function () {
|
|||||||
sequence(pure('a').fast(3), [pure('b').fast(3), pure('c').fast(3)]).firstCycle(),
|
sequence(pure('a').fast(3), [pure('b').fast(3), pure('c').fast(3)]).firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
it('Doesnt drop haps in the 9th cycle', () => {
|
||||||
|
// fixed with https://github.com/tidalcycles/strudel/commit/72eeaf446e3d5e186d63cc0d2276f0723cde017a
|
||||||
|
assert.equal(sequence(1, 2, 3).ply(2).early(8).firstCycle().length, 6);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('striate', () => {
|
||||||
|
it('Can striate(2)', () => {
|
||||||
|
sameFirst(
|
||||||
|
sequence({ sound: 'a' }).striate(2),
|
||||||
|
sequence({ sound: 'a', begin: 0, end: 0.5 }, { sound: 'a', begin: 0.5, end: 1 }),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('chop', () => {
|
describe('chop', () => {
|
||||||
it('Can _chop(2)', () => {
|
it('Can _chop(2)', () => {
|
||||||
@@ -631,7 +865,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
it('Can chop(2,3)', () => {
|
it('Can chop(2,3)', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure({ sound: 'a' }).fast(2).chop(2, 3)._sortEventsByPart().firstCycle(),
|
pure({ sound: 'a' }).fast(2).chop(2, 3)._sortHapsByPart().firstCycle(),
|
||||||
sequence(
|
sequence(
|
||||||
[
|
[
|
||||||
{ sound: 'a', begin: 0, end: 0.5 },
|
{ sound: 'a', begin: 0, end: 0.5 },
|
||||||
@@ -643,7 +877,7 @@ describe('Pattern', function () {
|
|||||||
{ sound: 'a', begin: 2 / 3, end: 1 },
|
{ sound: 'a', begin: 2 / 3, end: 1 },
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
._sortEventsByPart()
|
._sortHapsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
|
/*
|
||||||
|
util.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/test/util.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 { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { isNote, tokenizeNote, toMidi, mod, compose } from '../util.mjs';
|
import { pure } from '../pattern.mjs';
|
||||||
|
import { isNote, tokenizeNote, toMidi, fromMidi, mod, compose, getFrequency } from '../util.mjs';
|
||||||
|
|
||||||
describe('isNote', () => {
|
describe('isNote', () => {
|
||||||
it('should recognize notes without accidentals', () => {
|
it('should recognize notes without accidentals', () => {
|
||||||
@@ -64,6 +71,21 @@ describe('toMidi', () => {
|
|||||||
assert.equal(toMidi('C##3'), 50);
|
assert.equal(toMidi('C##3'), 50);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe('fromMidi', () => {
|
||||||
|
it('should turn midi into frequency', () => {
|
||||||
|
assert.equal(fromMidi(69), 440);
|
||||||
|
assert.equal(fromMidi(57), 220);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('getFrequency', () => {
|
||||||
|
it('should turn midi into frequency', () => {
|
||||||
|
const happify = (val, context = {}) => pure(val).firstCycle()[0].setContext(context);
|
||||||
|
assert.equal(getFrequency(happify('a4')), 440);
|
||||||
|
assert.equal(getFrequency(happify('a3')), 220);
|
||||||
|
assert.equal(getFrequency(happify(440, { type: 'frequency' })), 440); // TODO: migrate when values are objects..
|
||||||
|
assert.equal(getFrequency(happify(432, { type: 'frequency' })), 432);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('mod', () => {
|
describe('mod', () => {
|
||||||
it('should work like regular modulo with positive numbers', () => {
|
it('should work like regular modulo with positive numbers', () => {
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
value.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/test/value.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 { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { map, valued, mul } from '../value.mjs';
|
import { map, valued, mul } from '../value.mjs';
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
timespan.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/timespan.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 Fraction from './fraction.mjs';
|
import Fraction from './fraction.mjs';
|
||||||
|
|
||||||
export class TimeSpan {
|
export class TimeSpan {
|
||||||
@@ -28,12 +34,16 @@ export class TimeSpan {
|
|||||||
return spans;
|
return spans;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get duration() {
|
||||||
|
return this.end.sub(this.begin);
|
||||||
|
}
|
||||||
|
|
||||||
cycleArc() {
|
cycleArc() {
|
||||||
// Shifts a timespan to one of equal duration that starts within cycle zero.
|
// Shifts a timespan to one of equal duration that starts within cycle zero.
|
||||||
// (Note that the output timespan probably does not start *at* Time 0 --
|
// (Note that the output timespan probably does not start *at* Time 0 --
|
||||||
// that only happens when the input Arc starts at an integral Time.)
|
// that only happens when the input Arc starts at an integral Time.)
|
||||||
const b = this.begin.cyclePos();
|
const b = this.begin.cyclePos();
|
||||||
const e = b + (this.end - this.begin);
|
const e = b.add(this.duration);
|
||||||
return new TimeSpan(b, e);
|
return new TimeSpan(b, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,14 +91,13 @@ export class TimeSpan {
|
|||||||
// Like 'sect', but raises an exception if the timespans don't intersect.
|
// Like 'sect', but raises an exception if the timespans don't intersect.
|
||||||
const result = this.intersection(other);
|
const result = this.intersection(other);
|
||||||
if (result == undefined) {
|
if (result == undefined) {
|
||||||
// TODO - raise exception
|
throw 'TimeSpans do not intersect';
|
||||||
// raise ValueError(f'TimeSpan {self} and TimeSpan {other} do not intersect')
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
midpoint() {
|
midpoint() {
|
||||||
return this.begin.add(this.end.sub(this.begin).div(Fraction(2)));
|
return this.begin.add(this.duration.div(Fraction(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
equals(other) {
|
equals(other) {
|
||||||
|
|||||||
+26
-4
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
util.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/util.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
// returns true if the given string is a note
|
// returns true if the given string is a note
|
||||||
export const isNote = (name) => /^[a-gA-G][#b]*[0-9]$/.test(name);
|
export const isNote = (name) => /^[a-gA-G][#b]*[0-9]$/.test(name);
|
||||||
export const tokenizeNote = (note) => {
|
export const tokenizeNote = (note) => {
|
||||||
@@ -27,19 +33,35 @@ export const fromMidi = (n) => {
|
|||||||
|
|
||||||
// modulo that works with negative numbers e.g. mod(-1, 3) = 2
|
// modulo that works with negative numbers e.g. mod(-1, 3) = 2
|
||||||
// const mod = (n: number, m: number): number => (n < 0 ? mod(n + m, m) : n % m);
|
// const mod = (n: number, m: number): number => (n < 0 ? mod(n + m, m) : n % m);
|
||||||
export const mod = (n, m) => (n < 0 ? mod(n + m, m) : n % m);
|
export const mod = (n, m) => ((n % m) + m) % m;
|
||||||
|
|
||||||
export const getPlayableNoteValue = (event) => {
|
export const getPlayableNoteValue = (hap) => {
|
||||||
let { value: note, context } = event;
|
let { value: note, context } = hap;
|
||||||
// if value is number => interpret as midi number as long as its not marked as frequency
|
// if value is number => interpret as midi number as long as its not marked as frequency
|
||||||
if (typeof note === 'number' && context.type !== 'frequency') {
|
if (typeof note === 'number' && context.type !== 'frequency') {
|
||||||
note = fromMidi(event.value);
|
note = fromMidi(hap.value);
|
||||||
} else if (typeof note === 'string' && !isNote(note)) {
|
} else if (typeof note === 'string' && !isNote(note)) {
|
||||||
throw new Error('not a note: ' + note);
|
throw new Error('not a note: ' + note);
|
||||||
}
|
}
|
||||||
return note;
|
return note;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getFrequency = (hap) => {
|
||||||
|
let { value, context } = hap;
|
||||||
|
// if value is number => interpret as midi number as long as its not marked as frequency
|
||||||
|
if (typeof value === 'object' && value.freq) {
|
||||||
|
return value.freq;
|
||||||
|
}
|
||||||
|
if (typeof value === 'number' && context.type !== 'frequency') {
|
||||||
|
value = fromMidi(hap.value);
|
||||||
|
} else if (typeof value === 'string' && isNote(value)) {
|
||||||
|
value = fromMidi(toMidi(hap.value));
|
||||||
|
} else if (typeof value !== 'number') {
|
||||||
|
throw new Error('not a note or frequency:' + value);
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
// rotate array by n steps (to the left)
|
// rotate array by n steps (to the left)
|
||||||
export const rotate = (arr, n) => arr.slice(n).concat(arr.slice(0, n));
|
export const rotate = (arr, n) => arr.slice(n).concat(arr.slice(0, n));
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
/*
|
||||||
|
value.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/core/value.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 { curry } from './util.mjs';
|
import { curry } from './util.mjs';
|
||||||
|
|
||||||
function unionWithObj(a, b, func) {
|
export function unionWithObj(a, b, func) {
|
||||||
const common = Object.keys(a).filter((k) => Object.keys(b).includes(k));
|
const common = Object.keys(a).filter((k) => Object.keys(b).includes(k));
|
||||||
return Object.assign({}, a, b, Object.fromEntries(common.map((k) => [k, func(a[k], b[k])])));
|
return Object.assign({}, a, b, Object.fromEntries(common.map((k) => [k, func(a[k], b[k])])));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# @strudel.cycles/embed
|
||||||
|
|
||||||
|
This package contains a embeddable web component for the Strudel REPL.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Either install with `npm i @strudel.cycles/embed` or just use a cdn to import the script:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="https://unpkg.com/@strudel.cycles/embed@latest"></script>
|
||||||
|
<strudel-repl>
|
||||||
|
<!--
|
||||||
|
"a4 [a3 c3] a3 c3".color('#F9D649')
|
||||||
|
.sub("<7 12 5 12>".slow(2))
|
||||||
|
.off(1/4,x=>x.add(7).color("#FFFFFF #0C3AA1 #C63928"))
|
||||||
|
.off(1/8,x=>x.add(12).color('#215CB6'))
|
||||||
|
.slow(2)
|
||||||
|
.legato(sine.range(0.3, 2).slow(28))
|
||||||
|
.wave("sawtooth square".fast(2))
|
||||||
|
.filter('lowpass', cosine.range(500,4000).slow(16))
|
||||||
|
.out()
|
||||||
|
.pianoroll({minMidi:20,maxMidi:120,background:'#202124'})
|
||||||
|
-->
|
||||||
|
</strudel-repl>
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the Code is placed inside HTML comments to prevent the browser from treating it as HTML.
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
class Strudel extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
connectedCallback() {
|
||||||
|
setTimeout(() => {
|
||||||
|
const code = (this.innerHTML + '').replace('<!--', '').replace('-->', '').trim();
|
||||||
|
const iframe = document.createElement('iframe');
|
||||||
|
const src = `https://strudel.tidalcycles.org/#${encodeURIComponent(btoa(code))}`;
|
||||||
|
// const src = `http://localhost:3000/#${encodeURIComponent(btoa(code))}`;
|
||||||
|
iframe.setAttribute('src', src);
|
||||||
|
iframe.setAttribute('width', '600');
|
||||||
|
iframe.setAttribute('height', '400');
|
||||||
|
this.appendChild(iframe);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
customElements.define('strudel-repl', Strudel);
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<script src="https://unpkg.com/@strudel.cycles/embed@latest"></script>
|
||||||
|
<!-- <script src="./embed.js"></script> -->
|
||||||
|
<strudel-repl>
|
||||||
|
<!--
|
||||||
|
"a4 [a3 c3] a3 c3".color('#F9D649')
|
||||||
|
.sub("<7 12 5 12>".slow(2))
|
||||||
|
.off(1/4,x=>x.add(7).color("#FFFFFF #0C3AA1 #C63928"))
|
||||||
|
.off(1/8,x=>x.add(12).color('#215CB6'))
|
||||||
|
.slow(2)
|
||||||
|
.legato(sine.range(0.3, 2).slow(28))
|
||||||
|
.wave("sawtooth square".fast(2))
|
||||||
|
.filter('lowpass', cosine.range(500,4000).slow(16))
|
||||||
|
.out()
|
||||||
|
.pianoroll({minMidi:20,maxMidi:120,background:'#202124'})
|
||||||
|
-->
|
||||||
|
</strudel-repl>
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "@strudel.cycles/embed",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Embeddable Web Component to load a Strudel REPL into an iframe",
|
||||||
|
"main": "embed.js",
|
||||||
|
"type": "module",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ npm i @strudel.cycles/eval --save
|
|||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
|
<!-- TODO: -extend +evalScope -->
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { evaluate, extend } from '@strudel.cycles/eval';
|
import { evaluate, extend } from '@strudel.cycles/eval';
|
||||||
import * as strudel from '@strudel.cycles/core';
|
import * as strudel from '@strudel.cycles/core';
|
||||||
|
|||||||
@@ -1,17 +1,45 @@
|
|||||||
|
/*
|
||||||
|
evaluate.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/eval/evaluate.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 shapeshifter from './shapeshifter.mjs';
|
import shapeshifter from './shapeshifter.mjs';
|
||||||
import * as strudel from '@strudel.cycles/core';
|
import * as strudel from '@strudel.cycles/core';
|
||||||
|
|
||||||
const { isPattern } = strudel;
|
const { isPattern, Pattern } = strudel;
|
||||||
|
|
||||||
export const extend = (...args) => {
|
export const extend = (...args) => {
|
||||||
// TODO: find a way to make args available to eval without adding it to global scope...
|
console.warn('@strudel.cycles/eval extend is deprecated, please use evalScope instead');
|
||||||
// sadly, "with" does not work in strict mode
|
|
||||||
Object.assign(globalThis, ...args);
|
Object.assign(globalThis, ...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let scoped = false;
|
||||||
|
export const evalScope = async (...args) => {
|
||||||
|
if (scoped) {
|
||||||
|
console.warn('@strudel.cycles/eval evalScope was called more than once.');
|
||||||
|
}
|
||||||
|
scoped = true;
|
||||||
|
const results = await Promise.allSettled(args);
|
||||||
|
const modules = results.filter((result) => result.status === 'fulfilled').map((r) => r.value);
|
||||||
|
results.forEach((result, i) => {
|
||||||
|
if (result.status === 'rejected') {
|
||||||
|
console.warn(`evalScope: module with index ${i} could not be loaded:`, result.reason);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Object.assign(globalThis, ...modules, Pattern.prototype.bootstrap());
|
||||||
|
};
|
||||||
|
|
||||||
|
function safeEval(str) {
|
||||||
|
return Function('"use strict";return (' + str + ')')();
|
||||||
|
}
|
||||||
|
|
||||||
export const evaluate = async (code) => {
|
export const evaluate = async (code) => {
|
||||||
|
if (!scoped) {
|
||||||
|
await evalScope(); // at least scope Pattern.prototype.boostrap
|
||||||
|
}
|
||||||
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
||||||
let evaluated = await eval(shapeshifted);
|
let evaluated = await safeEval(shapeshifted);
|
||||||
if (!isPattern(evaluated)) {
|
if (!isPattern(evaluated)) {
|
||||||
console.log('evaluated', evaluated);
|
console.log('evaluated', evaluated);
|
||||||
const message = `got "${typeof evaluated}" instead of pattern`;
|
const message = `got "${typeof evaluated}" instead of pattern`;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export * from './evaluate.mjs';
|
||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/eval",
|
"name": "@strudel.cycles/eval",
|
||||||
"version": "0.0.5",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/eval",
|
"name": "@strudel.cycles/eval",
|
||||||
"version": "0.0.5",
|
"version": "0.1.1",
|
||||||
"description": "Code evaluator for strudel",
|
"description": "Code evaluator for strudel",
|
||||||
"main": "evaluate.mjs",
|
"main": "index.mjs",
|
||||||
|
"type": "module",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/tidalcycles/strudel.git"
|
"url": "git+https://github.com/tidalcycles/strudel.git"
|
||||||
},
|
},
|
||||||
"type": "module",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"tidalcycles",
|
"tidalcycles",
|
||||||
"strudel",
|
"strudel",
|
||||||
@@ -22,13 +22,13 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel.cycles/core": "^0.0.5",
|
"@strudel.cycles/core": "^0.1.0",
|
||||||
"estraverse": "^5.3.0",
|
"estraverse": "^5.3.0",
|
||||||
"shift-ast": "^6.1.0",
|
"shift-ast": "^6.1.0",
|
||||||
"shift-codegen": "^7.0.3",
|
"shift-codegen": "^7.0.3",
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
shapeshifter.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/eval/shapeshifter.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 { parseScriptWithLocation } from './shift-parser/index.js'; // npm module does not work in the browser
|
/* import { parseScriptWithLocation } from './shift-parser/index.js'; // npm module does not work in the browser
|
||||||
import traverser from './shift-traverser/index.js'; // npm module does not work in the browser */
|
import traverser from './shift-traverser/index.js'; // npm module does not work in the browser */
|
||||||
import { parseScriptWithLocation } from 'shift-parser';
|
import { parseScriptWithLocation } from 'shift-parser';
|
||||||
@@ -23,6 +29,8 @@ const isNote = (name) => /^[a-gC-G][bs]?[0-9]$/.test(name);
|
|||||||
|
|
||||||
const addLocations = true;
|
const addLocations = true;
|
||||||
export const addMiniLocations = true;
|
export const addMiniLocations = true;
|
||||||
|
export const minifyStrings = true;
|
||||||
|
export const wrappedAsync = true;
|
||||||
|
|
||||||
export default (_code) => {
|
export default (_code) => {
|
||||||
const { code, addReturn } = wrapAsync(_code);
|
const { code, addReturn } = wrapAsync(_code);
|
||||||
@@ -38,18 +46,18 @@ export default (_code) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace template string `xxx` with mini(`xxx`)
|
// replace template string `xxx` with mini(`xxx`)
|
||||||
if (isBackTickString(node)) {
|
if (minifyStrings && isBackTickString(node)) {
|
||||||
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
||||||
}
|
}
|
||||||
// allows to use top level strings, which are normally directives... but we don't need directives
|
// allows to use top level strings, which are normally directives... but we don't need directives
|
||||||
if (node.directives?.length === 1 && !node.statements?.length) {
|
if (minifyStrings && node.directives?.length === 1 && !node.statements?.length) {
|
||||||
const str = new LiteralStringExpression({ value: node.directives[0].rawValue });
|
const str = new LiteralStringExpression({ value: node.directives[0].rawValue });
|
||||||
const wrapped = minifyWithLocation(str, node.directives[0], ast.locations, artificialNodes);
|
const wrapped = minifyWithLocation(str, node.directives[0], ast.locations, artificialNodes);
|
||||||
return { ...node, directives: [], statements: [wrapped] };
|
return { ...node, directives: [], statements: [wrapped] };
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace double quote string "xxx" with mini('xxx')
|
// replace double quote string "xxx" with mini('xxx')
|
||||||
if (isStringWithDoubleQuotes(node, ast.locations, code)) {
|
if (minifyStrings && isStringWithDoubleQuotes(node, ast.locations, code)) {
|
||||||
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +125,9 @@ export default (_code) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
// add return to last statement (because it's wrapped in an async function artificially)
|
// add return to last statement (because it's wrapped in an async function artificially)
|
||||||
addReturn(shifted);
|
if (wrappedAsync) {
|
||||||
|
addReturn(shifted);
|
||||||
|
}
|
||||||
const generated = codegen(shifted);
|
const generated = codegen(shifted);
|
||||||
return generated;
|
return generated;
|
||||||
};
|
};
|
||||||
@@ -125,9 +135,11 @@ export default (_code) => {
|
|||||||
function wrapAsync(code) {
|
function wrapAsync(code) {
|
||||||
// wrap code in async to make await work on top level => this will create 1 line offset to locations
|
// wrap code in async to make await work on top level => this will create 1 line offset to locations
|
||||||
// this is why line offset is -1 in getLocationObject calls below
|
// this is why line offset is -1 in getLocationObject calls below
|
||||||
code = `(async () => {
|
if (wrappedAsync) {
|
||||||
|
code = `(async () => {
|
||||||
${code}
|
${code}
|
||||||
})()`;
|
})()`;
|
||||||
|
}
|
||||||
const addReturn = (ast) => {
|
const addReturn = (ast) => {
|
||||||
const body = ast.statements[0].expression.callee.body; // actual code ast inside async function body
|
const body = ast.statements[0].expression.callee.body; // actual code ast inside async function body
|
||||||
body.statements = body.statements
|
body.statements = body.statements
|
||||||
@@ -204,9 +216,10 @@ function hasModifierCall(parent) {
|
|||||||
parent?.type === 'StaticMemberExpression' && Object.keys(Pattern.prototype.composable).includes(parent.property)
|
parent?.type === 'StaticMemberExpression' && Object.keys(Pattern.prototype.composable).includes(parent.property)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const factories = Object.keys(Pattern.prototype.factories).concat(['mini']);
|
||||||
|
|
||||||
function isPatternFactory(node) {
|
function isPatternFactory(node) {
|
||||||
return node?.type === 'CallExpression' && Object.keys(Pattern.prototype.factories).includes(node.callee.name);
|
return node?.type === 'CallExpression' && factories.includes(node.callee.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canBeOverloaded(node) {
|
function canBeOverloaded(node) {
|
||||||
@@ -233,9 +246,14 @@ function reifyWithLocation(literalNode, node, locations, artificialNodes) {
|
|||||||
// with this, the reified pattern can pass its location to the event, to know where to highlight when it's active
|
// with this, the reified pattern can pass its location to the event, to know where to highlight when it's active
|
||||||
function minifyWithLocation(literalNode, node, locations, artificialNodes) {
|
function minifyWithLocation(literalNode, node, locations, artificialNodes) {
|
||||||
const args = getLocationArguments(node, locations);
|
const args = getLocationArguments(node, locations);
|
||||||
|
const wrapped = wrapFunction('mini', literalNode);
|
||||||
|
if (!addMiniLocations) {
|
||||||
|
artificialNodes.push(wrapped);
|
||||||
|
return wrapped;
|
||||||
|
}
|
||||||
const withLocation = new CallExpression({
|
const withLocation = new CallExpression({
|
||||||
callee: new StaticMemberExpression({
|
callee: new StaticMemberExpression({
|
||||||
object: wrapFunction('mini', literalNode),
|
object: wrapped,
|
||||||
property: 'withMiniLocation',
|
property: 'withMiniLocation',
|
||||||
}),
|
}),
|
||||||
arguments: args,
|
arguments: args,
|
||||||
@@ -246,17 +264,18 @@ function minifyWithLocation(literalNode, node, locations, artificialNodes) {
|
|||||||
|
|
||||||
function getLocationArguments(node, locations) {
|
function getLocationArguments(node, locations) {
|
||||||
const loc = locations.get(node);
|
const loc = locations.get(node);
|
||||||
|
const lineOffset = wrappedAsync ? -1 : 0;
|
||||||
return [
|
return [
|
||||||
new ArrayExpression({
|
new ArrayExpression({
|
||||||
elements: [
|
elements: [
|
||||||
new LiteralNumericExpression({ value: loc.start.line - 1 }), // the minus 1 assumes the code has been wrapped in async iife
|
new LiteralNumericExpression({ value: loc.start.line + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
|
||||||
new LiteralNumericExpression({ value: loc.start.column }),
|
new LiteralNumericExpression({ value: loc.start.column }),
|
||||||
new LiteralNumericExpression({ value: loc.start.offset }),
|
new LiteralNumericExpression({ value: loc.start.offset }),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new ArrayExpression({
|
new ArrayExpression({
|
||||||
elements: [
|
elements: [
|
||||||
new LiteralNumericExpression({ value: loc.end.line - 1 }), // the minus 1 assumes the code has been wrapped in async iife
|
new LiteralNumericExpression({ value: loc.end.line + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
|
||||||
new LiteralNumericExpression({ value: loc.end.column }),
|
new LiteralNumericExpression({ value: loc.end.column }),
|
||||||
new LiteralNumericExpression({ value: loc.end.offset }),
|
new LiteralNumericExpression({ value: loc.end.offset }),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
index.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/eval/shift-traverser/index.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
|
Copyright (C) 2014 Yusuke Suzuki <utatane.tea@gmail.com>
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
|
/*
|
||||||
|
evaluate.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/eval/test/evaluate.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 { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { evaluate, extend } from '../evaluate.mjs';
|
import { evaluate, extend } from '../evaluate.mjs';
|
||||||
import { mini } from '@strudel.cycles/mini';
|
import { mini } from '@strudel.cycles/mini';
|
||||||
import * as strudel from '@strudel.cycles/core';
|
import * as strudel from '@strudel.cycles/core';
|
||||||
|
|
||||||
const { cat } = strudel;
|
const { fastcat } = strudel;
|
||||||
|
|
||||||
extend({ mini }, strudel);
|
extend({ mini }, strudel);
|
||||||
|
// TODO: test evalScope
|
||||||
|
|
||||||
describe('evaluate', () => {
|
describe('evaluate', () => {
|
||||||
const ev = async (code) => (await evaluate(code)).pattern._firstCycleValues;
|
const ev = async (code) => (await evaluate(code)).pattern._firstCycleValues;
|
||||||
it('Should evaluate strudel functions', async () => {
|
it('Should evaluate strudel functions', async () => {
|
||||||
assert.deepStrictEqual(await ev("pure('c3')"), ['c3']);
|
assert.deepStrictEqual(await ev("pure('c3')"), ['c3']);
|
||||||
assert.deepStrictEqual(await ev('cat(c3)'), ['c3']);
|
assert.deepStrictEqual(await ev('cat(c3)'), ['c3']);
|
||||||
assert.deepStrictEqual(await ev('cat(c3, d3)'), ['c3', 'd3']);
|
assert.deepStrictEqual(await ev('fastcat(c3, d3)'), ['c3', 'd3']);
|
||||||
assert.deepStrictEqual(await ev('slowcat(c3, d3)'), ['c3']);
|
assert.deepStrictEqual(await ev('slowcat(c3, d3)'), ['c3']);
|
||||||
});
|
});
|
||||||
it('Should be extendable', async () => {
|
it('Should be extendable', async () => {
|
||||||
extend({ myFunction: (...x) => cat(...x) });
|
extend({ myFunction: (...x) => fastcat(...x) });
|
||||||
assert.deepStrictEqual(await ev('myFunction(c3, d3)'), ['c3', 'd3']);
|
assert.deepStrictEqual(await ev('myFunction(c3, d3)'), ['c3', 'd3']);
|
||||||
});
|
});
|
||||||
it('Should evaluate simple double quoted mini notation', async () => {
|
it('Should evaluate simple double quoted mini notation', async () => {
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
shapeshifter.test.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/eval/test/shapeshifter.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 { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import shapeshifter from '../shapeshifter.mjs';
|
import shapeshifter from '../shapeshifter.mjs';
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import './midi.mjs';
|
||||||
|
|
||||||
|
export * from './midi.mjs';
|
||||||
+13
-7
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
midi.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/midi/midi.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 { isNote } from 'tone';
|
import { isNote } from 'tone';
|
||||||
import _WebMidi from 'webmidi';
|
import _WebMidi from 'webmidi';
|
||||||
import { Pattern, isPattern } from '@strudel.cycles/core';
|
import { Pattern, isPattern } from '@strudel.cycles/core';
|
||||||
@@ -33,11 +39,11 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
|||||||
}')`,
|
}')`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this._withEvent((event) => {
|
return this._withHap((hap) => {
|
||||||
// const onTrigger = (time: number, event: any) => {
|
// const onTrigger = (time: number, hap: any) => {
|
||||||
const onTrigger = (time, event) => {
|
const onTrigger = (time, hap) => {
|
||||||
let note = event.value;
|
let note = hap.value;
|
||||||
const velocity = event.context?.velocity ?? 0.9;
|
const velocity = hap.context?.velocity ?? 0.9;
|
||||||
if (!isNote(note)) {
|
if (!isNote(note)) {
|
||||||
throw new Error('not a note: ' + note);
|
throw new Error('not a note: ' + note);
|
||||||
}
|
}
|
||||||
@@ -69,10 +75,10 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
|||||||
// await enableWebMidi()
|
// await enableWebMidi()
|
||||||
device.playNote(note, channel, {
|
device.playNote(note, channel, {
|
||||||
time,
|
time,
|
||||||
duration: event.duration * 1000 - 5,
|
duration: hap.duration.valueOf() * 1000 - 5,
|
||||||
velocity,
|
velocity,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return event.setContext({ ...event.context, onTrigger });
|
return hap.setContext({ ...hap.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/midi",
|
"name": "@strudel.cycles/midi",
|
||||||
"version": "0.0.6",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/midi",
|
"name": "@strudel.cycles/midi",
|
||||||
"version": "0.0.6",
|
"version": "0.1.1",
|
||||||
"description": "Midi API for strudel",
|
"description": "Midi API for strudel",
|
||||||
"main": "midi.mjs",
|
"main": "index.mjs",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/tidalcycles/strudel.git"
|
"url": "git+https://github.com/tidalcycles/strudel.git"
|
||||||
@@ -15,13 +15,13 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel.cycles/tone": "^0.0.6",
|
"@strudel.cycles/tone": "^0.1.1",
|
||||||
"tone": "^14.7.77",
|
"tone": "^14.7.77",
|
||||||
"webmidi": "^2.5.2"
|
"webmidi": "^2.5.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './mini.mjs';
|
||||||
|
export * from './krill-parser.js';
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
krill-parser.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/mini/krill-parser.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
// Generated by Peggy 1.2.0.
|
// Generated by Peggy 1.2.0.
|
||||||
//
|
//
|
||||||
// https://peggyjs.org/
|
// https://peggyjs.org/
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
krill.pegjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/mini/krill.pegjs>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
// Some terminology:
|
// Some terminology:
|
||||||
// a sequence = a serie of elements placed between quotes
|
// a sequence = a serie of elements placed between quotes
|
||||||
// a stack = a serie of vertically aligned slices sharing the same overall length
|
// a stack = a serie of vertically aligned slices sharing the same overall length
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
mini.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/mini/mini.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 * as krill from './krill-parser.js';
|
import * as krill from './krill-parser.js';
|
||||||
import * as strudel from '@strudel.cycles/core';
|
import * as strudel from '@strudel.cycles/core';
|
||||||
import { addMiniLocations } from '@strudel.cycles/eval/shapeshifter.mjs';
|
import { addMiniLocations } from '@strudel.cycles/eval/shapeshifter.mjs';
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/mini",
|
"name": "@strudel.cycles/mini",
|
||||||
"version": "0.0.6",
|
"version": "0.1.1",
|
||||||
"description": "Mini notation for strudel",
|
"description": "Mini notation for strudel",
|
||||||
"main": "mini.mjs",
|
"main": "index.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --colors"
|
"test": "mocha --colors"
|
||||||
@@ -19,13 +19,14 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "GPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
"homepage": "https://github.com/tidalcycles/strudel#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@strudel.cycles/eval": "^0.0.5",
|
"@strudel.cycles/core": "^0.1.0",
|
||||||
"@strudel.cycles/tone": "^0.0.6"
|
"@strudel.cycles/eval": "^0.1.1",
|
||||||
|
"@strudel.cycles/tone": "^0.1.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
mini.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 { strict as assert } from 'assert';
|
import { strict as assert } from 'assert';
|
||||||
import { mini } from '../mini.mjs';
|
import { mini } from '../mini.mjs';
|
||||||
import '@strudel.cycles/core/euclid.mjs';
|
import '@strudel.cycles/core/euclid.mjs';
|
||||||
|
|||||||
+16
-6
@@ -1,23 +1,33 @@
|
|||||||
|
/*
|
||||||
|
osc.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/osc/osc.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 OSC from 'osc-js';
|
import OSC from 'osc-js';
|
||||||
import { Pattern } from '@strudel.cycles/core';
|
import { Pattern } from '@strudel.cycles/core';
|
||||||
|
|
||||||
const comm = new OSC();
|
const comm = new OSC();
|
||||||
comm.open();
|
comm.open();
|
||||||
const latency = 0.1;
|
const latency = 0.1;
|
||||||
|
let startedAt = -1;
|
||||||
|
|
||||||
Pattern.prototype.osc = function () {
|
Pattern.prototype.osc = function () {
|
||||||
return this._withEvent((event) => {
|
return this._withHap((hap) => {
|
||||||
const onTrigger = (time, event, currentTime) => {
|
const onTrigger = (time, hap, currentTime, cps, cycle, delta) => {
|
||||||
// time should be audio time of onset
|
// time should be audio time of onset
|
||||||
// currentTime should be current time of audio context (slightly before time)
|
// currentTime should be current time of audio context (slightly before time)
|
||||||
const keyvals = Object.entries(event.value).flat();
|
if (startedAt < 0) {
|
||||||
const offset = (time - currentTime + latency) * 1000;
|
startedAt = Date.now() - (currentTime * 1000);
|
||||||
const ts = Math.floor(Date.now() + offset);
|
}
|
||||||
|
const controls = Object.assign({}, { cps: cps, cycle: cycle, delta: delta }, hap.value);
|
||||||
|
const keyvals = Object.entries(controls).flat();
|
||||||
|
const ts = Math.floor(startedAt + ((time + latency) * 1000));
|
||||||
const message = new OSC.Message('/dirt/play', ...keyvals);
|
const message = new OSC.Message('/dirt/play', ...keyvals);
|
||||||
const bundle = new OSC.Bundle([message], ts);
|
const bundle = new OSC.Bundle([message], ts);
|
||||||
bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60
|
bundle.timestamp(ts); // workaround for https://github.com/adzialocha/osc-js/issues/60
|
||||||
comm.send(bundle);
|
comm.send(bundle);
|
||||||
};
|
};
|
||||||
return event.setContext({ ...event.context, onTrigger });
|
return hap.setContext({ ...hap.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/osc",
|
"name": "@strudel.cycles/osc",
|
||||||
"version": "0.0.2",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/osc",
|
"name": "@strudel.cycles/osc",
|
||||||
"version": "0.0.2",
|
"version": "0.1.0",
|
||||||
"description": "OSC messaging for strudel",
|
"description": "OSC messaging for strudel",
|
||||||
"main": "osc.mjs",
|
"main": "osc.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -21,7 +21,10 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "GPL-3.0-or-later",
|
"contributors": [
|
||||||
|
"Alex McLean <alex@slab.org>"
|
||||||
|
],
|
||||||
|
"license": "AGPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
server.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/osc/server.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
const OSC = require('osc-js');
|
const OSC = require('osc-js');
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
|||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
tidal-sniffer.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/osc/tidal-sniffer.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
const OSC = require('osc-js');
|
const OSC = require('osc-js');
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
!dist
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# @strudel.cycles/react
|
||||||
|
|
||||||
|
This package contains react hooks and components for strudel.
|
||||||
|
Example coming soon
|
||||||
Vendored
+3
File diff suppressed because one or more lines are too long
Vendored
+620
@@ -0,0 +1,620 @@
|
|||||||
|
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react';
|
||||||
|
import { CodeMirror as CodeMirror$1 } from 'react-codemirror6';
|
||||||
|
import { EditorView, Decoration } from '@codemirror/view';
|
||||||
|
import { StateEffect, StateField } from '@codemirror/state';
|
||||||
|
import { javascript } from '@codemirror/lang-javascript';
|
||||||
|
import { HighlightStyle, tags } from '@codemirror/highlight';
|
||||||
|
import { useInView } from 'react-hook-inview';
|
||||||
|
import { evaluate } from '@strudel.cycles/eval';
|
||||||
|
import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs';
|
||||||
|
import { Tone } from '@strudel.cycles/tone';
|
||||||
|
import { TimeSpan, State } from '@strudel.cycles/core';
|
||||||
|
import { WebMidi, enableWebMidi } from '@strudel.cycles/midi';
|
||||||
|
|
||||||
|
/*
|
||||||
|
Credits for color palette:
|
||||||
|
|
||||||
|
Author: Mattia Astorino (http://github.com/equinusocio)
|
||||||
|
Website: https://material-theme.site/
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ivory = '#abb2bf',
|
||||||
|
stone = '#7d8799', // Brightened compared to original to increase contrast
|
||||||
|
invalid = '#ffffff',
|
||||||
|
darkBackground = '#21252b',
|
||||||
|
highlightBackground = 'rgba(0, 0, 0, 0.5)',
|
||||||
|
// background = '#292d3e',
|
||||||
|
background = 'transparent',
|
||||||
|
tooltipBackground = '#353a42',
|
||||||
|
selection = 'rgba(128, 203, 196, 0.2)',
|
||||||
|
cursor = '#ffcc00';
|
||||||
|
|
||||||
|
/// The editor theme styles for Material Palenight.
|
||||||
|
const materialPalenightTheme = EditorView.theme(
|
||||||
|
{
|
||||||
|
// done
|
||||||
|
'&': {
|
||||||
|
color: '#ffffff',
|
||||||
|
backgroundColor: background,
|
||||||
|
fontSize: '15px',
|
||||||
|
'z-index': 11,
|
||||||
|
},
|
||||||
|
|
||||||
|
// done
|
||||||
|
'.cm-content': {
|
||||||
|
caretColor: cursor,
|
||||||
|
lineHeight: '22px',
|
||||||
|
},
|
||||||
|
'.cm-line': {
|
||||||
|
background: '#2C323699',
|
||||||
|
},
|
||||||
|
// done
|
||||||
|
'&.cm-focused .cm-cursor': {
|
||||||
|
borderLeftColor: cursor,
|
||||||
|
},
|
||||||
|
|
||||||
|
'&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection': {
|
||||||
|
backgroundColor: selection,
|
||||||
|
},
|
||||||
|
|
||||||
|
'.cm-panels': { backgroundColor: darkBackground, color: '#ffffff' },
|
||||||
|
'.cm-panels.cm-panels-top': { borderBottom: '2px solid black' },
|
||||||
|
'.cm-panels.cm-panels-bottom': { borderTop: '2px solid black' },
|
||||||
|
|
||||||
|
// done, use onedarktheme
|
||||||
|
'.cm-searchMatch': {
|
||||||
|
backgroundColor: '#72a1ff59',
|
||||||
|
outline: '1px solid #457dff',
|
||||||
|
},
|
||||||
|
'.cm-searchMatch.cm-searchMatch-selected': {
|
||||||
|
backgroundColor: '#6199ff2f',
|
||||||
|
},
|
||||||
|
|
||||||
|
'.cm-activeLine': { backgroundColor: highlightBackground },
|
||||||
|
'.cm-selectionMatch': { backgroundColor: '#aafe661a' },
|
||||||
|
|
||||||
|
'&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket': {
|
||||||
|
backgroundColor: '#bad0f847',
|
||||||
|
outline: '1px solid #515a6b',
|
||||||
|
},
|
||||||
|
|
||||||
|
// done
|
||||||
|
'.cm-gutters': {
|
||||||
|
background: '#2C323699',
|
||||||
|
color: '#676e95',
|
||||||
|
border: 'none',
|
||||||
|
},
|
||||||
|
|
||||||
|
'.cm-activeLineGutter': {
|
||||||
|
backgroundColor: highlightBackground,
|
||||||
|
},
|
||||||
|
|
||||||
|
'.cm-foldPlaceholder': {
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
border: 'none',
|
||||||
|
color: '#ddd',
|
||||||
|
},
|
||||||
|
|
||||||
|
'.cm-tooltip': {
|
||||||
|
border: 'none',
|
||||||
|
backgroundColor: tooltipBackground,
|
||||||
|
},
|
||||||
|
'.cm-tooltip .cm-tooltip-arrow:before': {
|
||||||
|
borderTopColor: 'transparent',
|
||||||
|
borderBottomColor: 'transparent',
|
||||||
|
},
|
||||||
|
'.cm-tooltip .cm-tooltip-arrow:after': {
|
||||||
|
borderTopColor: tooltipBackground,
|
||||||
|
borderBottomColor: tooltipBackground,
|
||||||
|
},
|
||||||
|
'.cm-tooltip-autocomplete': {
|
||||||
|
'& > ul > li[aria-selected]': {
|
||||||
|
backgroundColor: highlightBackground,
|
||||||
|
color: ivory,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ dark: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
/// The highlighting style for code in the Material Palenight theme.
|
||||||
|
const materialPalenightHighlightStyle = HighlightStyle.define([
|
||||||
|
{ tag: tags.keyword, color: '#c792ea' },
|
||||||
|
{ tag: tags.operator, color: '#89ddff' },
|
||||||
|
{ tag: tags.special(tags.variableName), color: '#eeffff' },
|
||||||
|
{ tag: tags.typeName, color: '#f07178' },
|
||||||
|
{ tag: tags.atom, color: '#f78c6c' },
|
||||||
|
{ tag: tags.number, color: '#ff5370' },
|
||||||
|
{ tag: tags.definition(tags.variableName), color: '#82aaff' },
|
||||||
|
{ tag: tags.string, color: '#c3e88d' },
|
||||||
|
{ tag: tags.special(tags.string), color: '#f07178' },
|
||||||
|
{ tag: tags.comment, color: stone },
|
||||||
|
{ tag: tags.variableName, color: '#f07178' },
|
||||||
|
{ tag: tags.tagName, color: '#ff5370' },
|
||||||
|
{ tag: tags.bracket, color: '#a2a1a4' },
|
||||||
|
{ tag: tags.meta, color: '#ffcb6b' },
|
||||||
|
{ tag: tags.attributeName, color: '#c792ea' },
|
||||||
|
{ tag: tags.propertyName, color: '#c792ea' },
|
||||||
|
{ tag: tags.className, color: '#decb6b' },
|
||||||
|
{ tag: tags.invalid, color: invalid },
|
||||||
|
]);
|
||||||
|
|
||||||
|
/// Extension to enable the Material Palenight theme (both the editor theme and
|
||||||
|
/// the highlight style).
|
||||||
|
// : Extension
|
||||||
|
const materialPalenight = [materialPalenightTheme, materialPalenightHighlightStyle];
|
||||||
|
|
||||||
|
const setHighlights = StateEffect.define();
|
||||||
|
const highlightField = StateField.define({
|
||||||
|
create() {
|
||||||
|
return Decoration.none;
|
||||||
|
},
|
||||||
|
update(highlights, tr) {
|
||||||
|
try {
|
||||||
|
for (let e of tr.effects) {
|
||||||
|
if (e.is(setHighlights)) {
|
||||||
|
highlights = Decoration.set(e.value.flatMap((hap) => (hap.context.locations || []).map(({ start, end }) => {
|
||||||
|
const color = hap.context.color || "#FFCA28";
|
||||||
|
let from = tr.newDoc.line(start.line).from + start.column;
|
||||||
|
let to = tr.newDoc.line(end.line).from + end.column;
|
||||||
|
const l = tr.newDoc.length;
|
||||||
|
if (from > l || to > l) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const mark = Decoration.mark({ attributes: { style: `outline: 1px solid ${color}` } });
|
||||||
|
return mark.range(from, to);
|
||||||
|
})).filter(Boolean), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highlights;
|
||||||
|
} catch (err) {
|
||||||
|
return highlights;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide: (f) => EditorView.decorations.from(f)
|
||||||
|
});
|
||||||
|
function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) {
|
||||||
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(CodeMirror$1, {
|
||||||
|
onViewChange: onViewChanged,
|
||||||
|
style: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
flex: "1 0 auto"
|
||||||
|
},
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
extensions: [
|
||||||
|
javascript(),
|
||||||
|
materialPalenight,
|
||||||
|
highlightField
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
useCycle.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useCycle.mjs>
|
||||||
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* export declare interface UseCycleProps {
|
||||||
|
onEvent: ToneEventCallback<any>;
|
||||||
|
onQuery?: (state: State) => Hap[];
|
||||||
|
onSchedule?: (events: Hap[], cycle: number) => void;
|
||||||
|
onDraw?: ToneEventCallback<any>;
|
||||||
|
ready?: boolean; // if false, query will not be called on change props
|
||||||
|
} */
|
||||||
|
|
||||||
|
// function useCycle(props: UseCycleProps) {
|
||||||
|
function useCycle(props) {
|
||||||
|
// onX must use useCallback!
|
||||||
|
const { onEvent, onQuery, onSchedule, ready = true, onDraw } = props;
|
||||||
|
const [started, setStarted] = useState(false);
|
||||||
|
const cycleDuration = 1;
|
||||||
|
const activeCycle = () => Math.floor(Tone.getTransport().seconds / cycleDuration);
|
||||||
|
|
||||||
|
// pull events with onQuery + count up to next cycle
|
||||||
|
const query = (cycle = activeCycle()) => {
|
||||||
|
const timespan = new TimeSpan(cycle, cycle + 1);
|
||||||
|
const events = onQuery?.(new State(timespan)) || [];
|
||||||
|
onSchedule?.(events, cycle);
|
||||||
|
// cancel events after current query. makes sure no old events are player for rescheduled cycles
|
||||||
|
// console.log('schedule', cycle);
|
||||||
|
// query next cycle in the middle of the current
|
||||||
|
const cancelFrom = timespan.begin.valueOf();
|
||||||
|
Tone.getTransport().cancel(cancelFrom);
|
||||||
|
// const queryNextTime = (cycle + 1) * cycleDuration - 0.1;
|
||||||
|
const queryNextTime = (cycle + 1) * cycleDuration - 0.5;
|
||||||
|
|
||||||
|
// if queryNextTime would be before current time, execute directly (+0.1 for safety that it won't miss)
|
||||||
|
const t = Math.max(Tone.getTransport().seconds, queryNextTime) + 0.1;
|
||||||
|
Tone.getTransport().schedule(() => {
|
||||||
|
query(cycle + 1);
|
||||||
|
}, t);
|
||||||
|
|
||||||
|
// schedule events for next cycle
|
||||||
|
events
|
||||||
|
?.filter((event) => event.part.begin.equals(event.whole?.begin))
|
||||||
|
.forEach((event) => {
|
||||||
|
Tone.getTransport().schedule((time) => {
|
||||||
|
onEvent(time, event, Tone.getContext().currentTime);
|
||||||
|
Tone.Draw.schedule(() => {
|
||||||
|
// do drawing or DOM manipulation here
|
||||||
|
onDraw?.(time, event);
|
||||||
|
}, time);
|
||||||
|
}, event.part.begin.valueOf());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
ready && query();
|
||||||
|
}, [onEvent, onSchedule, onQuery, onDraw, ready]);
|
||||||
|
|
||||||
|
const start = async () => {
|
||||||
|
setStarted(true);
|
||||||
|
await Tone.start();
|
||||||
|
Tone.getTransport().start('+0.1');
|
||||||
|
};
|
||||||
|
const stop = () => {
|
||||||
|
Tone.getTransport().pause();
|
||||||
|
setStarted(false);
|
||||||
|
};
|
||||||
|
const toggle = () => (started ? stop() : start());
|
||||||
|
return {
|
||||||
|
start,
|
||||||
|
stop,
|
||||||
|
onEvent,
|
||||||
|
started,
|
||||||
|
setStarted,
|
||||||
|
toggle,
|
||||||
|
query,
|
||||||
|
activeCycle,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
usePostMessage.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/usePostMessage.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function usePostMessage(listener) {
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('message', listener);
|
||||||
|
return () => window.removeEventListener('message', listener);
|
||||||
|
}, [listener]);
|
||||||
|
return useCallback((data) => window.postMessage(data, '*'), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
useRepl.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useRepl.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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
let s4 = () => {
|
||||||
|
return Math.floor((1 + Math.random()) * 0x10000)
|
||||||
|
.toString(16)
|
||||||
|
.substring(1);
|
||||||
|
};
|
||||||
|
const generateHash = (code) => encodeURIComponent(btoa(code));
|
||||||
|
|
||||||
|
function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawProp }) {
|
||||||
|
const id = useMemo(() => s4(), []);
|
||||||
|
const [code, setCode] = useState(tune);
|
||||||
|
const [activeCode, setActiveCode] = useState();
|
||||||
|
const [log, setLog] = useState('');
|
||||||
|
const [error, setError] = useState();
|
||||||
|
const [pending, setPending] = useState(false);
|
||||||
|
const [hash, setHash] = useState('');
|
||||||
|
const [pattern, setPattern] = useState();
|
||||||
|
const dirty = useMemo(() => code !== activeCode || error, [code, activeCode, error]);
|
||||||
|
const pushLog = useCallback((message) => setLog((log) => log + `${log ? '\n\n' : ''}${message}`), []);
|
||||||
|
|
||||||
|
// below block allows disabling the highlighting by including "strudel disable-highlighting" in the code (as comment)
|
||||||
|
const onDraw = useMemo(() => {
|
||||||
|
if (activeCode && !activeCode.includes('strudel disable-highlighting')) {
|
||||||
|
return (time, event) => onDrawProp?.(time, event, activeCode);
|
||||||
|
}
|
||||||
|
}, [activeCode, onDrawProp]);
|
||||||
|
|
||||||
|
// cycle hook to control scheduling
|
||||||
|
const cycle = useCycle({
|
||||||
|
onDraw,
|
||||||
|
onEvent: useCallback(
|
||||||
|
(time, event, currentTime) => {
|
||||||
|
try {
|
||||||
|
onEvent?.(event);
|
||||||
|
if (event.context.logs?.length) {
|
||||||
|
event.context.logs.forEach(pushLog);
|
||||||
|
}
|
||||||
|
const { onTrigger, velocity } = event.context;
|
||||||
|
if (!onTrigger) {
|
||||||
|
if (defaultSynth) {
|
||||||
|
const note = getPlayableNoteValue(event);
|
||||||
|
defaultSynth.triggerAttackRelease(note, event.duration.valueOf(), time, velocity);
|
||||||
|
} else {
|
||||||
|
throw new Error('no defaultSynth passed to useRepl.');
|
||||||
|
}
|
||||||
|
/* console.warn('no instrument chosen', event);
|
||||||
|
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
|
||||||
|
} else {
|
||||||
|
onTrigger(
|
||||||
|
time,
|
||||||
|
event,
|
||||||
|
currentTime,
|
||||||
|
1 /* cps */,
|
||||||
|
event.wholeOrPart().begin.valueOf(),
|
||||||
|
event.duration.valueOf(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
err.message = 'unplayable event: ' + err?.message;
|
||||||
|
pushLog(err.message); // not with setError, because then we would have to setError(undefined) on next playable event
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onEvent, pushLog, defaultSynth],
|
||||||
|
),
|
||||||
|
onQuery: useCallback(
|
||||||
|
(state) => {
|
||||||
|
try {
|
||||||
|
return pattern?.query(state) || [];
|
||||||
|
} catch (err) {
|
||||||
|
console.warn(err);
|
||||||
|
err.message = 'query error: ' + err.message;
|
||||||
|
setError(err);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[pattern],
|
||||||
|
),
|
||||||
|
onSchedule: useCallback((_events, cycle) => logCycle(_events, cycle), []),
|
||||||
|
ready: !!pattern && !!activeCode,
|
||||||
|
});
|
||||||
|
|
||||||
|
const broadcast = usePostMessage(({ data: { from, type } }) => {
|
||||||
|
if (type === 'start' && from !== id) {
|
||||||
|
// console.log('message', from, type);
|
||||||
|
cycle.setStarted(false);
|
||||||
|
setActiveCode(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const activateCode = useCallback(
|
||||||
|
async (_code = code) => {
|
||||||
|
if (activeCode && !dirty) {
|
||||||
|
setError(undefined);
|
||||||
|
cycle.start();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setPending(true);
|
||||||
|
const parsed = await evaluate(_code);
|
||||||
|
cycle.start();
|
||||||
|
broadcast({ type: 'start', from: id });
|
||||||
|
setPattern(() => parsed.pattern);
|
||||||
|
if (autolink) {
|
||||||
|
window.location.hash = '#' + encodeURIComponent(btoa(code));
|
||||||
|
}
|
||||||
|
setHash(generateHash(code));
|
||||||
|
setError(undefined);
|
||||||
|
setActiveCode(_code);
|
||||||
|
setPending(false);
|
||||||
|
} catch (err) {
|
||||||
|
err.message = 'evaluation error: ' + err.message;
|
||||||
|
console.warn(err);
|
||||||
|
setError(err);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[activeCode, dirty, code, cycle, autolink, id, broadcast],
|
||||||
|
);
|
||||||
|
// logs events of cycle
|
||||||
|
const logCycle = (_events, cycle) => {
|
||||||
|
if (_events.length) ;
|
||||||
|
};
|
||||||
|
|
||||||
|
const togglePlay = () => {
|
||||||
|
if (!cycle.started) {
|
||||||
|
activateCode();
|
||||||
|
} else {
|
||||||
|
cycle.stop();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
pending,
|
||||||
|
code,
|
||||||
|
setCode,
|
||||||
|
pattern,
|
||||||
|
error,
|
||||||
|
cycle,
|
||||||
|
setPattern,
|
||||||
|
dirty,
|
||||||
|
log,
|
||||||
|
togglePlay,
|
||||||
|
setActiveCode,
|
||||||
|
activateCode,
|
||||||
|
activeCode,
|
||||||
|
pushLog,
|
||||||
|
hash,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
cx.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/cx.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function cx(...classes) {
|
||||||
|
// : Array<string | undefined>
|
||||||
|
return classes.filter(Boolean).join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
let highlights = []; // actively highlighted events
|
||||||
|
let lastEnd;
|
||||||
|
|
||||||
|
function useHighlighting({ view, pattern, active }) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (view) {
|
||||||
|
if (pattern && active) {
|
||||||
|
let frame = requestAnimationFrame(updateHighlights);
|
||||||
|
|
||||||
|
function updateHighlights() {
|
||||||
|
try {
|
||||||
|
const audioTime = Tone.getTransport().seconds;
|
||||||
|
const span = [lastEnd || audioTime, audioTime + 1 / 60];
|
||||||
|
lastEnd = audioTime + 1 / 60;
|
||||||
|
highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
|
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
||||||
|
highlights = highlights.concat(haps); // add potential new onsets
|
||||||
|
view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps
|
||||||
|
} catch (err) {
|
||||||
|
// console.log('error in updateHighlights', err);
|
||||||
|
view.dispatch({ effects: setHighlights.of([]) });
|
||||||
|
}
|
||||||
|
frame = requestAnimationFrame(updateHighlights);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
highlights = [];
|
||||||
|
view.dispatch({ effects: setHighlights.of([]) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [pattern, active, view]);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tailwind = '';
|
||||||
|
|
||||||
|
const container = "_container_10e1g_1";
|
||||||
|
const header = "_header_10e1g_5";
|
||||||
|
const buttons = "_buttons_10e1g_9";
|
||||||
|
const button = "_button_10e1g_9";
|
||||||
|
const buttonDisabled = "_buttonDisabled_10e1g_17";
|
||||||
|
const error = "_error_10e1g_21";
|
||||||
|
const body = "_body_10e1g_25";
|
||||||
|
var styles = {
|
||||||
|
container: container,
|
||||||
|
header: header,
|
||||||
|
buttons: buttons,
|
||||||
|
button: button,
|
||||||
|
buttonDisabled: buttonDisabled,
|
||||||
|
error: error,
|
||||||
|
body: body
|
||||||
|
};
|
||||||
|
|
||||||
|
function Icon({ type }) {
|
||||||
|
return /* @__PURE__ */ React.createElement("svg", {
|
||||||
|
xmlns: "http://www.w3.org/2000/svg",
|
||||||
|
className: "sc-h-5 sc-w-5",
|
||||||
|
viewBox: "0 0 20 20",
|
||||||
|
fill: "currentColor"
|
||||||
|
}, {
|
||||||
|
refresh: /* @__PURE__ */ React.createElement("path", {
|
||||||
|
fillRule: "evenodd",
|
||||||
|
d: "M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z",
|
||||||
|
clipRule: "evenodd"
|
||||||
|
}),
|
||||||
|
play: /* @__PURE__ */ React.createElement("path", {
|
||||||
|
fillRule: "evenodd",
|
||||||
|
d: "M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z",
|
||||||
|
clipRule: "evenodd"
|
||||||
|
}),
|
||||||
|
pause: /* @__PURE__ */ React.createElement("path", {
|
||||||
|
fillRule: "evenodd",
|
||||||
|
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z",
|
||||||
|
clipRule: "evenodd"
|
||||||
|
})
|
||||||
|
}[type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||||
|
const { code, setCode, pattern, activateCode, error, cycle, dirty, togglePlay } = useRepl({
|
||||||
|
tune,
|
||||||
|
defaultSynth,
|
||||||
|
autolink: false
|
||||||
|
});
|
||||||
|
const [view, setView] = useState();
|
||||||
|
const [ref, isVisible] = useInView({
|
||||||
|
threshold: 0.01
|
||||||
|
});
|
||||||
|
const wasVisible = useRef();
|
||||||
|
const show = useMemo(() => {
|
||||||
|
if (isVisible || !hideOutsideView) {
|
||||||
|
wasVisible.current = true;
|
||||||
|
}
|
||||||
|
return isVisible || wasVisible.current;
|
||||||
|
}, [isVisible, hideOutsideView]);
|
||||||
|
useHighlighting({ view, pattern, active: cycle.started });
|
||||||
|
return /* @__PURE__ */ React.createElement("div", {
|
||||||
|
className: styles.container,
|
||||||
|
ref
|
||||||
|
}, /* @__PURE__ */ React.createElement("div", {
|
||||||
|
className: styles.header
|
||||||
|
}, /* @__PURE__ */ React.createElement("div", {
|
||||||
|
className: styles.buttons
|
||||||
|
}, /* @__PURE__ */ React.createElement("button", {
|
||||||
|
className: cx(styles.button, cycle.started ? "sc-animate-pulse" : ""),
|
||||||
|
onClick: () => togglePlay()
|
||||||
|
}, /* @__PURE__ */ React.createElement(Icon, {
|
||||||
|
type: cycle.started ? "pause" : "play"
|
||||||
|
})), /* @__PURE__ */ React.createElement("button", {
|
||||||
|
className: cx(dirty ? styles.button : styles.buttonDisabled),
|
||||||
|
onClick: () => activateCode()
|
||||||
|
}, /* @__PURE__ */ React.createElement(Icon, {
|
||||||
|
type: "refresh"
|
||||||
|
}))), error && /* @__PURE__ */ React.createElement("div", {
|
||||||
|
className: styles.error
|
||||||
|
}, error.message)), /* @__PURE__ */ React.createElement("div", {
|
||||||
|
className: styles.body
|
||||||
|
}, show && /* @__PURE__ */ React.createElement(CodeMirror, {
|
||||||
|
value: code,
|
||||||
|
onChange: setCode,
|
||||||
|
onViewChanged: setView
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
useWebMidi.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useWebMidi.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function useWebMidi(props) {
|
||||||
|
const { ready, connected, disconnected } = props;
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [outputs, setOutputs] = useState(WebMidi?.outputs || []);
|
||||||
|
useEffect(() => {
|
||||||
|
enableWebMidi()
|
||||||
|
.then(() => {
|
||||||
|
// Reacting when a new device becomes available
|
||||||
|
WebMidi.addListener('connected', (e) => {
|
||||||
|
setOutputs([...WebMidi.outputs]);
|
||||||
|
connected?.(WebMidi, e);
|
||||||
|
});
|
||||||
|
// Reacting when a device becomes unavailable
|
||||||
|
WebMidi.addListener('disconnected', (e) => {
|
||||||
|
setOutputs([...WebMidi.outputs]);
|
||||||
|
disconnected?.(WebMidi, e);
|
||||||
|
});
|
||||||
|
ready?.(WebMidi);
|
||||||
|
setLoading(false);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err);
|
||||||
|
//throw new Error("Web Midi could not be enabled...");
|
||||||
|
console.warn('Web Midi could not be enabled..');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [ready, connected, disconnected, outputs]);
|
||||||
|
const outputByName = (name) => WebMidi.getOutputByName(name);
|
||||||
|
return { loading, outputs, outputByName };
|
||||||
|
}
|
||||||
|
|
||||||
|
export { CodeMirror, MiniRepl, cx, useCycle, useHighlighting, usePostMessage, useRepl, useWebMidi };
|
||||||
Vendored
+1
@@ -0,0 +1 @@
|
|||||||
|
*,:before,:after{--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.sc-h-5{height:1.25rem}.sc-w-5{width:1.25rem}@keyframes sc-pulse{50%{opacity:.5}}.sc-animate-pulse{animation:sc-pulse 2s cubic-bezier(.4,0,.6,1) infinite}._container_10e1g_1{overflow:hidden;border-radius:.375rem;--tw-bg-opacity: 1;background-color:rgb(68 76 87 / var(--tw-bg-opacity))}._header_10e1g_5{display:flex;justify-content:space-between;border-top-width:1px;--tw-border-opacity: 1;border-color:rgb(100 116 139 / var(--tw-border-opacity));--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity))}._buttons_10e1g_9{display:flex}._button_10e1g_9{display:flex;width:4rem;cursor:pointer;align-items:center;justify-content:center;border-right-width:1px;--tw-border-opacity: 1;border-color:rgb(100 116 139 / var(--tw-border-opacity));--tw-bg-opacity: 1;background-color:rgb(51 65 85 / var(--tw-bg-opacity));padding:.25rem;--tw-text-opacity: 1;color:rgb(255 255 255 / var(--tw-text-opacity))}._button_10e1g_9:hover{--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity))}._buttonDisabled_10e1g_17{display:flex;width:4rem;cursor:pointer;cursor:not-allowed;align-items:center;justify-content:center;--tw-bg-opacity: 1;background-color:rgb(71 85 105 / var(--tw-bg-opacity));padding:.25rem;--tw-text-opacity: 1;color:rgb(148 163 184 / var(--tw-text-opacity))}._error_10e1g_21{padding:.25rem;text-align:right;font-size:.875rem;line-height:1.25rem;--tw-text-opacity: 1;color:rgb(254 202 202 / var(--tw-text-opacity))}._body_10e1g_25{position:relative;overflow:auto}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<!-- <link rel="icon" type="image/svg+xml" href="/src/favicon.svg" /> -->
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Strudel React Components</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.jsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
{
|
||||||
|
"name": "@strudel.cycles/react",
|
||||||
|
"version": "0.1.2",
|
||||||
|
"description": "React components for strudel",
|
||||||
|
"main": "dist/index.cjs.js",
|
||||||
|
"module": "dist/index.es.js",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"require": "./dist/index.cjs.js",
|
||||||
|
"import": "./dist/index.es.js"
|
||||||
|
},
|
||||||
|
"./dist/style.css": "./dist/style.css"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"dev": "vite",
|
||||||
|
"build": "vite build",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"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": {
|
||||||
|
"@codemirror/lang-javascript": "^0.19.0",
|
||||||
|
"@strudel.cycles/core": "*",
|
||||||
|
"@strudel.cycles/eval": "^0.1.1",
|
||||||
|
"@strudel.cycles/tone": "^0.1.1",
|
||||||
|
"react-codemirror6": "^1.1.0",
|
||||||
|
"react-hook-inview": "^4.5.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/react": "^17.0.2",
|
||||||
|
"@types/react-dom": "^17.0.2",
|
||||||
|
"@vitejs/plugin-react": "^1.3.0",
|
||||||
|
"autoprefixer": "^10.4.7",
|
||||||
|
"postcss": "^8.4.13",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"tailwindcss": "^3.0.24",
|
||||||
|
"vite": "^2.9.9"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/*
|
||||||
|
postcss.config.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/postcss.config.js>
|
||||||
|
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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { MiniRepl } from './components/MiniRepl';
|
||||||
|
import 'tailwindcss/tailwind.css';
|
||||||
|
import { Tone, getDefaultSynth } from '@strudel.cycles/tone';
|
||||||
|
import { evalScope } from '@strudel.cycles/eval';
|
||||||
|
|
||||||
|
const defaultSynth = getDefaultSynth();
|
||||||
|
|
||||||
|
evalScope(
|
||||||
|
Tone,
|
||||||
|
import('@strudel.cycles/core'),
|
||||||
|
import('@strudel.cycles/tone'),
|
||||||
|
import('@strudel.cycles/tonal'),
|
||||||
|
import('@strudel.cycles/mini'),
|
||||||
|
import('@strudel.cycles/midi'),
|
||||||
|
import('@strudel.cycles/xen'),
|
||||||
|
import('@strudel.cycles/webaudio'),
|
||||||
|
);
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<MiniRepl tune={`"c3"`} defaultSynth={defaultSynth} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
||||||
@@ -1,53 +1,73 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Controlled as CodeMirror2 } from 'react-codemirror2';
|
import { CodeMirror as _CodeMirror } from 'react-codemirror6';
|
||||||
import 'codemirror/mode/javascript/javascript';
|
// import { CodeMirrorLite as _CodeMirror } from 'react-codemirror6/dist/lite';
|
||||||
import 'codemirror/mode/pegjs/pegjs';
|
import { EditorView, Decoration } from '@codemirror/view';
|
||||||
// import 'codemirror/theme/material.css';
|
import { StateField, StateEffect } from '@codemirror/state';
|
||||||
import 'codemirror/lib/codemirror.css';
|
import { javascript } from '@codemirror/lang-javascript';
|
||||||
import 'codemirror/theme/material.css';
|
// import { materialPalenight } from 'codemirror6-themes';
|
||||||
|
import { materialPalenight } from '../themes/material-palenight';
|
||||||
|
|
||||||
export default function CodeMirror({ value, onChange, onCursor, options, editorDidMount }) {
|
export const setHighlights = StateEffect.define();
|
||||||
options = options || {
|
const highlightField = StateField.define({
|
||||||
mode: 'javascript',
|
create() {
|
||||||
theme: 'material',
|
return Decoration.none;
|
||||||
lineNumbers: true,
|
},
|
||||||
styleSelectedText: true,
|
update(highlights, tr) {
|
||||||
cursorBlinkRate: 500,
|
try {
|
||||||
};
|
for (let e of tr.effects) {
|
||||||
|
if (e.is(setHighlights)) {
|
||||||
|
highlights = Decoration.set(
|
||||||
|
e.value
|
||||||
|
.flatMap((hap) =>
|
||||||
|
(hap.context.locations || []).map(({ start, end }) => {
|
||||||
|
const color = hap.context.color || '#FFCA28';
|
||||||
|
let from = tr.newDoc.line(start.line).from + start.column;
|
||||||
|
let to = tr.newDoc.line(end.line).from + end.column;
|
||||||
|
const l = tr.newDoc.length;
|
||||||
|
if (from > l || to > l) {
|
||||||
|
return; // dont mark outside of range, as it will throw an error
|
||||||
|
}
|
||||||
|
const mark = Decoration.mark({ attributes: { style: `outline: 1px solid ${color}` } });
|
||||||
|
return mark.range(from, to);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.filter(Boolean),
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return highlights;
|
||||||
|
} catch (err) {
|
||||||
|
// console.warn('highlighting error', err);
|
||||||
|
return highlights;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide: (f) => EditorView.decorations.from(f),
|
||||||
|
});
|
||||||
|
|
||||||
|
export default function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) {
|
||||||
return (
|
return (
|
||||||
<CodeMirror2
|
<>
|
||||||
value={value}
|
<_CodeMirror
|
||||||
options={options}
|
onViewChange={onViewChanged}
|
||||||
onBeforeChange={onChange}
|
style={{
|
||||||
editorDidMount={editorDidMount}
|
display: 'flex',
|
||||||
onCursor={(editor, data) => onCursor?.(editor, data)}
|
flexDirection: 'column',
|
||||||
/>
|
flex: '1 0 auto',
|
||||||
|
}}
|
||||||
|
value={value}
|
||||||
|
onChange={onChange}
|
||||||
|
extensions={[
|
||||||
|
javascript(),
|
||||||
|
materialPalenight,
|
||||||
|
highlightField,
|
||||||
|
// theme, language, ...
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const markEvent = (editor) => (time, event) => {
|
|
||||||
const locs = event.context.locations;
|
|
||||||
if (!locs || !editor) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const col = event.context?.color || '#FFCA28';
|
|
||||||
// mark active event
|
|
||||||
const marks = locs.map(({ start, end }) =>
|
|
||||||
editor.getDoc().markText(
|
|
||||||
{ line: start.line - 1, ch: start.column },
|
|
||||||
{ line: end.line - 1, ch: end.column },
|
|
||||||
//{ css: 'background-color: #FFCA28; color: black' } // background-color is now used by parent marking
|
|
||||||
{ css: 'outline: 1px solid ' + col + '; box-sizing:border-box' },
|
|
||||||
//{ css: `background-color: ${col};border-radius:5px` },
|
|
||||||
),
|
|
||||||
);
|
|
||||||
//Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler...
|
|
||||||
setTimeout(() => {
|
|
||||||
marks.forEach((mark) => mark.clear());
|
|
||||||
// }, '+' + event.duration * 0.5);
|
|
||||||
}, event.duration /* * 0.9 */ * 1000);
|
|
||||||
};
|
|
||||||
|
|
||||||
let parenMark;
|
let parenMark;
|
||||||
export const markParens = (editor, data) => {
|
export const markParens = (editor, data) => {
|
||||||
const v = editor.getDoc().getValue();
|
const v = editor.getDoc().getValue();
|
||||||
@@ -75,6 +95,10 @@ export function offsetToPosition(offset, code) {
|
|||||||
// returns absolute character offset from { line, ch }
|
// returns absolute character offset from { line, ch }
|
||||||
export function positionToOffset(position, code) {
|
export function positionToOffset(position, code) {
|
||||||
const lines = code.split('\n');
|
const lines = code.split('\n');
|
||||||
|
if (position.line > lines.length) {
|
||||||
|
// throw new Error('positionToOffset: position.line > lines.length');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
let offset = 0;
|
let offset = 0;
|
||||||
for (let i = 0; i < position.line; i++) {
|
for (let i = 0; i < position.line; i++) {
|
||||||
offset += lines[i].length + 1;
|
offset += lines[i].length + 1;
|
||||||
@@ -119,3 +143,27 @@ export function getCurrentParenArea(code, caretPosition) {
|
|||||||
end = i;
|
end = i;
|
||||||
return [begin, end].map((o) => offsetToPosition(o, code));
|
return [begin, end].map((o) => offsetToPosition(o, code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
export const markEvent = (editor) => (time, event) => {
|
||||||
|
const locs = event.context.locations;
|
||||||
|
if (!locs || !editor) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const col = event.context?.color || '#FFCA28';
|
||||||
|
// mark active event
|
||||||
|
const marks = locs.map(({ start, end }) =>
|
||||||
|
editor.getDoc().markText(
|
||||||
|
{ line: start.line - 1, ch: start.column },
|
||||||
|
{ line: end.line - 1, ch: end.column },
|
||||||
|
//{ css: 'background-color: #FFCA28; color: black' } // background-color is now used by parent marking
|
||||||
|
{ css: 'outline: 1px solid ' + col + '; box-sizing:border-box' },
|
||||||
|
//{ css: `background-color: ${col};border-radius:5px` },
|
||||||
|
),
|
||||||
|
);
|
||||||
|
//Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler...
|
||||||
|
setTimeout(() => {
|
||||||
|
marks.forEach((mark) => mark.clear());
|
||||||
|
// }, '+' + event.duration * 0.5);
|
||||||
|
}, event.duration * 1000);
|
||||||
|
}; */
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
export function Icon({ type }) {
|
||||||
|
return (
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" className="sc-h-5 sc-w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||||
|
{
|
||||||
|
{
|
||||||
|
refresh: (
|
||||||
|
<path
|
||||||
|
fillRule="evenodd"
|
||||||
|
d="M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z"
|
||||||
|
clipRule="evenodd"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
play: (
|
||||||
|
<path
|
||||||
|
fillRule="evenodd"
|
||||||
|
d="M10 18a8 8 0 100-16 8 8 0 000 16zM9.555 7.168A1 1 0 008 8v4a1 1 0 001.555.832l3-2a1 1 0 000-1.664l-3-2z"
|
||||||
|
clipRule="evenodd"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
pause: (
|
||||||
|
<path
|
||||||
|
fillRule="evenodd"
|
||||||
|
d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zM7 8a1 1 0 012 0v4a1 1 0 11-2 0V8zm5-1a1 1 0 00-1 1v4a1 1 0 102 0V8a1 1 0 00-1-1z"
|
||||||
|
clipRule="evenodd"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
}[type]
|
||||||
|
}
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import React, { useState, useMemo, useRef } from 'react';
|
||||||
|
import { useInView } from 'react-hook-inview';
|
||||||
|
import useRepl from '../hooks/useRepl.mjs';
|
||||||
|
import cx from '../cx';
|
||||||
|
import useHighlighting from '../hooks/useHighlighting.mjs';
|
||||||
|
import CodeMirror6 from './CodeMirror6';
|
||||||
|
import 'tailwindcss/tailwind.css';
|
||||||
|
import './style.css';
|
||||||
|
import styles from './MiniRepl.module.css';
|
||||||
|
import { Icon } from './Icon';
|
||||||
|
|
||||||
|
export function MiniRepl({ tune, defaultSynth, hideOutsideView = false }) {
|
||||||
|
const { code, setCode, pattern, activateCode, error, cycle, dirty, togglePlay } = useRepl({
|
||||||
|
tune,
|
||||||
|
defaultSynth,
|
||||||
|
autolink: false,
|
||||||
|
});
|
||||||
|
const [view, setView] = useState();
|
||||||
|
const [ref, isVisible] = useInView({
|
||||||
|
threshold: 0.01,
|
||||||
|
});
|
||||||
|
const wasVisible = useRef();
|
||||||
|
const show = useMemo(() => {
|
||||||
|
if (isVisible || !hideOutsideView) {
|
||||||
|
wasVisible.current = true;
|
||||||
|
}
|
||||||
|
return isVisible || wasVisible.current;
|
||||||
|
}, [isVisible, hideOutsideView]);
|
||||||
|
useHighlighting({ view, pattern, active: cycle.started });
|
||||||
|
return (
|
||||||
|
<div className={styles.container} ref={ref}>
|
||||||
|
<div className={styles.header}>
|
||||||
|
<div className={styles.buttons}>
|
||||||
|
<button className={cx(styles.button, cycle.started ? 'sc-animate-pulse' : '')} onClick={() => togglePlay()}>
|
||||||
|
<Icon type={cycle.started ? 'pause' : 'play'} />
|
||||||
|
</button>
|
||||||
|
<button className={cx(dirty ? styles.button : styles.buttonDisabled)} onClick={() => activateCode()}>
|
||||||
|
<Icon type="refresh" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{error && <div className={styles.error}>{error.message}</div>}
|
||||||
|
</div>
|
||||||
|
<div className={styles.body} >
|
||||||
|
{show && <CodeMirror6 value={code} onChange={setCode} onViewChanged={setView} />}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
.container {
|
||||||
|
@apply sc-rounded-md sc-overflow-hidden sc-bg-[#444C57];
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
@apply sc-flex sc-justify-between sc-bg-slate-700 sc-border-t sc-border-slate-500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttons {
|
||||||
|
@apply sc-flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
@apply sc-cursor-pointer sc-w-16 sc-flex sc-items-center sc-justify-center sc-p-1 sc-bg-slate-700 sc-border-r sc-border-slate-500 sc-text-white hover:sc-bg-slate-600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.buttonDisabled {
|
||||||
|
@apply sc-cursor-pointer sc-w-16 sc-flex sc-items-center sc-justify-center sc-p-1 sc-bg-slate-600 sc-text-slate-400 sc-cursor-not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
@apply sc-text-right sc-p-1 sc-text-sm sc-text-red-200;
|
||||||
|
}
|
||||||
|
|
||||||
|
.body {
|
||||||
|
@apply sc-overflow-auto sc-relative;
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.cm-editor {
|
||||||
|
background-color: transparent !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
cx.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/cx.js>
|
||||||
|
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 default function cx(...classes) {
|
||||||
|
// : Array<string | undefined>
|
||||||
|
return classes.filter(Boolean).join(' ');
|
||||||
|
}
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
useCycle.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useCycle.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 { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Tone } from '@strudel.cycles/tone';
|
import { Tone } from '@strudel.cycles/tone';
|
||||||
import { State, TimeSpan } from '@strudel.cycles/core';
|
import { State, TimeSpan } from '@strudel.cycles/core';
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
import { setHighlights } from '../components/CodeMirror6';
|
||||||
|
import { Tone } from '@strudel.cycles/tone';
|
||||||
|
|
||||||
|
let highlights = []; // actively highlighted events
|
||||||
|
let lastEnd;
|
||||||
|
|
||||||
|
function useHighlighting({ view, pattern, active }) {
|
||||||
|
useEffect(() => {
|
||||||
|
if (view) {
|
||||||
|
if (pattern && active) {
|
||||||
|
let frame = requestAnimationFrame(updateHighlights);
|
||||||
|
|
||||||
|
function updateHighlights() {
|
||||||
|
try {
|
||||||
|
const audioTime = Tone.getTransport().seconds;
|
||||||
|
const span = [lastEnd || audioTime, audioTime + 1 / 60];
|
||||||
|
lastEnd = audioTime + 1 / 60;
|
||||||
|
highlights = highlights.filter((hap) => hap.whole.end > audioTime); // keep only highlights that are still active
|
||||||
|
const haps = pattern.queryArc(...span).filter((hap) => hap.hasOnset());
|
||||||
|
highlights = highlights.concat(haps); // add potential new onsets
|
||||||
|
view.dispatch({ effects: setHighlights.of(highlights) }); // highlight all still active + new active haps
|
||||||
|
} catch (err) {
|
||||||
|
// console.log('error in updateHighlights', err);
|
||||||
|
view.dispatch({ effects: setHighlights.of([]) });
|
||||||
|
}
|
||||||
|
frame = requestAnimationFrame(updateHighlights);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelAnimationFrame(frame);
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
highlights = [];
|
||||||
|
view.dispatch({ effects: setHighlights.of([]) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [pattern, active, view]);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useHighlighting;
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
usePostMessage.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/usePostMessage.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 { useEffect, useCallback } from 'react';
|
||||||
|
|
||||||
|
function usePostMessage(listener) {
|
||||||
|
useEffect(() => {
|
||||||
|
window.addEventListener('message', listener);
|
||||||
|
return () => window.removeEventListener('message', listener);
|
||||||
|
}, [listener]);
|
||||||
|
return useCallback((data) => window.postMessage(data, '*'), []);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default usePostMessage;
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
useRepl.mjs - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useRepl.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 { useCallback, useState, useMemo } from 'react';
|
import { useCallback, useState, useMemo } from 'react';
|
||||||
import { evaluate } from '@strudel.cycles/eval';
|
import { evaluate } from '@strudel.cycles/eval';
|
||||||
import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs';
|
import { getPlayableNoteValue } from '@strudel.cycles/core/util.mjs';
|
||||||
@@ -11,7 +17,7 @@ let s4 = () => {
|
|||||||
};
|
};
|
||||||
const generateHash = (code) => encodeURIComponent(btoa(code));
|
const generateHash = (code) => encodeURIComponent(btoa(code));
|
||||||
|
|
||||||
function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
|
function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw: onDrawProp }) {
|
||||||
const id = useMemo(() => s4(), []);
|
const id = useMemo(() => s4(), []);
|
||||||
const [code, setCode] = useState(tune);
|
const [code, setCode] = useState(tune);
|
||||||
const [activeCode, setActiveCode] = useState();
|
const [activeCode, setActiveCode] = useState();
|
||||||
@@ -24,12 +30,12 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
|
|||||||
const pushLog = useCallback((message) => setLog((log) => log + `${log ? '\n\n' : ''}${message}`), []);
|
const pushLog = useCallback((message) => setLog((log) => log + `${log ? '\n\n' : ''}${message}`), []);
|
||||||
|
|
||||||
// below block allows disabling the highlighting by including "strudel disable-highlighting" in the code (as comment)
|
// below block allows disabling the highlighting by including "strudel disable-highlighting" in the code (as comment)
|
||||||
onDraw = useMemo(() => {
|
const onDraw = useMemo(() => {
|
||||||
if (activeCode && !activeCode.includes('strudel disable-highlighting')) {
|
if (activeCode && !activeCode.includes('strudel disable-highlighting')) {
|
||||||
return onDraw;
|
return (time, event) => onDrawProp?.(time, event, activeCode);
|
||||||
}
|
}
|
||||||
}, [activeCode, onDraw]);
|
}, [activeCode, onDrawProp]);
|
||||||
|
|
||||||
// cycle hook to control scheduling
|
// cycle hook to control scheduling
|
||||||
const cycle = useCycle({
|
const cycle = useCycle({
|
||||||
onDraw,
|
onDraw,
|
||||||
@@ -37,18 +43,28 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
|
|||||||
(time, event, currentTime) => {
|
(time, event, currentTime) => {
|
||||||
try {
|
try {
|
||||||
onEvent?.(event);
|
onEvent?.(event);
|
||||||
|
if (event.context.logs?.length) {
|
||||||
|
event.context.logs.forEach(pushLog);
|
||||||
|
}
|
||||||
const { onTrigger, velocity } = event.context;
|
const { onTrigger, velocity } = event.context;
|
||||||
if (!onTrigger) {
|
if (!onTrigger) {
|
||||||
if (defaultSynth) {
|
if (defaultSynth) {
|
||||||
const note = getPlayableNoteValue(event);
|
const note = getPlayableNoteValue(event);
|
||||||
defaultSynth.triggerAttackRelease(note, event.duration, time, velocity);
|
defaultSynth.triggerAttackRelease(note, event.duration.valueOf(), time, velocity);
|
||||||
} else {
|
} else {
|
||||||
throw new Error('no defaultSynth passed to useRepl.');
|
throw new Error('no defaultSynth passed to useRepl.');
|
||||||
}
|
}
|
||||||
/* console.warn('no instrument chosen', event);
|
/* console.warn('no instrument chosen', event);
|
||||||
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
|
throw new Error(`no instrument chosen for ${JSON.stringify(event)}`); */
|
||||||
} else {
|
} else {
|
||||||
onTrigger(time, event, currentTime);
|
onTrigger(
|
||||||
|
time,
|
||||||
|
event,
|
||||||
|
currentTime,
|
||||||
|
1 /* cps */,
|
||||||
|
event.wholeOrPart().begin.valueOf(),
|
||||||
|
event.duration.valueOf(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn(err);
|
console.warn(err);
|
||||||
@@ -137,6 +153,7 @@ function useRepl({ tune, defaultSynth, autolink = true, onEvent, onDraw }) {
|
|||||||
dirty,
|
dirty,
|
||||||
log,
|
log,
|
||||||
togglePlay,
|
togglePlay,
|
||||||
|
setActiveCode,
|
||||||
activateCode,
|
activateCode,
|
||||||
activeCode,
|
activeCode,
|
||||||
pushLog,
|
pushLog,
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
|
/*
|
||||||
|
useWebMidi.js - <short description TODO>
|
||||||
|
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/repl/src/useWebMidi.js>
|
||||||
|
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 { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { enableWebMidi, WebMidi } from '@strudel.cycles/midi'
|
import { enableWebMidi, WebMidi } from '@strudel.cycles/midi'
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// import 'tailwindcss/tailwind.css';
|
||||||
|
|
||||||
|
export { default as CodeMirror } from './components/CodeMirror6';
|
||||||
|
export * from './components/MiniRepl';
|
||||||
|
export { default as useCycle } from './hooks/useCycle';
|
||||||
|
export { default as useHighlighting } from './hooks/useHighlighting';
|
||||||
|
export { default as usePostMessage } from './hooks/usePostMessage';
|
||||||
|
export { default as useRepl } from './hooks/useRepl';
|
||||||
|
export { default as cx } from './cx';
|
||||||
|
export { useWebMidi } from './hooks/useWebMidi';
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import React from 'react'
|
||||||
|
import ReactDOM from 'react-dom'
|
||||||
|
import App from './App'
|
||||||
|
|
||||||
|
ReactDOM.render(<React.StrictMode><App /></React.StrictMode>,document.getElementById('root'))
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user