20 #include <pongasoft/logging/logging.h> 24 #include <pluginterfaces/vst/vsttypes.h> 25 #include <base/source/fstreamer.h> 35 using namespace Steinberg;
36 using namespace Steinberg::Vst;
48 virtual int32 getStepCount()
const = 0;
49 virtual tresult convertFromDiscreteValue(int32 iDiscreteValue, T &oValue)
const = 0;
50 virtual tresult convertToDiscreteValue(T
const &iValue, int32 &oDiscreteValue)
const = 0;
69 DCHECK_F(fStepCount > 0);
79 oValue = static_cast<T>(iDiscreteValue);
86 oDiscreteValue = static_cast<int32>(iValue);
109 virtual tresult readFromStream(IBStreamer &iStreamer,
ParamType &oValue)
const = 0;
110 virtual tresult writeToStream(
const ParamType &iValue, IBStreamer &oStreamer)
const = 0;
119 if constexpr(Utils::is_operator_write_to_ostream_defined<ParamType>)
127 std::ostringstream s;
130 s.precision(iPrecision);
131 s.setf(std::ios::fixed);
133 writeToStream(iValue, s);
141 namespace IBStreamHelper {
144 inline tresult
readDouble(IBStreamer &iStreamer,
double &oValue)
147 if(!iStreamer.readDouble(value))
154 inline tresult
readFloat(IBStreamer &iStreamer,
float &oValue)
157 if(!iStreamer.readFloat(value))
164 template<
typename Int>
167 for(Int i = 0; i < iCount; i++)
169 if(!iStreamer.readFloat(oValue[i]))
177 inline tresult
readInt64(IBStreamer &iStreamer, int64 &oValue)
180 if(!iStreamer.readInt64(value))
187 inline tresult
readInt64u(IBStreamer &iStreamer, uint64 &oValue)
190 if(!iStreamer.readInt64u(value))
197 inline tresult
readInt32(IBStreamer &iStreamer, int32 &oValue)
200 if(!iStreamer.readInt32(value))
207 inline tresult
readBool(IBStreamer &iStreamer,
bool &oValue)
210 if(!iStreamer.readBool(value))
231 oStreamer.writeDouble(iValue);
249 oStreamer.writeDouble(iValue);
267 oStreamer.writeInt32(iValue);
285 oStreamer.writeInt64(iValue);
297 std::string iTrueString =
"On") :
298 fFalseString{std::move(iFalseString)},
299 fTrueString{std::move(iTrueString)}
309 oStreamer.writeBool(iValue);
315 oStream << (iValue ? fTrueString : fFalseString);
323 oValue = iDiscreteValue != 0;
329 oDiscreteValue = iValue ? 1 : 0;
344 template<
int size = 128>
353 if(iStreamer.readRaw(static_cast<void*>(oValue), size) == size)
355 oValue[size - 1] = 0;
365 if(oStreamer.writeRaw(static_cast<void const *>(iValue), size) == size)
374 if(std::find(std::begin(iValue), std::end(iValue), 0) != std::end(iValue))
382 std::copy(std::begin(iValue), std::end(iValue), std::begin(str));
385 DLOG_F(WARNING,
"%s not properly null terminated!", str);
417 template<
typename T,
class Compare = std::less<T>>
423 using TMap = std::map<T, std::pair<std::string, int32>, Compare>;
431 using ConstructorType = std::initializer_list<std::pair<const T, std::string>>
const &;
440 auto stepCount = static_cast<int32>(iInitList.size() - 1);
441 DCHECK_F(stepCount > 0);
445 for(
auto &pair : iInitList)
447 fMap[pair.first] = std::make_pair(pair.second, i);
448 fList.emplace_back(pair.first);
453 DCHECK_F(fList.size() == fMap.size());
457 inline int32
getStepCount()
const override {
return static_cast<int32>(fMap.size() - 1); }
462 if(iDiscreteValue < 0 || iDiscreteValue > getStepCount())
464 oValue = fList[iDiscreteValue];
471 auto iter = fMap.find(iValue);
472 if(iter != fMap.cend())
474 oDiscreteValue = std::get<1>(iter->second);
479 DLOG_F(WARNING,
"could not convertToDiscreteValue...");
490 return convertFromDiscreteValue(discreteValue, oValue);
499 if(convertToDiscreteValue(iValue, discreteValue) == kResultOk)
501 if(oStreamer.writeInt32(discreteValue))
511 auto iter = fMap.find(iValue);
512 if(iter != fMap.cend())
514 oStream << std::get<0>(iter->second);
This parameter handles serializing a double parameter.
Definition: ParamSerializers.h:239
tresult readDouble(IBStreamer &iStreamer, double &oValue)
Definition: ParamSerializers.h:144
tresult readFloat(IBStreamer &iStreamer, float &oValue)
Definition: ParamSerializers.h:154
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
This parameter handles serializing a int64 parameter.
Definition: ParamSerializers.h:275
tresult convertToDiscreteValue(T const &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:84
tresult readInt64u(IBStreamer &iStreamer, uint64 &oValue)
Definition: ParamSerializers.h:187
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:363
char[size] ParamType
Definition: ParamSerializers.h:348
std::initializer_list< std::pair< const T, std::string > > const & ConstructorType
Defines the type for the constructor argument.
Definition: ParamSerializers.h:431
This parameter handles serializing a bool parameter.
Definition: ParamSerializers.h:293
constexpr auto ZERO_INT32
Definition: Constants.h:24
This parameter handles serializing a raw parameter (ParamValue)
Definition: ParamSerializers.h:221
int32 getStepCount() const override
Definition: ParamSerializers.h:457
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:247
tresult convertFromDiscreteValue(int32 iDiscreteValue, T &oValue) const override
Definition: ParamSerializers.h:76
tresult convertFromDiscreteValue(int32 iDiscreteValue, bool &oValue) const override
Definition: ParamSerializers.h:321
std::vector< T > TList
Defines the mapping: discrete value [0, stepCount] to T.
Definition: ParamSerializers.h:427
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:260
tresult readInt32(IBStreamer &iStreamer, int32 &oValue)
Definition: ParamSerializers.h:197
DiscreteTypeParamSerializer(ConstructorType iInitList)
Definition: ParamSerializers.h:436
tresult convertToDiscreteValue(ParamType const &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:469
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:265
tresult readFloatArray(IBStreamer &iStreamer, float *oValue, Int iCount)
Definition: ParamSerializers.h:165
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:302
tresult convertFromDiscreteValue(int32 iDiscreteValue, ParamType &oValue) const override
Definition: ParamSerializers.h:460
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:283
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:351
int32 fStepCount
Definition: ParamSerializers.h:92
A parameter backed by a C type string (char[size]).
Definition: ParamSerializers.h:345
void writeToStream(ParamType const &iValue, std::ostream &oStream) const override
By default, this implementation simply writes the value to the stream IF it is possible (determined a...
Definition: ParamSerializers.h:313
tresult readBool(IBStreamer &iStreamer, bool &oValue)
Definition: ParamSerializers.h:207
std::map< T, std::pair< std::string, int32 >, Compare > TMap
Maintains the map of possible values of T (defined in constructor)
Definition: ParamSerializers.h:423
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:229
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:307
Interface that defines a converter from a type T to an int32 given a number of steps (provided by get...
Definition: ParamSerializers.h:45
std::string fFalseString
Definition: ParamSerializers.h:334
BooleanParamSerializer(std::string iFalseString="Off", std::string iTrueString="On")
Definition: ParamSerializers.h:296
void writeToStream(ParamType const &iValue, std::ostream &oStream) const override
Definition: ParamSerializers.h:372
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition: ParamSerializers.h:105
This parameter handles serializing a int32 parameter.
Definition: ParamSerializers.h:257
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition: ParamSerializers.h:125
tresult convertToDiscreteValue(const bool &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:327
This converters maps a list of values of type T to discrete values.
Definition: ParamSerializers.h:418
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:224
virtual void writeToStream(ParamType const &iValue, std::ostream &oStream) const
By default, this implementation simply writes the value to the stream IF it is possible (determined a...
Definition: ParamSerializers.h:117
int32 getStepCount() const override
Definition: ParamSerializers.h:319
tresult readInt64(IBStreamer &iStreamer, int64 &oValue)
Definition: ParamSerializers.h:177
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:278
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:242
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:496
int32 getStepCount() const override
Definition: ParamSerializers.h:73
void writeToStream(ParamType const &iValue, std::ostream &oStream) const override
By default, this implementation simply writes the value to the stream IF it is possible (determined a...
Definition: ParamSerializers.h:509
ParamValue ParamType
Definition: ParamSerializers.h:108
This implementation simply cast T to an int32 (and vice-versa).
Definition: ParamSerializers.h:63
StaticCastDiscreteConverter(int32 iStepCount)
Definition: ParamSerializers.h:67
std::string fTrueString
Definition: ParamSerializers.h:335
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:485