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.

168 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - 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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-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. #pragma once
  19. #include <juce_audio_plugin_client/detail/juce_IncludeModuleHeaders.h>
  20. namespace juce::detail
  21. {
  22. struct PluginUtilities
  23. {
  24. PluginUtilities() = delete;
  25. static int getDesktopFlags (const AudioProcessorEditor& editor)
  26. {
  27. return editor.wantsLayerBackedView()
  28. ? 0
  29. : ComponentPeer::windowRequiresSynchronousCoreGraphicsRendering;
  30. }
  31. static int getDesktopFlags (const AudioProcessorEditor* editor)
  32. {
  33. return editor != nullptr ? getDesktopFlags (*editor) : 0;
  34. }
  35. static void addToDesktop (AudioProcessorEditor& editor, void* parent)
  36. {
  37. editor.addToDesktop (getDesktopFlags (editor), parent);
  38. }
  39. static const PluginHostType& getHostType()
  40. {
  41. static PluginHostType hostType;
  42. return hostType;
  43. }
  44. #ifndef JUCE_VST3_CAN_REPLACE_VST2
  45. #define JUCE_VST3_CAN_REPLACE_VST2 1
  46. #endif
  47. // NB: Nasty old-fashioned code in here because it's copied from the Steinberg example code.
  48. static void getUUIDForVST2ID (bool forControllerUID, uint8 uuid[16])
  49. {
  50. #if JUCE_WINDOWS && ! JUCE_MINGW
  51. const auto juce_sprintf = [] (auto&& head, auto&&... tail) { sprintf_s (head, (size_t) numElementsInArray (head), tail...); };
  52. const auto juce_strcpy = [] (auto&& head, auto&&... tail) { strcpy_s (head, (size_t) numElementsInArray (head), tail...); };
  53. const auto juce_strcat = [] (auto&& head, auto&&... tail) { strcat_s (head, (size_t) numElementsInArray (head), tail...); };
  54. const auto juce_sscanf = [] (auto&&... args) { sscanf_s (args...); };
  55. #else
  56. const auto juce_sprintf = [] (auto&& head, auto&&... tail) { snprintf (head, (size_t) numElementsInArray (head), tail...); };
  57. const auto juce_strcpy = [] (auto&&... args) { strcpy (args...); };
  58. const auto juce_strcat = [] (auto&&... args) { strcat (args...); };
  59. const auto juce_sscanf = [] (auto&&... args) { sscanf (args...); };
  60. #endif
  61. char uidString[33];
  62. const int vstfxid = (('V' << 16) | ('S' << 8) | (forControllerUID ? 'E' : 'T'));
  63. char vstfxidStr[7] = { 0 };
  64. juce_sprintf (vstfxidStr, "%06X", vstfxid);
  65. juce_strcpy (uidString, vstfxidStr);
  66. char uidStr[9] = { 0 };
  67. juce_sprintf (uidStr, "%08X", JucePlugin_VSTUniqueID);
  68. juce_strcat (uidString, uidStr);
  69. char nameidStr[3] = { 0 };
  70. const size_t len = strlen (JucePlugin_Name);
  71. for (size_t i = 0; i <= 8; ++i)
  72. {
  73. juce::uint8 c = i < len ? static_cast<juce::uint8> (JucePlugin_Name[i]) : 0;
  74. if (c >= 'A' && c <= 'Z')
  75. c += 'a' - 'A';
  76. juce_sprintf (nameidStr, "%02X", c);
  77. juce_strcat (uidString, nameidStr);
  78. }
  79. unsigned long p0;
  80. unsigned int p1, p2;
  81. unsigned int p3[8];
  82. juce_sscanf (uidString, "%08lX%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
  83. &p0, &p1, &p2, &p3[0], &p3[1], &p3[2], &p3[3], &p3[4], &p3[5], &p3[6], &p3[7]);
  84. union q0_u {
  85. uint32 word;
  86. uint8 bytes[4];
  87. } q0;
  88. union q1_u {
  89. uint16 half;
  90. uint8 bytes[2];
  91. } q1, q2;
  92. q0.word = static_cast<uint32> (p0);
  93. q1.half = static_cast<uint16> (p1);
  94. q2.half = static_cast<uint16> (p2);
  95. // VST3 doesn't use COM compatible UUIDs on non windows platforms
  96. #if ! JUCE_WINDOWS
  97. q0.word = ByteOrder::swap (q0.word);
  98. q1.half = ByteOrder::swap (q1.half);
  99. q2.half = ByteOrder::swap (q2.half);
  100. #endif
  101. for (int i = 0; i < 4; ++i)
  102. uuid[i+0] = q0.bytes[i];
  103. for (int i = 0; i < 2; ++i)
  104. uuid[i+4] = q1.bytes[i];
  105. for (int i = 0; i < 2; ++i)
  106. uuid[i+6] = q2.bytes[i];
  107. for (int i = 0; i < 8; ++i)
  108. uuid[i+8] = static_cast<uint8> (p3[i]);
  109. }
  110. #if JucePlugin_Build_VST
  111. static bool handleManufacturerSpecificVST2Opcode ([[maybe_unused]] int32 index,
  112. [[maybe_unused]] pointer_sized_int value,
  113. [[maybe_unused]] void* ptr,
  114. float)
  115. {
  116. #if JUCE_VST3_CAN_REPLACE_VST2
  117. if ((index == (int32) ByteOrder::bigEndianInt ("stCA") || index == (int32) ByteOrder::bigEndianInt ("stCa"))
  118. && value == (int32) ByteOrder::bigEndianInt ("FUID") && ptr != nullptr)
  119. {
  120. uint8 fuid[16];
  121. getUUIDForVST2ID (false, fuid);
  122. ::memcpy (ptr, fuid, 16);
  123. return true;
  124. }
  125. #endif
  126. return false;
  127. }
  128. #endif
  129. };
  130. } // namespace juce::detail