JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
futils.h
Go to the documentation of this file.
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
17#pragma once
18
20
21namespace Steinberg {
22//----------------------------------------------------------------------------
23// min/max/etc. template functions
24template <class T>
25inline const T& Min (const T& a, const T& b)
26{
27 return b < a ? b : a;
28}
29
30//----------------------------------------------------------------------------
31template <class T>
32inline const T& Max (const T& a, const T& b)
33{
34 return a < b ? b : a;
35}
36
37//----------------------------------------------------------------------------
38template <class T>
39inline T Abs (const T& value)
40{
41 return (value >= (T)0) ? value : -value;
42}
43
44//----------------------------------------------------------------------------
45template <class T>
46inline T Sign (const T& value)
47{
48 return (value == (T)0) ? 0 : ((value >= (T)0) ? 1 : -1);
49}
50
51//----------------------------------------------------------------------------
52template <class T>
53inline T Bound (T minval, T maxval, T x)
54{
55 if (x < minval)
56 return minval;
57 if (x > maxval)
58 return maxval;
59 return x;
60}
61
62//----------------------------------------------------------------------------
63template <class T>
64void Swap (T& t1, T& t2)
65{
66 T tmp = t1;
67 t1 = t2;
68 t2 = tmp;
69}
70
71//----------------------------------------------------------------------------
72template <class T>
73bool IsApproximateEqual (T t1, T t2, T epsilon)
74{
75 if (t1 == t2)
76 return true;
77 T diff = t1 - t2;
78 if (diff < 0.0)
79 diff = -diff;
80 if (diff < epsilon)
81 return true;
82 return false;
83}
84
85//----------------------------------------------------------------------------
86template <class T>
87inline T ToNormalized (const T& value, const int32 numSteps)
88{
89 return value / T (numSteps);
90}
91
92//----------------------------------------------------------------------------
93template <class T>
94inline int32 FromNormalized (const T& norm, const int32 numSteps)
95{
96 return Min<int32> (numSteps, int32 (norm * (numSteps + 1)));
97}
98
99//----------------------------------------------------------------------------
100// Four character constant
101#ifndef CCONST
102#define CCONST(a, b, c, d) \
103 ((((int32) (a)) << 24) | (((int32) (b)) << 16) | (((int32) (c)) << 8) | (((int32) (d)) << 0))
104#endif
105
106//------------------------------------------------------------------------
107} // namespace Steinberg