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.

209 lines
6.2KB

  1. /*
  2. * Carla common defines
  3. * Copyright (C) 2011-2013 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_HPP_INCLUDED
  18. #define CARLA_DEFINES_HPP_INCLUDED
  19. // Check OS
  20. #if defined(WIN64) || defined(_WIN64) || defined(__WIN64__)
  21. # define CARLA_OS_WIN64
  22. #elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
  23. # define CARLA_OS_WIN32
  24. #elif defined(__APPLE__)
  25. # define CARLA_OS_MAC
  26. #elif defined(__HAIKU__)
  27. # define CARLA_OS_HAIKU
  28. #elif defined(__linux__) || defined(__linux)
  29. # define CARLA_OS_LINUX
  30. #else
  31. # warning Unsupported platform!
  32. #endif
  33. #if defined(CARLA_OS_WIN32) || defined(CARLA_OS_WIN64)
  34. # define CARLA_OS_WIN
  35. #elif ! defined(CARLA_OS_HAIKU)
  36. # define CARLA_OS_UNIX
  37. #endif
  38. // Check for C++11 support
  39. #if defined(HAVE_CPP11_SUPPORT)
  40. # define CARLA_PROPER_CPP11_SUPPORT
  41. #elif defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__)
  42. # if (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
  43. # define CARLA_PROPER_CPP11_SUPPORT
  44. # if (__GNUC__ * 100 + __GNUC_MINOR__) < 407
  45. # define override // gcc4.7+ only
  46. # define final // gcc4.7+ only
  47. # endif
  48. # endif
  49. #endif
  50. #ifndef CARLA_PROPER_CPP11_SUPPORT
  51. # define override
  52. # define final
  53. # define noexcept
  54. # define nullptr (0)
  55. #endif
  56. // Common includes
  57. #ifdef CARLA_OS_WIN
  58. # include <winsock2.h>
  59. # include <windows.h>
  60. #else
  61. # include <unistd.h>
  62. # ifndef __cdecl
  63. # define __cdecl
  64. # endif
  65. #endif
  66. // Define various string format types
  67. #if defined(CARLA_OS_WIN64)
  68. # define P_INT64 "%I64i"
  69. # define P_INTPTR "%I64i"
  70. # define P_UINTPTR "%I64x"
  71. # define P_SIZE "%I64u"
  72. #elif defined(CARLA_OS_WIN32)
  73. # define P_INT64 "%I64i"
  74. # define P_INTPTR "%i"
  75. # define P_UINTPTR "%x"
  76. # define P_SIZE "%u"
  77. #elif __WORDSIZE == 64
  78. # define P_INT64 "%li"
  79. # define P_INTPTR "%li"
  80. # define P_UINTPTR "%lx"
  81. # define P_SIZE "%lu"
  82. #else
  83. # define P_INT64 "%lli"
  84. # define P_INTPTR "%i"
  85. # define P_UINTPTR "%x"
  86. # define P_SIZE "%u"
  87. #endif
  88. // Define BINARY_NATIVE
  89. #if defined(CARLA_OS_HAIKU) || defined(CARLA_OS_UNIX)
  90. # if defined (__LP64__) || defined (_LP64)
  91. # define BINARY_NATIVE BINARY_POSIX64
  92. # else
  93. # define BINARY_NATIVE BINARY_POSIX32
  94. # endif
  95. #elif defined(CARLA_OS_WIN)
  96. # ifdef CARLA_OS_WIN64
  97. # define BINARY_NATIVE BINARY_WIN64
  98. # else
  99. # define BINARY_NATIVE BINARY_WIN32
  100. # endif
  101. #else
  102. # warning Unknown binary native
  103. # define BINARY_NATIVE BINARY_OTHER
  104. #endif
  105. // Define CARLA_ASSERT*
  106. #if defined(CARLA_NO_ASSERTS)
  107. # define CARLA_ASSERT(cond)
  108. # define CARLA_ASSERT_INT(cond, value)
  109. # define CARLA_ASSERT_INT2(cond, v1, v2)
  110. #elif defined(NDEBUG)
  111. # define CARLA_ASSERT CARLA_SAFE_ASSERT
  112. # define CARLA_ASSERT_INT CARLA_SAFE_ASSERT_INT
  113. # define CARLA_ASSERT_INT2 CARLA_SAFE_ASSERT_INT2
  114. #else
  115. # define CARLA_ASSERT(cond) assert(cond)
  116. # define CARLA_ASSERT_INT(cond, value) assert(cond)
  117. # define CARLA_ASSERT_INT2(cond, v1, v2) assert(cond)
  118. #endif
  119. // Define CARLA_SAFE_ASSERT*
  120. #define CARLA_SAFE_ASSERT(cond) if (cond) pass(); else carla_assert (#cond, __FILE__, __LINE__);
  121. #define CARLA_SAFE_ASSERT_INT(cond, value) if (cond) pass(); else carla_assert_int (#cond, __FILE__, __LINE__, value);
  122. #define CARLA_SAFE_ASSERT_INT2(cond, v1, v2) if (cond) pass(); else carla_assert_int2(#cond, __FILE__, __LINE__, v1, v2);
  123. #define CARLA_SAFE_ASSERT_CONTINUE(cond) if (cond) pass(); else { carla_assert(#cond, __FILE__, __LINE__); continue; }
  124. #define CARLA_SAFE_ASSERT_RETURN(cond, ret) if (cond) pass(); else { carla_assert(#cond, __FILE__, __LINE__); return ret; }
  125. // Define CARLA_DECLARE_NON_COPY_CLASS
  126. #ifdef CARLA_PROPER_CPP11_SUPPORT
  127. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  128. private: \
  129. ClassName(ClassName&) = delete; \
  130. ClassName(const ClassName&) = delete; \
  131. ClassName& operator=(ClassName&) = delete; \
  132. ClassName& operator=(const ClassName&) = delete;
  133. #else
  134. # define CARLA_DECLARE_NON_COPY_CLASS(ClassName) \
  135. private: \
  136. ClassName(ClassName&); \
  137. ClassName(const ClassName&); \
  138. ClassName& operator=(ClassName&); \
  139. ClassName& operator=(const ClassName&);
  140. #endif
  141. // Define CARLA_DECLARE_NON_COPY_STRUCT
  142. #ifdef CARLA_PROPER_CPP11_SUPPORT
  143. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName) \
  144. StructName(StructName&) = delete; \
  145. StructName(const StructName&) = delete; \
  146. StructName& operator=(StructName&) = delete; \
  147. StructName& operator=(const StructName&) = delete;
  148. #else
  149. # define CARLA_DECLARE_NON_COPY_STRUCT(StructName)
  150. #endif
  151. #ifdef CARLA_PROPER_CPP11_SUPPORT
  152. # define CARLA_PREVENT_HEAP_ALLOCATION \
  153. private: \
  154. static void* operator new(size_t) = delete; \
  155. static void operator delete(void*) = delete;
  156. #else
  157. # define CARLA_PREVENT_HEAP_ALLOCATION \
  158. private: \
  159. static void* operator new(size_t); \
  160. static void operator delete(void*);
  161. #endif
  162. // Define CARLA_EXPORT
  163. #ifdef BUILD_BRIDGE
  164. # define CARLA_EXPORT extern "C"
  165. #else
  166. # if defined(CARLA_OS_WIN) && ! defined(__WINE__)
  167. # define CARLA_EXPORT extern "C" __declspec (dllexport)
  168. # else
  169. # define CARLA_EXPORT extern "C" __attribute__ ((visibility("default")))
  170. # endif
  171. #endif
  172. // Define PRE/POST_PACKED_STRUCTURE
  173. #if defined(__GNUC__)
  174. # define PRE_PACKED_STRUCTURE
  175. # define POST_PACKED_STRUCTURE __attribute__((__packed__))
  176. #elif defined(_MSC_VER)
  177. # define PRE_PACKED_STRUCTURE1 __pragma(pack(push,1))
  178. # define PRE_PACKED_STRUCTURE PRE_PACKED_STRUCTURE1
  179. # define POST_PACKED_STRUCTURE ;__pragma(pack(pop))
  180. #else
  181. # define PRE_PACKED_STRUCTURE
  182. # define POST_PACKED_STRUCTURE
  183. #endif
  184. // Define OS_SEP
  185. #ifdef CARLA_OS_WIN
  186. # define OS_SEP '\\'
  187. #else
  188. # define OS_SEP '/'
  189. #endif
  190. #endif // CARLA_DEFINES_HPP_INCLUDED