@devaloop/devalang 0.0.1-alpha.8 → 0.0.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cargo/config.toml +2 -0
- package/.devalang +10 -4
- package/.github/workflows/ci.yml +103 -0
- package/Cargo.toml +80 -48
- package/README.md +135 -158
- package/docs/CHANGELOG.md +413 -1
- package/docs/CONTRIBUTING.md +101 -0
- package/docs/ROADMAP.md +10 -7
- package/docs/TODO.md +21 -9
- package/examples/automation.deva +42 -0
- package/examples/bank.deva +7 -0
- package/examples/condition.deva +8 -12
- package/examples/duration.deva +9 -0
- package/examples/events.deva +12 -0
- package/examples/function.deva +15 -0
- package/examples/group.deva +3 -3
- package/examples/index.deva +57 -10
- package/examples/loop.deva +7 -12
- package/examples/pattern.deva +8 -0
- package/examples/plugin.deva +16 -0
- package/examples/synth.deva +14 -0
- package/examples/variables.deva +2 -2
- package/out-tsc/bin/index.d.ts +2 -0
- package/out-tsc/bin/index.js +51 -7
- package/out-tsc/core/functions/index.d.ts +37 -0
- package/out-tsc/core/functions/index.js +76 -0
- package/out-tsc/core/index.d.ts +6 -0
- package/out-tsc/core/index.js +22 -0
- package/out-tsc/core/types/index.d.ts +4 -0
- package/out-tsc/core/types/index.js +20 -0
- package/out-tsc/core/types/plugin.d.ts +18 -0
- package/out-tsc/core/types/plugin.js +2 -0
- package/out-tsc/core/types/result.d.ts +27 -0
- package/out-tsc/core/types/result.js +2 -0
- package/out-tsc/core/types/statement.d.ts +106 -0
- package/out-tsc/core/types/statement.js +2 -0
- package/out-tsc/core/types/value.d.ts +43 -0
- package/out-tsc/core/types/value.js +2 -0
- package/out-tsc/index.d.ts +7 -0
- package/out-tsc/index.js +42 -1
- package/out-tsc/pkg/devalang_core.d.ts +13 -0
- package/out-tsc/pkg/devalang_core.js +50 -0
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +33 -0
- package/out-tsc/scripts/copy-wasm-dts.d.ts +1 -0
- package/out-tsc/scripts/copy-wasm-dts.js +73 -0
- package/out-tsc/scripts/postinstall.d.ts +1 -0
- package/out-tsc/scripts/postinstall.js +83 -0
- package/out-tsc/scripts/version/bump.d.ts +1 -0
- package/out-tsc/scripts/version/fetch.d.ts +1 -0
- package/out-tsc/scripts/version/fetch.js +1 -5
- package/out-tsc/scripts/version/index.d.ts +1 -0
- package/out-tsc/scripts/version/sync.d.ts +1 -0
- package/package.json +28 -7
- package/project-version.json +4 -4
- package/rust/cli/bank/api.rs +122 -0
- package/rust/cli/bank/commands.rs +275 -0
- package/rust/cli/bank/mod.rs +29 -0
- package/rust/cli/build/commands.rs +103 -0
- package/rust/cli/build/mod.rs +2 -0
- package/rust/cli/build/process.rs +146 -0
- package/rust/cli/check/mod.rs +208 -0
- package/rust/cli/discover/commands.rs +253 -0
- package/rust/cli/discover/config.rs +111 -0
- package/rust/cli/discover/fs.rs +19 -0
- package/rust/cli/discover/install.rs +103 -0
- package/rust/cli/discover/metadata.rs +48 -0
- package/rust/cli/discover/mod.rs +5 -0
- package/rust/cli/{init.rs → init/commands.rs} +32 -23
- package/rust/cli/init/mod.rs +1 -0
- package/rust/cli/install/addon.rs +118 -0
- package/rust/cli/install/bank.rs +53 -0
- package/rust/cli/install/commands.rs +35 -0
- package/rust/cli/install/mod.rs +4 -0
- package/rust/cli/install/plugin.rs +61 -0
- package/rust/cli/login/commands.rs +124 -0
- package/rust/cli/login/mod.rs +1 -0
- package/rust/cli/mod.rs +12 -205
- package/rust/cli/parser.rs +314 -0
- package/rust/cli/play/commands.rs +324 -0
- package/rust/cli/play/io.rs +17 -0
- package/rust/cli/play/mod.rs +5 -0
- package/rust/cli/play/process.rs +150 -0
- package/rust/cli/play/realtime.rs +91 -0
- package/rust/cli/play/utils.rs +23 -0
- package/rust/cli/telemetry/commands.rs +22 -0
- package/rust/cli/telemetry/event_creator.rs +80 -0
- package/rust/cli/telemetry/mod.rs +3 -0
- package/rust/cli/telemetry/send.rs +51 -0
- package/rust/cli/{template.rs → template/commands.rs} +69 -57
- package/rust/cli/template/mod.rs +1 -0
- package/rust/cli/update/commands.rs +6 -0
- package/rust/cli/update/mod.rs +1 -0
- package/rust/config/driver.rs +103 -0
- package/rust/config/mod.rs +3 -16
- package/rust/config/ops.rs +26 -0
- package/rust/config/settings.rs +101 -0
- package/rust/core/audio/engine/helpers.rs +170 -0
- package/rust/core/audio/engine/mod.rs +7 -0
- package/rust/core/audio/engine/sample.rs +366 -0
- package/rust/core/audio/engine/synth.rs +325 -0
- package/rust/core/audio/evaluator.rs +310 -31
- package/rust/core/audio/interpreter/arrow_call.rs +311 -0
- package/rust/core/audio/interpreter/automate.rs +18 -0
- package/rust/core/audio/interpreter/call.rs +294 -42
- package/rust/core/audio/interpreter/condition.rs +71 -65
- package/rust/core/audio/interpreter/driver.rs +542 -204
- package/rust/core/audio/interpreter/function.rs +26 -0
- package/rust/core/audio/interpreter/let_.rs +38 -19
- package/rust/core/audio/interpreter/load.rs +19 -18
- package/rust/core/audio/interpreter/loop_.rs +114 -59
- package/rust/core/audio/interpreter/mod.rs +14 -11
- package/rust/core/audio/interpreter/sleep.rs +28 -36
- package/rust/core/audio/interpreter/spawn.rs +252 -65
- package/rust/core/audio/interpreter/tempo.rs +40 -16
- package/rust/core/audio/interpreter/trigger.rs +239 -69
- package/rust/core/audio/loader/mod.rs +1 -1
- package/rust/core/audio/loader/trigger.rs +97 -52
- package/rust/core/audio/mod.rs +7 -6
- package/rust/core/audio/player.rs +70 -54
- package/rust/core/audio/renderer.rs +54 -57
- package/rust/core/audio/special/easing.rs +189 -0
- package/rust/core/audio/special/env.rs +45 -0
- package/rust/core/audio/special/math.rs +134 -0
- package/rust/core/audio/special/mod.rs +9 -0
- package/rust/core/audio/special/modulator.rs +143 -0
- package/rust/core/builder/mod.rs +86 -80
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/mod.rs +30 -21
- package/rust/core/debugger/module.rs +55 -0
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +40 -25
- package/rust/core/error/mod.rs +269 -60
- package/rust/core/lexer/driver.rs +61 -0
- package/rust/core/lexer/handler/arrow.rs +82 -0
- package/rust/core/lexer/handler/at.rs +21 -21
- package/rust/core/lexer/handler/brace.rs +41 -41
- package/rust/core/lexer/handler/colon.rs +21 -21
- package/rust/core/lexer/handler/comment.rs +30 -30
- package/rust/core/lexer/handler/dot.rs +21 -21
- package/rust/core/lexer/handler/driver.rs +337 -215
- package/rust/core/lexer/handler/identifier.rs +47 -40
- package/rust/core/lexer/handler/indent.rs +66 -52
- package/rust/core/lexer/handler/mod.rs +15 -13
- package/rust/core/lexer/handler/newline.rs +23 -23
- package/rust/core/lexer/handler/number.rs +31 -31
- package/rust/core/lexer/handler/operator.rs +46 -44
- package/rust/core/lexer/handler/parenthesis.rs +41 -0
- package/rust/core/lexer/handler/slash.rs +21 -0
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +3 -30
- package/rust/core/lexer/token.rs +21 -12
- package/rust/core/mod.rs +10 -10
- package/rust/core/parser/driver.rs +584 -312
- package/rust/core/parser/handler/arrow_call.rs +253 -0
- package/rust/core/parser/handler/at.rs +279 -162
- package/rust/core/parser/handler/bank.rs +104 -41
- package/rust/core/parser/handler/condition.rs +83 -74
- package/rust/core/parser/handler/dot.rs +148 -112
- package/rust/core/parser/handler/identifier/automate.rs +254 -0
- package/rust/core/parser/handler/identifier/call.rs +91 -0
- package/rust/core/parser/handler/identifier/emit.rs +70 -0
- package/rust/core/parser/handler/identifier/function.rs +113 -0
- package/rust/core/parser/handler/identifier/group.rs +89 -0
- package/rust/core/parser/handler/identifier/let_.rs +173 -0
- package/rust/core/parser/handler/identifier/mod.rs +55 -0
- package/rust/core/parser/handler/identifier/on.rs +107 -0
- package/rust/core/parser/handler/identifier/print.rs +49 -0
- package/rust/core/parser/handler/identifier/sleep.rs +43 -0
- package/rust/core/parser/handler/identifier/spawn.rs +91 -0
- package/rust/core/parser/handler/identifier/synth.rs +135 -0
- package/rust/core/parser/handler/loop_.rs +194 -66
- package/rust/core/parser/handler/mod.rs +9 -7
- package/rust/core/parser/handler/pattern.rs +74 -0
- package/rust/core/parser/handler/tempo.rs +57 -47
- package/rust/core/parser/mod.rs +3 -4
- package/rust/core/parser/statement.rs +11 -88
- package/rust/core/plugin/loader.rs +137 -0
- package/rust/core/plugin/mod.rs +2 -0
- package/rust/core/plugin/runner.rs +347 -0
- package/rust/core/preprocessor/loader.rs +637 -179
- package/rust/core/preprocessor/mod.rs +4 -4
- package/rust/core/preprocessor/module.rs +60 -53
- package/rust/core/preprocessor/processor.rs +114 -67
- package/rust/core/preprocessor/resolver/bank.rs +49 -47
- package/rust/core/preprocessor/resolver/call.rs +124 -53
- package/rust/core/preprocessor/resolver/condition.rs +95 -66
- package/rust/core/preprocessor/resolver/driver.rs +324 -182
- package/rust/core/preprocessor/resolver/function.rs +69 -0
- package/rust/core/preprocessor/resolver/group.rs +94 -118
- package/rust/core/preprocessor/resolver/let_.rs +32 -0
- package/rust/core/preprocessor/resolver/loop_.rs +318 -145
- package/rust/core/preprocessor/resolver/mod.rs +16 -10
- package/rust/core/preprocessor/resolver/pattern.rs +83 -0
- package/rust/core/preprocessor/resolver/spawn.rs +99 -53
- package/rust/core/preprocessor/resolver/synth.rs +54 -0
- package/rust/core/preprocessor/resolver/tempo.rs +48 -49
- package/rust/core/preprocessor/resolver/trigger.rs +116 -111
- package/rust/core/preprocessor/resolver/value.rs +176 -0
- package/rust/core/store/export.rs +28 -28
- package/rust/core/store/function.rs +40 -0
- package/rust/core/store/global.rs +61 -39
- package/rust/core/store/import.rs +28 -28
- package/rust/core/store/mod.rs +5 -4
- package/rust/core/store/variable.rs +51 -28
- package/rust/core/utils/mod.rs +1 -2
- package/rust/core/utils/path.rs +37 -46
- package/rust/lib.rs +308 -117
- package/rust/main.rs +364 -65
- package/rust/types/Cargo.toml +11 -0
- package/rust/types/src/addons.rs +55 -0
- package/rust/types/src/ast.rs +202 -0
- package/rust/types/src/config.rs +74 -0
- package/rust/types/src/lib.rs +12 -0
- package/rust/types/src/telemetry.rs +85 -0
- package/rust/utils/Cargo.toml +26 -0
- package/rust/utils/src/error.rs +186 -0
- package/rust/utils/src/file.rs +94 -0
- package/rust/utils/src/first_usage.rs +97 -0
- package/rust/utils/{mod.rs → src/lib.rs} +9 -6
- package/rust/utils/{logger.rs → src/logger.rs} +200 -123
- package/rust/utils/src/path.rs +88 -0
- package/rust/utils/src/signature.rs +41 -0
- package/rust/utils/{spinner.rs → src/spinner.rs} +20 -21
- package/rust/utils/src/version.rs +27 -0
- package/rust/utils/{watcher.rs → src/watcher.rs} +46 -33
- package/rust/web/api.rs +5 -0
- package/rust/web/cdn.rs +34 -0
- package/rust/web/mod.rs +3 -0
- package/rust/web/sso.rs +5 -0
- package/templates/minimal/README.md +143 -127
- package/templates/welcome/README.md +143 -127
- package/templates/welcome/src/index.deva +56 -8
- package/templates/welcome/src/variables.deva +2 -4
- package/tests/integration.rs +21 -0
- package/tests/rust/cli_check_build.rs +21 -0
- package/tests/rust/cli_help.rs +12 -0
- package/tests/rust/cli_template_list.rs +10 -0
- package/tests/rust/cli_version.rs +11 -0
- package/tests/typescript/index.spec.ts +136 -0
- package/tests/typescript/playhead.spec.ts +36 -0
- package/tests/typescript/render_e2e.spec.ts +77 -0
- package/tsconfig.json +12 -10
- package/typescript/bin/index.ts +19 -5
- package/typescript/core/functions/index.ts +83 -0
- package/typescript/core/index.ts +6 -0
- package/typescript/core/types/index.ts +4 -0
- package/typescript/core/types/plugin.ts +19 -0
- package/typescript/core/types/result.ts +29 -0
- package/typescript/core/types/statement.ts +47 -0
- package/typescript/core/types/value.ts +29 -0
- package/typescript/index.ts +8 -1
- package/typescript/pkg/devalang_core.d.ts +4 -0
- package/typescript/pkg/devalang_core.ts +49 -0
- package/typescript/scripts/copy-wasm-dts.ts +41 -0
- package/typescript/scripts/postinstall.ts +85 -0
- package/typescript/scripts/version/bump.ts +0 -1
- package/typescript/scripts/version/fetch.ts +1 -6
- package/typescript/scripts/version/index.ts +0 -1
- package/docs/COMMANDS.md +0 -85
- package/docs/CONFIG.md +0 -30
- package/docs/SYNTAX.md +0 -210
- package/out-tsc/bin/devalang.exe +0 -0
- package/out-tsc/scripts/postbuild.js +0 -11
- package/rust/cli/build.rs +0 -137
- package/rust/cli/check.rs +0 -117
- package/rust/cli/play.rs +0 -193
- package/rust/config/loader.rs +0 -13
- package/rust/core/audio/engine.rs +0 -126
- package/rust/core/parser/handler/identifier.rs +0 -262
- package/rust/core/shared/duration.rs +0 -8
- package/rust/core/shared/mod.rs +0 -2
- package/rust/core/shared/value.rs +0 -18
- package/rust/core/utils/validation.rs +0 -35
- package/rust/utils/file.rs +0 -35
- package/rust/utils/signature.rs +0 -17
- package/rust/utils/version.rs +0 -15
- package/typescript/scripts/postbuild.ts +0 -8
|
@@ -1,204 +1,542 @@
|
|
|
1
|
-
use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
trigger::interprete_trigger_statement,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
parser::statement::{
|
|
17
|
-
store::variable::VariableTable,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
use devalang_types::Value;
|
|
2
|
+
use devalang_utils::logger::{LogLevel, Logger};
|
|
3
|
+
use rayon::prelude::*;
|
|
4
|
+
|
|
5
|
+
use crate::core::{
|
|
6
|
+
audio::{
|
|
7
|
+
engine::AudioEngine,
|
|
8
|
+
interpreter::{
|
|
9
|
+
arrow_call::interprete_call_arrow_statement, call::interprete_call_statement,
|
|
10
|
+
function::interprete_function_statement, let_::interprete_let_statement,
|
|
11
|
+
load::interprete_load_statement, loop_::interprete_loop_statement,
|
|
12
|
+
sleep::interprete_sleep_statement, spawn::interprete_spawn_statement,
|
|
13
|
+
tempo::interprete_tempo_statement, trigger::interprete_trigger_statement,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
parser::statement::{Statement, StatementKind},
|
|
17
|
+
store::{function::FunctionTable, global::GlobalStore, variable::VariableTable},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// WASM playhead callback support (only compiled for wasm32 target)
|
|
21
|
+
#[cfg(target_arch = "wasm32")]
|
|
22
|
+
use serde::Serialize;
|
|
23
|
+
|
|
24
|
+
#[cfg(target_arch = "wasm32")]
|
|
25
|
+
use wasm_bindgen::prelude::JsValue;
|
|
26
|
+
|
|
27
|
+
#[cfg(target_arch = "wasm32")]
|
|
28
|
+
use std::cell::RefCell;
|
|
29
|
+
|
|
30
|
+
#[cfg(target_arch = "wasm32")]
|
|
31
|
+
thread_local! {
|
|
32
|
+
static PLAYHEAD_CB: RefCell<Option<js_sys::Function>> = RefCell::new(None);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[cfg(target_arch = "wasm32")]
|
|
36
|
+
pub fn register_playhead_callback(cb: js_sys::Function) {
|
|
37
|
+
PLAYHEAD_CB.with(|c| *c.borrow_mut() = Some(cb));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[cfg(target_arch = "wasm32")]
|
|
41
|
+
pub fn unregister_playhead_callback() {
|
|
42
|
+
PLAYHEAD_CB.with(|c| *c.borrow_mut() = None);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#[cfg(target_arch = "wasm32")]
|
|
46
|
+
fn emit_playhead(time: f32, line: usize, column: usize) {
|
|
47
|
+
#[derive(Serialize)]
|
|
48
|
+
struct PlayheadEvent {
|
|
49
|
+
time: f32,
|
|
50
|
+
line: usize,
|
|
51
|
+
column: usize,
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let ev = PlayheadEvent { time, line, column };
|
|
55
|
+
if let Ok(v) = serde_wasm_bindgen::to_value(&ev) {
|
|
56
|
+
PLAYHEAD_CB.with(|c| {
|
|
57
|
+
if let Some(f) = c.borrow().as_ref() {
|
|
58
|
+
let _ = f.call1(&JsValue::NULL, &v);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
pub fn run_audio_program(
|
|
65
|
+
statements: &[Statement],
|
|
66
|
+
audio_engine: &mut AudioEngine,
|
|
67
|
+
_entry: String,
|
|
68
|
+
_output: String,
|
|
69
|
+
_module_variables: VariableTable,
|
|
70
|
+
_module_functions: FunctionTable,
|
|
71
|
+
global_store: &mut GlobalStore,
|
|
72
|
+
) -> (f32, f32) {
|
|
73
|
+
let base_bpm = 120.0;
|
|
74
|
+
let base_duration = 60.0 / base_bpm;
|
|
75
|
+
|
|
76
|
+
let (max_end_time, cursor_time) = execute_audio_block(
|
|
77
|
+
audio_engine,
|
|
78
|
+
global_store,
|
|
79
|
+
global_store.variables.clone(),
|
|
80
|
+
global_store.functions.clone(),
|
|
81
|
+
statements,
|
|
82
|
+
base_bpm,
|
|
83
|
+
base_duration,
|
|
84
|
+
0.0,
|
|
85
|
+
0.0,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
(max_end_time, cursor_time)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/// Execute a block of statements and schedule audio into the provided
|
|
92
|
+
/// AudioEngine. This function is the core of offline rendering and
|
|
93
|
+
/// performs the following responsibilities:
|
|
94
|
+
/// - sequential evaluation of statements (load, let, trigger, loop, etc.)
|
|
95
|
+
/// - parallel execution of `spawn` blocks (using rayon) and merging results
|
|
96
|
+
/// - scheduling of periodic events (beat/bar) once at the root depth
|
|
97
|
+
/// - emitting playhead events (when compiled for wasm32) after each sequential statement
|
|
98
|
+
pub fn execute_audio_block(
|
|
99
|
+
audio_engine: &mut AudioEngine,
|
|
100
|
+
global_store: &GlobalStore,
|
|
101
|
+
mut variable_table: VariableTable,
|
|
102
|
+
mut functions_table: FunctionTable,
|
|
103
|
+
statements: &[Statement],
|
|
104
|
+
mut base_bpm: f32,
|
|
105
|
+
mut base_duration: f32,
|
|
106
|
+
mut max_end_time: f32,
|
|
107
|
+
mut cursor_time: f32,
|
|
108
|
+
) -> (f32, f32) {
|
|
109
|
+
// Track nested depth of execute_audio_block to avoid scheduling periodic events multiple times
|
|
110
|
+
let current_depth = match variable_table.get("__depth") {
|
|
111
|
+
Some(Value::Number(n)) => *n,
|
|
112
|
+
_ => 0.0,
|
|
113
|
+
};
|
|
114
|
+
variable_table.set("__depth".to_string(), Value::Number(current_depth + 1.0));
|
|
115
|
+
let (spawns, others): (Vec<_>, Vec<_>) = statements
|
|
116
|
+
.iter()
|
|
117
|
+
.partition(|stmt| matches!(stmt.kind, StatementKind::Spawn { .. }));
|
|
118
|
+
|
|
119
|
+
// Execute sequential statements first
|
|
120
|
+
for stmt in others {
|
|
121
|
+
match &stmt.kind {
|
|
122
|
+
StatementKind::Load { .. } => {
|
|
123
|
+
if let Some(new_table) = interprete_load_statement(stmt, &mut variable_table) {
|
|
124
|
+
variable_table = new_table;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
StatementKind::On { .. } => {
|
|
128
|
+
// already registered in global store during parsing; nothing to do at runtime
|
|
129
|
+
}
|
|
130
|
+
StatementKind::Emit { event, payload: _ } => {
|
|
131
|
+
if let Some(handlers) = global_store.get_event_handlers(event) {
|
|
132
|
+
for h in handlers {
|
|
133
|
+
if let StatementKind::On {
|
|
134
|
+
event: _,
|
|
135
|
+
args,
|
|
136
|
+
body,
|
|
137
|
+
} = &h.kind
|
|
138
|
+
{
|
|
139
|
+
// Create a derived variable table with event context
|
|
140
|
+
let mut vt = variable_table.clone();
|
|
141
|
+
let mut ctx = std::collections::HashMap::new();
|
|
142
|
+
ctx.insert("name".to_string(), Value::String(event.clone()));
|
|
143
|
+
if let Some(arg_list) = args.clone() {
|
|
144
|
+
ctx.insert("args".to_string(), Value::Array(arg_list));
|
|
145
|
+
}
|
|
146
|
+
// Attach payload if any on the Emit statement value
|
|
147
|
+
ctx.insert("payload".to_string(), stmt.value.clone());
|
|
148
|
+
vt.set("event".to_string(), Value::Map(ctx));
|
|
149
|
+
// Mark we're inside an event handler to avoid re-scheduling periodic events recursively
|
|
150
|
+
vt.set("__in_event".to_string(), Value::Boolean(true));
|
|
151
|
+
|
|
152
|
+
let (_max, _cursor) = execute_audio_block(
|
|
153
|
+
audio_engine,
|
|
154
|
+
global_store,
|
|
155
|
+
vt,
|
|
156
|
+
functions_table.clone(),
|
|
157
|
+
body,
|
|
158
|
+
base_bpm,
|
|
159
|
+
base_duration,
|
|
160
|
+
max_end_time,
|
|
161
|
+
cursor_time,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
StatementKind::Let { .. } => {
|
|
168
|
+
if let Some(new_table) = interprete_let_statement(stmt, &mut variable_table) {
|
|
169
|
+
variable_table = new_table;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
StatementKind::Function { .. } => {
|
|
173
|
+
if let Some(new_functions) =
|
|
174
|
+
interprete_function_statement(stmt, &mut functions_table)
|
|
175
|
+
{
|
|
176
|
+
functions_table = new_functions;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
StatementKind::Tempo => {
|
|
180
|
+
if let Some((new_bpm, new_duration)) = interprete_tempo_statement(stmt) {
|
|
181
|
+
base_bpm = new_bpm;
|
|
182
|
+
base_duration = new_duration;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
StatementKind::Trigger { .. } => {
|
|
186
|
+
if let Some((new_cursor, new_max, _)) = interprete_trigger_statement(
|
|
187
|
+
stmt,
|
|
188
|
+
audio_engine,
|
|
189
|
+
&variable_table,
|
|
190
|
+
base_duration,
|
|
191
|
+
cursor_time,
|
|
192
|
+
max_end_time,
|
|
193
|
+
) {
|
|
194
|
+
cursor_time = new_cursor;
|
|
195
|
+
max_end_time = new_max;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
StatementKind::Sleep => {
|
|
199
|
+
let (new_cursor, new_max) =
|
|
200
|
+
interprete_sleep_statement(stmt, cursor_time, max_end_time);
|
|
201
|
+
cursor_time = new_cursor;
|
|
202
|
+
max_end_time = new_max;
|
|
203
|
+
}
|
|
204
|
+
StatementKind::Loop => {
|
|
205
|
+
let (new_max, new_cursor) = interprete_loop_statement(
|
|
206
|
+
stmt,
|
|
207
|
+
audio_engine,
|
|
208
|
+
global_store,
|
|
209
|
+
&variable_table,
|
|
210
|
+
&functions_table,
|
|
211
|
+
base_bpm,
|
|
212
|
+
base_duration,
|
|
213
|
+
max_end_time,
|
|
214
|
+
cursor_time,
|
|
215
|
+
);
|
|
216
|
+
cursor_time = new_cursor;
|
|
217
|
+
max_end_time = new_max;
|
|
218
|
+
}
|
|
219
|
+
StatementKind::Call { .. } => {
|
|
220
|
+
let (new_max, _) = interprete_call_statement(
|
|
221
|
+
stmt,
|
|
222
|
+
audio_engine,
|
|
223
|
+
&variable_table,
|
|
224
|
+
&functions_table,
|
|
225
|
+
global_store,
|
|
226
|
+
base_bpm,
|
|
227
|
+
base_duration,
|
|
228
|
+
max_end_time,
|
|
229
|
+
cursor_time,
|
|
230
|
+
);
|
|
231
|
+
cursor_time = new_max;
|
|
232
|
+
max_end_time = new_max;
|
|
233
|
+
}
|
|
234
|
+
StatementKind::ArrowCall { .. } => {
|
|
235
|
+
let (new_max, new_cursor) = interprete_call_arrow_statement(
|
|
236
|
+
stmt,
|
|
237
|
+
audio_engine,
|
|
238
|
+
&variable_table,
|
|
239
|
+
global_store,
|
|
240
|
+
base_bpm,
|
|
241
|
+
base_duration,
|
|
242
|
+
&mut max_end_time,
|
|
243
|
+
Some(&mut cursor_time),
|
|
244
|
+
true,
|
|
245
|
+
);
|
|
246
|
+
cursor_time = new_cursor;
|
|
247
|
+
|
|
248
|
+
if new_max > max_end_time {
|
|
249
|
+
max_end_time = new_max;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
StatementKind::Automate { .. } => {
|
|
253
|
+
if let Some(new_table) =
|
|
254
|
+
crate::core::audio::interpreter::automate::interprete_automate_statement(
|
|
255
|
+
stmt,
|
|
256
|
+
&mut variable_table,
|
|
257
|
+
)
|
|
258
|
+
{
|
|
259
|
+
variable_table = new_table;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
StatementKind::Print => {
|
|
263
|
+
// Only print in real-time mode (during playback), not during offline render.
|
|
264
|
+
let is_realtime = matches!(variable_table.get("__rt"), Some(Value::Boolean(true)));
|
|
265
|
+
if is_realtime {
|
|
266
|
+
let logger = Logger::new();
|
|
267
|
+
match &stmt.value {
|
|
268
|
+
Value::String(s) => {
|
|
269
|
+
let bpm = if let Some(Value::Number(n)) = variable_table.get("bpm") {
|
|
270
|
+
*n
|
|
271
|
+
} else {
|
|
272
|
+
120.0
|
|
273
|
+
};
|
|
274
|
+
let beat = if let Some(Value::Number(n)) = variable_table.get("beat") {
|
|
275
|
+
*n
|
|
276
|
+
} else {
|
|
277
|
+
0.0
|
|
278
|
+
};
|
|
279
|
+
// First try JS-like string concatenation: "str " + var + 1 + $env.*
|
|
280
|
+
if let Some(res) =
|
|
281
|
+
crate::core::audio::evaluator::evaluate_string_expression(
|
|
282
|
+
s,
|
|
283
|
+
&variable_table,
|
|
284
|
+
bpm,
|
|
285
|
+
beat,
|
|
286
|
+
)
|
|
287
|
+
{
|
|
288
|
+
logger.log_message(LogLevel::Print, &res);
|
|
289
|
+
} else if let Some(val) = variable_table.get(s) {
|
|
290
|
+
logger.log_message(LogLevel::Print, &format!("{:?}", val));
|
|
291
|
+
} else if s.contains("$env")
|
|
292
|
+
|| s.contains("$math")
|
|
293
|
+
|| s.parse::<f32>().is_ok()
|
|
294
|
+
{
|
|
295
|
+
let v = crate::core::audio::evaluator::evaluate_rhs_into_value(
|
|
296
|
+
s,
|
|
297
|
+
&variable_table,
|
|
298
|
+
bpm,
|
|
299
|
+
beat,
|
|
300
|
+
);
|
|
301
|
+
match v {
|
|
302
|
+
Value::Number(n) => {
|
|
303
|
+
logger.log_message(LogLevel::Print, &format!("{}", n));
|
|
304
|
+
}
|
|
305
|
+
_ => logger.log_message(LogLevel::Print, s),
|
|
306
|
+
}
|
|
307
|
+
} else {
|
|
308
|
+
logger.log_message(LogLevel::Print, s);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
Value::Number(n) => {
|
|
312
|
+
logger.log_message(LogLevel::Print, &format!("{}", n));
|
|
313
|
+
}
|
|
314
|
+
Value::Identifier(name) => {
|
|
315
|
+
if let Some(val) = variable_table.get(name) {
|
|
316
|
+
match val {
|
|
317
|
+
Value::Number(n) => {
|
|
318
|
+
logger.log_message(LogLevel::Print, &format!("{}", n));
|
|
319
|
+
}
|
|
320
|
+
Value::String(s) => logger.log_message(LogLevel::Print, s),
|
|
321
|
+
Value::Boolean(b) => {
|
|
322
|
+
logger.log_message(LogLevel::Print, &format!("{}", b));
|
|
323
|
+
}
|
|
324
|
+
other => {
|
|
325
|
+
logger
|
|
326
|
+
.log_message(LogLevel::Print, &format!("{:?}", other));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
logger.log_message(LogLevel::Print, name);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
v => logger.log_message(LogLevel::Print, &format!("{:?}", v)),
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
_ => {}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// Emit playhead event for UI bindings when building real-time playback
|
|
341
|
+
#[cfg(target_arch = "wasm32")]
|
|
342
|
+
{
|
|
343
|
+
emit_playhead(cursor_time, stmt.line, stmt.column);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// Execute parallel spawns (collect results)
|
|
348
|
+
let spawn_results: Vec<(AudioEngine, f32)> = spawns
|
|
349
|
+
.par_iter()
|
|
350
|
+
.map(|stmt| {
|
|
351
|
+
let mut local_engine = AudioEngine::new(audio_engine.module_name.clone());
|
|
352
|
+
let (spawn_max, _) = interprete_spawn_statement(
|
|
353
|
+
stmt,
|
|
354
|
+
&mut local_engine,
|
|
355
|
+
&variable_table,
|
|
356
|
+
&functions_table,
|
|
357
|
+
global_store,
|
|
358
|
+
base_bpm,
|
|
359
|
+
base_duration,
|
|
360
|
+
0.0,
|
|
361
|
+
0.0,
|
|
362
|
+
);
|
|
363
|
+
(local_engine, spawn_max)
|
|
364
|
+
})
|
|
365
|
+
.collect();
|
|
366
|
+
|
|
367
|
+
// Finally, merge results from all spawns
|
|
368
|
+
for (local_engine, spawn_max) in spawn_results {
|
|
369
|
+
audio_engine.merge_with(local_engine);
|
|
370
|
+
if spawn_max > max_end_time {
|
|
371
|
+
max_end_time = spawn_max;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Built-in periodic events (e.g., on beat(n), on bar(n))
|
|
376
|
+
// Emit handlers across the timeline up to max_end_time.
|
|
377
|
+
// If no audio was scheduled (max_end_time == 0.0), skip.
|
|
378
|
+
// Don't schedule periodic events if we're already inside an event handler
|
|
379
|
+
let in_event = matches!(variable_table.get("__in_event"), Some(Value::Boolean(true)));
|
|
380
|
+
let depth_is_root = matches!(variable_table.get("__depth"), Some(Value::Number(n)) if (*n - 1.0).abs() < f32::EPSILON);
|
|
381
|
+
if max_end_time > 0.0 && !in_event && depth_is_root && !global_store.events.is_empty() {
|
|
382
|
+
// Beat-based handlers (support "beat" and "$beat")
|
|
383
|
+
for ev_key in ["beat", "$beat"] {
|
|
384
|
+
if let Some(handlers) = global_store.get_event_handlers(ev_key) {
|
|
385
|
+
let mut seen: std::collections::HashSet<(usize, usize, usize)> =
|
|
386
|
+
std::collections::HashSet::new();
|
|
387
|
+
// Default every 1 beat if args missing
|
|
388
|
+
for h in handlers {
|
|
389
|
+
let key = (h.line, h.column, h.indent);
|
|
390
|
+
if !seen.insert(key) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
if let StatementKind::On { event, args, body } = &h.kind {
|
|
394
|
+
let every: f32 = args
|
|
395
|
+
.as_ref()
|
|
396
|
+
.and_then(|v| v.first())
|
|
397
|
+
.and_then(|x| {
|
|
398
|
+
match x {
|
|
399
|
+
Value::Number(n) => Some(*n),
|
|
400
|
+
Value::Identifier(s) => {
|
|
401
|
+
// Try to resolve from variables first, fallback to parsing the literal
|
|
402
|
+
match variable_table.get(s) {
|
|
403
|
+
Some(Value::Number(n)) => Some(*n),
|
|
404
|
+
_ => s.parse::<f32>().ok(),
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
_ => None,
|
|
408
|
+
}
|
|
409
|
+
})
|
|
410
|
+
.unwrap_or(1.0)
|
|
411
|
+
.max(0.0001);
|
|
412
|
+
let step = base_duration * every;
|
|
413
|
+
// Start from first full bar boundary after t=0
|
|
414
|
+
let mut t = step;
|
|
415
|
+
while t <= max_end_time {
|
|
416
|
+
// Prepare event context
|
|
417
|
+
let mut vt = variable_table.clone();
|
|
418
|
+
let mut ctx = std::collections::HashMap::new();
|
|
419
|
+
ctx.insert("name".to_string(), Value::String(event.clone()));
|
|
420
|
+
if let Some(a) = args.clone() {
|
|
421
|
+
ctx.insert("args".to_string(), Value::Array(a));
|
|
422
|
+
}
|
|
423
|
+
vt.set("event".to_string(), Value::Map(ctx));
|
|
424
|
+
vt.set("beat".to_string(), Value::Number(t / base_duration));
|
|
425
|
+
// Prevent nested scheduling
|
|
426
|
+
vt.set("__in_event".to_string(), Value::Boolean(true));
|
|
427
|
+
|
|
428
|
+
let (_m, _c) = execute_audio_block(
|
|
429
|
+
audio_engine,
|
|
430
|
+
global_store,
|
|
431
|
+
vt,
|
|
432
|
+
functions_table.clone(),
|
|
433
|
+
body,
|
|
434
|
+
base_bpm,
|
|
435
|
+
base_duration,
|
|
436
|
+
max_end_time,
|
|
437
|
+
t,
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
t += step;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Bar-based handlers (default 4/4 time => 4 beats per bar); support "bar" and "$bar"
|
|
448
|
+
for ev_key in ["bar", "$bar"] {
|
|
449
|
+
if let Some(handlers) = global_store.get_event_handlers(ev_key) {
|
|
450
|
+
let mut seen: std::collections::HashSet<(usize, usize, usize)> =
|
|
451
|
+
std::collections::HashSet::new();
|
|
452
|
+
for h in handlers {
|
|
453
|
+
let key = (h.line, h.column, h.indent);
|
|
454
|
+
if !seen.insert(key) {
|
|
455
|
+
continue;
|
|
456
|
+
}
|
|
457
|
+
if let StatementKind::On { event, args, body } = &h.kind {
|
|
458
|
+
let bar_beats = 4.0f32; // TODO: time signature support
|
|
459
|
+
let first_only = args.as_ref().and_then(|v| v.first()).is_none();
|
|
460
|
+
|
|
461
|
+
let every_bar: f32 = if first_only {
|
|
462
|
+
1.0
|
|
463
|
+
} else {
|
|
464
|
+
args.as_ref()
|
|
465
|
+
.and_then(|v| v.first())
|
|
466
|
+
.and_then(|x| match x {
|
|
467
|
+
Value::Number(n) => Some(*n),
|
|
468
|
+
Value::Identifier(s) => match variable_table.get(s) {
|
|
469
|
+
Some(Value::Number(n)) => Some(*n),
|
|
470
|
+
_ => s.parse::<f32>().ok(),
|
|
471
|
+
},
|
|
472
|
+
_ => None,
|
|
473
|
+
})
|
|
474
|
+
.unwrap_or(1.0)
|
|
475
|
+
.max(0.0001)
|
|
476
|
+
};
|
|
477
|
+
|
|
478
|
+
let step = base_duration * bar_beats * every_bar;
|
|
479
|
+
|
|
480
|
+
if first_only {
|
|
481
|
+
let t = step; // first full bar after t=0
|
|
482
|
+
if t <= max_end_time {
|
|
483
|
+
let mut vt = variable_table.clone();
|
|
484
|
+
let mut ctx = std::collections::HashMap::new();
|
|
485
|
+
ctx.insert("name".to_string(), Value::String(event.clone()));
|
|
486
|
+
if let Some(a) = args.clone() {
|
|
487
|
+
ctx.insert("args".to_string(), Value::Array(a));
|
|
488
|
+
}
|
|
489
|
+
vt.set("event".to_string(), Value::Map(ctx));
|
|
490
|
+
vt.set("beat".to_string(), Value::Number(t / base_duration));
|
|
491
|
+
// Prevent nested scheduling
|
|
492
|
+
vt.set("__in_event".to_string(), Value::Boolean(true));
|
|
493
|
+
|
|
494
|
+
let (_m, _c) = execute_audio_block(
|
|
495
|
+
audio_engine,
|
|
496
|
+
global_store,
|
|
497
|
+
vt,
|
|
498
|
+
functions_table.clone(),
|
|
499
|
+
body,
|
|
500
|
+
base_bpm,
|
|
501
|
+
base_duration,
|
|
502
|
+
max_end_time,
|
|
503
|
+
t,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
} else {
|
|
507
|
+
let mut t = step; // start from first full bar after t=0
|
|
508
|
+
while t <= max_end_time {
|
|
509
|
+
let mut vt = variable_table.clone();
|
|
510
|
+
let mut ctx = std::collections::HashMap::new();
|
|
511
|
+
ctx.insert("name".to_string(), Value::String(event.clone()));
|
|
512
|
+
if let Some(a) = args.clone() {
|
|
513
|
+
ctx.insert("args".to_string(), Value::Array(a));
|
|
514
|
+
}
|
|
515
|
+
vt.set("event".to_string(), Value::Map(ctx));
|
|
516
|
+
vt.set("beat".to_string(), Value::Number(t / base_duration));
|
|
517
|
+
// Prevent nested scheduling
|
|
518
|
+
vt.set("__in_event".to_string(), Value::Boolean(true));
|
|
519
|
+
|
|
520
|
+
let (_m, _c) = execute_audio_block(
|
|
521
|
+
audio_engine,
|
|
522
|
+
global_store,
|
|
523
|
+
vt,
|
|
524
|
+
functions_table.clone(),
|
|
525
|
+
body,
|
|
526
|
+
base_bpm,
|
|
527
|
+
base_duration,
|
|
528
|
+
max_end_time,
|
|
529
|
+
t,
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
t += step;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
(max_end_time.max(cursor_time), cursor_time)
|
|
542
|
+
}
|