| 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_CPieceWiseLinearTaperDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-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
19/*================================================================================================*/
20
21
22#ifndef AAX_CPIECEWISELINEARTAPERDELEGATE_H
23#define AAX_CPIECEWISELINEARTAPERDELEGATE_H
24
25#include "AAX_ITaperDelegate.h"
26#include "AAX.h" //for types
27
28#include <cmath> //for floor()
29
30
54 template <typename T, int32_t RealPrecision=100>
55 class AAX_CPieceWiseLinearTaperDelegate : public AAX_ITaperDelegate<T>
56{
57 public:
66 AAX_CPieceWiseLinearTaperDelegate(const double* normalizedValues, const T* realValues, int32_t numValues);
67
68 AAX_CPieceWiseLinearTaperDelegate(const AAX_CPieceWiseLinearTaperDelegate& other); //Explicit copy constructor because there are internal arrays.
69 ~AAX_CPieceWiseLinearTaperDelegate();
70
71 //Virtual AAX_ITaperDelegate Overrides
72 AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>* Clone() const AAX_OVERRIDE;
73 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
74 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
75 T ConstrainRealValue(T value) const AAX_OVERRIDE;
76 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
77 double RealToNormalized(T realValue) const AAX_OVERRIDE;
78
79 protected:
80 T Round(double iValue) const;
81
82 private:
83 double* mNormalizedValues;
84 T* mRealValues;
85 int32_t mNumValues;
86 T mMinValue; //Really just an optimization
87 T mMaxValue; //Really just an optimization
88};
89
90 template <typename T, int32_t RealPrecision>
91T AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::Round(double iValue) const
92{
93 if (RealPrecision > 0)
94 return static_cast<T>(floor(iValue * RealPrecision + 0.5) / RealPrecision);
95 else
96 return static_cast<T>(iValue);
97}
98
99 template <typename T, int32_t RealPrecision>
100 AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::AAX_CPieceWiseLinearTaperDelegate(const double* normalizedValues, const T* realValues, int32_t numValues) : AAX_ITaperDelegate<T>(),
101 mNormalizedValues(0),
102 mRealValues(0),
103 mNumValues(0),
104 mMinValue(0),
105 mMaxValue(0)
106{
107 mNormalizedValues = new double[numValues];
108 mRealValues = new T[numValues];
109 mNumValues = numValues;
110
111 if (numValues > 0)
112 {
113 mMaxValue = realValues[0];
114 mMinValue = realValues[0];
115 }
116 for (int32_t i=0; i< numValues; i++)
117 {
118 mNormalizedValues[i] = normalizedValues[i];
119 mRealValues[i] = realValues[i];
120 if (mRealValues[i] > mMaxValue)
121 mMaxValue = mRealValues[i];
122 if (mRealValues[i] < mMinValue)
123 mMinValue = mRealValues[i];
124 }
125}
126
127 template <typename T, int32_t RealPrecision>
128 AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::AAX_CPieceWiseLinearTaperDelegate(const AAX_CPieceWiseLinearTaperDelegate& other) : AAX_ITaperDelegate<T>(),
129 mNormalizedValues(0),
130 mRealValues(0),
131 mNumValues(0),
132 mMinValue(0),
133 mMaxValue(0)
134{
135 mNormalizedValues = new double[other.mNumValues];
136 mRealValues = new T[other.mNumValues];
137 mNumValues = other.mNumValues;
138 mMaxValue = other.mMaxValue;
139 mMinValue = other.mMinValue;
140 for (int32_t i=0; i< mNumValues; i++)
141 {
142 mNormalizedValues[i] = other.mNormalizedValues[i];
143 mRealValues[i] = other.mRealValues[i];
144 }
145}
146
147 template <typename T, int32_t RealPrecision>
148 AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::~AAX_CPieceWiseLinearTaperDelegate()
149{
150 mNumValues = 0;
151 delete [] mNormalizedValues;
152 delete [] mRealValues;
153}
154
155
156 template <typename T, int32_t RealPrecision>
157 AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>* AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::Clone() const
158{
159 return new AAX_CPieceWiseLinearTaperDelegate(*this);
160}
161
162 template <typename T, int32_t RealPrecision>
163T AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::ConstrainRealValue(T value) const
164{
165 if (mMinValue == mMaxValue)
166 return mMinValue;
167
168 if (RealPrecision)
169 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
170
171 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
172 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
173
174 if (value > highValue)
175 return highValue;
176 if (value < lowValue)
177 return lowValue;
178
179 return value;
180}
181
182 template <typename T, int32_t RealPrecision>
183T AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
184{
185
186 // Clip to normalized range.
187 if (normalizedValue > 1.0)
188 normalizedValue = 1.0;
189 if (normalizedValue < 0.0)
190 normalizedValue = 0.0;
191
192 // This is basically linear interpolation so let's first find the bounding normalized points from our specified array.
193 int32_t mLowerIndex = 0;
194 int32_t mUpperIndex = 0;
195 for (int32_t i=1;i<mNumValues;i++)
196 {
197 mUpperIndex++;
198 if (mNormalizedValues[i] >= normalizedValue)
199 break;
200 mLowerIndex++;
201 }
202
203 // Do the interpolation.
204 double delta = normalizedValue - mNormalizedValues[mLowerIndex];
205 double slope = double(mRealValues[mUpperIndex] - mRealValues[mLowerIndex]) / (mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]);
206 double interpolatedValue = mRealValues[mLowerIndex] + (delta * slope);
207 return ConstrainRealValue(static_cast<T>(interpolatedValue));
208}
209
210 template <typename T, int32_t RealPrecision>
211 double AAX_CPieceWiseLinearTaperDelegate<T, RealPrecision>::RealToNormalized(T realValue) const
212{
213 realValue = ConstrainRealValue(realValue);
214
215 // This is basically linear interpolation so let's first find the bounding normalized points from our specified array.
216 int32_t mLowerIndex = 0;
217 int32_t mUpperIndex = 0;
218 if (mRealValues[0] < mRealValues[mNumValues-1])
219 {
220 //Increasing real values (positive slope)
221 for (int32_t i=1;i<mNumValues;i++)
222 {
223 mUpperIndex++;
224 if (mRealValues[i] >= realValue)
225 break;
226 mLowerIndex++;
227 }
228 }
229 else
230 {
231 //Decreasing real values (negative slope)
232 for (int32_t i=1;i<mNumValues;i++)
233 {
234 mUpperIndex++;
235 if (mRealValues[i] <= realValue)
236 break;
237 mLowerIndex++;
238 }
239 }
240
241 // Do the interpolation.
242 double delta = realValue - mRealValues[mLowerIndex];
243 double slope = (mRealValues[mUpperIndex] == mRealValues[mLowerIndex]) ? 0.5 : double(mNormalizedValues[mUpperIndex] - mNormalizedValues[mLowerIndex]) / (mRealValues[mUpperIndex] - mRealValues[mLowerIndex]);
244 double interpolatedValue = mNormalizedValues[mLowerIndex] + (delta * slope);
245 return static_cast<T>(interpolatedValue);
246}
247
248
249
250
251#endif //AAX_CPIECEWISELINEARTAPERDELEGATE_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_CPieceWiseLinearTaperDelegate
A piece-wise linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:56
AAX_CPieceWiseLinearTaperDelegate::GetMaximumValue
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:74
AAX_CPieceWiseLinearTaperDelegate::AAX_CPieceWiseLinearTaperDelegate
AAX_CPieceWiseLinearTaperDelegate(const double *normalizedValues, const T *realValues, int32_t numValues)
Constructs a Piece-wise Linear Taper with paired normalized and real values.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:100
AAX_CPieceWiseLinearTaperDelegate::GetMinimumValue
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:73
AAX_CPieceWiseLinearTaperDelegate::~AAX_CPieceWiseLinearTaperDelegate
~AAX_CPieceWiseLinearTaperDelegate()
Definition: AAX_CPieceWiseLinearTaperDelegate.h:148
AAX_CPieceWiseLinearTaperDelegate::RealToNormalized
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:211
AAX_CPieceWiseLinearTaperDelegate::Round
T Round(double iValue) const
Definition: AAX_CPieceWiseLinearTaperDelegate.h:91
AAX_CPieceWiseLinearTaperDelegate::NormalizedToReal
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:183
AAX_CPieceWiseLinearTaperDelegate::Clone
AAX_CPieceWiseLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:157
AAX_CPieceWiseLinearTaperDelegate::ConstrainRealValue
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CPieceWiseLinearTaperDelegate.h:163
AAX_ITaperDelegate
Definition: AAX_ITaperDelegate.h:86