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.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  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. namespace juce
  20. {
  21. AudioProcessor::WrapperType PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_Undefined;
  22. std::function<bool(AudioProcessor&)> PluginHostType::jucePlugInIsRunningInAudioSuiteFn = nullptr;
  23. #if JucePlugin_Build_Unity
  24. bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; }
  25. #endif
  26. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  27. #define JUCE_VST3_CAN_REPLACE_VST2 1
  28. #endif
  29. #if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64 || LINUX || __linux__) && JUCE_VST3_CAN_REPLACE_VST2
  30. #define VST3_REPLACEMENT_AVAILABLE 1
  31. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  32. void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  33. {
  34. char uidString[33];
  35. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  36. char vstfxidStr[7] = { 0 };
  37. sprintf (vstfxidStr, "%06X", vstfxid);
  38. strcpy (uidString, vstfxidStr);
  39. char uidStr[9] = { 0 };
  40. sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  41. strcat (uidString, uidStr);
  42. char nameidStr[3] = { 0 };
  43. const size_t len = strlen (JucePlugin_Name);
  44. for (size_t i = 0; i <= 8; ++i)
  45. {
  46. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  47. if (c >= 'A' && c <= 'Z')
  48. c += 'a' - 'A';
  49. sprintf (nameidStr, "%02X", c);
  50. strcat (uidString, nameidStr);
  51. }
  52. unsigned long p0;
  53. unsigned int p1, p2;
  54. unsigned int p3[8];
  55. #ifndef _MSC_VER
  56. sscanf
  57. #else
  58. sscanf_s
  59. #endif
  60. (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  61. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  62. union q0_u {
  63. uint32 word;
  64. uint8 bytes[4];
  65. } q0;
  66. union q1_u {
  67. uint16 half;
  68. uint8 bytes[2];
  69. } q1, q2;
  70. q0.word = static_cast<uint32> (p0);
  71. q1.half = static_cast<uint16> (p1);
  72. q2.half = static_cast<uint16> (p2);
  73. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  74. #ifndef _WIN32
  75. q0.word = ByteOrder::swap (q0.word);
  76. q1.half = ByteOrder::swap (q1.half);
  77. q2.half = ByteOrder::swap (q2.half);
  78. #endif
  79. for (int i = 0; i < 4; ++i)
  80. uuid[i+0] = q0.bytes[i];
  81. for (int i = 0; i < 2; ++i)
  82. uuid[i+4] = q1.bytes[i];
  83. for (int i = 0; i < 2; ++i)
  84. uuid[i+6] = q2.bytes[i];
  85. for (int i = 0; i < 8; ++i)
  86. uuid[i+8] = static_cast<uint8> (p3[i]);
  87. }
  88. #else
  89. #define VST3_REPLACEMENT_AVAILABLE 0
  90. #endif
  91. #if JucePlugin_Build_VST
  92. bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  93. {
  94. #if VST3_REPLACEMENT_AVAILABLE
  95. if ((index == 'stCA' || index == 'stCa') && value == 'FUID' && ptr != nullptr)
  96. {
  97. uint8 fuid[16];
  98. getUUIDForVST2ID (false, fuid);
  99. ::memcpy (ptr, fuid, 16);
  100. return true;
  101. }
  102. #else
  103. ignoreUnused (index, value, ptr);
  104. #endif
  105. return false;
  106. }
  107. #endif
  108. } // namespace juce
  109. using 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