AAX SDK 2.6.1
Avid Audio Extensions Development Kit
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
56template <typename T, int32_t RealPrecision=0>
58{
59public:
67 AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1);
68
69 //Virtual AAX_ITaperDelegate Overrides
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
77protected:
78 T Round(double iValue) const;
79
80private:
81 T mMinValue;
82 T mMaxValue;
83};
84
85template <typename T, int32_t RealPrecision>
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
94template <typename T, int32_t RealPrecision>
96 mMinValue(minValue),
97 mMaxValue(maxValue)
98{
99
100}
101
102template <typename T, int32_t RealPrecision>
104{
105 return new AAX_CLinearTaperDelegate(*this);
106}
107
108template <typename T, int32_t RealPrecision>
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
128template <typename T, int32_t RealPrecision>
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
139template <typename T, int32_t RealPrecision>
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
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:58
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:103
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:86
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:129
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLinearTaperDelegate.h:72
AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Linear Taper with specified minimum and maximum values.
Definition: AAX_CLinearTaperDelegate.h:95
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:140
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLinearTaperDelegate.h:71
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLinearTaperDelegate.h:109
Definition: AAX_ITaperDelegate.h:86