AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CLogTaperDelegate.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013-2017, 2019 by Avid Technology, Inc.
5  * All rights reserved.
6  *
7  * CONFIDENTIAL: This document contains confidential information. Do not
8  * read or examine this document unless you are an Avid Technology employee
9  * or have signed a non-disclosure agreement with Avid Technology which protects
10  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
11  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
12  * OF Avid Technology, INC.
13  *
14  */
15 
21 /*================================================================================================*/
22 
23 
24 #ifndef AAX_CLOGTAPERDELEGATE_H
25 #define AAX_CLOGTAPERDELEGATE_H
26 
27 #include "AAX_ITaperDelegate.h"
28 #include "AAX_UtilsNative.h"
29 #include "AAX.h" //for types
30 
31 #include <cmath> //for floor(), log()
32 
33 
34 
60 template <typename T, int32_t RealPrecision=1000>
62 {
63 public:
71  AAX_CLogTaperDelegate(T minValue=0, T maxValue=1);
72 
73  //Virtual Overrides
75  T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
76  T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
77  T ConstrainRealValue(T value) const AAX_OVERRIDE;
78  T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
79  double RealToNormalized(T realValue) const AAX_OVERRIDE;
80 
81 protected:
82  T Round(double iValue) const;
83 
84 private:
85  T mMinValue;
86  T mMaxValue;
87 };
88 
89 template <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 
98 template <typename T, int32_t RealPrecision>
100  mMinValue(minValue),
101  mMaxValue(maxValue)
102 {
103 
104 }
105 
106 template <typename T, int32_t RealPrecision>
108 {
109  return new AAX_CLogTaperDelegate(*this);
110 }
111 
112 template <typename T, int32_t RealPrecision>
114 {
115  if (mMinValue == mMaxValue)
116  return mMinValue;
117 
118  if (RealPrecision)
119  value = Round(value); //reduce the precision to get proper rounding behavior with integers.
120 
121  const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
122  const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
123 
124  if (value > highValue)
125  return highValue;
126  if (value < lowValue)
127  return lowValue;
128 
129  return value;
130 }
131 
132 template <typename T, int32_t RealPrecision>
134 {
135  double minLog = AAX::SafeLog(double(mMinValue));
136  double maxLog = AAX::SafeLog(double(mMaxValue));
137 
138  double doubleRealValue = exp(normalizedValue * (maxLog - minLog) + minLog);
139  T realValue = (T) doubleRealValue;
140 
141  return ConstrainRealValue(realValue);
142 }
143 
144 template <typename T, int32_t RealPrecision>
146 {
147  double minLog = AAX::SafeLog(double(mMinValue));
148  double maxLog = AAX::SafeLog(double(mMaxValue));
149 
150  realValue = ConstrainRealValue(realValue);
151  double normalizedValue = (maxLog == minLog) ? 0.5 : (AAX::SafeLog(double(realValue)) - minLog) / (maxLog - minLog);
152  return normalizedValue;
153 }
154 
155 #endif // AAX_CLOGTAPERDELEGATE_H
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX Native.
double SafeLog(double aValue)
Double-precision safe log function. Returns zero for input values that are <= 0.0.
Definition: AAX_UtilsNative.h:53
A logarithmic taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLogTaperDelegate.h:62
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLogTaperDelegate.h:133
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLogTaperDelegate.h:75
AAX_CLogTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Log Taper with specified minimum and maximum values.
Definition: AAX_CLogTaperDelegate.h:99
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLogTaperDelegate.h:76
T Round(double iValue) const
Definition: AAX_CLogTaperDelegate.h:90
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLogTaperDelegate.h:145
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLogTaperDelegate.h:113
AAX_CLogTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLogTaperDelegate.h:107
Classes for conversion to and from normalized parameter values.
Definition: AAX_ITaperDelegate.h:89