| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_CLogTaperDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-2017, 2019, 2023 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * CONFIDENTIAL: this document contains confidential information of Avid. Do
8 * not disclose to any third party. Use of the information contained in this
9 * document is subject to an Avid SDK license.
10 *
11 */
12
18/*================================================================================================*/
19
20
21#ifndef AAX_CLOGTAPERDELEGATE_H
22#define AAX_CLOGTAPERDELEGATE_H
23
24#include "AAX_ITaperDelegate.h"
25#include "AAX_UtilsNative.h"
26#include "AAX.h" //for types
27
28#include <cmath> //for floor(), log()
29
30
31
57 template <typename T, int32_t RealPrecision=1000>
58 class AAX_CLogTaperDelegate : public AAX_ITaperDelegate<T>
59{
60 public:
68 AAX_CLogTaperDelegate(T minValue=0, T maxValue=1);
69
70 //Virtual Overrides
71 AAX_CLogTaperDelegate<T, RealPrecision>* Clone() const AAX_OVERRIDE;
72 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
73 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
74 T ConstrainRealValue(T value) const AAX_OVERRIDE;
75 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
76 double RealToNormalized(T realValue) const AAX_OVERRIDE;
77
78 protected:
79 T Round(double iValue) const;
80
81 private:
82 T mMinValue;
83 T mMaxValue;
84};
85
86 template <typename T, int32_t RealPrecision>
87T AAX_CLogTaperDelegate<T, RealPrecision>::Round(double iValue) const
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
95 template <typename T, int32_t RealPrecision>
96 AAX_CLogTaperDelegate<T, RealPrecision>::AAX_CLogTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
97 mMinValue(minValue),
98 mMaxValue(maxValue)
99{
100
101}
102
103 template <typename T, int32_t RealPrecision>
104 AAX_CLogTaperDelegate<T, RealPrecision>* AAX_CLogTaperDelegate<T, RealPrecision>::Clone() const
105{
106 return new AAX_CLogTaperDelegate(*this);
107}
108
109 template <typename T, int32_t RealPrecision>
110T AAX_CLogTaperDelegate<T, RealPrecision>::ConstrainRealValue(T value) const
111{
112 if (mMinValue == mMaxValue)
113 return mMinValue;
114
115 if (RealPrecision)
116 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
117
118 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
119 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
120
121 if (value > highValue)
122 return highValue;
123 if (value < lowValue)
124 return lowValue;
125
126 return value;
127}
128
129 template <typename T, int32_t RealPrecision>
130T AAX_CLogTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
131{
132 double minLog = AAX::SafeLog(double(mMinValue));
133 double maxLog = AAX::SafeLog(double(mMaxValue));
134
135 double doubleRealValue = exp(normalizedValue * (maxLog - minLog) + minLog);
136 T realValue = (T) doubleRealValue;
137
138 return ConstrainRealValue(realValue);
139}
140
141 template <typename T, int32_t RealPrecision>
142 double AAX_CLogTaperDelegate<T, RealPrecision>::RealToNormalized(T realValue) const
143{
144 double minLog = AAX::SafeLog(double(mMinValue));
145 double maxLog = AAX::SafeLog(double(mMaxValue));
146
147 realValue = ConstrainRealValue(realValue);
148 double normalizedValue = (maxLog == minLog) ? 0.5 : (AAX::SafeLog(double(realValue)) - minLog) / (maxLog - minLog);
149 return normalizedValue;
150}
151
152#endif // AAX_CLOGTAPERDELEGATE_H
AAX_ITaperDelegate.h
Defines the taper conversion behavior for a parameter.
AAX.h
Various utility definitions for AAX.
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
AAX_UtilsNative.h
Various utility definitions for AAX Native.
AAX::SafeLog
double SafeLog(double aValue)
Double-precision safe log function. Returns zero for input values that are <= 0.0.
Definition: AAX_UtilsNative.h:50
AAX_CLogTaperDelegate
A logarithmic taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLogTaperDelegate.h:59
AAX_CLogTaperDelegate::NormalizedToReal
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLogTaperDelegate.h:130
AAX_CLogTaperDelegate::GetMinimumValue
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLogTaperDelegate.h:72
AAX_CLogTaperDelegate::AAX_CLogTaperDelegate
AAX_CLogTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Log Taper with specified minimum and maximum values.
Definition: AAX_CLogTaperDelegate.h:96
AAX_CLogTaperDelegate::GetMaximumValue
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLogTaperDelegate.h:73
AAX_CLogTaperDelegate::Round
T Round(double iValue) const
Definition: AAX_CLogTaperDelegate.h:87
AAX_CLogTaperDelegate::RealToNormalized
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLogTaperDelegate.h:142
AAX_CLogTaperDelegate::ConstrainRealValue
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLogTaperDelegate.h:110
AAX_CLogTaperDelegate::Clone
AAX_CLogTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLogTaperDelegate.h:104
AAX_ITaperDelegate
Definition: AAX_ITaperDelegate.h:86