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.

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