DISTRHO Plugin Framework
DistrhoInfo.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
6  * or without fee is hereby granted, provided that the above copyright notice and this
7  * permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 #ifdef DOXYGEN
18 
19 #include "src/DistrhoDefines.h"
20 
21 START_NAMESPACE_DISTRHO
22 
23 /* ------------------------------------------------------------------------------------------------------------
24  * Intro */
25 
26 /**
27  @mainpage DISTRHO %Plugin Framework
28 
29  DISTRHO %Plugin Framework (or @b DPF for short)
30  is a plugin framework designed to make development of new plugins an easy and enjoyable task.@n
31  It allows developers to create plugins with custom UIs using a simple C++ API.@n
32  The framework facilitates exporting various different plugin formats from the same code-base.
33 
34  DPF can build for LADSPA, DSSI, LV2 and VST2 formats.@n
35  A JACK/Standalone mode is also available, allowing you to quickly test plugins.
36 
37  @section Macros
38  You start by creating a "DistrhoPluginInfo.h" file describing the plugin via macros, see @ref PluginMacros.@n
39  This file is included in the main DPF code to select which features to activate for each plugin format.
40 
41  For example, a plugin (with %UI) that use states will require LV2 hosts to support Atom and Worker extensions for
42  message passing from the %UI to the plugin.@n
43  If your plugin does not make use of states, the Worker extension is not set as a required feature.
44 
45  @section Plugin
46  The next step is to create your plugin code by subclassing DPF's Plugin class.@n
47  You need to pass the number of parameters in the constructor and also the number of programs and states, if any.
48 
49  Here's an example of an audio plugin that simply mutes the host output:
50  @code
51  class MutePlugin : public Plugin
52  {
53  public:
54  /**
55  Plugin class constructor.
56  */
57  MutePlugin()
58  : Plugin(0, 0, 0) // 0 parameters, 0 programs and 0 states
59  {
60  }
61 
62  protected:
63  /* ----------------------------------------------------------------------------------------
64  * Information */
65 
66  /**
67  Get the plugin label.
68  This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
69  */
70  const char* getLabel() const override
71  {
72  return "Mute";
73  }
74 
75  /**
76  Get the plugin author/maker.
77  */
78  const char* getMaker() const override
79  {
80  return "DPF";
81  }
82 
83  /**
84  Get the plugin license name (a single line of text).
85  For commercial plugins this should return some short copyright information.
86  */
87  const char* getLicense() const override
88  {
89  return "MIT";
90  }
91 
92  /**
93  Get the plugin version, in hexadecimal.
94  */
95  uint32_t getVersion() const override
96  {
97  return d_version(1, 0, 0);
98  }
99 
100  /**
101  Get the plugin unique Id.
102  This value is used by LADSPA, DSSI and VST plugin formats.
103  */
104  int64_t getUniqueId() const override
105  {
106  return d_cconst('M', 'u', 't', 'e');
107  }
108 
109  /* ----------------------------------------------------------------------------------------
110  * Audio/MIDI Processing */
111 
112  /**
113  Run/process function for plugins without MIDI input.
114  NOTE: Some parameters might be null if there are no audio inputs or outputs.
115  */
116  void run(const float**, float** outputs, uint32_t frames) override
117  {
118  // get the left and right audio outputs
119  float* const outL = outputs[0];
120  float* const outR = outputs[1];
121 
122  // mute audio
123  std::memset(outL, 0, sizeof(float)*frames);
124  std::memset(outR, 0, sizeof(float)*frames);
125  }
126 
127  };
128  @endcode
129 
130  See the Plugin class for more information and to understand what each function does.
131 
132  @section Parameters
133  A plugin is nothing without parameters.@n
134  In DPF parameters can be inputs or outputs.@n
135  They have hints to describe how they behave plus a name and a symbol identifying them.@n
136  Parameters also have 'ranges' – a minimum, maximum and default value.
137 
138  Input parameters are "read-only": the plugin can read them but not change them.
139  (the exception being when changing programs, more on that below)@n
140  It's the host responsibility to save, restore and set input parameters.
141 
142  Output parameters can be changed at anytime by the plugin.@n
143  The host will simply read their values and not change them.
144 
145  Here's an example of an audio plugin that has 1 input parameter:
146  @code
147  class GainPlugin : public Plugin
148  {
149  public:
150  /**
151  Plugin class constructor.
152  You must set all parameter values to their defaults, matching ParameterRanges::def.
153  */
154  GainPlugin()
155  : Plugin(1, 0, 0), // 1 parameter, 0 programs and 0 states
156  fGain(1.0f)
157  {
158  }
159 
160  protected:
161  /* ----------------------------------------------------------------------------------------
162  * Information */
163 
164  const char* getLabel() const override
165  {
166  return "Gain";
167  }
168 
169  const char* getMaker() const override
170  {
171  return "DPF";
172  }
173 
174  const char* getLicense() const override
175  {
176  return "MIT";
177  }
178 
179  uint32_t getVersion() const override
180  {
181  return d_version(1, 0, 0);
182  }
183 
184  int64_t getUniqueId() const override
185  {
186  return d_cconst('G', 'a', 'i', 'n');
187  }
188 
189  /* ----------------------------------------------------------------------------------------
190  * Init */
191 
192  /**
193  Initialize a parameter.
194  This function will be called once, shortly after the plugin is created.
195  */
196  void initParameter(uint32_t index, Parameter& parameter) override
197  {
198  // we only have one parameter so we can skip checking the index
199 
200  parameter.hints = kParameterIsAutomable;
201  parameter.name = "Gain";
202  parameter.symbol = "gain";
203  parameter.ranges.min = 0.0f;
204  parameter.ranges.max = 2.0f;
205  parameter.ranges.def = 1.0f;
206  }
207 
208  /* ----------------------------------------------------------------------------------------
209  * Internal data */
210 
211  /**
212  Get the current value of a parameter.
213  */
214  float getParameterValue(uint32_t index) const override
215  {
216  // same as before, ignore index check
217 
218  return fGain;
219  }
220 
221  /**
222  Change a parameter value.
223  */
224  void setParameterValue(uint32_t index, float value) override
225  {
226  // same as before, ignore index check
227 
228  fGain = value;
229  }
230 
231  /* ----------------------------------------------------------------------------------------
232  * Audio/MIDI Processing */
233 
234  void run(const float**, float** outputs, uint32_t frames) override
235  {
236  // get the mono input and output
237  const float* const in = inputs[0];
238  /* */ float* const out = outputs[0];
239 
240  // apply gain against all samples
241  for (uint32_t i=0; i < frames; ++i)
242  out[i] = in[i] * fGain;
243  }
244 
245  private:
246  float fGain;
247  };
248  @endcode
249 
250  See the Parameter struct for more information about parameters.
251 
252  @section Programs
253  Programs in DPF refer to plugin-side presets (usually called "factory presets"),
254  an initial set of presets provided by plugin authors included in the actual plugin.
255 
256  To use programs you must first enable them by setting @ref DISTRHO_PLUGIN_WANT_PROGRAMS to 1 in your DistrhoPluginInfo.h file.@n
257  When enabled you'll need to override 2 new function in your plugin code,
258  Plugin::initProgramName(uint32_t, String&) and Plugin::loadProgram(uint32_t).
259 
260  Here's an example of a plugin with a "default" program:
261  @code
262  class PluginWithPresets : public Plugin
263  {
264  public:
265  PluginWithPresets()
266  : Plugin(2, 1, 0), // 2 parameters, 1 program and 0 states
267  fGainL(1.0f),
268  fGainR(1.0f),
269  {
270  }
271 
272  protected:
273  /* ----------------------------------------------------------------------------------------
274  * Information */
275 
276  const char* getLabel() const override
277  {
278  return "Prog";
279  }
280 
281  const char* getMaker() const override
282  {
283  return "DPF";
284  }
285 
286  const char* getLicense() const override
287  {
288  return "MIT";
289  }
290 
291  uint32_t getVersion() const override
292  {
293  return d_version(1, 0, 0);
294  }
295 
296  int64_t getUniqueId() const override
297  {
298  return d_cconst('P', 'r', 'o', 'g');
299  }
300 
301  /* ----------------------------------------------------------------------------------------
302  * Init */
303 
304  /**
305  Initialize a parameter.
306  This function will be called once, shortly after the plugin is created.
307  */
308  void initParameter(uint32_t index, Parameter& parameter) override
309  {
310  parameter.hints = kParameterIsAutomable;
311  parameter.ranges.min = 0.0f;
312  parameter.ranges.max = 2.0f;
313  parameter.ranges.def = 1.0f;
314 
315  switch (index)
316  {
317  case 0;
318  parameter.name = "Gain Right";
319  parameter.symbol = "gainR";
320  break;
321  case 1;
322  parameter.name = "Gain Left";
323  parameter.symbol = "gainL";
324  break;
325  }
326  }
327 
328  /**
329  Set the name of the program @a index.
330  This function will be called once, shortly after the plugin is created.
331  */
332  void initProgramName(uint32_t index, String& programName)
333  {
334  switch(index)
335  {
336  case 0:
337  programName = "Default";
338  break;
339  }
340  }
341 
342  /* ----------------------------------------------------------------------------------------
343  * Internal data */
344 
345  /**
346  Get the current value of a parameter.
347  */
348  float getParameterValue(uint32_t index) const override
349  {
350  switch (index)
351  {
352  case 0;
353  return fGainL;
354  case 1;
355  return fGainR;
356  }
357  }
358 
359  /**
360  Change a parameter value.
361  */
362  void setParameterValue(uint32_t index, float value) override
363  {
364  switch (index)
365  {
366  case 0;
367  fGainL = value;
368  break;
369  case 1;
370  fGainR = value;
371  break;
372  }
373  }
374 
375  /**
376  Load a program.
377  */
378  void loadProgram(uint32_t index)
379  {
380  switch(index)
381  {
382  case 0:
383  fGainL = 1.0f;
384  fGainR = 1.0f;
385  break;
386  }
387  }
388 
389  /* ----------------------------------------------------------------------------------------
390  * Audio/MIDI Processing */
391 
392  void run(const float**, float** outputs, uint32_t frames) override
393  {
394  // get the left and right audio buffers
395  const float* const inL = inputs[0];
396  const float* const inR = inputs[0];
397  /* */ float* const outL = outputs[0];
398  /* */ float* const outR = outputs[0];
399 
400  // apply gain against all samples
401  for (uint32_t i=0; i < frames; ++i)
402  {
403  outL[i] = inL[i] * fGainL;
404  outR[i] = inR[i] * fGainR;
405  }
406  }
407 
408  private:
409  float fGainL, fGainR;
410  };
411  @endcode
412 
413  This is a work-in-progress documentation page. States, MIDI, Latency, Time-Position and UI are still TODO.
414 */
415 
416 #if 0
417  @section States
418  describe them
419 
420  @section MIDI
421  describe them
422 
423  @section Latency
424  describe it
425 
426  @section Time-Position
427  describe it
428 
429  @section UI
430  describe them
431 #endif
432 
433 /* ------------------------------------------------------------------------------------------------------------
434  * Plugin Macros */
435 
436 /**
437  @defgroup PluginMacros Plugin Macros
438 
439  C Macros that describe your plugin. (defined in the "DistrhoPluginInfo.h" file)
440 
441  With these macros you can tell the host what features your plugin requires.@n
442  Depending on which macros you enable, new functions will be available to call and/or override.
443 
444  All values are either integer or strings.@n
445  For boolean-like values 1 means 'on' and 0 means 'off'.
446 
447  The values defined in this group are for documentation purposes only.@n
448  All macros are disabled by default.
449 
450  Only 4 macros are required, they are:
451  - @ref DISTRHO_PLUGIN_NAME
452  - @ref DISTRHO_PLUGIN_NUM_INPUTS
453  - @ref DISTRHO_PLUGIN_NUM_OUTPUTS
454  - @ref DISTRHO_PLUGIN_URI
455  @{
456  */
457 
458 /**
459  The plugin name.@n
460  This is used to identify your plugin before a Plugin instance can be created.
461  @note This macro is required.
462  */
463 #define DISTRHO_PLUGIN_NAME "Plugin Name"
464 
465 /**
466  Number of audio inputs the plugin has.
467  @note This macro is required.
468  */
469 #define DISTRHO_PLUGIN_NUM_INPUTS 2
470 
471 /**
472  Number of audio outputs the plugin has.
473  @note This macro is required.
474  */
475 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2
476 
477 /**
478  The plugin URI when exporting in LV2 format.
479  @note This macro is required.
480  */
481 #define DISTRHO_PLUGIN_URI "urn:distrho:name"
482 
483 /**
484  Whether the plugin has a custom %UI.
485  @see DISTRHO_UI_USE_NANOVG
486  @see UI
487  */
488 #define DISTRHO_PLUGIN_HAS_UI 1
489 
490 /**
491  Whether the plugin processing is realtime-safe.@n
492  TODO - list rtsafe requirements
493  */
494 #define DISTRHO_PLUGIN_IS_RT_SAFE 1
495 
496 /**
497  Whether the plugin is a synth.@n
498  @ref DISTRHO_PLUGIN_WANT_MIDI_INPUT is automatically enabled when this is too.
499  @see DISTRHO_PLUGIN_WANT_MIDI_INPUT
500  */
501 #define DISTRHO_PLUGIN_IS_SYNTH 1
502 
503 /**
504  Request the minimum buffer size for the input and output event ports.@n
505  Currently only used in LV2, with a default value of 2048 if unset.
506  */
507 #define DISTRHO_PLUGIN_MINIMUM_BUFFER_SIZE 2048
508 
509 /**
510  Whether the plugin has an LV2 modgui.
511 
512  This will simply add a "rdfs:seeAlso <modgui.ttl>" on the LV2 manifest.@n
513  It is up to you to create this file.
514  */
515 #define DISTRHO_PLUGIN_USES_MODGUI 0
516 
517 /**
518  Enable direct access between the %UI and plugin code.
519  @see UI::getPluginInstancePointer()
520  @note DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
521  Try to avoid it at all costs!
522  */
523 #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
524 
525 /**
526  Whether the plugin introduces latency during audio or midi processing.
527  @see Plugin::setLatency(uint32_t)
528  */
529 #define DISTRHO_PLUGIN_WANT_LATENCY 1
530 
531 /**
532  Whether the plugin wants MIDI input.@n
533  This is automatically enabled if @ref DISTRHO_PLUGIN_IS_SYNTH is true.
534  */
535 #define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
536 
537 /**
538  Whether the plugin wants MIDI output.
539  @see Plugin::writeMidiEvent(const MidiEvent&)
540  */
541 #define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
542 
543 /**
544  Whether the plugin wants to change its own parameter inputs.@n
545  Not all hosts or plugin formats support this,
546  so Plugin::canRequestParameterValueChanges() can be used to query support at runtime.
547  @see Plugin::requestParameterValueChange(uint32_t, float)
548  */
549 #define DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST 1
550 
551 /**
552  Whether the plugin provides its own internal programs.
553  @see Plugin::initProgramName(uint32_t, String&)
554  @see Plugin::loadProgram(uint32_t)
555  */
556 #define DISTRHO_PLUGIN_WANT_PROGRAMS 1
557 
558 /**
559  Whether the plugin uses internal non-parameter data.
560  @see Plugin::initState(uint32_t, String&, String&)
561  @see Plugin::setState(const char*, const char*)
562  */
563 #define DISTRHO_PLUGIN_WANT_STATE 1
564 
565 /**
566  Whether the plugin implements the full state API.
567  When this macro is enabled, the plugin must implement a new getState(const char* key) function, which the host calls when saving its session/project.
568  This is useful for plugins that have custom internal values not exposed to the host as key-value state pairs or parameters.
569  Most simple effects and synths will not need this.
570  @note this macro is automatically enabled if a plugin has programs and state, as the key-value state pairs need to be updated when the current program changes.
571  @see Plugin::getState(const char*)
572  */
573 #define DISTRHO_PLUGIN_WANT_FULL_STATE 1
574 
575 /**
576  Whether the plugin wants time position information from the host.
577  @see Plugin::getTimePosition()
578  */
579 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1
580 
581 /**
582  Whether the %UI uses a custom toolkit implementation based on OpenGL.@n
583  When enabled, the macros @ref DISTRHO_UI_CUSTOM_INCLUDE_PATH and @ref DISTRHO_UI_CUSTOM_WIDGET_TYPE are required.
584  */
585 #define DISTRHO_UI_USE_CUSTOM 1
586 
587 /**
588  The include path to the header file used by the custom toolkit implementation.
589  This path must be relative to dpf/distrho/DistrhoUI.hpp
590  @see DISTRHO_UI_USE_CUSTOM
591  */
592 #define DISTRHO_UI_CUSTOM_INCLUDE_PATH
593 
594 /**
595  The top-level-widget typedef to use for the custom toolkit.
596  This widget class MUST be a subclass of DGL TopLevelWindow class.
597  It is recommended that you keep this widget class inside the DGL namespace,
598  and define widget type as e.g. DGL_NAMESPACE::MyCustomTopLevelWidget.
599  @see DISTRHO_UI_USE_CUSTOM
600  */
601 #define DISTRHO_UI_CUSTOM_WIDGET_TYPE
602 
603 /**
604  Whether the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
605  When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
606  */
607 #define DISTRHO_UI_USE_NANOVG 1
608 
609 /**
610  Whether the %UI is resizable to any size by the user.@n
611  By default this is false, and resizing is only allowed under the plugin UI control,@n
612  Enabling this options makes it possible for the user to resize the plugin UI at anytime.
613  @see UI::setGeometryConstraints(uint, uint, bool, bool)
614  */
615 #define DISTRHO_UI_USER_RESIZABLE 1
616 
617 /**
618  The %UI URI when exporting in LV2 format.@n
619  By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
620  */
621 #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
622 
623 /** @} */
624 
625 /* ------------------------------------------------------------------------------------------------------------
626  * Plugin Macros */
627 
628 /**
629  @defgroup ExtraPluginMacros Extra Plugin Macros
630 
631  C Macros to customize DPF behaviour.
632 
633  These are macros that do not set plugin features or information, but instead change DPF internals.
634  They are all optional.
635 
636  Unless stated otherwise, values are assumed to be a simple/empty define.
637  @{
638  */
639 
640 /**
641  Whether to enable runtime plugin tests.@n
642  This will check, during initialization of the plugin, if parameters, programs and states are setup properly.@n
643  Useful to enable as part of CI, can safely be skipped.@n
644  Under DPF makefiles this can be enabled by using `make DPF_RUNTIME_TESTING=true`.
645 
646  @note Some checks are only available with the GCC compiler,
647  for detecting if a virtual function has been reimplemented.
648  */
649 #define DPF_RUNTIME_TESTING
650 
651 /**
652  Whether to show parameter outputs in the VST2 plugins.@n
653  This is disabled (unset) by default, as the VST2 format has no notion of read-only parameters.
654  */
655 #define DPF_VST_SHOW_PARAMETER_OUTPUTS
656 
657 /**
658  Whether to use OpenGL3 instead of the default OpenGL2 compatility profile.
659  Under DPF makefiles this can be enabled by using `make USE_OPENGL3=true` on the dgl build step.
660 
661  @note This is experimental and incomplete, contributions are welcome and appreciated.
662  */
663 #define DGL_USE_OPENGL3
664 
665 /**
666  Whether to use the GPLv2+ vestige header instead of the official Steinberg VST2 SDK.@n
667  This is a boolean, and enabled (set to 1) by default.@n
668  Set this to 0 in order to create non-GPL binaries.
669  (but then at your own discretion in regards to Steinberg licensing)@n
670  When set to 0, DPF will import the VST2 definitions from `"vst/aeffectx.h"` (not shipped with DPF).
671  */
672 #define VESTIGE_HEADER 1
673 
674 /** @} */
675 
676 // -----------------------------------------------------------------------------------------------------------
677 
678 END_NAMESPACE_DISTRHO
679 
680 #endif // DOXYGEN
String
Definition: String.hpp:30
Parameter::ranges
ParameterRanges ranges
Definition: DistrhoPlugin.hpp:491
Parameter
Definition: DistrhoPlugin.hpp:445
UI
Definition: DistrhoUI.hpp:71
ParameterRanges::def
float def
Definition: DistrhoPlugin.hpp:249
Parameter::name
String name
Definition: DistrhoPlugin.hpp:457
Parameter::symbol
String symbol
Definition: DistrhoPlugin.hpp:472
DISTRHO_PLUGIN_WANT_PROGRAMS
#define DISTRHO_PLUGIN_WANT_PROGRAMS
Definition: DistrhoInfo.hpp:556
Plugin
Definition: DistrhoPlugin.hpp:802
kParameterIsAutomable
static const uint32_t kParameterIsAutomable
Definition: DistrhoPlugin.hpp:90
Plugin::loadProgram
virtual void loadProgram(uint32_t index)
ParameterRanges::max
float max
Definition: DistrhoPlugin.hpp:259
ParameterRanges::min
float min
Definition: DistrhoPlugin.hpp:254
Parameter::hints
uint32_t hints
Definition: DistrhoPlugin.hpp:450