22 #ifdef SAMPLE_TYPE_FLOAT
23 #define FAUSTFLOAT float
25 #define FAUSTFLOAT double
37#include "faust/dsp/dsp.h"
38#include "faust/dsp/poly-dsp.h"
39#include "faust/gui/UI.h"
40#include "faust/gui/meta.h"
41#include "faust/gui/MetaDataUI.h"
42#include "faust/gui/MidiUI.h"
43#include "faust/midi/iplug2-midi.h"
49static_assert(
sizeof(FAUSTFLOAT) ==
sizeof(iplug::sample),
"FAUSTFLOAT must be the same type as iplug::sample");
53#ifndef FAUST_SHARE_PATH
54 #define FAUST_SHARE_PATH ""
58#ifndef FAUST_UI_INTERVAL
59 #define FAUST_UI_INTERVAL 30
69 enum class EType { TabBox, HBox, VBox, Button, CheckButton, HSlider, VSlider, NumEntry, HBargraph, VBargraph, Soundfile };
71 EType type = EType::VBox;
74 FAUSTFLOAT* zone =
nullptr;
75 double init = 0., min = 0., max = 1., step = 0.;
77 int paramIdx = kNoParameter;
84 bool numerical =
false;
89 std::vector<std::pair<std::string, double>> options;
91 std::vector<FaustUIItem> children;
93 bool IsGroup()
const {
return type == EType::TabBox || type == EType::HBox || type == EType::VBox; }
94 bool IsBargraph()
const {
return type == EType::HBargraph || type == EType::VBargraph; }
108 static constexpr int kDefaultCtrlTagStart = 1000;
113 IPlugFaust(
const char* name,
int nVoices = 0,
int ctrlTagStart = kDefaultCtrlTagStart);
135 void ProcessBlock(sample** inputs, sample** outputs,
int nFrames);
138 bool IsReady()
const {
return mDSP !=
nullptr && !mChannelCountError && !mHasSoundfile; }
140 int NInputs()
const {
return mDSP ? mDSP->getNumInputs() : 0; }
141 int NOutputs()
const {
return mDSP ? mDSP->getNumOutputs() : 0; }
142 int GetMaxNInputs()
const {
return mMaxNInputs; }
143 int GetMaxNOutputs()
const {
return mMaxNOutputs; }
145#pragma mark - Parameters
148 int NParams()
const {
return static_cast<int>(mParams.size()); }
195 const char*
GetJSON()
const {
return mJSON.c_str(); }
200#pragma mark - Faust UI interface (used internally)
202 void openTabBox(
const char* label)
override;
203 void openHorizontalBox(
const char* label)
override;
204 void openVerticalBox(
const char* label)
override;
205 void closeBox()
override;
206 void addButton(
const char* label, FAUSTFLOAT* zone)
override;
207 void addCheckButton(
const char* label, FAUSTFLOAT* zone)
override;
208 void addVerticalSlider(
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
override;
209 void addHorizontalSlider(
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
override;
210 void addNumEntry(
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
override;
211 void addHorizontalBargraph(
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
override;
212 void addVerticalBargraph(
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
override;
213 void addSoundfile(
const char* label,
const char* filename, Soundfile** sfZone)
override;
214 void declare(FAUSTFLOAT* zone,
const char* key,
const char* value)
override;
221 void SetDSP(::dsp* pMonoDSP);
236 std::unique_ptr<IParam> param = std::make_unique<IParam>();
237 FAUSTFLOAT* zone =
nullptr;
238 std::vector<double> enumValues;
244 FAUSTFLOAT* zone =
nullptr;
247 int ctrlTag = kNoTag;
249 double lastSentValue = -1.;
262 mNUsers.fetch_add(1, std::memory_order_seq_cst);
264 if (mReplacing.load(std::memory_order_seq_cst))
266 mNUsers.fetch_sub(1, std::memory_order_release);
273 void Exit() { mNUsers.fetch_sub(1, std::memory_order_release); }
277 mReplaceMutex.lock();
278 mReplacing.store(
true, std::memory_order_seq_cst);
280 while (mNUsers.load(std::memory_order_seq_cst) > 0)
281 std::this_thread::yield();
286 mReplacing.store(
false, std::memory_order_release);
287 mReplaceMutex.unlock();
291 std::atomic<int> mNUsers {0};
292 std::atomic<bool> mReplacing {
false};
293 std::mutex mReplaceMutex;
300 ScopedDSPUser(DSPGuard& guard) : mGuard(guard), mEntered(guard.TryEnter()) {}
301 ~ScopedDSPUser() {
if (mEntered) mGuard.Exit(); }
302 bool IsEntered()
const {
return mEntered; }
309 class ScopedDSPReplace
312 ScopedDSPReplace(DSPGuard& guard) : mGuard(guard) { mGuard.BeginReplace(); }
313 ~ScopedDSPReplace() { mGuard.EndReplace(); }
318 void BuildDescription(::dsp* pDSP);
319 void OpenGroup(FaustUIItem::EType type,
const char* label);
320 FaustUIItem& AddItem(FaustUIItem::EType type,
const char* label, FAUSTFLOAT* zone);
321 void AddBargraph(FaustUIItem::EType type,
const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max);
324 void WriteZone(
int faustParamIdx,
double value);
325 void WriteZoneUnguarded(
int faustParamIdx,
double value);
326 void OnUITimer(
Timer& timer);
330 int mMaxNInputs = -1;
331 int mMaxNOutputs = -1;
332 bool mChannelCountError =
false;
333 bool mHasSoundfile =
false;
334 double mSampleRate = 0.;
338 std::unique_ptr<iplug2_midi_handler> mMidiHandler;
339 std::unique_ptr<MidiUI> mMidiUI;
340 std::unique_ptr<::dsp> mDSP;
341 std::vector<Param> mParams;
342 std::vector<Bargraph> mBargraphs;
347 std::vector<Param> mNewParams;
348 std::vector<Bargraph> mNewBargraphs;
350 bool mNewHasSoundfile =
false;
351 std::vector<FaustUIItem*> mGroupStack;
355 std::atomic<int> mPlugParamStartIdx {-1};
356 std::atomic<int> mPlugParamEndIdx {-1};
357 bool mParamsChanged =
false;
359 std::unique_ptr<Timer> mUITimer;
IPlug Constant definitions, Types, magic numbers.
Platform timer primitives.
EParamType
Defines types or parameter.
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
IPlugFaust is the base class for hosting a Faust DSP inside an iPlug2 plug-in.
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,...
void InformHostIfParamsChanged()
If SetDSP() re-initialized the linked plug-in parameters (i.e.
int GetPlugParamIdx(int faustParamIdx) const
void ProcessMidiMsg(const IMidiMsg &msg)
Call this from the plug-in's ProcessMidiMsg()
void ReleaseDSP()
Destroys the DSP, waiting for a block that is being processed to finish first.
void SetSampleRate(double sampleRate)
Call this from the plug-in's OnReset().
void BuildUI(UI *pUI)
Calls buildUserInterface() and metadata() on the DSP, to build a Faust UI.
const char * GetJSON() const
int GetFaustParamIdxForZone(FAUSTFLOAT *zone) const
void SetParameterValue(int faustParamIdx, double value)
Set a Faust widget's value via its parameter index (0...NParams()-1)
const FaustUIItem & GetUIRoot() const
void ProcessBlock(sample **inputs, sample **outputs, int nFrames)
Call this from the plug-in's ProcessBlock().
virtual void Init()=0
Create the DSP.
void SetParameterValueNormalised(int faustParamIdx, double normalizedValue)
Set a Faust widget's value via its parameter index (0...NParams()-1)
bool OnParamChange(int plugParamIdx)
If plugParamIdx is linked to a Faust widget, update its zone from the plug-in's parameter value.
void SetMaxChannelCount(int maxNInputs, int maxNOutputs)
Tell IPlugFaust the maximum number of channels the plug-in provides, if the DSP needs more it will ou...
void SetDSP(::dsp *pMonoDSP)
Takes ownership of a newly created DSP, wraps it for polyphony if required, (re)builds the parameters...
void SyncFaustParams()
Apply the values of all the parameters to the DSP (e.g.
A node in the description of a Faust DSP's user interface, as declared by its buildUserInterface() me...
Encapsulates a MIDI message and provides helper functions.