diff --git a/plugins/gain/src/lib.rs b/plugins/gain/src/lib.rs index 2ac82770..5105c7ad 100644 --- a/plugins/gain/src/lib.rs +++ b/plugins/gain/src/lib.rs @@ -19,7 +19,7 @@ extern crate nih_plug; use nih_plug::{ params::{FloatParam, Params, Range}, - plugin::{BufferConfig, BusConfig, Plugin, ProcessStatus}, + plugin::{BufferConfig, BusConfig, Plugin, ProcessStatus, Vst3Plugin}, util, }; use std::pin::Pin; @@ -67,7 +67,6 @@ impl Plugin for Gain { const EMAIL: &'static str = "info@example.com"; const VERSION: &'static str = "0.0.1"; - const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; const DEFAULT_NUM_INPUTS: u32 = 2; const DEFAULT_NUM_OUTPUTS: u32 = 2; @@ -121,4 +120,9 @@ impl Plugin for Gain { } } -nih_export_vst3!(Gain, *b"GainMoistestPlug"); +impl Vst3Plugin for Gain { + const VST3_CLASS_ID: [u8; 16] = *b"GainMoistestPlug"; + const VST3_CATEGORIES: &'static str = "Fx|Dynamics"; +} + +nih_export_vst3!(Gain); diff --git a/src/plugin.rs b/src/plugin.rs index ed2f7e2f..d2b50c7d 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -46,10 +46,6 @@ pub trait Plugin: Default + Sync { /// Semver compatible version string (e.g. `0.0.1`). Hosts likely won't do anything with this, /// but just in case they do this should only contain decimals values and dots. const VERSION: &'static str; - /// One or more categories, separated by pipe characters (`|`), up to 127 characters. Anything - /// logner than that will be truncated. See the VST3 SDK for examples of common categories: - /// https://github.com/steinbergmedia/vst3_pluginterfaces/blob/2ad397ade5b51007860bedb3b01b8afd2c5f6fba/vst/ivstaudioprocessor.h#L49-L90 - const VST3_CATEGORIES: &'static str; /// The default number of inputs. Some hosts like, like Bitwig and Ardour, use the defaults /// instead of setting up the busses properly. @@ -92,6 +88,17 @@ pub trait Plugin: Default + Sync { fn process(&mut self, samples: &mut [&mut [f32]]) -> ProcessStatus; } +/// Provides auxiliary metadata needed for a VST3 plugin. +pub trait Vst3Plugin: Plugin { + /// The unique class ID that identifies this particular plugin. You can use the + /// `*b"fooofooofooofooo"` syntax for this. + const VST3_CLASS_ID: [u8; 16]; + /// One or more categories, separated by pipe characters (`|`), up to 127 characters. Anything + /// logner than that will be truncated. See the VST3 SDK for examples of common categories: + /// https://github.com/steinbergmedia/vst3_pluginterfaces/blob/2ad397ade5b51007860bedb3b01b8afd2c5f6fba/vst/ivstaudioprocessor.h#L49-L90 + const VST3_CATEGORIES: &'static str; +} + /// We only support a single main input and output bus at the moment. #[derive(Debug, PartialEq, Eq)] pub struct BusConfig { diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 1047f0c0..5c38abe4 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -28,7 +28,7 @@ use vst3_sys::VST3; use widestring::U16CStr; use crate::params::ParamPtr; -use crate::plugin::{BusConfig, Plugin}; +use crate::plugin::{BusConfig, Plugin, Vst3Plugin}; use crate::wrapper::util::{hash_param_id, strlcpy, u16strlcpy}; // Alias needed for the VST3 attribute macro @@ -437,7 +437,7 @@ impl IEditController for Wrapper

{ } #[VST3(implements(IPluginFactory, IPluginFactory2, IPluginFactory3))] -pub struct Factory { +pub struct Factory { /// The exposed plugin's GUID. Instead of generating this, we'll just let the programmer decide /// on their own. cid: GUID, @@ -445,13 +445,18 @@ pub struct Factory { _phantom: PhantomData

, } -impl Factory

{ - pub fn new(guid: GUID) -> Box { - Self::allocate(guid, PhantomData::default()) +impl Factory

{ + pub fn new() -> Box { + Self::allocate( + GUID { + data: P::VST3_CLASS_ID, + }, + PhantomData::default(), + ) } } -impl IPluginFactory for Factory

{ +impl IPluginFactory for Factory

{ unsafe fn get_factory_info(&self, info: *mut vst3_sys::base::PFactoryInfo) -> tresult { *info = mem::zeroed(); @@ -503,7 +508,7 @@ impl IPluginFactory for Factory

{ } } -impl IPluginFactory2 for Factory

{ +impl IPluginFactory2 for Factory

{ unsafe fn get_class_info2( &self, index: i32, @@ -530,7 +535,7 @@ impl IPluginFactory2 for Factory

{ } } -impl IPluginFactory3 for Factory

{ +impl IPluginFactory3 for Factory

{ unsafe fn get_class_info_unicode( &self, index: i32, @@ -562,19 +567,16 @@ impl IPluginFactory3 for Factory

{ } } -/// Export a VST3 plugin from this library using the provided plugin type and a 4x4 character class -/// ID. This CID should be a `[u8; 16]`. You can use the `*b"fooofooofooofooo"` syntax for this. +/// Export a VST3 plugin from this library using the provided plugin type. /// /// 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, $cid:expr) => { + ($plugin_ty:ty) => { #[no_mangle] pub extern "system" fn GetPluginFactory() -> *mut ::std::ffi::c_void { - let factory = ::nih_plug::wrapper::vst3::Factory::<$plugin_ty>::new( - ::nih_plug::wrapper::vst3::GUID { data: $cid }, - ); + let factory = ::nih_plug::wrapper::vst3::Factory::<$plugin_ty>::new(); Box::into_raw(factory) as *mut ::std::ffi::c_void }