@devaloop/devalang 0.0.1-alpha.16-hotfix.3 → 0.0.1-alpha.18
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 -10
- package/.github/workflows/ci.yml +0 -1
- package/Cargo.toml +18 -2
- package/README.md +82 -34
- package/docs/CHANGELOG.md +91 -0
- package/docs/ROADMAP.md +7 -4
- package/docs/TODO.md +1 -1
- package/examples/index.deva +55 -35
- package/examples/pattern.deva +5 -5
- package/out-tsc/bin/index.d.ts +2 -0
- 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 +41 -2
- package/out-tsc/pkg/devalang_core.d.ts +7 -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 +33 -23
- 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/index.d.ts +1 -0
- package/out-tsc/scripts/version/sync.d.ts +1 -0
- package/package.json +16 -4
- package/project-version.json +3 -3
- 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 +107 -0
- package/rust/cli/build/mod.rs +2 -0
- package/rust/cli/build/process.rs +146 -0
- package/rust/cli/{check.rs → check/mod.rs} +18 -31
- 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} +88 -87
- package/rust/cli/init/mod.rs +1 -0
- package/rust/cli/install/addon.rs +126 -0
- package/rust/cli/install/bank.rs +53 -0
- package/rust/cli/{install.rs → install/commands.rs} +9 -9
- package/rust/{installer → cli/install}/mod.rs +2 -3
- package/rust/cli/install/plugin.rs +61 -0
- package/rust/cli/{login.rs → login/commands.rs} +8 -11
- package/rust/cli/login/mod.rs +1 -0
- package/rust/cli/mod.rs +2 -2
- package/rust/cli/{driver.rs → parser.rs} +7 -2
- 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.rs → telemetry/commands.rs} +4 -4
- 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} +1 -1
- package/rust/cli/template/mod.rs +1 -0
- package/rust/cli/{update.rs → update/commands.rs} +6 -6
- package/rust/cli/update/mod.rs +1 -0
- package/rust/config/driver.rs +57 -72
- package/rust/config/mod.rs +1 -2
- package/rust/config/ops.rs +26 -0
- package/rust/config/settings.rs +40 -42
- package/rust/core/audio/engine/helpers.rs +158 -0
- package/rust/core/audio/engine/mod.rs +7 -0
- package/rust/core/audio/engine/sample.rs +359 -0
- package/rust/core/audio/engine/synth.rs +325 -0
- package/rust/core/audio/evaluator.rs +68 -27
- package/rust/core/audio/interpreter/arrow_call.rs +113 -33
- package/rust/core/audio/interpreter/call.rs +232 -56
- package/rust/core/audio/interpreter/condition.rs +3 -2
- package/rust/core/audio/interpreter/driver.rs +206 -151
- package/rust/core/audio/interpreter/let_.rs +1 -1
- package/rust/core/audio/interpreter/load.rs +2 -1
- package/rust/core/audio/interpreter/loop_.rs +7 -6
- package/rust/core/audio/interpreter/sleep.rs +2 -1
- package/rust/core/audio/interpreter/spawn.rs +186 -54
- package/rust/core/audio/interpreter/tempo.rs +31 -10
- package/rust/core/audio/interpreter/trigger.rs +2 -2
- package/rust/core/audio/loader/trigger.rs +4 -7
- package/rust/core/audio/player.rs +6 -0
- package/rust/core/audio/renderer.rs +5 -7
- package/rust/core/audio/special/env.rs +3 -1
- package/rust/core/audio/special/math.rs +26 -6
- package/rust/core/audio/special/modulator.rs +2 -2
- package/rust/core/builder/mod.rs +9 -3
- package/rust/core/debugger/lexer.rs +1 -1
- package/rust/core/debugger/mod.rs +6 -0
- package/rust/core/debugger/module.rs +4 -4
- package/rust/core/debugger/preprocessor.rs +1 -1
- package/rust/core/debugger/store.rs +2 -2
- package/rust/core/error/mod.rs +189 -0
- package/rust/core/lexer/driver.rs +61 -0
- package/rust/core/lexer/handler/arrow.rs +1 -1
- package/rust/core/lexer/handler/at.rs +1 -1
- package/rust/core/lexer/handler/brace.rs +2 -2
- package/rust/core/lexer/handler/colon.rs +1 -1
- package/rust/core/lexer/handler/comment.rs +1 -1
- package/rust/core/lexer/handler/dot.rs +1 -1
- package/rust/core/lexer/handler/driver.rs +1 -1
- package/rust/core/lexer/handler/identifier.rs +4 -3
- package/rust/core/lexer/handler/mod.rs +1 -2
- package/rust/core/lexer/handler/number.rs +1 -1
- package/rust/core/lexer/handler/operator.rs +1 -1
- package/rust/core/lexer/handler/parenthesis.rs +2 -2
- package/rust/core/lexer/handler/slash.rs +1 -1
- package/rust/core/lexer/handler/string.rs +1 -1
- package/rust/core/lexer/mod.rs +1 -52
- package/rust/core/lexer/token.rs +91 -97
- package/rust/core/mod.rs +0 -1
- package/rust/core/parser/driver.rs +78 -22
- package/rust/core/parser/handler/arrow_call.rs +28 -8
- package/rust/core/parser/handler/at.rs +55 -21
- package/rust/core/parser/handler/bank.rs +14 -4
- package/rust/core/parser/handler/condition.rs +6 -3
- package/rust/core/parser/handler/dot.rs +5 -3
- package/rust/core/parser/handler/identifier/automate.rs +13 -16
- package/rust/core/parser/handler/identifier/call.rs +4 -4
- package/rust/core/parser/handler/identifier/emit.rs +9 -5
- package/rust/core/parser/handler/identifier/function.rs +20 -7
- package/rust/core/parser/handler/identifier/group.rs +11 -7
- package/rust/core/parser/handler/identifier/let_.rs +24 -9
- package/rust/core/parser/handler/identifier/mod.rs +6 -5
- package/rust/core/parser/handler/identifier/on.rs +16 -7
- package/rust/core/parser/handler/identifier/print.rs +6 -9
- package/rust/core/parser/handler/identifier/sleep.rs +12 -5
- package/rust/core/parser/handler/identifier/spawn.rs +4 -4
- package/rust/core/parser/handler/identifier/synth.rs +79 -9
- package/rust/core/parser/handler/loop_.rs +38 -13
- package/rust/core/parser/handler/mod.rs +1 -0
- package/rust/core/parser/handler/pattern.rs +74 -0
- package/rust/core/parser/handler/tempo.rs +9 -5
- package/rust/core/parser/mod.rs +0 -1
- package/rust/core/parser/statement.rs +6 -137
- package/rust/core/plugin/loader.rs +41 -27
- package/rust/core/plugin/runner.rs +68 -17
- package/rust/core/preprocessor/loader.rs +181 -99
- package/rust/core/preprocessor/processor.rs +9 -9
- package/rust/core/preprocessor/resolver/bank.rs +6 -8
- package/rust/core/preprocessor/resolver/call.rs +47 -23
- package/rust/core/preprocessor/resolver/condition.rs +6 -8
- package/rust/core/preprocessor/resolver/driver.rs +28 -28
- package/rust/core/preprocessor/resolver/function.rs +6 -6
- package/rust/core/preprocessor/resolver/group.rs +6 -8
- package/rust/core/preprocessor/resolver/loop_.rs +8 -10
- package/rust/core/preprocessor/resolver/mod.rs +1 -0
- package/rust/core/preprocessor/resolver/pattern.rs +75 -0
- package/rust/core/preprocessor/resolver/spawn.rs +45 -22
- package/rust/core/preprocessor/resolver/synth.rs +6 -8
- package/rust/core/preprocessor/resolver/tempo.rs +6 -8
- package/rust/core/preprocessor/resolver/trigger.rs +22 -19
- package/rust/core/preprocessor/resolver/value.rs +99 -4
- package/rust/core/store/export.rs +28 -28
- package/rust/core/store/function.rs +6 -0
- package/rust/core/store/global.rs +7 -1
- package/rust/core/store/import.rs +28 -28
- package/rust/core/store/variable.rs +16 -2
- package/rust/core/utils/mod.rs +0 -1
- package/rust/lib.rs +102 -9
- package/rust/main.rs +159 -45
- 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/{error.rs → src/error.rs} +186 -200
- 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} +1 -1
- package/rust/utils/{logger.rs → src/logger.rs} +17 -12
- package/rust/utils/src/path.rs +88 -0
- package/rust/utils/src/signature.rs +41 -0
- package/rust/utils/{spinner.rs → src/spinner.rs} +3 -5
- package/rust/utils/src/version.rs +27 -0
- package/rust/utils/{watcher.rs → src/watcher.rs} +13 -1
- package/rust/web/cdn.rs +34 -0
- package/templates/minimal/README.md +98 -54
- package/templates/welcome/README.md +98 -54
- package/templates/welcome/src/index.deva +56 -8
- package/templates/welcome/src/variables.deva +2 -4
- package/tests/rust/TODO.md +0 -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 +1 -1
- 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 +7 -2
- package/typescript/pkg/devalang_core.d.ts +4 -0
- package/typescript/scripts/copy-wasm-dts.ts +41 -0
- package/rust/cli/bank.rs +0 -462
- package/rust/cli/build.rs +0 -252
- package/rust/cli/play.rs +0 -1123
- package/rust/common/cdn.rs +0 -5
- package/rust/config/loader.rs +0 -165
- package/rust/config/stats.rs +0 -257
- package/rust/core/audio/engine.rs +0 -696
- package/rust/core/shared/bank.rs +0 -21
- package/rust/core/shared/duration.rs +0 -9
- package/rust/core/shared/mod.rs +0 -3
- package/rust/core/shared/value.rs +0 -35
- package/rust/core/utils/validation.rs +0 -35
- package/rust/installer/addon.rs +0 -84
- package/rust/installer/bank.rs +0 -62
- package/rust/installer/plugin.rs +0 -54
- package/rust/installer/utils.rs +0 -56
- package/rust/utils/file.rs +0 -38
- package/rust/utils/first_usage.rs +0 -83
- package/rust/utils/signature.rs +0 -19
- package/rust/utils/telemetry.rs +0 -292
- package/rust/utils/version.rs +0 -15
- /package/rust/{common → web}/api.rs +0 -0
- /package/rust/{common → web}/mod.rs +0 -0
- /package/rust/{common → web}/sso.rs +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
use crate::config::settings::get_user_config;
|
|
2
|
+
use devalang_types::{
|
|
3
|
+
TelemetryErrorLevel as SharedTelemetryErrorLevel, TelemetryEvent as SharedTelemetryEvent,
|
|
4
|
+
};
|
|
5
|
+
use uuid::Uuid;
|
|
6
|
+
|
|
7
|
+
pub type TelemetryEvent = SharedTelemetryEvent;
|
|
8
|
+
pub type TelemetryErrorLevel = SharedTelemetryErrorLevel;
|
|
9
|
+
|
|
10
|
+
pub trait TelemetryEventExt {
|
|
11
|
+
fn set_timestamp(&mut self, timestamp: String);
|
|
12
|
+
fn set_duration(&mut self, duration: u64);
|
|
13
|
+
fn set_success(&mut self, success: bool);
|
|
14
|
+
fn set_error(
|
|
15
|
+
&mut self,
|
|
16
|
+
level: TelemetryErrorLevel,
|
|
17
|
+
message: Option<String>,
|
|
18
|
+
exit_code: Option<i32>,
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
impl TelemetryEventExt for SharedTelemetryEvent {
|
|
23
|
+
fn set_timestamp(&mut self, timestamp: String) {
|
|
24
|
+
self.timestamp = timestamp;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
fn set_duration(&mut self, duration: u64) {
|
|
28
|
+
self.duration = duration;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn set_success(&mut self, success: bool) {
|
|
32
|
+
self.success = success;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
fn set_error(
|
|
36
|
+
&mut self,
|
|
37
|
+
level: TelemetryErrorLevel,
|
|
38
|
+
message: Option<String>,
|
|
39
|
+
exit_code: Option<i32>,
|
|
40
|
+
) {
|
|
41
|
+
self.error_level = level;
|
|
42
|
+
self.error_message = message;
|
|
43
|
+
self.exit_code = exit_code;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
pub struct TelemetryEventCreator {
|
|
48
|
+
pub events: Vec<TelemetryEvent>,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
impl TelemetryEventCreator {
|
|
52
|
+
pub fn new() -> Self {
|
|
53
|
+
TelemetryEventCreator { events: Vec::new() }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
pub fn create_event(&mut self, event: TelemetryEvent) {
|
|
57
|
+
self.events.push(event.clone());
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
pub fn get_base_event(&self) -> TelemetryEvent {
|
|
61
|
+
let uuid = match get_user_config() {
|
|
62
|
+
Some(cfg) if !cfg.telemetry.uuid.is_empty() => cfg.telemetry.uuid.clone(),
|
|
63
|
+
_ => Uuid::new_v4().to_string(),
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
TelemetryEvent {
|
|
67
|
+
uuid,
|
|
68
|
+
cli_version: env!("CARGO_PKG_VERSION").to_string(),
|
|
69
|
+
os: std::env::consts::OS.to_string(),
|
|
70
|
+
command: std::env::args().collect::<Vec<_>>(),
|
|
71
|
+
project_info: None,
|
|
72
|
+
error_level: TelemetryErrorLevel::None,
|
|
73
|
+
error_message: None,
|
|
74
|
+
exit_code: None,
|
|
75
|
+
timestamp: chrono::Utc::now().to_string(),
|
|
76
|
+
duration: 0,
|
|
77
|
+
success: true,
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
use std::time::Duration;
|
|
2
|
+
|
|
3
|
+
use crate::{config::settings::get_user_config, web::api::get_api_url};
|
|
4
|
+
use devalang_types::{TelemetryEvent, TelemetrySendError};
|
|
5
|
+
|
|
6
|
+
pub async fn send_telemetry_event(event: &TelemetryEvent) -> Result<(), TelemetrySendError> {
|
|
7
|
+
if let Some(cfg) = get_user_config() {
|
|
8
|
+
if cfg.telemetry.enabled == false {
|
|
9
|
+
return Ok(());
|
|
10
|
+
}
|
|
11
|
+
} else {
|
|
12
|
+
return Ok(());
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let telemetry_url = format!("{}/v1/telemetry/send", get_api_url());
|
|
16
|
+
let client = reqwest::Client::builder()
|
|
17
|
+
.timeout(Duration::from_secs(5))
|
|
18
|
+
.build()
|
|
19
|
+
.map_err(|e| TelemetrySendError::Http(format!("client build error: {}", e)))?;
|
|
20
|
+
|
|
21
|
+
let mut last_err: Option<String> = None;
|
|
22
|
+
for (i, delay_ms) in [0u64, 250, 500, 1000].iter().enumerate() {
|
|
23
|
+
if *delay_ms > 0 {
|
|
24
|
+
tokio::time::sleep(Duration::from_millis(*delay_ms)).await;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let res = client
|
|
28
|
+
.post(telemetry_url.clone())
|
|
29
|
+
.json(event)
|
|
30
|
+
.send()
|
|
31
|
+
.await
|
|
32
|
+
.and_then(|r| r.error_for_status());
|
|
33
|
+
|
|
34
|
+
match res {
|
|
35
|
+
Ok(_) => {
|
|
36
|
+
return Ok(());
|
|
37
|
+
}
|
|
38
|
+
Err(err) => {
|
|
39
|
+
last_err = Some(err.to_string());
|
|
40
|
+
|
|
41
|
+
if i == 3 {
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
Err(TelemetrySendError::Http(
|
|
49
|
+
last_err.unwrap_or_else(|| "unknown error".to_string()),
|
|
50
|
+
))
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pub mod commands;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
pub async fn handle_update_command(
|
|
2
|
-
_only: Option<String>,
|
|
3
|
-
) -> Result<(), Box<dyn std::error::Error>> {
|
|
4
|
-
println!("Updates are not yet implemented.
|
|
5
|
-
Ok(())
|
|
6
|
-
}
|
|
1
|
+
pub async fn handle_update_command(
|
|
2
|
+
_only: Option<String>,
|
|
3
|
+
) -> Result<(), Box<dyn std::error::Error>> {
|
|
4
|
+
println!("Updates are not yet implemented.");
|
|
5
|
+
Ok(())
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pub mod commands;
|
package/rust/config/driver.rs
CHANGED
|
@@ -1,60 +1,45 @@
|
|
|
1
|
-
use
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
pub
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
pub path: String,
|
|
36
|
-
pub version: String,
|
|
37
|
-
pub author: String,
|
|
38
|
-
pub access: String,
|
|
1
|
+
use devalang_types::{
|
|
2
|
+
PluginEntry as SharedPluginEntry, ProjectConfig as SharedProjectConfig,
|
|
3
|
+
ProjectConfigBankEntry as SharedProjectConfigBankEntry,
|
|
4
|
+
ProjectConfigDefaults as SharedProjectConfigDefaults,
|
|
5
|
+
ProjectConfigPluginEntry as SharedProjectConfigPluginEntry,
|
|
6
|
+
};
|
|
7
|
+
use devalang_utils::path as path_utils;
|
|
8
|
+
use std::path::PathBuf;
|
|
9
|
+
|
|
10
|
+
pub type ProjectConfig = SharedProjectConfig;
|
|
11
|
+
pub type ProjectConfigDefaults = SharedProjectConfigDefaults;
|
|
12
|
+
pub type ProjectConfigBankEntry = SharedProjectConfigBankEntry;
|
|
13
|
+
pub type ProjectConfigPluginEntry = SharedProjectConfigPluginEntry;
|
|
14
|
+
pub type PluginEntry = SharedPluginEntry;
|
|
15
|
+
|
|
16
|
+
pub trait ProjectConfigExt {
|
|
17
|
+
fn new_config() -> Self;
|
|
18
|
+
fn with_defaults(
|
|
19
|
+
entry: Option<String>,
|
|
20
|
+
output: Option<String>,
|
|
21
|
+
watch: Option<bool>,
|
|
22
|
+
repeat: Option<bool>,
|
|
23
|
+
debug: Option<bool>,
|
|
24
|
+
compress: Option<bool>,
|
|
25
|
+
) -> Self;
|
|
26
|
+
fn get() -> Result<Self, String>
|
|
27
|
+
where
|
|
28
|
+
Self: Sized;
|
|
29
|
+
fn from_string(config_string: &str) -> Result<(Self, String), String>
|
|
30
|
+
where
|
|
31
|
+
Self: Sized;
|
|
32
|
+
fn write_config(&self, new_config: &Self) -> Result<(), String>
|
|
33
|
+
where
|
|
34
|
+
Self: Sized;
|
|
39
35
|
}
|
|
40
36
|
|
|
41
|
-
impl
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
defaults: ProjectConfigDefaults {
|
|
45
|
-
entry: None,
|
|
46
|
-
output: None,
|
|
47
|
-
watch: None,
|
|
48
|
-
repeat: None,
|
|
49
|
-
debug: None,
|
|
50
|
-
compress: None,
|
|
51
|
-
},
|
|
52
|
-
banks: Some(Vec::new()),
|
|
53
|
-
plugins: Some(Vec::new()),
|
|
54
|
-
}
|
|
37
|
+
impl ProjectConfigExt for SharedProjectConfig {
|
|
38
|
+
fn new_config() -> Self {
|
|
39
|
+
SharedProjectConfig::default()
|
|
55
40
|
}
|
|
56
41
|
|
|
57
|
-
|
|
42
|
+
fn with_defaults(
|
|
58
43
|
entry: Option<String>,
|
|
59
44
|
output: Option<String>,
|
|
60
45
|
watch: Option<bool>,
|
|
@@ -62,8 +47,8 @@ impl ProjectConfig {
|
|
|
62
47
|
debug: Option<bool>,
|
|
63
48
|
compress: Option<bool>,
|
|
64
49
|
) -> Self {
|
|
65
|
-
|
|
66
|
-
defaults:
|
|
50
|
+
SharedProjectConfig {
|
|
51
|
+
defaults: SharedProjectConfigDefaults {
|
|
67
52
|
entry,
|
|
68
53
|
output,
|
|
69
54
|
watch,
|
|
@@ -76,42 +61,42 @@ impl ProjectConfig {
|
|
|
76
61
|
}
|
|
77
62
|
}
|
|
78
63
|
|
|
79
|
-
|
|
80
|
-
let
|
|
81
|
-
let config_path = root.join(".devalang");
|
|
82
|
-
|
|
83
|
-
if config_path.try_exists().is_err() {
|
|
84
|
-
return Err(format!(
|
|
85
|
-
"Config file not found at path: {}",
|
|
86
|
-
config_path.display()
|
|
87
|
-
));
|
|
88
|
-
}
|
|
64
|
+
fn get() -> Result<Self, String> {
|
|
65
|
+
let config_path = path_utils::get_devalang_config_path()?;
|
|
89
66
|
|
|
90
67
|
let config_content = std::fs::read_to_string(&config_path)
|
|
91
68
|
.map_err(|e| format!("Failed to read config file: {}", e))?;
|
|
92
69
|
|
|
93
|
-
let config:
|
|
70
|
+
let config: SharedProjectConfig = toml::from_str(&config_content)
|
|
94
71
|
.map_err(|e| format!("Failed to parse config file: {}", e))?;
|
|
95
72
|
|
|
96
73
|
Ok(config)
|
|
97
74
|
}
|
|
98
75
|
|
|
99
|
-
|
|
100
|
-
let config:
|
|
76
|
+
fn from_string(config_string: &str) -> Result<(Self, String), String> {
|
|
77
|
+
let config: SharedProjectConfig = toml::from_str(config_string)
|
|
101
78
|
.map_err(|e| format!("Failed to parse config string: {}", e))?;
|
|
102
79
|
let config_path = ".devalang".to_string();
|
|
103
80
|
|
|
104
81
|
Ok((config, config_path))
|
|
105
82
|
}
|
|
106
83
|
|
|
107
|
-
|
|
108
|
-
let config_path =
|
|
84
|
+
fn write_config(&self, new_config: &Self) -> Result<(), String> {
|
|
85
|
+
let config_path: PathBuf = match path_utils::get_project_root() {
|
|
86
|
+
Ok(root) => root.join(path_utils::DEVALANG_CONFIG),
|
|
87
|
+
Err(_) => PathBuf::from(path_utils::DEVALANG_CONFIG),
|
|
88
|
+
};
|
|
109
89
|
|
|
110
90
|
let content = toml::to_string(new_config)
|
|
111
91
|
.map_err(|e| format!("Failed to serialize config: {}", e))?;
|
|
112
92
|
|
|
113
|
-
std::fs::write(config_path, content)
|
|
114
|
-
|
|
93
|
+
std::fs::write(&config_path, content).map_err(|e| {
|
|
94
|
+
format!(
|
|
95
|
+
"Failed to write config to file '{}': {}",
|
|
96
|
+
config_path.display(),
|
|
97
|
+
e
|
|
98
|
+
)
|
|
99
|
+
})?;
|
|
115
100
|
|
|
116
101
|
Ok(())
|
|
117
102
|
}
|
package/rust/config/mod.rs
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
use crate::config::driver::ProjectConfig;
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
pub fn load_config(path: Option<&Path>) -> Option<ProjectConfig> {
|
|
6
|
+
let config_path_buf;
|
|
7
|
+
let config_path = match path {
|
|
8
|
+
Some(p) => p,
|
|
9
|
+
None => {
|
|
10
|
+
config_path_buf = match devalang_utils::path::get_devalang_config_path() {
|
|
11
|
+
Ok(p) => p,
|
|
12
|
+
Err(_) => {
|
|
13
|
+
return None;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
&config_path_buf
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
if config_path.exists() {
|
|
21
|
+
let content = fs::read_to_string(config_path).ok()?;
|
|
22
|
+
toml::from_str(&content).ok()
|
|
23
|
+
} else {
|
|
24
|
+
None
|
|
25
|
+
}
|
|
26
|
+
}
|
package/rust/config/settings.rs
CHANGED
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
use
|
|
1
|
+
use devalang_types::{TelemetrySettings, UserSettings};
|
|
2
|
+
use serde_json::Value as JsonValue;
|
|
2
3
|
use std::io::Write;
|
|
3
4
|
|
|
4
|
-
#[derive(Serialize, Deserialize, Default, Debug)]
|
|
5
|
-
pub struct UserSettings {
|
|
6
|
-
pub session: String,
|
|
7
|
-
pub telemetry: TelemetrySettings,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
#[derive(Serialize, Deserialize, Default, Debug)]
|
|
11
|
-
pub struct TelemetrySettings {
|
|
12
|
-
pub uuid: String,
|
|
13
|
-
pub stats: bool,
|
|
14
|
-
pub level: String,
|
|
15
|
-
pub enabled: bool,
|
|
16
|
-
}
|
|
17
|
-
|
|
18
5
|
pub fn get_home_dir() -> Option<std::path::PathBuf> {
|
|
19
6
|
dirs::home_dir()
|
|
20
7
|
}
|
|
@@ -32,9 +19,9 @@ pub fn get_default_user_config() -> UserSettings {
|
|
|
32
19
|
session: "".into(),
|
|
33
20
|
telemetry: TelemetrySettings {
|
|
34
21
|
uuid: uuid::Uuid::new_v4().to_string(),
|
|
35
|
-
enabled:
|
|
22
|
+
enabled: false,
|
|
36
23
|
level: "basic".into(),
|
|
37
|
-
stats:
|
|
24
|
+
stats: false,
|
|
38
25
|
},
|
|
39
26
|
}
|
|
40
27
|
}
|
|
@@ -53,51 +40,62 @@ pub fn write_user_config_file() {
|
|
|
53
40
|
if let Some(config_path) = get_devalang_homedir().join("config.json").into() {
|
|
54
41
|
let settings = get_user_config().unwrap_or_else(get_default_user_config);
|
|
55
42
|
|
|
56
|
-
let mut file = std::fs::File::create(config_path).unwrap();
|
|
57
43
|
let config_json = serde_json::to_string(&settings).unwrap();
|
|
58
44
|
|
|
59
|
-
|
|
45
|
+
if let Err(e) = write_config_atomic(&config_path, &config_json) {
|
|
46
|
+
println!("Could not write config file: {}", e);
|
|
47
|
+
}
|
|
60
48
|
} else {
|
|
61
49
|
println!("Could not create config file");
|
|
62
50
|
}
|
|
63
51
|
}
|
|
64
52
|
|
|
65
|
-
pub fn
|
|
53
|
+
pub fn ensure_user_config_file_exists() {
|
|
54
|
+
if let Some(config_path) = get_devalang_homedir().join("config.json").into() {
|
|
55
|
+
if !config_path.exists() {
|
|
56
|
+
write_user_config_file();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pub fn set_user_config_value(key: &str, value: JsonValue) {
|
|
66
62
|
let mut settings = get_user_config().unwrap_or_default();
|
|
67
63
|
|
|
68
|
-
match key {
|
|
69
|
-
"telemetry" => {
|
|
70
|
-
settings.telemetry.enabled =
|
|
64
|
+
match (key, &value) {
|
|
65
|
+
("telemetry", JsonValue::Bool(b)) => {
|
|
66
|
+
settings.telemetry.enabled = *b;
|
|
67
|
+
}
|
|
68
|
+
("session", JsonValue::String(s)) => {
|
|
69
|
+
settings.session = s.clone();
|
|
70
|
+
}
|
|
71
|
+
_ => {
|
|
72
|
+
println!("Unsupported key or value type for '{}': {:?}", key, value);
|
|
71
73
|
}
|
|
72
|
-
_ => {}
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
if let Some(config_path) = get_devalang_homedir().join("config.json").into() {
|
|
76
77
|
let config_json = serde_json::to_string(&settings).unwrap();
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
if let Err(e) = write_config_atomic(&config_path, &config_json) {
|
|
79
|
+
println!("Could not write config file: {}", e);
|
|
80
|
+
}
|
|
80
81
|
} else {
|
|
81
82
|
println!("Could not create config file");
|
|
82
83
|
}
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
pub fn
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
_ => {}
|
|
86
|
+
pub fn write_config_atomic(
|
|
87
|
+
config_path: &std::path::PathBuf,
|
|
88
|
+
contents: &str,
|
|
89
|
+
) -> std::io::Result<()> {
|
|
90
|
+
if let Some(parent) = config_path.parent() {
|
|
91
|
+
std::fs::create_dir_all(parent)?;
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
let tmp_path = config_path.with_extension("json.tmp");
|
|
95
|
+
let mut tmp_file = std::fs::File::create(&tmp_path)?;
|
|
96
|
+
tmp_file.write_all(contents.as_bytes())?;
|
|
97
|
+
tmp_file.sync_all()?;
|
|
98
|
+
std::fs::rename(&tmp_path, config_path)?;
|
|
98
99
|
|
|
99
|
-
|
|
100
|
-
} else {
|
|
101
|
-
println!("Could not create config file");
|
|
102
|
-
}
|
|
100
|
+
Ok(())
|
|
103
101
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
use devalang_types::Value;
|
|
2
|
+
use std::collections::HashMap;
|
|
3
|
+
|
|
4
|
+
type OptMap = Option<HashMap<String, Value>>;
|
|
5
|
+
|
|
6
|
+
pub fn env_maps_from_automation(
|
|
7
|
+
automation: &Option<HashMap<String, Value>>,
|
|
8
|
+
) -> (OptMap, OptMap, OptMap) {
|
|
9
|
+
if let Some(auto) = automation {
|
|
10
|
+
let vol = match auto.get("volume") {
|
|
11
|
+
Some(Value::Map(m)) => Some(m.clone()),
|
|
12
|
+
_ => None,
|
|
13
|
+
};
|
|
14
|
+
let pan = match auto.get("pan") {
|
|
15
|
+
Some(Value::Map(m)) => Some(m.clone()),
|
|
16
|
+
_ => None,
|
|
17
|
+
};
|
|
18
|
+
let pit = match auto.get("pitch") {
|
|
19
|
+
Some(Value::Map(m)) => Some(m.clone()),
|
|
20
|
+
_ => None,
|
|
21
|
+
};
|
|
22
|
+
(vol, pan, pit)
|
|
23
|
+
} else {
|
|
24
|
+
(None, None, None)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pub fn eval_env_map(
|
|
29
|
+
env_opt: &Option<HashMap<String, Value>>,
|
|
30
|
+
progress: f32,
|
|
31
|
+
default_val: f32,
|
|
32
|
+
) -> f32 {
|
|
33
|
+
let env = match env_opt {
|
|
34
|
+
Some(m) => m,
|
|
35
|
+
None => {
|
|
36
|
+
return default_val;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
let mut points: Vec<(f32, f32)> = Vec::with_capacity(env.len());
|
|
40
|
+
for (k, v) in env.iter() {
|
|
41
|
+
let key = if k.ends_with('%') {
|
|
42
|
+
&k[..k.len() - 1]
|
|
43
|
+
} else {
|
|
44
|
+
&k[..]
|
|
45
|
+
};
|
|
46
|
+
if let Ok(mut p) = key.parse::<f32>() {
|
|
47
|
+
p = (p / 100.0).clamp(0.0, 1.0);
|
|
48
|
+
let val = match v {
|
|
49
|
+
Value::Number(n) => *n,
|
|
50
|
+
Value::String(s) => s.parse::<f32>().unwrap_or(default_val),
|
|
51
|
+
Value::Identifier(s) => s.parse::<f32>().unwrap_or(default_val),
|
|
52
|
+
_ => default_val,
|
|
53
|
+
};
|
|
54
|
+
points.push((p, val));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if points.is_empty() {
|
|
58
|
+
return default_val;
|
|
59
|
+
}
|
|
60
|
+
points.sort_by(|a, b| a.0.partial_cmp(&b.0).unwrap());
|
|
61
|
+
let t = progress.clamp(0.0, 1.0);
|
|
62
|
+
if t <= points[0].0 {
|
|
63
|
+
return points[0].1;
|
|
64
|
+
}
|
|
65
|
+
if t >= points[points.len() - 1].0 {
|
|
66
|
+
return points[points.len() - 1].1;
|
|
67
|
+
}
|
|
68
|
+
for w in points.windows(2) {
|
|
69
|
+
let (p0, v0) = w[0];
|
|
70
|
+
let (p1, v1) = w[1];
|
|
71
|
+
if t >= p0 && t <= p1 {
|
|
72
|
+
let ratio = if (p1 - p0).abs() < f32::EPSILON {
|
|
73
|
+
0.0
|
|
74
|
+
} else {
|
|
75
|
+
(t - p0) / (p1 - p0)
|
|
76
|
+
};
|
|
77
|
+
return v0 + (v1 - v0) * ratio;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
default_val
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
pub fn oscillator_sample(waveform: &str, current_freq: f32, t: f32) -> f32 {
|
|
84
|
+
let phase = 2.0 * std::f32::consts::PI * current_freq * t;
|
|
85
|
+
match waveform {
|
|
86
|
+
"sine" => phase.sin(),
|
|
87
|
+
"square" => {
|
|
88
|
+
if phase.sin() >= 0.0 {
|
|
89
|
+
1.0
|
|
90
|
+
} else {
|
|
91
|
+
-1.0
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
"saw" => 2.0 * (current_freq * t - (current_freq * t + 0.5).floor()),
|
|
95
|
+
"triangle" => (2.0 * (2.0 * (current_freq * t).fract() - 1.0)).abs() * 2.0 - 1.0,
|
|
96
|
+
_ => 0.0,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
pub fn adsr_envelope_value(
|
|
101
|
+
i: usize,
|
|
102
|
+
attack_samples: usize,
|
|
103
|
+
decay_samples: usize,
|
|
104
|
+
sustain_samples: usize,
|
|
105
|
+
release_samples: usize,
|
|
106
|
+
sustain_level: f32,
|
|
107
|
+
) -> f32 {
|
|
108
|
+
let attack_start = 0usize;
|
|
109
|
+
let decay_start = attack_samples;
|
|
110
|
+
let sustain_start = attack_samples + decay_samples;
|
|
111
|
+
let release_start = attack_samples + decay_samples + sustain_samples;
|
|
112
|
+
|
|
113
|
+
if i < attack_start + attack_samples && attack_samples > 0 {
|
|
114
|
+
let k = i - attack_start;
|
|
115
|
+
let denom = if attack_samples > 1 { (attack_samples - 1) as f32 } else { 1.0 };
|
|
116
|
+
(k as f32) / denom
|
|
117
|
+
} else if i < decay_start + decay_samples && decay_samples > 0 {
|
|
118
|
+
let k = i - decay_start;
|
|
119
|
+
let denom = if decay_samples > 1 { (decay_samples - 1) as f32 } else { 1.0 };
|
|
120
|
+
let ratio = (k as f32) / denom;
|
|
121
|
+
1.0 - (1.0 - sustain_level) * ratio
|
|
122
|
+
} else if i < sustain_start + sustain_samples {
|
|
123
|
+
sustain_level
|
|
124
|
+
} else if release_samples > 0 {
|
|
125
|
+
// release: interpolate from sustain_level down to 0 inclusive
|
|
126
|
+
let k = i.saturating_sub(release_start);
|
|
127
|
+
let denom = if release_samples > 1 { (release_samples - 1) as f32 } else { 1.0 };
|
|
128
|
+
let ratio = (k as f32) / denom;
|
|
129
|
+
let val = sustain_level * (1.0 - ratio);
|
|
130
|
+
if val < 0.0 { 0.0 } else { val }
|
|
131
|
+
} else {
|
|
132
|
+
0.0
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
pub fn pan_gains(pan_val: f32) -> (f32, f32) {
|
|
137
|
+
let left_gain = 1.0 - pan_val.max(0.0);
|
|
138
|
+
let right_gain = 1.0 + pan_val.min(0.0);
|
|
139
|
+
(left_gain, right_gain)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
pub fn mix_stereo_samples_into_buffer(
|
|
143
|
+
engine: &mut super::synth::AudioEngine,
|
|
144
|
+
start_sample: usize,
|
|
145
|
+
channels: usize,
|
|
146
|
+
stereo_samples: &[i16],
|
|
147
|
+
) {
|
|
148
|
+
let offset = start_sample * channels;
|
|
149
|
+
let required_len = offset + stereo_samples.len();
|
|
150
|
+
|
|
151
|
+
if engine.buffer.len() < required_len {
|
|
152
|
+
engine.buffer.resize(required_len, 0);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (i, sample) in stereo_samples.iter().enumerate() {
|
|
156
|
+
engine.buffer[offset + i] = engine.buffer[offset + i].saturating_add(*sample);
|
|
157
|
+
}
|
|
158
|
+
}
|