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.

695 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. The reason is that "double_Pi" was a confusing name, and many people misused it,
  329. wrongly thinking it meant 2 * pi !
  330. */
  331. const constexpr double double_Pi = MathConstants<double>::pi;
  332. /** A single-precision constant for pi.
  333. @deprecated This is deprecated in favour of MathConstants<float>::pi.
  334. The reason is that "double_Pi" was a confusing name, and many people misused it,
  335. wrongly thinking it meant 2 * pi !
  336. */
  337. const constexpr float float_Pi = MathConstants<float>::pi;
  338. #endif
  339. /** Converts an angle in degrees to radians. */
  340. template <typename FloatType>
  341. constexpr FloatType degreesToRadians (FloatType degrees) noexcept { return degrees * (MathConstants<FloatType>::pi / FloatType (180)); }
  342. /** Converts an angle in radians to degrees. */
  343. template <typename FloatType>
  344. constexpr FloatType radiansToDegrees (FloatType radians) noexcept { return radians * (FloatType (180) / MathConstants<FloatType>::pi); }
  345. //==============================================================================
  346. /** The isfinite() method seems to vary between platforms, so this is a
  347. platform-independent function for it.
  348. */
  349. template <typename NumericType>
  350. bool juce_isfinite (NumericType) noexcept
  351. {
  352. return true; // Integer types are always finite
  353. }
  354. template <>
  355. inline bool juce_isfinite (float value) noexcept
  356. {
  357. #if JUCE_WINDOWS && ! JUCE_MINGW
  358. return _finite (value) != 0;
  359. #else
  360. return std::isfinite (value);
  361. #endif
  362. }
  363. template <>
  364. inline bool juce_isfinite (double value) noexcept
  365. {
  366. #if JUCE_WINDOWS && ! JUCE_MINGW
  367. return _finite (value) != 0;
  368. #else
  369. return std::isfinite (value);
  370. #endif
  371. }
  372. //==============================================================================
  373. #if JUCE_MSVC
  374. #pragma optimize ("t", off)
  375. #ifndef __INTEL_COMPILER
  376. #pragma float_control (precise, on, push)
  377. #endif
  378. #endif
  379. /** Fast floating-point-to-integer conversion.
  380. This is faster than using the normal c++ cast to convert a float to an int, and
  381. it will round the value to the nearest integer, rather than rounding it down
  382. like the normal cast does.
  383. Note that this routine gets its speed at the expense of some accuracy, and when
  384. rounding values whose floating point component is exactly 0.5, odd numbers and
  385. even numbers will be rounded up or down differently.
  386. */
  387. template <typename FloatType>
  388. int roundToInt (const FloatType value) noexcept
  389. {
  390. #ifdef __INTEL_COMPILER
  391. #pragma float_control (precise, on, push)
  392. #endif
  393. union { int asInt[2]; double asDouble; } n;
  394. n.asDouble = ((double) value) + 6755399441055744.0;
  395. #if JUCE_BIG_ENDIAN
  396. return n.asInt [1];
  397. #else
  398. return n.asInt [0];
  399. #endif
  400. }
  401. inline int roundToInt (int value) noexcept
  402. {
  403. return value;
  404. }
  405. #if JUCE_MSVC
  406. #ifndef __INTEL_COMPILER
  407. #pragma float_control (pop)
  408. #endif
  409. #pragma optimize ("", on) // resets optimisations to the project defaults
  410. #endif
  411. /** Fast floating-point-to-integer conversion.
  412. This is a slightly slower and slightly more accurate version of roundToInt(). It works
  413. fine for values above zero, but negative numbers are rounded the wrong way.
  414. */
  415. inline int roundToIntAccurate (double value) noexcept
  416. {
  417. #ifdef __INTEL_COMPILER
  418. #pragma float_control (pop)
  419. #endif
  420. return roundToInt (value + 1.5e-8);
  421. }
  422. //==============================================================================
  423. /** Truncates a positive floating-point number to an unsigned int.
  424. This is generally faster than static_cast<unsigned int> (std::floor (x))
  425. but it only works for positive numbers small enough to be represented as an
  426. unsigned int.
  427. */
  428. template <typename FloatType>
  429. unsigned int truncatePositiveToUnsignedInt (FloatType value) noexcept
  430. {
  431. jassert (value >= static_cast<FloatType> (0));
  432. jassert (static_cast<FloatType> (value)
  433. <= static_cast<FloatType> (std::numeric_limits<unsigned int>::max()));
  434. return static_cast<unsigned int> (value);
  435. }
  436. //==============================================================================
  437. /** Returns true if the specified integer is a power-of-two. */
  438. template <typename IntegerType>
  439. constexpr bool isPowerOfTwo (IntegerType value)
  440. {
  441. return (value & (value - 1)) == 0;
  442. }
  443. /** Returns the smallest power-of-two which is equal to or greater than the given integer. */
  444. inline int nextPowerOfTwo (int n) noexcept
  445. {
  446. --n;
  447. n |= (n >> 1);
  448. n |= (n >> 2);
  449. n |= (n >> 4);
  450. n |= (n >> 8);
  451. n |= (n >> 16);
  452. return n + 1;
  453. }
  454. /** Returns the index of the highest set bit in a (non-zero) number.
  455. So for n=3 this would return 1, for n=7 it returns 2, etc.
  456. An input value of 0 is illegal!
  457. */
  458. int findHighestSetBit (uint32 n) noexcept;
  459. /** Returns the number of bits in a 32-bit integer. */
  460. inline int countNumberOfBits (uint32 n) noexcept
  461. {
  462. n -= ((n >> 1) & 0x55555555);
  463. n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
  464. n = (((n >> 4) + n) & 0x0f0f0f0f);
  465. n += (n >> 8);
  466. n += (n >> 16);
  467. return (int) (n & 0x3f);
  468. }
  469. /** Returns the number of bits in a 64-bit integer. */
  470. inline int countNumberOfBits (uint64 n) noexcept
  471. {
  472. return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
  473. }
  474. /** Performs a modulo operation, but can cope with the dividend being negative.
  475. The divisor must be greater than zero.
  476. */
  477. template <typename IntegerType>
  478. IntegerType negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
  479. {
  480. jassert (divisor > 0);
  481. dividend %= divisor;
  482. return (dividend < 0) ? (dividend + divisor) : dividend;
  483. }
  484. /** Returns the square of its argument. */
  485. template <typename NumericType>
  486. inline constexpr NumericType square (NumericType n) noexcept
  487. {
  488. return n * n;
  489. }
  490. //==============================================================================
  491. /** Writes a number of bits into a memory buffer at a given bit index.
  492. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  493. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the value would be written
  494. into bits 2-8 of targetBuffer[1], and the upper 5 bits of value into bits 0-5 of targetBuffer[2].
  495. @see readLittleEndianBitsInBuffer
  496. */
  497. void writeLittleEndianBitsInBuffer (void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
  498. /** Reads a number of bits from a buffer at a given bit index.
  499. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  500. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the result would be read
  501. from bits 2-8 of sourceBuffer[1], and the upper 5 bits of the result from bits 0-5 of sourceBuffer[2].
  502. @see writeLittleEndianBitsInBuffer
  503. */
  504. uint32 readLittleEndianBitsInBuffer (const void* sourceBuffer, uint32 startBit, uint32 numBits) noexcept;
  505. //==============================================================================
  506. #if JUCE_INTEL || defined (DOXYGEN)
  507. /** This macro can be applied to a float variable to check whether it contains a denormalised
  508. value, and to normalise it if necessary.
  509. On CPUs that aren't vulnerable to denormalisation problems, this will have no effect.
  510. */
  511. #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
  512. #else
  513. #define JUCE_UNDENORMALISE(x)
  514. #endif
  515. //==============================================================================
  516. /** This namespace contains a few template classes for helping work out class type variations.
  517. */
  518. namespace TypeHelpers
  519. {
  520. /** The ParameterType struct is used to find the best type to use when passing some kind
  521. of object as a parameter.
  522. Of course, this is only likely to be useful in certain esoteric template situations.
  523. E.g. "myFunction (typename TypeHelpers::ParameterType<int>::type, typename TypeHelpers::ParameterType<MyObject>::type)"
  524. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  525. pass-by-value, but passing objects as a const reference, to avoid copying.
  526. @tags{Core}
  527. */
  528. template <typename Type> struct ParameterType { using type = const Type&; };
  529. #if ! DOXYGEN
  530. template <typename Type> struct ParameterType <Type&> { using type = Type&; };
  531. template <typename Type> struct ParameterType <Type*> { using type = Type*; };
  532. template <> struct ParameterType <char> { using type = char; };
  533. template <> struct ParameterType <unsigned char> { using type = unsigned char; };
  534. template <> struct ParameterType <short> { using type = short; };
  535. template <> struct ParameterType <unsigned short> { using type = unsigned short; };
  536. template <> struct ParameterType <int> { using type = int; };
  537. template <> struct ParameterType <unsigned int> { using type = unsigned int; };
  538. template <> struct ParameterType <long> { using type = long; };
  539. template <> struct ParameterType <unsigned long> { using type = unsigned long; };
  540. template <> struct ParameterType <int64> { using type = int64; };
  541. template <> struct ParameterType <uint64> { using type = uint64; };
  542. template <> struct ParameterType <bool> { using type = bool; };
  543. template <> struct ParameterType <float> { using type = float; };
  544. template <> struct ParameterType <double> { using type = double; };
  545. #endif
  546. /** These templates are designed to take a type, and if it's a double, they return a double
  547. type; for anything else, they return a float type.
  548. @tags{Core}
  549. */
  550. template <typename Type> struct SmallestFloatType { using type = float; };
  551. #if ! DOXYGEN
  552. template <> struct SmallestFloatType <double> { using type = double; };
  553. #endif
  554. /** These templates are designed to take an integer type, and return an unsigned int
  555. version with the same size.
  556. @tags{Core}
  557. */
  558. template <int bytes> struct UnsignedTypeWithSize {};
  559. #if ! DOXYGEN
  560. template <> struct UnsignedTypeWithSize<1> { using type = uint8; };
  561. template <> struct UnsignedTypeWithSize<2> { using type = uint16; };
  562. template <> struct UnsignedTypeWithSize<4> { using type = uint32; };
  563. template <> struct UnsignedTypeWithSize<8> { using type = uint64; };
  564. #endif
  565. }
  566. //==============================================================================
  567. #if ! DOXYGEN
  568. // These old functions are deprecated: Just use roundToInt instead.
  569. JUCE_DEPRECATED_ATTRIBUTE inline int roundDoubleToInt (double value) noexcept { return roundToInt (value); }
  570. JUCE_DEPRECATED_ATTRIBUTE inline int roundFloatToInt (float value) noexcept { return roundToInt (value); }
  571. // This old function isn't needed - just use std::abs() instead
  572. JUCE_DEPRECATED_ATTRIBUTE inline int64 abs64 (int64 n) noexcept { return std::abs (n); }
  573. #endif
  574. } // namespace juce