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.

666 lines
25KB

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