Add the glue code to call Bliss functions and return JS values
This commit is contained in:
parent
b4d5019d83
commit
5fd2ef3902
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
target
|
target
|
||||||
node_modules
|
node_modules
|
||||||
|
index.node
|
||||||
|
|
55
Cargo.lock
generated
55
Cargo.lock
generated
|
@ -244,7 +244,7 @@ checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"libc",
|
"libc",
|
||||||
"libloading 0.7.4",
|
"libloading",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -693,16 +693,6 @@ version = "0.2.151"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libloading"
|
|
||||||
version = "0.6.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"winapi 0.3.9",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libloading"
|
name = "libloading"
|
||||||
version = "0.7.4"
|
version = "0.7.4"
|
||||||
|
@ -845,45 +835,29 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "neon"
|
name = "neon"
|
||||||
version = "0.10.1"
|
version = "1.0.0-alpha.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28e15415261d880aed48122e917a45e87bb82cf0260bb6db48bbab44b7464373"
|
checksum = "8687031acf51f8b065aaf906b5a694f8d6b547c5c9430b6d636ab42422bfd0cc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"neon-build",
|
"libloading",
|
||||||
"neon-macros",
|
"neon-macros",
|
||||||
"neon-runtime",
|
"once_cell",
|
||||||
"semver",
|
"semver",
|
||||||
|
"send_wrapper",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "neon-build"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8bac98a702e71804af3dacfde41edde4a16076a7bbe889ae61e56e18c5b1c811"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "neon-macros"
|
name = "neon-macros"
|
||||||
version = "0.10.1"
|
version = "1.0.0-alpha.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b7288eac8b54af7913c60e0eb0e2a7683020dffa342ab3fd15e28f035ba897cf"
|
checksum = "facd664405d5140677a63d7b7c5762425dd9d4179e07d2e67da29089c50b1ddd"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quote",
|
"quote",
|
||||||
"syn 1.0.109",
|
"syn 1.0.109",
|
||||||
"syn-mid",
|
"syn-mid",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "neon-runtime"
|
|
||||||
version = "0.10.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4676720fa8bb32c64c3d9f49c47a47289239ec46b4bdb66d0913cc512cb0daca"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"libloading 0.6.7",
|
|
||||||
"smallvec",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "noisy_float"
|
name = "noisy_float"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -1373,18 +1347,15 @@ checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver"
|
name = "semver"
|
||||||
version = "0.9.0"
|
version = "1.0.20"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
|
||||||
dependencies = [
|
|
||||||
"semver-parser",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "semver-parser"
|
name = "send_wrapper"
|
||||||
version = "0.7.0"
|
version = "0.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
|
|
|
@ -69,7 +69,7 @@ anyhow = { version = "1.0.58", optional = true }
|
||||||
indicatif = { version = "0.17.0", optional = true }
|
indicatif = { version = "0.17.0", optional = true }
|
||||||
|
|
||||||
[dependencies.neon]
|
[dependencies.neon]
|
||||||
version = "0.10.1"
|
version = "1.0.0-alpha.4"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["napi-6", "channel-api", "promise-api", "try-catch-api"]
|
features = ["napi-6", "channel-api", "promise-api", "try-catch-api"]
|
||||||
|
|
||||||
|
|
BIN
index.node
BIN
index.node
Binary file not shown.
27
src/lib.rs
27
src/lib.rs
|
@ -10,15 +10,32 @@ mod temporal;
|
||||||
mod timbral;
|
mod timbral;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
use neon::prelude::*;
|
use neon::{prelude::*, types::buffer::TypedArray};
|
||||||
|
use song::Song;
|
||||||
|
|
||||||
#[neon::main]
|
#[neon::main]
|
||||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||||
cx.export_function("test", test)?;
|
cx.export_function("analyze", analyze)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test(mut cx: FunctionContext) -> JsResult<JsNumber> {
|
/// Returns a Uint8Array, with the first 2 bytes being the version in platform endianness
|
||||||
Ok(cx.number(34))
|
/// and the rest (currently 80 bytes) being the analysis data in little endian
|
||||||
|
fn analyze(mut cx: FunctionContext) -> JsResult<JsUint8Array> {
|
||||||
|
let path = cx.argument::<JsString>(0)?.value(&mut cx);
|
||||||
|
let song = Song::from_path(path)
|
||||||
|
.or_else(|e| cx.throw_error(e.to_string()))?;
|
||||||
|
let version_bytes = song.features_version.to_ne_bytes();
|
||||||
|
let analysis_bytes = song.analysis.as_bytes();
|
||||||
|
|
||||||
|
let mut buffer_handle = JsUint8Array::new(
|
||||||
|
&mut cx,
|
||||||
|
analysis_bytes.len() + version_bytes.len(),
|
||||||
|
)?;
|
||||||
|
let buffer = buffer_handle.as_mut_slice(&mut cx);
|
||||||
|
|
||||||
|
buffer[0..version_bytes.len()].copy_from_slice(&version_bytes);
|
||||||
|
buffer[version_bytes.len()..].copy_from_slice(&analysis_bytes);
|
||||||
|
|
||||||
|
Ok(buffer_handle)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user