iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
IPlugFaust Class Referenceabstract

IPlugFaust is the base class for hosting a Faust DSP inside an iPlug2 plug-in. More...

#include <IPlugFaust.h>

Inheritance diagram for IPlugFaust:
[legend]

Public Member Functions

 IPlugFaust (const char *name, int nVoices=0, int ctrlTagStart=kDefaultCtrlTagStart)
 
 IPlugFaust (const IPlugFaust &)=delete
 
IPlugFaust & operator= (const IPlugFaust &)=delete
 
virtual void Init ()=0
 Create the DSP. More...
 
void SetMaxChannelCount (int maxNInputs, int maxNOutputs)
 Tell IPlugFaust the maximum number of channels the plug-in provides, if the DSP needs more it will output silence. More...
 
void SetSampleRate (double sampleRate)
 Call this from the plug-in's OnReset(). More...
 
void ProcessMidiMsg (const IMidiMsg &msg)
 Call this from the plug-in's ProcessMidiMsg() More...
 
void ProcessBlock (sample **inputs, sample **outputs, int nFrames)
 Call this from the plug-in's ProcessBlock(). More...
 
bool IsReady () const
 
int NInputs () const
 
int NOutputs () const
 
int GetMaxNInputs () const
 
int GetMaxNOutputs () const
 
int NParams () const
 
int CreateIPlugParameters (IPlugAPIBase *pPlug, int startIdx=0, int endIdx=-1, bool setToDefault=true)
 Initialize the plug-in's parameters startIdx...startIdx+NParams() from the Faust widgets, and link them. More...
 
bool OnParamChange (int plugParamIdx)
 If plugParamIdx is linked to a Faust widget, update its zone from the plug-in's parameter value. More...
 
void SetParameterValueNormalised (int faustParamIdx, double normalizedValue)
 Set a Faust widget's value via its parameter index (0...NParams()-1) More...
 
void SetParameterValue (int faustParamIdx, double value)
 Set a Faust widget's value via its parameter index (0...NParams()-1) More...
 
void SetParameterValue (const char *labelOrPath, double value)
 Set a Faust widget's value via its label or full path (e.g. More...
 
