Add python3 to github action test deps
[zynaddsubfx-code.git] / src / globals.h
blob1e43c8a532d70367073c414b58e228745b18bf50
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 SVFilter;
71 class FormantFilter;
72 class ModFilter;
74 typedef double fftw_real;
75 typedef std::complex<fftw_real> fft_t;
77 /**
78 * The number of harmonics of additive synth
79 * This must be smaller than OSCIL_SIZE/2
81 #define MAX_AD_HARMONICS 128
84 /**
85 * The number of harmonics of substractive
87 #define MAX_SUB_HARMONICS 64
91 * The maximum number of samples that are used for 1 PADsynth instrument(or item)
93 #define PAD_MAX_SAMPLES 64
97 * Number of parts
99 #define NUM_MIDI_PARTS 16
102 * Number of Midi channels
104 #define NUM_MIDI_CHANNELS 16
107 * The number of voices of additive synth for a single note
109 #define NUM_VOICES 8
112 * The polyphony (notes)
114 #define POLYPHONY 60
117 * Number of system effects
119 #define NUM_SYS_EFX 4
123 * Number of insertion effects
125 #define NUM_INS_EFX 8
128 * Number of part's insertion effects
130 #define NUM_PART_EFX 3
133 * Maximum number of the instrument on a part
135 #define NUM_KIT_ITEMS 16
139 * How is applied the velocity sensing
141 #define VELOCITY_MAX_SCALE 8.0f
144 * The maximum length of instrument's name
146 #define PART_MAX_NAME_LEN 30
149 * The maximum we allow for an XMZ path
151 * Note that this is an ugly hack. Finding a compile time path
152 * max portably is painful.
154 #define XMZ_PATH_MAX 1024
157 * The maximum number of bands of the equaliser
159 #define MAX_EQ_BANDS 8
160 #if (MAX_EQ_BANDS >= 20)
161 #error "Too many EQ bands in globals.h"
162 #endif
166 * Maximum filter stages
168 #define MAX_FILTER_STAGES 5
171 * Formant filter (FF) limits
173 #define FF_MAX_VOWELS 6
174 #define FF_MAX_FORMANTS 12
175 #define FF_MAX_SEQUENCE 8
177 #define MAX_PRESETTYPE_SIZE 30
179 #define LOG_2 0.693147181f
180 #define PI 3.1415926536f
181 #define LOG_10 2.302585093f
184 * For de-pop adjustment
186 #define FADEIN_ADJUSTMENT_SCALE 20
189 * Envelope Limits
191 #define MAX_ENVELOPE_POINTS 40
192 #define MIN_ENVELOPE_DB -400
195 * The threshold for the amplitude interpolation used if the amplitude
196 * is changed (by LFO's or Envelope's). If the change of the amplitude
197 * is below this, the amplitude is not interpolated
199 #define AMPLITUDE_INTERPOLATION_THRESHOLD 0.0001f
202 * How the amplitude threshold is computed
204 #define ABOVE_AMPLITUDE_THRESHOLD(a, b) ((2.0f * fabsf((b) - (a)) \
205 / (fabsf((b) + (a) \
206 + 0.0000000001f))) > \
207 AMPLITUDE_INTERPOLATION_THRESHOLD)
210 * Interpolate Amplitude
212 #define INTERPOLATE_AMPLITUDE(a, b, x, size) ((a) \
213 + ((b) \
214 - (a)) * (float)(x) \
215 / (float) (size))
219 * dB
221 #define dB2rap(dB) ((expf((dB) * LOG_10 / 20.0f)))
222 #define rap2dB(rap) ((20 * logf(rap) / LOG_10))
224 #define ZERO(data, size) {char *data_ = (char *) data; for(int i = 0; \
225 i < size; \
226 i++) \
227 data_[i] = 0; }
228 #define ZERO_float(data, size) {float *data_ = (float *) data; \
229 for(int i = 0; \
230 i < size; \
231 i++) \
232 data_[i] = 0.0f; }
234 enum ONOFFTYPE {
235 OFF = 0, ON = 1
238 enum MidiControllers {
239 C_bankselectmsb = 0, C_pitchwheel = 1000, C_NULL = 1001,
240 C_aftertouch = 1002, C_pitch = 1003,
241 C_expression = 11, C_panning = 10, C_bankselectlsb = 32,
242 C_filtercutoff = 74, C_filterq = 71, C_bandwidth = 75, C_modwheel = 1,
243 C_fmamp = 76,
244 C_volume = 7, C_sustain = 64, C_allnotesoff = 123, C_allsoundsoff = 120,
245 C_resetallcontrollers = 121,
246 C_portamento = 65, C_resonance_center = 77, C_resonance_bandwidth = 78,
248 C_dataentryhi = 0x06, C_dataentrylo = 0x26, C_nrpnhi = 99, C_nrpnlo = 98
251 enum LegatoMsg {
252 LM_Norm, LM_FadeIn, LM_FadeOut, LM_CatchUp, LM_ToNorm
255 //is like i=(int)(floor(f))
256 #ifdef ASM_F2I_YES
257 #define F2I(f, i)\
258 do {\
259 __asm__ __volatile__\
260 ("fistpl %0" : "=m" (i) : "t" (f - 0.49999999f) : "st");\
261 } while (false)
262 #else
263 #define F2I(f, i)\
264 do {\
265 (i) = ((f > 0) ? ((int)(f)) : ((int)(f - 1.0f)));\
266 } while (false)
267 #endif
271 #ifndef O_BINARY
272 #define O_BINARY 0
273 #endif
275 template<class T>
276 class m_unique_array
278 T* ptr = nullptr; //!< @invariant nullptr or pointer to new[]'ed memory
279 public:
280 m_unique_array() = default;
281 m_unique_array(m_unique_array&& other) : ptr(other.ptr) {
282 other.ptr = nullptr;
284 m_unique_array& operator=(m_unique_array&& other) {
285 ptr = other.ptr;
286 other.ptr = nullptr;
287 return *this;
289 m_unique_array(const m_unique_array& other) = delete;
290 ~m_unique_array() { delete[] ptr; ptr = nullptr; }
291 void resize(unsigned sz) {
292 delete[] ptr;
293 ptr = new T[sz]; }
295 operator T*() { return ptr; }
296 operator const T*() const { return ptr; }
297 //T& operator[](unsigned idx) { return ptr[idx]; }
298 //const T& operator[](unsigned idx) const { return ptr[idx]; }
301 //temporary include for synth->{samplerate/buffersize} members
302 struct SYNTH_T {
304 SYNTH_T(void)
305 :samplerate(44100), buffersize(256), oscilsize(1024)
307 alias(false);
310 SYNTH_T(const SYNTH_T& ) = delete;
311 SYNTH_T(SYNTH_T&& ) = default;
312 SYNTH_T& operator=(const SYNTH_T& ) = delete;
313 SYNTH_T& operator=(SYNTH_T&& ) = default;
315 /** the buffer to add noise in order to avoid denormalisation */
316 m_unique_array<float> denormalkillbuf;
318 /**Sampling rate*/
319 unsigned int samplerate;
322 * The size of a sound buffer (or the granularity)
323 * All internal transfer of sound data use buffer of this size.
324 * All parameters are constant during this period of time, except
325 * some parameters(like amplitudes) which are linearly interpolated.
326 * If you increase this you'll ecounter big latencies, but if you
327 * decrease this the CPU requirements gets high.
329 int buffersize;
332 * The size of ADnote Oscillator
333 * Decrease this => poor quality
334 * Increase this => CPU requirements gets high (only at start of the note)
336 int oscilsize;
338 //Alias for above terms
339 float samplerate_f;
340 float halfsamplerate_f;
341 float buffersize_f;
342 int bufferbytes;
343 float oscilsize_f;
345 float dt(void) const
347 return buffersize_f / samplerate_f;
349 void alias(bool randomize=true);
350 static float numRandom(void); //defined in Util.cpp for now
353 class smooth_float {
354 private:
355 bool init;
356 float curr_value;
357 float next_value;
358 public:
359 smooth_float() {
360 init = false;
361 next_value = curr_value = 0.0f;
363 smooth_float(const float value) {
364 init = true;
365 next_value = curr_value = value;
367 operator float() {
368 const float delta = (next_value - curr_value) / 128.0f;
369 curr_value += delta;
370 return (curr_value);
372 void operator =(const float value) {
373 if (init) {
374 next_value = value;
375 } else {
376 next_value = curr_value = value;
377 init = true;
380 bool isSet() const {
381 return (init);
386 #endif