28 return param.mMin + value * (param.mMax - param.mMin);
33 return (value - param.mMin) / (param.mMax - param.mMin);
36IParam::ShapePowCurve::ShapePowCurve(
double shape)
43 if (mShape > 2.5)
return kDisplayCubeRoot;
44 if (mShape > 1.5)
return kDisplaySquareRoot;
45 if (mShape < (2.0 / 5.0))
return kDisplayCubed;
46 if (mShape < (2.0 / 3.0))
return kDisplaySquared;
48 return IParam::kDisplayLinear;
58 return std::pow((value - param.
GetMin()) / (param.
GetMax() - param.
GetMin()), 1.0 / mShape);
63 double min = param.
GetMin();
69 mMul = std::log(param.
GetMax() / min);
74 return std::exp(mAdd + value * mMul);
79 return (std::log(value) - mAdd) / mMul;
86 mShape = std::make_unique<ShapeLinear>();
87 memset(mName, 0, MAX_PARAM_NAME_LEN *
sizeof(
char));
88 memset(mLabel, 0, MAX_PARAM_LABEL_LEN *
sizeof(
char));
89 memset(mParamGroup, 0, MAX_PARAM_LABEL_LEN *
sizeof(
char));
92void IParam::InitBool(
const char* name,
bool defaultVal,
const char* label,
int flags,
const char* group,
const char* offText,
const char* onText)
94 if (mType == kTypeNone) mType = kTypeBool;
102void IParam::InitEnum(
const char* name,
int defaultVal,
int nEnums,
const char* label,
int flags,
const char* group,
const char* listItems, ...)
104 if (mType == kTypeNone) mType = kTypeEnum;
113 va_start(args, listItems);
114 for (
auto i = 1; i < nEnums; ++i)
120void IParam::InitEnum(
const char* name,
int defaultVal,
const std::initializer_list<const char*>& listItems,
int flags,
const char* group)
122 if (mType == kTypeNone) mType = kTypeEnum;
124 InitInt(name, defaultVal, 0,
static_cast<int>(listItems.size()) - 1,
"", flags |
kFlagStepped, group);
127 for (
auto& item : listItems)
133void IParam::InitInt(
const char* name,
int defaultVal,
int minVal,
int maxVal,
const char* label,
int flags,
const char* group)
135 if (mType == kTypeNone) mType = kTypeInt;
137 InitDouble(name, (
double) defaultVal, (
double) minVal, (
double) maxVal, 1.0, label, flags |
kFlagStepped, group);
140void IParam::InitDouble(
const char* name,
double defaultVal,
double minVal,
double maxVal,
double step,
const char* label,
int flags,
const char* group,
const Shape& shape,
EParamUnit unit,
DisplayFunc displayFunc)
142 if (mType == kTypeNone) mType = kTypeDouble;
148 strcpy(mLabel, label);
149 strcpy(mParamGroup, group);
153 mMax = std::max(maxVal, minVal + step);
155 mDefault = defaultVal;
158 mDisplayFunction = displayFunc;
162 for (mDisplayPrecision = 0;
163 mDisplayPrecision < MAX_PARAM_DISPLAY_PRECISION && step != floor(step);
164 ++mDisplayPrecision, step *= 10.0)
169 mShape = std::unique_ptr<Shape>(shape.
Clone());
173void IParam::InitFrequency(
const char *name,
double defaultVal,
double minVal,
double maxVal,
double step,
int flags,
const char *group)
175 InitDouble(name, defaultVal, minVal, maxVal, step,
"Hz", flags, group,
ShapeExp(), kUnitFrequency);
178void IParam::InitSeconds(
const char *name,
double defaultVal,
double minVal,
double maxVal,
double step,
int flags,
const char *group)
180 InitDouble(name, defaultVal, minVal, maxVal, step,
"Seconds", flags, group,
ShapeLinear(), kUnitSeconds);
185 InitDouble(name, defaultVal, minVal, maxVal, 1,
"ms", flags, group,
ShapeLinear(), kUnitMilliseconds);
188void IParam::InitPitch(
const char *name,
int defaultVal,
int minVal,
int maxVal,
int flags,
const char *group,
bool middleCisC)
190 InitEnum(name, defaultVal, (maxVal - minVal) + 1,
"", flags, group);
191 WDL_String displayText;
192 for (
auto i = minVal; i <= maxVal; i++)
199void IParam::InitGain(
const char *name,
double defaultVal,
double minVal,
double maxVal,
double step,
int flags,
const char *group)
204void IParam::InitPercentage(
const char *name,
double defaultVal,
double minVal,
double maxVal,
int flags,
const char *group)
211 InitDouble(name, defaultVal, minVal, maxVal, 1,
"degrees", flags, group,
ShapeLinear(), kUnitDegrees);
214void IParam::Init(
const IParam& p,
const char* searchStr,
const char* replaceStr,
const char* newGroup)
216 if (mType == kTypeNone) mType = p.
Type();
218 WDL_String str(p.mName);
219 WDL_String group(p.mParamGroup);
221 if (CStringHasContents(searchStr))
223 char* pos = strstr(str.Get(), searchStr);
227 int insertionPos =
static_cast<int>(str.Get() - pos);
228 str.DeleteSub(insertionPos,
static_cast<int>(strlen(searchStr)));
229 str.Insert(replaceStr, insertionPos);
233 if (CStringHasContents(newGroup))
238 InitDouble(str.Get(), p.mDefault, p.mMin, p.mMax, p.mStep, p.mLabel, p.mFlags, group.Get(), *p.mShape, p.mUnit, p.mDisplayFunction);
250 int n = mDisplayTexts.GetSize();
251 mDisplayTexts.Resize(n + 1);
252 DisplayText* pDT = mDisplayTexts.Get() + n;
254 strcpy(pDT->mText, str);
259 mDisplayPrecision = precision;
266 if (mDisplayFunction !=
nullptr)
268 mDisplayFunction(value, str);
282 if (CStringHasContents(displayText))
284 str.Set(displayText, MAX_PARAM_DISPLAY_LEN);
289 double displayValue = value;
292 displayValue = -displayValue;
295 if (!displayValue) displayValue = 0.0;
297 if (mDisplayPrecision == 0)
299 str.SetFormatted(MAX_PARAM_DISPLAY_LEN,
"%d",
static_cast<int>(round(displayValue)));
304 snprintf(fmt, 16,
"%%+.%df", mDisplayPrecision);
305 str.SetFormatted(MAX_PARAM_DISPLAY_LEN, fmt, displayValue);
309 str.SetFormatted(MAX_PARAM_DISPLAY_LEN,
"%.*f", mDisplayPrecision, displayValue);
320 return (CStringHasContents(
GetDisplayText(
static_cast<int>(mValue.load())))) ?
"" : mLabel;
330 return mDisplayTexts.GetSize();
335 int n = mDisplayTexts.GetSize();
336 for (DisplayText* pDT = mDisplayTexts.Get(); n; --n, ++pDT)
338 if (value == pDT->mValue)
return pDT->mText;
345 DisplayText* pDT = mDisplayTexts.Get()+idx;
346 if (pValue) *pValue = pDT->mValue;
352 int n = mDisplayTexts.GetSize();
353 for (DisplayText* pDT = mDisplayTexts.Get(); n; --n, ++pDT)
355 if (!strcmp(str, pDT->mText))
357 *pValue = pDT->mValue;
372 if (!mapped &&
Type() != kTypeEnum &&
Type() != kTypeBool)
394 json.AppendFormatted(8192,
"{");
395 json.AppendFormatted(8192,
"\"id\":%i, ", idx);
396 json.AppendFormatted(8192,
"\"name\":\"%s\", ",
GetName());
399 case IParam::kTypeNone:
401 case IParam::kTypeBool:
402 json.AppendFormatted(8192,
"\"type\":\"%s\", ",
"bool");
404 case IParam::kTypeInt:
405 json.AppendFormatted(8192,
"\"type\":\"%s\", ",
"int");
407 case IParam::kTypeEnum:
408 json.AppendFormatted(8192,
"\"type\":\"%s\", ",
"enum");
410 case IParam::kTypeDouble:
411 json.AppendFormatted(8192,
"\"type\":\"%s\", ",
"float");
416 json.AppendFormatted(8192,
"\"min\":%f, ",
GetMin());
417 json.AppendFormatted(8192,
"\"max\":%f, ",
GetMax());
418 json.AppendFormatted(8192,
"\"default\":%f, ",
GetDefault());
419 json.AppendFormatted(8192,
"\"display_type\":%i, ", mShape->GetDisplayType());
420 json.AppendFormatted(8192,
"\"rate\":\"control\"");
421 json.AppendFormatted(8192,
"}");
432 return IParam::EShapeIDs::kShapeLinear;
434 return IParam::EShapeIDs::kShapePowCurve;
436 return IParam::EShapeIDs::kShapeExponential;
438 return IParam::EShapeIDs::kShapeUnknown;
444 return pShapePowCurve->mShape;
IPlug logging a.k.a tracing functionality.
double GetDefault(bool normalized=false) const
Returns the parameter's default value.
void InitGain(const char *name, double defaultVal=0., double minVal=-70., double maxVal=24., double step=0.5, int flags=0, const char *group="")
Initialize the parameter as gain (units in decibels)
void InitAngleDegrees(const char *name, double defaultVal=0., double minVal=0., double maxVal=360., int flags=0, const char *group="")
Initialize the parameter as angle in degrees.
EParamType Type() const
Get the parameter's type.
void InitPercentage(const char *name, double defaultVal=0., double minVal=0., double maxVal=100., int flags=0, const char *group="")
Initialize the parameter as percentage.
@ kFlagSignDisplay
Indicates that the parameter should be displayed as a signed value.
@ kFlagStepped
Indicates that the parameter is stepped
@ kFlagNegateDisplay
Indicates that the parameter should be displayed as a negative value.
void InitEnum(const char *name, int defaultValue, int nEnums, const char *label="", int flags=0, const char *group="", const char *listItems=0,...)
Initialize the parameter as an enumerated list.
void GetDisplay(WDL_String &display, bool withDisplayText=true) const
Get the current textual display for the current parameter value.
double GetMin() const
Returns the parameter's minimum value.
void InitDouble(const char *name, double defaultVal, double minVal, double maxVal, double step, const char *label="", int flags=0, const char *group="", const Shape &shape=ShapeLinear(), EParamUnit unit=kUnitCustom, DisplayFunc displayFunc=nullptr)
Initialize the parameter as double.
void Init(const IParam &p, const char *searchStr="", const char *replaceStr="", const char *newGroup="")
Initialize the parameter based on another parameter, replacing a CString in the name.
void GetBounds(double &lo, double &hi) const
Get the minimum and maximum real value of the parameter's range in one method call.
void Set(double value)
Sets the parameter value.
const char * GetLabel() const
Returns the parameter's label.
void SetDisplayText(double value, const char *str)
Set some text to display for a particular value, e.g.
std::function< void(double, WDL_String &)> DisplayFunc
DisplayFunc allows custom parameter display functions, defined by a lambda matching this signature.
EShapeIDs
IDs for the shapes.
double StringToValue(const char *str) const
Convert a textual representation of the parameter value to a double (real value)
bool MapDisplayText(const char *str, double *pValue) const
Get the value of a particular display text.
void InitFrequency(const char *name, double defaultVal=1000., double minVal=0.1, double maxVal=10000., double step=0.1, int flags=0, const char *group="")
Initialize the parameter as frequency.
EParamUnit
Used by AudioUnit plugins to determine the appearance of parameters, based on the kind of data they r...
const char * GetName() const
Returns the parameter's name.
void InitSeconds(const char *name, double defaultVal=1., double minVal=0., double maxVal=10., double step=0.1, int flags=0, const char *group="")
Initialize the parameter as seconds.
double FromNormalized(double normalizedValue) const
Convert a normalized value to real value for this parameter.
void PrintDetails() const
Helper to print the parameter details to debug console in debug builds.
const char * GetDisplayTextAtIdx(int idx, double *pValue=nullptr) const
Get the display text at a particular index.
double Constrain(double value) const
Constrains the input value between mMin and mMax and apply stepping if relevant.
const char * GetDisplayText(double value) const
Get the display text for a particular value.
const char * GetGroup() const
Returns the parameter's group.
void InitMilliseconds(const char *name, double defaultVal=1., double minVal=0., double maxVal=100., int flags=0, const char *group="")
Initialize the parameter as milliseconds.
void SetDisplayPrecision(int precision)
Set the parameters display precision.
EDisplayType
Used by AudioUnit plugins to determine the mapping of parameters.
double GetShapeValue() const
void InitPitch(const char *name, int defaultVal=60, int minVal=0, int maxVal=128, int flags=0, const char *group="", bool middleCisC4=false)
Initialize the parameter as pitch.
double Value() const
Gets a readable value of the parameter.
int NDisplayTexts() const
Get the number of display texts for the parameter.
EShapeIDs GetShapeID() const
double GetMax() const
Returns the parameter's maximum value.
void InitBool(const char *name, bool defaultValue, const char *label="", int flags=0, const char *group="", const char *offText="off", const char *onText="on")
Initialize the parameter as boolean.
void InitInt(const char *name, int defaultValue, int minVal, int maxVal, const char *label="", int flags=0, const char *group="")
Initialize the parameter as integer.
void GetJSON(WDL_String &json, int idx) const
Get a JSON description of the parameter.
static void MidiNoteName(double midiPitch, WDL_String ¬eName, bool cents=false, bool middleCisC4=false)
Converts a MIDI pitch number to a human-readable note name.
Exponential parameter shaping.
void Init(const IParam ¶m) override
Initializes the shape instance.
double NormalizedToValue(double value, const IParam ¶m) const override
Returns the real value from a normalized input, based on an IParam's settings.
double ValueToNormalized(double value, const IParam ¶m) const override
Returns the normalized value from a real value, based on an IParam's settings.
Base struct for parameter shaping.
virtual Shape * Clone() const =0
Linear parameter shaping.
double ValueToNormalized(double value, const IParam ¶m) const override
Returns the normalized value from a real value, based on an IParam's settings.
double NormalizedToValue(double value, const IParam ¶m) const override
Returns the real value from a normalized input, based on an IParam's settings.
PowCurve parameter shaping.
IParam::EDisplayType GetDisplayType() const override
double ValueToNormalized(double value, const IParam ¶m) const override
Returns the normalized value from a real value, based on an IParam's settings.
double NormalizedToValue(double value, const IParam ¶m) const override
Returns the real value from a normalized input, based on an IParam's settings.