The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #if _MSC_VER || defined (__MINGW32__) || defined (__MINGW64__)
  20. #include <windows.h>
  21. #endif
  22. #include "../../juce_core/system/juce_TargetPlatform.h"
  23. #include "../utility/juce_CheckSettingMacros.h"
  24. #include "juce_IncludeModuleHeaders.h"
  25. namespace juce
  26. {
  27. AudioProcessor::WrapperType PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_Undefined;
  28. }
  29. //==============================================================================
  30. namespace juce
  31. {
  32. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  33. #define JUCE_VST3_CAN_REPLACE_VST2 1
  34. #endif
  35. #if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64) && JUCE_VST3_CAN_REPLACE_VST2
  36. #define VST3_REPLACEMENT_AVAILABLE 1
  37. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  38. void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  39. {
  40. char uidString[33];
  41. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  42. char vstfxidStr[7] = { 0 };
  43. sprintf (vstfxidStr, "%06X", vstfxid);
  44. strcpy (uidString, vstfxidStr);
  45. char uidStr[9] = { 0 };
  46. sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  47. strcat (uidString, uidStr);
  48. char nameidStr[3] = { 0 };
  49. const size_t len = strlen (JucePlugin_Name);
  50. for (size_t i = 0; i <= 8; ++i)
  51. {
  52. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  53. if (c >= 'A' && c <= 'Z')
  54. c += 'a' - 'A';
  55. sprintf (nameidStr, "%02X", c);
  56. strcat (uidString, nameidStr);
  57. }
  58. unsigned long p0;
  59. unsigned int p1, p2;
  60. unsigned int p3[8];
  61. #ifndef _MSC_VER
  62. sscanf
  63. #else
  64. sscanf_s
  65. #endif
  66. (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  67. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  68. union q0_u {
  69. uint32 word;
  70. uint8 bytes[4];
  71. } q0;
  72. union q1_u {
  73. uint16 half;
  74. uint8 bytes[2];
  75. } q1, q2;
  76. q0.word = static_cast<uint32> (p0);
  77. q1.half = static_cast<uint16> (p1);
  78. q2.half = static_cast<uint16> (p2);
  79. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  80. #ifndef _WIN32
  81. q0.word = ByteOrder::swap (q0.word);
  82. q1.half = ByteOrder::swap (q1.half);
  83. q2.half = ByteOrder::swap (q2.half);
  84. #endif
  85. for (int i = 0; i < 4; ++i)
  86. uuid[i+0] = q0.bytes[i];
  87. for (int i = 0; i < 2; ++i)
  88. uuid[i+4] = q1.bytes[i];
  89. for (int i = 0; i < 2; ++i)
  90. uuid[i+6] = q2.bytes[i];
  91. for (int i = 0; i < 8; ++i)
  92. uuid[i+8] = static_cast<uint8> (p3[i]);
  93. }
  94. #else
  95. #define VST3_REPLACEMENT_AVAILABLE 0
  96. #endif
  97. #if JucePlugin_Build_VST
  98. bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  99. {
  100. #if VST3_REPLACEMENT_AVAILABLE
  101. if ((index == 'stCA' || index == 'stCa') && value == 'FUID' && ptr != nullptr)
  102. {
  103. uint8 fuid[16];
  104. getUUIDForVST2ID (false, fuid);
  105. ::memcpy (ptr, fuid, 16);
  106. return true;
  107. }
  108. #else
  109. ignoreUnused (index, value, ptr);
  110. #endif
  111. return false;
  112. }
  113. #endif
  114. } // namespace juce
  115. //==============================================================================
  116. /** Somewhere in the codebase of your plugin, you need to implement this function
  117. and make it return a new instance of the filter subclass that you're building.
  118. */
  119. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  120. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  121. extern bool JUCE_CALLTYPE juce_isInterAppAudioConnected();
  122. extern void JUCE_CALLTYPE juce_switchToHostApplication();
  123. #if JUCE_MODULE_AVAILABLE_juce_gui_basics
  124. extern Image JUCE_CALLTYPE juce_getIAAHostIcon (int);
  125. #endif
  126. #endif
  127. AudioProcessor* JUCE_API JUCE_CALLTYPE createPluginFilterOfType (AudioProcessor::WrapperType type)
  128. {
  129. AudioProcessor::setTypeOfNextNewPlugin (type);
  130. AudioProcessor* const pluginInstance = createPluginFilter();
  131. AudioProcessor::setTypeOfNextNewPlugin (AudioProcessor::wrapperType_Undefined);
  132. // your createPluginFilter() method must return an object!
  133. jassert (pluginInstance != nullptr && pluginInstance->wrapperType == type);
  134. return pluginInstance;
  135. }
  136. bool PluginHostType::isInterAppAudioConnected() const
  137. {
  138. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  139. if (getPluginLoadedAs() == AudioProcessor::wrapperType_Standalone)
  140. return juce_isInterAppAudioConnected();
  141. #endif
  142. return false;
  143. }
  144. void PluginHostType::switchToHostApplication() const
  145. {
  146. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  147. if (getPluginLoadedAs() == AudioProcessor::wrapperType_Standalone)
  148. juce_switchToHostApplication();
  149. #endif
  150. }
  151. #if JUCE_MODULE_AVAILABLE_juce_gui_basics
  152. namespace juce {
  153. extern Image JUCE_API getIconFromApplication (const String&, const int);
  154. Image PluginHostType::getHostIcon (int size) const
  155. {
  156. ignoreUnused (size);
  157. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  158. if (isInterAppAudioConnected())
  159. return juce_getIAAHostIcon (size);
  160. #endif
  161. #if JUCE_MAC
  162. String bundlePath (getHostPath().upToLastOccurrenceOf (".app", true, true));
  163. return getIconFromApplication (bundlePath, size);
  164. #endif
  165. return Image();
  166. }
  167. }
  168. #endif