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.

316 lines
13KB

  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 0x020402
  32. #define CARLA_VERSION_STRING "2.4.3"
  33. #define CARLA_VERSION_STRMIN "2.4"
  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. #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)
  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)
  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 noexcept throw()
  76. # define override
  77. # define final
  78. # define nullptr NULL
  79. #endif
  80. /* Common includes */
  81. #ifdef __cplusplus
  82. # include <cstddef>
  83. #else
  84. # include <stdbool.h>
  85. # include <stddef.h>
  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_MAC)
  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(__WORDSIZE) && __WORDSIZE == 64) || \
  110. (defined(__SIZE_WIDTH__) && __SIZE_WIDTH__ == 64) || \
  111. (defined(CARLA_OS_HAIKU) && defined(CARLA_OS_64BIT))
  112. # define P_INT64 "%li"
  113. # define P_UINT64 "%lu"
  114. # define P_INTPTR "%li"
  115. # define P_UINTPTR "%lx"
  116. # define P_SIZE "%lu"
  117. # define P_SSIZE "%li"
  118. #else
  119. # define P_INT64 "%lli"
  120. # define P_UINT64 "%llu"
  121. # define P_INTPTR "%i"
  122. # define P_UINTPTR "%x"
  123. # define P_SIZE "%u"
  124. # define P_SSIZE "%i"
  125. #endif
  126. /* Define BINARY_NATIVE */
  127. #if defined(CARLA_OS_WIN)
  128. # ifdef CARLA_OS_WIN64
  129. # define BINARY_NATIVE BINARY_WIN64
  130. # else
  131. # define BINARY_NATIVE BINARY_WIN32
  132. # endif
  133. #else
  134. # ifdef CARLA_OS_64BIT
  135. # define BINARY_NATIVE BINARY_POSIX64
  136. # else
  137. # define BINARY_NATIVE BINARY_POSIX32
  138. # endif
  139. #endif
  140. /* Define CARLA_ASSERT* */
  141. #if defined(CARLA_NO_ASSERTS)
  142. # define CARLA_ASSERT(cond)
  143. # define CARLA_ASSERT_INT(cond, value)
  144. # define CARLA_ASSERT_INT2(cond, v1, v2)
  145. #elif defined(NDEBUG)
  146. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  147. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  148. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  149. #else
  150. # define CARLA_ASSERT(cond) assert(cond)
  151. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  152. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  153. #endif
  154. /* Define CARLA_SAFE_ASSERT* */
  155. #define CARLA_SAFE_ASSERT(cond) if (__builtin_expect(!(cond),0)) carla_safe_assert (#cond, __FILE__, __LINE__);
  156. #define CARLA_SAFE_ASSERT_INT(cond, value) if (__builtin_expect(!(cond),0)) carla_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  157. #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));
  158. #define CARLA_SAFE_ASSERT_UINT(cond, value) if (__builtin_expect(!(cond),0)) carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  159. #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));
  160. #define CARLA_SAFE_ASSERT_BREAK(cond) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
  161. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
  162. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (__builtin_expect(!(cond),0)) { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  163. #define CARLA_CUSTOM_SAFE_ASSERT(msg, cond) if (__builtin_expect(!(cond),0)) carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__);
  164. #define CARLA_CUSTOM_SAFE_ASSERT_BREAK(msg, cond) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); break; }
  165. #define CARLA_CUSTOM_SAFE_ASSERT_CONTINUE(msg, cond) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); continue; }
  166. #define CARLA_CUSTOM_SAFE_ASSERT_RETURN(msg, cond, ret) if (__builtin_expect(!(cond),0)) { carla_custom_safe_assert(msg, #cond, __FILE__, __LINE__); return ret; }
  167. #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; }
  168. #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; }
  169. #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; }
  170. #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; }
  171. #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; }
  172. #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; }
  173. #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; }
  174. #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; }
  175. #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; }
  176. #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; }
  177. #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; }
  178. #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; }
  179. #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; }
  180. #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; }
  181. #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; }
  182. #if defined(__GNUC__) && defined(CARLA_PROPER_CPP11_SUPPORT) && ! defined(__clang__)
  183. # define CARLA_CATCH_UNWIND catch (abi::__forced_unwind&) { throw; }
  184. # if __GNUC__ >= 6
  185. # pragma GCC diagnostic push
  186. # pragma GCC diagnostic ignored "-Wterminate"
  187. # endif
  188. #else
  189. # define CARLA_CATCH_UNWIND
  190. #endif
  191. /* Define CARLA_SAFE_EXCEPTION */
  192. #define CARLA_SAFE_EXCEPTION(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); }
  193. #define CARLA_SAFE_EXCEPTION_BREAK(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); break; }
  194. #define CARLA_SAFE_EXCEPTION_CONTINUE(msg) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); continue; }
  195. #define CARLA_SAFE_EXCEPTION_RETURN(msg, ret) CARLA_CATCH_UNWIND catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); return ret; }
  196. /* Define CARLA_DECLARE_NON_COPYABLE */
  197. #ifdef CARLA_PROPER_CPP11_SUPPORT
  198. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  199. private: \
  200. ClassName(ClassName&) = delete; \
  201. ClassName(const ClassName&) = delete; \
  202. ClassName& operator=(ClassName&) = delete; \
  203. ClassName& operator=(const ClassName&) = delete;
  204. #else
  205. # define CARLA_DECLARE_NON_COPYABLE(ClassName) \
  206. private: \
  207. ClassName(ClassName&); \
  208. ClassName(const ClassName&); \
  209. ClassName& operator=(ClassName&); \
  210. ClassName& operator=(const ClassName&);
  211. #endif
  212. /* Define CARLA_PREVENT_HEAP_ALLOCATION */
  213. #ifdef CARLA_PROPER_CPP11_SUPPORT
  214. # define CARLA_PREVENT_HEAP_ALLOCATION \
  215. private: \
  216. static void* operator new(std::size_t) = delete; \
  217. static void operator delete(void*) = delete;
  218. #else
  219. # define CARLA_PREVENT_HEAP_ALLOCATION \
  220. private: \
  221. static void* operator new(std::size_t); \
  222. static void operator delete(void*);
  223. #endif
  224. /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  225. #ifdef CARLA_PROPER_CPP11_SUPPORT
  226. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  227. private: \
  228. static void* operator new(std::size_t) = delete;
  229. #else
  230. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  231. private: \
  232. static void* operator new(std::size_t);
  233. #endif
  234. /* CARLA_VISIBLE_SYMBOL */
  235. #if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  236. # ifdef BUILDING_CARLA
  237. # define CARLA_VISIBLE_SYMBOL __declspec (dllexport)
  238. # else
  239. # define CARLA_VISIBLE_SYMBOL __declspec (dllimport)
  240. # endif
  241. #else
  242. # define CARLA_VISIBLE_SYMBOL __attribute__ ((visibility("default")))
  243. #endif
  244. /* Define CARLA_API */
  245. #if defined(BUILD_BRIDGE) || defined(STATIC_PLUGIN_TARGET)
  246. # define CARLA_API
  247. #else
  248. # define CARLA_API CARLA_VISIBLE_SYMBOL
  249. #endif
  250. /* Define CARLA_EXTERN_C */
  251. #ifdef __cplusplus
  252. # define CARLA_EXTERN_C extern "C"
  253. #else
  254. # define CARLA_EXTERN_C
  255. #endif
  256. /* Define CARLA_*_EXPORT */
  257. #ifdef BUILD_BRIDGE
  258. # define CARLA_API_EXPORT CARLA_EXTERN_C
  259. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C
  260. #else
  261. # define CARLA_API_EXPORT CARLA_EXTERN_C CARLA_API
  262. # define CARLA_PLUGIN_EXPORT CARLA_EXTERN_C CARLA_VISIBLE_SYMBOL
  263. #endif
  264. /* Define CARLA_OS_SEP */
  265. #ifdef CARLA_OS_WIN
  266. # define CARLA_OS_SEP '\\'
  267. # define CARLA_OS_SEP_STR "\\"
  268. # define CARLA_OS_SPLIT ';'
  269. # define CARLA_OS_SPLIT_STR ";"
  270. #else
  271. # define CARLA_OS_SEP '/'
  272. # define CARLA_OS_SEP_STR "/"
  273. # define CARLA_OS_SPLIT ':'
  274. # define CARLA_OS_SPLIT_STR ":"
  275. #endif
  276. /* Useful typedefs */
  277. typedef unsigned char uchar;
  278. typedef unsigned short int ushort;
  279. typedef unsigned int uint;
  280. typedef unsigned long int ulong;
  281. typedef unsigned long long int ulonglong;
  282. #endif /* CARLA_DEFINES_H_INCLUDED */