AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CLogTaperDelegate.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
31/*================================================================================================*/
32
33
34#ifndef AAX_CLOGTAPERDELEGATE_H
35#define AAX_CLOGTAPERDELEGATE_H
36
37#include "AAX_ITaperDelegate.h"
38#include "AAX_UtilsNative.h"
39#include "AAX.h" //for types
40
41#include <cmath> //for floor(), log()
42
43
44
70template <typename T, int32_t RealPrecision=1000>
72{
73public:
81 AAX_CLogTaperDelegate(T minValue=0, T maxValue=1);
82
83 //Virtual Overrides
85 T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
86 T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
87 T ConstrainRealValue(T value) const AAX_OVERRIDE;
88 T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
89 double RealToNormalized(T realValue) const AAX_OVERRIDE;
90
91protected:
92 T Round(double iValue) const;
93
94private:
95 T mMinValue;
96 T mMaxValue;
97};
98
99template <typename T, int32_t RealPrecision>
101{
102 double precision = RealPrecision;
103 if (precision > 0)
104 return static_cast<T>(floor(iValue * precision + 0.5) / precision);
105 return static_cast<T>(iValue);
106}
107
108template <typename T, int32_t RealPrecision>
110 mMinValue(minValue),
111 mMaxValue(maxValue)
112{
113
114}
115
116template <typename T, int32_t RealPrecision>
118{
119 return new AAX_CLogTaperDelegate(*this);
120}
121
122template <typename T, int32_t RealPrecision>
124{
125 if (mMinValue == mMaxValue)
126 return mMinValue;
127
128 if (RealPrecision)
129 value = Round(value); //reduce the precision to get proper rounding behavior with integers.
130
131 const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
132 const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
133
134 if (value > highValue)
135 return highValue;
136 if (value < lowValue)
137 return lowValue;
138
139 return value;
140}
141
142template <typename T, int32_t RealPrecision>
144{
145 double minLog = AAX::SafeLog(double(mMinValue));
146 double maxLog = AAX::SafeLog(double(mMaxValue));
147
148 double doubleRealValue = exp(normalizedValue * (maxLog - minLog) + minLog);
149 T realValue = (T) doubleRealValue;
150
151 return ConstrainRealValue(realValue);
152}
153
154template <typename T, int32_t RealPrecision>
156{
157 double minLog = AAX::SafeLog(double(mMinValue));
158 double maxLog = AAX::SafeLog(double(mMaxValue));
159
160 realValue = ConstrainRealValue(realValue);
161 double normalizedValue = (maxLog == minLog) ? 0.5 : (AAX::SafeLog(double(realValue)) - minLog) / (maxLog - minLog);
162 return normalizedValue;
163}
164
165#endif // AAX_CLOGTAPERDELEGATE_H
Defines the taper conversion behavior for a parameter.
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
Various utility definitions for AAX Native.
double SafeLog(double aValue)
Double-precision safe log function. Returns zero for input values that are <= 0.0.
Definition: AAX_UtilsNative.h:63
A logarithmic taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLogTaperDelegate.h:72
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLogTaperDelegate.h:143
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLogTaperDelegate.h:85
AAX_CLogTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Log Taper with specified minimum and maximum values.
Definition: AAX_CLogTaperDelegate.h:109
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLogTaperDelegate.h:86
T Round(double iValue) const
Definition: AAX_CLogTaperDelegate.h:100
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLogTaperDelegate.h:155
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLogTaperDelegate.h:123
AAX_CLogTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLogTaperDelegate.h:117
Definition: AAX_ITaperDelegate.h:99