diff --git a/Cargo.lock b/Cargo.lock index db4580a..9c21c51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,56 +17,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.6.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys", -] - [[package]] name = "anyhow" version = "1.0.98" @@ -91,7 +41,7 @@ version = "0.0.2" dependencies = [ "anyhow", "bliplib", - "clap", + "constcat", "derive-new", "serde", "serde_json", @@ -161,50 +111,10 @@ dependencies = [ ] [[package]] -name = "clap" -version = "4.5.40" +name = "constcat" +version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40b6887a1d8685cebccf115538db5c0efe625ccac9696ad45c409d96566e910f" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c66c08ce9f0c698cbce5c0279d0bb6ac936d8674174fe48f736533b964f59e" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c7947ae4cc3d851207c1adb5b5e260ff0cca11446b1d6d1423788e442257ce" -dependencies = [ - "heck", - "proc-macro2 1.0.95", - "quote 1.0.40", - "syn 2.0.103", -] - -[[package]] -name = "clap_lex" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" +checksum = "136d3e02915a2cea4d74caa8681e2d44b1c3254bdbf17d11d41d587ff858832c" [[package]] name = "core-foundation-sys" @@ -427,12 +337,6 @@ dependencies = [ "serde", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" - [[package]] name = "itoa" version = "1.0.15" @@ -514,12 +418,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "once_cell_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" - [[package]] name = "powerfmt" version = "0.2.0" @@ -810,12 +708,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "wasm-bindgen" version = "0.2.100" @@ -932,76 +824,3 @@ checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ "windows-link", ] - -[[package]] -name = "windows-sys" -version = "0.59.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml index 24ab297..d5f4ee6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,14 +13,14 @@ name = "bliplab" [dependencies] anyhow = { version = "1", optional = true } bliplib = { version = "0.2.5", default-features = false } -clap = { version = "4.5", features = ["derive"], optional = true } +constcat = { version = "0.6.1", optional = true } derive-new = "0.7.0" serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", optional = true } serde_with = "3.13" [features] -bin = ["clap", "serde_json", "anyhow"] +bin = ["serde_json", "anyhow", "constcat"] [[bin]] name = "bliplab" diff --git a/example.json b/example.json new file mode 100644 index 0000000..ecd8298 --- /dev/null +++ b/example.json @@ -0,0 +1,33 @@ +{ + "global_variables": { + "absolute_length": "L", + "note_index": "n" + }, + "channels": { + "Piano": { + "input": { + "string": "hi" + }, + "notes": [ + "do", + "ré", + "mi" + ], + "instrument": "sin(2*pi()*(442*2^((n+1)/N))*t)", + "variables": { + "t": 0.0, + "L": 0.0, + "N": 12.0, + "l": 4.0, + "T": 60.0 + }, + "macros": {}, + "slopes": { + "L": { + "target": "L", + "change": "2^(2-log(2, l))*(60/T)" + } + } + } + } +} \ No newline at end of file diff --git a/src/cli/main.rs b/src/cli/main.rs index ae1c00a..94b574e 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -1,42 +1,28 @@ //! See [BLIPlab](https://docs.rs/bliplab) +use std::{env::args, fs::File}; + use anyhow::Context; -use bliplab::{Channel, PathOrString, Song, VariableChange}; +use bliplab::Song; +use constcat::concat; + +const TARGET: &str = "BLIP lab file"; fn main() -> anyhow::Result<()> { - let stringified = serde_json::to_string_pretty(&Song::new( - Default::default(), - [( - "Piano".into(), - Channel::new( - PathOrString::String("hi".into()), - vec!["do", "ré", "mi"].into_iter().map(Into::into), - "sin(2*pi()*(442*2^((n+1)/N))*t)" - .parse() - .context("failed to parse instrument expression")?, - [ - ('l', 4f64), - ('L', 0.0), - ('t', 0.0), - ('T', 60.0), - ('N', 12.0), - ], - [], - [( - "L".into(), - VariableChange::new( - 'L', - "2^(2-log(2, l))*(60/T)" - .parse() - .context("failed to parse length expression")?, - ), - )], - ), - )], - )) - .context("failed to serialize the song")?; + let song: Song = serde_json::from_reader( + File::open(args().skip(1).next().context(concat!( + "You need to give a single argument with the filename of your ", + TARGET, + "." + ))?) + .context(concat!("Failed to open the ", TARGET, "."))?, + ) + .context(concat!("Failed to read the ", TARGET, "."))?; - println!("{}", stringified); + println!( + "{}", + serde_json::to_string_pretty(&song).context("Failed to pretty print the song! What?!")? + ); Ok(()) }