Commit 71791d7
authored
JS editor update: Ability to convert JS code from editor to blocks (simple flow, pitch, tone, and rhythm blocks) (#4591)
* Add functionality to convert JavaScript code to block list format that can be loaded into the MusicBlocks editor.
This is the first commit for such functionality, which allows users to write JavaScript code in the JS Editor directly and convert the code back to music blocks. Blocks supported in this commit are:
1. settimbre
2. newnote
3. pitch (only supports solfege)
4. if
5. for
6. All number blocks. Supports arbitrary expressions like 1 / 2, Math.abs(-1) / 2, MathUtility.doRandom(1, 2) / 4, etc.
7. All boolean blocks. Supports arbitrary boolean expressions like MathUtility.doRandom(0, 1) == 1, false | MathUtility.doRandom(0, 1) == 1, etc.
8. Action (supports recursion)
9. Dictionary (setValue, getValue, function overloading)
New files in the commit:
1. ast2blocklist.js - main logic to convert an AST generated from JavaScript code to block list format that can be loaded into the block editor
2. ast2blocklist.test.js - unit tests that cover all supported blocks conversion
3. acorn.js - library that converts JavaScript code to AST
* Updated UI to include button for converting JS code in the editor to musicblocks.
Updated structure of ast2blocklist.js for better readability, and makes adding more block support easier.
Minor change: Play pitch now supports notes (A-G) in addition to solfege.
* Updated tooltips in jseditor to use _() so that it is available for translation.
* 1. Added logic to calculate the vertical spaces used by blocks and arguments, and adds v-spacers based on the information
2. Instead of console.error for errors, it now throws error and shows in console panel of jseditor
3. Uses minified version of acorn library for faster loading
4. Removed driver code from ast2blocklist
* Updated ast2blocklist, ast2blocklist.test, jseditor, and activity to fix lint errors.1 parent a22aefe commit 71791d7
File tree
7 files changed
+1684
-20
lines changed- js
- js-export
- __tests__
- widgets
- lib
7 files changed
+1684
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
58 | 62 | | |
59 | 63 | | |
60 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
108 | 109 | | |
109 | 110 | | |
110 | 111 | | |
| |||
2995 | 2996 | | |
2996 | 2997 | | |
2997 | 2998 | | |
2998 | | - | |
| 2999 | + | |
2999 | 3000 | | |
3000 | 3001 | | |
3001 | 3002 | | |
| |||
4004 | 4005 | | |
4005 | 4006 | | |
4006 | 4007 | | |
| 4008 | + | |
4007 | 4009 | | |
4008 | | - | |
| 4010 | + | |
4009 | 4011 | | |
4010 | 4012 | | |
4011 | 4013 | | |
| |||
4065 | 4067 | | |
4066 | 4068 | | |
4067 | 4069 | | |
4068 | | - | |
| 4070 | + | |
| 4071 | + | |
| 4072 | + | |
4069 | 4073 | | |
4070 | 4074 | | |
4071 | 4075 | | |
| |||
0 commit comments