18 #ifndef __PONGASOFT_VST_PARAM_CONVERTERS_H__ 19 #define __PONGASOFT_VST_PARAM_CONVERTERS_H__ 23 #include <pluginterfaces/vst/vsttypes.h> 24 #include <pluginterfaces/vst/ivstparameterchanges.h> 25 #include <pluginterfaces/base/ustring.h> 26 #include <base/source/fstring.h> 27 #include <pluginterfaces/base/ftypes.h> 39 using namespace Steinberg;
40 using namespace Steinberg::Vst;
55 virtual ParamValue normalize(ParamType
const &iValue)
const = 0;
56 virtual ParamType denormalize(ParamValue iNormalizedValue)
const = 0;
57 virtual void toString(
ParamType const &iValue, String128 iString, int32 iPrecision)
const { }
61 toString(iValue, s, iPrecision);
62 return String(s).text8();
75 inline ParamValue
normalize(ParamValue
const &iValue)
const override 80 inline ParamValue
denormalize(ParamValue iNormalizedValue)
const override 85 inline void toString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
const override 87 staticToString(iValue, oString, iPrecision);
90 static inline void staticToString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
92 Steinberg::UString wrapper(oString, str16BufferSize(String128));
93 if(!wrapper.printFloat(iValue, iPrecision))
109 char16
const *iTrueString = STR16(
"On")) :
110 fFalseString{iFalseString},
111 fTrueString{iTrueString}
116 inline ParamValue
normalize(
bool const &iValue)
const override 118 return iValue ? 1.0 : 0;
121 inline bool denormalize(ParamValue iNormalizedValue)
const override 123 return iNormalizedValue >= 0.5;
126 inline void toString(
bool const &iValue, String128 oString, int32 )
const override 128 Steinberg::UString wrapper(oString, str16BufferSize(String128));
130 wrapper.assign(fTrueString);
132 wrapper.assign(fFalseString);
155 inline ParamValue
normalize(
double const &iValue)
const override 160 inline double denormalize(ParamValue iNormalizedValue)
const override 165 inline void toString(
ParamType const &iValue, String128 oString, int32 iPrecision)
const override 167 Steinberg::UString wrapper(oString, str16BufferSize (String128));
168 wrapper.printFloat(iValue * 100, iPrecision);
169 wrapper.append(STR16(
"%"));
178 template<
int StepCount>
191 fToStringOffset{iToStringOffset}, fFormat{iFormat} {}
195 fToStringValues(iToStringValues.cbegin(), iToStringValues.cend()) {}
199 inline ParamValue
normalize(
int const &iDiscreteValue)
const override 201 auto value =
Utils::clamp(iDiscreteValue, 0, StepCount);
202 return value / static_cast<double>(StepCount);
205 inline int denormalize(ParamValue iNormalizedValue)
const override 209 return static_cast<int>(std::floor(std::min(static_cast<ParamValue>(StepCount),
210 value * (StepCount + 1))));
216 Steinberg::UString wrapper(oString, str16BufferSize (String128));
220 s.printf(fFormat, iValue + fToStringOffset);
221 wrapper.assign(s.text());
225 if(fToStringValues.empty())
227 if(!wrapper.printInt(iValue + fToStringOffset))
232 wrapper.assign(fToStringValues[iValue].text());
238 int fToStringOffset{};
239 char16
const *fFormat{};
240 std::vector<ConstString> fToStringValues{};
247 template<
typename Enum, Enum MaxValue>
259 explicit EnumParamConverter(char16
const *iFormat,
int iToStringOffset = 0) : fConverter{iFormat, iToStringOffset} {}
262 explicit EnumParamConverter(std::array<ConstString, MaxValue + 1>
const &iToStringValues) : fConverter{iToStringValues} {}
264 inline int getStepCount()
const override {
return fConverter.getStepCount(); }
268 return fConverter.normalize(iDiscreteValue);
273 return static_cast<ParamType>(fConverter.denormalize(iNormalizedValue));
278 fConverter.toString(iValue, oString, iPrecision);
288 #endif // __PONGASOFT_VST_PARAM_CONVERTERS_H__ Enum ParamType
Definition: ParamConverters.h:251
char16 const * fTrueString
Definition: ParamConverters.h:137
BooleanParamConverter(char16 const *iFalseString=STR16("Off"), char16 const *iTrueString=STR16("On"))
Definition: ParamConverters.h:108
EnumParamConverter(char16 const *iFormat, int iToStringOffset=0)
Definition: ParamConverters.h:259
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Definition: Misc.h:33
int getStepCount() const override
Definition: ParamConverters.h:114
EnumParamConverter(std::array< ConstString, MaxValue+1 > const &iToStringValues)
Definition: ParamConverters.h:262
virtual void toString(ParamType const &iValue, String128 iString, int32 iPrecision) const
Definition: ParamConverters.h:57
ParamValue normalize(int const &iDiscreteValue) const override
Definition: ParamConverters.h:199
int getStepCount() const override
Definition: ParamConverters.h:197
DiscreteValueParamConverter(int iToStringOffset=0)
Definition: ParamConverters.h:187
ParamValue denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:80
Definition: ParamConverters.h:69
double Percent
Definition: ParamConverters.h:143
Definition: ParamConverters.h:149
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:276
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:165
Enum ParamType
Definition: ParamConverters.h:53
ParamValue normalize(double const &iValue) const override
Definition: ParamConverters.h:155
void toString(ParamType const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:214
bool denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:121
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition: ParamConverters.h:266
EnumParamConverter(int iToStringOffset=0)
Definition: ParamConverters.h:256
int denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:205
DiscreteValueParamConverter< MaxValue > fConverter
Definition: ParamConverters.h:282
Definition: ParamConverters.h:103
Definition: ParamConverters.h:179
ParamValue normalize(bool const &iValue) const override
Definition: ParamConverters.h:116
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition: ParamConverters.h:58
char16 const * fFalseString
Definition: ParamConverters.h:136
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:271
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition: ParamConverters.h:90
virtual int getStepCount() const
Definition: ParamConverters.h:54
int getStepCount() const override
Definition: ParamConverters.h:264
ParamValue normalize(ParamValue const &iValue) const override
Definition: ParamConverters.h:75
void toString(ParamValue const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:85
DiscreteValueParamConverter(std::array< ConstString, StepCount+1 > const &iToStringValues)
Definition: ParamConverters.h:194
double denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:160
void toString(bool const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:126
DiscreteValueParamConverter(char16 const *iFormat, int iToStringOffset=0)
Definition: ParamConverters.h:190
Definition: ParamConverters.h:248
Definition: ParamConverters.h:50