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