void SyncFaustParams ()
 Apply the values of all the parameters to the DSP (e.g. More...
 
int GetFaustParamIdxForZone (FAUSTFLOAT *zone) const
 
int GetPlugParamIdx (int faustParamIdx) const
 
const FaustUIItem & GetUIRoot () const
 
const char * GetJSON () const
 
void BuildUI (UI *pUI)
 Calls buildUserInterface() and metadata() on the DSP, to build a Faust UI. More...
 
void openTabBox (const char *label) override
 
void openHorizontalBox (const char *label) override
 
void openVerticalBox (const char *label) override
 
void closeBox () override
 
void addButton (const char *label, FAUSTFLOAT *zone) override
 
void addCheckButton (const char *label, FAUSTFLOAT *zone) override
 
void addVerticalSlider (const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) override
 
void addHorizontalSlider (const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) override
 
void addNumEntry (const char *label, FAUSTFLOAT *zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) override
 
void addHorizontalBargraph (const char *label, FAUSTFLOAT *zone, FAUSTFLOAT min, FAUSTFLOAT max) override
 
void addVerticalBargraph (const char *label, FAUSTFLOAT *zone, FAUSTFLOAT min, FAUSTFLOAT max) override
 
void addSoundfile (const char *label, const char *filename, Soundfile **sfZone) override
 
void declare (FAUSTFLOAT *zone, const char *key, const char *value) override
 

Static Public Attributes

static constexpr int kDefaultCtrlTagStart = 1000
 

Protected Member Functions

void SetDSP (::dsp *pMonoDSP)
 Takes ownership of a newly created DSP, wraps it for polyphony if required, (re)builds the parameters and UI description and swaps it in. More...
 
void ReleaseDSP ()
 Destroys the DSP, waiting for a block that is being processed to finish first. More...
 
void InformHostIfParamsChanged ()
 If SetDSP() re-initialized the linked plug-in parameters (i.e. More...
 

Protected Attributes

WDL_String mName
 

Detailed Description

IPlugFaust is the base class for hosting a Faust DSP inside an iPlug2 plug-in.

It maps the Faust DSP's widgets to IPlug parameters, routes MIDI to the DSP (including polyphony via the "[nvoices:N]" option), sends bargraph values to the editor and keeps a description of the Faust UI that UI builders can use.

There are two implementations which share this interface:

Definition at line 105 of file IPlugFaust.h.

Constructor & Destructor Documentation

◆ IPlugFaust()

IPlugFaust::IPlugFaust ( const char *  name,
int  nVoices = 0,
int  ctrlTagStart = kDefaultCtrlTagStart 
)
Parameters
nameA name for the DSP, used for logging
nVoicesNumber of polyphonic voices to use if the DSP doesn't declare "[nvoices:N]" in its options metadata. Values < 2 mean monophonic.
ctrlTagStartThe first control tag used for bargraphs. Bargraphs are given consecutive tags in the order they are declared.

Definition at line 44 of file IPlugFaust.cpp.

◆ ~IPlugFaust()

IPlugFaust::~IPlugFaust ( )
virtual

Definition at line 51 of file IPlugFaust.cpp.

Member Function Documentation

◆ addButton()

void IPlugFaust::addButton ( const char *  label,
FAUSTFLOAT *  zone 
)
override

Definition at line 669 of file IPlugFaust.cpp.

◆ addCheckButton()

void IPlugFaust::addCheckButton ( const char *  label,
FAUSTFLOAT *  zone 
)
override

Definition at line 675 of file IPlugFaust.cpp.

◆ addHorizontalBargraph()

void IPlugFaust::addHorizontalBargraph ( const char *  label,
FAUSTFLOAT *  zone,
FAUSTFLOAT  min,
FAUSTFLOAT  max 
)
override

Definition at line 723 of file IPlugFaust.cpp.

◆ addHorizontalSlider()

void IPlugFaust::addHorizontalSlider ( const char *  label,
FAUSTFLOAT *  zone,
FAUSTFLOAT  init,
FAUSTFLOAT  min,
FAUSTFLOAT  max,
FAUSTFLOAT  step 
)
override

Definition at line 688 of file IPlugFaust.cpp.

◆ addNumEntry()

void IPlugFaust::addNumEntry ( const char *  label,
FAUSTFLOAT *  zone,
FAUSTFLOAT  init,
FAUSTFLOAT  min,
FAUSTFLOAT  max,
FAUSTFLOAT  step 
)
override

Definition at line 695 of file IPlugFaust.cpp.

◆ addSoundfile()

void IPlugFaust::addSoundfile ( const char *  label,
const char *  filename,
Soundfile **  sfZone 
)
override

Definition at line 733 of file IPlugFaust.cpp.

◆ addVerticalBargraph()

void IPlugFaust::addVerticalBargraph ( const char *  label,
FAUSTFLOAT *  zone,
FAUSTFLOAT  min,
FAUSTFLOAT  max 
)
override

Definition at line 728 of file IPlugFaust.cpp.

◆ addVerticalSlider()

void IPlugFaust::addVerticalSlider ( const char *  label,
FAUSTFLOAT *  zone,
FAUSTFLOAT  init,
FAUSTFLOAT  min,
FAUSTFLOAT  max,
FAUSTFLOAT  step 
)
override

Definition at line 681 of file IPlugFaust.cpp.

◆ BuildUI()

void IPlugFaust::BuildUI ( UI *  pUI)

Calls buildUserInterface() and metadata() on the DSP, to build a Faust UI.

Only call this on the main thread.

Definition at line 486 of file IPlugFaust.cpp.

◆ closeBox()

void IPlugFaust::closeBox ( )
override

Definition at line 554 of file IPlugFaust.cpp.

◆ CreateIPlugParameters()

int IPlugFaust::CreateIPlugParameters ( IPlugAPIBase *  pPlug,
int  startIdx = 0,
int  endIdx = -1,
bool  setToDefault = true 
)

Initialize the plug-in's parameters startIdx...startIdx+NParams() from the Faust widgets, and link them.

The plug-in must have enough parameters, so for a JIT compiled DSP that may change, allocate some spare ones. After linking, the IPlug parameter values are applied to the DSP in SetParameterValueNormalised().

Parameters
pPlugThe plug-in
startIdxThe index of the first plug-in parameter to use
endIdxThe index after the last Faust parameter to link, or -1 for all of them
setToDefaultIf true the parameters are set to their default values, otherwise the current normalized values are kept
Returns
startIdx, or -1 if the DSP has no parameters

Definition at line 139 of file IPlugFaust.cpp.

References IParam::GetNormalized(), IParam::Init(), NParams(), IParam::SetNormalized(), IParam::SetToDefault(), and SyncFaustParams().

◆ declare()

void IPlugFaust::declare ( FAUSTFLOAT *  zone,
const char *  key,
const char *  value 
)
override

Definition at line 740 of file IPlugFaust.cpp.

◆ GetFaustParamIdxForZone()

int IPlugFaust::GetFaustParamIdxForZone ( FAUSTFLOAT *  zone) const
Returns
The Faust parameter index for a zone, or kNoParameter

Definition at line 254 of file IPlugFaust.cpp.

References NParams().

◆ GetJSON()

const char * IPlugFaust::GetJSON ( ) const
inline
Returns
A JSON description of the DSP, as generated by Faust's JSONUI

Definition at line 195 of file IPlugFaust.h.

◆ GetMaxNInputs()

int IPlugFaust::GetMaxNInputs ( ) const
inline

Definition at line 142 of file IPlugFaust.h.

◆ GetMaxNOutputs()

int IPlugFaust::GetMaxNOutputs ( ) const
inline

Definition at line 143 of file IPlugFaust.h.

◆ GetPlugParamIdx()

int IPlugFaust::GetPlugParamIdx ( int  faustParamIdx) const
Returns
The IPlug parameter index linked to a Faust parameter, or kNoParameter if not linked

Definition at line 265 of file IPlugFaust.cpp.

Referenced by IGraphicsFaustUI::CreateControl(), SetDSP(), and SyncFaustParams().

◆ GetUIRoot()

const FaustUIItem & IPlugFaust::GetUIRoot ( ) const
inline
Returns
The description of the Faust UI (the root is the top-level group), which is rebuilt every time the DSP changes

Definition at line 192 of file IPlugFaust.h.

Referenced by IGraphicsFaustUI::CreateControl().

◆ InformHostIfParamsChanged()

void IPlugFaust::InformHostIfParamsChanged ( )
protected

If SetDSP() re-initialized the linked plug-in parameters (i.e.

the DSP was replaced), tell the host to re-read the parameter details. Call this on the main thread, after the plug-in has finished updating its parameters

Definition at line 356 of file IPlugFaust.cpp.

References IPluginBase::InformHostOfParameterDetailsChange().

◆ Init()

virtual void IPlugFaust::Init ( )
pure virtual

Create the DSP.

Call this once after construction (and after SetMaxChannelCount)

Implemented in FaustGen.

◆ IsReady()

bool IPlugFaust::IsReady ( ) const
inline
Returns
true if a DSP has been created and can be processed (it fits the channel count and doesn't use soundfiles)

Definition at line 138 of file IPlugFaust.h.

◆ NInputs()

int IPlugFaust::NInputs ( ) const
inline

Definition at line 140 of file IPlugFaust.h.

◆ NOutputs()

int IPlugFaust::NOutputs ( ) const
inline

Definition at line 141 of file IPlugFaust.h.

◆ NParams()

int IPlugFaust::NParams ( ) const
inline
Returns
The number of Faust widgets that are mapped to parameters (buttons, checkboxes, sliders and numerical entries)

Definition at line 148 of file IPlugFaust.h.

Referenced by IGraphicsFaustUI::CreateControl(), CreateIPlugParameters(), GetFaustParamIdxForZone(), SetDSP(), SetParameterValue(), SetParameterValueNormalised(), and SyncFaustParams().

◆ OnParamChange()

bool IPlugFaust::OnParamChange ( int  plugParamIdx)

If plugParamIdx is linked to a Faust widget, update its zone from the plug-in's parameter value.

Call this from the plug-in's OnParamChange().

Returns
true if the parameter belongs to this DSP

Definition at line 178 of file IPlugFaust.cpp.

◆ openHorizontalBox()

void IPlugFaust::openHorizontalBox ( const char *  label)
override

Definition at line 544 of file IPlugFaust.cpp.

◆ openTabBox()

void IPlugFaust::openTabBox ( const char *  label)
override

Definition at line 539 of file IPlugFaust.cpp.

◆ openVerticalBox()

void IPlugFaust::openVerticalBox ( const char *  label)
override

Definition at line 549 of file IPlugFaust.cpp.

◆ ProcessBlock()

void IPlugFaust::ProcessBlock ( sample **  inputs,
sample **  outputs,
int  nFrames 
)

Call this from the plug-in's ProcessBlock().

Unused output channels are cleared.

Definition at line 115 of file IPlugFaust.cpp.

◆ ProcessMidiMsg()

void IPlugFaust::ProcessMidiMsg ( const IMidiMsg &  msg)

Call this from the plug-in's ProcessMidiMsg()

Definition at line 105 of file IPlugFaust.cpp.

◆ ReleaseDSP()

void IPlugFaust::ReleaseDSP ( )
protected

Destroys the DSP, waiting for a block that is being processed to finish first.

Call it on the main thread. Subclasses that own something the DSP depends on (e.g. the factory that created it) must call this in their destructor

Definition at line 56 of file IPlugFaust.cpp.

◆ SetDSP()

void IPlugFaust::SetDSP ( ::dsp *  pMonoDSP)
protected

Takes ownership of a newly created DSP, wraps it for polyphony if required, (re)builds the parameters and UI description and swaps it in.

Everything is prepared first. The swap itself only exchanges pointers, while the audio thread outputs silence (at most one block), so it is safe to call while processing. Call it on the main thread.

Parameters
pMonoDSPThe new DSP instance

Definition at line 367 of file IPlugFaust.cpp.

References Timer::Create(), FAUST_UI_INTERVAL, GetPlugParamIdx(), NParams(), and SyncFaustParams().

◆ SetMaxChannelCount()

void IPlugFaust::SetMaxChannelCount ( int  maxNInputs,
int  maxNOutputs 
)

Tell IPlugFaust the maximum number of channels the plug-in provides, if the DSP needs more it will output silence.

Parameters
maxNInputsMaximum number of input channels
maxNOutputsMaximum number of output channels

Definition at line 85 of file IPlugFaust.cpp.

◆ SetParameterValue() [1/2]

void IPlugFaust::SetParameterValue ( const char *  labelOrPath,
double  value 
)

Set a Faust widget's value via its label or full path (e.g.

"freq" or "/synth/freq"). This doesn't update linked IPlug parameters. It compares strings to find the widget, so it is not meant for the audio thread: use the index overload there.

Parameters
labelOrPathThe label or full path of the widget
valueThe non-normalized value (for menus and radio buttons, the index of the item)

Definition at line 214 of file IPlugFaust.cpp.

References NParams().

◆ SetParameterValue() [2/2]

void IPlugFaust::SetParameterValue ( int  faustParamIdx,
double  value 
)

Set a Faust widget's value via its parameter index (0...NParams()-1)

Parameters
faustParamIdxThe index of the Faust parameter
valueThe non-normalized value (for menus and radio buttons, the index of the item)

Definition at line 209 of file IPlugFaust.cpp.

◆ SetParameterValueNormalised()

void IPlugFaust::SetParameterValueNormalised ( int  faustParamIdx,
double  normalizedValue 
)

Set a Faust widget's value via its parameter index (0...NParams()-1)

Parameters
faustParamIdxThe index of the Faust parameter
normalizedValueThe normalized [0, 1] value

Definition at line 192 of file IPlugFaust.cpp.

References NParams().

◆ SetSampleRate()

void IPlugFaust::SetSampleRate ( double  sampleRate)

Call this from the plug-in's OnReset().

It re-initializes the DSP, waiting for a block that is being processed to finish first, so don't call it from ProcessBlock()

Definition at line 91 of file IPlugFaust.cpp.

References SyncFaustParams().

◆ SyncFaustParams()

void IPlugFaust::SyncFaustParams ( )

Apply the values of all the parameters to the DSP (e.g.

after dsp::init() has reset the zones)

Definition at line 235 of file IPlugFaust.cpp.

References GetPlugParamIdx(), and NParams().

Referenced by CreateIPlugParameters(), SetDSP(), and SetSampleRate().

Member Data Documentation

◆ kDefaultCtrlTagStart

constexpr int IPlugFaust::kDefaultCtrlTagStart = 1000
staticconstexpr

Definition at line 108 of file IPlugFaust.h.

◆ mName

WDL_String IPlugFaust::mName
protected

Definition at line 231 of file IPlugFaust.h.


The documentation for this class was generated from the following files: