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.1KB

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