Audio plugin host https://kx.studio/carla
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.

163 lines
5.1KB

  1. /*
  2. * Carla VST3 utils
  3. * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_VST3_UTILS_HPP_INCLUDED
  18. #define CARLA_VST3_UTILS_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #include "CarlaUtils.hpp"
  21. #include "travesty/audio_processor.h"
  22. #include "travesty/component.h"
  23. #include "travesty/edit_controller.h"
  24. #include "travesty/factory.h"
  25. #include "travesty/host.h"
  26. // --------------------------------------------------------------------------------------------------------------------
  27. #if !(defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  28. #if defined(__aarch64__) || defined(__arm64__)
  29. #define V3_ARCHITECTURE "aarch64"
  30. #elif defined(__TARGET_ARCH_ARM)
  31. #if __TARGET_ARCH_ARM == 9
  32. #define V3_ARCHITECTURE "armv9l"
  33. #elif __TARGET_ARCH_ARM == 8
  34. #define V3_ARCHITECTURE "armv8l"
  35. #elif __TARGET_ARCH_ARM == 7
  36. #define V3_ARCHITECTURE "armv7l"
  37. #elif _TARGET_ARCH_ARM == 6
  38. #define V3_ARCHITECTURE "armv6l"
  39. #elif __TARGET_ARCH_ARM == 5
  40. #define V3_ARCHITECTURE "armv5l"
  41. #else
  42. #define V3_ARCHITECTURE "arm"
  43. #endif
  44. #elif defined(__arm__)
  45. #define V3_ARCHITECTURE "arm"
  46. #elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64)
  47. #define V3_ARCHITECTURE "x86_64"
  48. #elif defined(__i386) || defined(__i386__)
  49. #define V3_ARCHITECTURE "i386"
  50. #elif defined(__ia64) || defined(__ia64__)
  51. #define V3_ARCHITECTURE "ia64"
  52. #elif defined(__mips64)
  53. #define V3_ARCHITECTURE "mips64"
  54. #elif defined(__mips) || defined(__mips__)
  55. #define V3_ARCHITECTURE "mips"
  56. #elif defined(__ppc64) || defined(__ppc64__) || defined(__powerpc64__)
  57. #define V3_ARCHITECTURE "ppc64"
  58. #elif defined(__ppc) || defined(__ppc__) || defined(__powerpc__)
  59. #define V3_ARCHITECTURE "ppc"
  60. #elif defined(__riscv)
  61. #if __riscv_xlen == 64
  62. #define V3_ARCHITECTURE "riscv64"
  63. #else
  64. #define V3_ARCHITECTURE "riscv"
  65. #endif
  66. #else
  67. #define V3_ARCHITECTURE "unknown"
  68. #endif
  69. #if defined(__HAIKU__)
  70. #define V3_PLATFORM "haiku"
  71. #elif defined(__linux__) || defined(__linux)
  72. #define V3_PLATFORM "linux"
  73. #elif defined(__FreeBSD__)
  74. #define V3_PLATFORM "freebsd"
  75. #elif defined(__NetBSD__)
  76. #define V3_PLATFORM "netbsd"
  77. #elif defined(__OpenBSD__)
  78. #define V3_PLATFORM "openbsd"
  79. #elif defined(__GNU__)
  80. #define V3_PLATFORM "hurd"
  81. #else
  82. #define V3_PLATFORM "unknown"
  83. #endif
  84. #endif
  85. #if defined(CARLA_OS_MAC)
  86. #define V3_CONTENT_DIR "MacOS"
  87. #elif defined(_M_ARM64)
  88. #define V3_CONTENT_DIR "aarch64-win" /* TBD */
  89. #elif defined(_M_ARM)
  90. #define V3_CONTENT_DIR "arm-win" /* TBD */
  91. #elif defined(CARLA_OS_WIN64)
  92. #define V3_CONTENT_DIR "x86_64-win"
  93. #elif defined(CARLA_OS_WIN32)
  94. #define V3_CONTENT_DIR "x86-win"
  95. #else
  96. #define V3_CONTENT_DIR V3_ARCHITECTURE "-" V3_PLATFORM
  97. #endif
  98. #if defined(CARLA_OS_MAC)
  99. # define V3_ENTRYFNNAME "bundleEntry"
  100. # define V3_EXITFNNAME "bundleExit"
  101. typedef void (*V3_ENTRYFN)(void*);
  102. typedef void (*V3_EXITFN)(void);
  103. #elif defined(CARLA_OS_WIN)
  104. # define V3_ENTRYFNNAME "InitDll"
  105. # define V3_EXITFNNAME "ExitDll"
  106. typedef void (*V3_ENTRYFN)(void);
  107. typedef void (*V3_EXITFN)(void);
  108. #else
  109. # define V3_ENTRYFNNAME "ModuleEntry"
  110. # define V3_EXITFNNAME "ModuleExit"
  111. typedef void (*V3_ENTRYFN)(void*);
  112. typedef void (*V3_EXITFN)(void);
  113. #endif
  114. #define V3_GETFNNAME "GetPluginFactory"
  115. typedef v3_plugin_factory** (*V3_GETFN)(void);
  116. // --------------------------------------------------------------------------------------------------------------------
  117. CARLA_BACKEND_START_NAMESPACE
  118. // --------------------------------------------------------------------------------------------------------------------
  119. static inline
  120. PluginCategory getPluginCategoryFromV3SubCategories(const char* const subcategories) noexcept
  121. {
  122. if (std::strstr(subcategories, "Instrument") != nullptr)
  123. return PLUGIN_CATEGORY_SYNTH;
  124. return subcategories[0] != '\0' ? PLUGIN_CATEGORY_OTHER : PLUGIN_CATEGORY_NONE;
  125. }
  126. static inline constexpr
  127. uint32_t v3_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_t d) noexcept
  128. {
  129. return static_cast<uint32_t>((a << 24) | (b << 16) | (c << 8) | (d << 0));
  130. }
  131. static inline
  132. const char* tuid2str(const v3_tuid iid) noexcept
  133. {
  134. static char buf[44];
  135. std::snprintf(buf, sizeof(buf), "0x%08X,0x%08X,0x%08X,0x%08X",
  136. v3_cconst(iid[ 0], iid[ 1], iid[ 2], iid[ 3]),
  137. v3_cconst(iid[ 4], iid[ 5], iid[ 6], iid[ 7]),
  138. v3_cconst(iid[ 8], iid[ 9], iid[10], iid[11]),
  139. v3_cconst(iid[12], iid[13], iid[14], iid[15]));
  140. return buf;
  141. }
  142. // --------------------------------------------------------------------------------------------------------------------
  143. CARLA_BACKEND_END_NAMESPACE
  144. #endif // CARLA_VST3_UTILS_HPP_INCLUDED