Fix VST3 CID consistency between platforms
This commit is contained in:
parent
a83cbf8aca
commit
6e1f7930e3
|
@ -121,11 +121,40 @@ pub trait Plugin: Default + Send + Sync + 'static {
|
|||
pub trait Vst3Plugin: Plugin {
|
||||
/// The unique class ID that identifies this particular plugin. You can use the
|
||||
/// `*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];
|
||||
/// 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;
|
||||
|
||||
/// [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].
|
||||
|
|
|
@ -72,7 +72,7 @@ impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
|
|||
*info = mem::zeroed();
|
||||
|
||||
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;
|
||||
strlcpy(&mut info.category, "Audio Module Class");
|
||||
strlcpy(&mut info.name, P::NAME);
|
||||
|
@ -88,7 +88,7 @@ impl<P: Vst3Plugin> IPluginFactory for Factory<P> {
|
|||
) -> tresult {
|
||||
check_null_ptr!(cid, obj);
|
||||
|
||||
if (*cid).data != P::VST3_CLASS_ID {
|
||||
if (*cid).data != P::PLATFORM_VST3_CLASS_ID {
|
||||
return kNoInterface;
|
||||
}
|
||||
|
||||
|
@ -111,7 +111,7 @@ impl<P: Vst3Plugin> IPluginFactory2 for Factory<P> {
|
|||
*info = mem::zeroed();
|
||||
|
||||
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;
|
||||
strlcpy(&mut info.category, "Audio Module Class");
|
||||
strlcpy(&mut info.name, P::NAME);
|
||||
|
@ -138,7 +138,7 @@ impl<P: Vst3Plugin> IPluginFactory3 for Factory<P> {
|
|||
*info = mem::zeroed();
|
||||
|
||||
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;
|
||||
strlcpy(&mut info.category, "Audio Module Class");
|
||||
u16strlcpy(&mut info.name, P::NAME);
|
||||
|
|
Loading…
Reference in a new issue