Skip to main content

Overview

The IParam class represents a plugin parameter in iPlug2. It handles value storage, normalization, display formatting, constraints, and parameter shaping. Parameters are accessed by index and store non-normalized (real) values. Header: IPlug/IPlugParameter.h
IParam values are stored as atomic doubles for thread-safe access. Use Value() to read and Set() to write.

Enumerations

EParamType

Defines the type of parameter.
enum EParamType
{
  kTypeNone,    // Uninitialized
  kTypeBool,    // Boolean (0 or 1)
  kTypeInt,     // Integer
  kTypeEnum,    // Enumerated list
  kTypeDouble   // Double precision floating point
};

EParamUnit

Used by AudioUnit plugins to determine parameter appearance.
enum EParamUnit
{
  kUnitPercentage, kUnitSeconds, kUnitMilliseconds, kUnitSamples,
  kUnitDB, kUnitLinearGain, kUnitPan, kUnitPhase, kUnitDegrees,
  kUnitMeters, kUnitRate, kUnitRatio, kUnitFrequency, kUnitOctaves,
  kUnitCents, kUnitAbsCents, kUnitSemitones, kUnitMIDINote,
  kUnitMIDICtrlNum, kUnitBPM, kUnitBeats, kUnitCustom
};

EDisplayType

Used by AudioUnit plugins to determine parameter mapping.
enum EDisplayType
{
  kDisplayLinear, kDisplayLog, kDisplayExp, kDisplaySquared,
  kDisplaySquareRoot, kDisplayCubed, kDisplayCubeRoot
};

EFlags

Parameter flags for special characteristics.
enum EFlags
{
  kFlagsNone = 0,
  kFlagCannotAutomate = 0x1,  // Parameter is not automatable
  kFlagStepped = 0x2,          // Parameter is stepped/discrete
  kFlagNegateDisplay = 0x4,    // Display as negative value
  kFlagSignDisplay = 0x8,      // Display as signed value
  kFlagMeta = 0x10             // Meta parameter (affects other params)
};

EShapeIDs

enum EShapeIDs
{
  kShapeLinear = 0,
  kShapePowCurve = 1,
  kShapeExponential = 2,
  kShapeUnknown
};

Parameter Shaping

Parameter shapes determine how normalized values (0-1) map to real values.

Shape

Base struct for parameter shaping.
struct Shape
{
  virtual Shape* Clone() const = 0;
  virtual void Init(const IParam& param);
  virtual EDisplayType GetDisplayType() const = 0;
  virtual double NormalizedToValue(double value, const IParam& param) const = 0;
  virtual double ValueToNormalized(double value, const IParam& param) const = 0;
};

ShapeLinear

Linear parameter mapping (default).
struct ShapeLinear : public Shape
{
  double mShape;
};

ShapePowCurve

Power curve shaping for custom response curves.
struct ShapePowCurve : public Shape
{
  ShapePowCurve(double shape);
  double mShape;
};
shape
double
required
Shape exponent. Values < 1 compress low end, > 1 compress high end
// Example: Frequency parameter with power curve
GetParam(kFreq)->InitDouble("Frequency", 1000., 20., 20000., 0.1, "Hz",
                            0, "", IParam::ShapePowCurve(3.0));

ShapeExp

Exponential/logarithmic shaping (ideal for frequency).
struct ShapeExp : public Shape
{
  void Init(const IParam& param) override;
  double mMul = 1.0;
  double mAdd = 1.0;
};
// Example: Exponential frequency parameter
GetParam(kFreq)->InitDouble("Frequency", 1000., 20., 20000., 0.1, "Hz",
                            0, "", IParam::ShapeExp());

Constructor

IParam

IParam();
Default constructor. Parameters must be initialized with one of the Init*() methods.
Copy constructor and assignment operator are deleted. Parameters cannot be copied.

Initialization Methods

InitBool

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 as a boolean parameter.
name
const char*
required
Parameter name
defaultValue
bool
required
Default value (true/false)
offText
const char*
Display text when value is 0 (default: “off”)
onText
const char*
Display text when value is 1 (default: “on”)
GetParam(kBypass)->InitBool("Bypass", false, "", 0, "", "Disabled", "Enabled");

InitEnum

void InitEnum(const char* name, int defaultValue, int nEnums,
              const char* label = "", int flags = 0, const char* group = "",
              const char* listItems = nullptr, ...);
              
void InitEnum(const char* name, int defaultValue,
              const std::initializer_list<const char*>& listItems,
              int flags = 0, const char* group = "");
Initialize as an enumerated list parameter.
name
const char*
required
Parameter name
defaultValue
int
required
Default value (0-based index)
nEnums
int
required
Number of enum items (variadic version)
listItems
initializer_list or variadic
required
List of item names
// Using initializer list (preferred)
GetParam(kWaveform)->InitEnum("Waveform", 0,
  {"Sine", "Triangle", "Saw", "Square"}, 0, "Oscillator");

