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.

212 lines
6.2KB

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