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.

338 lines
14KB

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