diff --git a/src/plugin.rs b/src/plugin.rs index dcb67061..c8555b49 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -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: /// 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]. diff --git a/src/wrapper/vst3/factory.rs b/src/wrapper/vst3/factory.rs index 101bc068..26f1dc0d 100644 --- a/src/wrapper/vst3/factory.rs +++ b/src/wrapper/vst3/factory.rs @@ -72,7 +72,7 @@ impl IPluginFactory for Factory

{ *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 IPluginFactory for Factory

{ ) -> 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 IPluginFactory2 for Factory

{ *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 IPluginFactory3 for Factory

{ *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);