| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_CDecibelDisplayDelegateDecorator.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-2017, 2019, 2023 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * CONFIDENTIAL: this document contains confidential information of Avid. Do
8 * not disclose to any third party. Use of the information contained in this
9 * document is subject to an Avid SDK license.
10 *
11 */
12
19/*================================================================================================*/
20
21
22#ifndef AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
23#define AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
24
25
26#include "AAX_IDisplayDelegateDecorator.h"
27#include <cmath>
28
29
30
52 template <typename T>
53 class AAX_CDecibelDisplayDelegateDecorator : public AAX_IDisplayDelegateDecorator<T>
54{
55 public:
56 AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate);
57
58 //Virtual Overrides
59 AAX_CDecibelDisplayDelegateDecorator<T>* Clone() const AAX_OVERRIDE;
60 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
61 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
62 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
63};
64
65
66
67
68
69
70 template <typename T>
71 AAX_CDecibelDisplayDelegateDecorator<T>::AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate) :
72 AAX_IDisplayDelegateDecorator<T>(displayDelegate)
73{
74
75}
76
77 template <typename T>
78 AAX_CDecibelDisplayDelegateDecorator<T>* AAX_CDecibelDisplayDelegateDecorator<T>::Clone() const
79{
80 return new AAX_CDecibelDisplayDelegateDecorator(*this);
81}
82
83 template <typename T>
84 bool AAX_CDecibelDisplayDelegateDecorator<T>::ValueToString(T value, AAX_CString* valueString) const
85{
86 bool succeeded = false;
87 if (value <= 0)
88 {
89 //*valueString = AAX_CString("--- dB");
90 *valueString = AAX_CString("-INF ");
91 succeeded = true;
92 }
93 else
94 {
95 value = (T)(20.0*log10(value));
96 if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
97 value = 0.0f;
98
99 succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
100 }
101
102 *valueString += AAX_CString("dB");
103 return succeeded;
104}
105
106 template <typename T>
107 bool AAX_CDecibelDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
108{
109 if (value <= 0)
110 {
111 *valueString = AAX_CString("-INF");
112 if (maxNumChars >= 7)
113 valueString->Append(" dB"); //<DMT> Add a space for longer strings and dB
114 return true;
115 }
116
117 value = (T)(20.0*log10(value));
118 if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
119 value = 0.0f;
120 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
121
122
123 //<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.
124 uint32_t strlen = valueString->Length();
125 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
126 if (maxNumCharsUnsigned >= (strlen + 2)) //length of string plus 2 for the "dB"
127 *valueString += AAX_CString("dB");
128 return succeeded;
129}
130
131
132 template <typename T>
133 bool AAX_CDecibelDisplayDelegateDecorator<T>::StringToValue(const AAX_CString& valueString, T* value) const
134{
135 //Just call through if there is obviously no unit string.
136 if (valueString.Length() <= 2)
137 {
138 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
139 *value = (T)pow((T)10.0, (*value / (T)20.0));
140 return success;
141 }
142
143 //Just call through if the end of this string does not match the unit string.
144 AAX_CString unitSubString;
145 valueString.SubString(valueString.Length() - 2, 2, &unitSubString);
146 if (unitSubString != AAX_CString("dB"))
147 {
148 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
149 *value = (T)pow((T)10.0, *value / (T)20.0);
150 return success;
151 }
152
153 //Call through with the stripped down value string.
154 AAX_CString valueSubString;
155 valueString.SubString(0, valueString.Length() - 2, &valueSubString);
156 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueSubString, value);
157 *value = (T)pow((T)10.0, *value / (T)20.0);
158 return success;
159}
160
161
162
163
164#endif //AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
AAX_IDisplayDelegateDecorator.h
The base class for all concrete display delegate decorators.
AAX_CDecibelDisplayDelegateDecorator
A percent decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:54
AAX_CDecibelDisplayDelegateDecorator::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:84
AAX_CDecibelDisplayDelegateDecorator::Clone
AAX_CDecibelDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:78
AAX_CDecibelDisplayDelegateDecorator::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:133
AAX_CDecibelDisplayDelegateDecorator::AAX_CDecibelDisplayDelegateDecorator
AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CDecibelDisplayDelegateDecorator.h:71
AAX_CString
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:44
AAX_CString::Length
uint32_t Length() const AAX_OVERRIDE
AAX_CString::SubString
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
AAX_CString::Append
AAX_CString & Append(const AAX_CString &str)
AAX_IDisplayDelegate
Definition: AAX_IDisplayDelegate.h:66
AAX_IDisplayDelegateDecorator
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:41
AAX_IDisplayDelegateDecorator::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:194
AAX_IDisplayDelegateDecorator::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:182