AAX SDK 2.8.0
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-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
69template <typename T, int32_t RealPrecision=0>
71{
72public:
80 AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1);
81
82 //Virtual AAX_ITaperDelegate Overrides
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
90protected:
91 T Round(double iValue) const;
92
93private:
94 T mMinValue;
95 T mMaxValue;
96};
97
98template <typename T, int32_t RealPrecision>
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
107template <typename T, int32_t RealPrecision>
109 mMinValue(minValue),
110 mMaxValue(maxValue)
111{
112
113}
114
115template <typename T, int32_t RealPrecision>
117{
118 return new AAX_CLinearTaperDelegate(*this);
119}
120
121template <typename T, int32_t RealPrecision>
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
141template <typename T, int32_t RealPrecision>
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
152template <typename T, int32_t RealPrecision>
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
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:71
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:116
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:99
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:142
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLinearTaperDelegate.h:85
AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Linear Taper with specified minimum and maximum values.
Definition: AAX_CLinearTaperDelegate.h:108
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:153
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLinearTaperDelegate.h:84
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLinearTaperDelegate.h:122
Definition: AAX_ITaperDelegate.h:99