Change ALSA device default to 'default' from hw:0
[zynaddsubfx-code.git] / src / globals.h
blobfd0024100dbca94788cee1e2c74a8460cec25d62
1 /*
2 ZynAddSubFX - a software synthesizer
4 globals.h - it contains program settings and the program capabilities
5 like number of parts, of effects
6 Copyright (C) 2002-2005 Nasca Octavian Paul
7 Author: Nasca Octavian Paul
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
16 #ifndef GLOBALS_H
17 #define GLOBALS_H
19 #if defined(__clang__)
20 #define REALTIME __attribute__((annotate("realtime")))
21 #define NONREALTIME __attribute__((annotate("nonrealtime")))
22 #else
23 #define REALTIME
24 #define NONREALTIME
25 #endif
27 //Forward Declarations
29 #if defined(HAVE_CPP_STD_COMPLEX)
30 #include <complex>
31 #else
32 namespace std {
33 template<class T> struct complex;
35 #endif
37 namespace rtosc{struct Ports; struct ClonePorts; struct MergePorts; class ThreadLink;}
38 namespace zyn {
40 class EffectMgr;
41 class ADnoteParameters;
42 struct ADnoteGlobalParam;
43 class SUBnoteParameters;
44 class PADnoteParameters;
45 class SynthNote;
47 class Allocator;
48 class AbsTime;
49 class RelTime;
51 class Microtonal;
52 class XMLwrapper;
53 class Resonance;
54 class FFTwrapper;
55 class EnvelopeParams;
56 class LFOParams;
57 class FilterParams;
59 struct WatchManager;
60 class LFO;
61 class Envelope;
62 class OscilGen;
64 class Controller;
65 class Master;
66 class Part;
68 class Filter;
69 class AnalogFilter;
70 class MoogFilter;
71 class CombFilter;
72 class SVFilter;
73 class FormantFilter;
74 class ModFilter;
76 typedef float fftwf_real;
77 typedef std::complex<fftwf_real> fft_t;
79 /**
80 * The number of harmonics of additive synth
81 * This must be smaller than OSCIL_SIZE/2
83 #define MAX_AD_HARMONICS 128
86 /**
87 * The number of harmonics of substractive
89 #define MAX_SUB_HARMONICS 64
93 * The maximum number of samples that are used for 1 PADsynth instrument(or item)
95 #define PAD_MAX_SAMPLES 64
99 * Number of parts
101 #define NUM_MIDI_PARTS 16
104 * Number of Midi channels
106 #define NUM_MIDI_CHANNELS 16
109 * The number of voices of additive synth for a single note
111 #define NUM_VOICES 8
114 * The polyphony (notes)
116 #define POLYPHONY 60
119 * Number of system effects
121 #define NUM_SYS_EFX 4
125 * Number of insertion effects
127 #define NUM_INS_EFX 8
130 * Number of part's insertion effects
132 #define NUM_PART_EFX 3
135 * Maximum number of the instrument on a part
137 #define NUM_KIT_ITEMS 16
140 * Maximum number of "strings" in Sympathetic Resonance Effect
142 #define NUM_SYMPATHETIC_STRINGS 228U // 76*3
145 * How is applied the velocity sensing
147 #define VELOCITY_MAX_SCALE 8.0f
150 * The maximum length of instrument's name
152 #define PART_MAX_NAME_LEN 30
155 * The maximum we allow for an XMZ path
157 * Note that this is an ugly hack. Finding a compile time path
158 * max portably is painful.
160 #define XMZ_PATH_MAX 1024
163 * The maximum number of bands of the equaliser
165 #define MAX_EQ_BANDS 8
166 #if (MAX_EQ_BANDS >= 20)
167 #error "Too many EQ bands in globals.h"
168 #endif
172 * Maximum filter stages
174 #define MAX_FILTER_STAGES 5
177 * Formant filter (FF) limits
179 #define FF_MAX_VOWELS 6
180 #define FF_MAX_FORMANTS 12
181 #define FF_MAX_SEQUENCE 8
183 #define MAX_PRESETTYPE_SIZE 30
185 #define LOG_2 0.693147181f
186 #define PI 3.1415926536f
187 #define PIDIV2 1.5707963268f
188 #define LOG_10 2.302585093f
191 * For de-pop adjustment
193 #define FADEIN_ADJUSTMENT_SCALE 20
196 * Envelope Limits
198 #define MAX_ENVELOPE_POINTS 40
199 #define MIN_ENVELOPE_DB -400
202 * The threshold for the amplitude interpolation used if the amplitude
203 * is changed (by LFO's or Envelope's). If the change of the amplitude
204 * is below this, the amplitude is not interpolated
206 #define AMPLITUDE_INTERPOLATION_THRESHOLD 0.0001f
209 * How the amplitude threshold is computed
211 #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabsf((b) - (a)) \
212 / (fabsf((b) + (a) \
213 + 0.0000000001f))) > \
214 AMPLITUDE_INTERPOLATION_THRESHOLD)
217 * Interpolate Amplitude
219 #define INTERPOLATE_AMPLITUDE(a, b, x, size) ((a) \
220 + ((b) \
221 - (a)) * (float)(x) \
222 / (float) (size))
226 * dB
228 #define dB2rap(dB) ((expf((dB) * LOG_10 / 20.0f)))
229 #define rap2dB(rap) ((20 * logf(rap) / LOG_10))
231 #define ZERO(data, size) {char *data_ = (char *) data; for(int i = 0; \
232 i < size; \
233 i++) \
234 data_[i] = 0; }
235 #define ZERO_float(data, size) {float *data_ = (float *) data; \
236 for(int i = 0; \
237 i < size; \
238 i++) \
239 data_[i] = 0.0f; }
241 enum ONOFFTYPE {
242 OFF = 0, ON = 1
245 enum MidiControllers {
246 C_bankselectmsb = 0, C_pitchwheel = 1000, C_NULL = 1001,
247 C_aftertouch = 1002, C_pitch = 1003,
248 C_expression = 11, C_panning = 10, C_bankselectlsb = 32,
249 C_filtercutoff = 74, C_filterq = 71, C_bandwidth = 75, C_modwheel = 1,
250 C_fmamp = 76,
251 C_volume = 7, C_sustain = 64, C_allnotesoff = 123, C_allsoundsoff = 120,
252 C_resetallcontrollers = 121,
253 C_portamento = 65, C_resonance_center = 77, C_resonance_bandwidth = 78,
255 C_dataentryhi = 0x06, C_dataentrylo = 0x26, C_nrpnhi = 99, C_nrpnlo = 98
258 enum LegatoMsg {
259 LM_Norm, LM_FadeIn, LM_FadeOut, LM_CatchUp, LM_ToNorm
262 //is like i=(int)(floor(f))
263 #ifdef ASM_F2I_YES
264 #define F2I(f, i)\
265 do {\
266 __asm__ __volatile__\
267 ("fistpl %0" : "=m" (i) : "t" (f - 0.49999999f) : "st");\
268 } while (false)
269 #else
270 #define F2I(f, i)\
271 do {\
272 (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f)));\
273 } while (false)
274 #endif
278 #ifndef O_BINARY
279 #define O_BINARY 0
280 #endif
282 template<class T>
283 class m_unique_array
285 T* ptr = nullptr; //!< @invariant nullptr or pointer to new[]'ed memory
286 public:
287 m_unique_array() = default;
288 m_unique_array(m_unique_array&& other) : ptr(other.ptr) {
289 other.ptr = nullptr;
291 m_unique_array& operator=(m_unique_array&& other) {
292 ptr = other.ptr;
293 other.ptr = nullptr;
294 return *this;
296 m_unique_array(const m_unique_array& other) = delete;
297 ~m_unique_array() { delete[] ptr; ptr = nullptr; }
298 void resize(unsigned sz) {
299 delete[] ptr;
300 ptr = new T[sz]; }
302 operator T*() { return ptr; }
303 operator const T*() const { return ptr; }
304 //T& operator[](unsigned idx) { return ptr[idx]; }
305 //const T& operator[](unsigned idx) const { return ptr[idx]; }
308 //temporary include for synth->{samplerate/buffersize} members
309 struct SYNTH_T {
311 SYNTH_T(void)
312 :samplerate(44100), buffersize(256), oscilsize(1024)
314 alias(false);
317 SYNTH_T(const SYNTH_T& ) = delete;
318 SYNTH_T(SYNTH_T&& ) = default;
319 SYNTH_T& operator=(const SYNTH_T& ) = delete;
320 SYNTH_T& operator=(SYNTH_T&& ) = default;
322 /** the buffer to add noise in order to avoid denormalisation */
323 m_unique_array<float> denormalkillbuf;
325 /**Sampling rate*/
326 unsigned int samplerate;
329 * The size of a sound buffer (or the granularity)
330 * All internal transfer of sound data use buffer of this size.
331 * All parameters are constant during this period of time, except
332 * some parameters(like amplitudes) which are linearly interpolated.
333 * If you increase this you'll encounter big latencies, but if you
334 * decrease this the CPU requirements gets high.
336 int buffersize;
339 * The size of ADnote Oscillator
340 * Decrease this => poor quality
341 * Increase this => CPU requirements gets high (only at start of the note)
343 int oscilsize;
345 //Alias for above terms
346 float samplerate_f;
347 float halfsamplerate_f;
348 float buffersize_f;
349 int bufferbytes;
350 float oscilsize_f;
352 float dt(void) const
354 return buffersize_f / samplerate_f;
356 void alias(bool randomize=true);
357 static float numRandom(void); //defined in Util.cpp for now
360 class smooth_float {
361 private:
362 bool init;
363 float curr_value;
364 float next_value;
365 public:
366 smooth_float() {
367 init = false;
368 next_value = curr_value = 0.0f;
370 smooth_float(const float value) {
371 init = true;
372 next_value = curr_value = value;
374 operator float() {
375 const float delta = (next_value - curr_value) / 32.0f;
376 curr_value += delta;
377 return (curr_value);
379 void operator =(const float value) {
380 if (init) {
381 next_value = value;
382 } else {
383 next_value = curr_value = value;
384 init = true;
387 bool isSet() const {
388 return (init);
393 #endif