AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CDecibelDisplayDelegateDecorator.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_CDECIBELDISPLAYDELEGATEDECORATOR_H
26 #define AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
27 
28 
30 #include <cmath>
31 
32 
33 
55 template <typename T>
57 {
58 public:
60 
61  //Virtual Overrides
63  bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
64  bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
65  bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
66 };
67 
68 
69 
70 
71 
72 
73 template <typename T>
75  AAX_IDisplayDelegateDecorator<T>(displayDelegate)
76 {
77 
78 }
79 
80 template <typename T>
82 {
83  return new AAX_CDecibelDisplayDelegateDecorator(*this);
84 }
85 
86 template <typename T>
88 {
89  bool succeeded = false;
90  if (value <= 0)
91  {
92  //*valueString = AAX_CString("--- dB");
93  *valueString = AAX_CString("-INF ");
94  succeeded = true;
95  }
96  else
97  {
98  value = (T)(20.0*log10(value));
99  if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
100  value = 0.0f;
101 
102  succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
103  }
104 
105  *valueString += AAX_CString("dB");
106  return succeeded;
107 }
108 
109 template <typename T>
110 bool AAX_CDecibelDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
111 {
112  if (value <= 0)
113  {
114  *valueString = AAX_CString("-INF");
115  if (maxNumChars >= 7)
116  valueString->Append(" dB"); //<DMT> Add a space for longer strings and dB
117  return true;
118  }
119 
120  value = (T)(20.0*log10(value));
121  if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
122  value = 0.0f;
123  bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
124 
125 
126  //<DMT> Check current string length and see if there is room to add units. I believe these units are usually less important than precision on control surfaces.
127  uint32_t strlen = valueString->Length();
128  const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
129  if (maxNumCharsUnsigned >= (strlen + 2)) //length of string plus 2 for the "dB"
130  *valueString += AAX_CString("dB");
131  return succeeded;
132 }
133 
134 
135 template <typename T>
137 {
138  //Just call through if there is obviously no unit string.
139  if (valueString.Length() <= 2)
140  {
141  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
142  *value = (T)pow((T)10.0, (*value / (T)20.0));
143  return success;
144  }
145 
146  //Just call through if the end of this string does not match the unit string.
147  AAX_CString unitSubString;
148  valueString.SubString(valueString.Length() - 2, 2, &unitSubString);
149  if (unitSubString != AAX_CString("dB"))
150  {
151  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
152  *value = (T)pow((T)10.0, *value / (T)20.0);
153  return success;
154  }
155 
156  //Call through with the stripped down value string.
157  AAX_CString valueSubString;
158  valueString.SubString(0, valueString.Length() - 2, &valueSubString);
159  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueSubString, value);
160  *value = (T)pow((T)10.0, *value / (T)20.0);
161  return success;
162 }
163 
164 
165 
166 
167 #endif //AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
The base class for all concrete display delegate decorators.
A percent decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:57
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:87
AAX_CDecibelDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:81
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:136
AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CDecibelDisplayDelegateDecorator.h:74
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:46
uint32_t Length() const AAX_OVERRIDE
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
AAX_CString & Append(const AAX_CString &str)
Classes for parameter value string conversion.
Definition: AAX_IDisplayDelegate.h:69
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:44
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:197
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:185