The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

686 lines
25KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /*
  21. This file sets up some handy mathematical typdefs and functions.
  22. */
  23. //==============================================================================
  24. // Definitions for the int8, int16, int32, int64 and pointer_sized_int types.
  25. /** A platform-independent 8-bit signed integer type. */
  26. using int8 = signed char;
  27. /** A platform-independent 8-bit unsigned integer type. */
  28. using uint8 = unsigned char;
  29. /** A platform-independent 16-bit signed integer type. */
  30. using int16 = signed short;
  31. /** A platform-independent 16-bit unsigned integer type. */
  32. using uint16 = unsigned short;
  33. /** A platform-independent 32-bit signed integer type. */
  34. using int32 = signed int;
  35. /** A platform-independent 32-bit unsigned integer type. */
  36. using uint32 = unsigned int;
  37. #if JUCE_MSVC
  38. /** A platform-independent 64-bit integer type. */
  39. using int64 = __int64;
  40. /** A platform-independent 64-bit unsigned integer type. */
  41. using uint64 = unsigned __int64;
  42. #else
  43. /** A platform-independent 64-bit integer type. */
  44. using int64 = long long;
  45. /** A platform-independent 64-bit unsigned integer type. */
  46. using uint64 = unsigned long long;
  47. #endif
  48. #ifndef DOXYGEN
  49. /** A macro for creating 64-bit literals.
  50. Historically, this was needed to support portability with MSVC6, and is kept here
  51. so that old code will still compile, but nowadays every compiler will support the
  52. LL and ULL suffixes, so you should use those in preference to this macro.
  53. */
  54. #define literal64bit(longLiteral) (longLiteral##LL)
  55. #endif
  56. #if JUCE_64BIT
  57. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  58. using pointer_sized_int = int64;
  59. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  60. using pointer_sized_uint = uint64;
  61. #elif JUCE_MSVC
  62. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  63. using pointer_sized_int = _W64 int;
  64. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  65. using pointer_sized_uint = _W64 unsigned int;
  66. #else
  67. /** A signed integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  68. using pointer_sized_int = int;
  69. /** An unsigned integer type that's guaranteed to be large enough to hold a pointer without truncating it. */
  70. using pointer_sized_uint = unsigned int;
  71. #endif
  72. #if JUCE_WINDOWS && ! JUCE_MINGW
  73. using ssize_t = pointer_sized_int;
  74. #endif
  75. //==============================================================================
  76. // Some indispensable min/max functions
  77. /** Returns the larger of two values. */
  78. template <typename Type>
  79. constexpr Type jmax (Type a, Type b) { return a < b ? b : a; }
  80. /** Returns the larger of three values. */
  81. template <typename Type>
  82. constexpr Type jmax (Type a, Type b, Type c) { return a < b ? (b < c ? c : b) : (a < c ? c : a); }
  83. /** Returns the larger of four values. */
  84. template <typename Type>
  85. constexpr Type jmax (Type a, Type b, Type c, Type d) { return jmax (a, jmax (b, c, d)); }
  86. /** Returns the smaller of two values. */
  87. template <typename Type>
  88. constexpr Type jmin (Type a, Type b) { return b < a ? b : a; }
  89. /** Returns the smaller of three values. */
  90. template <typename Type>
  91. constexpr Type jmin (Type a, Type b, Type c) { return b < a ? (c < b ? c : b) : (c < a ? c : a); }
  92. /** Returns the smaller of four values. */
  93. template <typename Type>
  94. constexpr Type jmin (Type a, Type b, Type c, Type d) { return jmin (a, jmin (b, c, d)); }
  95. /** Remaps a normalised value (between 0 and 1) to a target range.
  96. This effectively returns (targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin)).
  97. */
  98. template <typename Type>
  99. constexpr Type jmap (Type value0To1, Type targetRangeMin, Type targetRangeMax)
  100. {
  101. return targetRangeMin + value0To1 * (targetRangeMax - targetRangeMin);
  102. }
  103. /** Remaps a value from a source range to a target range. */
  104. template <typename Type>
  105. Type jmap (Type sourceValue, Type sourceRangeMin, Type sourceRangeMax, Type targetRangeMin, Type targetRangeMax)
  106. {
  107. jassert (sourceRangeMax != sourceRangeMin); // mapping from a range of zero will produce NaN!
  108. return targetRangeMin + ((targetRangeMax - targetRangeMin) * (sourceValue - sourceRangeMin)) / (sourceRangeMax - sourceRangeMin);
  109. }
  110. /** Remaps a normalised value (between 0 and 1) to a logarithmic target range.
  111. The entire target range must be greater than zero.
  112. @see mapFromLog10
  113. @code
  114. mapToLog10 (0.5, 0.4, 40.0) == 4.0
  115. @endcode
  116. */
  117. template <typename Type>
  118. Type mapToLog10 (Type value0To1, Type logRangeMin, Type logRangeMax)
  119. {
  120. jassert (logRangeMin > 0);
  121. jassert (logRangeMax > 0);
  122. auto logMin = std::log10 (logRangeMin);
  123. auto logMax = std::log10 (logRangeMax);
  124. return std::pow ((Type) 10.0, value0To1 * (logMax - logMin) + logMin);
  125. }
  126. /** Remaps a logarithmic value in a target range to a normalised value (between 0 and 1).
  127. The entire target range must be greater than zero.
  128. @see mapToLog10
  129. @code
  130. mapFromLog10 (4.0, 0.4, 40.0) == 0.5
  131. @endcode
  132. */
  133. template <typename Type>
  134. Type mapFromLog10 (Type valueInLogRange, Type logRangeMin, Type logRangeMax)
  135. {
  136. jassert (logRangeMin > 0);
  137. jassert (logRangeMax > 0);
  138. auto logMin = std::log10 (logRangeMin);
  139. auto logMax = std::log10 (logRangeMax);
  140. return (std::log10 (valueInLogRange) - logMin) / (logMax - logMin);
  141. }
  142. /** Scans an array of values, returning the minimum value that it contains. */
  143. template <typename Type>
  144. Type findMinimum (const Type* data, int numValues)
  145. {
  146. if (numValues <= 0)
  147. return Type (0);
  148. auto result = *data++;
  149. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  150. {
  151. auto v = *data++;
  152. if (v < result)
  153. result = v;
  154. }
  155. return result;
  156. }
  157. /** Scans an array of values, returning the maximum value that it contains. */
  158. template <typename Type>
  159. Type findMaximum (const Type* values, int numValues)
  160. {
  161. if (numValues <= 0)
  162. return Type (0);
  163. auto result = *values++;
  164. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  165. {
  166. auto v = *values++;
  167. if (result < v)
  168. result = v;
  169. }
  170. return result;
  171. }
  172. /** Scans an array of values, returning the minimum and maximum values that it contains. */
  173. template <typename Type>
  174. void findMinAndMax (const Type* values, int numValues, Type& lowest, Type& highest)
  175. {
  176. if (numValues <= 0)
  177. {
  178. lowest = Type (0);
  179. highest = Type (0);
  180. }
  181. else
  182. {
  183. auto mn = *values++;
  184. auto mx = mn;
  185. while (--numValues > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  186. {
  187. auto v = *values++;
  188. if (mx < v) mx = v;
  189. if (v < mn) mn = v;
  190. }
  191. lowest = mn;
  192. highest = mx;
  193. }
  194. }
  195. //==============================================================================
  196. /** Constrains a value to keep it within a given range.
  197. This will check that the specified value lies between the lower and upper bounds
  198. specified, and if not, will return the nearest value that would be in-range. Effectively,
  199. it's like calling jmax (lowerLimit, jmin (upperLimit, value)).
  200. Note that it expects that lowerLimit <= upperLimit. If this isn't true,
  201. the results will be unpredictable.
  202. @param lowerLimit the minimum value to return
  203. @param upperLimit the maximum value to return
  204. @param valueToConstrain the value to try to return
  205. @returns the closest value to valueToConstrain which lies between lowerLimit
  206. and upperLimit (inclusive)
  207. @see jmin, jmax, jmap
  208. */
  209. template <typename Type>
  210. Type jlimit (Type lowerLimit,
  211. Type upperLimit,
  212. Type valueToConstrain) noexcept
  213. {
  214. jassert (lowerLimit <= upperLimit); // if these are in the wrong order, results are unpredictable..
  215. return valueToConstrain < lowerLimit ? lowerLimit
  216. : (upperLimit < valueToConstrain ? upperLimit
  217. : valueToConstrain);
  218. }
  219. /** Returns true if a value is at least zero, and also below a specified upper limit.
  220. This is basically a quicker way to write:
  221. @code valueToTest >= 0 && valueToTest < upperLimit
  222. @endcode
  223. */
  224. template <typename Type1, typename Type2>
  225. bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
  226. {
  227. jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
  228. return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
  229. }
  230. template <typename Type>
  231. bool isPositiveAndBelow (int valueToTest, Type upperLimit) noexcept
  232. {
  233. jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
  234. return static_cast<unsigned int> (valueToTest) < static_cast<unsigned int> (upperLimit);
  235. }
  236. /** Returns true if a value is at least zero, and also less than or equal to a specified upper limit.
  237. This is basically a quicker way to write:
  238. @code valueToTest >= 0 && valueToTest <= upperLimit
  239. @endcode
  240. */
  241. template <typename Type1, typename Type2>
  242. bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
  243. {
  244. jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
  245. return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
  246. }
  247. template <typename Type>
  248. bool isPositiveAndNotGreaterThan (int valueToTest, Type upperLimit) noexcept
  249. {
  250. jassert (upperLimit >= 0); // makes no sense to call this if the upper limit is itself below zero..
  251. return static_cast<unsigned int> (valueToTest) <= static_cast<unsigned int> (upperLimit);
  252. }
  253. /** Computes the absolute difference between two values and returns true if it is less than or equal
  254. to a given tolerance, otherwise it returns false.
  255. */
  256. template <typename Type>
  257. bool isWithin (Type a, Type b, Type tolerance) noexcept
  258. {
  259. return std::abs (a - b) <= tolerance;
  260. }
  261. /** Returns true if the two numbers are approximately equal. This is useful for floating-point
  262. and double comparisons.
  263. */
  264. template <typename Type>
  265. bool approximatelyEqual (Type a, Type b) noexcept
  266. {
  267. return std::abs (a - b) <= (std::numeric_limits<Type>::epsilon() * std::max (a, b))
  268. || std::abs (a - b) < std::numeric_limits<Type>::min();
  269. }
  270. //==============================================================================
  271. /** Handy function for avoiding unused variables warning. */
  272. template <typename... Types>
  273. void ignoreUnused (Types&&...) noexcept {}
  274. /** Handy function for getting the number of elements in a simple const C array.
  275. E.g.
  276. @code
  277. static int myArray[] = { 1, 2, 3 };
  278. int numElements = numElementsInArray (myArray) // returns 3
  279. @endcode
  280. */
  281. template <typename Type, size_t N>
  282. constexpr int numElementsInArray (Type (&)[N]) noexcept { return N; }
  283. //==============================================================================
  284. // Some useful maths functions that aren't always present with all compilers and build settings.
  285. /** Using juce_hypot is easier than dealing with the different types of hypot function
  286. that are provided by the various platforms and compilers. */
  287. template <typename Type>
  288. Type juce_hypot (Type a, Type b) noexcept
  289. {
  290. #if JUCE_MSVC
  291. return static_cast<Type> (_hypot (a, b));
  292. #else
  293. return static_cast<Type> (hypot (a, b));
  294. #endif
  295. }
  296. #ifndef DOXYGEN
  297. template <>
  298. inline float juce_hypot (float a, float b) noexcept
  299. {
  300. #if JUCE_MSVC
  301. return _hypotf (a, b);
  302. #else
  303. return hypotf (a, b);
  304. #endif
  305. }
  306. #endif
  307. //==============================================================================
  308. /** Commonly used mathematical constants
  309. @tags{Core}
  310. */
  311. template <typename FloatType>
  312. struct MathConstants
  313. {
  314. /** A predefined value for Pi */
  315. static constexpr FloatType pi = static_cast<FloatType> (3.141592653589793238L);
  316. /** A predefined value for 2 * Pi */
  317. static constexpr FloatType twoPi = static_cast<FloatType> (2 * 3.141592653589793238L);
  318. /** A predefined value for Pi / 2 */
  319. static constexpr FloatType halfPi = static_cast<FloatType> (3.141592653589793238L / 2);
  320. /** A predefined value for Euler's number */
  321. static constexpr FloatType euler = static_cast<FloatType> (2.71828182845904523536L);
  322. /** A predefined value for sqrt(2) */
  323. static constexpr FloatType sqrt2 = static_cast<FloatType> (1.4142135623730950488L);
  324. };
  325. #ifndef DOXYGEN
  326. /** A double-precision constant for pi. */
  327. [[deprecated ("This is deprecated in favour of MathConstants<double>::pi.")]]
  328. const constexpr double double_Pi = MathConstants<double>::pi;
  329. /** A single-precision constant for pi. */
  330. [[deprecated ("This is deprecated in favour of MathConstants<float>::pi.")]]
  331. const constexpr float float_Pi = MathConstants<float>::pi;
  332. #endif
  333. /** Converts an angle in degrees to radians. */
  334. template <typename FloatType>
  335. constexpr FloatType degreesToRadians (FloatType degrees) noexcept { return degrees * (MathConstants<FloatType>::pi / FloatType (180)); }
  336. /** Converts an angle in radians to degrees. */
  337. template <typename FloatType>
  338. constexpr FloatType radiansToDegrees (FloatType radians) noexcept { return radians * (FloatType (180) / MathConstants<FloatType>::pi); }
  339. //==============================================================================
  340. /** The isfinite() method seems to vary between platforms, so this is a
  341. platform-independent function for it.
  342. */
  343. template <typename NumericType>
  344. bool juce_isfinite (NumericType) noexcept
  345. {
  346. return true; // Integer types are always finite
  347. }
  348. template <>
  349. inline bool juce_isfinite (float value) noexcept
  350. {
  351. #if JUCE_WINDOWS && ! JUCE_MINGW
  352. return _finite (value) != 0;
  353. #else
  354. return std::isfinite (value);
  355. #endif
  356. }
  357. template <>
  358. inline bool juce_isfinite (double value) noexcept
  359. {
  360. #if JUCE_WINDOWS && ! JUCE_MINGW
  361. return _finite (value) != 0;
  362. #else
  363. return std::isfinite (value);
  364. #endif
  365. }
  366. //==============================================================================
  367. #if JUCE_MSVC
  368. #pragma optimize ("t", off)
  369. #ifndef __INTEL_COMPILER
  370. #pragma float_control (precise, on, push)
  371. #endif
  372. #endif
  373. /** Fast floating-point-to-integer conversion.
  374. This is faster than using the normal c++ cast to convert a float to an int, and
  375. it will round the value to the nearest integer, rather than rounding it down
  376. like the normal cast does.
  377. Note that this routine gets its speed at the expense of some accuracy, and when
  378. rounding values whose floating point component is exactly 0.5, odd numbers and
  379. even numbers will be rounded up or down differently.
  380. */
  381. template <typename FloatType>
  382. int roundToInt (const FloatType value) noexcept
  383. {
  384. #ifdef __INTEL_COMPILER
  385. #pragma float_control (precise, on, push)
  386. #endif
  387. union { int asInt[2]; double asDouble; } n;
  388. n.asDouble = ((double) value) + 6755399441055744.0;
  389. #if JUCE_BIG_ENDIAN
  390. return n.asInt [1];
  391. #else
  392. return n.asInt [0];
  393. #endif
  394. }
  395. inline int roundToInt (int value) noexcept
  396. {
  397. return value;
  398. }
  399. #if JUCE_MSVC
  400. #ifndef __INTEL_COMPILER
  401. #pragma float_control (pop)
  402. #endif
  403. #pragma optimize ("", on) // resets optimisations to the project defaults
  404. #endif
  405. /** Fast floating-point-to-integer conversion.
  406. This is a slightly slower and slightly more accurate version of roundToInt(). It works
  407. fine for values above zero, but negative numbers are rounded the wrong way.
  408. */
  409. inline int roundToIntAccurate (double value) noexcept
  410. {
  411. #ifdef __INTEL_COMPILER
  412. #pragma float_control (pop)
  413. #endif
  414. return roundToInt (value + 1.5e-8);
  415. }
  416. //==============================================================================
  417. /** Truncates a positive floating-point number to an unsigned int.
  418. This is generally faster than static_cast<unsigned int> (std::floor (x))
  419. but it only works for positive numbers small enough to be represented as an
  420. unsigned int.
  421. */
  422. template <typename FloatType>
  423. unsigned int truncatePositiveToUnsignedInt (FloatType value) noexcept
  424. {
  425. jassert (value >= static_cast<FloatType> (0));
  426. jassert (static_cast<FloatType> (value)
  427. <= static_cast<FloatType> (std::numeric_limits<unsigned int>::max()));
  428. return static_cast<unsigned int> (value);
  429. }
  430. //==============================================================================
  431. /** Returns true if the specified integer is a power-of-two. */
  432. template <typename IntegerType>
  433. constexpr bool isPowerOfTwo (IntegerType value)
  434. {
  435. return (value & (value - 1)) == 0;
  436. }
  437. /** Returns the smallest power-of-two which is equal to or greater than the given integer. */
  438. inline int nextPowerOfTwo (int n) noexcept
  439. {
  440. --n;
  441. n |= (n >> 1);
  442. n |= (n >> 2);
  443. n |= (n >> 4);
  444. n |= (n >> 8);
  445. n |= (n >> 16);
  446. return n + 1;
  447. }
  448. /** Returns the index of the highest set bit in a (non-zero) number.
  449. So for n=3 this would return 1, for n=7 it returns 2, etc.
  450. An input value of 0 is illegal!
  451. */
  452. int findHighestSetBit (uint32 n) noexcept;
  453. /** Returns the number of bits in a 32-bit integer. */
  454. inline int countNumberOfBits (uint32 n) noexcept
  455. {
  456. n -= ((n >> 1) & 0x55555555);
  457. n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
  458. n = (((n >> 4) + n) & 0x0f0f0f0f);
  459. n += (n >> 8);
  460. n += (n >> 16);
  461. return (int) (n & 0x3f);
  462. }
  463. /** Returns the number of bits in a 64-bit integer. */
  464. inline int countNumberOfBits (uint64 n) noexcept
  465. {
  466. return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
  467. }
  468. /** Performs a modulo operation, but can cope with the dividend being negative.
  469. The divisor must be greater than zero.
  470. */
  471. template <typename IntegerType>
  472. IntegerType negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
  473. {
  474. jassert (divisor > 0);
  475. dividend %= divisor;
  476. return (dividend < 0) ? (dividend + divisor) : dividend;
  477. }
  478. /** Returns the square of its argument. */
  479. template <typename NumericType>
  480. inline constexpr NumericType square (NumericType n) noexcept
  481. {
  482. return n * n;
  483. }
  484. //==============================================================================
  485. /** Writes a number of bits into a memory buffer at a given bit index.
  486. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  487. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the value would be written
  488. into bits 2-8 of targetBuffer[1], and the upper 5 bits of value into bits 0-5 of targetBuffer[2].
  489. @see readLittleEndianBitsInBuffer
  490. */
  491. void writeLittleEndianBitsInBuffer (void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
  492. /** Reads a number of bits from a buffer at a given bit index.
  493. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  494. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the result would be read
  495. from bits 2-8 of sourceBuffer[1], and the upper 5 bits of the result from bits 0-5 of sourceBuffer[2].
  496. @see writeLittleEndianBitsInBuffer
  497. */
  498. uint32 readLittleEndianBitsInBuffer (const void* sourceBuffer, uint32 startBit, uint32 numBits) noexcept;
  499. //==============================================================================
  500. #if JUCE_INTEL || DOXYGEN
  501. /** This macro can be applied to a float variable to check whether it contains a denormalised
  502. value, and to normalise it if necessary.
  503. On CPUs that aren't vulnerable to denormalisation problems, this will have no effect.
  504. */
  505. #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
  506. #else
  507. #define JUCE_UNDENORMALISE(x)
  508. #endif
  509. //==============================================================================
  510. /** This namespace contains a few template classes for helping work out class type variations.
  511. */
  512. namespace TypeHelpers
  513. {
  514. /** The ParameterType struct is used to find the best type to use when passing some kind
  515. of object as a parameter.
  516. Of course, this is only likely to be useful in certain esoteric template situations.
  517. E.g. "myFunction (typename TypeHelpers::ParameterType<int>::type, typename TypeHelpers::ParameterType<MyObject>::type)"
  518. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  519. pass-by-value, but passing objects as a const reference, to avoid copying.
  520. @tags{Core}
  521. */
  522. template <typename Type> struct ParameterType { using type = const Type&; };
  523. #ifndef DOXYGEN
  524. template <typename Type> struct ParameterType <Type&> { using type = Type&; };
  525. template <typename Type> struct ParameterType <Type*> { using type = Type*; };
  526. template <> struct ParameterType <char> { using type = char; };
  527. template <> struct ParameterType <unsigned char> { using type = unsigned char; };
  528. template <> struct ParameterType <short> { using type = short; };
  529. template <> struct ParameterType <unsigned short> { using type = unsigned short; };
  530. template <> struct ParameterType <int> { using type = int; };
  531. template <> struct ParameterType <unsigned int> { using type = unsigned int; };
  532. template <> struct ParameterType <long> { using type = long; };
  533. template <> struct ParameterType <unsigned long> { using type = unsigned long; };
  534. template <> struct ParameterType <int64> { using type = int64; };
  535. template <> struct ParameterType <uint64> { using type = uint64; };
  536. template <> struct ParameterType <bool> { using type = bool; };
  537. template <> struct ParameterType <float> { using type = float; };
  538. template <> struct ParameterType <double> { using type = double; };
  539. #endif
  540. /** These templates are designed to take a type, and if it's a double, they return a double
  541. type; for anything else, they return a float type.
  542. @tags{Core}
  543. */
  544. template <typename Type> struct SmallestFloatType { using type = float; };
  545. #ifndef DOXYGEN
  546. template <> struct SmallestFloatType <double> { using type = double; };
  547. #endif
  548. /** These templates are designed to take an integer type, and return an unsigned int
  549. version with the same size.
  550. @tags{Core}
  551. */
  552. template <int bytes> struct UnsignedTypeWithSize {};
  553. #ifndef DOXYGEN
  554. template <> struct UnsignedTypeWithSize<1> { using type = uint8; };
  555. template <> struct UnsignedTypeWithSize<2> { using type = uint16; };
  556. template <> struct UnsignedTypeWithSize<4> { using type = uint32; };
  557. template <> struct UnsignedTypeWithSize<8> { using type = uint64; };
  558. #endif
  559. }
  560. //==============================================================================
  561. #ifndef DOXYGEN
  562. [[deprecated ("Use roundToInt instead.")]] inline int roundDoubleToInt (double value) noexcept { return roundToInt (value); }
  563. [[deprecated ("Use roundToInt instead.")]] inline int roundFloatToInt (float value) noexcept { return roundToInt (value); }
  564. [[deprecated ("Use std::abs() instead.")]] inline int64 abs64 (int64 n) noexcept { return std::abs (n); }
  565. #endif
  566. } // namespace juce