26#include <pluginterfaces/vst/vsttypes.h>
27#include <pluginterfaces/base/ustring.h>
28#include <base/source/fstring.h>
29#include <pluginterfaces/base/ftypes.h>
42using namespace Steinberg;
43using namespace Steinberg::Vst;
62 virtual void toString(
ParamType const &iValue, String128 iString, int32 iPrecision)
const { }
72template<
typename T,
typename ParamType>
78 {
typename T::ParamType; } &&
90 ParamValue
normalize(ParamValue
const &iValue)
const override
95 ParamValue
denormalize(ParamValue iNormalizedValue)
const override
100 void toString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
const override
105 static void staticToString(ParamValue
const &iValue, String128 oString, int32 iPrecision)
107 Steinberg::UString wrapper(oString, str16BufferSize(String128));
108 if(!wrapper.printFloat(iValue, iPrecision))
133 return iValue ? 1.0 : 0;
141 void toString(
bool const &iValue, String128 oString, int32 )
const override
143 Steinberg::UString wrapper(oString, str16BufferSize(String128));
153 static constexpr bool toBoolean(ParamValue iNormalizedValue) {
return iNormalizedValue >= 0.5; }
187 Steinberg::UString wrapper(oString, str16BufferSize (String128));
188 wrapper.printFloat(iValue * 100, iPrecision);
189 wrapper.append(STR16(
"%"));
203 return value /
static_cast<ParamValue
>(iStepCount);
214 auto discreteValue = std::min(
static_cast<ParamValue
>(iStepCount), value * (iStepCount + 1));
216 return static_cast<int32
>(discreteValue);
237 auto discreteValue = iValue + iIncrement;
244 while(discreteValue > iStepCount)
245 discreteValue -= iStepCount + 1;
249 while(discreteValue < 0)
250 discreteValue += iStepCount + 1;
259 return discreteValue;
272template<
int32 StepCount, Utils::IntegralOrEnum IntType =
int32>
310 Steinberg::UString wrapper(oString, str16BufferSize (String128));
315 wrapper.assign(s.text());
363template<
typename T,
class Compare = std::less<T>>
369 using TMap = std::map<T, std::tuple<VstString16, ParamValue, int32>, Compare>;
377 using ConstructorType = std::initializer_list<std::pair<const T, VstString16>>
const &;
388 auto stepCount =
static_cast<int32
>(iInitList.size() - 1);
391 DCHECK_F(stepCount > 0);
394 for(
auto &pair : iInitList)
397 fMap[pair.first] = std::make_tuple(pair.second, paramValue, i);
398 fList.emplace_back(pair.first);
412 auto iter =
fMap.find(iValue);
413 if(iter !=
fMap.cend())
414 return std::get<1>(iter->second);
417 DLOG_F(WARNING,
"could not normalize value...");
432 auto iter =
fMap.find(iValue);
433 if(iter !=
fMap.cend())
435 Steinberg::UString wrapper(oString, str16BufferSize (String128));
436 wrapper.assign(std::get<0>(iter->second).c_str());
452template<
typename Enum, Enum MaxValue>
requires std::is_enum_v<Enum>
487 return static_cast<Enum
>(
fConverter.denormalize(iNormalizedValue));
BooleanParamConverter(VstString16 iFalseString=STR16("Off"), VstString16 iTrueString=STR16("On"))
Definition ParamConverters.h:123
int32 getStepCount() const override
Definition ParamConverters.h:129
VstString16 fFalseString
Definition ParamConverters.h:156
bool denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:136
static constexpr bool toBoolean(ParamValue iNormalizedValue)
Converts a normalized value to a boolean according to the rule: false for [0.0, 0....
Definition ParamConverters.h:153
ParamValue normalize(bool const &iValue) const override
Definition ParamConverters.h:131
VstString16 fTrueString
Definition ParamConverters.h:157
void toString(bool const &iValue, String128 oString, int32) const override
Definition ParamConverters.h:141
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:423
int32 getStepCount() const override
Definition ParamConverters.h:407
std::map< T, std::tuple< VstString16, ParamValue, int32 >, Compare > TMap
Maintains the map of possible values of T (defined in constructor).
Definition ParamConverters.h:369
std::initializer_list< std::pair< const T, VstString16 > > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:377
std::vector< T > TList
Defines the mapping: discrete value [0, stepCount] to T.
Definition ParamConverters.h:373
ParamValue normalize(ParamType const &iValue) const override
Definition ParamConverters.h:410
DiscreteTypeParamConverter(ConstructorType iInitList)
This constructor will be called this way when initializing a vst or jmb parameter:
Definition ParamConverters.h:386
T ParamType
Definition ParamConverters.h:379
TMap fMap
Definition ParamConverters.h:443
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:430
TList fList
Definition ParamConverters.h:444
A converter to deal with a discrete value which has StepCount steps.
Definition ParamConverters.h:274
IntType fToStringOffset
Definition ParamConverters.h:332
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:302
int32 getStepCount() const override
Definition ParamConverters.h:295
std::vector< VstString16 > fToStringValues
Definition ParamConverters.h:334
IntType ParamType
Definition ParamConverters.h:276
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition ParamConverters.h:297
DiscreteValueParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition ParamConverters.h:288
DiscreteValueParamConverter(ConstructorType iToStringValues)
Definition ParamConverters.h:292
DiscreteValueParamConverter(IntType iToStringOffset=0)
Definition ParamConverters.h:285
std::array< VstString16, StepCount+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:282
void toString(ParamType const &iValue, String128 oString, int32) const override
Definition ParamConverters.h:308
VstString16 fFormat
Definition ParamConverters.h:333
std::underlying_type_t< Enum > IntType
Definition ParamConverters.h:458
ParamType denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:485
int32 getStepCount() const override
Definition ParamConverters.h:476
Enum ParamType
Definition ParamConverters.h:456
std::array< VstString16, MaxValue+1 > const & ConstructorType
Defines the type for the constructor argument.
Definition ParamConverters.h:464
ParamValue normalize(ParamType const &iDiscreteValue) const override
Definition ParamConverters.h:479
EnumParamConverter(IntType iToStringOffset=0)
Definition ParamConverters.h:467
EnumParamConverter(VstString16 iFormat, IntType iToStringOffset=0)
Definition ParamConverters.h:470
DiscreteValueParamConverter< MaxValue, IntType > fConverter
Definition ParamConverters.h:497
EnumParamConverter(ConstructorType iToStringValues)
Definition ParamConverters.h:473
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:491
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition ParamConverters.h:54
virtual void toString(ParamType const &iValue, String128 iString, int32 iPrecision) const
Definition ParamConverters.h:62
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition ParamConverters.h:63
virtual int32 getStepCount() const
Definition ParamConverters.h:59
virtual ParamValue normalize(ParamType const &iValue) const =0
virtual ParamType denormalize(ParamValue iNormalizedValue) const =0
virtual ~IParamConverter()=default
T ParamType
Definition ParamConverters.h:58
A trivial percent converter.
Definition ParamConverters.h:170
ParamValue normalize(Percent const &iValue) const override
Definition ParamConverters.h:175
Percent denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:180
void toString(ParamType const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:185
This parameter is just a no-op wrapper to the ParamValue to adapt it to the use of the ParamConverter...
Definition ParamConverters.h:85
void toString(ParamValue const &iValue, String128 oString, int32 iPrecision) const override
Definition ParamConverters.h:100
ParamValue normalize(ParamValue const &iValue) const override
Definition ParamConverters.h:90
ParamValue denormalize(ParamValue iNormalizedValue) const override
Definition ParamConverters.h:95
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition ParamConverters.h:105
Definition ParamConverters.h:73
Defines the concept that matches IParamConverter.
Definition ParamConverters.h:77
static constexpr 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 constexpr 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:197
static constexpr 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:210
double Percent
Percent type represented by a double.
Definition ParamConverters.h:163
static constexpr int32 computeNextDiscreteValue(int32 iValue, int32 iStepCount, int32 iIncrement, bool iWrap)
Implements a standard behavior for what it means to increment (resp.
Definition ParamConverters.h:229
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