Collection of DPF-based plugins for packaging
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.

216 lines
11KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DISTRHO_DEFINES_H_INCLUDED
  17. #define DISTRHO_DEFINES_H_INCLUDED
  18. /* Compatibility with non-clang compilers */
  19. #ifndef __has_feature
  20. # define __has_feature(x) 0
  21. #endif
  22. #ifndef __has_extension
  23. # define __has_extension __has_feature
  24. #endif
  25. /* Check OS */
  26. #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
  27. # define DISTRHO_PLUGIN_EXPORT extern "C" __declspec (dllexport)
  28. # define DISTRHO_OS_WINDOWS 1
  29. # define DISTRHO_DLL_EXTENSION "dll"
  30. #else
  31. # define DISTRHO_PLUGIN_EXPORT extern "C" __attribute__ ((visibility("default")))
  32. # if defined(__APPLE__)
  33. # define DISTRHO_OS_MAC 1
  34. # define DISTRHO_DLL_EXTENSION "dylib"
  35. # elif defined(__HAIKU__)
  36. # define DISTRHO_OS_HAIKU 1
  37. # elif defined(__linux__) || defined(__linux)
  38. # define DISTRHO_OS_LINUX 1
  39. # elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
  40. # define DISTRHO_OS_BSD 1
  41. # elif defined(__GNU__)
  42. # define DISTRHO_OS_GNU_HURD 1
  43. # endif
  44. #endif
  45. #ifndef DISTRHO_DLL_EXTENSION
  46. # define DISTRHO_DLL_EXTENSION "so"
  47. #endif
  48. /* Check for C++11 support */
  49. #if defined(HAVE_CPP11_SUPPORT)
  50. # if HAVE_CPP11_SUPPORT
  51. # define DISTRHO_PROPER_CPP11_SUPPORT
  52. # endif
  53. #elif __cplusplus >= 201103L || (defined(__GNUC__) && defined(__GXX_EXPERIMENTAL_CXX0X__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405) || __has_extension(cxx_noexcept) || (defined(_MSC_VER) && _MSVC_LANG >= 201103L)
  54. # define DISTRHO_PROPER_CPP11_SUPPORT
  55. # if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) < 407 && ! defined(__clang__)) || (defined(__clang__) && ! __has_extension(cxx_override_control))
  56. # define override /* gcc4.7+ only */
  57. # define final /* gcc4.7+ only */
  58. # endif
  59. #endif
  60. #ifndef DISTRHO_PROPER_CPP11_SUPPORT
  61. # define constexpr
  62. # define noexcept throw()
  63. # define override
  64. # define final
  65. # define nullptr NULL
  66. #endif
  67. /* Define DISTRHO_DEPRECATED */
  68. #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 480
  69. # define DISTRHO_DEPRECATED __attribute__((deprecated))
  70. #elif defined(_MSC_VER)
  71. # define DISTRHO_DEPRECATED [[deprecated]] /* Note: __declspec(deprecated) it not applicable to enum members */
  72. #else
  73. # define DISTRHO_DEPRECATED
  74. #endif
  75. /* Define DISTRHO_DEPRECATED_BY */
  76. #if defined(__clang__) && defined(DISTRHO_PROPER_CPP11_SUPPORT)
  77. # define DISTRHO_DEPRECATED_BY(other) __attribute__((deprecated("", other)))
  78. #elif defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 480
  79. # define DISTRHO_DEPRECATED_BY(other) __attribute__((deprecated("Use " other)))
  80. #else
  81. # define DISTRHO_DEPRECATED_BY(other) DISTRHO_DEPRECATED
  82. #endif
  83. /* Define DISTRHO_SAFE_ASSERT* */
  84. #define DISTRHO_SAFE_ASSERT(cond) if (! (cond)) d_safe_assert (#cond, __FILE__, __LINE__);
  85. #define DISTRHO_SAFE_ASSERT_INT(cond, value) if (! (cond)) d_safe_assert_int (#cond, __FILE__, __LINE__, static_cast<int>(value));
  86. #define DISTRHO_SAFE_ASSERT_INT2(cond, v1, v2) if (! (cond)) d_safe_assert_int2 (#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2));
  87. #define DISTRHO_SAFE_ASSERT_UINT(cond, value) if (! (cond)) d_safe_assert_uint (#cond, __FILE__, __LINE__, static_cast<uint>(value));
  88. #define DISTRHO_SAFE_ASSERT_UINT2(cond, v1, v2) if (! (cond)) d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2));
  89. #define DISTRHO_SAFE_ASSERT_BREAK(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); break; }
  90. #define DISTRHO_SAFE_ASSERT_CONTINUE(cond) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); continue; }
  91. #define DISTRHO_SAFE_ASSERT_RETURN(cond, ret) if (! (cond)) { d_safe_assert(#cond, __FILE__, __LINE__); return ret; }
  92. #define DISTRHO_CUSTOM_SAFE_ASSERT(msg, cond) if (! (cond)) d_custom_safe_assert(msg, #cond, __FILE__, __LINE__);
  93. #define DISTRHO_CUSTOM_SAFE_ASSERT_BREAK(msg, cond) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); break; }
  94. #define DISTRHO_CUSTOM_SAFE_ASSERT_CONTINUE(msg, cond) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); continue; }
  95. #define DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(msg, cond, ret) if (! (cond)) { d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); return ret; }
  96. #define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_BREAK(msg, cond) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } break; }
  97. #define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_CONTINUE(msg, cond) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } continue; }
  98. #define DISTRHO_CUSTOM_SAFE_ASSERT_ONCE_RETURN(msg, cond, ret) if (! (cond)) { static bool _p; if (!_p) { _p = true; d_custom_safe_assert(msg, #cond, __FILE__, __LINE__); } return ret; }
  99. #define DISTRHO_SAFE_ASSERT_INT_BREAK(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); break; }
  100. #define DISTRHO_SAFE_ASSERT_INT_CONTINUE(cond, value) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); continue; }
  101. #define DISTRHO_SAFE_ASSERT_INT_RETURN(cond, value, ret) if (! (cond)) { d_safe_assert_int(#cond, __FILE__, __LINE__, static_cast<int>(value)); return ret; }
  102. #define DISTRHO_SAFE_ASSERT_INT2_BREAK(cond, v1, v2) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); break; }
  103. #define DISTRHO_SAFE_ASSERT_INT2_CONTINUE(cond, v1, v2) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); continue; }
  104. #define DISTRHO_SAFE_ASSERT_INT2_RETURN(cond, v1, v2, ret) if (! (cond)) { d_safe_assert_int2(#cond, __FILE__, __LINE__, static_cast<int>(v1), static_cast<int>(v2)); return ret; }
  105. #define DISTRHO_SAFE_ASSERT_UINT_BREAK(cond, value) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); break; }
  106. #define DISTRHO_SAFE_ASSERT_UINT_CONTINUE(cond, value) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); continue; }
  107. #define DISTRHO_SAFE_ASSERT_UINT_RETURN(cond, value, ret) if (! (cond)) { d_safe_assert_uint(#cond, __FILE__, __LINE__, static_cast<uint>(value)); return ret; }
  108. #define DISTRHO_SAFE_ASSERT_UINT2_BREAK(cond, v1, v2) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); break; }
  109. #define DISTRHO_SAFE_ASSERT_UINT2_CONTINUE(cond, v1, v2) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); continue; }
  110. #define DISTRHO_SAFE_ASSERT_UINT2_RETURN(cond, v1, v2, ret) if (! (cond)) { d_safe_assert_uint2(#cond, __FILE__, __LINE__, static_cast<uint>(v1), static_cast<uint>(v2)); return ret; }
  111. /* Define DISTRHO_SAFE_EXCEPTION */
  112. #define DISTRHO_SAFE_EXCEPTION(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); }
  113. #define DISTRHO_SAFE_EXCEPTION_BREAK(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); break; }
  114. #define DISTRHO_SAFE_EXCEPTION_CONTINUE(msg) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); continue; }
  115. #define DISTRHO_SAFE_EXCEPTION_RETURN(msg, ret) catch(...) { d_safe_exception(msg, __FILE__, __LINE__); return ret; }
  116. /* Define DISTRHO_DECLARE_NON_COPYABLE */
  117. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  118. # define DISTRHO_DECLARE_NON_COPYABLE(ClassName) \
  119. private: \
  120. ClassName(ClassName&) = delete; \
  121. ClassName(const ClassName&) = delete; \
  122. ClassName& operator=(ClassName&) = delete; \
  123. ClassName& operator=(const ClassName&) = delete;
  124. #else
  125. # define DISTRHO_DECLARE_NON_COPYABLE(ClassName) \
  126. private: \
  127. ClassName(ClassName&); \
  128. ClassName(const ClassName&); \
  129. ClassName& operator=(ClassName&); \
  130. ClassName& operator=(const ClassName&);
  131. #endif
  132. /* Define DISTRHO_PREVENT_HEAP_ALLOCATION */
  133. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  134. # define DISTRHO_PREVENT_HEAP_ALLOCATION \
  135. private: \
  136. static void* operator new(size_t) = delete; \
  137. static void operator delete(void*) = delete;
  138. #else
  139. # define DISTRHO_PREVENT_HEAP_ALLOCATION \
  140. private: \
  141. static void* operator new(size_t); \
  142. static void operator delete(void*);
  143. #endif
  144. /* Define DISTRHO_PREVENT_VIRTUAL_HEAP_ALLOCATION */
  145. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  146. # define DISTRHO_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  147. private: \
  148. static void* operator new(std::size_t) = delete;
  149. #else
  150. # define DISTRHO_PREVENT_VIRTUAL_HEAP_ALLOCATION \
  151. private: \
  152. static void* operator new(std::size_t);
  153. #endif
  154. /* Define namespace */
  155. #ifndef DISTRHO_NAMESPACE
  156. # define DISTRHO_NAMESPACE DISTRHO
  157. #endif
  158. #define START_NAMESPACE_DISTRHO namespace DISTRHO_NAMESPACE {
  159. #define END_NAMESPACE_DISTRHO }
  160. #define USE_NAMESPACE_DISTRHO using namespace DISTRHO_NAMESPACE;
  161. /* Define DISTRHO_OS_SEP and DISTRHO_OS_SPLIT */
  162. #ifdef DISTRHO_OS_WINDOWS
  163. # define DISTRHO_OS_SEP '\\'
  164. # define DISTRHO_OS_SEP_STR "\\"
  165. # define DISTRHO_OS_SPLIT ';'
  166. # define DISTRHO_OS_SPLIT_STR ";"
  167. #else
  168. # define DISTRHO_OS_SEP '/'
  169. # define DISTRHO_OS_SEP_STR "/"
  170. # define DISTRHO_OS_SPLIT ':'
  171. # define DISTRHO_OS_SPLIT_STR ":"
  172. #endif
  173. /* MSVC warnings */
  174. #ifdef _MSC_VER
  175. # define strdup _strdup
  176. # pragma warning(disable:4244) /* possible loss of data */
  177. #endif
  178. /* Useful macros */
  179. #define ARRAY_SIZE(ARRAY) sizeof(ARRAY)/sizeof(ARRAY[0])
  180. /* Useful typedefs */
  181. typedef unsigned char uchar;
  182. typedef unsigned short int ushort;
  183. typedef unsigned int uint;
  184. typedef unsigned long int ulong;
  185. /* Deprecated macros */
  186. #define DISTRHO_DECLARE_NON_COPY_CLASS(ClassName) DISTRHO_DECLARE_NON_COPYABLE(ClassName)
  187. #define DISTRHO_DECLARE_NON_COPY_STRUCT(StructName) DISTRHO_DECLARE_NON_COPYABLE(StructName)
  188. #endif // DISTRHO_DEFINES_H_INCLUDED