AAX SDK 2.6.1
Avid Audio Extensions Development Kit
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
57template <typename T, int32_t RealPrecision=1000>
59{
60public:
68 AAX_CLogTaperDelegate(T minValue=0, T maxValue=1);
69
70 //Virtual Overrides
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
78protected:
79 T Round(double iValue) const;
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>
97 mMinValue(minValue),
98 mMaxValue(maxValue)
99{
100
101}
102
103template <typename T, int32_t RealPrecision>
105{
106 return new AAX_CLogTaperDelegate(*this);
107}
108
109template <typename T, int32_t RealPrecision>
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
129template <typename T, int32_t RealPrecision>
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
141template <typename T, int32_t RealPrecision>
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
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
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:50
A logarithmic taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLogTaperDelegate.h:59
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLogTaperDelegate.h:130
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLogTaperDelegate.h:72
AAX_CLogTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Log Taper with specified minimum and maximum values.
Definition: AAX_CLogTaperDelegate.h:96
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLogTaperDelegate.h:73
T Round(double iValue) const
Definition: AAX_CLogTaperDelegate.h:87
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLogTaperDelegate.h:142
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< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLogTaperDelegate.h:104
Definition: AAX_ITaperDelegate.h:86