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.

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