1
0
Fork 0

Move VST3 categories and class ID to a new trait

Makes more sense than having this in either the general plugin trait or
as part of the macro.
This commit is contained in:
Robbert van der Helm 2022-01-27 22:13:13 +01:00
parent c11abdc77d
commit 217b28fdca
3 changed files with 34 additions and 21 deletions

View file

@ -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);

View file

@ -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 {

View file

@ -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<P: Plugin> IEditController for Wrapper<P> {
}
#[VST3(implements(IPluginFactory, IPluginFactory2, IPluginFactory3))]
pub struct Factory<P: Plugin> {
pub struct Factory<P: Vst3Plugin> {
/// 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<P: Plugin> {
_phantom: PhantomData<P>,
}
impl<P: Plugin> Factory<P> {
pub fn new(guid: GUID) -> Box<Self> {
Self::allocate(guid, PhantomData::default())
impl<P: Vst3Plugin> Factory<P> {
pub fn new() -> Box<Self> {
Self::allocate(
GUID {
data: P::VST3_CLASS_ID,
},
PhantomData::default(),
)
}
}
impl<P: Plugin> IPluginFactory for Factory<P> {
impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
unsafe fn get_factory_info(&self, info: *mut vst3_sys::base::PFactoryInfo) -> tresult {
*info = mem::zeroed();
@ -503,7 +508,7 @@ impl<P: Plugin> IPluginFactory for Factory<P> {
}
}
impl<P: Plugin> IPluginFactory2 for Factory<P> {
impl<P: Vst3Plugin> IPluginFactory2 for Factory<P> {
unsafe fn get_class_info2(
&self,
index: i32,
@ -530,7 +535,7 @@ impl<P: Plugin> IPluginFactory2 for Factory<P> {
}
}
impl<P: Plugin> IPluginFactory3 for Factory<P> {
impl<P: Vst3Plugin> IPluginFactory3 for Factory<P> {
unsafe fn get_class_info_unicode(
&self,
index: i32,
@ -562,19 +567,16 @@ impl<P: Plugin> IPluginFactory3 for Factory<P> {
}
}
/// 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
}