iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
Public Member Functions | List of all members
FaustGen Class Reference

FaustGen compiles Faust code at runtime using the libfaust interpreter backend, so that the DSP can be edited while the plug-in is running. More...

#include <IPlugFaustGen.h>

Inheritance diagram for FaustGen:
[legend]

Public Member Functions

 FaustGen (const char *name, const char *inputDSPFile=nullptr, int nVoices=0, const char *libraryPath=FAUST_SHARE_PATH)
 
 FaustGen (const FaustGen &)=delete
 
FaustGen & operator= (const FaustGen &)=delete
 
void Init () override
 Compile the DSP. More...
 
bool LoadFile (const char *path)
 Load and compile a .dsp file, replacing the current DSP if compilation succeeds. More...
 
bool SetSourceCode (const char *sourceCode)
 Compile Faust source code, replacing the current DSP if compilation succeeds. More...
 
void AddLibraryPath (const char *path)
 Add a path that is searched for imported .lib/.dsp files. More...
 
void SetBundleResourcePath (const char *resourcesPath)
 Use the .dsp file and Faust libraries that iplug_add_faust(... BUNDLE) copies into the bundle's resources (FAUST_BUNDLED is defined). More...
 
void AddCompileOption (const char *option)
 Add a compiler option such as "-vec" (see faust –help) More...
 
void SetAutoRecompile (bool enable)
 Watch the .dsp file and recompile it when it changes. More...
 
void SetOnCompileFunc (std::function< void(bool success)> func)
 Set a function that is called on the main thread after a (re)compilation. More...
 
const char * GetErrorMessage () const
 
const char * GetSourceCode () const
 
const char * GetDSPFile () const
 
- Public Member Functions inherited from IPlugFaust
 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
 

Additional Inherited Members

- Static Public Attributes inherited from IPlugFaust
static constexpr int kDefaultCtrlTagStart = 1000
 
- Protected Member Functions inherited from IPlugFaust
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 inherited from IPlugFaust
WDL_String mName
 

Detailed Description

FaustGen compiles Faust code at runtime using the libfaust interpreter backend, so that the DSP can be edited while the plug-in is running.

The interpreter is much slower than compiled code, so use it for development and switch to the statically compiled DSP (FAUST_COMPILED) for release builds. All methods except ProcessBlock() and ProcessMidiMsg() must be called on the main thread.

Definition at line 54 of file IPlugFaustGen.h.

Constructor & Destructor Documentation

◆ FaustGen()

FaustGen::FaustGen ( const char *  name,
const char *  inputDSPFile = nullptr,
int  nVoices = 0,
const char *  libraryPath = FAUST_SHARE_PATH 
)
Parameters
nameA name for the DSP
inputDSPFileThe absolute path of a .dsp file to load. Its folder is added to the library search paths.
nVoicesNumber of polyphonic voices, if the DSP doesn't declare "[nvoices:N]" in its options. Values < 2 mean monophonic.
libraryPathThe path to the Faust standard libraries (the share/faust folder of a Faust installation)

Definition at line 69 of file IPlugFaustGen.cpp.

References AddLibraryPath().

◆ ~FaustGen()

FaustGen::~FaustGen ( )

Definition at line 87 of file IPlugFaustGen.cpp.

Member Function Documentation

◆ AddCompileOption()

void FaustGen::AddCompileOption ( const char *  option)

Add a compiler option such as "-vec" (see faust –help)

Definition at line 198 of file IPlugFaustGen.cpp.

◆ AddLibraryPath()

void FaustGen::AddLibraryPath ( const char *  path)

Add a path that is searched for imported .lib/.dsp files.

Definition at line 165 of file IPlugFaustGen.cpp.

Referenced by FaustGen(), and LoadFile().

◆ GetDSPFile()

const char * FaustGen::GetDSPFile ( ) const
inline

Definition at line 104 of file IPlugFaustGen.h.

◆ GetErrorMessage()

const char * FaustGen::GetErrorMessage ( ) const
inline
Returns
The error message of the last failed compilation, or an empty string

Definition at line 101 of file IPlugFaustGen.h.

◆ GetSourceCode()

const char * FaustGen::GetSourceCode ( ) const
inline

Definition at line 103 of file IPlugFaustGen.h.

◆ Init()

void FaustGen::Init ( )
overridevirtual

Compile the DSP.

If no file was given, or it fails to compile, a pass-through/silent DSP that matches the max channel count is created. Call SetMaxChannelCount() first.

Implements IPlugFaust.

Definition at line 101 of file IPlugFaustGen.cpp.

◆ LoadFile()

bool FaustGen::LoadFile ( const char *  path)

Load and compile a .dsp file, replacing the current DSP if compilation succeeds.

Returns
true on success

Definition at line 128 of file IPlugFaustGen.cpp.

References AddLibraryPath().

◆ SetAutoRecompile()

void FaustGen::SetAutoRecompile ( bool  enable)

Watch the .dsp file and recompile it when it changes.

Definition at line 204 of file IPlugFaustGen.cpp.

References Timer::Create().

◆ SetBundleResourcePath()

void FaustGen::SetBundleResourcePath ( const char *  resourcesPath)

Use the .dsp file and Faust libraries that iplug_add_faust(... BUNDLE) copies into the bundle's resources (FAUST_BUNDLED is defined).

The bundled libraries are searched first. The bundled .dsp file is used if the original one doesn't exist, i.e. on another computer, so that during development the original file is still used and can be edited. Call this before Init().

Parameters
resourcesPathThe bundle's resources folder, from BundleResourcePath()

Definition at line 171 of file IPlugFaustGen.cpp.

◆ SetOnCompileFunc()

void FaustGen::SetOnCompileFunc ( std::function< void(bool success)>  func)
inline

Set a function that is called on the main thread after a (re)compilation.

When it is called after a successful recompilation, the parameters have already been updated, but the plug-in's UI should be rebuilt e.g. with IGraphicsFaustUI. After it returns, the host is told to re-read the parameter details (IPluginBase::InformHostOfParameterDetailsChange()), so any other changes the plug-in makes to its parameters in this function are included

Definition at line 98 of file IPlugFaustGen.h.

◆ SetSourceCode()

bool FaustGen::SetSourceCode ( const char *  sourceCode)

Compile Faust source code, replacing the current DSP if compilation succeeds.

Returns
true on success

Definition at line 148 of file IPlugFaustGen.cpp.


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