AAX SDK 2.6.1
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 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_CNUMBERDISPLAYDELEGATE_H
23#define AAX_CNUMBERDISPLAYDELEGATE_H
24
26#include "AAX_CString.h"
27
28
38template <typename T, uint32_t Precision=2, uint32_t SpaceAfter=0>
40{
41public:
42 //Virtual Overrides
44 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
45 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
46 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
47};
48
49
50
51
52template <typename T, uint32_t Precision, uint32_t SpaceAfter>
54{
55 return new AAX_CNumberDisplayDelegate(*this);
56}
57
58template <typename T, uint32_t Precision, uint32_t SpaceAfter>
60{
61 valueString->Clear();
62 valueString->AppendNumber(value, Precision);
63 if (SpaceAfter != 0)
64 valueString->Append(" "); //Added a space after the number for easier display of units.
65 return true;
66}
67
68template <typename T, uint32_t Precision, uint32_t SpaceAfter>
69bool AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
70{
71 valueString->Clear();
72 valueString->AppendNumber(value, Precision);
73 uint32_t strlen = valueString->Length();
74 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
75 if (strlen > maxNumCharsUnsigned)
76 {
77 valueString->Erase(maxNumCharsUnsigned, strlen-maxNumCharsUnsigned);
78 strlen = valueString->Length();
79 }
80
81 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.
82 {
83 valueString->Erase(maxNumCharsUnsigned-1, 1);
84 strlen = valueString->Length();
85 }
86
87 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)
88 valueString->Append(" "); //Added a space after the number for easier display of units.
89 return true;
90}
91
92template <typename T, uint32_t Precision, uint32_t SpaceAfter>
94{
95 double dValue;
96 if (valueString.ToDouble(&dValue))
97 {
98 *value = static_cast<T> (dValue);
99 return true;
100 }
101 *value = 0;
102 return false;
103}
104
105
106
107
108#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:151
A numeric display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CNumberDisplayDelegate.h:40
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CNumberDisplayDelegate.h:59
AAX_CNumberDisplayDelegate * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CNumberDisplayDelegate.h:53
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CNumberDisplayDelegate.h:93
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:44
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:66