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

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