iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IPlugFaust.cpp
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
16#include "IPlugFaust.h"
17
18#include <cstring>
19#include <map>
20
21#include "faust/gui/GUI.h"
22#include "faust/gui/JSONUI.h"
23
24// Static members of Faust's GUI base class (used by MidiUI). If you combine IPlugFaust with other Faust architecture code that defines these, define FAUST_GUI_STATICS_DEFINED
25#ifndef FAUST_GUI_STATICS_DEFINED
26std::list<GUI*> GUI::fGuiList;
27ztimedmap GUI::gTimedZoneMap;
28#endif
29
30using namespace iplug;
31
32namespace
33{
34 // Faust names anonymous groups "0x00"
35 std::string CleanLabel(const char* label)
36 {
37 if (!label || strcmp(label, "0x00") == 0)
38 return "";
39
40 return label;
41 }
42}
43
44IPlugFaust::IPlugFaust(const char* name, int nVoices, int ctrlTagStart)
45: mName(name)
46, mNVoices(nVoices)
47, mCtrlTagStart(ctrlTagStart)
48{
49}
50
51IPlugFaust::~IPlugFaust()
52{
53 ReleaseDSP();
54}
55
57{
58 if (mUITimer)
59 {
60 mUITimer->Stop();
61 mUITimer = nullptr;
62 }
63
64 std::unique_ptr<MidiUI> pMidiUI;
65 std::unique_ptr<::dsp> pDSP;
66 std::unique_ptr<iplug2_midi_handler> pMidiHandler;
67
68 std::vector<Param> params;
69
70 {
71 ScopedDSPReplace replace(mDSPGuard);
72 std::swap(mMidiUI, pMidiUI);
73 std::swap(mDSP, pDSP);
74 std::swap(mMidiHandler, pMidiHandler);
75 std::swap(mParams, params);
76 mBargraphs.clear();
77 }
78
79 // A polyphonic DSP unregisters itself from the MidiUI, which unregisters itself from the MIDI handler
80 pDSP = nullptr;
81 pMidiUI = nullptr;
82 pMidiHandler = nullptr;
83}
84
85void IPlugFaust::SetMaxChannelCount(int maxNInputs, int maxNOutputs)
86{
87 mMaxNInputs = maxNInputs;
88 mMaxNOutputs = maxNOutputs;
89}
90
91void IPlugFaust::SetSampleRate(double sampleRate)
92{
93 mSampleRate = sampleRate;
94
95 {
96 ScopedDSPReplace replace(mDSPGuard);
97
98 if (mDSP)
99 mDSP->init(static_cast<int>(sampleRate)); // NOTE: this resets the zones to their default values
100 }
101
103}
104
106{
107 // Messages are only dropped while the DSP is being replaced. The new DSP has no sounding voices, so a dropped note-off can't leave a stuck note.
108 // A note-on that arrives during the swap is lost
109 ScopedDSPUser user(mDSPGuard);
110
111 if (user.IsEntered() && mMidiHandler)
112 mMidiHandler->decodeMessage(msg);
113}
114
115void IPlugFaust::ProcessBlock(sample** inputs, sample** outputs, int nFrames)
116{
117 // If the DSP is being replaced on the main thread (recompilation), output silence for this block. This never blocks
118 ScopedDSPUser user(mDSPGuard);
119
120 int nOutputsProcessed = 0;
121
122 if (user.IsEntered() && mDSP && !mChannelCountError && !mHasSoundfile)
123 {
124 mDSP->compute(nFrames, inputs, outputs);
125 nOutputsProcessed = mDSP->getNumOutputs();
126 }
127
128 if (mMaxNOutputs > -1)
129 {
130 for (int c = nOutputsProcessed; c < mMaxNOutputs; c++)
131 {
132 memset(outputs[c], 0, nFrames * sizeof(sample));
133 }
134 }
135}
136
137#pragma mark - Parameters
138
139int IPlugFaust::CreateIPlugParameters(IPlugAPIBase* pPlug, int startIdx, int endIdx, bool setToDefault)
140{
141 assert(pPlug != nullptr);
142
143 mPlug = pPlug;
144
145 // The mapping is recorded even if there are no parameters yet, so that a recompiled DSP that has some can be linked
146 mPlugParamStartIdx = startIdx;
147 mPlugParamEndIdx = (endIdx < 0 || endIdx > NParams()) ? NParams() : endIdx;
148
149 if (NParams() == 0)
150 return -1;
151
152 for (int p = 0; p < mPlugParamEndIdx; p++)
153 {
154 const int plugParamIdx = mPlugParamStartIdx + p;
155
156 if (plugParamIdx >= pPlug->NParams())
157 {
158 DBGMSG("IPlugFaust-%s: the plug-in doesn't have enough parameters for the Faust DSP (needs %i)\n", mName.Get(), mPlugParamStartIdx + mPlugParamEndIdx);
159 mPlugParamEndIdx = p;
160 break;
161 }
162
163 IParam* pPlugParam = pPlug->GetParam(plugParamIdx);
164 const double currentValueNormalized = pPlugParam->GetNormalized();
165 pPlugParam->Init(*mParams[p].param);
166
167 if (setToDefault)
168 pPlugParam->SetToDefault();
169 else
170 pPlugParam->SetNormalized(currentValueNormalized);
171 }
172
174
175 return mPlugParamStartIdx;
176}
177
178bool IPlugFaust::OnParamChange(int plugParamIdx)
179{
180 if (!mPlug || mPlugParamStartIdx < 0)
181 return false;
182
183 const int faustParamIdx = plugParamIdx - mPlugParamStartIdx;
184
185 if (faustParamIdx < 0 || faustParamIdx >= mPlugParamEndIdx)
186 return false;
187
188 WriteZone(faustParamIdx, mPlug->GetParam(plugParamIdx)->Value());
189 return true;
190}
191
192void IPlugFaust::SetParameterValueNormalised(int faustParamIdx, double normalizedValue)
193{
194 // mParams is replaced with the DSP, so it is only used while the DSP can't be replaced
195 ScopedDSPUser user(mDSPGuard);
196
197 if (!user.IsEntered())
198 return;
199
200 if (faustParamIdx < 0 || faustParamIdx >= NParams())
201 {
202 DBGMSG("IPlugFaust-%s: no parameter %i\n", mName.Get(), faustParamIdx);
203 return;
204 }
205
206 WriteZoneUnguarded(faustParamIdx, mParams[faustParamIdx].param->FromNormalized(normalizedValue));
207}
208
209void IPlugFaust::SetParameterValue(int faustParamIdx, double value)
210{
211 WriteZone(faustParamIdx, value);
212}
213
214void IPlugFaust::SetParameterValue(const char* labelOrPath, double value)
215{
216 ScopedDSPUser user(mDSPGuard);
217
218 if (!user.IsEntered())
219 return;
220
221 for (int i = 0; i < NParams(); i++)
222 {
223 const Param& p = mParams[i];
224
225 if (p.path == labelOrPath || strcmp(p.param->GetName(), labelOrPath) == 0)
226 {
227 WriteZoneUnguarded(i, value); // like the index overload, so for menus and radio buttons the value is the enum index
228 return;
229 }
230 }
231
232 DBGMSG("IPlugFaust-%s: no parameter named %s\n", mName.Get(), labelOrPath);
233}
234
236{
237 ScopedDSPUser user(mDSPGuard);
238
239 // If the DSP is being replaced, the thread replacing it syncs the parameters afterwards
240 if (!user.IsEntered())
241 return;
242
243 for (int p = 0; p < NParams(); p++)
244 {
245 const int plugParamIdx = GetPlugParamIdx(p);
246
247 if (plugParamIdx > kNoParameter)
248 WriteZoneUnguarded(p, mPlug->GetParam(plugParamIdx)->Value());
249 else
250 WriteZoneUnguarded(p, mParams[p].param->Value());
251 }
252}
253
254int IPlugFaust::GetFaustParamIdxForZone(FAUSTFLOAT* zone) const
255{
256 for (int p = 0; p < NParams(); p++)
257 {
258 if (mParams[p].zone == zone)
259 return p;
260 }
261
262 return kNoParameter;
263}
264
265int IPlugFaust::GetPlugParamIdx(int faustParamIdx) const
266{
267 if (!mPlug || mPlugParamStartIdx < 0 || faustParamIdx < 0 || faustParamIdx >= mPlugParamEndIdx)
268 return kNoParameter;
269
270 return mPlugParamStartIdx + faustParamIdx;
271}
272
273void IPlugFaust::WriteZone(int faustParamIdx, double value)
274{
275 ScopedDSPUser user(mDSPGuard);
276
277 // If the DSP is being replaced, SyncFaustParams() applies the parameter values to the new DSP afterwards
278 if (user.IsEntered())
279 WriteZoneUnguarded(faustParamIdx, value);
280}
281
282void IPlugFaust::WriteZoneUnguarded(int faustParamIdx, double value)
283{
284 if (faustParamIdx < 0 || faustParamIdx >= NParams())
285 return;
286
287 Param& p = mParams[faustParamIdx];
288
289 if (!p.enumValues.empty())
290 {
291 const int idx = Clip(static_cast<int>(value + 0.5), 0, static_cast<int>(p.enumValues.size()) - 1);
292 value = p.enumValues[idx];
293 }
294
295 *p.zone = static_cast<FAUSTFLOAT>(value);
296}
297
298namespace
299{
300 // Whether two parameters have the same definition (ignoring their values), so that re-initializing one from the other would change nothing
301 bool SameDefinition(const IParam& a, const IParam& b)
302 {
303 if (a.Type() != b.Type() || strcmp(a.GetName(), b.GetName()) != 0 || strcmp(a.GetLabel(), b.GetLabel()) != 0 ||
304 strcmp(a.GetGroup(), b.GetGroup()) != 0 || a.GetMin() != b.GetMin() || a.GetMax() != b.GetMax() ||
305 a.GetStep() != b.GetStep() || a.GetDefault() != b.GetDefault() || a.GetFlags() != b.GetFlags() ||
306 a.GetShapeID() != b.GetShapeID() || a.GetShapeValue() != b.GetShapeValue() || a.NDisplayTexts() != b.NDisplayTexts())
307 return false;
308
309 for (int i = 0; i < a.NDisplayTexts(); i++)
310 {
311 double valueA, valueB;
312 const char* textA = a.GetDisplayTextAtIdx(i, &valueA);
313 const char* textB = b.GetDisplayTextAtIdx(i, &valueB);
314
315 if (valueA != valueB || strcmp(textA, textB) != 0)
316 return false;
317 }
318
319 return true;
320 }
321}
322
323void IPlugFaust::RelinkParams()
324{
325 if (!mPlug || mPlugParamStartIdx < 0)
326 return;
327
328 const int prevEndIdx = mPlugParamEndIdx;
329 mPlugParamEndIdx = std::min(NParams(), mPlug->NParams() - mPlugParamStartIdx);
330
331 if (mPlugParamEndIdx < NParams())
332 DBGMSG("IPlugFaust-%s: the plug-in doesn't have enough parameters for the Faust DSP (needs %i)\n", mName.Get(), mPlugParamStartIdx + NParams());
333
334 bool changed = mPlugParamEndIdx != prevEndIdx;
335
336 // Only parameters whose definition changed are re-initialized. Re-initializing a parameter isn't thread safe: IParam::Init() replaces its
337 // shape and display texts, which the host may be using on another thread (e.g. converting automation on the audio thread, or getting a
338 // display string). So this keeps the risk to recompilations that actually change the parameters, which is a development-time workflow
339 for (int p = 0; p < mPlugParamEndIdx; p++)
340 {
341 IParam* pPlugParam = mPlug->GetParam(mPlugParamStartIdx + p);
342 const IParam& faustParam = *mParams[p].param;
343
344 if (!SameDefinition(*pPlugParam, faustParam))
345 {
346 pPlugParam->Init(faustParam);
347 pPlugParam->Set(faustParam.Value());
348 changed = true;
349 }
350 }
351
352 if (changed)
353 mParamsChanged = true;
354}
355
357{
358 if (mParamsChanged && mPlug)
359 {
360 mParamsChanged = false;
362 }
363}
364
365#pragma mark - DSP
366
367void IPlugFaust::SetDSP(::dsp* pMonoDSP)
368{
369 assert(pMonoDSP != nullptr);
370
371 // Polyphony is enabled with declare options "[midi:on][nvoices:N]" or the nVoices constructor argument
372 bool midi = false, midiSync = false;
373 int nVoices = 0;
374 MidiMeta::analyse(pMonoDSP, midi, midiSync, nVoices);
375
376 if (nVoices == 0 && mNVoices > 1)
377 nVoices = mNVoices;
378
379 auto pMidiHandler = std::make_unique<iplug2_midi_handler>();
380 std::unique_ptr<::dsp> pDSP;
381
382 if (nVoices > 0)
383 pDSP.reset(new mydsp_poly(pMonoDSP, nVoices, true /* control */, true /* group */));
384 else
385 pDSP.reset(pMonoDSP);
386
387 // MidiUI maps MIDI to the zones with [midi:...] metadata. A polyphonic DSP also registers itself with it, to receive notes
388 auto pMidiUI = std::make_unique<MidiUI>(pMidiHandler.get());
389 pDSP->buildUserInterface(pMidiUI.get());
390 pMidiUI->run();
391
392 pDSP->init(mSampleRate > 0. ? static_cast<int>(mSampleRate) : static_cast<int>(DEFAULT_SAMPLE_RATE));
393
394 JSONUI jsonUI(pDSP->getNumInputs(), pDSP->getNumOutputs());
395 pDSP->buildUserInterface(&jsonUI);
396 pDSP->metadata(&jsonUI);
397
398 // Build the new parameters and UI description (into mNew...), before taking the audio thread out
399 BuildDescription(pDSP.get());
400
401 // Keep the values of parameters with the same path, when the DSP is recompiled
402 for (auto& newParam : mNewParams)
403 {
404 for (int p = 0; p < NParams(); p++)
405 {
406 if (mParams[p].path == newParam.path)
407 {
408 const int plugParamIdx = GetPlugParamIdx(p);
409 newParam.param->Set(plugParamIdx > kNoParameter ? mPlug->GetParam(plugParamIdx)->Value() : mParams[p].param->Value());
410 break;
411 }
412 }
413 }
414
415 const bool channelCountError = (mMaxNInputs > -1 && pDSP->getNumInputs() > mMaxNInputs) ||
416 (mMaxNOutputs > -1 && pDSP->getNumOutputs() > mMaxNOutputs);
417
418 const bool hadDSP = mDSP != nullptr;
419 std::string json = jsonUI.JSON();
420
421 {
422 // Only pointers and containers are swapped while the audio thread is kept out.
423 // The previous objects are destroyed afterwards, when they go out of scope
424 ScopedDSPReplace replace(mDSPGuard);
425
426 std::swap(mMidiUI, pMidiUI);
427 std::swap(mDSP, pDSP);
428 std::swap(mMidiHandler, pMidiHandler);
429 std::swap(mParams, mNewParams);
430 std::swap(mBargraphs, mNewBargraphs);
431 std::swap(mUIRoot, mNewUIRoot);
432 std::swap(mJSON, json);
433 mChannelCountError = channelCountError;
434 mHasSoundfile = mNewHasSoundfile;
435 }
436
437 mNewParams.clear();
438 mNewBargraphs.clear();
439 mNewUIRoot = FaustUIItem();
440
441 if (mChannelCountError)
442 {
443 DBGMSG("IPlugFaust-%s: the DSP has %i inputs and %i outputs, but the plug-in only provides %i inputs and %i outputs. Outputting silence.\n",
444 mName.Get(), mDSP->getNumInputs(), mDSP->getNumOutputs(), mMaxNInputs, mMaxNOutputs);
445 }
446
447 // A polyphonic DSP unregisters itself from the MidiUI, which unregisters itself from the MIDI handler
448 pDSP = nullptr;
449 pMidiUI = nullptr;
450 pMidiHandler = nullptr;
451
452 if (hadDSP)
453 RelinkParams();
454
456
457 if (!mBargraphs.empty() && !mUITimer)
458 mUITimer = std::unique_ptr<Timer>(Timer::Create(std::bind(&IPlugFaust::OnUITimer, this, std::placeholders::_1), FAUST_UI_INTERVAL));
459}
460
461void IPlugFaust::BuildDescription(::dsp* pDSP)
462{
463 // Only uses mNew... members, so the audio thread can keep using the current ones
464 mNewParams.clear();
465 mNewBargraphs.clear();
466 mNewHasSoundfile = false;
467 clearMetadata();
468
469 mNewUIRoot = FaustUIItem();
470 mNewUIRoot.type = FaustUIItem::EType::VBox;
471 mGroupStack.clear();
472 mGroupStack.push_back(&mNewUIRoot);
473
474 pDSP->buildUserInterface(this);
475
476 mGroupStack.clear();
477
478 // Faust DSPs normally have a single top-level group. If so, make that the root
479 if (mNewUIRoot.children.size() == 1 && mNewUIRoot.children[0].IsGroup())
480 {
481 FaustUIItem root = std::move(mNewUIRoot.children[0]);
482 mNewUIRoot = std::move(root);
483 }
484}
485
487{
488 if (mDSP)
489 {
490 mDSP->buildUserInterface(pUI);
491
492 if (auto* pMeta = dynamic_cast<Meta*>(pUI))
493 mDSP->metadata(pMeta);
494 }
495}
496
497void IPlugFaust::OnUITimer(Timer& timer)
498{
499 if (!mPlug)
500 return;
501
502 // Zones are written on the audio thread, here we just read the latest value, like Faust's own GUIs
503 for (auto& b : mBargraphs)
504 {
505 if (b.hidden)
506 continue;
507
508 const double range = b.max - b.min;
509 const double normalized = range != 0. ? Clip((static_cast<double>(*b.zone) - b.min) / range, 0., 1.) : 0.;
510
511 if (normalized != b.lastSentValue)
512 {
513 b.lastSentValue = normalized;
514 mPlug->SendControlValueFromDelegate(b.ctrlTag, normalized);
515 }
516 }
517}
518
519#pragma mark - Faust UI interface
520
521void IPlugFaust::OpenGroup(FaustUIItem::EType type, const char* label)
522{
523 std::string cleanLabel;
524 std::map<std::string, std::string> metadata;
525 extractMetadata(CleanLabel(label), cleanLabel, metadata);
526
527 FaustUIItem& parent = *mGroupStack.back();
528 parent.children.emplace_back();
529 FaustUIItem& group = parent.children.back();
530 group.type = type;
531 group.label = cleanLabel;
532 group.path = parent.path + "/" + cleanLabel;
533 group.hidden = metadata.count("hidden") && metadata["hidden"] == "1";
534 group.tooltip = metadata.count("tooltip") ? metadata["tooltip"] : "";
535
536 mGroupStack.push_back(&group);
537}
538
539void IPlugFaust::openTabBox(const char* label)
540{
541 OpenGroup(FaustUIItem::EType::TabBox, label);
542}
543
544void IPlugFaust::openHorizontalBox(const char* label)
545{
546 OpenGroup(FaustUIItem::EType::HBox, label);
547}
548
549void IPlugFaust::openVerticalBox(const char* label)
550{
551 OpenGroup(FaustUIItem::EType::VBox, label);
552}
553
554void IPlugFaust::closeBox()
555{
556 if (mGroupStack.size() > 1)
557 mGroupStack.pop_back();
558}
559
560FaustUIItem& IPlugFaust::AddItem(FaustUIItem::EType type, const char* label, FAUSTFLOAT* zone)
561{
562 FaustUIItem& parent = *mGroupStack.back();
563 parent.children.emplace_back();
564 FaustUIItem& item = parent.children.back();
565 item.type = type;
566 item.label = CleanLabel(label);
567 item.path = parent.path + "/" + item.label;
568 item.zone = zone;
569 item.hidden = isHidden(zone);
570 item.knob = isKnob(zone);
571 item.led = isLed(zone);
572 item.numerical = isNumerical(zone);
573 item.menu = isMenu(zone);
574 item.radio = isRadio(zone);
575 item.unit = getUnit(zone);
576 item.tooltip = getTooltip(zone);
577
578 if (item.menu)
579 item.options = getMenuDescription(zone);
580 else if (item.radio)
581 item.options = getRadioDescription(zone);
582
583 return item;
584}
585
586void IPlugFaust::AddParam(FaustUIItem& item, IParam::EParamType type)
587{
588 // The parameter group is the path of the containing boxes
589 std::string group;
590
591 for (size_t i = 1; i < mGroupStack.size(); i++)
592 {
593 const std::string& label = mGroupStack[i]->label;
594
595 if (label.empty())
596 continue;
597
598 if (!group.empty())
599 group += "/";
600
601 group += label;
602 }
603
604 if (group.length() > MAX_PARAM_GROUP_LEN - 1)
605 group = group.substr(0, MAX_PARAM_GROUP_LEN - 4) + "...";
606
607 Param p;
608 p.zone = item.zone;
609 p.path = item.path;
610
611 const char* name = item.label.c_str();
612 const char* unit = item.unit.c_str();
613 const auto flags = IParam::kFlagsNone;
614
615 switch (type)
616 {
617 case IParam::kTypeBool:
618 p.param->InitBool(name, item.init > 0.5, unit, flags, group.c_str());
619 break;
620 case IParam::kTypeEnum:
621 {
622 const int nOptions = static_cast<int>(item.options.size());
623 int defaultIdx = 0;
624
625 for (int i = 0; i < nOptions; i++)
626 {
627 p.enumValues.push_back(item.options[i].second);
628
629 if (item.options[i].second == item.init)
630 defaultIdx = i;
631 }
632
633 p.param->InitEnum(name, defaultIdx, nOptions, unit, flags, group.c_str());
634
635 for (int i = 0; i < nOptions; i++)
636 p.param->SetDisplayText(i, item.options[i].first.c_str());
637
638 break;
639 }
640 case IParam::kTypeDouble:
641 default:
642 {
643 const double step = item.step > 0. ? item.step : 0.001;
644
645 switch (getScale(item.zone))
646 {
647 case MetaDataUI::kLog:
648 if (item.min > 0.)
649 p.param->InitDouble(name, item.init, item.min, item.max, step, unit, flags, group.c_str(), IParam::ShapeExp());
650 else
651 p.param->InitDouble(name, item.init, item.min, item.max, step, unit, flags, group.c_str(), IParam::ShapePowCurve(3.));
652 break;
653 case MetaDataUI::kExp:
654 p.param->InitDouble(name, item.init, item.min, item.max, step, unit, flags, group.c_str(), IParam::ShapePowCurve(1./3.));
655 break;
656 case MetaDataUI::kLin:
657 default:
658 p.param->InitDouble(name, item.init, item.min, item.max, step, unit, flags, group.c_str());
659 break;
660 }
661 break;
662 }
663 }
664
665 item.paramIdx = static_cast<int>(mNewParams.size());
666 mNewParams.push_back(std::move(p));
667}
668
669void IPlugFaust::addButton(const char* label, FAUSTFLOAT* zone)
670{
671 FaustUIItem& item = AddItem(FaustUIItem::EType::Button, label, zone);
672 AddParam(item, IParam::kTypeBool);
673}
674
675void IPlugFaust::addCheckButton(const char* label, FAUSTFLOAT* zone)
676{
677 FaustUIItem& item = AddItem(FaustUIItem::EType::CheckButton, label, zone);
678 AddParam(item, IParam::kTypeBool);
679}
680
681void IPlugFaust::addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
682{
683 FaustUIItem& item = AddItem(FaustUIItem::EType::VSlider, label, zone);
684 item.init = init; item.min = min; item.max = max; item.step = step;
685 AddParam(item, (item.menu || item.radio) ? IParam::kTypeEnum : IParam::kTypeDouble);
686}
687
688void IPlugFaust::addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
689{
690 FaustUIItem& item = AddItem(FaustUIItem::EType::HSlider, label, zone);
691 item.init = init; item.min = min; item.max = max; item.step = step;
692 AddParam(item, (item.menu || item.radio) ? IParam::kTypeEnum : IParam::kTypeDouble);
693}
694
695void IPlugFaust::addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
696{
697 FaustUIItem& item = AddItem(FaustUIItem::EType::NumEntry, label, zone);
698 item.init = init; item.min = min; item.max = max; item.step = step;
699 AddParam(item, (item.menu || item.radio) ? IParam::kTypeEnum : IParam::kTypeDouble);
700}
701
702void IPlugFaust::AddBargraph(FaustUIItem::EType type, const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
703{
704 FaustUIItem& item = AddItem(type, label, zone);
705 item.min = min; item.max = max;
706 item.ctrlTag = mCtrlTagStart + static_cast<int>(mNewBargraphs.size());
707
708 // A hidden bargraph, or one in a hidden group, gets no control in IGraphicsFaustUI, so no values are sent to its tag
709 bool hidden = item.hidden;
710
711 for (const FaustUIItem* pGroup : mGroupStack)
712 hidden = hidden || pGroup->hidden;
713
714 Bargraph b;
715 b.zone = zone;
716 b.min = item.min;
717 b.max = item.max;
718 b.ctrlTag = item.ctrlTag;
719 b.hidden = hidden;
720 mNewBargraphs.push_back(b);
721}
722
723void IPlugFaust::addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
724{
725 AddBargraph(FaustUIItem::EType::HBargraph, label, zone, min, max);
726}
727
728void IPlugFaust::addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
729{
730 AddBargraph(FaustUIItem::EType::VBargraph, label, zone, min, max);
731}
732
733void IPlugFaust::addSoundfile(const char* label, const char* filename, Soundfile** sfZone)
734{
735 // The soundfile zone would need to be filled with a Soundfile, otherwise compute() crashes
736 DBGMSG("IPlugFaust-%s: soundfiles are not supported (%s), the DSP will output silence\n", mName.Get(), label);
737 mNewHasSoundfile = true;
738}
739
740void IPlugFaust::declare(FAUSTFLOAT* zone, const char* key, const char* value)
741{
742 MetaDataUI::declare(zone, key, value);
743}
#define FAUST_UI_INTERVAL
Interval in milliseconds at which bargraph (meter) values are sent to the editor.
Definition: IPlugFaust.h:59
IPlug's parameter class.
double GetStep() const
Returns the parameter's step size.
double GetDefault(bool normalized=false) const
Returns the parameter's default value.
void SetToDefault()
Replaces the parameter's current value with the default one
EParamType Type() const
Get the parameter's type.
int GetFlags() const
Returns the parameter's flags.
@ kFlagsNone
No flags.
double GetMin() const
Returns the parameter's minimum value.
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 Set(double value)
Sets the parameter value.
const char * GetLabel() const
Returns the parameter's label.
void SetNormalized(double normalizedValue)
Sets the parameter value from a normalized range (usually coming from the linked IControl)
const char * GetName() const
Returns the parameter's name.
double GetNormalized() const
Returns the parameter's normalized value.
const char * GetDisplayTextAtIdx(int idx, double *pValue=nullptr) const
Get the display text at a particular index.
const char * GetGroup() const
Returns the parameter's group.
double GetShapeValue() const
double Value() const
Gets a readable value of the parameter.
int NDisplayTexts() const
Get the number of display texts for the parameter.
EParamType
Defines types or parameter.
EShapeIDs GetShapeID() const
double GetMax() const
Returns the parameter's maximum value.
The base class of an IPlug plug-in, which interacts with the different plug-in APIs.
Definition: IPlugAPIBase.h:43
int NParams() const
Definition: IPlugFaust.h:148
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,...
Definition: IPlugFaust.cpp:139
void InformHostIfParamsChanged()
If SetDSP() re-initialized the linked plug-in parameters (i.e.
Definition: IPlugFaust.cpp:356
int GetPlugParamIdx(int faustParamIdx) const
Definition: IPlugFaust.cpp:265
void ProcessMidiMsg(const IMidiMsg &msg)
Call this from the plug-in's ProcessMidiMsg()
Definition: IPlugFaust.cpp:105
void ReleaseDSP()
Destroys the DSP, waiting for a block that is being processed to finish first.
Definition: IPlugFaust.cpp:56
void SetSampleRate(double sampleRate)
Call this from the plug-in's OnReset().
Definition: IPlugFaust.cpp:91
void BuildUI(UI *pUI)
Calls buildUserInterface() and metadata() on the DSP, to build a Faust UI.
Definition: IPlugFaust.cpp:486
int GetFaustParamIdxForZone(FAUSTFLOAT *zone) const
Definition: IPlugFaust.cpp:254
void SetParameterValue(int faustParamIdx, double value)
Set a Faust widget's value via its parameter index (0...NParams()-1)
Definition: IPlugFaust.cpp:209
void ProcessBlock(sample **inputs, sample **outputs, int nFrames)
Call this from the plug-in's ProcessBlock().
Definition: IPlugFaust.cpp:115
IPlugFaust(const char *name, int nVoices=0, int ctrlTagStart=kDefaultCtrlTagStart)
Definition: IPlugFaust.cpp:44
void SetParameterValueNormalised(int faustParamIdx, double normalizedValue)
Set a Faust widget's value via its parameter index (0...NParams()-1)
Definition: IPlugFaust.cpp:192
bool OnParamChange(int plugParamIdx)
If plugParamIdx is linked to a Faust widget, update its zone from the plug-in's parameter value.
Definition: IPlugFaust.cpp:178
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...
Definition: IPlugFaust.cpp:85
void SetDSP(::dsp *pMonoDSP)
Takes ownership of a newly created DSP, wraps it for polyphony if required, (re)builds the parameters...
Definition: IPlugFaust.cpp:367
void SyncFaustParams()
Apply the values of all the parameters to the DSP (e.g.
Definition: IPlugFaust.cpp:235
virtual void InformHostOfParameterDetailsChange()
Implemented by the API class.
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
A node in the description of a Faust DSP's user interface, as declared by its buildUserInterface() me...
Definition: IPlugFaust.h:68
Encapsulates a MIDI message and provides helper functions.
Definition: IPlugMidi.h:31
Exponential parameter shaping.
PowCurve parameter shaping.
Base class for timer.
Definition: IPlugTimer.h:43
static Timer * Create(ITimerFunction func, uint32_t intervalMs)
On Linux, callbacks run on a worker; returns nullptr if that worker cannot be created.