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.

water.h 8.9KB

6 years ago
7 years ago
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 wassertfalse carla_safe_assert("wassertfalse triggered", __FILE__, __LINE__);
  23. #define wassert(expression) CARLA_SAFE_ASSERT(expression)
  24. #define static_wassert(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_implicit_moves) && __clang_major__ >= 9
  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. // FIXME
  53. /* WATER_PACKED needs to be a macro which
  54. expands into a compiler directive. The directive must
  55. tell the compiler to arrange the preceding structure
  56. declaration so that it is packed on byte-boundaries rather
  57. than use the natural alignment of the processor and/or
  58. compiler.
  59. */
  60. #if defined(__GNUC__)
  61. #define WATER_PACKED __attribute__((__packed__))
  62. #elif defined(_MSC_VER)
  63. #define WATER_PACKED ;__pragma(pack(pop))
  64. #else
  65. #define WATER_PACKED
  66. #endif
  67. //==============================================================================
  68. namespace water
  69. {
  70. class AudioProcessor;
  71. class AudioSampleBuffer;
  72. class File;
  73. class FileInputStream;
  74. class FileInputSource;
  75. class FileOutputStream;
  76. class Identifier;
  77. class InputStream;
  78. class MidiBuffer;
  79. class MidiMessage;
  80. class MemoryBlock;
  81. class MemoryOutputStream;
  82. class NewLine;
  83. class OutputStream;
  84. class Result;
  85. class String;
  86. class StringArray;
  87. class StringRef;
  88. class Time;
  89. class XmlElement;
  90. class var;
  91. //==============================================================================
  92. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  93. /** A platform-independent 8-bit signed integer type. */
  94. typedef signed char int8;
  95. /** A platform-independent 8-bit unsigned integer type. */
  96. typedef unsigned char uint8;
  97. /** A platform-independent 16-bit signed integer type. */
  98. typedef signed short int16;
  99. /** A platform-independent 16-bit unsigned integer type. */
  100. typedef unsigned short uint16;
  101. /** A platform-independent 32-bit signed integer type. */
  102. typedef signed int int32;
  103. /** A platform-independent 32-bit unsigned integer type. */
  104. typedef unsigned int uint32;
  105. /** A platform-independent 64-bit integer type. */
  106. typedef long long int64;
  107. /** A platform-independent 64-bit unsigned integer type. */
  108. typedef unsigned long long uint64;
  109. #ifdef CARLA_OS_64BIT
  110. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  111. typedef int64 pointer_sized_int;
  112. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  113. typedef uint64 pointer_sized_uint;
  114. #else
  115. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  116. typedef int pointer_sized_int;
  117. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  118. typedef unsigned int pointer_sized_uint;
  119. #endif
  120. //==============================================================================
  121. namespace NumberToStringConverters
  122. {
  123. enum
  124. {
  125. charsNeededForInt = 32,
  126. charsNeededForDouble = 48
  127. };
  128. template <typename Type>
  129. static inline
  130. char* printDigits (char* t, Type v) noexcept
  131. {
  132. *--t = 0;
  133. do
  134. {
  135. *--t = static_cast<char>('0' + (v % 10));
  136. v /= 10;
  137. } while (v > 0);
  138. return t;
  139. }
  140. // pass in a pointer to the END of a buffer..
  141. static inline
  142. char* numberToString (char* t, const int64 n) noexcept
  143. {
  144. if (n >= 0)
  145. return printDigits (t, static_cast<uint64> (n));
  146. // NB: this needs to be careful not to call -std::numeric_limits<int64>::min(),
  147. // which has undefined behaviour
  148. t = printDigits (t, static_cast<uint64> (-(n + 1)) + 1);
  149. *--t = '-';
  150. return t;
  151. }
  152. }
  153. //==============================================================================
  154. /** This namespace contains a few template classes for helping work out class type variations.
  155. */
  156. namespace TypeHelpers
  157. {
  158. /** The ParameterType struct is used to find the best type to use when passing some kind
  159. of object as a parameter.
  160. Of course, this is only likely to be useful in certain esoteric template situations.
  161. Because "typename TypeHelpers::ParameterType<SomeClass>::type" is a bit of a mouthful, there's
  162. a PARAMETER_TYPE(SomeClass) macro that you can use to get the same effect.
  163. E.g. "myFunction (PARAMETER_TYPE (int), PARAMETER_TYPE (MyObject))"
  164. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  165. pass-by-value, but passing objects as a const reference, to avoid copying.
  166. */
  167. template <typename Type> struct ParameterType { typedef const Type& type; };
  168. template <typename Type> struct ParameterType <Type&> { typedef Type& type; };
  169. template <typename Type> struct ParameterType <Type*> { typedef Type* type; };
  170. template <> struct ParameterType <char> { typedef char type; };
  171. template <> struct ParameterType <unsigned char> { typedef unsigned char type; };
  172. template <> struct ParameterType <short> { typedef short type; };
  173. template <> struct ParameterType <unsigned short> { typedef unsigned short type; };
  174. template <> struct ParameterType <int> { typedef int type; };
  175. template <> struct ParameterType <unsigned int> { typedef unsigned int type; };
  176. template <> struct ParameterType <long> { typedef long type; };
  177. template <> struct ParameterType <unsigned long> { typedef unsigned long type; };
  178. template <> struct ParameterType <int64> { typedef int64 type; };
  179. template <> struct ParameterType <uint64> { typedef uint64 type; };
  180. template <> struct ParameterType <bool> { typedef bool type; };
  181. template <> struct ParameterType <float> { typedef float type; };
  182. template <> struct ParameterType <double> { typedef double type; };
  183. /** A helpful macro to simplify the use of the ParameterType template.
  184. @see ParameterType
  185. */
  186. #define PARAMETER_TYPE(a) typename TypeHelpers::ParameterType<a>::type
  187. /** These templates are designed to take a type, and if it's a double, they return a double
  188. type; for anything else, they return a float type.
  189. */
  190. template <typename Type> struct SmallestFloatType { typedef float type; };
  191. template <> struct SmallestFloatType <double> { typedef double type; };
  192. }
  193. }
  194. #endif // WATER_H_INCLUDED