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.

257 lines
8.4KB

  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 0x01095
  32. #define CARLA_VERSION_STRING "1.9.5 (2.0-beta3)"
  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 "%I64i"
  80. # define P_UINT64 "%I64u"
  81. # define P_INTPTR "%I64i"
  82. # define P_UINTPTR "%llx"
  83. # define P_SIZE "%I64u"
  84. #elif defined(CARLA_OS_WIN32)
  85. # define P_INT64 "%I64i"
  86. # define P_UINT64 "%I64u"
  87. # define P_INTPTR "%i"
  88. # define P_UINTPTR "%x"
  89. # define P_SIZE "%u"
  90. #elif defined(CARLA_OS_MAC) && defined(__LP64__)
  91. # define P_INT64 "%lli"
  92. # define P_UINT64 "%llu"
  93. # define P_INTPTR "%li"
  94. # define P_UINTPTR "%lx"
  95. # define P_SIZE "%lu"
  96. #elif defined(__WORDSIZE) && __WORDSIZE == 64
  97. # define P_INT64 "%li"
  98. # define P_UINT64 "%lu"
  99. # define P_INTPTR "%li"
  100. # define P_UINTPTR "%lx"
  101. # define P_SIZE "%lu"
  102. #else
  103. # define P_INT64 "%lli"
  104. # define P_UINT64 "%llu"
  105. # define P_INTPTR "%i"
  106. # define P_UINTPTR "%x"
  107. # define P_SIZE "%u"
  108. #endif
  109. /* Define BINARY_NATIVE */
  110. #if defined(CARLA_OS_HAIKU) || defined(CARLA_OS_UNIX)
  111. # if defined(__LP64__) || defined(_LP64) || defined(__arm64__)
  112. # define BINARY_NATIVE BINARY_POSIX64
  113. # else
  114. # define BINARY_NATIVE BINARY_POSIX32
  115. # endif
  116. #elif defined(CARLA_OS_WIN)
  117. # ifdef CARLA_OS_WIN64
  118. # define BINARY_NATIVE BINARY_WIN64
  119. # else
  120. # define BINARY_NATIVE BINARY_WIN32
  121. # endif
  122. #else
  123. # warning Unknown native binary type
  124. # define BINARY_NATIVE BINARY_OTHER
  125. #endif
  126. /* Define CARLA_ASSERT* */
  127. #if defined(CARLA_NO_ASSERTS)
  128. # define CARLA_ASSERT(cond)
  129. # define CARLA_ASSERT_INT(cond, value)
  130. # define CARLA_ASSERT_INT2(cond, v1, v2)
  131. #elif defined(NDEBUG)
  132. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  133. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  134. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  135. #else
  136. # define CARLA_ASSERT(cond) assert(cond)
  137. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  138. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  139. #endif
  140. /* Define CARLA_SAFE_ASSERT* */
  141. #define CARLA_SAFE_ASSERT(cond) if (! (cond)) carla_safe_assert (#cond, __FILE__, __LINE__);
  142. #define CARLA_SAFE_ASSERT_INT(cond, value) if (! (cond)) carla_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  143. #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));
  144. #define CARLA_SAFE_ASSERT_UINT(cond, value) if (! (cond)) carla_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  145. #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));
  146. #define CARLA_SAFE_ASSERT_BREAK(cond) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); break; }
  147. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); continue; }
  148. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  149. /* Define CARLA_SAFE_EXCEPTION */
  150. #define CARLA_SAFE_EXCEPTION(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); }
  151. #define CARLA_SAFE_EXCEPTION_BREAK(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); break; }
  152. #define CARLA_SAFE_EXCEPTION_CONTINUE(msg) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); continue; }
  153. #define CARLA_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { carla_safe_exception(msg, __FILE__, __LINE__); return ret; }
  154. /* Define CARLA_DECLARE_NON_COPY_CLASS */
  155. #ifdef CARLA_PROPER_CPP11_SUPPORT
  156. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  157. private: \
  158. ClassName(ClassName&) = delete; \
  159. ClassName(const ClassName&) = delete; \
  160. ClassName& operator=(ClassName&) = delete; \
  161. ClassName& operator=(const ClassName&) = delete;
  162. #else
  163. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  164. private: \
  165. ClassName(ClassName&); \
  166. ClassName(const ClassName&); \
  167. ClassName& operator=(ClassName&); \
  168. ClassName& operator=(const ClassName&);
  169. #endif
  170. /* Define CARLA_DECLARE_NON_COPY_STRUCT */
  171. #ifdef CARLA_PROPER_CPP11_SUPPORT
  172. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName) \
  173. StructName(StructName&) = delete; \
  174. StructName(const StructName&) = delete; \
  175. StructName& operator=(StructName&) = delete; \
  176. StructName& operator=(const StructName&) = delete;
  177. #else
  178. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName)
  179. #endif
  180. /* Define CARLA_PREVENT_HEAP_ALLOCATION */
  181. #ifdef CARLA_PROPER_CPP11_SUPPORT
  182. # define CARLA_PREVENT_HEAP_ALLOCATION \
  183. private: \
  184. static void* operator new(std::size_t) = delete; \
  185. static void operator delete(void*) = delete;
  186. #else
  187. # define CARLA_PREVENT_HEAP_ALLOCATION \
  188. private: \
  189. static void* operator new(std::size_t); \
  190. static void operator delete(void*);
  191. #endif
  192. /* Define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  193. #ifdef CARLA_PROPER_CPP11_SUPPORT
  194. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  195. private: \
  196. static void* operator new(std::size_t) = delete;
  197. #else
  198. # define CARLA_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  199. private: \
  200. static void* operator new(std::size_t);
  201. #endif
  202. /* Define CARLA_EXTERN_C */
  203. #ifdef __cplusplus
  204. # define CARLA_EXTERN_C extern "C"
  205. #else
  206. # define CARLA_EXTERN_C
  207. #endif
  208. /* Define CARLA_EXPORT */
  209. #ifdef BUILD_BRIDGE
  210. # define CARLA_EXPORT CARLA_EXTERN_C
  211. #else
  212. # if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  213. # define CARLA_EXPORT CARLA_EXTERN_C __declspec (dllexport)
  214. # else
  215. # define CARLA_EXPORT CARLA_EXTERN_C __attribute__ ((visibility("default")))
  216. # endif
  217. #endif
  218. /* Define CARLA_OS_SEP */
  219. #ifdef CARLA_OS_WIN
  220. # define CARLA_OS_SEP '\\'
  221. # define CARLA_OS_SEP_STR "\\"
  222. #else
  223. # define CARLA_OS_SEP '/'
  224. # define CARLA_OS_SEP_STR "/"
  225. #endif
  226. /* Useful typedefs */
  227. typedef unsigned char uchar;
  228. typedef unsigned long int ulong;
  229. typedef unsigned short int ushort;
  230. typedef unsigned int uint;
  231. #endif /* CARLA_DEFINES_H_INCLUDED */