AAX SDK  2.1.1
Avid Audio Extensions Development Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AAX_CLinearTaperDelegate.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013 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 Technolgy, 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 { return mMinValue; }
75  T GetMaximumValue() const { return mMaxValue; }
76  T ConstrainRealValue(T value) const;
77  virtual T NormalizedToReal(double normalizedValue) const;
78  virtual double RealToNormalized(T realValue) const;
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 (RealPrecision)
115  value = Round(value); //reduce the precision to get proper rounding behavior with integers.
116 
117  if (value > mMaxValue)
118  return mMaxValue;
119  if (value < mMinValue)
120  return mMinValue;
121  return value;
122 }
123 
124 template <typename T, int32_t RealPrecision>
126 {
127  double doubleRealValue = normalizedValue * (double(mMaxValue) - double(mMinValue)) + double(mMinValue);
128 
129  // If RealPrecision is set, reduce the precision to get proper rounding behavior with integers.
130  T realValue = (0 != RealPrecision) ? Round(doubleRealValue) : static_cast<T>(doubleRealValue);
131 
132  return ConstrainRealValue(realValue);
133 }
134 
135 template <typename T, int32_t RealPrecision>
137 {
138  realValue = ConstrainRealValue(realValue);
139  double normalizedValue = (double(realValue) - double(mMinValue)) / (double(mMaxValue) - double(mMinValue));
140  return normalizedValue;
141 }
142 
143 
144 
145 
146 #endif //AAX_CLINEARTAPERDELEGATE_H
Various utility definitions for AAX.
virtual T NormalizedToReal(double normalizedValue) const
Converts a normalized value to a real value.
Definition: AAX_CLinearTaperDelegate.h:125
T GetMinimumValue() const
Returns the taper&#39;s minimum real value.
Definition: AAX_CLinearTaperDelegate.h:74
Defines the taper conversion behavior for a parameter.
T ConstrainRealValue(T value) const
Applies a contraint to the value and returns the constrained value.
Definition: AAX_CLinearTaperDelegate.h:112
virtual double RealToNormalized(T realValue) const
Normalizes a real parameter value.
Definition: AAX_CLinearTaperDelegate.h:136
Classes for conversion to and from normalized parameter values.
Definition: AAX_ITaperDelegate.h:88
AAX_CLinearTaperDelegate(T minValue=0, T maxValue=1)
Constructs a Linear Taper with specified minimum and maximum values.
Definition: AAX_CLinearTaperDelegate.h:98
A linear taper conforming to AAX_ITaperDelegate.
Definition: AAX_CLinearTaperDelegate.h:60
T GetMaximumValue() const
Returns the taper&#39;s maximum real value.
Definition: AAX_CLinearTaperDelegate.h:75
T Round(double iValue) const
Definition: AAX_CLinearTaperDelegate.h:89
AAX_CLinearTaperDelegate< T, RealPrecision > * Clone() const
Constructs and returns a copy of the taper delegate.
Definition: AAX_CLinearTaperDelegate.h:106