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.

210 lines
6.0KB

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