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.

155 lines
4.6KB

  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. #if !(defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  27. #if defined(__aarch64__) || defined(__arm64__)
  28. #define V3_ARCHITECTURE "aarch64"
  29. #elif defined(__TARGET_ARCH_ARM)
  30. #if __TARGET_ARCH_ARM == 9
  31. #define V3_ARCHITECTURE "armv9l"
  32. #elif __TARGET_ARCH_ARM == 8
  33. #define V3_ARCHITECTURE "armv8l"
  34. #elif __TARGET_ARCH_ARM == 7
  35. #define V3_ARCHITECTURE "armv7l"
  36. #elif _TARGET_ARCH_ARM == 6
  37. #define V3_ARCHITECTURE "armv6l"
  38. #elif __TARGET_ARCH_ARM == 5
  39. #define V3_ARCHITECTURE "armv5l"
  40. #else
  41. #define V3_ARCHITECTURE "arm"
  42. #endif
  43. #elif defined(__arm__)
  44. #define V3_ARCHITECTURE "arm"
  45. #elif defined(__x86_64) || defined(__x86_64__) || defined(__amd64)
  46. #define V3_ARCHITECTURE "x86_64"
  47. #elif defined(__i386) || defined(__i386__)
  48. #define V3_ARCHITECTURE "i386"
  49. #elif defined(__ia64) || defined(__ia64__)
  50. #define V3_ARCHITECTURE "ia64"
  51. #elif defined(__mips64)
  52. #define V3_ARCHITECTURE "mips64"
  53. #elif defined(__mips) || defined(__mips__)
  54. #define V3_ARCHITECTURE "mips"
  55. #elif defined(__ppc64) || defined(__ppc64__) || defined(__powerpc64__)
  56. #define V3_ARCHITECTURE "ppc64"
  57. #elif defined(__ppc) || defined(__ppc__) || defined(__powerpc__)
  58. #define V3_ARCHITECTURE "ppc"
  59. #elif defined(__riscv)
  60. #if __riscv_xlen == 64
  61. #define V3_ARCHITECTURE "riscv64"
  62. #else
  63. #define V3_ARCHITECTURE "riscv"
  64. #endif
  65. #else
  66. #define V3_ARCHITECTURE "unknown"
  67. #endif
  68. #if defined(__HAIKU__)
  69. #define V3_PLATFORM "haiku"
  70. #elif defined(__linux__) || defined(__linux)
  71. #define V3_PLATFORM "linux"
  72. #elif defined(__FreeBSD__)
  73. #define V3_PLATFORM "freebsd"
  74. #elif defined(__NetBSD__)
  75. #define V3_PLATFORM "netbsd"
  76. #elif defined(__OpenBSD__)
  77. #define V3_PLATFORM "openbsd"
  78. #elif defined(__GNU__)
  79. #define V3_PLATFORM "hurd"
  80. #else
  81. #define V3_PLATFORM "unknown"
  82. #endif
  83. #endif
  84. #if defined(CARLA_OS_MAC)
  85. #define V3_CONTENT_DIR "MacOS"
  86. #elif defined(_M_ARM64)
  87. #define V3_CONTENT_DIR "aarch64-win" /* TBD */
  88. #elif defined(_M_ARM)
  89. #define V3_CONTENT_DIR "arm-win" /* TBD */
  90. #elif defined(CARLA_OS_WIN64)
  91. #define V3_CONTENT_DIR "x86_64-win"
  92. #elif defined(CARLA_OS_WIN32)
  93. #define V3_CONTENT_DIR "x86-win"
  94. #else
  95. #define V3_CONTENT_DIR V3_ARCHITECTURE "-" V3_PLATFORM
  96. #endif
  97. #if defined(CARLA_OS_MAC)
  98. # define V3_ENTRYFNNAME "bundleEntry"
  99. # define V3_EXITFNNAME "bundleExit"
  100. typedef void (*V3_ENTRYFN)(void*);
  101. typedef void (*V3_EXITFN)(void);
  102. #elif defined(CARLA_OS_WIN)
  103. # define V3_ENTRYFNNAME "InitDll"
  104. # define V3_EXITFNNAME "ExitDll"
  105. typedef void (*V3_ENTRYFN)(void);
  106. typedef void (*V3_EXITFN)(void);
  107. #else
  108. # define V3_ENTRYFNNAME "ModuleEntry"
  109. # define V3_EXITFNNAME "ModuleExit"
  110. typedef void (*V3_ENTRYFN)(void*);
  111. typedef void (*V3_EXITFN)(void);
  112. #endif
  113. #define V3_GETFNNAME "GetPluginFactory"
  114. typedef v3_plugin_factory** (*V3_GETFN)(void);
  115. CARLA_BACKEND_START_NAMESPACE
  116. static inline
  117. PluginCategory getPluginCategoryFromV3SubCategories(const char* const subcategories)
  118. {
  119. if (std::strstr(subcategories, "Instrument") != nullptr)
  120. return PLUGIN_CATEGORY_SYNTH;
  121. return subcategories[0] != '\0' ? PLUGIN_CATEGORY_OTHER : PLUGIN_CATEGORY_NONE;
  122. }
  123. static inline constexpr
  124. uint32_t v3_cconst(const uint8_t a, const uint8_t b, const uint8_t c, const uint8_t d) noexcept
  125. {
  126. return static_cast<uint32_t>((a << 24) | (b << 16) | (c << 8) | (d << 0));
  127. }
  128. static inline
  129. const char* tuid2str(const v3_tuid iid)
  130. {
  131. static char buf[44];
  132. std::snprintf(buf, sizeof(buf), "0x%08X,0x%08X,0x%08X,0x%08X",
  133. v3_cconst(iid[ 0], iid[ 1], iid[ 2], iid[ 3]),
  134. v3_cconst(iid[ 4], iid[ 5], iid[ 6], iid[ 7]),
  135. v3_cconst(iid[ 8], iid[ 9], iid[10], iid[11]),
  136. v3_cconst(iid[12], iid[13], iid[14], iid[15]));
  137. return buf;
  138. }
  139. CARLA_BACKEND_END_NAMESPACE
  140. #endif // CARLA_VST3_UTILS_HPP_INCLUDED