AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CLinearTaperDelegate.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013-2017, 2019 by Avid Technology, Inc.
5  * All rights reserved.
6  *
7  * CONFIDENTIAL: This document contains confidential information. Do not
8  * read or examine this document unless you are an Avid Technology employee
9  * or have signed a non-disclosure agreement with Avid Technology which protects
10  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
11  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
12  * OF Avid Technology, INC.
13  *
14  */
15 
22 /*================================================================================================*/
23 
24 
25 #ifndef AAX_CLINEARTAPERDELEGATE_H
26 #define AAX_CLINEARTAPERDELEGATE_H
27 
28 #include "AAX_ITaperDelegate.h"
29 #include "AAX.h" //for types
30 
31 #include <cmath> //for floor()
32 
33 
59 template <typename T, int32_t RealPrecision=0>
61 {
62 public:
70  AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1);
71 
72  //Virtual AAX_ITaperDelegate Overrides
74  T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
75  T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
76  T ConstrainRealValue(T value) const AAX_OVERRIDE;
77  T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
78  double RealToNormalized(T realValue) const AAX_OVERRIDE;
79 
80 protected:
81  T Round(double iValue) const;
82 
83 private:
84  T mMinValue;
85  T mMaxValue;
86 };
87 
88 template <typename T, int32_t RealPrecision>
90 {
91  double precision = RealPrecision;
92  if (precision > 0)
93  return static_cast<T>(floor(iValue * precision + 0.5) / precision);
94  return static_cast<T>(iValue);
95 }
96 
97 template <typename T, int32_t RealPrecision>
99  mMinValue(minValue),
100  mMaxValue(maxValue)
101 {
102 
103 }
104 
105 template <typename T, int32_t RealPrecision>
107 {
108  return new AAX_CLinearTaperDelegate(*this);
109 }
110 
111 template <typename T, int32_t RealPrecision>
113 {
114  if (mMinValue == mMaxValue)
115  return mMinValue;
116 
117  if (RealPrecision)
118  value = Round(value); //reduce the precision to get proper rounding behavior with integers.
119 
120  const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
121  const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
122 
123  if (value > highValue)
124  return highValue;
125  if (value < lowValue)
126  return lowValue;
127 
128  return value;
129 }
130 
131 template <typename T, int32_t RealPrecision>
133 {
134  double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
135 
136  // If RealPrecision is set, reduce the precision to get proper rounding behavior with integers.
137  T realValue = (0 != RealPrecision) ? Round(doubleRealValue) : static_cast<T>(doubleRealValue);
138 
139  return ConstrainRealValue(realValue);
140 }
141 
142 template <typename T, int32_t RealPrecision>
144 {
145  realValue = ConstrainRealValue(realValue);
146  double normalizedValue = (mMaxValue == mMinValue) ? 0.5 : (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
147  return normalizedValue;
148 }
149 
150 
151 
152 
153 #endif //AAX_CLINEARTAPERDELEGATE_H
Various utility definitions for AAX.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
Defines the taper conversion behavior for a parameter.
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:61
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:106
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:89
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:132
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CLinearTaperDelegate.h:75
AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Linear Taper with specified minimum and maximum values.
Definition: AAX_CLinearTaperDelegate.h:98
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:143
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CLinearTaperDelegate.h:74
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLinearTaperDelegate.h:112
Classes for conversion to and from normalized parameter values.
Definition: AAX_ITaperDelegate.h:89