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