1
0
Fork 0

Fix VST3 CID consistency between platforms

This commit is contained in:
Robbert van der Helm 2022-02-10 21:30:39 +01:00
parent a83cbf8aca
commit 6e1f7930e3
2 changed files with 33 additions and 4 deletions

View file

@ -121,11 +121,40 @@ pub trait Plugin: Default + Send + Sync + 'static {
pub trait Vst3Plugin: Plugin { pub trait Vst3Plugin: Plugin {
/// The unique class ID that identifies this particular plugin. You can use the /// The unique class ID that identifies this particular plugin. You can use the
/// `*b"fooofooofooofooo"` syntax for this. /// `*b"fooofooofooofooo"` syntax for this.
///
/// This will be shuffled into a different byte order on Windows for project-compatibility.
const VST3_CLASS_ID: [u8; 16]; const VST3_CLASS_ID: [u8; 16];
/// One or more categories, separated by pipe characters (`|`), up to 127 characters. Anything /// 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: /// 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> /// <https://github.com/steinbergmedia/vst3_pluginterfaces/blob/2ad397ade5b51007860bedb3b01b8afd2c5f6fba/vst/ivstaudioprocessor.h#L49-L90>
const VST3_CATEGORIES: &'static str; const VST3_CATEGORIES: &'static str;
/// [Self::VST3_CLASS_ID] in the correct order for the current platform so projects and presets
/// can be shared between platforms. This should not be overridden.
const PLATFORM_VST3_CLASS_ID: [u8; 16] = swap_vst3_uid_byte_order(Self::VST3_CLASS_ID);
}
#[cfg(not(target_os = "windows"))]
const fn swap_vst3_uid_byte_order(uid: [u8; 16]) -> [u8; 16] {
uid
}
#[cfg(target_os = "windows")]
const fn swap_vst3_uid_byte_order(mut uid: [u8; 16]) -> [u8; 16] {
// No mutable references in const functions, so we can't use `uid.swap()`
let original_uid = uid;
uid[0] = original_uid[3];
uid[1] = original_uid[2];
uid[2] = original_uid[1];
uid[3] = original_uid[0];
uid[4] = original_uid[5];
uid[5] = original_uid[4];
uid[6] = original_uid[7];
uid[7] = original_uid[6];
uid
} }
/// An editor for a [Plugin]. /// An editor for a [Plugin].

View file

@ -72,7 +72,7 @@ impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
*info = mem::zeroed(); *info = mem::zeroed();
let info = &mut *info; let info = &mut *info;
info.cid.data = P::VST3_CLASS_ID; info.cid.data = P::PLATFORM_VST3_CLASS_ID;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32; info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class"); strlcpy(&mut info.category, "Audio Module Class");
strlcpy(&mut info.name, P::NAME); strlcpy(&mut info.name, P::NAME);
@ -88,7 +88,7 @@ impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
) -> tresult { ) -> tresult {
check_null_ptr!(cid, obj); check_null_ptr!(cid, obj);
if (*cid).data != P::VST3_CLASS_ID { if (*cid).data != P::PLATFORM_VST3_CLASS_ID {
return kNoInterface; return kNoInterface;
} }
@ -111,7 +111,7 @@ impl<P: Vst3Plugin> IPluginFactory2 for Factory<P> {
*info = mem::zeroed(); *info = mem::zeroed();
let info = &mut *info; let info = &mut *info;
info.cid.data = P::VST3_CLASS_ID; info.cid.data = P::PLATFORM_VST3_CLASS_ID;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32; info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class"); strlcpy(&mut info.category, "Audio Module Class");
strlcpy(&mut info.name, P::NAME); strlcpy(&mut info.name, P::NAME);
@ -138,7 +138,7 @@ impl<P: Vst3Plugin> IPluginFactory3 for Factory<P> {
*info = mem::zeroed(); *info = mem::zeroed();
let info = &mut *info; let info = &mut *info;
info.cid.data = P::VST3_CLASS_ID; info.cid.data = P::PLATFORM_VST3_CLASS_ID;
info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32; info.cardinality = vst3_sys::base::ClassCardinality::kManyInstances as i32;
strlcpy(&mut info.category, "Audio Module Class"); strlcpy(&mut info.category, "Audio Module Class");
u16strlcpy(&mut info.name, P::NAME); u16strlcpy(&mut info.name, P::NAME);