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.

320 lines
13KB

  1. /*
  2. * Carla common defines
  3. * Copyright (C) 2011-2024 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_DEFINES_H_INCLUDED
  18. #define CARLA_DEFINES_H_INCLUDED
  19. /* Compatibility with non-clang compilers */
  20. #ifndef __has_feature
  21. # define __has_feature(x) 0
  22. #endif
  23. #ifndef __has_extension
  24. # define __has_extension __has_feature
  25. #endif
  26. /* Set Version */
  27. #define CARLA_VERSION_HEX 0x020509
  28. #define CARLA_VERSION_STRING "2.5.9"
  29. #define CARLA_VERSION_STRMIN "2.5"
  30. /* Check OS */
  31. #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(_M_ARM64)
  32. # define CARLA_OS_WIN64
  33. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_M_ARM)
  34. # define CARLA_OS_WIN32
  35. #elif defined(__APPLE__)
  36. # define CARLA_OS_MAC
  37. #elif defined(__HAIKU__)
  38. # define CARLA_OS_HAIKU
  39. #elif defined(__linux__) || defined(__linux)
  40. # define CARLA_OS_LINUX
  41. #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
  42. # define CARLA_OS_BSD
  43. #elif defined(__GNU__)
  44. # define CARLA_OS_GNU_HURD
  45. #elif defined(__EMSCRIPTEN__)
  46. # define CARLA_OS_WASM
  47. #else
  48. # warning Unsupported platform!
  49. #endif
  50. #if defined(CARLA_OS_WIN32) || defined(CARLA_OS_WIN64)
  51. # define CARLA_OS_WIN
  52. #elif defined(CARLA_OS_BSD) || defined(CARLA_OS_GNU_HURD) || defined(CARLA_OS_LINUX) || defined(CARLA_OS_MAC)
  53. # define CARLA_OS_UNIX
  54. #endif
  55. #if defined(__LP64__) || defined(_LP64) || defined(__arm64__) || defined(__aarch64__) || defined(CARLA_OS_WIN64)
  56. # define CARLA_OS_64BIT
  57. #endif
  58. /* Check for C++11 support */
  59. #if defined(HAVE_CPP11_SUPPORT)
  60. # if HAVE_CPP11_SUPPORT
  61. # define CARLA_PROPER_CPP11_SUPPORT
  62. # endif
  63. #elif defined(__cplusplus)
  64. # if __cplusplus >= 201103L || (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 && defined(__GXX_EXPERIMENTAL_CXX0X__)) || __has_extension(cxx_noexcept)
  65. # define CARLA_PROPER_CPP11_SUPPORT
  66. # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control))
  67. # define override /* gcc4.7+ only */
  68. # define final /* gcc4.7+ only */
  69. # endif
  70. # endif
  71. #endif
  72. #if defined(__cplusplus) && ! defined(CARLA_PROPER_CPP11_SUPPORT)
  73. # define noexcept throw()
  74. # define override
  75. # define final
  76. # define nullptr NULL
  77. #endif
  78. /* Common includes */
  79. #ifdef __cplusplus
  80. # include <cstddef>
  81. #else
  82. # include <stdbool.h>
  83. # include <stddef.h>
  84. #endif
  85. /* Define various string format types */
  86. #if defined(CARLA_OS_WIN64)
  87. # define P_INT64 "%lli"
  88. # define P_UINT64 "%llu"
  89. # define P_INTPTR "%lli"
  90. # define P_UINTPTR "%llx"
  91. # define P_SIZE "%llu"
  92. # define P_SSIZE "%lli"
  93. #elif defined(CARLA_OS_WIN32)
  94. # define P_INT64 "%lli"
  95. # define P_UINT64 "%llu"
  96. # define P_INTPTR "%i"
  97. # define P_UINTPTR "%x"
  98. # define P_SIZE "%u"
  99. # define P_SSIZE "%i"
  100. #elif defined(CARLA_OS_WASM)
  101. # define P_INT64 "%lli"
  102. # define P_UINT64 "%llu"
  103. # define P_INTPTR "%li"
  104. # define P_UINTPTR "%lx"
  105. # define P_SIZE "%lu"
  106. # define P_SSIZE "%li"
  107. #elif defined(CARLA_OS_MAC)
  108. # define P_INT64 "%lli"
  109. # define P_UINT64 "%llu"
  110. # define P_INTPTR "%li"
  111. # define P_UINTPTR "%lx"
  112. # define P_SIZE "%lu"
  113. # define P_SSIZE "%li"
  114. #elif (defined(__WORDSIZE) && __WORDSIZE == 64) || \
  115. (defined(__SIZE_WIDTH__) && __SIZE_WIDTH__ == 64) || \
  116. (defined(CARLA_OS_HAIKU) && defined(CARLA_OS_64BIT))
  117. # define P_INT64 "%li"
  118. # define P_UINT64 "%lu"
  119. # define P_INTPTR "%li"
  120. # define P_UINTPTR "%lx"
  121. # define P_SIZE "%lu"
  122. # define P_SSIZE "%li"
  123. #else
  124. # define P_INT64 "%lli"
  125. # define P_UINT64 "%llu"
  126. # define P_INTPTR "%i"
  127. # define P_UINTPTR "%x"
  128. # define P_SIZE "%u"
  129. # define P_SSIZE "%i"
  130. #endif
  131. /* Define BINARY_NATIVE */
  132. #if defined(CARLA_OS_WIN)
  133. # ifdef CARLA_OS_WIN64
  134. # define BINARY_NATIVE BINARY_WIN64
  135. # else
  136. # define BINARY_NATIVE BINARY_WIN32
  137. # endif
  138. #else
  139. # ifdef CARLA_OS_64BIT
  140. # define BINARY_NATIVE BINARY_POSIX64
  141. # else
  142. # define BINARY_NATIVE BINARY_POSIX32
  143. # endif
  144. #endif
  145. /* Define CARLA_ASSERT* */
  146. #if defined(CARLA_NO_ASSERTS)
  147. # define CARLA_ASSERT(cond)
  148. # define CARLA_ASSERT_INT(cond, value)
  149. # define CARLA_ASSERT_INT2(cond, v1, v2)
  150. #elif defined(NDEBUG)
  151. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  152. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  153. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  154. #else
  155. # define CARLA_ASSERT(cond) assert(cond)
  156. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  157. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  158. #endif
  159. /* Define CARLA_SAFE_ASSERT* */
  160. #define CARLA_SAFE_ASSERT(cond) if (__builtin_expect(!(cond),0)) carla_safe_assert (#cond, __FILE__, __LINE__);
  161. #define CARLA_SAFE_ASSERT_INT(cond, value) if (__builtin_expect(!(cond),0)) carla_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  162. #define CARLA_SAFE_ASSERT_INT2(cond, v1, v2) if (__builtin_expect(!(cond),0)) carla_safe_assert_int2 (#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2));
  163. #define CARLA_SAFE_ASSERT_UINT(cond, value) if (__builtin_expect(!(cond),0)) carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  164. #define CARLA_SAFE_ASSERT_UINT2(cond, v1, v2) if (__builtin_expect(!(cond),0)) carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2));
  165. #define CARLA_SAFE_ASSERT_BREAK(cond) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
  166. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
  167. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  168. #define CARLA_CUSTOM_SAFE_ASSERT(msg, cond) if (__builtin_expect(!(cond),0)) carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__);
  169. #define CARLA_CUSTOM_SAFE_ASSERT_BREAK(msg, cond) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); break; }
  170. #define CARLA_CUSTOM_SAFE_ASSERT_CONTINUE(msg, cond) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); continue; }
  171. #define CARLA_CUSTOM_SAFE_ASSERT_RETURN(msg, cond, ret) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); return ret; }
  172. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_BREAK(msg, cond) if (__builtin_expect(!(cond),0)) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } break; }
  173. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_CONTINUE(msg, cond) if (__builtin_expect(!(cond),0)) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } continue; }
  174. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_RETURN(msg, cond, ret) if (__builtin_expect(!(cond),0)) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } return ret; }
  175. #define CARLA_SAFE_ASSERT_INT_BREAK(cond, value) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value); break; }
  176. #define CARLA_SAFE_ASSERT_INT_CONTINUE(cond, value) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); continue; }
  177. #define CARLA_SAFE_ASSERT_INT_RETURN(cond, value, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); return ret; }
  178. #define CARLA_SAFE_ASSERT_INT2_BREAK(cond, v1, v2) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); break; }
  179. #define CARLA_SAFE_ASSERT_INT2_CONTINUE(cond, v1, v2) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); continue; }
  180. #define CARLA_SAFE_ASSERT_INT2_RETURN(cond, v1, v2, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); return ret; }
  181. #define CARLA_SAFE_ASSERT_UINT_BREAK(cond, value) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value); break; }
  182. #define CARLA_SAFE_ASSERT_UINT_CONTINUE(cond, value) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); continue; }
  183. #define CARLA_SAFE_ASSERT_UINT_RETURN(cond, value, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); return ret; }
  184. #define CARLA_SAFE_ASSERT_UINT2_BREAK(cond, v1, v2) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); break; }
  185. #define CARLA_SAFE_ASSERT_UINT2_CONTINUE(cond, v1, v2) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); continue; }
  186. #define CARLA_SAFE_ASSERT_UINT2_RETURN(cond, v1, v2, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); return ret; }
  187. #if defined(__GNUC__) && defined(CARLA_PROPER_CPP11_SUPPORT) && ! defined(__clang__)
  188. # define CARLA_CATCH_UNWIND catch (abi::__forced_unwind&) { throw; }
  189. # if __GNUC__ >= 6
  190. # pragma GCC diagnostic push
  191. # pragma GCC diagnostic ignored "-Wterminate"
  192. # endif
  193. #else
  194. # define CARLA_CATCH_UNWIND
  195. #endif
  196. /* Define CARLA_SAFE_EXCEPTION */
  197. #define CARLA_SAFE_EXCEPTION(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); }
  198. #define CARLA_SAFE_EXCEPTION_BREAK(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); break; }
  199. #define CARLA_SAFE_EXCEPTION_CONTINUE(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); continue; }
  200. #define CARLA_SAFE_EXCEPTION_RETURN(msg, ret) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); return ret; }
  201. /* Define CARLA_DECLARE_NON_COPYABLE */
  202. #ifdef CARLA_PROPER_CPP11_SUPPORT
  203. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  204. private: \
  205. ClassName(ClassName&) = delete; \
  206. ClassName(const ClassName&) = delete; \
  207. ClassName& operator=(ClassName&) = delete; \
  208. ClassName& operator=(const ClassName&) = delete;
  209. #else
  210. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  211. private: \
  212. ClassName(ClassName&); \
  213. ClassName(const ClassName&); \
  214. ClassName& operator=(ClassName&); \
  215. ClassName& operator=(const ClassName&);
  216. #endif
  217. /* Define CARLA_PREVENT_HEAP_ALLOCATION */
  218. #ifdef CARLA_PROPER_CPP11_SUPPORT
  219. # define CARLA_PREVENT_HEAP_ALLOCATION \
  220. private: \
  221. static void* operator new(std::size_t) = delete; \
  222. static void operator delete(void*) = delete;
  223. #else
  224. # define CARLA_PREVENT_HEAP_ALLOCATION \
  225. private: \
  226. static void* operator new(std::size_t); \
  227. static void operator delete(void*);
  228. #endif
  229. /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  230. #ifdef CARLA_PROPER_CPP11_SUPPORT
  231. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  232. private: \
  233. static void* operator new(std::size_t) = delete;
  234. #else
  235. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  236. private: \
  237. static void* operator new(std::size_t);
  238. #endif
  239. /* CARLA_VISIBLE_SYMBOL */
  240. #if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  241. # ifdef BUILDING_CARLA
  242. # define CARLA_VISIBLE_SYMBOL __declspec (dllexport)
  243. # else
  244. # define CARLA_VISIBLE_SYMBOL __declspec (dllimport)
  245. # endif
  246. #else
  247. # define CARLA_VISIBLE_SYMBOL __attribute__ ((visibility("default")))
  248. #endif
  249. /* Define CARLA_API */
  250. #if defined(BUILD_BRIDGE) || defined(STATIC_PLUGIN_TARGET)
  251. # define CARLA_API
  252. #else
  253. # define CARLA_API CARLA_VISIBLE_SYMBOL
  254. #endif
  255. /* Define CARLA_EXTERN_C */
  256. #ifdef __cplusplus
  257. # define CARLA_EXTERN_C extern "C"
  258. #else
  259. # define CARLA_EXTERN_C
  260. #endif
  261. /* Define CARLA_*_EXPORT */
  262. #ifdef BUILD_BRIDGE
  263. # define CARLA_API_EXPORT CARLA_EXTERN_C
  264. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C
  265. #else
  266. # define CARLA_API_EXPORT CARLA_EXTERN_C CARLA_API
  267. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C CARLA_VISIBLE_SYMBOL
  268. #endif
  269. /* Define CARLA_OS_SEP */
  270. #ifdef CARLA_OS_WIN
  271. # define CARLA_OS_SEP '\\'
  272. # define CARLA_OS_SEP_STR "\\"
  273. # define CARLA_OS_SPLIT ';'
  274. # define CARLA_OS_SPLIT_STR ";"
  275. #else
  276. # define CARLA_OS_SEP '/'
  277. # define CARLA_OS_SEP_STR "/"
  278. # define CARLA_OS_SPLIT ':'
  279. # define CARLA_OS_SPLIT_STR ":"
  280. #endif
  281. /* Useful typedefs */
  282. typedef unsigned char uchar;
  283. typedef unsigned short int ushort;
  284. typedef unsigned int uint;
  285. typedef unsigned long int ulong;
  286. typedef unsigned long long int ulonglong;
  287. #endif /* CARLA_DEFINES_H_INCLUDED */