AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CNumberDisplayDelegate.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_CNUMBERDISPLAYDELEGATE_H
36#define AAX_CNUMBERDISPLAYDELEGATE_H
37
39#include "AAX_CString.h"
40
41
51template <typename T, uint32_t Precision=2, uint32_t SpaceAfter=0>
53{
54public:
55 //Virtual Overrides
57 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
58 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
59 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
60};
61
62
63
64
65template <typename T, uint32_t Precision, uint32_t SpaceAfter>
67{
68 return new AAX_CNumberDisplayDelegate(*this);
69}
70
71template <typename T, uint32_t Precision, uint32_t SpaceAfter>
73{
74 valueString->Clear();
75 valueString->AppendNumber(value, Precision);
76 if (SpaceAfter != 0)
77 valueString->Append(" "); //Added a space after the number for easier display of units.
78 return true;
79}
80
81template <typename T, uint32_t Precision, uint32_t SpaceAfter>
82bool AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
83{
84 valueString->Clear();
85 valueString->AppendNumber(value, Precision);
86 uint32_t strlen = valueString->Length();
87 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
88 if (strlen > maxNumCharsUnsigned)
89 {
90 valueString->Erase(maxNumCharsUnsigned, strlen-maxNumCharsUnsigned);
91 strlen = valueString->Length();
92 }
93
94 if ( 0 < maxNumCharsUnsigned && strlen == maxNumCharsUnsigned && (*valueString)[maxNumCharsUnsigned-1] == '.') //<DMT> Edge case when the decimal point is the last character, we probably shouldn't show it.
95 {
96 valueString->Erase(maxNumCharsUnsigned-1, 1);
97 strlen = valueString->Length();
98 }
99
100 if ((SpaceAfter != 0) && (maxNumCharsUnsigned > strlen) && (maxNumCharsUnsigned-strlen > 2)) //<DMT> Kind of a random threshold for dropping the space after, but seems reasonable for our control surfaces. (allows dB and Unit prefixes)
101 valueString->Append(" "); //Added a space after the number for easier display of units.
102 return true;
103}
104
105template <typename T, uint32_t Precision, uint32_t SpaceAfter>
107{
108 double dValue;
109 if (valueString.ToDouble(&dValue))
110 {
111 *value = static_cast<T> (dValue);
112 return true;
113 }
114 *value = 0;
115 return false;
116}
117
118
119
120
121#endif //AAX_CNUMBERDISPLAYDELEGATE_H
A generic AAX string class with similar functionality to std::string.
Defines the display behavior for a parameter.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
A numeric display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CNumberDisplayDelegate.h:53
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CNumberDisplayDelegate.h:72
AAX_CNumberDisplayDelegate * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CNumberDisplayDelegate.h:66
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CNumberDisplayDelegate.h:106
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
uint32_t Length() const AAX_OVERRIDE
bool ToDouble(double *oValue) const
void Clear()
AAX_CString & Erase(uint32_t pos, uint32_t n)
AAX_CString & Append(const AAX_CString &str)
AAX_CString & AppendNumber(double number, int32_t precision)
Definition: AAX_IDisplayDelegate.h:79