ASPiK SDK
value.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include "../ivalue.h"
8 #include <vector>
9 
10 //------------------------------------------------------------------------
11 namespace VSTGUI {
12 namespace Standalone {
13 
14 //------------------------------------------------------------------------
16 {
17 public:
18  using StringType = UTF8String;
19  using StringList = std::vector<StringType>;
20  virtual bool updateStringList (const StringList& newStrings) = 0;
21 };
22 
23 //------------------------------------------------------------------------
27 namespace Value {
28 
29 //------------------------------------------------------------------------
33 //------------------------------------------------------------------------
41 ValuePtr make (const UTF8String& id, IValue::Type initialValue = 0.,
42  const ValueConverterPtr& valueConverter = nullptr);
43 
44 //------------------------------------------------------------------------
53 ValuePtr makeStepValue (const UTF8String& id, IStepValue::StepType numSteps,
54  IValue::Type initialValue = 0.,
55  const ValueConverterPtr& valueConverter = nullptr);
56 
57 //------------------------------------------------------------------------
70 ValuePtr makeStringListValue (const UTF8String& id,
71  const std::initializer_list<IStringListValue::StringType>& strings,
72  IValue::Type initialValue = 0.);
73 
74 //------------------------------------------------------------------------
83 ValuePtr makeStringListValue (const UTF8String& id, const IStringListValue::StringList& strings);
84 
85 //------------------------------------------------------------------------
94 ValuePtr makeStaticStringValue (const UTF8String& id, const UTF8String& value);
95 
96 //------------------------------------------------------------------------
105 ValuePtr makeStaticStringValue (const UTF8String& id, UTF8String&& value);
106 
111 //------------------------------------------------------------------------
116 ValueConverterPtr makePercentConverter ();
117 
118 //------------------------------------------------------------------------
123 ValueConverterPtr makeRangeConverter (IValue::Type minValue, IValue::Type maxValue);
124 
127 //------------------------------------------------------------------------
131 inline IValue::Type plainToNormalize (IValue& value, IValue::Type plainValue)
132 {
133  return value.getConverter ().plainToNormalized (plainValue);
134 }
135 
136 //------------------------------------------------------------------------
137 inline IValue::Type normalizeToPlain (IValue& value, IValue::Type normalizeValue)
138 {
139  return value.getConverter ().normalizedToPlain (normalizeValue);
140 }
141 
142 //------------------------------------------------------------------------
143 inline IValue::Type stepToNormalize (IValue& value, IStepValue::StepType stepValue)
144 {
145  if (auto sv = value.dynamicCast<IStepValue> ())
146  {
147  return sv->stepToValue (stepValue);
148  }
149  return IValue::InvalidValue;
150 }
151 
152 //------------------------------------------------------------------------
153 inline IStepValue::StepType normalizeToStep (IValue& value, IValue::Type normalizeValue)
154 {
155  if (auto sv = value.dynamicCast<IStepValue> ())
156  {
157  return sv->valueToStep (normalizeValue);
158  }
159  return IStepValue::InvalidStep;
160 }
161 
162 //------------------------------------------------------------------------
163 inline IValue::Type currentPlainValue (IValue& value)
164 {
165  return normalizeToPlain (value, value.getValue ());
166 }
167 
168 //------------------------------------------------------------------------
169 inline IStepValue::StepType currentStepValue (IValue& value)
170 {
171  return normalizeToStep (value, value.getValue ());
172 }
173 
174 //------------------------------------------------------------------------
175 inline void performSingleEdit (IValue& value, IValue::Type newValue)
176 {
177  value.beginEdit ();
178  value.performEdit (newValue);
179  value.endEdit ();
180 }
181 
182 //------------------------------------------------------------------------
183 inline void performSinglePlainEdit (IValue& value, IValue::Type plainValue)
184 {
185  performSingleEdit (value, plainToNormalize (value, plainValue));
186 }
187 
188 //------------------------------------------------------------------------
189 inline bool performSingleStepEdit (IValue& value, IStepValue::StepType step)
190 {
191  if (auto stepValue = value.dynamicCast<IStepValue> ())
192  {
193  performSingleEdit (value, stepValue->stepToValue (step));
194  return true;
195  }
196  return false;
197 }
200 //------------------------------------------------------------------------
201 } // Value
202 } // Standalone
203 } // VSTGUI
ValueConverterPtr makeRangeConverter(IValue::Type minValue, IValue::Type maxValue)
Definition: value.cpp:526
ValuePtr makeStepValue(const UTF8String &id, IStepValue::StepType numSteps, IValue::Type initialValue=0., const ValueConverterPtr &valueConverter=nullptr)
Definition: value.cpp:480
ValuePtr makeStringListValue(const UTF8String &id, const std::initializer_list< IStringListValue::StringType > &strings, IValue::Type initialValue=0.)
Definition: value.cpp:488
double Type
Definition: ivalue.h:24
Definition: interface.h:13
Definition: customcontrols.cpp:8
ValuePtr make(const UTF8String &id, IValue::Type initialValue=0., const ValueConverterPtr &valueConverter=nullptr)
Definition: value.cpp:470
ValuePtr makeStaticStringValue(const UTF8String &id, const UTF8String &value)
Definition: value.cpp:508
ValueConverterPtr makePercentConverter()
Definition: value.cpp:520
static constexpr Type InvalidValue
Definition: ivalue.h:26
Definition: ivalue.h:20
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
Definition: ivalue.h:62