18 #ifndef __PONGASOFT_VST_PARAM_CONVERTERS_H__ 19 #define __PONGASOFT_VST_PARAM_CONVERTERS_H__ 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> 36 #include <type_traits> 41 using namespace Steinberg;
42 using namespace Steinberg::Vst;
57 virtual ParamValue normalize(ParamType
const &iValue)
const = 0;
58 virtual ParamType denormalize(ParamValue iNormalizedValue)
const = 0;
59 virtual void toString(
ParamType const &iValue, String128 iString, int32 iPrecision)
const { }
63 toString(iValue, s, iPrecision);
64 return String(s).text8();
77 inline ParamValue
normalize(ParamValue
const &iValue)
const override 82 inline ParamValue
denormalize(ParamValue iNormalizedValue)
const override 87 inline void toString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
const override 89 staticToString(iValue, oString, iPrecision);
92 static inline void staticToString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
94 Steinberg::UString wrapper(oString, str16BufferSize(String128));
95 if(!wrapper.printFloat(iValue, iPrecision))
112 fFalseString{std::move(iFalseString)},
113 fTrueString{std::move(iTrueString)}
118 inline ParamValue
normalize(
bool const &iValue)
const override 120 return iValue ? 1.0 : 0;
123 inline bool denormalize(ParamValue iNormalizedValue)
const override 125 return iNormalizedValue >= 0.5;
128 inline void toString(
bool const &iValue, String128 oString, int32 )
const override 130 Steinberg::UString wrapper(oString, str16BufferSize(String128));
132 wrapper.assign(fTrueString.c_str());
134 wrapper.assign(fFalseString.c_str());
157 inline ParamValue
normalize(
double const &iValue)
const override 162 inline double denormalize(ParamValue iNormalizedValue)
const override 167 inline void toString(
ParamType const &iValue, String128 oString, int32 iPrecision)
const override 169 Steinberg::UString wrapper(oString, str16BufferSize (String128));
170 wrapper.printFloat(iValue * 100, iPrecision);
171 wrapper.append(STR16(
"%"));
179 template<
typename IntType =
int>
182 auto value = Utils::clamp<int32, int32>(iDiscreteValue, 0, iStepCount);
186 return value / static_cast<ParamValue>(iStepCount);
193 template<
typename IntType =
int>
198 auto discreteValue = std::floor(std::min(static_cast<ParamValue>(iStepCount), value * (iStepCount + 1)));
199 return static_cast<IntType>(discreteValue);
207 template<
int32 StepCount,
typename IntType =
int>
220 fToStringOffset{iToStringOffset}, fFormat{std::move(iFormat)} {}
224 fToStringValues(iToStringValues.cbegin(), iToStringValues.cend()) {}
230 return convertDiscreteValueToNormalizedValue<IntType>(StepCount, iDiscreteValue);
235 return convertNormalizedValueToDiscreteValue<IntType>(StepCount, iNormalizedValue);
241 Steinberg::UString wrapper(oString, str16BufferSize (String128));
245 s.printf(fFormat.c_str(), iValue + fToStringOffset);
246 wrapper.assign(s.text());
250 if(fToStringValues.empty())
252 if(!wrapper.printInt(iValue + fToStringOffset))
257 wrapper.assign(fToStringValues[iValue].c_str());
263 IntType fToStringOffset{};
265 std::vector<VstString16> fToStringValues{};
272 template<
typename Enum, Enum MaxValue>
289 explicit EnumParamConverter(std::array<VstString16, MaxValue + 1>
const &iToStringValues) : fConverter{iToStringValues} {}
295 return fConverter.normalize(static_cast<IntType>(iDiscreteValue));
300 return static_cast<Enum>(fConverter.denormalize(iNormalizedValue));
305 fConverter.toString(static_cast<IntType>(iValue), oString, iPrecision);
315 #endif // __PONGASOFT_VST_PARAM_CONVERTERS_H__ Enum ParamType
Definition: ParamConverters.h:276
DiscreteValueParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition: ParamConverters.h:219
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Definition: Misc.h:33
EnumParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition: ParamConverters.h:286
static ParamValue convertDiscreteValueToNormalizedValue(int32 iStepCount, IntType iDiscreteValue)
Definition: ParamConverters.h:180
virtual void toString(ParamType const &iValue, String128 iString, int32 iPrecision) const
Definition: ParamConverters.h:59
VstString16 fTrueString
Definition: ParamConverters.h:139
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition: ParamConverters.h:228
std::basic_string< Steinberg::char16 > VstString16
Definition: Types.h:37
VstString16 fFalseString
Definition: ParamConverters.h:138
BooleanParamConverter(VstString16 iFalseString=STR16("Off"), VstString16 iTrueString=STR16("On"))
Definition: ParamConverters.h:110
ParamValue denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:82
int32 getStepCount() const override
Definition: ParamConverters.h:116
Definition: ParamConverters.h:71
double Percent
Definition: ParamConverters.h:145
Definition: ParamConverters.h:151
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:303
DiscreteValueParamConverter< MaxValue, IntType > fConverter
Definition: ParamConverters.h:309
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:167
Enum ParamType
Definition: ParamConverters.h:55
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:233
void toString(ParamType const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:239
ParamValue normalize(double const &iValue) const override
Definition: ParamConverters.h:157
EnumParamConverter(std::array< VstString16, MaxValue+1 > const &iToStringValues)
Definition: ParamConverters.h:289
bool denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:123
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition: ParamConverters.h:293
int32 getStepCount() const override
Definition: ParamConverters.h:226
int32 getStepCount() const override
Definition: ParamConverters.h:291
DiscreteValueParamConverter(IntType iToStringOffset=0)
Definition: ParamConverters.h:216
DiscreteValueParamConverter(std::array< VstString16, StepCount+1 > const &iToStringValues)
Definition: ParamConverters.h:223
Definition: ParamConverters.h:105
Definition: ParamConverters.h:208
ParamValue normalize(bool const &iValue) const override
Definition: ParamConverters.h:118
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition: ParamConverters.h:60
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:298
EnumParamConverter(IntType iToStringOffset=0)
Definition: ParamConverters.h:283
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition: ParamConverters.h:92
ParamValue normalize(ParamValue const &iValue) const override
Definition: ParamConverters.h:77
void toString(ParamValue const &iValue, String128 oString, int32 iPrecision) const override
Definition: ParamConverters.h:87
double denormalize(ParamValue iNormalizedValue) const override
Definition: ParamConverters.h:162
void toString(bool const &iValue, String128 oString, int32) const override
Definition: ParamConverters.h:128
virtual int32 getStepCount() const
Definition: ParamConverters.h:56
static IntType convertNormalizedValueToDiscreteValue(int32 iStepCount, ParamValue iNormalizedValue)
Definition: ParamConverters.h:194
std::underlying_type_t< Enum > IntType
Definition: ParamConverters.h:278
Definition: ParamConverters.h:273
Definition: ParamConverters.h:52