// Using variadic arguments
GetParam(kFilter)->InitEnum("Filter Type", 0, 3, "", 0, "Filter",
  "Low Pass", "High Pass", "Band Pass");

InitInt

void InitInt(const char* name, int defaultValue, int minVal, int maxVal,
             const char* label = "", int flags = 0, const char* group = "");
Initialize as an integer parameter.
GetParam(kVoices)->InitInt("Voices", 8, 1, 32, "", 0, "Polyphony");

InitDouble

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 as a double-precision floating point parameter.
name
const char*
required
Parameter name
defaultVal
double
required
Default value
minVal
double
required
Minimum value
maxVal
double
required
Maximum value
step
double
required
Step size (0.01 for 2 decimal places)
label
const char*
Unit suffix (e.g., “dB”, “Hz”, ”%”)
flags
int
Parameter flags (see EFlags)
group
const char*
Parameter group name
shape
const Shape&
Parameter shaping (linear, exponential, power curve)
unit
EParamUnit
AudioUnit unit type
displayFunc
DisplayFunc
Custom display function (lambda)
// Standard gain parameter
GetParam(kGain)->InitDouble("Gain", 0., -70., 12., 0.1, "dB",
                            0, "Levels", IParam::ShapeLinear(), IParam::kUnitDB);

// Frequency with exponential scaling
GetParam(kFreq)->InitDouble("Frequency", 1000., 20., 20000., 0.1, "Hz",
                            0, "Filter", IParam::ShapeExp(), IParam::kUnitFrequency);

Convenience Initialization Methods

InitSeconds

void InitSeconds(const char* name, double defaultVal = 1.,
                 double minVal = 0., double maxVal = 10.,
                 double step = 0.1, int flags = 0,
                 const char* group = "");

InitMilliseconds

void InitMilliseconds(const char* name, double defaultVal = 1.,
                      double minVal = 0., double maxVal = 100.,
                      int flags = 0, const char* group = "");

InitFrequency

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 = "");

InitPitch

void InitPitch(const char* name, int defaultVal = 60,
               int minVal = 0, int maxVal = 128,
               int flags = 0, const char* group = "",
               bool middleCisC4 = false);

InitGain

void InitGain(const char* name, double defaultVal = 0.,
              double minVal = -70., double maxVal = 24.,
              double step = 0.5, int flags = 0,
              const char* group = "");

InitPercentage

void InitPercentage(const char* name, double defaultVal = 0.,
                    double minVal = 0., double maxVal = 100.,
                    int flags = 0, const char* group = "");

InitAngleDegrees

void InitAngleDegrees(const char* name, double defaultVal = 0.,
                      double minVal = 0., double maxVal = 360.,
                      int flags = 0, const char* group = "");

Init

Clone from existing parameter
void Init(const IParam& p, const char* searchStr = "",
          const char* replaceStr = "",
          const char* newGroup = "");

Value Access

Value

double Value() const;
Get the current parameter value (non-normalized, real value).
return
double
Current parameter value (thread-safe atomic read)

Bool

bool Bool() const;
Get parameter value as boolean.
return
bool
true if value >= 0.5, false otherwise

Int

int Int() const;
Get parameter value as integer.

DBToAmp

double DBToAmp() const;
Convert current value from decibels to linear amplitude.
return
double
Linear gain (approximation of 10^(value/20))
// Example: Apply gain parameter
void ProcessBlock(sample** inputs, sample** outputs, int nFrames)
{
  const double gain = GetParam(kGain)->DBToAmp();
  
  for (int s = 0; s < nFrames; s++)
  {
    outputs[0][s] = inputs[0][s] * gain;
  }
}

GetNormalized

double GetNormalized() const;
Get the current value as normalized (0-1).

Value Modification

Set

void Set(double value);
Set the parameter value (real value). Automatically constrains and steps.
value
double
required
New value (will be clamped to min/max and stepped)

SetNormalized

void SetNormalized(double normalizedValue);
Set the parameter from a normalized value (0-1).
normalizedValue
double
required
Normalized value between 0 and 1

SetString

void SetString(const char* str);
Set parameter value from textual representation.

SetToDefault

void SetToDefault();
Reset parameter to its default value.

SetDefault

void SetDefault(double value);
Change the default value and reset to it.

Value Conversion

ToNormalized

inline double ToNormalized(double nonNormalizedValue) const;
Convert a real value to normalized (0-1).

FromNormalized

inline double FromNormalized(double normalizedValue) const;
Convert a normalized value (0-1) to real value.

Constrain

inline double Constrain(double value) const;
Constrain value to min/max range and apply stepping.

ConstrainNormalized

inline double ConstrainNormalized(double normalizedValue) const;
Constrain a normalized value.

StringToValue

double StringToValue(const char* str) const;
Convert textual representation to value.

Display

GetDisplay

void GetDisplay(WDL_String& display, bool withDisplayText = true) const;
void GetDisplay(double value, bool normalized, WDL_String& display,
                bool withDisplayText = true) const;
