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
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12*/
13
14#ifndef UTIL_H
15#define UTIL_H
16
17#include <string>
18#include <sstream>
19#include <stdint.h>
20#include <algorithm>
21#include <set>
22
23#include <rtosc/ports.h>
24#include <rtosc/port-sugar.h>
25
26namespace zyncarla {
27
28extern bool isPlugin;
29bool fileexists(const char *filename);
30
31using std::min;
32using std::max;
33
34//Velocity Sensing function
35extern float VelF(float velocity, unsigned char scaling);
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_usleep(long length);
50
52std::string os_pid_as_padded_string();
53
54std::string legalizeFilename(std::string filename);
55
56void invSignal(float *sig, size_t len);
57
58template<class T>
59std::string stringFrom(T x)
60{
61 std::stringstream ss;
62 ss << x;
63 return ss.str();
64}
65
66template<class T>
67std::string to_s(T x)
68{
69 return stringFrom(x);
70}
71
72template<class T>
73T stringTo(const char *x)
74{
75 std::string str = x != NULL ? x : "0"; //should work for the basic float/int
76 std::stringstream ss(str);
77 T ans;
78 ss >> ans;
79 return ans;
80}
81
82
83
84template<class T>
85T limit(T val, T min, T max)
86{
87 return val < min ? min : (val > max ? max : val);
88}
89
90template<class T>
91bool inRange(T val, T min, T max)
92{
93 return val >= min && val <= max;
94}
95
96template<class T>
97T array_max(const T *data, size_t len)
98{
99 T max = 0;
100
101 for(unsigned i = 0; i < len; ++i)
102 if(max < data[i])
103 max = data[i];
104 return max;
105}
106
107//Random number generator
108
110extern prng_t prng_state;
111
112// Portable Pseudo-Random Number Generator
114{
115 return p = p * 1103515245 + 12345;
116}
117
118inline prng_t prng(void)
119{
120 return prng_r(prng_state) & 0x7fffffff;
121}
122
123inline void sprng(prng_t p)
124{
125 prng_state = p;
126}
127
128/*
129 * The random generator (0.0f..1.0f)
130 */
131#ifndef INT32_MAX
132#define INT32_MAX (2147483647)
133#endif
134#define RND (prng() / (INT32_MAX * 1.0f))
135
136//Linear Interpolation
137float interpolate(const float *data, size_t len, float pos);
138
139//Linear circular interpolation
140float cinterpolate(const float *data, size_t len, float pos);
141
142template<class T>
143static inline void nullify(T &t) {delete t; t = NULL; }
144template<class T>
145static inline void arrayNullify(T &t) {delete [] t; t = NULL; }
146
147char *rtosc_splat(const char *path, std::set<std::string>);
148
153#define rParamZyn(name, ...) \
154 {STRINGIFY(name) "::i", rProp(parameter) rMap(min, 0) rMap(max, 127) DOC(__VA_ARGS__), NULL, rParamICb(name)}
155
156#define rPresetType \
157{"preset-type:", rProp(internal) rDoc("clipboard type of object"), 0, \
158 [](const char *, rtosc::RtData &d){ \
159 rObject *obj = (rObject*)d.obj; \
160 d.reply(d.loc, "s", obj->type);}}
161
162#define rPaste \
163rPresetType, \
164{"paste:b", rProp(internal) rDoc("paste port"), 0, \
165 [](const char *m, rtosc::RtData &d){ \
166 printf("rPaste...\n"); \
167 rObject &paste = **(rObject **)rtosc_argument(m,0).b.data; \
168 rObject &o = *(rObject*)d.obj;\
169 o.paste(paste);}}
170
171#define rArrayPaste \
172{"paste-array:bi", rProp(internal) rDoc("array paste port"), 0, \
173 [](const char *m, rtosc::RtData &d){ \
174 printf("rArrayPaste...\n"); \
175 rObject &paste = **(rObject **)rtosc_argument(m,0).b.data; \
176 int field = rtosc_argument(m,1).i; \
177 rObject &o = *(rObject*)d.obj;\
178 o.pasteArray(paste,field);}}
179
180}
181
182#define rUnit(x) rMap(unit, x)
183
184#endif
#define NULL
Definition CarlaBridgeFormat.cpp:30
CAdPlugDatabase::CRecord::RecordType type
Definition adplugdb.cpp:93
struct huft * t
Definition inflate.c:943
register unsigned i
Definition inflate.c:1575
unsigned x[BMAX+1]
Definition inflate.c:1586
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
Definition zynaddsubfx-src.cpp:569
void sprng(prng_t p)
Definition Util.h:123
T limit(T val, T min, T max)
Definition Util.h:85
T stringTo(const char *x)
Definition Util.h:73
int max(int a, int b)
Definition Echo.cpp:99
std::string os_pid_as_padded_string()
returns pid padded to maximum pid lenght, posix conform
Definition Util.cpp:185
char * rtosc_splat(const char *path, std::set< std::string > v)
Definition Util.cpp:234
static void arrayNullify(T &t)
Definition Util.h:145
prng_t prng_r(prng_t &p)
Definition Util.h:113
void * data(next_t *n)
Definition Allocator.cpp:32
bool fileexists(const char *filename)
Definition Util.cpp:110
std::string legalizeFilename(std::string filename)
Definition Util.cpp:195
std::string to_s(T x)
Definition Util.h:67
float VelF(float velocity, unsigned char scaling)
Definition Util.cpp:48
T array_max(const T *data, size_t len)
Definition Util.h:97
prng_t prng(void)
Definition Util.h:118
bool inRange(T val, T min, T max)
Definition Util.h:91
void os_usleep(long length)
Definition Util.cpp:152
void set_realtime()
Definition Util.cpp:120
std::string stringFrom(T x)
Definition Util.h:59
static void nullify(T &t)
Definition Util.h:143
float cinterpolate(const float *data, size_t len, float pos)
Definition Util.cpp:225
uint32_t prng_t
Definition Util.h:109
float getdetune(unsigned char type, unsigned short int coarsedetune, unsigned short int finedetune)
Definition Util.cpp:61
bool isPlugin
Definition Util.cpp:41
void invSignal(float *sig, size_t len)
Definition Util.cpp:205
prng_t prng_state
Definition Util.cpp:43
float interpolate(const float *data, size_t len, float pos)
Definition Util.cpp:216
#define min(x, y)
Definition os.h:74
png_uint_32 length
Definition png.c:2247
uch * p
Definition crypt.c:594
ss
Definition zipinfo.c:2292