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.

282 lines
9.0KB

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