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.

288 lines
9.1KB

  1. /*
  2. * Carla common defines
  3. * Copyright (C) 2011-2017 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 0x01097
  32. #define CARLA_VERSION_STRING "1.9.7 (2.0-beta5)"
  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. #else
  45. # warning Unsupported platform!
  46. #endif
  47. #if defined(CARLA_OS_WIN32) || defined(CARLA_OS_WIN64)
  48. # define CARLA_OS_WIN
  49. #elif defined(CARLA_OS_LINUX) || defined(CARLA_OS_MAC)
  50. # define CARLA_OS_UNIX
  51. #endif
  52. #if defined (__LP64__) || defined (_LP64) || defined (__arm64__) || defined(CARLA_OS_WIN64)
  53. # define CARLA_OS_64BIT
  54. #endif
  55. /* Check for C++11 support */
  56. #if defined(HAVE_CPP11_SUPPORT)
  57. # if HAVE_CPP11_SUPPORT
  58. # define CARLA_PROPER_CPP11_SUPPORT
  59. # endif
  60. #elif defined(__cplusplus)
  61. # if __cplusplus >= 201103L || (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405 && defined(__GXX_EXPERIMENTAL_CXX0X__)) || __has_extension(cxx_noexcept)
  62. # define CARLA_PROPER_CPP11_SUPPORT
  63. # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control))
  64. # define override // gcc4.7+ only
  65. # define final // gcc4.7+ only
  66. # endif
  67. # endif
  68. #endif
  69. #if defined(__cplusplus) && ! defined(CARLA_PROPER_CPP11_SUPPORT)
  70. # define noexcept throw()
  71. # define override
  72. # define final
  73. # define nullptr NULL
  74. #endif
  75. /* Common includes */
  76. #ifdef __cplusplus
  77. # include <cstddef>
  78. #else
  79. # include <stdbool.h>
  80. # include <stddef.h>
  81. #endif
  82. /* Define various string format types */
  83. #if defined(CARLA_OS_WIN64)
  84. # define P_INT64 "%lli"
  85. # define P_UINT64 "%llu"
  86. # define P_INTPTR "%lli"
  87. # define P_UINTPTR "%llx"
  88. # define P_SIZE "%llu"
  89. # define P_SSIZE "%lli"
  90. #elif defined(CARLA_OS_WIN32)
  91. # define P_INT64 "%lli"
  92. # define P_UINT64 "%llu"
  93. # define P_INTPTR "%i"
  94. # define P_UINTPTR "%x"
  95. # define P_SIZE "%u"
  96. # define P_SSIZE "%i"
  97. #elif defined(CARLA_OS_MAC)
  98. // FIXME adjust for 32bit bridges
  99. # define P_INT64 "%lli"
  100. # define P_UINT64 "%llu"
  101. # define P_INTPTR "%li"
  102. # define P_UINTPTR "%lx"
  103. # define P_SIZE "%lu"
  104. # define P_SSIZE "%li"
  105. #elif defined(__WORDSIZE) && __WORDSIZE == 64
  106. # define P_INT64 "%li"
  107. # define P_UINT64 "%lu"
  108. # define P_INTPTR "%li"
  109. # define P_UINTPTR "%lx"
  110. # define P_SIZE "%lu"
  111. # define P_SSIZE "%li"
  112. #else
  113. # define P_INT64 "%lli"
  114. # define P_UINT64 "%llu"
  115. # define P_INTPTR "%i"
  116. # define P_UINTPTR "%x"
  117. # define P_SIZE "%u"
  118. # define P_SSIZE "%i"
  119. #endif
  120. /* Define BINARY_NATIVE */
  121. #if defined(CARLA_OS_HAIKU) || defined(CARLA_OS_UNIX)
  122. # ifdef CARLA_OS_64BIT
  123. # define BINARY_NATIVE BINARY_POSIX64
  124. # else
  125. # define BINARY_NATIVE BINARY_POSIX32
  126. # endif
  127. #elif 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. # warning Unknown native binary type
  135. # define BINARY_NATIVE BINARY_OTHER
  136. #endif
  137. /* Define CARLA_ASSERT* */
  138. #if defined(CARLA_NO_ASSERTS)
  139. # define CARLA_ASSERT(cond)
  140. # define CARLA_ASSERT_INT(cond, value)
  141. # define CARLA_ASSERT_INT2(cond, v1, v2)
  142. #elif defined(NDEBUG)
  143. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  144. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  145. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  146. #else
  147. # define CARLA_ASSERT(cond) assert(cond)
  148. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  149. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  150. #endif
  151. /* Define CARLA_SAFE_ASSERT* */
  152. #define CARLA_SAFE_ASSERT(cond) if (! (cond)) carla_safe_assert (#cond, __FILE__, __LINE__);
  153. #define CARLA_SAFE_ASSERT_INT(cond, value) if (! (cond)) carla_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  154. #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));
  155. #define CARLA_SAFE_ASSERT_UINT(cond, value) if (! (cond)) carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  156. #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));
  157. #define CARLA_SAFE_ASSERT_BREAK(cond) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
  158. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
  159. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  160. /* Define CARLA_SAFE_EXCEPTION */
  161. #define CARLA_SAFE_EXCEPTION(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); }
  162. #define CARLA_SAFE_EXCEPTION_BREAK(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); break; }
  163. #define CARLA_SAFE_EXCEPTION_CONTINUE(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); continue; }
  164. #define CARLA_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); return ret; }
  165. /* Define CARLA_DECLARE_NON_COPY_CLASS */
  166. #ifdef CARLA_PROPER_CPP11_SUPPORT
  167. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  168. private: \
  169. ClassName(ClassName&) = delete; \
  170. ClassName(const ClassName&) = delete; \
  171. ClassName& operator=(ClassName&) = delete; \
  172. ClassName& operator=(const ClassName&) = delete;
  173. #else
  174. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  175. private: \
  176. ClassName(ClassName&); \
  177. ClassName(const ClassName&); \
  178. ClassName& operator=(ClassName&); \
  179. ClassName& operator=(const ClassName&);
  180. #endif
  181. /* Define CARLA_DECLARE_NON_COPY_STRUCT */
  182. #ifdef CARLA_PROPER_CPP11_SUPPORT
  183. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName) \
  184. StructName(StructName&) = delete; \
  185. StructName(const StructName&) = delete; \
  186. StructName& operator=(StructName&) = delete; \
  187. StructName& operator=(const StructName&) = delete;
  188. #else
  189. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName)
  190. #endif
  191. /* Define CARLA_PREVENT_HEAP_ALLOCATION */
  192. #ifdef CARLA_PROPER_CPP11_SUPPORT
  193. # define CARLA_PREVENT_HEAP_ALLOCATION \
  194. private: \
  195. static void* operator new(std::size_t) = delete; \
  196. static void operator delete(void*) = delete;
  197. #else
  198. # define CARLA_PREVENT_HEAP_ALLOCATION \
  199. private: \
  200. static void* operator new(std::size_t); \
  201. static void operator delete(void*);
  202. #endif
  203. /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  204. #ifdef CARLA_PROPER_CPP11_SUPPORT
  205. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  206. private: \
  207. static void* operator new(std::size_t) = delete;
  208. #else
  209. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  210. private: \
  211. static void* operator new(std::size_t);
  212. #endif
  213. /* Define CARLA_API */
  214. #ifdef BUILD_BRIDGE
  215. # define CARLA_API
  216. #else
  217. # if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  218. # ifdef BUILDING_CARLA
  219. # define CARLA_API __declspec (dllexport)
  220. # else
  221. # define CARLA_API __declspec (dllimport)
  222. # endif
  223. # else
  224. # define CARLA_API __attribute__ ((visibility("default")))
  225. # endif
  226. #endif
  227. /* Define CARLA_EXTERN_C */
  228. #ifdef __cplusplus
  229. # define CARLA_EXTERN_C extern "C"
  230. #else
  231. # define CARLA_EXTERN_C
  232. #endif
  233. /* Define CARLA_EXPORT */
  234. #ifdef BUILD_BRIDGE
  235. # define CARLA_EXPORT CARLA_EXTERN_C
  236. #else
  237. # if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  238. # define CARLA_EXPORT CARLA_EXTERN_C CARLA_API
  239. # else
  240. # define CARLA_EXPORT CARLA_EXTERN_C CARLA_API
  241. # endif
  242. #endif
  243. /* Define CARLA_OS_SEP */
  244. #ifdef CARLA_OS_WIN
  245. # define CARLA_OS_SEP '\\'
  246. # define CARLA_OS_SEP_STR "\\"
  247. # define CARLA_OS_SPLIT ';'
  248. # define CARLA_OS_SPLIT_STR ";"
  249. #else
  250. # define CARLA_OS_SEP '/'
  251. # define CARLA_OS_SEP_STR "/"
  252. # define CARLA_OS_SPLIT ':'
  253. # define CARLA_OS_SPLIT_STR ":"
  254. #endif
  255. /* Useful typedefs */
  256. typedef unsigned char uchar;
  257. typedef unsigned long int ulong;
  258. typedef unsigned short int ushort;
  259. typedef unsigned int uint;
  260. #endif /* CARLA_DEFINES_H_INCLUDED */