AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CStateTaperDelegate.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2014-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_CSTATETAPERDELEGATE_H
26 #define AAX_CSTATETAPERDELEGATE_H
27 
28 #include "AAX_ITaperDelegate.h"
29 #include "AAX.h" //for types
30 
31 #include <cmath> //for floor()
32 
33 
45 template <typename T>
47 {
48 public:
56  AAX_CStateTaperDelegate(T minValue=0, T maxValue=1);
57 
58  //Virtual Overrides
60  T GetMinimumValue() const AAX_OVERRIDE { return mMinValue; }
61  T GetMaximumValue() const AAX_OVERRIDE { return mMaxValue; }
62  T ConstrainRealValue(T value) const AAX_OVERRIDE;
63  T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE;
64  double RealToNormalized(T realValue) const AAX_OVERRIDE;
65 
66 private:
67  T mMinValue;
68  T mMaxValue;
69 };
70 
71 template <typename T>
73  mMinValue(minValue),
74  mMaxValue(maxValue)
75 {
76 
77 }
78 
79 template <typename T>
81 {
82  return new AAX_CStateTaperDelegate(*this);
83 }
84 
85 template <typename T>
87 {
88  if (mMinValue == mMaxValue)
89  return mMinValue;
90 
91  const T& highValue = mMaxValue > mMinValue ? mMaxValue : mMinValue;
92  const T& lowValue = mMaxValue > mMinValue ? mMinValue : mMaxValue;
93 
94  if (value > highValue)
95  return highValue;
96  if (value < lowValue)
97  return lowValue;
98 
99  return value;
100 }
101 
102 template <typename T>
103 T AAX_CStateTaperDelegate<T>::NormalizedToReal(double normalizedValue) const
104 {
105  double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
106  if ( doubleRealValue >= 0 )
107  doubleRealValue += 0.5;
108  else doubleRealValue -= 0.5;
109  return ConstrainRealValue(static_cast<T>(doubleRealValue));
110 }
111 
112 template <typename T>
114 {
115  realValue = ConstrainRealValue(realValue);
116  double normalizedValue = (mMaxValue == mMinValue) ? 0.5 : (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
117  return normalizedValue;
118 }
119 
120 
121 
122 
123 #endif //AAX_CSTATETAPERDELEGATE_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_CStateTaperDelegate.h:47
T NormalizedToReal(double normalizedValue) const AAX_OVERRIDE
Converts a normalized value to a real value.
Definition: AAX_CStateTaperDelegate.h:103
T GetMinimumValue() const AAX_OVERRIDE
Returns the taper's minimum real value.
Definition: AAX_CStateTaperDelegate.h:60
AAX_CStateTaperDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the taper delegate.
Definition: AAX_CStateTaperDelegate.h:80
T ConstrainRealValue(T value) const AAX_OVERRIDE
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CStateTaperDelegate.h:86
AAX_CStateTaperDelegate(T minValue=0, T maxValue=1)
Constructs a State Taper with specified minimum and maximum values.
Definition: AAX_CStateTaperDelegate.h:72
T GetMaximumValue() const AAX_OVERRIDE
Returns the taper's maximum real value.
Definition: AAX_CStateTaperDelegate.h:61
double RealToNormalized(T realValue) const AAX_OVERRIDE
Normalizes a real parameter value.
Definition: AAX_CStateTaperDelegate.h:113
Classes for conversion to and from normalized parameter values.
Definition: AAX_ITaperDelegate.h:89