LMMS
Loading...
Searching...
No Matches
Util.h
Go to the documentation of this file.
1/*
2 ZynAddSubFX - a software synthesizer
3
4 Util.h - Miscellaneous functions
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2 or later) for more details.
16
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
21*/
22
23#ifndef UTIL_H
24#define UTIL_H
25
26#include <string>
27#include <sstream>
28#include <stdint.h>
29#include "Config.h"
30#include "../globals.h"
31
32//Velocity Sensing function
33extern float VelF(float velocity, unsigned char scaling);
34
35bool fileexists(const char *filename);
36
37#define N_DETUNE_TYPES 4 //the number of detune types
38extern float getdetune(unsigned char type,
39 unsigned short int coarsedetune,
40 unsigned short int finedetune);
41
46void set_realtime();
47
49void os_sleep(long length);
50
51std::string legalizeFilename(std::string filename);
52
53extern float *denormalkillbuf;
54
55extern class Config config;
56
57void invSignal(float *sig, size_t len);
58
59template<class T>
60std::string stringFrom(T x)
61{
62 std::stringstream ss;
63 ss << x;
64 return ss.str();
65}
66
67template<class T>
68T stringTo(const char *x)
69{
70 std::string str = x != NULL ? x : "0"; //should work for the basic float/int
71 std::stringstream ss(str);
72 T ans;
73 ss >> ans;
74 return ans;
75}
76
77template<class T>
78T limit(T val, T min, T max)
79{
80 return val < min ? min : (val > max ? max : val);
81}
82
83//Random number generator
84
85typedef uint32_t prng_t;
86extern prng_t prng_state;
87
88// Portable Pseudo-Random Number Generator
89inline prng_t prng_r(prng_t &p)
90{
91 return p = p * 1103515245 + 12345;
92}
93
94inline prng_t prng(void)
95{
96 return prng_r(prng_state) & 0x7fffffff;
97}
98
99inline void sprng(prng_t p)
100{
101 prng_state = p;
102}
103
104/*
105 * The random generator (0.0f..1.0f)
106 */
107#ifndef INT32_MAX
108# define INT32_MAX (2147483647)
109#endif
110#define RND (prng() / (INT32_MAX * 1.0f))
111
112//Linear Interpolation
113float interpolate(const float *data, size_t len, float pos);
114
115//Linear circular interpolation
116float cinterpolate(const float *data, size_t len, float pos);
117
118#endif
#define NULL
Definition CarlaBridgeFormat.cpp:30
prng_t prng_state
Definition Util.cpp:43
float * denormalkillbuf
Definition Util.cpp:46
void set_realtime()
Definition Util.cpp:124
std::string stringFrom(T x)
Definition Util.h:60
float getdetune(unsigned char type, unsigned short int coarsedetune, unsigned short int finedetune)
Definition Util.cpp:65
T limit(T val, T min, T max)
Definition Util.h:78
bool fileexists(const char *filename)
Definition Util.cpp:114
float cinterpolate(const float *data, size_t len, float pos)
Definition Util.cpp:224
std::string legalizeFilename(std::string filename)
Definition Util.cpp:141
T stringTo(const char *x)
Definition Util.h:68
void os_sleep(long length)
Definition Util.cpp:136
void invSignal(float *sig, size_t len)
Definition Util.cpp:151
prng_t prng_r(prng_t &p)
Definition Util.h:89
float interpolate(const float *data, size_t len, float pos)
Definition Util.cpp:215
void sprng(prng_t p)
Definition Util.h:99
prng_t prng(void)
Definition Util.h:94
float VelF(float velocity, unsigned char scaling)
Definition Util.cpp:52
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
Definition Config.h:32
unsigned x[BMAX+1]
Definition inflate.c:1586
struct config_s config
static char filename[]
Definition features.c:5
int val
Definition jpeglib.h:956
JSAMPIMAGE data
Definition jpeglib.h:945
unsigned int uint32_t
Definition mid.cpp:100
uint32_t prng_t
Definition Util.h:109
#define min(x, y)
Definition os.h:74
#define max(x, y)
Definition os.h:78
png_uint_32 length
Definition png.c:2247
uch * p
Definition crypt.c:594
ss
Definition zipinfo.c:2292