@devaloop/devalang 0.0.1-beta.1 → 0.0.1-beta.2
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/.devalang +9 -10
- package/Cargo.toml +5 -4
- package/README.md +7 -5
- package/docs/CHANGELOG.md +42 -0
- package/docs/ROADMAP.md +5 -1
- package/docs/TODO.md +3 -14
- package/examples/bus.deva +10 -0
- package/examples/effect.deva +2 -0
- package/examples/filter.deva +11 -0
- package/examples/lfo.deva +9 -0
- package/examples/synth.deva +11 -1
- package/examples/synth_types.deva +17 -0
- package/out-tsc/core/functions/index.d.ts +5 -0
- package/out-tsc/core/functions/index.js +11 -0
- package/out-tsc/pkg/devalang_core.d.ts +2 -0
- package/out-tsc/pkg/devalang_core.js +17 -2
- package/out-tsc/pkg/devalang_core_bg.wasm.d.ts +8 -7
- package/package.json +1 -1
- package/project-version.json +3 -3
- package/rust/cli/bank/api.rs +122 -122
- package/rust/cli/bank/commands.rs +33 -2
- package/rust/cli/bank/mod.rs +29 -29
- package/rust/cli/build/commands.rs +53 -3
- package/rust/cli/build/mod.rs +2 -2
- package/rust/cli/build/process.rs +26 -7
- package/rust/cli/check/mod.rs +2 -2
- package/rust/cli/discover/commands.rs +253 -253
- package/rust/cli/discover/config.rs +111 -111
- package/rust/cli/discover/fs.rs +19 -19
- package/rust/cli/discover/install.rs +103 -103
- package/rust/cli/discover/metadata.rs +48 -48
- package/rust/cli/discover/mod.rs +5 -5
- package/rust/cli/install/addon.rs +118 -118
- package/rust/cli/install/bank.rs +22 -3
- package/rust/cli/install/commands.rs +35 -35
- package/rust/cli/install/mod.rs +4 -4
- package/rust/cli/install/plugin.rs +80 -61
- package/rust/cli/login/commands.rs +124 -124
- package/rust/cli/mod.rs +12 -12
- package/rust/cli/parser.rs +46 -1
- package/rust/cli/play/commands.rs +71 -20
- package/rust/cli/play/mod.rs +5 -5
- package/rust/cli/play/process.rs +14 -5
- package/rust/cli/play/realtime.rs +91 -91
- package/rust/cli/telemetry/commands.rs +22 -22
- package/rust/cli/telemetry/event_creator.rs +80 -80
- package/rust/cli/telemetry/mod.rs +3 -3
- package/rust/cli/telemetry/send.rs +51 -51
- package/rust/cli/template/commands.rs +69 -69
- package/rust/config/driver.rs +112 -103
- package/rust/config/mod.rs +3 -3
- package/rust/config/ops.rs +26 -26
- package/rust/config/settings.rs +101 -101
- package/rust/core/audio/engine/driver.rs +220 -0
- package/rust/core/audio/engine/export.rs +169 -0
- package/rust/core/audio/engine/helpers.rs +178 -170
- package/rust/core/audio/engine/mod.rs +51 -2
- package/rust/core/audio/engine/notes/dsp.rs +85 -0
- package/rust/core/audio/engine/notes/mod.rs +44 -0
- package/rust/core/audio/engine/notes/params.rs +294 -0
- package/rust/core/audio/engine/sample/insert.rs +199 -0
- package/rust/core/audio/engine/sample/mod.rs +40 -0
- package/rust/core/audio/engine/sample/padding.rs +170 -0
- package/rust/core/audio/evaluator/condition.rs +61 -0
- package/rust/core/audio/evaluator/mod.rs +9 -0
- package/rust/core/audio/{evaluator.rs → evaluator/numeric.rs} +1 -159
- package/rust/core/audio/evaluator/rhs.rs +16 -0
- package/rust/core/audio/evaluator/string_expr.rs +94 -0
- package/rust/core/audio/interpreter/driver.rs +55 -23
- package/rust/core/audio/interpreter/mod.rs +1 -13
- package/rust/core/audio/interpreter/statements/arrow_call/interprete.rs +175 -0
- package/rust/core/audio/interpreter/statements/arrow_call/methods/chord.rs +384 -0
- package/rust/core/audio/interpreter/statements/arrow_call/methods/mod.rs +2 -0
- package/rust/core/audio/interpreter/statements/arrow_call/methods/note.rs +316 -0
- package/rust/core/audio/interpreter/statements/arrow_call/mod.rs +3 -0
- package/rust/core/audio/interpreter/statements/arrow_call/types/arp.rs +192 -0
- package/rust/core/audio/interpreter/statements/arrow_call/types/mod.rs +24 -0
- package/rust/core/audio/interpreter/statements/arrow_call/types/pad.rs +116 -0
- package/rust/core/audio/interpreter/statements/arrow_call/types/pluck.rs +97 -0
- package/rust/core/audio/interpreter/statements/arrow_call/types/sub.rs +100 -0
- package/rust/core/audio/interpreter/{automate.rs → statements/automate.rs} +16 -18
- package/rust/core/audio/interpreter/{call.rs → statements/call.rs} +5 -4
- package/rust/core/audio/interpreter/{condition.rs → statements/condition.rs} +2 -1
- package/rust/core/audio/interpreter/{function.rs → statements/function.rs} +2 -4
- package/rust/core/audio/interpreter/{let_.rs → statements/let_.rs} +2 -4
- package/rust/core/audio/interpreter/{load.rs → statements/load.rs} +2 -4
- package/rust/core/audio/interpreter/{loop_.rs → statements/loop_.rs} +2 -1
- package/rust/core/audio/interpreter/statements/mod.rs +12 -0
- package/rust/core/audio/interpreter/{sleep.rs → statements/sleep.rs} +28 -28
- package/rust/core/audio/interpreter/{spawn.rs → statements/spawn.rs} +3 -2
- package/rust/core/audio/interpreter/{tempo.rs → statements/tempo.rs} +40 -40
- package/rust/core/audio/interpreter/{trigger.rs → statements/trigger.rs} +1 -1
- package/rust/core/audio/loader/trigger.rs +2 -1
- package/rust/core/audio/mod.rs +6 -7
- package/rust/core/audio/player.rs +70 -70
- package/rust/core/audio/special/easing.rs +189 -189
- package/rust/core/audio/special/env.rs +45 -45
- package/rust/core/audio/special/math.rs +134 -134
- package/rust/core/audio/special/mod.rs +9 -9
- package/rust/core/audio/special/modulator.rs +143 -143
- package/rust/core/builder/mod.rs +45 -2
- package/rust/core/debugger/lexer.rs +27 -27
- package/rust/core/debugger/{module.rs → logs.rs} +3 -6
- package/rust/core/debugger/mod.rs +30 -30
- package/rust/core/debugger/preprocessor.rs +27 -27
- package/rust/core/debugger/store.rs +2 -4
- package/rust/core/error/mod.rs +269 -269
- package/rust/core/lexer/driver.rs +59 -61
- package/rust/core/lexer/handler/arrow.rs +82 -82
- 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 -337
- package/rust/core/lexer/handler/identifier.rs +47 -47
- package/rust/core/lexer/handler/indent.rs +66 -66
- package/rust/core/lexer/handler/mod.rs +15 -15
- 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 -46
- package/rust/core/lexer/handler/parenthesis.rs +41 -41
- package/rust/core/lexer/handler/slash.rs +21 -21
- package/rust/core/lexer/handler/string.rs +63 -63
- package/rust/core/lexer/mod.rs +3 -3
- package/rust/core/mod.rs +0 -1
- package/rust/core/parser/driver/block.rs +111 -0
- package/rust/core/parser/driver/cursor.rs +82 -0
- package/rust/core/parser/driver/driver_impl.rs +139 -0
- package/rust/core/parser/driver/mod.rs +6 -0
- package/rust/core/parser/driver/parse_array.rs +120 -0
- package/rust/core/parser/driver/parse_map.rs +223 -0
- package/rust/core/parser/driver/parser.rs +160 -0
- package/rust/core/parser/handler/arrow_call.rs +28 -4
- package/rust/core/parser/handler/at.rs +279 -279
- package/rust/core/parser/handler/bank.rs +104 -104
- package/rust/core/parser/handler/condition.rs +83 -83
- package/rust/core/parser/handler/dot.rs +148 -148
- package/rust/core/parser/handler/identifier/automate.rs +254 -254
- package/rust/core/parser/handler/identifier/call.rs +91 -91
- package/rust/core/parser/handler/identifier/emit.rs +70 -70
- package/rust/core/parser/handler/identifier/function.rs +113 -113
- package/rust/core/parser/handler/identifier/group.rs +89 -89
- package/rust/core/parser/handler/identifier/let_.rs +173 -173
- package/rust/core/parser/handler/identifier/mod.rs +55 -55
- package/rust/core/parser/handler/identifier/on.rs +107 -107
- package/rust/core/parser/handler/identifier/print.rs +49 -49
- package/rust/core/parser/handler/identifier/sleep.rs +96 -43
- package/rust/core/parser/handler/identifier/spawn.rs +91 -91
- package/rust/core/parser/handler/identifier/synth.rs +135 -135
- package/rust/core/parser/handler/loop_.rs +194 -194
- package/rust/core/parser/handler/mod.rs +9 -9
- package/rust/core/parser/handler/pattern.rs +1 -1
- package/rust/core/parser/handler/tempo.rs +105 -57
- package/rust/core/parser/statement.rs +10 -11
- package/rust/core/plugin/loader.rs +1 -1
- package/rust/core/plugin/mod.rs +2 -2
- package/rust/core/plugin/runner/mod.rs +11 -0
- package/rust/core/plugin/{runner.rs → runner/non_wasm.rs} +297 -347
- package/rust/core/plugin/runner/wasm32.rs +43 -0
- package/rust/core/preprocessor/loader/inject.rs +278 -0
- package/rust/core/preprocessor/loader/loader_helpers.rs +110 -0
- package/rust/core/preprocessor/loader/mod.rs +235 -0
- package/rust/core/preprocessor/module.rs +2 -7
- package/rust/core/preprocessor/{processor.rs → processor/handlers.rs} +6 -13
- package/rust/core/preprocessor/processor/mod.rs +1 -0
- package/rust/core/preprocessor/resolver/bank.rs +49 -49
- package/rust/core/preprocessor/resolver/call.rs +124 -124
- package/rust/core/preprocessor/resolver/condition.rs +95 -95
- package/rust/core/preprocessor/resolver/driver.rs +324 -324
- package/rust/core/preprocessor/resolver/function.rs +2 -2
- package/rust/core/preprocessor/resolver/group.rs +46 -18
- package/rust/core/preprocessor/resolver/let_.rs +32 -32
- package/rust/core/preprocessor/resolver/loop_.rs +318 -318
- package/rust/core/preprocessor/resolver/mod.rs +16 -16
- package/rust/core/preprocessor/resolver/pattern.rs +83 -83
- package/rust/core/preprocessor/resolver/spawn.rs +99 -99
- package/rust/core/preprocessor/resolver/synth.rs +54 -54
- package/rust/core/preprocessor/resolver/tempo.rs +48 -48
- package/rust/core/preprocessor/resolver/trigger.rs +116 -116
- package/rust/core/preprocessor/resolver/value.rs +176 -176
- package/rust/core/store/global.rs +2 -6
- package/rust/core/store/mod.rs +1 -5
- package/rust/lib.rs +18 -3
- package/rust/main.rs +27 -3
- package/rust/types/Cargo.toml +1 -1
- package/rust/types/src/addons.rs +55 -55
- package/rust/types/src/config.rs +84 -74
- package/rust/types/src/lib.rs +15 -12
- package/rust/types/src/plugin.rs +20 -0
- package/rust/types/src/store.rs +139 -0
- package/rust/types/src/telemetry.rs +85 -85
- package/rust/utils/Cargo.toml +2 -2
- package/rust/utils/src/file.rs +94 -94
- package/rust/utils/src/first_usage.rs +97 -97
- package/rust/utils/src/lib.rs +9 -9
- package/rust/utils/src/logger.rs +200 -200
- package/rust/utils/src/path.rs +129 -88
- package/rust/utils/src/signature.rs +41 -41
- package/rust/utils/src/spinner.rs +20 -20
- package/rust/utils/src/version.rs +27 -27
- package/rust/utils/src/watcher.rs +46 -46
- package/rust/web/api.rs +5 -5
- package/rust/web/cdn.rs +34 -34
- package/rust/web/mod.rs +3 -3
- package/tests/integration.rs +21 -21
- package/typescript/core/functions/index.ts +11 -0
- package/typescript/pkg/devalang_core.ts +20 -4
- package/rust/core/audio/engine/sample.rs +0 -366
- package/rust/core/audio/engine/synth.rs +0 -325
- package/rust/core/audio/interpreter/arrow_call.rs +0 -311
- package/rust/core/audio/renderer.rs +0 -54
- package/rust/core/parser/driver.rs +0 -584
- package/rust/core/preprocessor/loader.rs +0 -637
- package/rust/core/store/export.rs +0 -28
- package/rust/core/store/function.rs +0 -40
- package/rust/core/store/import.rs +0 -28
- package/rust/core/store/variable.rs +0 -51
- package/rust/core/utils/mod.rs +0 -1
- package/rust/core/utils/path.rs +0 -37
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
use crate::core::audio::special::resolve_env_atom;
|
|
2
|
+
use devalang_types::Value;
|
|
3
|
+
use devalang_types::VariableTable;
|
|
4
|
+
|
|
5
|
+
pub fn evaluate_condition_string(expr: &str, vars: &VariableTable) -> bool {
|
|
6
|
+
let tokens: Vec<&str> = expr.split_whitespace().collect();
|
|
7
|
+
if tokens.len() != 3 {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let left = tokens[0];
|
|
12
|
+
let op = tokens[1];
|
|
13
|
+
let right = tokens[2];
|
|
14
|
+
|
|
15
|
+
// Resolve left and right to numeric values where possible. Accept numbers, variables or env atoms.
|
|
16
|
+
fn resolve_for_cond(s: &str, vars: &VariableTable) -> Option<f32> {
|
|
17
|
+
if let Ok(n) = s.parse::<f32>() {
|
|
18
|
+
return Some(n);
|
|
19
|
+
}
|
|
20
|
+
if let Some(Value::Number(n)) = vars.get(s) {
|
|
21
|
+
return Some(*n);
|
|
22
|
+
}
|
|
23
|
+
if let Some(v) = resolve_env_atom(s, 120.0, 1.0) {
|
|
24
|
+
return Some(v);
|
|
25
|
+
}
|
|
26
|
+
None
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let left_val = match resolve_for_cond(left, vars) {
|
|
30
|
+
Some(v) => v,
|
|
31
|
+
None => {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let right_val = match resolve_for_cond(right, vars) {
|
|
37
|
+
Some(v) => v,
|
|
38
|
+
None => {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
match op {
|
|
44
|
+
">" => left_val > right_val,
|
|
45
|
+
"<" => left_val < right_val,
|
|
46
|
+
">=" => left_val >= right_val,
|
|
47
|
+
"<=" => left_val <= right_val,
|
|
48
|
+
"==" => {
|
|
49
|
+
// relative epsilon for floating comparisons
|
|
50
|
+
let diff = (left_val - right_val).abs();
|
|
51
|
+
let largest = left_val.abs().max(right_val.abs()).max(1.0);
|
|
52
|
+
diff <= f32::EPSILON * largest
|
|
53
|
+
}
|
|
54
|
+
"!=" => {
|
|
55
|
+
let diff = (left_val - right_val).abs();
|
|
56
|
+
let largest = left_val.abs().max(right_val.abs()).max(1.0);
|
|
57
|
+
diff > f32::EPSILON * largest
|
|
58
|
+
}
|
|
59
|
+
_ => false,
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
pub mod condition;
|
|
2
|
+
pub mod numeric;
|
|
3
|
+
pub mod rhs;
|
|
4
|
+
pub mod string_expr;
|
|
5
|
+
|
|
6
|
+
pub use condition::evaluate_condition_string;
|
|
7
|
+
pub use numeric::evaluate_numeric_expression;
|
|
8
|
+
pub use rhs::evaluate_rhs_into_value;
|
|
9
|
+
pub use string_expr::evaluate_string_expression;
|
|
@@ -2,62 +2,8 @@ use crate::core::audio::special::{
|
|
|
2
2
|
find_and_eval_first_easing_call, find_and_eval_first_math_call, find_and_eval_first_mod_call,
|
|
3
3
|
resolve_env_atom,
|
|
4
4
|
};
|
|
5
|
-
use crate::core::store::variable::VariableTable;
|
|
6
5
|
use devalang_types::Value;
|
|
7
|
-
|
|
8
|
-
pub fn evaluate_condition_string(expr: &str, vars: &VariableTable) -> bool {
|
|
9
|
-
let tokens: Vec<&str> = expr.split_whitespace().collect();
|
|
10
|
-
if tokens.len() != 3 {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let left = tokens[0];
|
|
15
|
-
let op = tokens[1];
|
|
16
|
-
let right = tokens[2];
|
|
17
|
-
|
|
18
|
-
// Resolve left and right to numeric values where possible. Accept numbers, variables or env atoms.
|
|
19
|
-
fn resolve_for_cond(s: &str, vars: &VariableTable) -> Option<f32> {
|
|
20
|
-
if let Ok(n) = s.parse::<f32>() {
|
|
21
|
-
return Some(n);
|
|
22
|
-
}
|
|
23
|
-
if let Some(Value::Number(n)) = vars.get(s) {
|
|
24
|
-
return Some(*n);
|
|
25
|
-
}
|
|
26
|
-
if let Some(v) = resolve_env_atom(s, 120.0, 1.0) {
|
|
27
|
-
return Some(v);
|
|
28
|
-
}
|
|
29
|
-
None
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let left_val = match resolve_for_cond(left, vars) {
|
|
33
|
-
Some(v) => v,
|
|
34
|
-
None => return false,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
let right_val = match resolve_for_cond(right, vars) {
|
|
38
|
-
Some(v) => v,
|
|
39
|
-
None => return false,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
match op {
|
|
43
|
-
">" => left_val > right_val,
|
|
44
|
-
"<" => left_val < right_val,
|
|
45
|
-
">=" => left_val >= right_val,
|
|
46
|
-
"<=" => left_val <= right_val,
|
|
47
|
-
"==" => {
|
|
48
|
-
// relative epsilon for floating comparisons
|
|
49
|
-
let diff = (left_val - right_val).abs();
|
|
50
|
-
let largest = left_val.abs().max(right_val.abs()).max(1.0);
|
|
51
|
-
diff <= (f32::EPSILON * largest)
|
|
52
|
-
}
|
|
53
|
-
"!=" => {
|
|
54
|
-
let diff = (left_val - right_val).abs();
|
|
55
|
-
let largest = left_val.abs().max(right_val.abs()).max(1.0);
|
|
56
|
-
diff > (f32::EPSILON * largest)
|
|
57
|
-
}
|
|
58
|
-
_ => false,
|
|
59
|
-
}
|
|
60
|
-
}
|
|
6
|
+
use devalang_types::VariableTable;
|
|
61
7
|
|
|
62
8
|
// Very small expression evaluator for `$env.*`, `$math.*` and variables.
|
|
63
9
|
// Supports: +, -, *, / and simple parentheses, left-to-right (no precedence), and $math.(sin|cos)(expr)
|
|
@@ -204,107 +150,3 @@ pub fn evaluate_numeric_expression(
|
|
|
204
150
|
|
|
205
151
|
eval(&expr, vars, env_bpm, env_beat)
|
|
206
152
|
}
|
|
207
|
-
|
|
208
|
-
pub fn evaluate_rhs_into_value(
|
|
209
|
-
raw: &str,
|
|
210
|
-
vars: &VariableTable,
|
|
211
|
-
env_bpm: f32,
|
|
212
|
-
env_beat: f32,
|
|
213
|
-
) -> Value {
|
|
214
|
-
if let Some(num) = evaluate_numeric_expression(raw, vars, env_bpm, env_beat) {
|
|
215
|
-
Value::Number(num)
|
|
216
|
-
} else {
|
|
217
|
-
Value::String(raw.to_string())
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Evaluate a simple string concatenation expression like: "hello " + name + "!" + $env.beat
|
|
222
|
-
// - Splits on + outside quotes
|
|
223
|
-
// - Terms can be string literals (double quotes), variables (Number/String/Boolean), or numeric env/math expressions
|
|
224
|
-
// Returns None if parsing fails (fallback to raw print)
|
|
225
|
-
pub fn evaluate_string_expression(
|
|
226
|
-
expr: &str,
|
|
227
|
-
vars: &VariableTable,
|
|
228
|
-
env_bpm: f32,
|
|
229
|
-
env_beat: f32,
|
|
230
|
-
) -> Option<String> {
|
|
231
|
-
// Quick reject if no '+' present
|
|
232
|
-
if !expr.contains('+') {
|
|
233
|
-
return None;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Split by '+' outside of quotes
|
|
237
|
-
let mut parts: Vec<String> = Vec::new();
|
|
238
|
-
let mut cur = String::new();
|
|
239
|
-
let mut in_quotes = false;
|
|
240
|
-
let mut escape = false;
|
|
241
|
-
for ch in expr.chars() {
|
|
242
|
-
if escape {
|
|
243
|
-
cur.push(ch);
|
|
244
|
-
escape = false;
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if ch == '\\' {
|
|
248
|
-
// escape next char
|
|
249
|
-
escape = true;
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
if ch == '"' {
|
|
253
|
-
in_quotes = !in_quotes;
|
|
254
|
-
cur.push(ch);
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
if ch == '+' && !in_quotes {
|
|
258
|
-
parts.push(cur.to_string());
|
|
259
|
-
cur.clear();
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
cur.push(ch);
|
|
263
|
-
}
|
|
264
|
-
if !cur.is_empty() {
|
|
265
|
-
parts.push(cur.to_string());
|
|
266
|
-
}
|
|
267
|
-
if parts.is_empty() {
|
|
268
|
-
return None;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
// Resolve each part into a string
|
|
272
|
-
fn strip_quotes(s: &str) -> Option<String> {
|
|
273
|
-
let st = s.trim();
|
|
274
|
-
if st.len() >= 2 && st.starts_with('"') && st.ends_with('"') {
|
|
275
|
-
Some(st[1..st.len() - 1].to_string())
|
|
276
|
-
} else {
|
|
277
|
-
None
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
let mut out = String::new();
|
|
282
|
-
for p in parts {
|
|
283
|
-
if p.is_empty() {
|
|
284
|
-
continue;
|
|
285
|
-
}
|
|
286
|
-
if let Some(lit) = strip_quotes(&p) {
|
|
287
|
-
out.push_str(&lit);
|
|
288
|
-
continue;
|
|
289
|
-
}
|
|
290
|
-
// Try variables first
|
|
291
|
-
if let Some(val) = vars.get(&p) {
|
|
292
|
-
match val {
|
|
293
|
-
Value::String(s) => out.push_str(s),
|
|
294
|
-
Value::Number(n) => out.push_str(&format!("{}", n)),
|
|
295
|
-
Value::Boolean(b) => out.push_str(&format!("{}", b)),
|
|
296
|
-
other => out.push_str(&format!("{:?}", other)),
|
|
297
|
-
}
|
|
298
|
-
continue;
|
|
299
|
-
}
|
|
300
|
-
// Try env/math/numeric expression for this term
|
|
301
|
-
if let Some(n) = evaluate_numeric_expression(&p, vars, env_bpm, env_beat) {
|
|
302
|
-
out.push_str(&format!("{}", n));
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
// Bareword not resolved: include as-is (safe fallback)
|
|
306
|
-
out.push_str(&p);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
Some(out)
|
|
310
|
-
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
use crate::core::audio::evaluator::numeric::evaluate_numeric_expression;
|
|
2
|
+
use devalang_types::Value;
|
|
3
|
+
use devalang_types::VariableTable;
|
|
4
|
+
|
|
5
|
+
pub fn evaluate_rhs_into_value(
|
|
6
|
+
raw: &str,
|
|
7
|
+
vars: &VariableTable,
|
|
8
|
+
env_bpm: f32,
|
|
9
|
+
env_beat: f32,
|
|
10
|
+
) -> Value {
|
|
11
|
+
if let Some(num) = evaluate_numeric_expression(raw, vars, env_bpm, env_beat) {
|
|
12
|
+
Value::Number(num)
|
|
13
|
+
} else {
|
|
14
|
+
Value::String(raw.to_string())
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
use crate::core::audio::evaluator::numeric::evaluate_numeric_expression;
|
|
2
|
+
use devalang_types::Value;
|
|
3
|
+
use devalang_types::VariableTable;
|
|
4
|
+
|
|
5
|
+
// Evaluate a simple string concatenation expression like: "hello " + name + "!" + $env.beat
|
|
6
|
+
// - Splits on + outside quotes
|
|
7
|
+
// - Terms can be string literals (double quotes), variables (Number/String/Boolean), or numeric env/math expressions
|
|
8
|
+
// Returns None if parsing fails (fallback to raw print)
|
|
9
|
+
pub fn evaluate_string_expression(
|
|
10
|
+
expr: &str,
|
|
11
|
+
vars: &VariableTable,
|
|
12
|
+
env_bpm: f32,
|
|
13
|
+
env_beat: f32,
|
|
14
|
+
) -> Option<String> {
|
|
15
|
+
// Quick reject if no '+' present
|
|
16
|
+
if !expr.contains('+') {
|
|
17
|
+
return None;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Split by '+' outside of quotes
|
|
21
|
+
let mut parts: Vec<String> = Vec::new();
|
|
22
|
+
let mut cur = String::new();
|
|
23
|
+
let mut in_quotes = false;
|
|
24
|
+
let mut escape = false;
|
|
25
|
+
for ch in expr.chars() {
|
|
26
|
+
if escape {
|
|
27
|
+
cur.push(ch);
|
|
28
|
+
escape = false;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if ch == '\\' {
|
|
32
|
+
// escape next char
|
|
33
|
+
escape = true;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if ch == '"' {
|
|
37
|
+
in_quotes = !in_quotes;
|
|
38
|
+
cur.push(ch);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if ch == '+' && !in_quotes {
|
|
42
|
+
parts.push(cur.to_string());
|
|
43
|
+
cur.clear();
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
cur.push(ch);
|
|
47
|
+
}
|
|
48
|
+
if !cur.is_empty() {
|
|
49
|
+
parts.push(cur.to_string());
|
|
50
|
+
}
|
|
51
|
+
if parts.is_empty() {
|
|
52
|
+
return None;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Resolve each part into a string
|
|
56
|
+
fn strip_quotes(s: &str) -> Option<String> {
|
|
57
|
+
let st = s.trim();
|
|
58
|
+
if st.len() >= 2 && st.starts_with('"') && st.ends_with('"') {
|
|
59
|
+
Some(st[1..st.len() - 1].to_string())
|
|
60
|
+
} else {
|
|
61
|
+
None
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let mut out = String::new();
|
|
66
|
+
for p in parts {
|
|
67
|
+
if p.is_empty() {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if let Some(lit) = strip_quotes(&p) {
|
|
71
|
+
out.push_str(&lit);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
// Try variables first
|
|
75
|
+
if let Some(val) = vars.get(&p) {
|
|
76
|
+
match val {
|
|
77
|
+
Value::String(s) => out.push_str(s),
|
|
78
|
+
Value::Number(n) => out.push_str(&format!("{}", n)),
|
|
79
|
+
Value::Boolean(b) => out.push_str(&format!("{}", b)),
|
|
80
|
+
other => out.push_str(&format!("{:?}", other)),
|
|
81
|
+
}
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
// Try env/math/numeric expression for this term
|
|
85
|
+
if let Some(n) = evaluate_numeric_expression(&p, vars, env_bpm, env_beat) {
|
|
86
|
+
out.push_str(&format!("{}", n));
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
// Bareword not resolved: include as-is (safe fallback)
|
|
90
|
+
out.push_str(&p);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
Some(out)
|
|
94
|
+
}
|
|
@@ -5,22 +5,32 @@ use rayon::prelude::*;
|
|
|
5
5
|
use crate::core::{
|
|
6
6
|
audio::{
|
|
7
7
|
engine::AudioEngine,
|
|
8
|
-
interpreter::{
|
|
9
|
-
arrow_call::
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
interpreter::statements::{
|
|
9
|
+
arrow_call::interprete::interprete_arrow_call_statement,
|
|
10
|
+
call::interprete_call_statement, function::interprete_function_statement,
|
|
11
|
+
let_::interprete_let_statement, load::interprete_load_statement,
|
|
12
|
+
loop_::interprete_loop_statement, sleep::interprete_sleep_statement,
|
|
13
|
+
spawn::interprete_spawn_statement, tempo::interprete_tempo_statement,
|
|
14
|
+
trigger::interprete_trigger_statement,
|
|
14
15
|
},
|
|
15
16
|
},
|
|
16
17
|
parser::statement::{Statement, StatementKind},
|
|
17
|
-
store::
|
|
18
|
+
store::global::GlobalStore,
|
|
18
19
|
};
|
|
20
|
+
use devalang_types::{FunctionTable, VariableTable};
|
|
19
21
|
|
|
20
22
|
// WASM playhead callback support (only compiled for wasm32 target)
|
|
21
23
|
#[cfg(target_arch = "wasm32")]
|
|
22
24
|
use serde::Serialize;
|
|
23
25
|
|
|
26
|
+
#[cfg(target_arch = "wasm32")]
|
|
27
|
+
#[derive(Serialize, Clone)]
|
|
28
|
+
pub struct PlayheadEvent {
|
|
29
|
+
time: f32,
|
|
30
|
+
line: usize,
|
|
31
|
+
column: usize,
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
#[cfg(target_arch = "wasm32")]
|
|
25
35
|
use wasm_bindgen::prelude::JsValue;
|
|
26
36
|
|
|
@@ -30,28 +40,33 @@ use std::cell::RefCell;
|
|
|
30
40
|
#[cfg(target_arch = "wasm32")]
|
|
31
41
|
thread_local! {
|
|
32
42
|
static PLAYHEAD_CB: RefCell<Option<js_sys::Function>> = RefCell::new(None);
|
|
43
|
+
static PLAYHEAD_EVENTS: RefCell<Vec<PlayheadEvent>> = RefCell::new(Vec::new());
|
|
33
44
|
}
|
|
34
45
|
|
|
35
46
|
#[cfg(target_arch = "wasm32")]
|
|
36
47
|
pub fn register_playhead_callback(cb: js_sys::Function) {
|
|
37
|
-
PLAYHEAD_CB.with(|c|
|
|
48
|
+
PLAYHEAD_CB.with(|c| {
|
|
49
|
+
*c.borrow_mut() = Some(cb);
|
|
50
|
+
});
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
#[cfg(target_arch = "wasm32")]
|
|
41
54
|
pub fn unregister_playhead_callback() {
|
|
42
|
-
PLAYHEAD_CB.with(|c|
|
|
55
|
+
PLAYHEAD_CB.with(|c| {
|
|
56
|
+
*c.borrow_mut() = None;
|
|
57
|
+
});
|
|
43
58
|
}
|
|
44
59
|
|
|
45
60
|
#[cfg(target_arch = "wasm32")]
|
|
46
|
-
fn
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
time: f32,
|
|
50
|
-
line: usize,
|
|
51
|
-
column: usize,
|
|
52
|
-
}
|
|
61
|
+
pub fn collect_playhead_events() -> Vec<PlayheadEvent> {
|
|
62
|
+
PLAYHEAD_EVENTS.with(|c| c.borrow().clone())
|
|
63
|
+
}
|
|
53
64
|
|
|
65
|
+
#[cfg(target_arch = "wasm32")]
|
|
66
|
+
fn emit_playhead(time: f32, line: usize, column: usize) {
|
|
54
67
|
let ev = PlayheadEvent { time, line, column };
|
|
68
|
+
PLAYHEAD_EVENTS.with(|c| c.borrow_mut().push(ev.clone()));
|
|
69
|
+
|
|
55
70
|
if let Ok(v) = serde_wasm_bindgen::to_value(&ev) {
|
|
56
71
|
PLAYHEAD_CB.with(|c| {
|
|
57
72
|
if let Some(f) = c.borrow().as_ref() {
|
|
@@ -70,6 +85,13 @@ pub fn run_audio_program(
|
|
|
70
85
|
_module_functions: FunctionTable,
|
|
71
86
|
global_store: &mut GlobalStore,
|
|
72
87
|
) -> (f32, f32) {
|
|
88
|
+
// Clear any previously collected playhead events for wasm target so each
|
|
89
|
+
// run starts with an empty events buffer.
|
|
90
|
+
#[cfg(target_arch = "wasm32")]
|
|
91
|
+
{
|
|
92
|
+
PLAYHEAD_EVENTS.with(|c| c.borrow_mut().clear());
|
|
93
|
+
}
|
|
94
|
+
|
|
73
95
|
let base_bpm = 120.0;
|
|
74
96
|
let base_duration = 60.0 / base_bpm;
|
|
75
97
|
|
|
@@ -232,7 +254,7 @@ pub fn execute_audio_block(
|
|
|
232
254
|
max_end_time = new_max;
|
|
233
255
|
}
|
|
234
256
|
StatementKind::ArrowCall { .. } => {
|
|
235
|
-
let (new_max, new_cursor) =
|
|
257
|
+
let (new_max, new_cursor) = interprete_arrow_call_statement(
|
|
236
258
|
stmt,
|
|
237
259
|
audio_engine,
|
|
238
260
|
&variable_table,
|
|
@@ -250,11 +272,12 @@ pub fn execute_audio_block(
|
|
|
250
272
|
}
|
|
251
273
|
}
|
|
252
274
|
StatementKind::Automate { .. } => {
|
|
253
|
-
if
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
275
|
+
if
|
|
276
|
+
let Some(new_table) =
|
|
277
|
+
crate::core::audio::interpreter::statements::automate::interprete_automate_statement(
|
|
278
|
+
stmt,
|
|
279
|
+
&mut variable_table
|
|
280
|
+
)
|
|
258
281
|
{
|
|
259
282
|
variable_table = new_table;
|
|
260
283
|
}
|
|
@@ -338,9 +361,18 @@ pub fn execute_audio_block(
|
|
|
338
361
|
}
|
|
339
362
|
|
|
340
363
|
// Emit playhead event for UI bindings when building real-time playback
|
|
364
|
+
// Only emit for statements that are "playable" (i.e., schedule audio)
|
|
341
365
|
#[cfg(target_arch = "wasm32")]
|
|
342
366
|
{
|
|
343
|
-
|
|
367
|
+
if matches!(
|
|
368
|
+
stmt.kind,
|
|
369
|
+
StatementKind::Trigger { .. }
|
|
370
|
+
| StatementKind::Call { .. }
|
|
371
|
+
| StatementKind::Spawn { .. }
|
|
372
|
+
| StatementKind::Loop
|
|
373
|
+
) {
|
|
374
|
+
emit_playhead(cursor_time, stmt.line, stmt.column);
|
|
375
|
+
}
|
|
344
376
|
}
|
|
345
377
|
}
|
|
346
378
|
|
|
@@ -1,14 +1,2 @@
|
|
|
1
1
|
pub mod driver;
|
|
2
|
-
|
|
3
|
-
pub mod arrow_call;
|
|
4
|
-
pub mod automate;
|
|
5
|
-
pub mod call;
|
|
6
|
-
pub mod condition;
|
|
7
|
-
pub mod function;
|
|
8
|
-
pub mod let_;
|
|
9
|
-
pub mod load;
|
|
10
|
-
pub mod loop_;
|
|
11
|
-
pub mod sleep;
|
|
12
|
-
pub mod spawn;
|
|
13
|
-
pub mod tempo;
|
|
14
|
-
pub mod trigger;
|
|
2
|
+
pub mod statements;
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
use crate::core::{
|
|
2
|
+
audio::{
|
|
3
|
+
engine::AudioEngine,
|
|
4
|
+
interpreter::statements::arrow_call::methods::{
|
|
5
|
+
chord::interprete_chord_method, note::interprete_note_method,
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
parser::statement::{Statement, StatementKind},
|
|
9
|
+
store::global::GlobalStore,
|
|
10
|
+
};
|
|
11
|
+
use devalang_types::{Value, VariableTable};
|
|
12
|
+
use devalang_utils::logger::{LogLevel, Logger};
|
|
13
|
+
|
|
14
|
+
use std::collections::HashMap;
|
|
15
|
+
|
|
16
|
+
pub fn interprete_arrow_call_statement(
|
|
17
|
+
stmt: &Statement,
|
|
18
|
+
audio_engine: &mut AudioEngine,
|
|
19
|
+
variable_table: &VariableTable,
|
|
20
|
+
global_store: &GlobalStore,
|
|
21
|
+
base_bpm: f32,
|
|
22
|
+
base_duration: f32,
|
|
23
|
+
max_end_time: &mut f32,
|
|
24
|
+
cursor_time: Option<&mut f32>,
|
|
25
|
+
update_cursor: bool,
|
|
26
|
+
) -> (f32, f32) {
|
|
27
|
+
let cursor_copy = cursor_time.as_ref().map(|c| **c).unwrap_or(0.0);
|
|
28
|
+
|
|
29
|
+
if let StatementKind::ArrowCall {
|
|
30
|
+
target,
|
|
31
|
+
method,
|
|
32
|
+
args,
|
|
33
|
+
} = &stmt.kind
|
|
34
|
+
{
|
|
35
|
+
let Some(Value::Statement(synth_stmt)) = variable_table.get(target) else {
|
|
36
|
+
let logger = Logger::new();
|
|
37
|
+
logger.log_message(
|
|
38
|
+
LogLevel::Error,
|
|
39
|
+
&format!("Synth '{}' not found in variable table", target),
|
|
40
|
+
);
|
|
41
|
+
return (*max_end_time, cursor_copy);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let Value::Map(synth_map) = &synth_stmt.value else {
|
|
45
|
+
let logger = Logger::new();
|
|
46
|
+
logger.log_message(
|
|
47
|
+
LogLevel::Error,
|
|
48
|
+
&format!("Invalid synth statement for '{}', expected a map.", target),
|
|
49
|
+
);
|
|
50
|
+
return (*max_end_time, cursor_copy);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
let Some(Value::String(entity)) = synth_map.get("entity") else {
|
|
54
|
+
let logger = Logger::new();
|
|
55
|
+
logger.log_message(
|
|
56
|
+
LogLevel::Error,
|
|
57
|
+
&format!("Missing 'entity' key in synth '{}'.", target),
|
|
58
|
+
);
|
|
59
|
+
return (*max_end_time, cursor_copy);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if entity != "synth" {
|
|
63
|
+
let logger = Logger::new();
|
|
64
|
+
logger.log_message(
|
|
65
|
+
LogLevel::Error,
|
|
66
|
+
&format!("'{}' is not a synth, entity is '{}'.", target, entity),
|
|
67
|
+
);
|
|
68
|
+
return (*max_end_time, cursor_copy);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let Some(Value::Map(value_map)) = synth_map.get("value") else {
|
|
72
|
+
let logger = Logger::new();
|
|
73
|
+
logger.log_message(
|
|
74
|
+
LogLevel::Error,
|
|
75
|
+
&format!("Missing 'value' map in synth '{}'.", target),
|
|
76
|
+
);
|
|
77
|
+
return (*max_end_time, cursor_copy);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
let waveform_str = match value_map.get("waveform") {
|
|
81
|
+
Some(Value::String(s)) => s.clone(),
|
|
82
|
+
Some(Value::Identifier(s)) => s.clone(),
|
|
83
|
+
_ => {
|
|
84
|
+
let logger = Logger::new();
|
|
85
|
+
logger.log_message(
|
|
86
|
+
LogLevel::Error,
|
|
87
|
+
&format!("Missing or invalid 'waveform' in synth '{}'.", target),
|
|
88
|
+
);
|
|
89
|
+
return (*max_end_time, cursor_copy);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
let Some(Value::Map(params)) = value_map.get("parameters") else {
|
|
93
|
+
println!("❌ Missing or invalid 'parameters' in synth '{}'.", target);
|
|
94
|
+
return (*max_end_time, cursor_copy);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Synth parameters (mutable so we can apply type presets)
|
|
98
|
+
let mut synth_params = params.clone();
|
|
99
|
+
|
|
100
|
+
// Apply type defaults using the modular types module
|
|
101
|
+
crate::core::audio::interpreter::statements::arrow_call::types::apply_type(
|
|
102
|
+
&mut synth_params,
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
let amp = extract_f32(&synth_params, "amp", base_bpm).unwrap_or(1.0);
|
|
106
|
+
|
|
107
|
+
match method.as_str() {
|
|
108
|
+
"note" => {
|
|
109
|
+
return interprete_note_method(
|
|
110
|
+
args,
|
|
111
|
+
target,
|
|
112
|
+
audio_engine,
|
|
113
|
+
variable_table,
|
|
114
|
+
global_store,
|
|
115
|
+
&waveform_str,
|
|
116
|
+
&synth_params,
|
|
117
|
+
amp,
|
|
118
|
+
base_bpm,
|
|
119
|
+
base_duration,
|
|
120
|
+
max_end_time,
|
|
121
|
+
cursor_time,
|
|
122
|
+
cursor_copy,
|
|
123
|
+
update_cursor,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
"chord" => {
|
|
128
|
+
return interprete_chord_method(
|
|
129
|
+
args,
|
|
130
|
+
target,
|
|
131
|
+
audio_engine,
|
|
132
|
+
variable_table,
|
|
133
|
+
global_store,
|
|
134
|
+
&waveform_str,
|
|
135
|
+
&synth_params,
|
|
136
|
+
amp,
|
|
137
|
+
base_bpm,
|
|
138
|
+
base_duration,
|
|
139
|
+
max_end_time,
|
|
140
|
+
cursor_time,
|
|
141
|
+
cursor_copy,
|
|
142
|
+
update_cursor,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
_ => {
|
|
147
|
+
let logger = Logger::new();
|
|
148
|
+
logger.log_message(
|
|
149
|
+
LogLevel::Error,
|
|
150
|
+
&format!("Unknown method '{}' on synth '{}'.", method, target),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
(*max_end_time, cursor_copy)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
fn extract_f32(map: &HashMap<String, Value>, key: &str, base_bpm: f32) -> Option<f32> {
|
|
160
|
+
map.get(key).and_then(|v| match v {
|
|
161
|
+
Value::Number(n) => Some(*n),
|
|
162
|
+
Value::Beat(beat_str) => {
|
|
163
|
+
let parts: Vec<&str> = beat_str.split('/').collect();
|
|
164
|
+
if parts.len() == 2 {
|
|
165
|
+
let numerator = parts[0].parse::<f32>().ok()?;
|
|
166
|
+
let denominator = parts[1].parse::<f32>().ok()?;
|
|
167
|
+
|
|
168
|
+
Some((numerator / denominator) * ((60.0 / base_bpm) * 1000.0))
|
|
169
|
+
} else {
|
|
170
|
+
None
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
_ => None,
|
|
174
|
+
})
|
|
175
|
+
}
|