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);
131 if constexpr(Utils::is_operator_write_to_ostream_defined<ParamType>)
139 std::ostringstream s;
142 s.precision(iPrecision);
143 s.setf(std::ios::fixed);
145 writeToStream(iValue, s);
153 namespace IBStreamHelper {
156 inline tresult
readDouble(IBStreamer &iStreamer,
double &oValue)
159 if(!iStreamer.readDouble(value))
166 inline tresult
readFloat(IBStreamer &iStreamer,
float &oValue)
169 if(!iStreamer.readFloat(value))
176 template<
typename Int>
179 for(Int i = 0; i < iCount; i++)
181 if(!iStreamer.readFloat(oValue[i]))
189 inline tresult
readInt64(IBStreamer &iStreamer, int64 &oValue)
192 if(!iStreamer.readInt64(value))
199 inline tresult
readInt64u(IBStreamer &iStreamer, uint64 &oValue)
202 if(!iStreamer.readInt64u(value))
209 inline tresult
readInt32(IBStreamer &iStreamer, int32 &oValue)
212 if(!iStreamer.readInt32(value))
219 inline tresult
readBool(IBStreamer &iStreamer,
bool &oValue)
222 if(!iStreamer.readBool(value))
243 oStreamer.writeDouble(iValue);
261 oStreamer.writeDouble(iValue);
279 oStreamer.writeInt32(iValue);
297 oStreamer.writeInt64(iValue);
309 std::string iTrueString =
"On") :
310 fFalseString{std::move(iFalseString)},
311 fTrueString{std::move(iTrueString)}
321 oStreamer.writeBool(iValue);
327 oStream << (iValue ? fTrueString : fFalseString);
335 oValue = iDiscreteValue != 0;
341 oDiscreteValue = iValue ? 1 : 0;
356 template<
int size = 128>
365 if(iStreamer.readRaw(static_cast<void*>(oValue), size) == size)
367 oValue[size - 1] = 0;
377 if(oStreamer.writeRaw(static_cast<void const *>(iValue), size) == size)
386 if(std::find(std::begin(iValue), std::end(iValue), 0) != std::end(iValue))
394 std::copy(std::begin(iValue), std::end(iValue), std::begin(str));
397 DLOG_F(WARNING,
"%s not properly null terminated!", str);
429 template<
typename T,
class Compare = std::less<T>>
435 using TMap = std::map<T, std::pair<std::string, int32>, Compare>;
443 using ConstructorType = std::initializer_list<std::pair<const T, std::string>>
const &;
452 auto stepCount = static_cast<int32>(iInitList.size() - 1);
453 DCHECK_F(stepCount > 0);
457 for(
auto &pair : iInitList)
459 fMap[pair.first] = std::make_pair(pair.second, i);
460 fList.emplace_back(pair.first);
465 DCHECK_F(fList.size() == fMap.size());
469 inline int32
getStepCount()
const override {
return static_cast<int32>(fMap.size() - 1); }
474 if(iDiscreteValue < 0 || iDiscreteValue > getStepCount())
476 oValue = fList[iDiscreteValue];
483 auto iter = fMap.find(iValue);
484 if(iter != fMap.cend())
486 oDiscreteValue = std::get<1>(iter->second);
491 DLOG_F(WARNING,
"could not convertToDiscreteValue...");
502 return convertFromDiscreteValue(discreteValue, oValue);
511 if(convertToDiscreteValue(iValue, discreteValue) == kResultOk)
513 if(oStreamer.writeInt32(discreteValue))
523 auto iter = fMap.find(iValue);
524 if(iter != fMap.cend())
526 oStream << std::get<0>(iter->second);
This parameter handles serializing a double parameter.
Definition: ParamSerializers.h:251
tresult readDouble(IBStreamer &iStreamer, double &oValue)
Definition: ParamSerializers.h:156
tresult readFloat(IBStreamer &iStreamer, float &oValue)
Definition: ParamSerializers.h:166
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:287
tresult convertToDiscreteValue(T const &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:84
tresult readInt64u(IBStreamer &iStreamer, uint64 &oValue)
Definition: ParamSerializers.h:199
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
Definition: ParamSerializers.h:375
char[size] ParamType
Definition: ParamSerializers.h:360
std::initializer_list< std::pair< const T, std::string > > const & ConstructorType
Defines the type for the constructor argument.
Definition: ParamSerializers.h:443
This parameter handles serializing a bool parameter.
Definition: ParamSerializers.h:305
constexpr auto ZERO_INT32
Definition: Constants.h:24
This parameter handles serializing a raw parameter (ParamValue)
Definition: ParamSerializers.h:233
int32 getStepCount() const override
Definition: ParamSerializers.h:469
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:259
tresult convertFromDiscreteValue(int32 iDiscreteValue, T &oValue) const override
Definition: ParamSerializers.h:76
tresult convertFromDiscreteValue(int32 iDiscreteValue, bool &oValue) const override
Definition: ParamSerializers.h:333
std::vector< T > TList
Defines the mapping: discrete value [0, stepCount] to T.
Definition: ParamSerializers.h:439
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:272
tresult readInt32(IBStreamer &iStreamer, int32 &oValue)
Definition: ParamSerializers.h:209
virtual tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:116
DiscreteTypeParamSerializer(ConstructorType iInitList)
Definition: ParamSerializers.h:448
tresult convertToDiscreteValue(ParamType const &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:481
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:277
tresult readFloatArray(IBStreamer &iStreamer, float *oValue, Int iCount)
Definition: ParamSerializers.h:177
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:314
tresult convertFromDiscreteValue(int32 iDiscreteValue, ParamType &oValue) const override
Definition: ParamSerializers.h:472
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:295
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
Definition: ParamSerializers.h:363
int32 fStepCount
Definition: ParamSerializers.h:92
virtual tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:122
A parameter backed by a C type string (char[size]).
Definition: ParamSerializers.h:357
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:325
tresult readBool(IBStreamer &iStreamer, bool &oValue)
Definition: ParamSerializers.h:219
std::map< T, std::pair< std::string, int32 >, Compare > TMap
Maintains the map of possible values of T (defined in constructor)
Definition: ParamSerializers.h:435
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:241
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:319
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:346
BooleanParamSerializer(std::string iFalseString="Off", std::string iTrueString="On")
Definition: ParamSerializers.h:308
void writeToStream(ParamType const &iValue, std::ostream &oStream) const override
Definition: ParamSerializers.h:384
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition: ParamSerializers.h:107
This parameter handles serializing a int32 parameter.
Definition: ParamSerializers.h:269
virtual std::string toString(ParamType const &iValue, int32 iPrecision) const
Definition: ParamSerializers.h:137
tresult convertToDiscreteValue(const bool &iValue, int32 &oDiscreteValue) const override
Definition: ParamSerializers.h:339
This converters maps a list of values of type T to discrete values.
Definition: ParamSerializers.h:430
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:236
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:129
int32 getStepCount() const override
Definition: ParamSerializers.h:331
tresult readInt64(IBStreamer &iStreamer, int64 &oValue)
Definition: ParamSerializers.h:189
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:290
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:254
tresult writeToStream(const ParamType &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamSerializers.h:508
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:521
ParamValue ParamType
Definition: ParamSerializers.h:110
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:347
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamSerializers.h:497