| 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_CLinearTaperDelegate.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
19/*================================================================================================*/
20
21
22#ifndef AAX_CLINEARTAPERDELEGATE_H
23#define AAX_CLINEARTAPERDELEGATE_H
24
25#include "AAX_ITaperDelegate.h"
26#include "AAX.h" //for types
27
28#include <cmath> //for floor()
29
30
56 template <typename T, int32_t RealPrecision=0>
57 class AAX_CLinearTaperDelegate : public AAX_ITaperDelegate<T>
58{
59 public:
67 AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1);
68
69 //Virtual AAX_ITaperDelegate Overrides
70 AAX_CLinearTaperDelegate<T, RealPrecision>* Clone() const AAX_OVERRIDE;
71 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
72 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
73 T ConstrainRealValue(T value) const AAX_OVERRIDE;
74 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
75 double RealToNormalized(T realValue) const AAX_OVERRIDE;
76
77 protected:
78 T Round(double iValue) const;
79
80 private:
81 T mMinValue;
82 T mMaxValue;
83};
84
85 template <typename T, int32_t RealPrecision>
86T AAX_CLinearTaperDelegate<T, RealPrecision>::Round(double iValue) const
87{
88 double precision = RealPrecision;
89 if (precision > 0)
90 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
91 return static_cast<T>(iValue);
92}
93
94 template <typename T, int32_t RealPrecision>
95 AAX_CLinearTaperDelegate<T, RealPrecision>::AAX_CLinearTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
96 mMinValue(minValue),
97 mMaxValue(maxValue)
98{
99
100}
101
102 template <typename T, int32_t RealPrecision>
103 AAX_CLinearTaperDelegate<T, RealPrecision>* AAX_CLinearTaperDelegate<T, RealPrecision>::Clone() const
104{
105 return new AAX_CLinearTaperDelegate(*this);
106}
107
108 template <typename T, int32_t RealPrecision>
109T AAX_CLinearTaperDelegate<T, RealPrecision>::ConstrainRealValue(T value) const
110{
111 if (mMinValue == mMaxValue)
112 return mMinValue;
113
114 if (RealPrecision)
115 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
116
117 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
118 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
119
120 if (value > highValue)
121 return highValue;
122 if (value < lowValue)
123 return lowValue;
124
125 return value;
126}
127
128 template <typename T, int32_t RealPrecision>
129T AAX_CLinearTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
130{
131 double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
132
133 // If RealPrecision is set, reduce the precision to get proper rounding behavior with integers.
134 T realValue = (0 != RealPrecision) ? Round(doubleRealValue) : static_cast<T>(doubleRealValue);
135
136 return ConstrainRealValue(realValue);
137}
138
139 template <typename T, int32_t RealPrecision>
140 double AAX_CLinearTaperDelegate<T, RealPrecision>::RealToNormalized(T realValue) const
141{
142 realValue = ConstrainRealValue(realValue);
143 double normalizedValue = (mMaxValue == mMinValue) ? 0.5 : (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
144 return normalizedValue;
145}
146
147
148
149
150#endif //AAX_CLINEARTAPERDELEGATE_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_CLinearTaperDelegate
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:58
AAX_CLinearTaperDelegate::Clone
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:103
AAX_CLinearTaperDelegate::Round
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:86
AAX_CLinearTaperDelegate::NormalizedToReal
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:129
AAX_CLinearTaperDelegate::GetMaximumValue
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLinearTaperDelegate.h:72
AAX_CLinearTaperDelegate::AAX_CLinearTaperDelegate
AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Linear Taper with specified minimum and maximum values.
Definition: AAX_CLinearTaperDelegate.h:95
AAX_CLinearTaperDelegate::RealToNormalized
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:140
AAX_CLinearTaperDelegate::GetMinimumValue
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLinearTaperDelegate.h:71
AAX_CLinearTaperDelegate::ConstrainRealValue
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLinearTaperDelegate.h:109
AAX_ITaperDelegate
Definition: AAX_ITaperDelegate.h:86