,
}
impl {
pub fn new() -> Box {
unsafe fn get_factory_info(&self, info: *mut vst3_sys::base::PFactoryInfo) -> tresult {
*info = mem::zeroed();
let info = &mut *info;
strlcpy(&mut info.vendor, P::VENDOR);
strlcpy(&mut info.url, P::URL);
strlcpy(&mut info.email, P::EMAIL);
info.flags = vst3_sys::base::FactoryFlags::kUnicode as i32;
kResultOk
}
unsafe fn count_classes(&self) -> i32 {
// We don't do shell plugins, and good of an idea having separated components and edit
// controllers in theory is, few software can use it, and doing that would make our simple
// microframework a lot less simple
1
}
unsafe fn get_class_info(&self, index: i32, info: *mut vst3_sys::base::PClassInfo) -> tresult {
if index != 0 {
return kInvalidArgument;
}
*info = mem::zeroed();
let info = &mut *info;
info.cid = self.cid;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class");
strlcpy(&mut info.name, P::NAME);
kResultOk
}
unsafe fn create_instance(
&self,
cid: *const vst3_sys::IID,
_iid: *const vst3_sys::IID,
obj: *mut *mut vst3_sys::c_void,
) -> tresult {
check_null_ptr!(cid, obj);
if *cid != self.cid {
return kNoInterface;
}
// XXX: Right now this `Arc` mostly serves to have clearer, safer interactions between the
// wrapper, the plugin, and the other behind the scene bits. The wrapper will still get
// freed using `FUnknown`'s internal reference count when the host drops it, so we
// actually need to leak this Arc here so it always stays at 1 reference or higher.
*obj = Arc::into_raw(Wrapper:: ::new()) as *mut vst3_sys::c_void;
kResultOk
}
}
impl {
unsafe fn get_class_info2(
&self,
index: i32,
info: *mut vst3_sys::base::PClassInfo2,
) -> tresult {
if index != 0 {
return kInvalidArgument;
}
*info = mem::zeroed();
let info = &mut *info;
info.cid = self.cid;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class");
strlcpy(&mut info.name, P::NAME);
info.class_flags = 1 << 1; // kSimpleModeSupported
strlcpy(&mut info.subcategories, P::VST3_CATEGORIES);
strlcpy(&mut info.vendor, P::VENDOR);
strlcpy(&mut info.version, P::VERSION);
strlcpy(&mut info.sdk_version, VST3_SDK_VERSION);
kResultOk
}
}
impl {
unsafe fn get_class_info_unicode(
&self,
index: i32,
info: *mut vst3_sys::base::PClassInfoW,
) -> tresult {
if index != 0 {
return kInvalidArgument;
}
*info = mem::zeroed();
let info = &mut *info;
info.cid = self.cid;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class");
u16strlcpy(&mut info.name, P::NAME);
info.class_flags = 1 << 1; // kSimpleModeSupported
strlcpy(&mut info.subcategories, P::VST3_CATEGORIES);
u16strlcpy(&mut info.vendor, P::VENDOR);
u16strlcpy(&mut info.version, P::VERSION);
u16strlcpy(&mut info.sdk_version, VST3_SDK_VERSION);
kResultOk
}
unsafe fn set_host_context(&self, _context: *mut c_void) -> tresult {
// We don't need to do anything with this
kResultOk
}
}
/// Export a VST3 plugin from this library using the provided plugin type.
#[macro_export]
macro_rules! nih_export_vst3 {
($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();
Box::into_raw(factory) as *mut ::std::ffi::c_void
}
// We don't need any special initialization logic, so all of these module entry point
// functions just return true all the time
// 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
}
};
}