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.

250 lines
7.6KB

  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. using namespace juce;
  26. namespace juce
  27. {
  28. AudioProcessor::WrapperType PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_Undefined;
  29. std::function<bool(AudioProcessor&)> PluginHostType::jucePlugInIsRunningInAudioSuiteFn = nullptr;
  30. #if JucePlugin_Build_Unity
  31. bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; }
  32. #endif
  33. #if JUCE_MODULE_AVAILABLE_juce_opengl && (JucePlugin_Build_VST || JucePlugin_Build_VST3)
  34. bool juce_shouldDoubleScaleNativeGLWindow()
  35. {
  36. auto wrapperType = PluginHostType::getPluginLoadedAs();
  37. auto hostType = getHostType().type;
  38. if (wrapperType == AudioProcessor::wrapperType_VST)
  39. return hostType == PluginHostType::SteinbergCubase10 || hostType == PluginHostType::AbletonLive10;
  40. else if (wrapperType == AudioProcessor::wrapperType_VST3)
  41. return hostType == PluginHostType::SteinbergCubase10;
  42. return false;
  43. }
  44. #endif
  45. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  46. #define JUCE_VST3_CAN_REPLACE_VST2 1
  47. #endif
  48. #if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64) && JUCE_VST3_CAN_REPLACE_VST2
  49. #define VST3_REPLACEMENT_AVAILABLE 1
  50. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  51. void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  52. {
  53. char uidString[33];
  54. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  55. char vstfxidStr[7] = { 0 };
  56. sprintf (vstfxidStr, "%06X", vstfxid);
  57. strcpy (uidString, vstfxidStr);
  58. char uidStr[9] = { 0 };
  59. sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  60. strcat (uidString, uidStr);
  61. char nameidStr[3] = { 0 };
  62. const size_t len = strlen (JucePlugin_Name);
  63. for (size_t i = 0; i <= 8; ++i)
  64. {
  65. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  66. if (c >= 'A' && c <= 'Z')
  67. c += 'a' - 'A';
  68. sprintf (nameidStr, "%02X", c);
  69. strcat (uidString, nameidStr);
  70. }
  71. unsigned long p0;
  72. unsigned int p1, p2;
  73. unsigned int p3[8];
  74. #ifndef _MSC_VER
  75. sscanf
  76. #else
  77. sscanf_s
  78. #endif
  79. (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  80. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  81. union q0_u {
  82. uint32 word;
  83. uint8 bytes[4];
  84. } q0;
  85. union q1_u {
  86. uint16 half;
  87. uint8 bytes[2];
  88. } q1, q2;
  89. q0.word = static_cast<uint32> (p0);
  90. q1.half = static_cast<uint16> (p1);
  91. q2.half = static_cast<uint16> (p2);
  92. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  93. #ifndef _WIN32
  94. q0.word = ByteOrder::swap (q0.word);
  95. q1.half = ByteOrder::swap (q1.half);
  96. q2.half = ByteOrder::swap (q2.half);
  97. #endif
  98. for (int i = 0; i < 4; ++i)
  99. uuid[i+0] = q0.bytes[i];
  100. for (int i = 0; i < 2; ++i)
  101. uuid[i+4] = q1.bytes[i];
  102. for (int i = 0; i < 2; ++i)
  103. uuid[i+6] = q2.bytes[i];
  104. for (int i = 0; i < 8; ++i)
  105. uuid[i+8] = static_cast<uint8> (p3[i]);
  106. }
  107. #else
  108. #define VST3_REPLACEMENT_AVAILABLE 0
  109. #endif
  110. #if JucePlugin_Build_VST
  111. bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  112. {
  113. #if VST3_REPLACEMENT_AVAILABLE
  114. if ((index == 'stCA' || index == 'stCa') && value == 'FUID' && ptr != nullptr)
  115. {
  116. uint8 fuid[16];
  117. getUUIDForVST2ID (false, fuid);
  118. ::memcpy (ptr, fuid, 16);
  119. return true;
  120. }
  121. #else
  122. ignoreUnused (index, value, ptr);
  123. #endif
  124. return false;
  125. }
  126. #endif
  127. } // namespace juce
  128. //==============================================================================
  129. /** Somewhere in the codebase of your plugin, you need to implement this function
  130. and make it return a new instance of the filter subclass that you're building.
  131. */
  132. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  133. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  134. extern bool JUCE_CALLTYPE juce_isInterAppAudioConnected();
  135. extern void JUCE_CALLTYPE juce_switchToHostApplication();
  136. #if JUCE_MODULE_AVAILABLE_juce_gui_basics
  137. extern Image JUCE_CALLTYPE juce_getIAAHostIcon (int);
  138. #endif
  139. #endif
  140. AudioProcessor* JUCE_API JUCE_CALLTYPE createPluginFilterOfType (AudioProcessor::WrapperType type)
  141. {
  142. AudioProcessor::setTypeOfNextNewPlugin (type);
  143. AudioProcessor* const pluginInstance = createPluginFilter();
  144. AudioProcessor::setTypeOfNextNewPlugin (AudioProcessor::wrapperType_Undefined);
  145. // your createPluginFilter() method must return an object!
  146. jassert (pluginInstance != nullptr && pluginInstance->wrapperType == type);
  147. return pluginInstance;
  148. }
  149. bool PluginHostType::isInterAppAudioConnected() const
  150. {
  151. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  152. if (getPluginLoadedAs() == AudioProcessor::wrapperType_Standalone)
  153. return juce_isInterAppAudioConnected();
  154. #endif
  155. return false;
  156. }
  157. void PluginHostType::switchToHostApplication() const
  158. {
  159. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  160. if (getPluginLoadedAs() == AudioProcessor::wrapperType_Standalone)
  161. juce_switchToHostApplication();
  162. #endif
  163. }
  164. bool PluginHostType::isInAAXAudioSuite (AudioProcessor& processor)
  165. {
  166. #if JucePlugin_Build_AAX
  167. if (PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_AAX
  168. && jucePlugInIsRunningInAudioSuiteFn != nullptr)
  169. {
  170. return jucePlugInIsRunningInAudioSuiteFn (processor);
  171. }
  172. #endif
  173. ignoreUnused (processor);
  174. return false;
  175. }
  176. #if JUCE_MODULE_AVAILABLE_juce_gui_basics
  177. namespace juce {
  178. extern Image JUCE_API getIconFromApplication (const String&, const int);
  179. Image PluginHostType::getHostIcon (int size) const
  180. {
  181. ignoreUnused (size);
  182. #if JucePlugin_Enable_IAA && JucePlugin_Build_Standalone && JUCE_IOS && (! JUCE_USE_CUSTOM_PLUGIN_STANDALONE_APP)
  183. if (isInterAppAudioConnected())
  184. return juce_getIAAHostIcon (size);
  185. #endif
  186. #if JUCE_MAC
  187. String bundlePath (getHostPath().upToLastOccurrenceOf (".app", true, true));
  188. return getIconFromApplication (bundlePath, size);
  189. #endif
  190. return Image();
  191. }
  192. }
  193. #endif