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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 XmlElement;
  69. class var;
  70. //==============================================================================
  71. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  72. /** A platform-independent 8-bit signed integer type. */
  73. typedef signed char int8;
  74. /** A platform-independent 8-bit unsigned integer type. */
  75. typedef unsigned char uint8;
  76. /** A platform-independent 16-bit signed integer type. */
  77. typedef signed short int16;
  78. /** A platform-independent 16-bit unsigned integer type. */
  79. typedef unsigned short uint16;
  80. /** A platform-independent 32-bit signed integer type. */
  81. typedef signed int int32;
  82. /** A platform-independent 32-bit unsigned integer type. */
  83. typedef unsigned int uint32;
  84. /** A platform-independent 64-bit integer type. */
  85. typedef long long int64;
  86. /** A platform-independent 64-bit unsigned integer type. */
  87. typedef unsigned long long uint64;
  88. #ifdef CARLA_OS_64BIT
  89. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  90. typedef int64 pointer_sized_int;
  91. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  92. typedef uint64 pointer_sized_uint;
  93. #else
  94. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  95. typedef int pointer_sized_int;
  96. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  97. typedef unsigned int pointer_sized_uint;
  98. #endif
  99. //==============================================================================
  100. namespace NumberToStringConverters
  101. {
  102. enum
  103. {
  104. charsNeededForInt = 32,
  105. charsNeededForDouble = 48
  106. };
  107. template <typename Type>
  108. static inline
  109. char* printDigits (char* t, Type v) noexcept
  110. {
  111. *--t = 0;
  112. do
  113. {
  114. *--t = static_cast<char>('0' + (v % 10));
  115. v /= 10;
  116. } while (v > 0);
  117. return t;
  118. }
  119. // pass in a pointer to the END of a buffer..
  120. static inline
  121. char* numberToString (char* t, const int64 n) noexcept
  122. {
  123. if (n >= 0)
  124. return printDigits (t, static_cast<uint64> (n));
  125. // NB: this needs to be careful not to call -std::numeric_limits<int64>::min(),
  126. // which has undefined behaviour
  127. t = printDigits (t, static_cast<uint64> (-(n + 1)) + 1);
  128. *--t = '-';
  129. return t;
  130. }
  131. }
  132. //==============================================================================
  133. /** This namespace contains a few template classes for helping work out class type variations.
  134. */
  135. namespace TypeHelpers
  136. {
  137. /** The ParameterType struct is used to find the best type to use when passing some kind
  138. of object as a parameter.
  139. Of course, this is only likely to be useful in certain esoteric template situations.
  140. Because "typename TypeHelpers::ParameterType<SomeClass>::type" is a bit of a mouthful, there's
  141. a PARAMETER_TYPE(SomeClass) macro that you can use to get the same effect.
  142. E.g. "myFunction (PARAMETER_TYPE (int), PARAMETER_TYPE (MyObject))"
  143. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  144. pass-by-value, but passing objects as a const reference, to avoid copying.
  145. */
  146. template <typename Type> struct ParameterType { typedef const Type& type; };
  147. template <typename Type> struct ParameterType <Type&> { typedef Type& type; };
  148. template <typename Type> struct ParameterType <Type*> { typedef Type* type; };
  149. template <> struct ParameterType <char> { typedef char type; };
  150. template <> struct ParameterType <unsigned char> { typedef unsigned char type; };
  151. template <> struct ParameterType <short> { typedef short type; };
  152. template <> struct ParameterType <unsigned short> { typedef unsigned short type; };
  153. template <> struct ParameterType <int> { typedef int type; };
  154. template <> struct ParameterType <unsigned int> { typedef unsigned int type; };
  155. template <> struct ParameterType <long> { typedef long type; };
  156. template <> struct ParameterType <unsigned long> { typedef unsigned long type; };
  157. template <> struct ParameterType <int64> { typedef int64 type; };
  158. template <> struct ParameterType <uint64> { typedef uint64 type; };
  159. template <> struct ParameterType <bool> { typedef bool type; };
  160. template <> struct ParameterType <float> { typedef float type; };
  161. template <> struct ParameterType <double> { typedef double type; };
  162. /** A helpful macro to simplify the use of the ParameterType template.
  163. @see ParameterType
  164. */
  165. #define PARAMETER_TYPE(a) typename TypeHelpers::ParameterType<a>::type
  166. /** These templates are designed to take a type, and if it's a double, they return a double
  167. type; for anything else, they return a float type.
  168. */
  169. template <typename Type> struct SmallestFloatType { typedef float type; };
  170. template <> struct SmallestFloatType <double> { typedef double type; };
  171. }
  172. }
  173. #endif // WATER_H_INCLUDED