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.

305 lines
11KB

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