Audio plugin host https://kx.studio/carla
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.

futils.h 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. //-----------------------------------------------------------------------------
  2. // Project : SDK Core
  3. //
  4. // Category : SDK Core Interfaces
  5. // Filename : pluginterfaces/base/futils.h
  6. // Created by : Steinberg, 01/2004
  7. // Description : Basic utilities
  8. //
  9. //-----------------------------------------------------------------------------
  10. // This file is part of a Steinberg SDK. It is subject to the license terms
  11. // in the LICENSE file found in the top-level directory of this distribution
  12. // and at www.steinberg.net/sdklicenses.
  13. // No part of the SDK, including this file, may be copied, modified, propagated,
  14. // or distributed except according to the terms contained in the LICENSE file.
  15. //-----------------------------------------------------------------------------
  16. #pragma once
  17. #include "pluginterfaces/base/ftypes.h"
  18. namespace Steinberg {
  19. //----------------------------------------------------------------------------
  20. // min/max/etc. template functions
  21. template <class T>
  22. inline const T& Min (const T& a, const T& b)
  23. {
  24. return b < a ? b : a;
  25. }
  26. template <class T>
  27. inline const T& Max (const T& a, const T& b)
  28. {
  29. return a < b ? b : a;
  30. }
  31. template <class T>
  32. inline T Abs (const T& value)
  33. {
  34. return (value >= (T)0) ? value : -value;
  35. }
  36. template <class T>
  37. inline T Sign (const T& value)
  38. {
  39. return (value == (T)0) ? 0 : ((value >= (T)0) ? 1 : -1);
  40. }
  41. template <class T>
  42. inline T Bound (T minval, T maxval, T x)
  43. {
  44. if (x < minval)
  45. return minval;
  46. else if (x > maxval)
  47. return maxval;
  48. return x;
  49. }
  50. template <class T>
  51. void Swap (T& t1, T& t2)
  52. {
  53. T tmp = t1;
  54. t1 = t2;
  55. t2 = tmp;
  56. }
  57. template <class T>
  58. bool IsApproximateEqual (T t1, T t2, T epsilon)
  59. {
  60. if (t1 == t2)
  61. return true;
  62. T diff = t1 - t2;
  63. if (diff < 0.0)
  64. diff = -diff;
  65. if (diff < epsilon)
  66. return true;
  67. return false;
  68. }
  69. template <class T>
  70. inline T ToNormalized (const T& value, const int32 numSteps)
  71. {
  72. return value / T (numSteps);
  73. }
  74. template <class T>
  75. inline int32 FromNormalized (const T& norm, const int32 numSteps)
  76. {
  77. return Min<int32> (numSteps, int32 (norm * (numSteps + 1)));
  78. }
  79. //------------------------------------------------------------------------
  80. } // namespace Steinberg