Get textual display for current or specified value.
display
WDL_String&
required
Output string
value
double
Value to format (if not using current value)
normalized
bool
If true, value is normalized
withDisplayText
bool
Include custom display texts

GetDisplayWithLabel

void GetDisplayWithLabel(WDL_String& display, bool withDisplayText = true) const;
Get display string with unit label appended.

SetDisplayText

void SetDisplayText(double value, const char* str);
Set custom display text for a specific value.
value
double
required
Value to associate with text
str
const char*
required
Display text
// Example: Show "-inf" for -70dB
GetParam(kGain)->SetDisplayText(-70.0, "-inf");

SetDisplayPrecision

void SetDisplayPrecision(int precision);
Set number of decimal places for display.

SetDisplayFunc

void SetDisplayFunc(DisplayFunc func);
Set custom display function.
// Example: Custom display function
GetParam(kRatio)->SetDisplayFunc([](double value, WDL_String& str) {
  str.SetFormatted(32, "%.2f:1", value);
});

DisplayFunc Type

using DisplayFunc = std::function<void(double, WDL_String&)>;

Display Text Methods

NDisplayTexts

int NDisplayTexts() const;
Get number of display texts

GetDisplayText

const char* GetDisplayText(double value) const;
Get display text for a value

GetDisplayTextAtIdx

const char* GetDisplayTextAtIdx(int idx, double* pValue = nullptr) const;
Get display text by index

MapDisplayText

bool MapDisplayText(const char* str, double* pValue) const;
Get value for display text

Property Accessors

GetName

const char* GetName() const;
Returns the parameter name.

GetLabel

const char* GetLabel() const;
Returns the parameter label (unit suffix).

GetGroup

const char* GetGroup() const;
Returns the parameter group.

SetLabel

void SetLabel(const char* label);
Set the parameter label after creation.
If called after the host queries parameters, the host may not update its display.

Type Information

Type

EParamType Type() const;

Unit

EParamUnit Unit() const;

DisplayType

EDisplayType DisplayType() const;

GetFlags

int GetFlags() const;

Range Information

GetDefault

double GetDefault(bool normalized = false) const;

GetMin

double GetMin() const;

GetMax

double GetMax() const;

GetBounds

void GetBounds(double& lo, double& hi) const;

GetRange

double GetRange() const;

GetStep

double GetStep() const;

Flag Queries

GetCanAutomate

bool GetCanAutomate() const;

GetStepped

bool GetStepped() const;

GetNegateDisplay

bool GetNegateDisplay() const;

GetSignDisplay

bool GetSignDisplay() const;

GetMeta

bool GetMeta() const;

Shape Information

EShapeIDs GetShapeID() const;
double GetShapeValue() const;

Debug Utilities

GetJSON

void GetJSON(WDL_String& json, int idx) const;
Get JSON description of the parameter.

PrintDetails

void PrintDetails() const;
Print parameter details to debug console (debug builds only).

Example Usage

enum EParams
{
  kGain,
  kFreq,
  kResonance,
  kFilterType,
  kBypass,
  kNumParams
};

class MyPlugin : public iplug::Plugin
{
public:
  MyPlugin(const iplug::InstanceInfo& info)
  : Plugin(info, MakeConfig(kNumParams, 1))
  {
    // Gain parameter with dB scaling
    GetParam(kGain)->InitGain("Gain", 0., -70., 12., 0.5, 0, "Levels");
    GetParam(kGain)->SetDisplayText(-70.0, "-inf");
    
    // Frequency with exponential scaling
    GetParam(kFreq)->InitFrequency("Cutoff", 1000., 20., 20000., 0.1, 0, "Filter");
    
    // Resonance percentage
    GetParam(kResonance)->InitPercentage("Resonance", 50., 0., 100., 0, "Filter");
    
    // Filter type enum
    GetParam(kFilterType)->InitEnum("Type", 0,
      {"Low Pass", "High Pass", "Band Pass", "Notch"},
      0, "Filter");
    
    // Bypass bool
    GetParam(kBypass)->InitBool("Bypass", false);
  }
  
  void OnParamChange(int paramIdx) override
  {
    switch (paramIdx)
    {
      case kGain:
      {
        double gainDB = GetParam(kGain)->Value();
        double gainLin = GetParam(kGain)->DBToAmp();
        DBGMSG("Gain changed: %.2f dB = %.4f linear\n", gainDB, gainLin);
        break;
      }
      
      case kFreq:
      case kResonance:
      {
        double freq = GetParam(kFreq)->Value();
        double res = GetParam(kResonance)->Value() / 100.0;
        mFilter.SetCutoff(freq, GetSampleRate());
        mFilter.SetResonance(res);
        break;
      }
      
      case kFilterType:
      {
        int type = GetParam(kFilterType)->Int();
        mFilter.SetType(static_cast<FilterType>(type));
        break;
      }
    }
  }
};

See Also