ASPiK SDK
Loading...
Searching...
No Matches
LogTaperDelegate.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// ASPiK AAX Shell File: logtaperdelegate.h
3//
18// -----------------------------------------------------------------------------
19#ifndef __LOGTAPERDELEGATE_H
20#define __LOGTAPERDELEGATE_H
21
22#include "AAX_ITaperDelegate.h"
23#include "AAX_UtilsNative.h"
24#include "AAX.h" //for types
25
26#include <cmath> //for floor(), log()
27#include "guiconstants.h"
28
29template <typename T, int32_t RealPrecision=1000>
30
46class LogTaperDelegate : public AAX_ITaperDelegate<T>
47{
48public:
49 LogTaperDelegate(T minValue=0, T maxValue=1);
50
51 // --- Virtual Overrides
53 T GetMinimumValue() const { return mMinValue; }
54 T GetMaximumValue() const { return mMaxValue; }
55 T ConstrainRealValue(T value) const;
56 T NormalizedToReal(double normalizedValue) const;
57 double RealToNormalized(T realValue) const;
58
59protected:
60 T Round(double iValue) const;
61
62 // --- fNormalizedParam = 0->1
63 // returns log scaled 0->1 value
64 inline double calcLogParameter(double fNormalizedParam) const
65 {
66 if(fNormalizedParam <= 0.0) return 0.0;
67 if(fNormalizedParam >= 1.0) return 1.0;
68
69 // --- MMA Convex Transform Inverse
70 return kCTCorrFactorAnitZero * ( pow (10.0, (fNormalizedParam - 1) / kCTCoefficient) - kCTCorrFactorZero);
71 }
72
73 // --- fPluginValue = 0->1 log scaled value
74 // returns normal 0-> value
75 inline double calcLogPluginValue(double fPluginValue) const
76 {
77 if(fPluginValue <= 0.0) return 0.0;
78 if(fPluginValue >= 1.0) return 1.0;
79
80 // --- MMA Convex Transform
81 return kCTCorrFactorUnity*(1.0 + kCTCoefficient*log10(fPluginValue + kCTCorrFactorZero));
82 }
83
84private:
85 T mMinValue;
86 T mMaxValue;
87};
88
89template <typename T, int32_t RealPrecision>
91{
92 double precision = RealPrecision;
93 if (precision > 0)
94 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
95 return static_cast<T>(iValue);
96}
97
98template <typename T, int32_t RealPrecision>
99LogTaperDelegate<T, RealPrecision>::LogTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
100 mMinValue(minValue),
101 mMaxValue(maxValue)
102{
103
104}
105
106template <typename T, int32_t RealPrecision>
108{
109 return new LogTaperDelegate(*this);
110}
111
112template <typename T, int32_t RealPrecision>
114{
115 if (RealPrecision)
116 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
117
118 if (value > mMaxValue)
119 return mMaxValue;
120 if (value < mMinValue)
121 return mMinValue;
122 return value;
123}
124
125template <typename T, int32_t RealPrecision>
126T LogTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
127{
128 normalizedValue = calcLogPluginValue(normalizedValue);
129 double doubleRealValue = normalizedValue*(mMaxValue - mMinValue) + mMinValue;
130
131 T realValue = (T) doubleRealValue;
132
133 return ConstrainRealValue(realValue);
134}
135
136template <typename T, int32_t RealPrecision>
138{
139 double normValue = (realValue - mMinValue)/(mMaxValue - mMinValue);
140 return calcLogParameter(normValue);
141}
142
143#endif // __LOGTAPERDELEGATE_H
The LogTaperDelegate object encapsulates a log parameter. Note that the standard log potentiometer in...
Definition: LogTaperDelegate.h:47
const double kCTCorrFactorUnity
concave/convex transform correction factor at x = 1
Definition: guiconstants.h:156
const double kCTCorrFactorAnitZero
inverse concave/convex transform factor at x = 0
Definition: guiconstants.h:149
const double kCTCoefficient
concave and/or convex transform correction factor
Definition: guiconstants.h:135
const double kCTCorrFactorZero
concave/convex transform correction factor at x = 0
Definition: guiconstants.h:142
globally utilized constants and enumerations