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.

153 lines
5.1KB

  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. #if JucePlugin_Build_Unity
  27. bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; }
  28. #endif
  29. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  30. #define JUCE_VST3_CAN_REPLACE_VST2 1
  31. #endif
  32. #if JucePlugin_Build_VST3 && JUCE_VST3_CAN_REPLACE_VST2 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD)
  33. #define VST3_REPLACEMENT_AVAILABLE 1
  34. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  35. void JUCE_API getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  36. {
  37. #if JUCE_MSVC
  38. const auto juce_sprintf = [] (auto&& head, auto&&... tail) { sprintf_s (head, numElementsInArray (head), tail...); };
  39. const auto juce_strcpy = [] (auto&& head, auto&&... tail) { strcpy_s (head, numElementsInArray (head), tail...); };
  40. const auto juce_strcat = [] (auto&& head, auto&&... tail) { strcat_s (head, numElementsInArray (head), tail...); };
  41. const auto juce_sscanf = [] (auto&&... args) { sscanf_s (args...); };
  42. #else
  43. const auto juce_sprintf = [] (auto&&... args) { sprintf (args...); };
  44. const auto juce_strcpy = [] (auto&&... args) { strcpy (args...); };
  45. const auto juce_strcat = [] (auto&&... args) { strcat (args...); };
  46. const auto juce_sscanf = [] (auto&&... args) { sscanf (args...); };
  47. #endif
  48. char uidString[33];
  49. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  50. char vstfxidStr[7] = { 0 };
  51. juce_sprintf (vstfxidStr, "%06X", vstfxid);
  52. juce_strcpy (uidString, vstfxidStr);
  53. char uidStr[9] = { 0 };
  54. juce_sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  55. juce_strcat (uidString, uidStr);
  56. char nameidStr[3] = { 0 };
  57. const size_t len = strlen (JucePlugin_Name);
  58. for (size_t i = 0; i <= 8; ++i)
  59. {
  60. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  61. if (c >= 'A' && c <= 'Z')
  62. c += 'a' - 'A';
  63. juce_sprintf (nameidStr, "%02X", c);
  64. juce_strcat (uidString, nameidStr);
  65. }
  66. unsigned long p0;
  67. unsigned int p1, p2;
  68. unsigned int p3[8];
  69. juce_sscanf (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  70. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  71. union q0_u {
  72. uint32 word;
  73. uint8 bytes[4];
  74. } q0;
  75. union q1_u {
  76. uint16 half;
  77. uint8 bytes[2];
  78. } q1, q2;
  79. q0.word = static_cast<uint32> (p0);
  80. q1.half = static_cast<uint16> (p1);
  81. q2.half = static_cast<uint16> (p2);
  82. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  83. #if ! JUCE_WINDOWS
  84. q0.word = ByteOrder::swap (q0.word);
  85. q1.half = ByteOrder::swap (q1.half);
  86. q2.half = ByteOrder::swap (q2.half);
  87. #endif
  88. for (int i = 0; i < 4; ++i)
  89. uuid[i+0] = q0.bytes[i];
  90. for (int i = 0; i < 2; ++i)
  91. uuid[i+4] = q1.bytes[i];
  92. for (int i = 0; i < 2; ++i)
  93. uuid[i+6] = q2.bytes[i];
  94. for (int i = 0; i < 8; ++i)
  95. uuid[i+8] = static_cast<uint8> (p3[i]);
  96. }
  97. #else
  98. #define VST3_REPLACEMENT_AVAILABLE 0
  99. #endif
  100. #if JucePlugin_Build_VST
  101. bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  102. {
  103. #if VST3_REPLACEMENT_AVAILABLE
  104. if ((index == (int32) ByteOrder::bigEndianInt ("stCA") || index == (int32) ByteOrder::bigEndianInt ("stCa"))
  105. && value == (int32) ByteOrder::bigEndianInt ("FUID") && ptr != nullptr)
  106. {
  107. uint8 fuid[16];
  108. getUUIDForVST2ID (false, fuid);
  109. ::memcpy (ptr, fuid, 16);
  110. return true;
  111. }
  112. #else
  113. ignoreUnused (index, value, ptr);
  114. #endif
  115. return false;
  116. }
  117. #endif
  118. } // namespace juce