24 #include <pluginterfaces/vst/vsttypes.h> 25 #include <pluginterfaces/vst/ivstparameterchanges.h> 26 #include <pluginterfaces/base/ustring.h> 27 #include <base/source/fstring.h> 28 #include <pluginterfaces/base/ftypes.h> 37 #include <type_traits> 42 using namespace Steinberg;
43 using namespace Steinberg::Vst;
58 virtual ParamValue normalize(ParamType
const &iValue)
const = 0;
59 virtual ParamType denormalize(ParamValue iNormalizedValue)
const = 0;
60 virtual void toString(
ParamType const &iValue, String128 iString, int32 iPrecision)
const { }
65 toString(iValue, s, iPrecision);
79 inline ParamValue
normalize(ParamValue
const &iValue)
const override 84 inline ParamValue
denormalize(ParamValue iNormalizedValue)
const override 89 inline void toString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
const override 91 staticToString(iValue, oString, iPrecision);
94 static inline void staticToString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
96 Steinberg::UString wrapper(oString, str16BufferSize(String128));
97 if(!wrapper.printFloat(iValue, iPrecision))
114 fFalseString{std::move(iFalseString)},
115 fTrueString{std::move(iTrueString)}
120 inline ParamValue
normalize(
bool const &iValue)
const override 122 return iValue ? 1.0 : 0;
125 inline bool denormalize(ParamValue iNormalizedValue)
const override 127 return toBoolean(iNormalizedValue);
130 inline void toString(
bool const &iValue, String128 oString, int32 )
const override 132 Steinberg::UString wrapper(oString, str16BufferSize(String128));
134 wrapper.assign(fTrueString.c_str());
136 wrapper.assign(fFalseString.c_str());
142 inline static bool toBoolean(ParamValue iNormalizedValue) {
return iNormalizedValue >= 0.5; }
164 inline ParamValue
normalize(
double const &iValue)
const override 169 inline double denormalize(ParamValue iNormalizedValue)
const override 174 inline void toString(
ParamType const &iValue, String128 oString, int32 iPrecision)
const override 176 Steinberg::UString wrapper(oString, str16BufferSize (String128));
177 wrapper.printFloat(iValue * 100, iPrecision);
178 wrapper.append(STR16(
"%"));
188 auto value = Utils::clamp<int32, int32>(iDiscreteValue, 0, iStepCount);
192 return value / static_cast<ParamValue>(iStepCount);
203 auto discreteValue = std::floor(std::min(static_cast<ParamValue>(iStepCount), value * (iStepCount + 1)));
204 return static_cast<int32>(discreteValue);
212 template<
int32 StepCount,
typename IntType =
int32>
229 fToStringOffset{iToStringOffset}, fFormat{std::move(iFormat)} {}
233 fToStringValues(iToStringValues.cbegin(), iToStringValues.cend()) {}
250 Steinberg::UString wrapper(oString, str16BufferSize (String128));
254 s.printf(fFormat.c_str(), iValue + fToStringOffset);
255 wrapper.assign(s.text());
259 if(fToStringValues.empty())
261 if(!wrapper.printInt(iValue + fToStringOffset))
266 wrapper.assign(fToStringValues[iValue].c_str());
272 IntType fToStringOffset{};
274 std::vector<VstString16> fToStringValues{};
303 template<
typename T,
class Compare = std::less<T>>
309 using TMap = std::map<T, std::tuple<VstString16, ParamValue, int32>, Compare>;
317 using ConstructorType = std::initializer_list<std::pair<const T, VstString16>>
const &;
328 auto stepCount = static_cast<int32>(iInitList.size() - 1);
331 DCHECK_F(stepCount > 0);
334 for(
auto &pair : iInitList)
337 fMap[pair.first] = std::make_tuple(pair.second, paramValue, i);
338 fList.emplace_back(pair.first);
343 DCHECK_F(fList.size() == fMap.size());
347 inline int32
getStepCount()
const override {
return static_cast<int32>(fMap.size() - 1); }
352 auto iter = fMap.find(iValue);
353 if(iter != fMap.cend())
354 return std::get<1>(iter->second);
357 DLOG_F(WARNING,
"could not normalize value...");
372 auto iter = fMap.find(iValue);
373 if(iter != fMap.cend())
375 Steinberg::UString wrapper(oString, str16BufferSize (String128));
376 wrapper.assign(std::get<0>(iter->second).c_str());
392 template<
typename Enum, Enum MaxValue>
421 return fConverter.normalize(static_cast<IntType>(iDiscreteValue));
427 return static_cast<Enum>(fConverter.denormalize(iNormalizedValue));
433 fConverter.toString(static_cast<IntType>(iValue), oString, iPrecision);
int32 getStepCount() const override
Definition: ParamConverters.h:235
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Make sure that the value remains within its bounds.
Definition: Misc.h:33
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:370
virtual void toString(ParamType const &iValue, String128 iString, int32 iPrecision) const
Definition: ParamConverters.h:60
std::initializer_list< std::pair< const T, VstString16 > > const & ConstructorType
Defines the type for the constructor argument.
Definition: ParamConverters.h:317
double denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:169
std::vector< T > TList
Defines the mapping: discrete value [0, stepCount] to T.
Definition: ParamConverters.h:313
int32 getStepCount() const override
Definition: ParamConverters.h:118
DiscreteValueParamConverter(ConstructorType iToStringValues)
Definition: ParamConverters.h:232
Enum ParamType
Definition: ParamConverters.h:56
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:431
std::underlying_type_t< Enum > IntType
Definition: ParamConverters.h:398
DiscreteValueParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition: ParamConverters.h:228
EnumParamConverter(ConstructorType iToStringValues)
Definition: ParamConverters.h:413
std::array< VstString16, MaxValue+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition: ParamConverters.h:404
std::array< VstString16, StepCount+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition: ParamConverters.h:222
DiscreteValueParamConverter(IntType iToStringOffset=0)
Definition: ParamConverters.h:225
DiscreteTypeParamConverter(ConstructorType iInitList)
This constructor will be called this way when initializing a vst or jmb parameter:
Definition: ParamConverters.h:326
void toString(bool const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:130
This converters maps a list of values of type T to discrete values.
Definition: ParamConverters.h:304
This parameter is just a no-op wrapper to the ParamValue to adapt it to the use of the ParamConverter...
Definition: ParamConverters.h:73
ParamValue normalize(ParamValue const &iValue) const override
Definition: ParamConverters.h:79
ParamValue normalize(double const &iValue) const override
Definition: ParamConverters.h:164
int32 getStepCount() const override
Definition: ParamConverters.h:347
A trivial percent converter.
Definition: ParamConverters.h:158
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition: ParamConverters.h:94
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition: ParamConverters.h:419
EnumParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition: ParamConverters.h:410
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:363
double Percent
Percent type represented by a double.
Definition: ParamConverters.h:152
void toString(ParamValue const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:89
std::basic_string< Steinberg::char16 > VstString16
Strings made of char16 characters are represented by the native C++11 type std::basic_string<Steinber...
Definition: Types.h:43
ParamValue normalize(bool const &iValue) const override
Definition: ParamConverters.h:120
ParamValue normalize(ParamType const &iValue) const override
Definition: ParamConverters.h:350
static bool toBoolean(ParamValue iNormalizedValue)
Converts a normalized value to a boolean according to the rule: false for [0.0, 0....
Definition: ParamConverters.h:142
int32 getStepCount() const override
Definition: ParamConverters.h:416
static ParamValue convertDiscreteValueToNormalizedValue(int32 iStepCount, int32 iDiscreteValue)
Implements the algorithm described in the VST documentation on how to interpret a discrete value into...
Definition: ParamConverters.h:186
VstString16 fTrueString
Definition: ParamConverters.h:146
bool denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:125
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:174
Manages the very common case when a param represents a boolean value.
Definition: ParamConverters.h:107
static int32 convertNormalizedValueToDiscreteValue(int32 iStepCount, ParamValue iNormalizedValue)
Implements the algorithm described in the VST documentation on how to interpret a normalized value as...
Definition: ParamConverters.h:199
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:425
A converter to deal with a discrete value which has StepCount steps.
Definition: ParamConverters.h:213
ParamValue denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:84
virtual int32 getStepCount() const
Definition: ParamConverters.h:57
Enum ParamType
Definition: ParamConverters.h:396
VstString16 fFalseString
Definition: ParamConverters.h:145
EnumParamConverter(IntType iToStringOffset=0)
Definition: ParamConverters.h:407
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:242
DiscreteValueParamConverter< MaxValue, IntType > fConverter
Definition: ParamConverters.h:437
std::map< T, std::tuple< VstString16, ParamValue, int32 >, Compare > TMap
Maintains the map of possible values of T (defined in constructor)
Definition: ParamConverters.h:309
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition: ParamConverters.h:61
BooleanParamConverter(VstString16 iFalseString=STR16("Off"), VstString16 iTrueString=STR16("On"))
Definition: ParamConverters.h:112
A converter to deal with an enum (assumes that the enum is contiguous, starts at 0 and that MaxValue ...
Definition: ParamConverters.h:393
std::string toUT8String(VstString16 const &iString)
Converts a VstString16 to a regular std::string that is properly utf-8 encoded.
Definition: Utils.h:34
void toString(ParamType const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:248
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition: ParamConverters.h:237
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition: ParamConverters.h:53