mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-22 05:05:26 -04:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e89d7ece9 | |||
| 967a9bb4a4 |
+1
-4
@@ -1,5 +1,4 @@
|
|||||||
dist
|
dist
|
||||||
out
|
|
||||||
!docs/dist
|
!docs/dist
|
||||||
dist-*
|
dist-*
|
||||||
cabal-dev
|
cabal-dev
|
||||||
@@ -28,6 +27,4 @@ node_modules/
|
|||||||
repl-parcel
|
repl-parcel
|
||||||
mytunes.ts
|
mytunes.ts
|
||||||
doc
|
doc
|
||||||
out
|
.parcel-cache
|
||||||
.parcel-cache
|
|
||||||
repl_old
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
GNU AFFERO GENERAL PUBLIC LICENSE
|
GNU GENERAL PUBLIC LICENSE
|
||||||
Version 3, 19 November 2007
|
Version 3, 29 June 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,15 +7,17 @@
|
|||||||
|
|
||||||
Preamble
|
Preamble
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
The GNU General Public License is a free, copyleft license for
|
||||||
software and other kinds of works, specifically designed to ensure
|
software and other kinds of works.
|
||||||
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,
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
the GNU General Public License is 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.
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
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
|
||||||
@@ -24,34 +26,44 @@ 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.
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
To protect your rights, we need to prevent others from denying you
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
you this License which gives you legal permission to copy, distribute
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
and/or modify the software.
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
For example, if you distribute copies of such a program, whether
|
||||||
improvements made in alternate versions of the program, if they
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
receive widespread use, become available for other developers to
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
incorporate. Many developers of free software are heartened and
|
or can get the source code. And you must show them these terms so they
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
know their rights.
|
||||||
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.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
ensure that, in such cases, the modified source code becomes available
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
to the community. It requires the operator of a network server to
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
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.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
that there is no warranty for this free software. For both users' and
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
changed, so that their problems will not be attributed erroneously to
|
||||||
this license.
|
authors of previous versions.
|
||||||
|
|
||||||
|
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.
|
||||||
@@ -60,7 +72,7 @@ modification follow.
|
|||||||
|
|
||||||
0. Definitions.
|
0. Definitions.
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
"This License" refers to version 3 of the GNU 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.
|
||||||
@@ -537,45 +549,35 @@ 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. Remote Network Interaction; Use with the GNU General Public License.
|
13. Use with the GNU Affero 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 General Public License into a single
|
under version 3 of the GNU Affero 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 work with which it is combined will remain governed by version
|
but the special requirements of the GNU Affero General Public License,
|
||||||
3 of the GNU General Public License.
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
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 Affero General Public License from time to time. Such new versions
|
the GNU General Public License from time to time. Such new versions will
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
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 Affero General
|
Program specifies that a certain numbered version of the GNU 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 Affero General Public License, you may choose any version ever published
|
GNU 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 Affero General Public License can be used, that proxy's
|
versions of the GNU 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.
|
||||||
|
|
||||||
@@ -633,29 +635,40 @@ 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 Affero General Public License as published by
|
it under the terms of the GNU 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 Affero General Public License for more details.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
You should have received a copy of the GNU 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 your software can interact with users remotely through a computer
|
If the program does terminal interaction, make it output a short
|
||||||
network, you should also make sure that it provides a way for users to
|
notice like this when it starts in an interactive mode:
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
<program> Copyright (C) <year> <name of author>
|
||||||
of the code. There are many ways you could offer source, and different
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
solutions will be better for different programs; see section 13 for the
|
This is free software, and you are welcome to redistribute it
|
||||||
specific requirements.
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
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 AGPL, see
|
For more information on this, and how to apply and follow the GNU GPL, 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,10 +27,8 @@ 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.35f2ca4c.css",
|
"main.css": "/static/css/main.0d689283.css",
|
||||||
"main.js": "/static/js/main.f848d51e.js",
|
"main.js": "/static/js/main.7e790d7f.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.35f2ca4c.css.map": "/static/css/main.35f2ca4c.css.map",
|
"main.0d689283.css.map": "/static/css/main.0d689283.css.map",
|
||||||
"main.f848d51e.js.map": "/static/js/main.f848d51e.js.map",
|
"main.7e790d7f.js.map": "/static/js/main.7e790d7f.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.35f2ca4c.css",
|
"static/css/main.0d689283.css",
|
||||||
"static/js/main.f848d51e.js"
|
"static/js/main.7e790d7f.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.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>
|
<!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.7e790d7f.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>
|
||||||
File diff suppressed because one or more lines are too long
+1
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
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
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
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
|
|
||||||
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.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>
|
<!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.a0cd6c24.js" defer></script> </body></html>
|
||||||
+131
@@ -0,0 +1,131 @@
|
|||||||
|
# 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
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"source": {
|
|
||||||
"includePattern": ".+\\.(js(doc|x)?|mjs)$",
|
|
||||||
"excludePattern": "node_modules|shift-parser|shift-reducer|shift-traverser"
|
|
||||||
},
|
|
||||||
"plugins": ["plugins/markdown"],
|
|
||||||
"opts": {
|
|
||||||
"destination": "./out/",
|
|
||||||
"recurse": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Generated
+195
-4071
File diff suppressed because it is too large
Load Diff
+5
-12
@@ -3,17 +3,14 @@
|
|||||||
"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 && cd repl && npm run test",
|
"test": "npm run test --workspaces --if-present",
|
||||||
"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 dev",
|
"repl": "cd repl && npm run start",
|
||||||
"osc": "cd packages/osc && npm run server",
|
"osc": "cd packages/osc && npm run server",
|
||||||
"build": "rm -rf out && cd repl && npm run build && cd ../tutorial && npm run build",
|
"build": "cd repl && 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/*"
|
||||||
@@ -30,17 +27,13 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
"author": "Alex McLean <alex@slab.org> (https://slab.org)",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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 = {};
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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.valueOf() * canvas.width, canvas.height);
|
ctx.fillRect(event.whole.begin * canvas.width, 0, event.duration * canvas.width, canvas.height);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
|
|
||||||
@@ -78,12 +72,6 @@ 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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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) =>
|
||||||
|
|||||||
+6
-22
@@ -1,8 +1,3 @@
|
|||||||
/*
|
|
||||||
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 {
|
||||||
/*
|
/*
|
||||||
@@ -14,10 +9,7 @@ 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) {
|
||||||
@@ -32,7 +24,7 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get duration() {
|
get duration() {
|
||||||
return this.whole.end.sub(this.whole.begin);
|
return this.whole.end.sub(this.whole.begin).valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
wholeOrPart() {
|
wholeOrPart() {
|
||||||
@@ -40,18 +32,18 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withSpan(func) {
|
withSpan(func) {
|
||||||
// Returns a new hap with the function f applies to the hap timespan.
|
// Returns a new event with the function f applies to the event 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 hap with the function f applies to the hap value.
|
// Returns a new event with the function f applies to the event 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 hap contains the onset, i.e that
|
// Test whether the event 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);
|
||||||
}
|
}
|
||||||
@@ -85,14 +77,6 @@ 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 || []) };
|
||||||
@@ -103,4 +87,4 @@ export class Hap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Hap;
|
export default Hap;
|
||||||
@@ -1,19 +1,11 @@
|
|||||||
/*
|
|
||||||
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.1.0",
|
"version": "0.0.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/core",
|
"name": "@strudel.cycles/core",
|
||||||
"version": "0.1.0",
|
"version": "0.0.5",
|
||||||
"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": "AGPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
+153
-533
File diff suppressed because it is too large
Load Diff
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
@@ -80,10 +74,7 @@ export const chooseWith = (pat, xs) => {
|
|||||||
if (xs.length == 0) {
|
if (xs.length == 0) {
|
||||||
return silence;
|
return silence;
|
||||||
}
|
}
|
||||||
return pat
|
return pat.range(0, xs.length).fmap((i) => xs[Math.floor(i)]).outerJoin();
|
||||||
.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);
|
||||||
@@ -97,14 +88,14 @@ const _wchooseWith = function (pat, ...pairs) {
|
|||||||
weights.push(accum);
|
weights.push(accum);
|
||||||
}
|
}
|
||||||
const total = accum;
|
const total = accum;
|
||||||
const match = function (r) {
|
const match = function(r) {
|
||||||
const find = r * total;
|
const find = r * total;
|
||||||
return values[weights.findIndex((x) => x > find, weights)];
|
return values[weights.findIndex((x) => x > find, weights)];
|
||||||
};
|
};
|
||||||
return pat.fmap(match);
|
return pat.fmap(match);
|
||||||
};
|
};
|
||||||
|
|
||||||
const wchooseWith = (...args) => _wchooseWith(...args).outerJoin();
|
const wchooseWith = (...args) => _wchooseWith(...args).outerJoin()
|
||||||
|
|
||||||
export const wchoose = (...pairs) => wchooseWith(rand, ...pairs);
|
export const wchoose = (...pairs) => wchooseWith(rand, ...pairs);
|
||||||
|
|
||||||
|
|||||||
+5
-17
@@ -1,18 +1,6 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
|
|
||||||
let synth;
|
const synth = window?.speechSynthesis;
|
||||||
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);
|
||||||
|
|
||||||
@@ -32,11 +20,11 @@ function speak(words, lang, voice) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype._speak = function (lang, voice) {
|
Pattern.prototype._speak = function (lang, voice) {
|
||||||
return this._withHap((hap) => {
|
return this._withEvent((event) => {
|
||||||
const onTrigger = (time, hap) => {
|
const onTrigger = (time, event) => {
|
||||||
speak(hap.value, lang, voice);
|
speak(event.value, lang, voice);
|
||||||
};
|
};
|
||||||
return hap.setContext({ ...hap.context, onTrigger });
|
return event.setContext({ ...event.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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;
|
||||||
|
|||||||
@@ -1,56 +0,0 @@
|
|||||||
/*
|
|
||||||
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`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
@@ -41,7 +35,6 @@ import {
|
|||||||
tri2,
|
tri2,
|
||||||
id,
|
id,
|
||||||
ply,
|
ply,
|
||||||
rev
|
|
||||||
} from '../index.mjs';
|
} from '../index.mjs';
|
||||||
|
|
||||||
import { steady } from '../signal.mjs';
|
import { steady } from '../signal.mjs';
|
||||||
@@ -58,7 +51,7 @@ const third = Fraction(1, 3);
|
|||||||
const twothirds = Fraction(2, 3);
|
const twothirds = Fraction(2, 3);
|
||||||
|
|
||||||
const sameFirst = (a, b) => {
|
const sameFirst = (a, b) => {
|
||||||
return assert.deepStrictEqual(a._sortHapsByPart().firstCycle(), b._sortHapsByPart().firstCycle());
|
return assert.deepStrictEqual(a._sortEventsByPart().firstCycle(), b._sortEventsByPart().firstCycle());
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('TimeSpan', function () {
|
describe('TimeSpan', function () {
|
||||||
@@ -153,32 +146,17 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('add()', function () {
|
describe('add()', function () {
|
||||||
it('can structure In()', function () {
|
it('Can add things', 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));
|
describe('addFlip()', () => {
|
||||||
|
it('Can add things with structure from second pattern', () => {
|
||||||
|
sameFirst(sequence(1, 2).addFlip(4), sequence(5, 6).struct(true));
|
||||||
});
|
});
|
||||||
it('can Mix() structure', () => {
|
});
|
||||||
assert.deepStrictEqual(sequence(1, 2).addMix(silence, 5, silence).firstCycle(), [
|
describe('addSqueeze()', () => {
|
||||||
hap(ts(1 / 3, 1 / 2), ts(1 / 3, 1 / 2), 6),
|
it('Can add while squeezing the second pattern inside the events of the first', () => {
|
||||||
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(
|
sameFirst(
|
||||||
sequence(1, [2, 3]).addSqueeze(sequence(10, 20, 30)),
|
sequence(1, [2, 3]).addSqueeze(sequence(10, 20, 30)),
|
||||||
sequence(
|
sequence(
|
||||||
@@ -190,97 +168,15 @@ describe('Pattern', function () {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it('can SqueezeOut() structure', () => {
|
});
|
||||||
|
describe('addSqueezeFlip()', () => {
|
||||||
|
it('Can add while squeezing the first pattern inside the events of the second', () => {
|
||||||
sameFirst(
|
sameFirst(
|
||||||
sequence(1, [2, 3]).addSqueezeOut(10, 20, 30),
|
sequence(1, [2, 3]).addSqueezeFlip(10, 20, 30),
|
||||||
sequence([11, [12, 13]], [21, [22, 23]], [31, [32, 33]]),
|
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 () {
|
||||||
it('Can subtract things', function () {
|
it('Can subtract things', function () {
|
||||||
assert.equal(pure(3).sub(pure(4)).query(st(0, 1))[0].value, -1);
|
assert.equal(pure(3).sub(pure(4)).query(st(0, 1))[0].value, -1);
|
||||||
@@ -312,13 +208,13 @@ describe('Pattern', function () {
|
|||||||
it('Can set things with plain values', function () {
|
it('Can set things with plain values', function () {
|
||||||
sameFirst(sequence(1, 2, 3).set(4), sequence(4).fast(3));
|
sameFirst(sequence(1, 2, 3).set(4), sequence(4).fast(3));
|
||||||
});
|
});
|
||||||
describe('setOut()', () => {
|
describe('setFlip()', () => {
|
||||||
it('Can set things with structure from second pattern', () => {
|
it('Can set things with structure from second pattern', () => {
|
||||||
sameFirst(sequence(1, 2).setOut(4), pure(4).mask(true, true));
|
sameFirst(sequence(1, 2).setFlip(4), pure(4).mask(true, true));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('setSqueeze()', () => {
|
describe('setSqueeze()', () => {
|
||||||
it('Can squeeze one pattern inside the haps of another', () => {
|
it('Can squeeze one pattern inside the events of another', () => {
|
||||||
sameFirst(
|
sameFirst(
|
||||||
sequence(1, [2, 3]).setSqueeze(sequence('a', 'b', 'c')),
|
sequence(1, [2, 3]).setSqueeze(sequence('a', 'b', 'c')),
|
||||||
sequence(
|
sequence(
|
||||||
@@ -351,9 +247,6 @@ 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 () {
|
||||||
@@ -392,7 +285,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 a hap in two..
|
// .fast(sequence(1,silence) is a quick hack to cut an event 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(),
|
||||||
@@ -437,20 +330,6 @@ 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(
|
||||||
@@ -480,7 +359,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)._sortHapsByPart().firstCycle(),
|
pure(10).when(slowcat(true, false), add(3)).fast(4)._sortEventsByPart().firstCycle(),
|
||||||
fastcat(13, 10, 13, 10).firstCycle(),
|
fastcat(13, 10, 13, 10).firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -495,11 +374,6 @@ 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(
|
||||||
@@ -530,9 +404,6 @@ 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 () {
|
||||||
@@ -601,11 +472,6 @@ 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(
|
||||||
@@ -696,7 +562,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('_setContext()', () => {
|
describe('_setContext()', () => {
|
||||||
it('Can set the hap context', () => {
|
it('Can set the event context', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure('a')
|
pure('a')
|
||||||
._setContext([
|
._setContext([
|
||||||
@@ -718,7 +584,7 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('_withContext()', () => {
|
describe('_withContext()', () => {
|
||||||
it('Can update the hap context', () => {
|
it('Can update the event context', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure('a')
|
pure('a')
|
||||||
._setContext([
|
._setContext([
|
||||||
@@ -773,13 +639,13 @@ describe('Pattern', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('early', () => {
|
describe('early', () => {
|
||||||
it('Can shift a hap earlier', () => {
|
it('Can shift an event 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 a hap earlier, into negative time', () => {
|
it('Can shift an event 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),
|
||||||
@@ -797,9 +663,9 @@ describe('Pattern', function () {
|
|||||||
describe('jux', () => {
|
describe('jux', () => {
|
||||||
it('Can juxtapose', () => {
|
it('Can juxtapose', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
pure({ a: 1 }).jux(fast(2))._sortHapsByPart().firstCycle(),
|
pure({ a: 1 }).jux(fast(2))._sortEventsByPart().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))
|
||||||
._sortHapsByPart()
|
._sortEventsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -807,9 +673,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))._sortHapsByPart().firstCycle(),
|
pure({ a: 1 }).juxBy(0.5, fast(2))._sortEventsByPart().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))
|
||||||
._sortHapsByPart()
|
._sortEventsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -838,7 +704,7 @@ 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', () => {
|
it('Doesnt drop events in the 9th cycle', () => {
|
||||||
// fixed with https://github.com/tidalcycles/strudel/commit/72eeaf446e3d5e186d63cc0d2276f0723cde017a
|
// fixed with https://github.com/tidalcycles/strudel/commit/72eeaf446e3d5e186d63cc0d2276f0723cde017a
|
||||||
assert.equal(sequence(1, 2, 3).ply(2).early(8).firstCycle().length, 6);
|
assert.equal(sequence(1, 2, 3).ply(2).early(8).firstCycle().length, 6);
|
||||||
});
|
});
|
||||||
@@ -865,7 +731,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)._sortHapsByPart().firstCycle(),
|
pure({ sound: 'a' }).fast(2).chop(2, 3)._sortEventsByPart().firstCycle(),
|
||||||
sequence(
|
sequence(
|
||||||
[
|
[
|
||||||
{ sound: 'a', begin: 0, end: 0.5 },
|
{ sound: 'a', begin: 0, end: 0.5 },
|
||||||
@@ -877,7 +743,7 @@ describe('Pattern', function () {
|
|||||||
{ sound: 'a', begin: 2 / 3, end: 1 },
|
{ sound: 'a', begin: 2 / 3, end: 1 },
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
._sortHapsByPart()
|
._sortEventsByPart()
|
||||||
.firstCycle(),
|
.firstCycle(),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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 { pure } from '../pattern.mjs';
|
import { pure } from '../pattern.mjs';
|
||||||
import { isNote, tokenizeNote, toMidi, fromMidi, mod, compose, getFrequency } from '../util.mjs';
|
import { isNote, tokenizeNote, toMidi, fromMidi, mod, compose, getFrequency } from '../util.mjs';
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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 {
|
||||||
@@ -34,16 +28,12 @@ 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.add(this.duration);
|
const e = b.add(this.end.sub(this.begin));
|
||||||
return new TimeSpan(b, e);
|
return new TimeSpan(b, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +87,7 @@ export class TimeSpan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
midpoint() {
|
midpoint() {
|
||||||
return this.begin.add(this.duration.div(Fraction(2)));
|
return this.begin.add(this.end.sub(this.begin).div(Fraction(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
equals(other) {
|
equals(other) {
|
||||||
|
|||||||
+8
-14
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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) => {
|
||||||
@@ -33,29 +27,29 @@ 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 % m) + m) % m;
|
export const mod = (n, m) => (n < 0 ? mod(n + m, m) : n % m);
|
||||||
|
|
||||||
export const getPlayableNoteValue = (hap) => {
|
export const getPlayableNoteValue = (event) => {
|
||||||
let { value: note, context } = hap;
|
let { value: note, context } = event;
|
||||||
// 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(hap.value);
|
note = fromMidi(event.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) => {
|
export const getFrequency = (event) => {
|
||||||
let { value, context } = hap;
|
let { value, context } = event;
|
||||||
// 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 value === 'object' && value.freq) {
|
if (typeof value === 'object' && value.freq) {
|
||||||
return value.freq;
|
return value.freq;
|
||||||
}
|
}
|
||||||
if (typeof value === 'number' && context.type !== 'frequency') {
|
if (typeof value === 'number' && context.type !== 'frequency') {
|
||||||
value = fromMidi(hap.value);
|
value = fromMidi(event.value);
|
||||||
} else if (typeof value === 'string' && isNote(value)) {
|
} else if (typeof value === 'string' && isNote(value)) {
|
||||||
value = fromMidi(toMidi(hap.value));
|
value = fromMidi(toMidi(event.value));
|
||||||
} else if (typeof value !== 'number') {
|
} else if (typeof value !== 'number') {
|
||||||
throw new Error('not a note or frequency:' + value);
|
throw new Error('not a note or frequency:' + value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,6 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
|
|
||||||
export function unionWithObj(a, b, func) {
|
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])])));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
# @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.
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
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);
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"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,8 +11,6 @@ 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,45 +1,17 @@
|
|||||||
/*
|
|
||||||
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, Pattern } = strudel;
|
const { isPattern } = strudel;
|
||||||
|
|
||||||
export const extend = (...args) => {
|
export const extend = (...args) => {
|
||||||
console.warn('@strudel.cycles/eval extend is deprecated, please use evalScope instead');
|
// TODO: find a way to make args available to eval without adding it to global scope...
|
||||||
|
// 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 safeEval(shapeshifted);
|
let evaluated = await eval(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`;
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export * from './evaluate.mjs';
|
|
||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/eval",
|
"name": "@strudel.cycles/eval",
|
||||||
"version": "0.1.0",
|
"version": "0.0.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/eval",
|
"name": "@strudel.cycles/eval",
|
||||||
"version": "0.1.0",
|
"version": "0.0.5",
|
||||||
"description": "Code evaluator for strudel",
|
"description": "Code evaluator for strudel",
|
||||||
"main": "index.mjs",
|
"main": "evaluate.mjs",
|
||||||
"type": "module",
|
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
@@ -14,6 +13,7 @@
|
|||||||
"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,7 +22,7 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-3.0-or-later",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/tidalcycles/strudel/issues"
|
"url": "https://github.com/tidalcycles/strudel/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
@@ -29,8 +23,6 @@ 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);
|
||||||
@@ -46,18 +38,18 @@ export default (_code) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// replace template string `xxx` with mini(`xxx`)
|
// replace template string `xxx` with mini(`xxx`)
|
||||||
if (minifyStrings && isBackTickString(node)) {
|
if (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 (minifyStrings && node.directives?.length === 1 && !node.statements?.length) {
|
if (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 (minifyStrings && isStringWithDoubleQuotes(node, ast.locations, code)) {
|
if (isStringWithDoubleQuotes(node, ast.locations, code)) {
|
||||||
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
return minifyWithLocation(node, node, ast.locations, artificialNodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,9 +117,7 @@ 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)
|
||||||
if (wrappedAsync) {
|
addReturn(shifted);
|
||||||
addReturn(shifted);
|
|
||||||
}
|
|
||||||
const generated = codegen(shifted);
|
const generated = codegen(shifted);
|
||||||
return generated;
|
return generated;
|
||||||
};
|
};
|
||||||
@@ -135,11 +125,9 @@ 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
|
||||||
if (wrappedAsync) {
|
code = `(async () => {
|
||||||
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
|
||||||
@@ -216,10 +204,9 @@ 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' && factories.includes(node.callee.name);
|
return node?.type === 'CallExpression' && Object.keys(Pattern.prototype.factories).includes(node.callee.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canBeOverloaded(node) {
|
function canBeOverloaded(node) {
|
||||||
@@ -246,14 +233,9 @@ 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: wrapped,
|
object: wrapFunction('mini', literalNode),
|
||||||
property: 'withMiniLocation',
|
property: 'withMiniLocation',
|
||||||
}),
|
}),
|
||||||
arguments: args,
|
arguments: args,
|
||||||
@@ -264,18 +246,17 @@ 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 + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
|
new LiteralNumericExpression({ value: loc.start.line - 1 }), // 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 + lineOffset }), // the minus 1 assumes the code has been wrapped in async iife
|
new LiteralNumericExpression({ value: loc.end.line - 1 }), // 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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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,29 +1,22 @@
|
|||||||
/*
|
|
||||||
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 { fastcat } = strudel;
|
const { cat } = 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('fastcat(c3, d3)'), ['c3', 'd3']);
|
assert.deepStrictEqual(await ev('cat(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) => fastcat(...x) });
|
extend({ myFunction: (...x) => cat(...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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
import './midi.mjs';
|
|
||||||
|
|
||||||
export * from './midi.mjs';
|
|
||||||
+7
-13
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
@@ -39,11 +33,11 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
|||||||
}')`,
|
}')`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this._withHap((hap) => {
|
return this._withEvent((event) => {
|
||||||
// const onTrigger = (time: number, hap: any) => {
|
// const onTrigger = (time: number, event: any) => {
|
||||||
const onTrigger = (time, hap) => {
|
const onTrigger = (time, event) => {
|
||||||
let note = hap.value;
|
let note = event.value;
|
||||||
const velocity = hap.context?.velocity ?? 0.9;
|
const velocity = event.context?.velocity ?? 0.9;
|
||||||
if (!isNote(note)) {
|
if (!isNote(note)) {
|
||||||
throw new Error('not a note: ' + note);
|
throw new Error('not a note: ' + note);
|
||||||
}
|
}
|
||||||
@@ -75,10 +69,10 @@ Pattern.prototype.midi = function (output, channel = 1) {
|
|||||||
// await enableWebMidi()
|
// await enableWebMidi()
|
||||||
device.playNote(note, channel, {
|
device.playNote(note, channel, {
|
||||||
time,
|
time,
|
||||||
duration: hap.duration.valueOf() * 1000 - 5,
|
duration: event.duration * 1000 - 5,
|
||||||
velocity,
|
velocity,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return hap.setContext({ ...hap.context, onTrigger });
|
return event.setContext({ ...event.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/midi",
|
"name": "@strudel.cycles/midi",
|
||||||
"version": "0.1.0",
|
"version": "0.0.6",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/midi",
|
"name": "@strudel.cycles/midi",
|
||||||
"version": "0.1.0",
|
"version": "0.0.6",
|
||||||
"description": "Midi API for strudel",
|
"description": "Midi API for strudel",
|
||||||
"main": "index.mjs",
|
"main": "midi.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": "AGPL-3.0-or-later",
|
"license": "GPL-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.1.0",
|
"@strudel.cycles/tone": "^0.0.6",
|
||||||
"tone": "^14.7.77",
|
"tone": "^14.7.77",
|
||||||
"webmidi": "^2.5.2"
|
"webmidi": "^2.5.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
export * from './mini.mjs';
|
|
||||||
export * from './krill-parser.js';
|
|
||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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.1.0",
|
"version": "0.0.7",
|
||||||
"description": "Mini notation for strudel",
|
"description": "Mini notation for strudel",
|
||||||
"main": "index.mjs",
|
"main": "mini.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha --colors"
|
"test": "mocha --colors"
|
||||||
@@ -19,14 +19,14 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-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.0.5",
|
||||||
"@strudel.cycles/eval": "^0.1.0",
|
"@strudel.cycles/eval": "^0.0.5",
|
||||||
"@strudel.cycles/tone": "^0.1.0"
|
"@strudel.cycles/tone": "^0.0.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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';
|
||||||
|
|||||||
+6
-16
@@ -1,33 +1,23 @@
|
|||||||
/*
|
|
||||||
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._withHap((hap) => {
|
return this._withEvent((event) => {
|
||||||
const onTrigger = (time, hap, currentTime, cps, cycle, delta) => {
|
const onTrigger = (time, event, currentTime) => {
|
||||||
// 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)
|
||||||
if (startedAt < 0) {
|
const keyvals = Object.entries(event.value).flat();
|
||||||
startedAt = Date.now() - (currentTime * 1000);
|
const offset = (time - currentTime + latency) * 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 hap.setContext({ ...hap.context, onTrigger });
|
return event.setContext({ ...event.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/osc",
|
"name": "@strudel.cycles/osc",
|
||||||
"version": "0.1.0",
|
"version": "0.0.2",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/osc",
|
"name": "@strudel.cycles/osc",
|
||||||
"version": "0.1.0",
|
"version": "0.0.2",
|
||||||
"description": "OSC messaging for strudel",
|
"description": "OSC messaging for strudel",
|
||||||
"main": "osc.mjs",
|
"main": "osc.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -21,10 +21,8 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Felix Roos <flix91@gmail.com>",
|
"author": "Felix Roos <flix91@gmail.com>",
|
||||||
"contributors": [
|
"contributors": ["Alex McLean <alex@slab.org>"],
|
||||||
"Alex McLean <alex@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"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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,9 +1,3 @@
|
|||||||
/*
|
|
||||||
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 = {
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
# 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?
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# @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
@@ -1,620 +0,0 @@
|
|||||||
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
@@ -1 +0,0 @@
|
|||||||
*,: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}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<!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>
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@strudel.cycles/react",
|
|
||||||
"version": "0.1.1",
|
|
||||||
"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.0",
|
|
||||||
"@strudel.cycles/tone": "^0.1.0",
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
/*
|
|
||||||
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: {},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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,33 +0,0 @@
|
|||||||
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
.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;
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
.cm-editor {
|
|
||||||
background-color: transparent !important;
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
/*
|
|
||||||
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,41 +0,0 @@
|
|||||||
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;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
/*
|
|
||||||
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,10 +0,0 @@
|
|||||||
// 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';
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import React from 'react'
|
|
||||||
import ReactDOM from 'react-dom'
|
|
||||||
import App from './App'
|
|
||||||
|
|
||||||
ReactDOM.render(<React.StrictMode><App /></React.StrictMode>,document.getElementById('root'))
|
|
||||||
@@ -1,135 +0,0 @@
|
|||||||
import { EditorView } from '@codemirror/view';
|
|
||||||
import { HighlightStyle, tags as t } from '@codemirror/highlight';
|
|
||||||
|
|
||||||
/*
|
|
||||||
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.
|
|
||||||
export 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.
|
|
||||||
export const materialPalenightHighlightStyle = HighlightStyle.define([
|
|
||||||
{ tag: t.keyword, color: '#c792ea' },
|
|
||||||
{ tag: t.operator, color: '#89ddff' },
|
|
||||||
{ tag: t.special(t.variableName), color: '#eeffff' },
|
|
||||||
{ tag: t.typeName, color: '#f07178' },
|
|
||||||
{ tag: t.atom, color: '#f78c6c' },
|
|
||||||
{ tag: t.number, color: '#ff5370' },
|
|
||||||
{ tag: t.definition(t.variableName), color: '#82aaff' },
|
|
||||||
{ tag: t.string, color: '#c3e88d' },
|
|
||||||
{ tag: t.special(t.string), color: '#f07178' },
|
|
||||||
{ tag: t.comment, color: stone },
|
|
||||||
{ tag: t.variableName, color: '#f07178' },
|
|
||||||
{ tag: t.tagName, color: '#ff5370' },
|
|
||||||
{ tag: t.bracket, color: '#a2a1a4' },
|
|
||||||
{ tag: t.meta, color: '#ffcb6b' },
|
|
||||||
{ tag: t.attributeName, color: '#c792ea' },
|
|
||||||
{ tag: t.propertyName, color: '#c792ea' },
|
|
||||||
{ tag: t.className, color: '#decb6b' },
|
|
||||||
{ tag: t.invalid, color: invalid },
|
|
||||||
]);
|
|
||||||
|
|
||||||
/// Extension to enable the Material Palenight theme (both the editor theme and
|
|
||||||
/// the highlight style).
|
|
||||||
// : Extension
|
|
||||||
export const materialPalenight = [materialPalenightTheme, materialPalenightHighlightStyle];
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
||||||
theme: {
|
|
||||||
extend: {},
|
|
||||||
},
|
|
||||||
plugins: [],
|
|
||||||
corePlugins: {
|
|
||||||
preflight: false,
|
|
||||||
},
|
|
||||||
prefix: 'sc-',
|
|
||||||
};
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
import { defineConfig } from 'vite';
|
|
||||||
import react from '@vitejs/plugin-react';
|
|
||||||
import { peerDependencies, dependencies } from './package.json';
|
|
||||||
import { resolve } from 'path';
|
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
|
||||||
export default defineConfig({
|
|
||||||
plugins: [
|
|
||||||
react({
|
|
||||||
jsxRuntime: 'classic',
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
build: {
|
|
||||||
lib: {
|
|
||||||
entry: resolve(__dirname, 'src', 'index.js'),
|
|
||||||
formats: ['es', 'cjs'],
|
|
||||||
fileName: (ext) => `index.${ext}.js`,
|
|
||||||
// for UMD name: 'GlobalName'
|
|
||||||
},
|
|
||||||
rollupOptions: {
|
|
||||||
external: [
|
|
||||||
...Object.keys(peerDependencies),
|
|
||||||
...Object.keys(dependencies),
|
|
||||||
// TODO: find out which of below names are obsolete now
|
|
||||||
'@strudel.cycles/tone',
|
|
||||||
'@strudel.cycles/eval',
|
|
||||||
'@strudel.cycles/core',
|
|
||||||
'@strudel.cycles/core/util.mjs',
|
|
||||||
'@strudel.cycles/mini',
|
|
||||||
'@strudel.cycles/tonal',
|
|
||||||
'@strudel.cycles/midi',
|
|
||||||
'@strudel.cycles/xen',
|
|
||||||
'@strudel.cycles/serial',
|
|
||||||
'@strudel.cycles/webaudio',
|
|
||||||
'@codemirror/view',
|
|
||||||
'@codemirror/highlight',
|
|
||||||
'@codemirror/state'
|
|
||||||
],
|
|
||||||
},
|
|
||||||
target: 'esnext',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@strudel.cycles/serial",
|
"name": "@strudel.cycles/serial",
|
||||||
"version": "0.1.0",
|
"version": "0.0.6",
|
||||||
"description": "Webserial API for strudel",
|
"description": "Webserial API for strudel",
|
||||||
"main": "serial.mjs",
|
"main": "serial.mjs",
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -15,9 +15,10 @@
|
|||||||
"algorave"
|
"algorave"
|
||||||
],
|
],
|
||||||
"author": "Alex McLean <alex@slab.org>",
|
"author": "Alex McLean <alex@slab.org>",
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "GPL-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": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,3 @@
|
|||||||
/*
|
|
||||||
serial.mjs - <short description TODO>
|
|
||||||
Copyright (C) 2022 Strudel contributors - see <https://github.com/tidalcycles/strudel/blob/main/packages/serial/serial.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, isPattern } from '@strudel.cycles/core';
|
import { Pattern, isPattern } from '@strudel.cycles/core';
|
||||||
|
|
||||||
var serialWriter;
|
var serialWriter;
|
||||||
@@ -36,23 +30,23 @@ const latency = 0.1;
|
|||||||
|
|
||||||
// Pattern.prototype.midi = function (output: string | number, channel = 1) {
|
// Pattern.prototype.midi = function (output: string | number, channel = 1) {
|
||||||
Pattern.prototype.serial = async function (...args) {
|
Pattern.prototype.serial = async function (...args) {
|
||||||
return this._withHap((hap) => {
|
return this._withEvent((event) => {
|
||||||
if (!serialWriter) {
|
if (!serialWriter) {
|
||||||
getWriter(...args);
|
getWriter(...args);
|
||||||
}
|
}
|
||||||
const onTrigger = (time, hap, currentTime) => {
|
const onTrigger = (time, event, currentTime) => {
|
||||||
var message = "";
|
var message = "";
|
||||||
if (typeof hap.value === 'object') {
|
if (typeof event.value === 'object') {
|
||||||
for (const [key, val] of Object.entries(hap.value).flat()) {
|
for (const [key, val] of Object.entries(event.value).flat()) {
|
||||||
message += `${key}:${val};`
|
message += `${key}:${val};`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message = hap.value;
|
message = event.value;
|
||||||
}
|
}
|
||||||
const offset = (time - currentTime + latency) * 1000;
|
const offset = (time - currentTime + latency) * 1000;
|
||||||
window.setTimeout(serialWriter, offset, message);
|
window.setTimeout(serialWriter, offset, message);
|
||||||
};
|
};
|
||||||
return hap.setContext({ ...hap.context, onTrigger });
|
return event.setContext({ ...event.context, onTrigger });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user