From 1e395274f699a6b89f0db9d90b523fd49e33e688 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Thu, 20 Jun 2024 20:40:08 +0300 Subject: [PATCH] wip: lv2 support? --- Cargo.lock | 108 ++++++++++++++++++++++++++++++++++++-- Cargo.toml | 1 + shell.nix | 5 ++ src/device/plugin.rs | 21 +++++--- src/device/plugin/lv2.rs | 17 ++++++ src/device/plugin/vst2.rs | 11 ++++ src/device/plugin/vst3.rs | 0 7 files changed, 153 insertions(+), 10 deletions(-) create mode 100644 src/device/plugin/lv2.rs create mode 100644 src/device/plugin/vst2.rs create mode 100644 src/device/plugin/vst3.rs diff --git a/Cargo.lock b/Cargo.lock index 1206d341..deeda854 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ dependencies = [ "crossterm_winapi", "libc", "mio", - "parking_lot", + "parking_lot 0.12.2", "signal-hook", "signal-hook-mio", "winapi", @@ -325,6 +325,15 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "instant" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" +dependencies = [ + "cfg-if", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -394,6 +403,40 @@ dependencies = [ "winapi", ] +[[package]] +name = "lilv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba8b5b9e4cc7a3f588377578868738c997eec13045ce31d727735181e425327a" +dependencies = [ + "lilv-sys", + "lv2_raw", + "parking_lot 0.11.2", + "pkg-config", +] + +[[package]] +name = "lilv-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aee56a6fdb8db62d01819f171d579c65fb0e03bcd077e1ea4509e06b6d58f53c" +dependencies = [ + "lv2_raw", +] + +[[package]] +name = "livi" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3a0c5cce0462040d482a75d2b3a7a4fa5593e9a2a4937167e1880ce6d941e43" +dependencies = [ + "lilv", + "log", + "lv2-sys", + "lv2_raw", + "ringbuf", +] + [[package]] name = "lock_api" version = "0.4.12" @@ -419,6 +462,21 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "lv2-sys" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9dd0f9e7de3649dcec348de51cbf611ab88688b97c0ce038f8c07b996b2a8e30" + +[[package]] +name = "lv2_raw" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "573ce7231f64fe795ad80134913f88f2e7f7f550527f6bd54d690a56cabf6a48" +dependencies = [ + "libc", +] + [[package]] name = "memchr" version = "2.7.2" @@ -506,6 +564,17 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "parking_lot" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core 0.8.6", +] + [[package]] name = "parking_lot" version = "0.12.2" @@ -513,7 +582,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.9.10", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" +dependencies = [ + "cfg-if", + "instant", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "winapi", ] [[package]] @@ -524,7 +607,7 @@ checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.1", "smallvec", "windows-targets 0.52.5", ] @@ -609,6 +692,15 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "redox_syscall" version = "0.5.1" @@ -618,6 +710,15 @@ dependencies = [ "bitflags 2.5.0", ] +[[package]] +name = "ringbuf" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79abed428d1fd2a128201cec72c5f6938e2da607c6f3745f769fabea399d950a" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "rustc-demangle" version = "0.1.24" @@ -782,6 +883,7 @@ dependencies = [ "clap", "crossterm", "jack", + "livi", "microxdg", "midly", "ratatui", diff --git a/Cargo.toml b/Cargo.toml index b23f5818..afbaef27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,3 +15,4 @@ midly = "0.5" vst = "0.4.0" #vst3 = "0.1.0" +livi = "0.7.4" diff --git a/shell.nix b/shell.nix index 47206151..2a4aa1c4 100644 --- a/shell.nix +++ b/shell.nix @@ -4,5 +4,10 @@ ]; buildInputs = with pkgs; [ jack2 + lilv + serd + libclang ]; + VST3_SDK_DIR = "/home/user/Lab/Music/tek/vst3sdk/"; + LIBCLANG_PATH = "${pkgs.libclang.lib.outPath}/lib"; } diff --git a/src/device/plugin.rs b/src/device/plugin.rs index 71d30efc..68d8f279 100644 --- a/src/device/plugin.rs +++ b/src/device/plugin.rs @@ -1,8 +1,18 @@ use crate::prelude::*; +mod lv2; +mod vst2; +mod vst3; + pub struct Plugin { name: String, - plugin: Option<::vst::host::PluginInstance> + plugin: Option +} + +enum PluginKind { + VST2(::vst::host::PluginInstance), + VST3, + LV2(::livi::Plugin), } impl Plugin { @@ -11,12 +21,9 @@ impl Plugin { name: name.into(), plugin: None, }); - let mut loader = ::vst::host::PluginLoader::load( - &std::path::Path::new("/nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lxvst/helm.so"), - device.state.clone() - )?; - let plugin = loader.instance()?; - device.state.lock().unwrap().plugin = Some(plugin); + device.state.lock().unwrap().plugin = Some(self::lv2::plug_in( + "file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lv2/helm.lv2" + )?); Ok(device) } } diff --git a/src/device/plugin/lv2.rs b/src/device/plugin/lv2.rs new file mode 100644 index 00000000..85e1ac17 --- /dev/null +++ b/src/device/plugin/lv2.rs @@ -0,0 +1,17 @@ +use crate::prelude::*; +use super::*; + +pub fn plug_in (path: &str) -> Usually { + let world = ::livi::World::with_load_bundle(&path); + world.build_features(::livi::FeaturesBuilder { + min_block_length: 1, + max_block_length: 65536, + }); + let mut plugin = None; + for p in world.iter_plugins() { + plugin = Some(p); + break + } + let result = PluginKind::LV2(plugin.unwrap()); + Ok(result) +} diff --git a/src/device/plugin/vst2.rs b/src/device/plugin/vst2.rs new file mode 100644 index 00000000..ea21520b --- /dev/null +++ b/src/device/plugin/vst2.rs @@ -0,0 +1,11 @@ +use crate::prelude::*; +use super::*; + +fn set_vst_plugin (host: &Arc>, path: &str) -> Usually { + let mut loader = ::vst::host::PluginLoader::load( + &std::path::Path::new("/nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lxvst/helm.so"), + host.clone() + )?; + Ok(PluginKind::VST2(loader.instance()?)) +} + //"file:///nix/store/ij3sz7nqg5l7v2dygdvzy3w6cj62bd6r-helm-0.9.0/lib/lxvst/helm.so" diff --git a/src/device/plugin/vst3.rs b/src/device/plugin/vst3.rs new file mode 100644 index 00000000..e69de29b