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.

CarlaDefines.h 13KB

10 years ago
10 years ago
6 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * Carla common defines
  3. * Copyright (C) 2011-2023 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 0x020591
  28. #define CARLA_VERSION_STRING "2.6.0-alpha1"
  29. #define CARLA_VERSION_STRMIN "2.6"
  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 constexpr
  74. # define noexcept throw()
  75. # define override
  76. # define final
  77. # define nullptr NULL
  78. #endif
  79. /* Common includes */
  80. #ifdef __cplusplus
  81. # include <cstddef>
  82. #else
  83. # include <stdbool.h>
  84. # include <stddef.h>
  85. # define constexpr /* note: constexpr is coming to C soon, but no compilers support it yet */
  86. #endif
  87. /* Define various string format types */
  88. #if defined(CARLA_OS_WIN64)
  89. # define P_INT64 "%lli"
  90. # define P_UINT64 "%llu"
  91. # define P_INTPTR "%lli"
  92. # define P_UINTPTR "%llx"
  93. # define P_SIZE "%llu"
  94. # define P_SSIZE "%lli"
  95. #elif defined(CARLA_OS_WIN32)
  96. # define P_INT64 "%lli"
  97. # define P_UINT64 "%llu"
  98. # define P_INTPTR "%i"
  99. # define P_UINTPTR "%x"
  100. # define P_SIZE "%u"
  101. # define P_SSIZE "%i"
  102. #elif defined(CARLA_OS_WASM)
  103. # define P_INT64 "%lli"
  104. # define P_UINT64 "%llu"
  105. # define P_INTPTR "%li"
  106. # define P_UINTPTR "%lx"
  107. # define P_SIZE "%lu"
  108. # define P_SSIZE "%li"
  109. #elif defined(CARLA_OS_MAC)
  110. # define P_INT64 "%lli"
  111. # define P_UINT64 "%llu"
  112. # define P_INTPTR "%li"
  113. # define P_UINTPTR "%lx"
  114. # define P_SIZE "%lu"
  115. # define P_SSIZE "%li"
  116. #elif (defined(__WORDSIZE) && __WORDSIZE == 64) || \
  117. (defined(__SIZE_WIDTH__) && __SIZE_WIDTH__ == 64) || \
  118. (defined(CARLA_OS_HAIKU) && defined(CARLA_OS_64BIT))
  119. # define P_INT64 "%li"
  120. # define P_UINT64 "%lu"
  121. # define P_INTPTR "%li"
  122. # define P_UINTPTR "%lx"
  123. # define P_SIZE "%lu"
  124. # define P_SSIZE "%li"
  125. #else
  126. # define P_INT64 "%lli"
  127. # define P_UINT64 "%llu"
  128. # define P_INTPTR "%i"
  129. # define P_UINTPTR "%x"
  130. # define P_SIZE "%u"
  131. # define P_SSIZE "%i"
  132. #endif
  133. /* Define BINARY_NATIVE */
  134. #if defined(CARLA_OS_WIN)
  135. # ifdef CARLA_OS_WIN64
  136. # define BINARY_NATIVE BINARY_WIN64
  137. # else
  138. # define BINARY_NATIVE BINARY_WIN32
  139. # endif
  140. #else
  141. # ifdef CARLA_OS_64BIT
  142. # define BINARY_NATIVE BINARY_POSIX64
  143. # else
  144. # define BINARY_NATIVE BINARY_POSIX32
  145. # endif
  146. #endif
  147. /* Define unlikely */
  148. #ifdef __GNUC__
  149. # define unlikely(x) __builtin_expect(x,0)
  150. #else
  151. # define unlikely(x) x
  152. #endif
  153. /* Define CARLA_ASSERT* */
  154. #if defined(CARLA_NO_ASSERTS)
  155. # define CARLA_ASSERT(cond)
  156. # define CARLA_ASSERT_INT(cond, value)
  157. # define CARLA_ASSERT_INT2(cond, v1, v2)
  158. #elif defined(NDEBUG)
  159. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  160. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  161. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  162. #else
  163. # define CARLA_ASSERT(cond) assert(cond)
  164. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  165. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  166. #endif
  167. /* Define CARLA_SAFE_ASSERT* */
  168. #define CARLA_SAFE_ASSERT(cond) if (unlikely(!(cond))) carla_safe_assert (#cond, __FILE__, __LINE__);
  169. #define CARLA_SAFE_ASSERT_INT(cond, value) if (unlikely(!(cond))) carla_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  170. #define CARLA_SAFE_ASSERT_INT2(cond, v1, v2) if (unlikely(!(cond))) carla_safe_assert_int2 (#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2));
  171. #define CARLA_SAFE_ASSERT_UINT(cond, value) if (unlikely(!(cond))) carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  172. #define CARLA_SAFE_ASSERT_UINT2(cond, v1, v2) if (unlikely(!(cond))) carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2));
  173. #define CARLA_SAFE_ASSERT_BREAK(cond) if (unlikely(!(cond))) { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
  174. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (unlikely(!(cond))) { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
  175. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (unlikely(!(cond))) { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  176. #define CARLA_CUSTOM_SAFE_ASSERT(msg, cond) if (unlikely(!(cond))) carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__);
  177. #define CARLA_CUSTOM_SAFE_ASSERT_BREAK(msg, cond) if (unlikely(!(cond))) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); break; }
  178. #define CARLA_CUSTOM_SAFE_ASSERT_CONTINUE(msg, cond) if (unlikely(!(cond))) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); continue; }
  179. #define CARLA_CUSTOM_SAFE_ASSERT_RETURN(msg, cond, ret) if (unlikely(!(cond))) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); return ret; }
  180. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_BREAK(msg, cond) if (unlikely(!(cond))) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } break; }
  181. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_CONTINUE(msg, cond) if (unlikely(!(cond))) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } continue; }
  182. #define CARLA_CUSTOM_SAFE_ASSERT_ONCE_RETURN(msg, cond, ret) if (unlikely(!(cond))) { static bool _p; if (!_p) { _p = true; carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } return ret; }
  183. #define CARLA_SAFE_ASSERT_INT_BREAK(cond, value) if (unlikely(!(cond))) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); break; }
  184. #define CARLA_SAFE_ASSERT_INT_CONTINUE(cond, value) if (unlikely(!(cond))) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); continue; }
  185. #define CARLA_SAFE_ASSERT_INT_RETURN(cond, value, ret) if (unlikely(!(cond))) { carla_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); return ret; }
  186. #define CARLA_SAFE_ASSERT_INT2_BREAK(cond, v1, v2) if (unlikely(!(cond))) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); break; }
  187. #define CARLA_SAFE_ASSERT_INT2_CONTINUE(cond, v1, v2) if (unlikely(!(cond))) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); continue; }
  188. #define CARLA_SAFE_ASSERT_INT2_RETURN(cond, v1, v2, ret) if (unlikely(!(cond))) { carla_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); return ret; }
  189. #define CARLA_SAFE_ASSERT_UINT_BREAK(cond, value) if (unlikely(!(cond))) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value); break; }
  190. #define CARLA_SAFE_ASSERT_UINT_CONTINUE(cond, value) if (unlikely(!(cond))) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); continue; }
  191. #define CARLA_SAFE_ASSERT_UINT_RETURN(cond, value, ret) if (unlikely(!(cond))) { carla_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); return ret; }
  192. #define CARLA_SAFE_ASSERT_UINT2_BREAK(cond, v1, v2) if (unlikely(!(cond))) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); break; }
  193. #define CARLA_SAFE_ASSERT_UINT2_CONTINUE(cond, v1, v2) if (unlikely(!(cond))) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); continue; }
  194. #define CARLA_SAFE_ASSERT_UINT2_RETURN(cond, v1, v2, ret) if (unlikely(!(cond))) { carla_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); return ret; }
  195. #if defined(__GNUC__) && defined(CARLA_PROPER_CPP11_SUPPORT) && ! defined(__clang__)
  196. # define CARLA_CATCH_UNWIND catch (abi::__forced_unwind&) { throw; }
  197. # if __GNUC__ >= 6
  198. # pragma GCC diagnostic push
  199. # pragma GCC diagnostic ignored "-Wterminate"
  200. # endif
  201. #else
  202. # define CARLA_CATCH_UNWIND
  203. #endif
  204. /* Define CARLA_SAFE_EXCEPTION */
  205. #define CARLA_SAFE_EXCEPTION(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); }
  206. #define CARLA_SAFE_EXCEPTION_BREAK(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); break; }
  207. #define CARLA_SAFE_EXCEPTION_CONTINUE(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); continue; }
  208. #define CARLA_SAFE_EXCEPTION_RETURN(msg, ret) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); return ret; }
  209. /* Define CARLA_DECLARE_NON_COPYABLE */
  210. #ifdef CARLA_PROPER_CPP11_SUPPORT
  211. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  212. private: \
  213. ClassName(ClassName&) = delete; \
  214. ClassName(const ClassName&) = delete; \
  215. ClassName& operator=(ClassName&) = delete; \
  216. ClassName& operator=(const ClassName&) = delete;
  217. #else
  218. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  219. private: \
  220. ClassName(ClassName&); \
  221. ClassName(const ClassName&); \
  222. ClassName& operator=(ClassName&); \
  223. ClassName& operator=(const ClassName&);
  224. #endif
  225. /* Define CARLA_PREVENT_HEAP_ALLOCATION */
  226. #ifdef CARLA_PROPER_CPP11_SUPPORT
  227. # define CARLA_PREVENT_HEAP_ALLOCATION \
  228. private: \
  229. static void* operator new(std::size_t) = delete; \
  230. static void operator delete(void*) = delete;
  231. #else
  232. # define CARLA_PREVENT_HEAP_ALLOCATION \
  233. private: \
  234. static void* operator new(std::size_t); \
  235. static void operator delete(void*);
  236. #endif
  237. /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  238. #ifdef CARLA_PROPER_CPP11_SUPPORT
  239. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  240. private: \
  241. static void* operator new(std::size_t) = delete;
  242. #else
  243. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  244. private: \
  245. static void* operator new(std::size_t);
  246. #endif
  247. /* CARLA_VISIBLE_SYMBOL */
  248. #if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  249. # ifdef BUILDING_CARLA
  250. # define CARLA_VISIBLE_SYMBOL __declspec (dllexport)
  251. # else
  252. # define CARLA_VISIBLE_SYMBOL __declspec (dllimport)
  253. # endif
  254. #else
  255. # define CARLA_VISIBLE_SYMBOL __attribute__ ((visibility("default")))
  256. #endif
  257. /* Define CARLA_API */
  258. #if defined(BUILD_BRIDGE) || defined(STATIC_PLUGIN_TARGET)
  259. # define CARLA_API
  260. #else
  261. # define CARLA_API CARLA_VISIBLE_SYMBOL
  262. #endif
  263. /* Define CARLA_EXTERN_C */
  264. #ifdef __cplusplus
  265. # define CARLA_EXTERN_C extern "C"
  266. #else
  267. # define CARLA_EXTERN_C
  268. #endif
  269. /* Define CARLA_*_EXPORT */
  270. #ifdef BUILD_BRIDGE
  271. # define CARLA_API_EXPORT CARLA_EXTERN_C
  272. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C
  273. #else
  274. # define CARLA_API_EXPORT CARLA_EXTERN_C CARLA_API
  275. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C CARLA_VISIBLE_SYMBOL
  276. #endif
  277. /* Define CARLA_OS_SEP */
  278. #ifdef CARLA_OS_WIN
  279. # define CARLA_OS_SEP '\\'
  280. # define CARLA_OS_SEP_STR "\\"
  281. # define CARLA_OS_SPLIT ';'
  282. # define CARLA_OS_SPLIT_STR ";"
  283. #else
  284. # define CARLA_OS_SEP '/'
  285. # define CARLA_OS_SEP_STR "/"
  286. # define CARLA_OS_SPLIT ':'
  287. # define CARLA_OS_SPLIT_STR ":"
  288. #endif
  289. /* Useful typedefs */
  290. typedef unsigned char uchar;
  291. typedef unsigned short int ushort;
  292. typedef unsigned int uint;
  293. typedef unsigned long int ulong;
  294. typedef unsigned long long int ulonglong;
  295. #ifdef _MSC_VER
  296. typedef SSIZE_T ssize_t;
  297. #endif
  298. #endif /* CARLA_DEFINES_H_INCLUDED */