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.

659 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 (Type lowerLimit,
  177. Type upperLimit,
  178. 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 Type1, typename Type2>
  191. bool isPositiveAndBelow (Type1 valueToTest, Type2 upperLimit) noexcept
  192. {
  193. jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
  194. return Type1() <= valueToTest && valueToTest < static_cast<Type1> (upperLimit);
  195. }
  196. template <typename Type>
  197. bool isPositiveAndBelow (int valueToTest, Type 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 Type1, typename Type2>
  208. bool isPositiveAndNotGreaterThan (Type1 valueToTest, Type2 upperLimit) noexcept
  209. {
  210. jassert (Type1() <= static_cast<Type1> (upperLimit)); // makes no sense to call this if the upper limit is itself below zero..
  211. return Type1() <= valueToTest && valueToTest <= static_cast<Type1> (upperLimit);
  212. }
  213. template <typename Type>
  214. bool isPositiveAndNotGreaterThan (int valueToTest, Type 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 for avoiding unused variables warning. */
  221. template <typename Type1>
  222. void ignoreUnused (const Type1&) noexcept {}
  223. template <typename Type1, typename Type2>
  224. void ignoreUnused (const Type1&, const Type2&) noexcept {}
  225. template <typename Type1, typename Type2, typename Type3>
  226. void ignoreUnused (const Type1&, const Type2&, const Type3&) noexcept {}
  227. template <typename Type1, typename Type2, typename Type3, typename Type4>
  228. void ignoreUnused (const Type1&, const Type2&, const Type3&, const Type4&) noexcept {}
  229. /** Handy function for getting the number of elements in a simple const C array.
  230. E.g.
  231. @code
  232. static int myArray[] = { 1, 2, 3 };
  233. int numElements = numElementsInArray (myArray) // returns 3
  234. @endcode
  235. */
  236. template <typename Type, int N>
  237. int numElementsInArray (Type (&array)[N])
  238. {
  239. ignoreUnused (array);
  240. (void) sizeof (0[array]); // This line should cause an error if you pass an object with a user-defined subscript operator
  241. return N;
  242. }
  243. //==============================================================================
  244. // Some useful maths functions that aren't always present with all compilers and build settings.
  245. /** Using juce_hypot is easier than dealing with the different types of hypot function
  246. that are provided by the various platforms and compilers. */
  247. template <typename Type>
  248. Type juce_hypot (Type a, Type b) noexcept
  249. {
  250. #if JUCE_MSVC
  251. return static_cast<Type> (_hypot (a, b));
  252. #else
  253. return static_cast<Type> (hypot (a, b));
  254. #endif
  255. }
  256. #ifndef DOXYGEN
  257. template <>
  258. inline float juce_hypot (float a, float b) noexcept
  259. {
  260. #if JUCE_MSVC
  261. return _hypotf (a, b);
  262. #else
  263. return hypotf (a, b);
  264. #endif
  265. }
  266. #endif
  267. /** 64-bit abs function. */
  268. inline int64 abs64 (const int64 n) noexcept
  269. {
  270. return (n >= 0) ? n : -n;
  271. }
  272. #if JUCE_MSVC && ! defined (DOXYGEN) // The MSVC libraries omit these functions for some reason...
  273. template<typename Type> Type asinh (Type x) { return std::log (x + std::sqrt (x * x + (Type) 1)); }
  274. template<typename Type> Type acosh (Type x) { return std::log (x + std::sqrt (x * x - (Type) 1)); }
  275. template<typename Type> Type atanh (Type x) { return (std::log (x + (Type) 1) - std::log (((Type) 1) - x)) / (Type) 2; }
  276. #endif
  277. //==============================================================================
  278. /** Commonly used mathematical constants */
  279. template <typename FloatType>
  280. struct MathConstants
  281. {
  282. /** A predefined value for Pi */
  283. static const FloatType pi;
  284. /** A predfined value for Euler's number */
  285. static const FloatType euler;
  286. };
  287. template <typename FloatType>
  288. const FloatType MathConstants<FloatType>::pi = static_cast<FloatType> (3.141592653589793238L);
  289. template <typename FloatType>
  290. const FloatType MathConstants<FloatType>::euler = static_cast<FloatType> (2.71828182845904523536L);
  291. /** A predefined value for Pi, at double-precision.
  292. @see float_Pi
  293. */
  294. const double double_Pi = MathConstants<double>::pi;
  295. /** A predefined value for Pi, at single-precision.
  296. @see double_Pi
  297. */
  298. const float float_Pi = MathConstants<float>::pi;
  299. /** Converts an angle in degrees to radians. */
  300. inline float degreesToRadians (float degrees) noexcept { return degrees * (float_Pi / 180.0f); }
  301. /** Converts an angle in degrees to radians. */
  302. inline double degreesToRadians (double degrees) noexcept { return degrees * (double_Pi / 180.0); }
  303. /** Converts an angle in radians to degrees. */
  304. inline float radiansToDegrees (float radians) noexcept { return radians * (180.0f / float_Pi); }
  305. /** Converts an angle in radians to degrees. */
  306. inline double radiansToDegrees (double radians) noexcept { return radians * (180.0 / double_Pi); }
  307. //==============================================================================
  308. /** The isfinite() method seems to vary between platforms, so this is a
  309. platform-independent function for it.
  310. */
  311. template <typename NumericType>
  312. bool juce_isfinite (NumericType) noexcept
  313. {
  314. return true; // Integer types are always finite
  315. }
  316. template <>
  317. inline bool juce_isfinite (float value) noexcept
  318. {
  319. #if JUCE_WINDOWS && ! JUCE_MINGW
  320. return _finite (value) != 0;
  321. #else
  322. return std::isfinite (value);
  323. #endif
  324. }
  325. template <>
  326. inline bool juce_isfinite (double value) noexcept
  327. {
  328. #if JUCE_WINDOWS && ! JUCE_MINGW
  329. return _finite (value) != 0;
  330. #else
  331. return std::isfinite (value);
  332. #endif
  333. }
  334. //==============================================================================
  335. #if JUCE_MSVC
  336. #pragma optimize ("t", off)
  337. #ifndef __INTEL_COMPILER
  338. #pragma float_control (precise, on, push)
  339. #endif
  340. #endif
  341. /** Fast floating-point-to-integer conversion.
  342. This is faster than using the normal c++ cast to convert a float to an int, and
  343. it will round the value to the nearest integer, rather than rounding it down
  344. like the normal cast does.
  345. Note that this routine gets its speed at the expense of some accuracy, and when
  346. rounding values whose floating point component is exactly 0.5, odd numbers and
  347. even numbers will be rounded up or down differently.
  348. */
  349. template <typename FloatType>
  350. int roundToInt (const FloatType value) noexcept
  351. {
  352. #ifdef __INTEL_COMPILER
  353. #pragma float_control (precise, on, push)
  354. #endif
  355. union { int asInt[2]; double asDouble; } n;
  356. n.asDouble = ((double) value) + 6755399441055744.0;
  357. #if JUCE_BIG_ENDIAN
  358. return n.asInt [1];
  359. #else
  360. return n.asInt [0];
  361. #endif
  362. }
  363. inline int roundToInt (int value) noexcept
  364. {
  365. return value;
  366. }
  367. #if JUCE_MSVC
  368. #ifndef __INTEL_COMPILER
  369. #pragma float_control (pop)
  370. #endif
  371. #pragma optimize ("", on) // resets optimisations to the project defaults
  372. #endif
  373. /** Fast floating-point-to-integer conversion.
  374. This is a slightly slower and slightly more accurate version of roundDoubleToInt(). It works
  375. fine for values above zero, but negative numbers are rounded the wrong way.
  376. */
  377. inline int roundToIntAccurate (double value) noexcept
  378. {
  379. #ifdef __INTEL_COMPILER
  380. #pragma float_control (pop)
  381. #endif
  382. return roundToInt (value + 1.5e-8);
  383. }
  384. /** Fast floating-point-to-integer conversion.
  385. This is faster than using the normal c++ cast to convert a double to an int, and
  386. it will round the value to the nearest integer, rather than rounding it down
  387. like the normal cast does.
  388. Note that this routine gets its speed at the expense of some accuracy, and when
  389. rounding values whose floating point component is exactly 0.5, odd numbers and
  390. even numbers will be rounded up or down differently. For a more accurate conversion,
  391. see roundDoubleToIntAccurate().
  392. */
  393. inline int roundDoubleToInt (double value) noexcept
  394. {
  395. return roundToInt (value);
  396. }
  397. /** Fast floating-point-to-integer conversion.
  398. This is faster than using the normal c++ cast to convert a float to an int, and
  399. it will round the value to the nearest integer, rather than rounding it down
  400. like the normal cast does.
  401. Note that this routine gets its speed at the expense of some accuracy, and when
  402. rounding values whose floating point component is exactly 0.5, odd numbers and
  403. even numbers will be rounded up or down differently.
  404. */
  405. inline int roundFloatToInt (float value) noexcept
  406. {
  407. return roundToInt (value);
  408. }
  409. //==============================================================================
  410. /** Truncates a positive floating-point number to an unsigned int.
  411. This is generally faster than static_cast<unsigned int> (std::floor (x))
  412. but it only works for positive numbers small enough to be represented as an
  413. unsigned int.
  414. */
  415. template <typename FloatType>
  416. unsigned int truncatePositiveToUnsignedInt (FloatType value) noexcept
  417. {
  418. jassert (value >= static_cast<FloatType> (0));
  419. jassert (static_cast<FloatType> (value) <= std::numeric_limits<unsigned int>::max());
  420. return static_cast<unsigned int> (value);
  421. }
  422. //==============================================================================
  423. /** Returns true if the specified integer is a power-of-two. */
  424. template <typename IntegerType>
  425. bool isPowerOfTwo (IntegerType value)
  426. {
  427. return (value & (value - 1)) == 0;
  428. }
  429. /** Returns the smallest power-of-two which is equal to or greater than the given integer. */
  430. inline int nextPowerOfTwo (int n) noexcept
  431. {
  432. --n;
  433. n |= (n >> 1);
  434. n |= (n >> 2);
  435. n |= (n >> 4);
  436. n |= (n >> 8);
  437. n |= (n >> 16);
  438. return n + 1;
  439. }
  440. /** Returns the index of the highest set bit in a (non-zero) number.
  441. So for n=3 this would return 1, for n=7 it returns 2, etc.
  442. An input value of 0 is illegal!
  443. */
  444. int findHighestSetBit (uint32 n) noexcept;
  445. /** Returns the number of bits in a 32-bit integer. */
  446. inline int countNumberOfBits (uint32 n) noexcept
  447. {
  448. n -= ((n >> 1) & 0x55555555);
  449. n = (((n >> 2) & 0x33333333) + (n & 0x33333333));
  450. n = (((n >> 4) + n) & 0x0f0f0f0f);
  451. n += (n >> 8);
  452. n += (n >> 16);
  453. return (int) (n & 0x3f);
  454. }
  455. /** Returns the number of bits in a 64-bit integer. */
  456. inline int countNumberOfBits (uint64 n) noexcept
  457. {
  458. return countNumberOfBits ((uint32) n) + countNumberOfBits ((uint32) (n >> 32));
  459. }
  460. /** Performs a modulo operation, but can cope with the dividend being negative.
  461. The divisor must be greater than zero.
  462. */
  463. template <typename IntegerType>
  464. IntegerType negativeAwareModulo (IntegerType dividend, const IntegerType divisor) noexcept
  465. {
  466. jassert (divisor > 0);
  467. dividend %= divisor;
  468. return (dividend < 0) ? (dividend + divisor) : dividend;
  469. }
  470. /** Returns the square of its argument. */
  471. template <typename NumericType>
  472. NumericType square (NumericType n) noexcept
  473. {
  474. return n * n;
  475. }
  476. //==============================================================================
  477. /** Writes a number of bits into a memory buffer at a given bit index.
  478. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  479. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the value would be written
  480. into bits 2-8 of targetBuffer[1], and the upper 5 bits of value into bits 0-5 of targetBuffer[2].
  481. @see readLittleEndianBitsInBuffer
  482. */
  483. void writeLittleEndianBitsInBuffer (void* targetBuffer, uint32 startBit, uint32 numBits, uint32 value) noexcept;
  484. /** Reads a number of bits from a buffer at a given bit index.
  485. The buffer is treated as a sequence of 8-bit bytes, and the value is encoded in little-endian order,
  486. so for example if startBit = 10, and numBits = 11 then the lower 6 bits of the result would be read
  487. from bits 2-8 of sourceBuffer[1], and the upper 5 bits of the result from bits 0-5 of sourceBuffer[2].
  488. @see writeLittleEndianBitsInBuffer
  489. */
  490. uint32 readLittleEndianBitsInBuffer (const void* sourceBuffer, uint32 startBit, uint32 numBits) noexcept;
  491. //==============================================================================
  492. #if JUCE_INTEL || defined (DOXYGEN)
  493. /** This macro can be applied to a float variable to check whether it contains a denormalised
  494. value, and to normalise it if necessary.
  495. On CPUs that aren't vulnerable to denormalisation problems, this will have no effect.
  496. */
  497. #define JUCE_UNDENORMALISE(x) { (x) += 0.1f; (x) -= 0.1f; }
  498. #else
  499. #define JUCE_UNDENORMALISE(x)
  500. #endif
  501. //==============================================================================
  502. /** This namespace contains a few template classes for helping work out class type variations.
  503. */
  504. namespace TypeHelpers
  505. {
  506. /** The ParameterType struct is used to find the best type to use when passing some kind
  507. of object as a parameter.
  508. Of course, this is only likely to be useful in certain esoteric template situations.
  509. E.g. "myFunction (typename TypeHelpers::ParameterType<int>::type, typename TypeHelpers::ParameterType<MyObject>::type)"
  510. would evaluate to "myfunction (int, const MyObject&)", keeping any primitive types as
  511. pass-by-value, but passing objects as a const reference, to avoid copying.
  512. */
  513. template <typename Type> struct ParameterType { typedef const Type& type; };
  514. #if ! DOXYGEN
  515. template <typename Type> struct ParameterType <Type&> { typedef Type& type; };
  516. template <typename Type> struct ParameterType <Type*> { typedef Type* type; };
  517. template <> struct ParameterType <char> { typedef char type; };
  518. template <> struct ParameterType <unsigned char> { typedef unsigned char type; };
  519. template <> struct ParameterType <short> { typedef short type; };
  520. template <> struct ParameterType <unsigned short> { typedef unsigned short type; };
  521. template <> struct ParameterType <int> { typedef int type; };
  522. template <> struct ParameterType <unsigned int> { typedef unsigned int type; };
  523. template <> struct ParameterType <long> { typedef long type; };
  524. template <> struct ParameterType <unsigned long> { typedef unsigned long type; };
  525. template <> struct ParameterType <int64> { typedef int64 type; };
  526. template <> struct ParameterType <uint64> { typedef uint64 type; };
  527. template <> struct ParameterType <bool> { typedef bool type; };
  528. template <> struct ParameterType <float> { typedef float type; };
  529. template <> struct ParameterType <double> { typedef double type; };
  530. #endif
  531. /** These templates are designed to take a type, and if it's a double, they return a double
  532. type; for anything else, they return a float type.
  533. */
  534. template <typename Type> struct SmallestFloatType { typedef float type; };
  535. template <> struct SmallestFloatType <double> { typedef double type; };
  536. /** These templates are designed to take an integer type, and return an unsigned int
  537. version with the same size.
  538. */
  539. template <int bytes> struct UnsignedTypeWithSize {};
  540. template <> struct UnsignedTypeWithSize<1> { typedef uint8 type; };
  541. template <> struct UnsignedTypeWithSize<2> { typedef uint16 type; };
  542. template <> struct UnsignedTypeWithSize<4> { typedef uint32 type; };
  543. template <> struct UnsignedTypeWithSize<8> { typedef uint64 type; };
  544. }
  545. } // namespace juce