Fix last commit
[carla.git] / source / includes / vst3sdk / pluginterfaces / base / futils.h
blob5ce9e295a8fa01973a3f564dab4209df16c34d9a
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 //-----------------------------------------------------------------------------
17 #pragma once
19 #include "pluginterfaces/base/ftypes.h"
21 namespace Steinberg {
22 //----------------------------------------------------------------------------
23 // min/max/etc. template functions
24 template <class T>
25 inline const T& Min (const T& a, const T& b)
27 return b < a ? b : a;
30 template <class T>
31 inline const T& Max (const T& a, const T& b)
33 return a < b ? b : a;
36 template <class T>
37 inline T Abs (const T& value)
39 return (value >= (T)0) ? value : -value;
42 template <class T>
43 inline T Sign (const T& value)
45 return (value == (T)0) ? 0 : ((value >= (T)0) ? 1 : -1);
48 template <class T>
49 inline T Bound (T minval, T maxval, T x)
51 if (x < minval)
52 return minval;
53 else if (x > maxval)
54 return maxval;
55 return x;
58 template <class T>
59 void Swap (T& t1, T& t2)
61 T tmp = t1;
62 t1 = t2;
63 t2 = tmp;
66 template <class T>
67 bool IsApproximateEqual (T t1, T t2, T epsilon)
69 if (t1 == t2)
70 return true;
71 T diff = t1 - t2;
72 if (diff < 0.0)
73 diff = -diff;
74 if (diff < epsilon)
75 return true;
76 return false;
79 template <class T>
80 inline T ToNormalized (const T& value, const int32 numSteps)
82 return value / T (numSteps);
85 template <class T>
86 inline int32 FromNormalized (const T& norm, const int32 numSteps)
88 return Min<int32> (numSteps, int32 (norm * (numSteps + 1)));
91 // Four character constant
92 #ifndef CCONST
93 #define CCONST(a, b, c, d) \
94 ((((int32) (a)) << 24) | (((int32) (b)) << 16) | (((int32) (c)) << 8) | (((int32) (d)) << 0))
95 #endif
97 //------------------------------------------------------------------------
98 } // namespace Steinberg