25 #include <base/source/fstreamer.h> 26 #include <pluginterfaces/vst/vsttypes.h> 27 #include <pluginterfaces/vst/ivsteditcontroller.h> 28 #include <pluginterfaces/vst/ivstunits.h> 35 using namespace Steinberg;
36 using namespace Steinberg::Vst;
39 namespace GUI::Params {
40 class IGUIJmbParameter;
46 class IParamDef :
public std::enable_shared_from_this<IParamDef>
58 static constexpr int16 kVersionNotDeprecated = -1;
64 bool const iTransient,
65 int16
const iDeprecatedSince) :
67 fTitle{std::move(iTitle)},
69 fTransient{iTransient},
70 fDeprecatedSince{iDeprecatedSince}
73 virtual ~IParamDef() =
default;
76 bool isDeprecated()
const {
return fDeprecatedSince > kVersionNotDeprecated; }
96 ParamValue
const iDefaultNormalizedValue,
97 int32
const iStepCount,
101 int32
const iPrecision,
103 bool const iTransient,
104 int16
const iDeprecatedSince) :
105 IParamDef(iParamID, std::move(iTitle), iOwner, iTransient, iDeprecatedSince),
106 fUnits{std::move(iUnits)},
107 fDefaultValue{
Utils::clampE(iDefaultNormalizedValue, 0.0, 1.0)},
108 fStepCount{iStepCount},
111 fShortTitle{std::move(iShortTitle)},
112 fPrecision{iPrecision}
119 ParamValue res = fDefaultValue;
131 ParamValue res = fDefaultValue;
143 virtual void toString(ParamValue iNormalizedValue, String128 iString)
const 154 virtual std::string
toUTF8String(ParamValue iNormalizedValue, int32 iPrecision)
const 186 UnitID
const iUnitID,
188 int32
const iPrecision,
190 bool const iTransient,
191 int16
const iDeprecatedSince,
196 iConverter ? iConverter->normalize(iDefaultValue) : 0,
197 iConverter ? iConverter->getStepCount() : 0,
200 std::move(iShortTitle),
205 fDefaultValue{iDefaultValue},
206 fConverter{std::move(iConverter)}
213 return denormalize(RawVstParamDef::readFromState(iState));
219 return RawVstParamDef::writeToState(normalize(iValue), oState);
229 return fConverter->normalize(iValue);
237 return fConverter->denormalize(iNormalizedValue);
238 return fDefaultValue;
244 void toString(ParamValue iNormalizedValue, String128 iString)
const override 247 fConverter->toString(fConverter->denormalize(iNormalizedValue), iString, fPrecision);
249 RawVstParamDef::toString(iNormalizedValue, iString);
258 std::string
toUTF8String(ParamValue iNormalizedValue, int32 iPrecision)
const override 264 fConverter->toString(fConverter->denormalize(iNormalizedValue), s, iPrecision >= 0 ? iPrecision : fPrecision);
273 const std::shared_ptr<IParamConverter<ParamType>>
fConverter;
285 bool const iTransient,
286 int16
const iDeprecatedSince,
288 :
IParamDef(iParamID, std::move(iTitle), iOwner, iTransient, iDeprecatedSince),
292 ~IJmbParamDef()
override =
default;
295 virtual void writeDefaultValue(std::ostream &oStreamer)
const = 0;
300 virtual std::shared_ptr<GUI::Params::IGUIJmbParameter> newGUIParam() = 0;
305 virtual bool isSerializable()
const = 0;
324 bool const iTransient,
325 int16
const iDeprecatedSince,
329 IJmbParamDef(iParamID, std::move(iTitle), iOwner, iTransient, iDeprecatedSince, iShared),
330 fDefaultValue{iDefaultValue},
331 fSerializer{std::move(iSerializer)}
335 tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue)
const override;
336 ParamType readFromStream(IBStreamer &iStreamer)
const;
339 tresult writeToStream(ParamType
const &iValue, IBStreamer &oStreamer)
const override;
342 void writeToStream(ParamType
const &iValue, std::ostream &oStreamer)
const override;
345 void writeDefaultValue(std::ostream &oStreamer)
const override;
348 tresult readFromMessage(Message
const &iMessage, ParamType &oValue)
const;
351 tresult writeToMessage(ParamType
const &iValue, Message &oMessage)
const;
362 return fSerializer->toString(iValue, iPrecision);
365 if constexpr(Utils::is_operator_write_to_ostream_defined<ParamType>)
367 std::ostringstream s;
370 s.precision(iPrecision);
371 s.setf(std::ios::fixed);
403 std::shared_ptr<GUI::Params::IGUIJmbParameter> newGUIParam()
override;
436 if(readFromStream(iStreamer, value) != kResultOk)
437 value = fDefaultValue;
464 if constexpr(Utils::is_operator_write_to_ostream_defined<ParamType>)
477 writeToStream(fDefaultValue, oStreamer);
tresult readDouble(IBStreamer &iStreamer, double &oValue)
Definition: ParamSerializers.h:156
const std::shared_ptr< IParamConverter< ParamType > > fConverter
Definition: ParamDef.h:273
ParamType readFromState(NormalizedState const &iState) const
Read the value from the (normalized) state.
Definition: ParamDef.h:211
tresult writeToState(ParamValue iValue, NormalizedState &oState) const
Writes the provided value to the (normalized) state.
Definition: ParamDef.h:137
const ParamType fDefaultValue
Definition: ParamDef.h:411
virtual std::string toUTF8String(ParamValue iNormalizedValue, int32 iPrecision) const
Return the value as a utf-8 string.
Definition: ParamDef.h:154
void toString(ParamValue iNormalizedValue, String128 iString) const override
Using fConverter::toString
Definition: ParamDef.h:244
const std::shared_ptr< IParamSerializer< ParamType > > fSerializer
Definition: ParamDef.h:412
tresult writeToStream(ParamType const &iValue, IBStreamer &oStreamer) const override
This method should write iValue to the stream (aka serialization)
Definition: ParamDef.h:446
Base class for a raw vst parameter definition.
Definition: ParamDef.h:90
const Owner fOwner
Definition: ParamDef.h:81
Simple wrapper class with better api.
Definition: Messaging.h:44
static T clampE(const U &value, const T &lower, const T &upper)
Same as clamp except it will actually fail/assert in debug mode.
Definition: Misc.h:58
const ParamID fParamID
Definition: ParamDef.h:79
ParamType denormalize(ParamValue iNormalizedValue) const
Definition: ParamDef.h:234
tresult setSerializableValue(IAttributeList::AttrID id, IParamSerializer< T > const &iSerializer, T const &iValue)
Serializes the parameter value as an entry in the message.
Definition: Messaging.h:151
const int32 fFlags
Definition: ParamDef.h:166
std::shared_ptr< RawVstParamDef > RawVstParam
Definition: ParamDef.h:509
tresult setNormalizedValue(ParamID iParamID, ParamValue iValue)
Sets the normalized value for the given param id if it exists.
Definition: NormalizedState.cpp:146
const int16 fDeprecatedSince
Definition: ParamDef.h:83
std::string toUTF8String(T const &iValue, Steinberg::int32 iPrecision)
This generic function will determine (at compilation time) whether T can be written to an ostream and...
Definition: Utils.h:49
std::string toUTF8String(ParamValue iNormalizedValue, int32 iPrecision) const override
Return the value as a utf-8 string.
Definition: ParamDef.h:258
ParamValue readFromStream(IBStreamer &iStreamer) const
Definition: ParamDef.h:117
ParamValue readFromState(NormalizedState const &iState) const
Read the value from the (normalized) state.
Definition: ParamDef.h:129
const VstString16 fUnits
Definition: ParamDef.h:163
Used to communicate the state between the UI and the RT and read/write to stream.
Definition: NormalizedState.h:37
const ParamType fDefaultValue
Definition: ParamDef.h:272
T ParamType
Definition: ParamDef.h:179
const int32 fStepCount
Definition: ParamDef.h:165
T ParamType
Definition: ParamDef.h:319
static void staticToString(ParamValue const &iValue, String128 oString, int32 iPrecision)
Definition: ParamConverters.h:94
const ParamValue fDefaultValue
Definition: ParamDef.h:164
const bool fTransient
Definition: ParamDef.h:82
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:43
const VstString16 fTitle
Definition: ParamDef.h:80
IParamDef(ParamID const iParamID, VstString16 iTitle, Owner const iOwner, bool const iTransient, int16 const iDeprecatedSince)
Definition: ParamDef.h:61
bool isDeprecated() const
Returns true if the parameter is deprecated (meaning it can only be used to upgrade to latest version...
Definition: ParamDef.h:76
VstParamDef(ParamID const iParamID, VstString16 iTitle, VstString16 iUnits, ParamType const iDefaultValue, int32 const iFlags, UnitID const iUnitID, VstString16 iShortTitle, int32 const iPrecision, Owner const iOwner, bool const iTransient, int16 const iDeprecatedSince, std::shared_ptr< IParamConverter< ParamType >> iConverter)
Definition: ParamDef.h:181
tresult readFromStream(IBStreamer &iStreamer, ParamType &oValue) const override
This method should read from the stream and populate oValue accordingly (aka deserialization)
Definition: ParamDef.h:419
Interface that defines a converter from a type T to an int32 given a number of steps (provided by get...
Definition: ParamSerializers.h:45
const VstString16 fShortTitle
Definition: ParamDef.h:168
tresult getNormalizedValue(ParamID iParamID, ParamValue &oValue) const
Returns the normalized value for the given param id if it exists.
Definition: NormalizedState.cpp:131
bool const fShared
Definition: ParamDef.h:308
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition: ParamSerializers.h:107
std::string computeMessageAttrID() const
Definition: ParamDef.h:392
IJmbParamDef(const ParamID iParamID, VstString16 iTitle, Owner const iOwner, bool const iTransient, int16 const iDeprecatedSince, bool const iShared)
Definition: ParamDef.h:282
Base class for all ParamDef.
Definition: ParamDef.h:46
ParamType getDefaultValue() const
Definition: ParamDef.h:223
std::shared_ptr< VstParamDef< T > > VstParam
Definition: ParamDef.h:508
ParamValue normalize(ParamType const &iValue) const
Definition: ParamDef.h:226
virtual void toString(ParamValue iNormalizedValue, String128 iString) const
Definition: ParamDef.h:143
Owner
Who owns the parameter (mostly for state saving purposes)
Definition: ParamDef.h:51
Typed parameter definition.
Definition: ParamDef.h:176
const int32 fPrecision
Definition: ParamDef.h:169
bool isSerializable() const override
Definition: ParamDef.h:408
RawVstParamDef(ParamID const iParamID, VstString16 iTitle, VstString16 iUnits, ParamValue const iDefaultNormalizedValue, int32 const iStepCount, int32 const iFlags, UnitID const iUnitID, VstString16 iShortTitle, int32 const iPrecision, Owner const iOwner, bool const iTransient, int16 const iDeprecatedSince)
Definition: ParamDef.h:93
const UnitID fUnitID
Definition: ParamDef.h:167
std::string toUTF8String(ParamType const &iValue, int32 iPrecision) const
Return the value as a utf-8 string.
Definition: ParamDef.h:359
Base class for all non vst parameters (need to provide serialization/deserialization)
Definition: ParamDef.h:316
JmbParamDef(ParamID const iParamID, VstString16 iTitle, Owner const iOwner, bool const iTransient, int16 const iDeprecatedSince, bool const iShared, ParamType const &iDefaultValue, std::shared_ptr< IParamSerializer< ParamType >> iSerializer)
Definition: ParamDef.h:321
tresult getSerializableValue(IAttributeList::AttrID id, IParamSerializer< T > const &iSerializer, T &oValue) const
Deserializes the parameter value from an entry in the message.
Definition: Messaging.h:169
std::shared_ptr< JmbParamDef< T > > JmbParam
Definition: ParamDef.h:515
std::shared_ptr< IDiscreteConverter< T > > getDiscreteConverter() const
Definition: ParamDef.h:384
Base class for jamba parameters (non templated)
Definition: ParamDef.h:279
constexpr char const * to_string(bool iValue)
Convenient call to convert a boolean into a string.
Definition: StringUtils.h:28
std::string toUT8String(VstString16 const &iString)
Converts a VstString16 to a regular std::string that is properly utf-8 encoded.
Definition: Utils.h:34
A vst parameter is represented by a ParamValue type which is a double in the range [0,...
Definition: ParamConverters.h:53
tresult writeToState(ParamType const &iValue, NormalizedState &oState) const
Writes the provided value to the (normalized) state.
Definition: ParamDef.h:217