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