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.

213 lines
8.3KB

  1. /*
  2. * Cross-platform C++ library for Carla, based on Juce v4
  3. * Copyright (C) 2015-2016 ROLI Ltd.
  4. * Copyright (C) 2017-2018 Filipe Coelho <falktx@falktx.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  17. */
  18. #ifndef WATER_H_INCLUDED
  19. #define WATER_H_INCLUDED
  20. #include "CarlaDefines.h"
  21. //==============================================================================
  22. #define jassertfalse carla_safe_assert("jassertfalse triggered", __FILE__, __LINE__);
  23. #define jassert(expression) CARLA_SAFE_ASSERT(expression)
  24. #define static_jassert(expression) static_assert(expression, #expression);
  25. //==============================================================================
  26. // Compiler support
  27. #if (__cplusplus >= 201103L || defined (__GXX_EXPERIMENTAL_CXX0X__)) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 405
  28. #define WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
  29. #if (__GNUC__ * 100 + __GNUC_MINOR__) >= 407 && ! defined (WATER_DELETED_FUNCTION)
  30. #define WATER_DELETED_FUNCTION = delete
  31. #endif
  32. #endif
  33. #ifdef __clang__
  34. #if __has_feature (cxx_rvalue_references)
  35. #define WATER_COMPILER_SUPPORTS_MOVE_SEMANTICS 1
  36. #endif
  37. #if __has_feature (cxx_deleted_functions)
  38. #define WATER_DELETED_FUNCTION = delete
  39. #endif
  40. #endif
  41. //==============================================================================
  42. // Declare some fake versions of nullptr and noexcept, for older compilers:
  43. #ifndef WATER_DELETED_FUNCTION
  44. /** This macro can be placed after a method declaration to allow the use of
  45. the C++11 feature "= delete" on all compilers.
  46. On newer compilers that support it, it does the C++11 "= delete", but on
  47. older ones it's just an empty definition.
  48. */
  49. #define WATER_DELETED_FUNCTION
  50. #endif
  51. //==============================================================================
  52. namespace water
  53. {
  54. class AudioFormatManager;
  55. class AudioProcessor;
  56. class File;
  57. class FileInputStream;
  58. class FileInputSource;
  59. class FileOutputStream;
  60. class Identifier;
  61. class InputStream;
  62. class MidiBuffer;
  63. class MidiMessage;
  64. class MemoryBlock;
  65. class MemoryOutputStream;
  66. class NewLine;
  67. class OutputStream;
  68. class Result;
  69. class String;
  70. class StringArray;
  71. class StringRef;
  72. class Time;
  73. class XmlElement;
  74. class var;
  75. //==============================================================================
  76. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  77. /** A platform-independent 8-bit signed integer type. */
  78. typedef signed char int8;
  79. /** A platform-independent 8-bit unsigned integer type. */
  80. typedef unsigned char uint8;
  81. /** A platform-independent 16-bit signed integer type. */
  82. typedef signed short int16;
  83. /** A platform-independent 16-bit unsigned integer type. */
  84. typedef unsigned short uint16;
  85. /** A platform-independent 32-bit signed integer type. */
  86. typedef signed int int32;
  87. /** A platform-independent 32-bit unsigned integer type. */
  88. typedef unsigned int uint32;
  89. /** A platform-independent 64-bit integer type. */
  90. typedef long long int64;
  91. /** A platform-independent 64-bit unsigned integer type. */
  92. typedef unsigned long long uint64;
  93. #ifdef CARLA_OS_64BIT
  94. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  95. typedef int64 pointer_sized_int;
  96. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  97. typedef uint64 pointer_sized_uint;
  98. #else
  99. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  100. typedef int pointer_sized_int;
  101. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  102. typedef unsigned int pointer_sized_uint;
  103. #endif
  104. //==============================================================================
  105. namespace NumberToStringConverters
  106. {
  107. enum
  108. {
  109. charsNeededForInt = 32,
  110. charsNeededForDouble = 48
  111. };
  112. template <typename Type>
  113. static inline
  114. char* printDigits (char* t, Type v) noexcept
  115. {
  116. *--t = 0;
  117. do
  118. {
  119. *--t = '0' + (char) (v % 10);
  120. v /= 10;
  121. } while (v > 0);
  122. return t;
  123. }
  124. // pass in a pointer to the END of a buffer..
  125. static inline
  126. char* numberToString (char* t, const int64 n) noexcept
  127. {
  128. if (n >= 0)
  129. return printDigits (t, static_cast<uint64> (n));
  130. // NB: this needs to be careful not to call -std::numeric_limits<int64>::min(),
  131. // which has undefined behaviour
  132. t = printDigits (t, static_cast<uint64> (-(n + 1)) + 1);
  133. *--t = '-';
  134. return t;
  135. }
  136. }
  137. //==============================================================================
  138. /** This namespace contains a few template classes for helping work out class type variations.
  139. */
  140. namespace TypeHelpers
  141. {
  142. /** The ParameterType struct is used to find the best type to use when passing some kind
  143. of object as a parameter.
  144. Of course, this is only likely to be useful in certain esoteric template situations.
  145. Because "typename TypeHelpers::ParameterType<SomeClass>::type" is a bit of a mouthful, there's
  146. a PARAMETER_TYPE(SomeClass) macro that you can use to get the same effect.
  147. E.g. "myFunction (PARAMETER_TYPE (int), PARAMETER_TYPE (MyObject))"
  148. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  149. pass-by-value, but passing objects as a const reference, to avoid copying.
  150. */
  151. template <typename Type> struct ParameterType { typedef const Type& type; };
  152. template <typename Type> struct ParameterType <Type&> { typedef Type& type; };
  153. template <typename Type> struct ParameterType <Type*> { typedef Type* type; };
  154. template <> struct ParameterType <char> { typedef char type; };
  155. template <> struct ParameterType <unsigned char> { typedef unsigned char type; };
  156. template <> struct ParameterType <short> { typedef short type; };
  157. template <> struct ParameterType <unsigned short> { typedef unsigned short type; };
  158. template <> struct ParameterType <int> { typedef int type; };
  159. template <> struct ParameterType <unsigned int> { typedef unsigned int type; };
  160. template <> struct ParameterType <long> { typedef long type; };
  161. template <> struct ParameterType <unsigned long> { typedef unsigned long type; };
  162. template <> struct ParameterType <int64> { typedef int64 type; };
  163. template <> struct ParameterType <uint64> { typedef uint64 type; };
  164. template <> struct ParameterType <bool> { typedef bool type; };
  165. template <> struct ParameterType <float> { typedef float type; };
  166. template <> struct ParameterType <double> { typedef double type; };
  167. /** A helpful macro to simplify the use of the ParameterType template.
  168. @see ParameterType
  169. */
  170. #define PARAMETER_TYPE(a) typename TypeHelpers::ParameterType<a>::type
  171. /** These templates are designed to take a type, and if it's a double, they return a double
  172. type; for anything else, they return a float type.
  173. */
  174. template <typename Type> struct SmallestFloatType { typedef float type; };
  175. template <> struct SmallestFloatType <double> { typedef double type; };
  176. }
  177. }
  178. #endif // WATER_H_INCLUDED