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.

270 lines
8.7KB

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