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.

190 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #if _MSC_VER || defined (__MINGW32__) || defined (__MINGW64__)
  18. #include <windows.h>
  19. #endif
  20. #include "../../juce_core/system/juce_TargetPlatform.h"
  21. #include "../utility/juce_CheckSettingMacros.h"
  22. #include "juce_IncludeModuleHeaders.h"
  23. namespace juce
  24. {
  25. AudioProcessor::WrapperType PluginHostType::jucePlugInClientCurrentWrapperType = AudioProcessor::wrapperType_Undefined;
  26. }
  27. #if _MSC_VER || JUCE_MINGW
  28. #if JucePlugin_Build_RTAS
  29. extern "C" BOOL WINAPI DllMainRTAS (HINSTANCE, DWORD, LPVOID);
  30. #endif
  31. extern "C" BOOL WINAPI DllMain (HINSTANCE instance, DWORD reason, LPVOID reserved)
  32. {
  33. if (reason == DLL_PROCESS_ATTACH)
  34. Process::setCurrentModuleInstanceHandle (instance);
  35. #if JucePlugin_Build_RTAS
  36. if (GetModuleHandleA ("DAE.DLL") != 0)
  37. {
  38. #if JucePlugin_Build_AAX
  39. if (! File::getSpecialLocation (File::currentExecutableFile).hasFileExtension ("aaxplugin"))
  40. #endif
  41. return DllMainRTAS (instance, reason, reserved);
  42. }
  43. #endif
  44. ignoreUnused (reserved);
  45. return TRUE;
  46. }
  47. #endif
  48. //==============================================================================
  49. namespace juce
  50. {
  51. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  52. #define JUCE_VST3_CAN_REPLACE_VST2 1
  53. #endif
  54. #if JucePlugin_Build_VST3 && (__APPLE_CPP__ || __APPLE_CC__ || _WIN32 || _WIN64) && JUCE_VST3_CAN_REPLACE_VST2
  55. #define VST3_REPLACEMENT_AVAILABLE 1
  56. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  57. void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  58. {
  59. char uidString[33];
  60. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  61. char vstfxidStr[7] = { 0 };
  62. sprintf (vstfxidStr, "%06X", vstfxid);
  63. strcpy (uidString, vstfxidStr);
  64. char uidStr[9] = { 0 };
  65. sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  66. strcat (uidString, uidStr);
  67. char nameidStr[3] = { 0 };
  68. const size_t len = strlen (JucePlugin_Name);
  69. for (size_t i = 0; i <= 8; ++i)
  70. {
  71. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  72. if (c >= 'A' && c <= 'Z')
  73. c += 'a' - 'A';
  74. sprintf (nameidStr, "%02X", c);
  75. strcat (uidString, nameidStr);
  76. }
  77. unsigned long p0;
  78. unsigned int p1, p2;
  79. unsigned int p3[8];
  80. #ifndef _MSC_VER
  81. sscanf
  82. #else
  83. sscanf_s
  84. #endif
  85. (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  86. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  87. union q0_u {
  88. uint32 word;
  89. uint8 bytes[4];
  90. } q0;
  91. union q1_u {
  92. uint16 half;
  93. uint8 bytes[2];
  94. } q1, q2;
  95. q0.word = static_cast<uint32> (p0);
  96. q1.half = static_cast<uint16> (p1);
  97. q2.half = static_cast<uint16> (p2);
  98. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  99. #ifndef _WIN32
  100. q0.word = ByteOrder::swap (q0.word);
  101. q1.half = ByteOrder::swap (q1.half);
  102. q2.half = ByteOrder::swap (q2.half);
  103. #endif
  104. for (int i = 0; i < 4; ++i)
  105. uuid[i+0] = q0.bytes[i];
  106. for (int i = 0; i < 2; ++i)
  107. uuid[i+4] = q1.bytes[i];
  108. for (int i = 0; i < 2; ++i)
  109. uuid[i+6] = q2.bytes[i];
  110. for (int i = 0; i < 8; ++i)
  111. uuid[i+8] = static_cast<uint8> (p3[i]);
  112. }
  113. #else
  114. #define VST3_REPLACEMENT_AVAILABLE 0
  115. #endif
  116. #if JucePlugin_Build_VST
  117. pointer_sized_int JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  118. {
  119. #if VST3_REPLACEMENT_AVAILABLE
  120. if ((index == 'stCA' || index == 'stCa') && value == 'FUID' && ptr != nullptr)
  121. {
  122. uint8 fuid[16];
  123. getUUIDForVST2ID (false, fuid);
  124. ::memcpy (ptr, fuid, 16);
  125. return 1;
  126. }
  127. #else
  128. ignoreUnused (index, value, ptr);
  129. #endif
  130. return 0;
  131. }
  132. #endif
  133. } // namespace juce
  134. //==============================================================================
  135. /** Somewhere in the codebase of your plugin, you need to implement this function
  136. and make it return a new instance of the filter subclass that you're building.
  137. */
  138. extern AudioProcessor* JUCE_CALLTYPE createPluginFilter();
  139. AudioProcessor* JUCE_API JUCE_CALLTYPE createPluginFilterOfType (AudioProcessor::WrapperType type)
  140. {
  141. AudioProcessor::setTypeOfNextNewPlugin (type);
  142. AudioProcessor* const pluginInstance = createPluginFilter();
  143. AudioProcessor::setTypeOfNextNewPlugin (AudioProcessor::wrapperType_Undefined);
  144. // your createPluginFilter() method must return an object!
  145. jassert (pluginInstance != nullptr && pluginInstance->wrapperType == type);
  146. return pluginInstance;
  147. }