ASPiK SDK
guiconstants.h
1 // -----------------------------------------------------------------------------
2 // ASPiK Plugin Kernel File: guiconstants.h
3 //
12 // -----------------------------------------------------------------------------
13 #ifndef _guiconstants_h
14 #define _guiconstants_h
15 
16 #define _MATH_DEFINES_DEFINED
17 
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include <vector>
21 #include <string>
22 #include <math.h>
23 
24 // --- RESERVED PARAMETER ID VALUES
25 const unsigned int PLUGIN_SIDE_BYPASS = 131072;
26 const unsigned int XY_TRACKPAD = 131073;
27 const unsigned int VECTOR_JOYSTICK = 131074;
28 const unsigned int PRESET_NAME = 131075;
29 const unsigned int WRITE_PRESET_FILE = 131076;
30 const unsigned int SCALE_GUI_SIZE = 131077;
31 // --- 131078 -through- 131999 are RESERVED ///<RESERVED PARAMETER ID VALUE
32 
33 // --- custom views may be added using the base here: e.g.
34 // const unsigned int CUSTOM_SPECTRUM_VIEW = CUSTOM_VIEW_BASE + 1;
35 const unsigned int CUSTOM_VIEW_BASE = 132000;
36 
37 // --- enum for the GUI object's message processing
38 enum { tinyGUI, verySmallGUI, smallGUI, normalGUI, largeGUI, veryLargeGUI };
39 
49 inline bool isReservedTag(int tag)
50 {
51  // --- these are reserved
52  if (tag >= 131072 && tag <= 131999)
53  return true;
54  return false;
55 }
56 
67 inline bool isBonusParameter(int tag)
68 {
69  // --- these are reserved
70  if (tag == XY_TRACKPAD ||
71  tag == VECTOR_JOYSTICK ||
72  tag == PRESET_NAME ||
73  tag == WRITE_PRESET_FILE ||
74  tag == SCALE_GUI_SIZE)
75  return true;
76 
77  return false;
78 }
79 
80 // --- typed enumeration helpers
90 #define enumToInt(ENUM) static_cast<int>(ENUM)
91 
102 #define compareEnumToInt(ENUM,INT) (static_cast<int>(ENUM) == (INT))
103 
115 #define compareIntToEnum(INT,ENUM) ((INT) == static_cast<int>(ENUM))
116 
128 #define convertIntToEnum(INT,ENUM) static_cast<ENUM>(INT)
129 
135 const double kCTCoefficient = 5.0 / 12.0;
136 
142 const double kCTCorrFactorZero = pow(10.0, (-1.0/kCTCoefficient));
143 
149 const double kCTCorrFactorAnitZero = 1.0 / (1.0 - kCTCorrFactorZero);
150 
156 const double kCTCorrFactorUnity = 1.0 / (1.0 + kCTCoefficient*log10(1.0 + kCTCorrFactorZero));
157 
163 const double kCTCorrFactorAntiUnity = 1.0 / (1.0 + (-pow(10.0, (-1.0/kCTCoefficient))));
164 
171 
178 
184 const double kPi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
185 
191 const double kTwoPi = 2.0*3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
192 
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
198 // ---
199 const uint32_t ENVELOPE_DETECT_MODE_PEAK = 0;
200 const uint32_t ENVELOPE_DETECT_MODE_MS = 1;
201 const uint32_t ENVELOPE_DETECT_MODE_RMS = 2;
202 const uint32_t ENVELOPE_DETECT_MODE_NONE = 3;
203 
204 const float ENVELOPE_DIGITAL_TC = -4.6051701859880913680359829093687;
205 const float ENVELOPE_ANALOG_TC = -1.0023934309275667804345424248947;
206 
210 // ---
211 const float GUI_METER_UPDATE_INTERVAL_MSEC = 50.f;
212 const float GUI_METER_MIN_DB = -60.f;
213 
216 #define FLT_EPSILON_PLUS 1.192092896e-07
217 
218 #define FLT_EPSILON_MINUS -1.192092896e-07
219 
220 #define FLT_MIN_PLUS 1.175494351e-38
221 
222 #define FLT_MIN_MINUS -1.175494351e-38
223 
224 // --- for math.h constants
225 #define _MATH_DEFINES_DEFINED
226 
240 enum class smoothingMethod { kLinearSmoother, kLPFSmoother };
241 
255 enum class taper { kLinearTaper, kLogTaper, kAntiLogTaper, kVoltOctaveTaper };
256 
270 enum class meterCal { kLinearMeter, kLogMeter };
271 
288 enum class controlVariableType { kFloat, kDouble, kInt, kTypedEnumStringList, kMeter, kNonVariableBoundControl };
289 
290 
304 enum class boundVariableType { kFloat, kDouble, kInt, kUInt };
305 
318 template <class T>
319 class ParamSmoother
320 {
321 public:
322  ParamSmoother() { a = 0.0; b = 0.0; z = 0.0; z2 = 0.0; }
323 
327  void setSampleRate(T samplingRate)
328  {
329  sampleRate = samplingRate;
330 
331  // --- for LPF smoother
332  a = exp(-kTwoPi / (smoothingTimeInMSec * 0.001 * sampleRate));
333  b = 1.0 - a;
334 
335  // --- for linear smoother
336  linInc = (maxVal - minVal) / (smoothingTimeInMSec * 0.001 * sampleRate);
337  }
338 
347  void initParamSmoother(T smoothingTimeInMs,
348  T samplingRate,
349  T initValue,
350  T minControlValue,
351  T maxControlValue,
352  smoothingMethod smoother = smoothingMethod::kLPFSmoother)
353  {
354  minVal = minControlValue;
355  maxVal = maxControlValue;
356  sampleRate = samplingRate;
357  smoothingTimeInMSec = smoothingTimeInMs;
358 
359  setSampleRate(samplingRate);
360 
361  // --- storage
362  z = initValue;
363  z2 = initValue;
364  }
365 
371  inline bool smoothParameter(T in, T& out)
372  {
373  if (smootherType == smoothingMethod::kLPFSmoother)
374  {
375  z = (in * b) + (z * a);
376  if (z == z2)
377  {
378  out = in;
379  return false;
380  }
381  z2 = z;
382  out = z2;
383  return true;
384  }
385  else // if (smootherType == smoothingMethod::kLinearSmoother)
386  {
387  if (in == z)
388  {
389  out = in;
390  return false;
391  }
392  if (in > z)
393  {
394  z += linInc;
395  if (z > in) z = in;
396  }
397  else if (in < z)
398  {
399  z -= linInc;
400  if (z < in) z = in;
401  }
402  out = z;
403  return true;
404  }
405  }
406 
407 private:
408  T a = 0.0;
409  T b = 0.0;
410  T z = 0.0;
411  T z2 = 0.0;
412 
413  T linInc = 0.0;
414 
415  T minVal = 0.0;
416  T maxVal = 1.0;
417 
418  T sampleRate = 44100;
419  T smoothingTimeInMSec = 100.0;
420 
421  smoothingMethod smootherType = smoothingMethod::kLPFSmoother;
422 };
423 
424 
425 #endif
void initParamSmoother(T smoothingTimeInMs, T samplingRate, T initValue, T minControlValue, T maxControlValue, smoothingMethod smoother=smoothingMethod::kLPFSmoother)
Definition: guiconstants.h:347
const double kCTCorrFactorAntiLogScale
concave/convex transform scaling factor
Definition: guiconstants.h:177
bool smoothParameter(T in, T &out)
Definition: guiconstants.h:371
const double kTwoPi
2pi to 80 decimal places
Definition: guiconstants.h:191
smoothingMethod
Use this strongly typed enum to easily set the smoothing type.
Definition: guiconstants.h:240
const double kCTCorrFactorZero
concave/convex transform correction factor at x = 0
Definition: guiconstants.h:142
The ParamSmoother object performs parameter smoothing on GUI control information. You can choose line...
Definition: guiconstants.h:319
const double kCTCorrFactorAntiLog
concave/convex transform correction factor
Definition: guiconstants.h:170
meterCal
Use this strongly typed enum to easily set meter calibration.
Definition: guiconstants.h:270
bool isBonusParameter(int tag)
check to see if a tag is Bonus Parameter: these should NOT be added to API parameter lists ...
Definition: guiconstants.h:67
const uint32_t ENVELOPE_DETECT_MODE_PEAK
|x|
Definition: guiconstants.h:199
controlVariableType
Use this strongly typed enum to easily set the control&#39;s behavior; this tells the PluginParameter obj...
Definition: guiconstants.h:288
const double kPi
pi to 80 decimal places
Definition: guiconstants.h:184
const float GUI_METER_UPDATE_INTERVAL_MSEC
repaint interval; larger = slower
Definition: guiconstants.h:211
bool isReservedTag(int tag)
check to see if a tag is reserved: ASPiK defines several reserved control ID values.
Definition: guiconstants.h:49
const double kCTCoefficient
concave and/or convex transform correction factor
Definition: guiconstants.h:135
const float ENVELOPE_DIGITAL_TC
ln(1%)
Definition: guiconstants.h:204
boundVariableType
Use this strongly typed enum to easily set the control&#39;s linked variable datatype (for automatic vari...
Definition: guiconstants.h:304
const double kCTCorrFactorAnitZero
inverse concave/convex transform factor at x = 0
Definition: guiconstants.h:149
const double kCTCorrFactorAntiUnity
inverse concave/convex transform correction factor at x = 1
Definition: guiconstants.h:163
const uint32_t ENVELOPE_DETECT_MODE_NONE
not used
Definition: guiconstants.h:202
const uint32_t ENVELOPE_DETECT_MODE_MS
(1/N)|x|^2
Definition: guiconstants.h:200
void setSampleRate(T samplingRate)
Definition: guiconstants.h:327
const uint32_t ENVELOPE_DETECT_MODE_RMS
SQRT((1/N)|x|^2)
Definition: guiconstants.h:201
const double kCTCorrFactorUnity
concave/convex transform correction factor at x = 1
Definition: guiconstants.h:156
const float ENVELOPE_ANALOG_TC
ln(36.7%)
Definition: guiconstants.h:205
taper
Use this strongly typed enum to easily set the control taper.
Definition: guiconstants.h:255