LMMS
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
30template <class T>
31inline const T& Max (const T& a, const T& b)
32{
33 return a < b ? b : a;
34}
35
36template <class T>
37inline T Abs (const T& value)
38{
39 return (value >= (T)0) ? value : -value;
40}
41
42template <class T>
43inline T Sign (const T& value)
44{
45 return (value == (T)0) ? 0 : ((value >= (T)0) ? 1 : -1);
46}
47
48template <class T>
49inline T Bound (T minval, T maxval, T x)
50{
51 if (x < minval)
52 return minval;
53 else if (x > maxval)
54 return maxval;
55 return x;
56}
57
58template <class T>
59void Swap (T& t1, T& t2)
60{
61 T tmp = t1;
62 t1 = t2;
63 t2 = tmp;
64}
65
66template <class T>
67bool IsApproximateEqual (T t1, T t2, T epsilon)
68{
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;
77}
78
79template <class T>
80inline T ToNormalized (const T& value, const int32 numSteps)
81{
82 return value / T (numSteps);
83}
84
85template <class T>
86inline int32 FromNormalized (const T& norm, const int32 numSteps)
87{
88 return Min<int32> (numSteps, int32 (norm * (numSteps + 1)));
89}
90
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
96
97//------------------------------------------------------------------------
98} // namespace Steinberg
uint8_t a
Definition Spc_Cpu.h:141
unsigned x[BMAX+1]
Definition inflate.c:1586
static PuglViewHint int value
Definition pugl.h:1708
Definition baseiids.cpp:43
const T & Max(const T &a, const T &b)
Definition futils.h:31
int32 FromNormalized(const T &norm, const int32 numSteps)
Definition futils.h:86
T Bound(T minval, T maxval, T x)
Definition futils.h:49
int int32
Definition ftypes.h:50
T ToNormalized(const T &value, const int32 numSteps)
Definition futils.h:80
T Sign(const T &value)
Definition futils.h:43
T Abs(const T &value)
Definition futils.h:37
const T & Min(const T &a, const T &b)
Definition futils.h:25
bool IsApproximateEqual(T t1, T t2, T epsilon)
Definition futils.h:67
void Swap(T &t1, T &t2)
Definition futils.h:59
static bool diff(const std::string fn1, const std::string fn2)
Definition playertest.cpp:161
b
Definition crypt.c:628