| AAX SDK 2.8.0 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-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
31/*================================================================================================*/
32
33
34#ifndef AAX_CLOGTAPERDELEGATE_H
35#define AAX_CLOGTAPERDELEGATE_H
36
37#include "AAX_ITaperDelegate.h"
38#include "AAX_UtilsNative.h"
39#include "AAX.h" //for types
40
41#include <cmath> //for floor(), log()
42
43
44
70 template <typename T, int32_t RealPrecision=1000>
71 class AAX_CLogTaperDelegate : public AAX_ITaperDelegate<T>
72{
73 public:
81 AAX_CLogTaperDelegate(T minValue=0, T maxValue=1);
82
83 //Virtual Overrides
84 AAX_CLogTaperDelegate<T, RealPrecision>* Clone() const AAX_OVERRIDE;
85 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
86 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
87 T ConstrainRealValue(T value) const AAX_OVERRIDE;
88 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
89 double RealToNormalized(T realValue) const AAX_OVERRIDE;
90
91 protected:
92 T Round(double iValue) const;
93
94 private:
95 T mMinValue;
96 T mMaxValue;
97};
98
99 template <typename T, int32_t RealPrecision>
100T AAX_CLogTaperDelegate<T, RealPrecision>::Round(double iValue) const
101{
102 double precision = RealPrecision;
103 if (precision > 0)
104 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
105 return static_cast<T>(iValue);
106}
107
108 template <typename T, int32_t RealPrecision>
109 AAX_CLogTaperDelegate<T, RealPrecision>::AAX_CLogTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
110 mMinValue(minValue),
111 mMaxValue(maxValue)
112{
113
114}
115
116 template <typename T, int32_t RealPrecision>
117 AAX_CLogTaperDelegate<T, RealPrecision>* AAX_CLogTaperDelegate<T, RealPrecision>::Clone() const
118{
119 return new AAX_CLogTaperDelegate(*this);
120}
121
122 template <typename T, int32_t RealPrecision>
123T AAX_CLogTaperDelegate<T, RealPrecision>::ConstrainRealValue(T value) const
124{
125 if (mMinValue == mMaxValue)
126 return mMinValue;
127
128 if (RealPrecision)
129 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
130
131 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
132 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
133
134 if (value > highValue)
135 return highValue;
136 if (value < lowValue)
137 return lowValue;
138
139 return value;
140}
141
142 template <typename T, int32_t RealPrecision>
143T AAX_CLogTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
144{
145 double minLog = AAX::SafeLog(double(mMinValue));
146 double maxLog = AAX::SafeLog(double(mMaxValue));
147
148 double doubleRealValue = exp(normalizedValue * (maxLog - minLog) + minLog);
149 T realValue = (T) doubleRealValue;
150
151 return ConstrainRealValue(realValue);
152}
153
154 template <typename T, int32_t RealPrecision>
155 double AAX_CLogTaperDelegate<T, RealPrecision>::RealToNormalized(T realValue) const
156{
157 double minLog = AAX::SafeLog(double(mMinValue));
158 double maxLog = AAX::SafeLog(double(mMaxValue));
159
160 realValue = ConstrainRealValue(realValue);
161 double normalizedValue = (maxLog == minLog) ? 0.5 : (AAX::SafeLog(double(realValue)) - minLog) / (maxLog - minLog);
162 return normalizedValue;
163}
164
165#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:164
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:63
AAX_CLogTaperDelegate
A logarithmic taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLogTaperDelegate.h:72
AAX_CLogTaperDelegate::NormalizedToReal
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLogTaperDelegate.h:143
AAX_CLogTaperDelegate::GetMinimumValue
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLogTaperDelegate.h:85
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:109
AAX_CLogTaperDelegate::GetMaximumValue
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLogTaperDelegate.h:86
AAX_CLogTaperDelegate::Round
T Round(double iValue) const
Definition: AAX_CLogTaperDelegate.h:100
AAX_CLogTaperDelegate::RealToNormalized
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLogTaperDelegate.h:155
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:123
AAX_CLogTaperDelegate::Clone
AAX_CLogTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLogTaperDelegate.h:117
AAX_ITaperDelegate
Definition: AAX_ITaperDelegate.h:99