AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CStateTaperDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-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_CSTATETAPERDELEGATE_H
36#define AAX_CSTATETAPERDELEGATE_H
37
38#include "AAX_ITaperDelegate.h"
39#include "AAX.h" //for types
40
41#include <cmath> //for floor()
42
43
55template <typename T>
57{
58public:
66 AAX_CStateTaperDelegate(T minValue=0, T maxValue=1);
67
68 //Virtual Overrides
70 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
71 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
72 T ConstrainRealValue(T value) const AAX_OVERRIDE;
73 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
74 double RealToNormalized(T realValue) const AAX_OVERRIDE;
75
76private:
77 T mMinValue;
78 T mMaxValue;
79};
80
81template <typename T>
83 mMinValue(minValue),
84 mMaxValue(maxValue)
85{
86
87}
88
89template <typename T>
91{
92 return new AAX_CStateTaperDelegate(*this);
93}
94
95template <typename T>
97{
98 if (mMinValue == mMaxValue)
99 return mMinValue;
100
101 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
102 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
103
104 if (value > highValue)
105 return highValue;
106 if (value < lowValue)
107 return lowValue;
108
109 return value;
110}
111
112template <typename T>
113T AAX_CStateTaperDelegate<T>::NormalizedToReal(double normalizedValue) const
114{
115 double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
116 if ( doubleRealValue >= 0 )
117 doubleRealValue += 0.5;
118 else doubleRealValue -= 0.5;
119 return ConstrainRealValue(static_cast<T>(doubleRealValue));
120}
121
122template <typename T>
124{
125 realValue = ConstrainRealValue(realValue);
126 double normalizedValue = (mMaxValue == mMinValue) ? 0.5 : (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
127 return normalizedValue;
128}
129
130
131
132
133#endif //AAX_CSTATETAPERDELEGATE_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_CStateTaperDelegate.h:57
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CStateTaperDelegate.h:113
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CStateTaperDelegate.h:70
AAX_CStateTaperDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CStateTaperDelegate.h:90
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CStateTaperDelegate.h:96
AAX_CStateTaperDelegate(T minValue=0, T maxValue=1)
Constructs a State Taper with specified minimum and maximum values.
Definition: AAX_CStateTaperDelegate.h:82
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CStateTaperDelegate.h:71
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CStateTaperDelegate.h:123
Definition: AAX_ITaperDelegate.h:99