| AAX SDK 2.8.0 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-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
32/*================================================================================================*/
33
34
35#ifndef AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
36#define AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
37
38
39#include "AAX_IDisplayDelegateDecorator.h"
40#include <cmath>
41
42
43
65 template <typename T>
66 class AAX_CDecibelDisplayDelegateDecorator : public AAX_IDisplayDelegateDecorator<T>
67{
68 public:
69 AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate);
70
71 //Virtual Overrides
72 AAX_CDecibelDisplayDelegateDecorator<T>* Clone() const AAX_OVERRIDE;
73 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
74 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
75 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
76};
77
78
79
80
81
82
83 template <typename T>
84 AAX_CDecibelDisplayDelegateDecorator<T>::AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate) :
85 AAX_IDisplayDelegateDecorator<T>(displayDelegate)
86{
87
88}
89
90 template <typename T>
91 AAX_CDecibelDisplayDelegateDecorator<T>* AAX_CDecibelDisplayDelegateDecorator<T>::Clone() const
92{
93 return new AAX_CDecibelDisplayDelegateDecorator(*this);
94}
95
96 template <typename T>
97 bool AAX_CDecibelDisplayDelegateDecorator<T>::ValueToString(T value, AAX_CString* valueString) const
98{
99 bool succeeded = false;
100 if (value <= 0)
101 {
102 //*valueString = AAX_CString("--- dB");
103 *valueString = AAX_CString("-INF ");
104 succeeded = true;
105 }
106 else
107 {
108 value = (T)(20.0*log10(value));
109 if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
110 value = 0.0f;
111
112 succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
113 }
114
115 *valueString += AAX_CString("dB");
116 return succeeded;
117}
118
119 template <typename T>
120 bool AAX_CDecibelDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
121{
122 if (value <= 0)
123 {
124 *valueString = AAX_CString("-INF");
125 if (maxNumChars >= 7)
126 valueString->Append(" dB"); //<DMT> Add a space for longer strings and dB
127 return true;
128 }
129
130 value = (T)(20.0*log10(value));
131 if ( value > -0.01f && value < 0.0f) //To prevent minus for 0.0 value in automation turned on
132 value = 0.0f;
133 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
134
135
136 //<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.
137 uint32_t strlen = valueString->Length();
138 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
139 if (maxNumCharsUnsigned >= (strlen + 2)) //length of string plus 2 for the "dB"
140 *valueString += AAX_CString("dB");
141 return succeeded;
142}
143
144
145 template <typename T>
146 bool AAX_CDecibelDisplayDelegateDecorator<T>::StringToValue(const AAX_CString& valueString, T* value) const
147{
148 //Just call through if there is obviously no unit string.
149 if (valueString.Length() <= 2)
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 //Just call through if the end of this string does not match the unit string.
157 AAX_CString unitSubString;
158 valueString.SubString(valueString.Length() - 2, 2, &unitSubString);
159 if (unitSubString != AAX_CString("dB"))
160 {
161 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
162 *value = (T)pow((T)10.0, *value / (T)20.0);
163 return success;
164 }
165
166 //Call through with the stripped down value string.
167 AAX_CString valueSubString;
168 valueString.SubString(0, valueString.Length() - 2, &valueSubString);
169 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueSubString, value);
170 *value = (T)pow((T)10.0, *value / (T)20.0);
171 return success;
172}
173
174
175
176
177#endif //AAX_CDECIBELDISPLAYDELEGATEDECORATOR_H
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
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:67
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:97
AAX_CDecibelDisplayDelegateDecorator::Clone
AAX_CDecibelDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CDecibelDisplayDelegateDecorator.h:91
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:146
AAX_CDecibelDisplayDelegateDecorator::AAX_CDecibelDisplayDelegateDecorator
AAX_CDecibelDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CDecibelDisplayDelegateDecorator.h:84
AAX_CString
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
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:79
AAX_IDisplayDelegateDecorator
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:54
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:207
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:195