25#include <pluginterfaces/vst/vsttypes.h>
26#include <pluginterfaces/vst/ivstparameterchanges.h>
27#include <pluginterfaces/base/ustring.h>
28#include <base/source/fstring.h>
29#include <pluginterfaces/base/ftypes.h>
43using namespace Steinberg;
44using namespace Steinberg::Vst;
61 virtual void toString(
ParamType const &iValue, String128 iString, int32 iPrecision)
const { }
80 inline ParamValue
normalize(ParamValue
const &iValue)
const override
85 inline ParamValue
denormalize(ParamValue iNormalizedValue)
const override
90 inline void toString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
const override
95 static inline void staticToString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
97 Steinberg::UString wrapper(oString, str16BufferSize(String128));
98 if(!wrapper.printFloat(iValue, iPrecision))
121 inline ParamValue
normalize(
bool const &iValue)
const override
123 return iValue ? 1.0 : 0;
126 inline bool denormalize(ParamValue iNormalizedValue)
const override
131 inline void toString(
bool const &iValue, String128 oString, int32 )
const override
133 Steinberg::UString wrapper(oString, str16BufferSize(String128));
143 inline static bool toBoolean(ParamValue iNormalizedValue) {
return iNormalizedValue >= 0.5; }
165 inline ParamValue
normalize(
double const &iValue)
const override
170 inline double denormalize(ParamValue iNormalizedValue)
const override
175 inline void toString(
ParamType const &iValue, String128 oString, int32 iPrecision)
const override
177 Steinberg::UString wrapper(oString, str16BufferSize (String128));
178 wrapper.printFloat(iValue * 100, iPrecision);
179 wrapper.append(STR16(
"%"));
193 return value /
static_cast<ParamValue
>(iStepCount);
204 auto discreteValue = std::floor(std::min(
static_cast<ParamValue
>(iStepCount), value * (iStepCount + 1)));
205 return static_cast<int32
>(discreteValue);
226 auto discreteValue = iValue + iIncrement;
233 while(discreteValue > iStepCount)
234 discreteValue -= iStepCount + 1;
238 while(discreteValue < 0)
239 discreteValue += iStepCount + 1;
248 return discreteValue;
261template<
int32 StepCount,
typename IntType =
int32>
299 Steinberg::UString wrapper(oString, str16BufferSize (String128));
304 wrapper.assign(s.text());
352template<
typename T,
class Compare = std::less<T>>
358 using TMap = std::map<T, std::tuple<VstString16, ParamValue, int32>, Compare>;
366 using ConstructorType = std::initializer_list<std::pair<const T, VstString16>>
const &;
377 auto stepCount =
static_cast<int32
>(iInitList.size() - 1);
380 DCHECK_F(stepCount > 0);
383 for(
auto &pair : iInitList)
386 fMap[pair.first] = std::make_tuple(pair.second, paramValue, i);
387 fList.emplace_back(pair.first);
401 auto iter =
fMap.find(iValue);
402 if(iter !=
fMap.cend())
403 return std::get<1>(iter->second);
406 DLOG_F(WARNING,
"could not normalize value...");
421 auto iter =
fMap.find(iValue);
422 if(iter !=
fMap.cend())
424 Steinberg::UString wrapper(oString, str16BufferSize (String128));
425 wrapper.assign(std::get<0>(iter->second).c_str());
441template<
typename Enum, Enum MaxValue>
476 return static_cast<Enum
>(
fConverter.denormalize(iNormalizedValue));
BooleanParamConverter(VstString16 iFalseString=STR16("Off"), VstString16 iTrueString=STR16("On"))
Definition ParamConverters.h:113
int32 getStepCount() const override
Definition ParamConverters.h:119
VstString16 fFalseString
Definition ParamConverters.h:146
bool denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:126
ParamValue normalize(bool const &iValue) const override
Definition ParamConverters.h:121
VstString16 fTrueString
Definition ParamConverters.h:147
void toString(bool const &iValue, String128 oString, int32) const override
Definition ParamConverters.h:131
static bool toBoolean(ParamValue iNormalizedValue)
Converts a normalized value to a boolean according to the rule: false for [0.0, 0....
Definition ParamConverters.h:143
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:412
int32 getStepCount() const override
Definition ParamConverters.h:396
std::map< T, std::tuple< VstString16, ParamValue, int32 >, Compare > TMap
Maintains the map of possible values of T (defined in constructor).
Definition ParamConverters.h:358
std::initializer_list< std::pair< const T, VstString16 > > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:366
std::vector< T > TList
Defines the mapping: discrete value [0, stepCount] to T.
Definition ParamConverters.h:362
ParamValue normalize(ParamType const &iValue) const override
Definition ParamConverters.h:399
DiscreteTypeParamConverter(ConstructorType iInitList)
This constructor will be called this way when initializing a vst or jmb parameter:
Definition ParamConverters.h:375
T ParamType
Definition ParamConverters.h:368
TMap fMap
Definition ParamConverters.h:432
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:419
TList fList
Definition ParamConverters.h:433
A converter to deal with a discrete value which has StepCount steps.
Definition ParamConverters.h:263
IntType fToStringOffset
Definition ParamConverters.h:321
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:291
int32 getStepCount() const override
Definition ParamConverters.h:284
std::vector< VstString16 > fToStringValues
Definition ParamConverters.h:323
IntType ParamType
Definition ParamConverters.h:265
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition ParamConverters.h:286
DiscreteValueParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition ParamConverters.h:277
DiscreteValueParamConverter(ConstructorType iToStringValues)
Definition ParamConverters.h:281
DiscreteValueParamConverter(IntType iToStringOffset=0)
Definition ParamConverters.h:274
std::array< VstString16, StepCount+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:271
void toString(ParamType const &iValue, String128 oString, int32) const override
Definition ParamConverters.h:297
VstString16 fFormat
Definition ParamConverters.h:322
std::underlying_type_t< Enum > IntType
Definition ParamConverters.h:447
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:474
int32 getStepCount() const override
Definition ParamConverters.h:465
Enum ParamType
Definition ParamConverters.h:445
std::array< VstString16, MaxValue+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:453
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition ParamConverters.h:468
EnumParamConverter(IntType iToStringOffset=0)
Definition ParamConverters.h:456
EnumParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition ParamConverters.h:459
DiscreteValueParamConverter< MaxValue, IntType > fConverter
Definition ParamConverters.h:486
EnumParamConverter(ConstructorType iToStringValues)
Definition ParamConverters.h:462
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:480
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition ParamConverters.h:55
virtual void toString(ParamType const &iValue, String128 iString, int32 iPrecision) const
Definition ParamConverters.h:61
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition ParamConverters.h:62
virtual int32 getStepCount() const
Definition ParamConverters.h:58
virtual ParamValue normalize(ParamType const &iValue) const =0
virtual ParamType denormalize(ParamValue iNormalizedValue) const =0
T ParamType
Definition ParamConverters.h:57
A trivial percent converter.
Definition ParamConverters.h:160
double denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:170
ParamValue normalize(double const &iValue) const override
Definition ParamConverters.h:165
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:175
This parameter is just a no-op wrapper to the ParamValue to adapt it to the use of the ParamConverter...
Definition ParamConverters.h:75
void toString(ParamValue const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:90
ParamValue normalize(ParamValue const &iValue) const override
Definition ParamConverters.h:80
ParamValue denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:85
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition ParamConverters.h:95
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Make sure that the value remains within its bounds.
Definition Misc.h:34
constexpr auto ZERO_INT32
Definition Constants.h:25
std::string toUT8String(VstString16 const &iString)
Converts a VstString16 to a regular std::string that is properly utf-8 encoded.
Definition Utils.h:35
static int32 computeNextDiscreteValue(int32 iValue, int32 iStepCount, int32 iIncrement, bool iWrap)
Implements a standard behavior for what it means to increment (resp.
Definition ParamConverters.h:218
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:200
double Percent
Percent type represented by a double.
Definition ParamConverters.h:153
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:187
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:44