forked from gabonator/LA104
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.h
62 lines (53 loc) · 1.38 KB
/
Utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef __UTILS_H__
#define __UTILS_H__
#include <library.h>
//#include <math.h>
//#include <stdint.h>
#define UTILS CUtils()
class CUtils
{
public:
static int atoi(char *str);
static uint32_t htoi(char *str);
static char* itoa(int16_t i);
static char* itoa2(ui8 n);
static char* ftoa(float f);
static char tohex(ui8 n);
static char* clrhex(ui16 c);
static char* MidiNote(int n);
static char* FormatVoltage( float fV, int nChars=8 );
static char* FormatFrequency( float fF, int nChars=8 );
static char* FormatTime( float fT, int nChars=8 );
static char* FormatFloat5( float f );
template <class T>
inline void Clamp(T& nVariable, T nMin, T nMax)
{
if ( nVariable < nMin )
{
nVariable = nMin;
return;
}
if ( nVariable > nMax )
{
nVariable = nMax;
return;
}
}
static unsigned int Random()
{
// our initial starting seed is 5323
static unsigned int nSeed = 5323;
static unsigned int nX = 0;
// Take the current seed and generate a new value from it
// Due to our use of large constants and overflow, it would be
// very hard for someone to predict what the next number is
// going to be from the previous one.
nSeed = (8253729 * nSeed + 2396403);
nSeed += nX++;
// Take the seed and return a value between 0 and 32767
return nSeed & 32767;
}
static ui16 InterpolateColor( ui16 clrA, ui16 clrB, int nLevel );
static int Sqrt(int a);
};
#endif