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.

284 lines
9.0KB

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