ASPiK SDK
Loading...
Searching...
No Matches
VoltOctaveTaperDelegate.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2// ASPiK AAX Shell File: voltoctavetaperdelegate.h
3//
18// -----------------------------------------------------------------------------
19#ifndef __VOLTOCTAVETAPERDELEGATE_H
20#define __VOLTOCTAVETAPERDELEGATE_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
28template <typename T, int32_t RealPrecision=1000>
29
45class VoltOctaveTaperDelegate : public AAX_ITaperDelegate<T>
46{
47public:
48 VoltOctaveTaperDelegate(T minValue=0, T maxValue=1);
49
50 // --- Virtual Overrides
52 T GetMinimumValue() const { return mMinValue; }
53 T GetMaximumValue() const { return mMaxValue; }
54 T ConstrainRealValue(T value) const;
55 T NormalizedToReal(double normalizedValue) const;
56 double RealToNormalized(T realValue) const;
57
58protected:
59 T Round(double iValue) const;
60
61 // --- cooked to V/O Scaled 0->1 param
62 inline double calcVoltOctaveParameter(double fCookedParam) const
63 {
64 double dOctaves = log2(getMax()/getMin());
65 return log2( fCookedParam/getMin() )/dOctaves;
66 }
67
68 // --- fPluginValue = 0->1
69 // returns V/O scaled version 0->1
70 inline double calcVoltOctavePluginValue(double fPluginValue) const
71 {
72 double dOctaves = log2(getMax()/getMin());
73 float fDisplay = getMin()*exp2(fPluginValue*dOctaves);
74 float fDiff = getMax() - getMin();
75 return (fDisplay - getMin())/fDiff;
76 }
77
78 double getMin() const {return (double)mMinValue;}
79 double getMax() const {return (double)mMaxValue;}
80
81private:
82 T mMinValue;
83 T mMaxValue;
84};
85
86template <typename T, int32_t RealPrecision>
88{
89 double precision = RealPrecision;
90 if (precision > 0)
91 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
92 return static_cast<T>(iValue);
93}
94
95template <typename T, int32_t RealPrecision>
96VoltOctaveTaperDelegate<T, RealPrecision>::VoltOctaveTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
97 mMinValue(minValue),
98 mMaxValue(maxValue)
99{
100
101}
102
103template <typename T, int32_t RealPrecision>
105{
106 return new VoltOctaveTaperDelegate(*this);
107}
108
109template <typename T, int32_t RealPrecision>
111{
112 if (RealPrecision)
113 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
114
115 if (value > mMaxValue)
116 return mMaxValue;
117 if (value < mMinValue)
118 return mMinValue;
119 return value;
120}
121
122template <typename T, int32_t RealPrecision>
124{
125 normalizedValue = calcVoltOctavePluginValue(normalizedValue);
126 double doubleRealValue = normalizedValue*(mMaxValue - mMinValue) + mMinValue;
127 T realValue = (T) doubleRealValue;
128
129 return ConstrainRealValue(realValue);
130}
131
132template <typename T, int32_t RealPrecision>
134{
135 return calcVoltOctaveParameter(realValue);
136}
137
138#endif // __VOLTOCTAVETAPERDELEGATE_H
Definition: VoltOctaveTaperDelegate.h:46