| 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_CLinearTaperDelegate.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
32/*================================================================================================*/
33
34
35#ifndef AAX_CLINEARTAPERDELEGATE_H
36#define AAX_CLINEARTAPERDELEGATE_H
37
38#include "AAX_ITaperDelegate.h"
39#include "AAX.h" //for types
40
41#include <cmath> //for floor()
42
43
69 template <typename T, int32_t RealPrecision=0>
70 class AAX_CLinearTaperDelegate : public AAX_ITaperDelegate<T>
71{
72 public:
80 AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1);
81
82 //Virtual AAX_ITaperDelegate Overrides
83 AAX_CLinearTaperDelegate<T, RealPrecision>* Clone() const AAX_OVERRIDE;
84 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
85 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
86 T ConstrainRealValue(T value) const AAX_OVERRIDE;
87 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
88 double RealToNormalized(T realValue) const AAX_OVERRIDE;
89
90 protected:
91 T Round(double iValue) const;
92
93 private:
94 T mMinValue;
95 T mMaxValue;
96};
97
98 template <typename T, int32_t RealPrecision>
99T AAX_CLinearTaperDelegate<T, RealPrecision>::Round(double iValue) const
100{
101 double precision = RealPrecision;
102 if (precision > 0)
103 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
104 return static_cast<T>(iValue);
105}
106
107 template <typename T, int32_t RealPrecision>
108 AAX_CLinearTaperDelegate<T, RealPrecision>::AAX_CLinearTaperDelegate(T minValue, T maxValue) : AAX_ITaperDelegate<T>(),
109 mMinValue(minValue),
110 mMaxValue(maxValue)
111{
112
113}
114
115 template <typename T, int32_t RealPrecision>
116 AAX_CLinearTaperDelegate<T, RealPrecision>* AAX_CLinearTaperDelegate<T, RealPrecision>::Clone() const
117{
118 return new AAX_CLinearTaperDelegate(*this);
119}
120
121 template <typename T, int32_t RealPrecision>
122T AAX_CLinearTaperDelegate<T, RealPrecision>::ConstrainRealValue(T value) const
123{
124 if (mMinValue == mMaxValue)
125 return mMinValue;
126
127 if (RealPrecision)
128 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
129
130 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
131 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
132
133 if (value > highValue)
134 return highValue;
135 if (value < lowValue)
136 return lowValue;
137
138 return value;
139}
140
141 template <typename T, int32_t RealPrecision>
142T AAX_CLinearTaperDelegate<T, RealPrecision>::NormalizedToReal(double normalizedValue) const
143{
144 double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
145
146 // If RealPrecision is set, reduce the precision to get proper rounding behavior with integers.
147 T realValue = (0 != RealPrecision) ? Round(doubleRealValue) : static_cast<T>(doubleRealValue);
148
149 return ConstrainRealValue(realValue);
150}
151
152 template <typename T, int32_t RealPrecision>
153 double AAX_CLinearTaperDelegate<T, RealPrecision>::RealToNormalized(T realValue) const
154{
155 realValue = ConstrainRealValue(realValue);
156 double normalizedValue = (mMaxValue == mMinValue) ? 0.5 : (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
157 return normalizedValue;
158}
159
160
161
162
163#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:164
AAX_CLinearTaperDelegate
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:71
AAX_CLinearTaperDelegate::Clone
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:116
AAX_CLinearTaperDelegate::Round
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:99
AAX_CLinearTaperDelegate::NormalizedToReal
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:142
AAX_CLinearTaperDelegate::GetMaximumValue
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLinearTaperDelegate.h:85
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:108
AAX_CLinearTaperDelegate::RealToNormalized
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:153
AAX_CLinearTaperDelegate::GetMinimumValue
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLinearTaperDelegate.h:84
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:122
AAX_ITaperDelegate
Definition: AAX_ITaperDelegate.h:99