diff --git a/Cargo.lock b/Cargo.lock index 6046a592..04ab34d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,6 +13,9 @@ dependencies = [ [[package]] name = "nih_plug" version = "0.1.0" +dependencies = [ + "vst3-sys", +] [[package]] name = "nih_plug_derive" @@ -56,3 +59,40 @@ name = "unicode-xid" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "vst3-com" +version = "0.1.0" +source = "git+https://github.com/RustAudio/vst3-sys.git#6ab2b43928588cdedcf499eecfc5a022e007dd76" +dependencies = [ + "vst3-com-macros", +] + +[[package]] +name = "vst3-com-macros" +version = "0.2.0" +source = "git+https://github.com/RustAudio/vst3-sys.git#6ab2b43928588cdedcf499eecfc5a022e007dd76" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "vst3-com-macros-support", +] + +[[package]] +name = "vst3-com-macros-support" +version = "0.2.0" +source = "git+https://github.com/RustAudio/vst3-sys.git#6ab2b43928588cdedcf499eecfc5a022e007dd76" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "vst3-sys" +version = "0.1.0" +source = "git+https://github.com/RustAudio/vst3-sys.git#6ab2b43928588cdedcf499eecfc5a022e007dd76" +dependencies = [ + "vst3-com", +] diff --git a/nih_plug/Cargo.toml b/nih_plug/Cargo.toml index aa890d97..f4ebbaef 100644 --- a/nih_plug/Cargo.toml +++ b/nih_plug/Cargo.toml @@ -6,3 +6,4 @@ authors = ["Robbert van der Helm "] license = "GPL-3.0-or-later" [dependencies] +vst3-sys = { git = "https://github.com/RustAudio/vst3-sys.git" } diff --git a/nih_plug/src/lib.rs b/nih_plug/src/lib.rs index a512a9cb..4e2d515d 100644 --- a/nih_plug/src/lib.rs +++ b/nih_plug/src/lib.rs @@ -18,3 +18,4 @@ pub mod debug; pub mod params; pub mod plugin; pub mod util; +pub mod wrapper; diff --git a/nih_plug/src/wrapper.rs b/nih_plug/src/wrapper.rs new file mode 100644 index 00000000..d98e01da --- /dev/null +++ b/nih_plug/src/wrapper.rs @@ -0,0 +1,20 @@ +// nih-plug: plugins, but rewritten in Rust +// Copyright (C) 2022 Robbert van der Helm +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Wrappers for different plugin types. Each wrapper has an entry point macro that you can pass the +//! name of a type that implements `Plugin` to. The macro will handle the rest. + +pub mod vst3; diff --git a/nih_plug/src/wrapper/vst3.rs b/nih_plug/src/wrapper/vst3.rs new file mode 100644 index 00000000..40d17f60 --- /dev/null +++ b/nih_plug/src/wrapper/vst3.rs @@ -0,0 +1,76 @@ +// nih-plug: plugins, but rewritten in Rust +// Copyright (C) 2022 Robbert van der Helm +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +//! Wrappers for different plugin types. Each wrapper has an entry point macro that you can pass the +//! name of a type that implements `Plugin` to. The macro will handle the rest. + +use std::pin::Pin; + +use crate::plugin::Plugin; + +pub struct Vst3Wrapper { + plugin: Pin>, +} + +// TODO: Come up with some way to hae Cargo spit out a VST3 module. Is that possible without a +// custom per-plugin build script? +#[macro_export] +macro_rules! nih_export_vst3 { + ($plugin_ty:ty) => { + // These two entry points are used on Linux, and they would theoretically also be used on + // the BSDs: + // https://github.com/steinbergmedia/vst3_public_sdk/blob/c3948deb407bdbff89de8fb6ab8500ea4df9d6d9/source/main/linuxmain.cpp#L47-L52 + #[no_mangle] + #[cfg(all(target_family = "unix", not(target_os = "macos")))] + pub extern "C" fn ModuleEntry(_lib_handle: *mut std::ffi::c_void) -> bool { + true + } + + #[no_mangle] + #[cfg(all(target_family = "unix", not(target_os = "macos")))] + pub extern "C" fn ModuleExit() -> bool { + true + } + + // These two entry points are used on macOS: + // https://github.com/steinbergmedia/vst3_public_sdk/blob/bc459feee68803346737901471441fd4829ec3f9/source/main/macmain.cpp#L60-L61 + #[no_mangle] + #[cfg(target_os = "macos")] + pub extern "C" fn bundleEntry(_lib_handle: *mut std::ffi::c_void) -> bool { + true + } + + #[no_mangle] + #[cfg(target_os = "macos")] + pub extern "C" fn bundleExit() -> bool { + true + } + + // And these two entry points are used on Windows: + // https://github.com/steinbergmedia/vst3_public_sdk/blob/bc459feee68803346737901471441fd4829ec3f9/source/main/dllmain.cpp#L59-L60 + #[no_mangle] + #[cfg(target_os = "windows")] + pub extern "system" fn InitModule() -> bool { + true + } + + #[no_mangle] + #[cfg(target_os = "windows")] + pub extern "system" fn DeinitModule() -> bool { + true + } + }; +} diff --git a/plugins/gain/src/lib.rs b/plugins/gain/src/lib.rs index 9228877c..15c61576 100644 --- a/plugins/gain/src/lib.rs +++ b/plugins/gain/src/lib.rs @@ -111,3 +111,5 @@ impl Plugin for Gain { } } } + +nih_export_vst3!(Gain);