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.

148 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 7 technical preview.
  4. Copyright (c) 2022 - 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 the technical preview this file cannot be licensed commercially.
  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. #if JucePlugin_Build_Unity
  22. bool juce_isRunningInUnity();
  23. bool juce_isRunningInUnity() { return PluginHostType::getPluginLoadedAs() == AudioProcessor::wrapperType_Unity; }
  24. #endif
  25. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  26. #define JUCE_VST3_CAN_REPLACE_VST2 1
  27. #endif
  28. #if JucePlugin_Build_VST3 && JUCE_VST3_CAN_REPLACE_VST2 && (JUCE_MAC || JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD)
  29. #define VST3_REPLACEMENT_AVAILABLE 1
  30. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  31. void getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  32. {
  33. #if JUCE_MSVC
  34. const auto juce_sprintf = [] (auto&& head, auto&&... tail) { sprintf_s (head, numElementsInArray (head), tail...); };
  35. const auto juce_strcpy = [] (auto&& head, auto&&... tail) { strcpy_s (head, numElementsInArray (head), tail...); };
  36. const auto juce_strcat = [] (auto&& head, auto&&... tail) { strcat_s (head, numElementsInArray (head), tail...); };
  37. const auto juce_sscanf = [] (auto&&... args) { sscanf_s (args...); };
  38. #else
  39. const auto juce_sprintf = [] (auto&&... args) { sprintf (args...); };
  40. const auto juce_strcpy = [] (auto&&... args) { strcpy (args...); };
  41. const auto juce_strcat = [] (auto&&... args) { strcat (args...); };
  42. const auto juce_sscanf = [] (auto&&... args) { sscanf (args...); };
  43. #endif
  44. char uidString[33];
  45. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  46. char vstfxidStr[7] = { 0 };
  47. juce_sprintf (vstfxidStr, "%06X", vstfxid);
  48. juce_strcpy (uidString, vstfxidStr);
  49. char uidStr[9] = { 0 };
  50. juce_sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  51. juce_strcat (uidString, uidStr);
  52. char nameidStr[3] = { 0 };
  53. const size_t len = strlen (JucePlugin_Name);
  54. for (size_t i = 0; i <= 8; ++i)
  55. {
  56. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  57. if (c >= 'A' && c <= 'Z')
  58. c += 'a' - 'A';
  59. juce_sprintf (nameidStr, "%02X", c);
  60. juce_strcat (uidString, nameidStr);
  61. }
  62. unsigned long p0;
  63. unsigned int p1, p2;
  64. unsigned int p3[8];
  65. juce_sscanf (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. #if ! JUCE_WINDOWS
  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. bool JUCE_API handleManufacturerSpecificVST2Opcode (int32 index, pointer_sized_int value, void* ptr, float)
  99. {
  100. #if VST3_REPLACEMENT_AVAILABLE
  101. if ((index == (int32) ByteOrder::bigEndianInt ("stCA") || index == (int32) ByteOrder::bigEndianInt ("stCa"))
  102. && value == (int32) ByteOrder::bigEndianInt ("FUID") && ptr != nullptr)
  103. {
  104. uint8 fuid[16];
  105. getUUIDForVST2ID (false, fuid);
  106. ::memcpy (ptr, fuid, 16);
  107. return true;
  108. }
  109. #else
  110. ignoreUnused (index, value, ptr);
  111. #endif
  112. return false;
  113. }
  114. #endif
  115. } // namespace juce