DISTRHO Plugin Framework
DistrhoInfo.hpp
1 /*
2  * DISTRHO Plugin Framework (DPF)
3  * Copyright (C) 2012-2019 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  * This example has no parameters, so skip parameter stuff */
111 
112  void initParameter(uint32_t, Parameter&) override {}
113  float getParameterValue(uint32_t) const override { return 0.0f; }
114  void setParameterValue(uint32_t, float) override {}
115 
116  /* ----------------------------------------------------------------------------------------
117  * Audio/MIDI Processing */
118 
119  /**
120  Run/process function for plugins without MIDI input.
121  NOTE: Some parameters might be null if there are no audio inputs or outputs.
122  */
123  void run(const float**, float** outputs, uint32_t frames) override
124  {
125  // get the left and right audio outputs
126  float* const outL = outputs[0];
127  float* const outR = outputs[1];
128 
129  // mute audio
130  std::memset(outL, 0, sizeof(float)*frames);
131  std::memset(outR, 0, sizeof(float)*frames);
132  }
133 
134  };
135  @endcode
136 
137  See the Plugin class for more information and to understand what each function does.
138 
139  @section Parameters
140  A plugin is nothing without parameters.@n
141  In DPF parameters can be inputs or outputs.@n
142  They have hints to describe how they behave plus a name and a symbol identifying them.@n
143  Parameters also have 'ranges' – a minimum, maximum and default value.
144 
145  Input parameters are "read-only": the plugin can read them but not change them.
146  (the exception being when changing programs, more on that below)@n
147  It's the host responsibility to save, restore and set input parameters.
148 
149  Output parameters can be changed at anytime by the plugin.@n
150  The host will simply read their values and not change them.
151 
152  Here's an example of an audio plugin that has 1 input parameter:
153  @code
154  class GainPlugin : public Plugin
155  {
156  public:
157  /**
158  Plugin class constructor.
159  You must set all parameter values to their defaults, matching ParameterRanges::def.
160  */
161  GainPlugin()
162  : Plugin(1, 0, 0), // 1 parameter, 0 programs and 0 states
163  fGain(1.0f)
164  {
165  }
166 
167  protected:
168  /* ----------------------------------------------------------------------------------------
169  * Information */
170 
171  const char* getLabel() const override
172  {
173  return "Gain";
174  }
175 
176  const char* getMaker() const override
177  {
178  return "DPF";
179  }
180 
181  const char* getLicense() const override
182  {
183  return "MIT";
184  }
185 
186  uint32_t getVersion() const override
187  {
188  return d_version(1, 0, 0);
189  }
190 
191  int64_t getUniqueId() const override
192  {
193  return d_cconst('G', 'a', 'i', 'n');
194  }
195 
196  /* ----------------------------------------------------------------------------------------
197  * Init */
198 
199  /**
200  Initialize a parameter.
201  This function will be called once, shortly after the plugin is created.
202  */
203  void initParameter(uint32_t index, Parameter& parameter) override
204  {
205  // we only have one parameter so we can skip checking the index
206 
207  parameter.hints = kParameterIsAutomable;
208  parameter.name = "Gain";
209  parameter.symbol = "gain";
210  parameter.ranges.min = 0.0f;
211  parameter.ranges.max = 2.0f;
212  parameter.ranges.def = 1.0f;
213  }
214 
215  /* ----------------------------------------------------------------------------------------
216  * Internal data */
217 
218  /**
219  Get the current value of a parameter.
220  */
221  float getParameterValue(uint32_t index) const override
222  {
223  // same as before, ignore index check
224 
225  return fGain;
226  }
227 
228  /**
229  Change a parameter value.
230  */
231  void setParameterValue(uint32_t index, float value) override
232  {
233  // same as before, ignore index check
234 
235  fGain = value;
236  }
237 
238  /* ----------------------------------------------------------------------------------------
239  * Audio/MIDI Processing */
240 
241  void run(const float**, float** outputs, uint32_t frames) override
242  {
243  // get the mono input and output
244  const float* const in = inputs[0];
245  /* */ float* const out = outputs[0];
246 
247  // apply gain against all samples
248  for (uint32_t i=0; i < frames; ++i)
249  out[i] = in[i] * fGain;
250  }
251 
252  private:
253  float fGain;
254  };
255  @endcode
256 
257  See the Parameter struct for more information about parameters.
258 
259  @section Programs
260  Programs in DPF refer to plugin-side presets (usually called "factory presets"),
261  an initial set of presets provided by plugin authors included in the actual plugin.
262 
263  To use programs you must first enable them by setting @ref DISTRHO_PLUGIN_WANT_PROGRAMS to 1 in your DistrhoPluginInfo.h file.@n
264  When enabled you'll need to override 2 new function in your plugin code,
265  Plugin::initProgramName(uint32_t, String&) and Plugin::loadProgram(uint32_t).
266 
267  Here's an example of a plugin with a "default" program:
268  @code
269  class PluginWithPresets : public Plugin
270  {
271  public:
272  PluginWithPresets()
273  : Plugin(2, 1, 0), // 2 parameters, 1 program and 0 states
274  fGainL(1.0f),
275  fGainR(1.0f),
276  {
277  }
278 
279  protected:
280  /* ----------------------------------------------------------------------------------------
281  * Information */
282 
283  const char* getLabel() const override
284  {
285  return "Prog";
286  }
287 
288  const char* getMaker() const override
289  {
290  return "DPF";
291  }
292 
293  const char* getLicense() const override
294  {
295  return "MIT";
296  }
297 
298  uint32_t getVersion() const override
299  {
300  return d_version(1, 0, 0);
301  }
302 
303  int64_t getUniqueId() const override
304  {
305  return d_cconst('P', 'r', 'o', 'g');
306  }
307 
308  /* ----------------------------------------------------------------------------------------
309  * Init */
310 
311  /**
312  Initialize a parameter.
313  This function will be called once, shortly after the plugin is created.
314  */
315  void initParameter(uint32_t index, Parameter& parameter) override
316  {
317  parameter.hints = kParameterIsAutomable;
318  parameter.ranges.min = 0.0f;
319  parameter.ranges.max = 2.0f;
320  parameter.ranges.def = 1.0f;
321 
322  switch (index)
323  {
324  case 0;
325  parameter.name = "Gain Right";
326  parameter.symbol = "gainR";
327  break;
328  case 1;
329  parameter.name = "Gain Left";
330  parameter.symbol = "gainL";
331  break;
332  }
333  }
334 
335  /**
336  Set the name of the program @a index.
337  This function will be called once, shortly after the plugin is created.
338  */
339  void initProgramName(uint32_t index, String& programName)
340  {
341  switch(index)
342  {
343  case 0:
344  programName = "Default";
345  break;
346  }
347  }
348 
349  /* ----------------------------------------------------------------------------------------
350  * Internal data */
351 
352  /**
353  Get the current value of a parameter.
354  */
355  float getParameterValue(uint32_t index) const override
356  {
357  switch (index)
358  {
359  case 0;
360  return fGainL;
361  case 1;
362  return fGainR;
363  }
364  }
365 
366  /**
367  Change a parameter value.
368  */
369  void setParameterValue(uint32_t index, float value) override
370  {
371  switch (index)
372  {
373  case 0;
374  fGainL = value;
375  break;
376  case 1;
377  fGainR = value;
378  break;
379  }
380  }
381 
382  /**
383  Load a program.
384  */
385  void loadProgram(uint32_t index)
386  {
387  switch(index)
388  {
389  case 0:
390  fGainL = 1.0f;
391  fGainR = 1.0f;
392  break;
393  }
394  }
395 
396  /* ----------------------------------------------------------------------------------------
397  * Audio/MIDI Processing */
398 
399  void run(const float**, float** outputs, uint32_t frames) override
400  {
401  // get the left and right audio buffers
402  const float* const inL = inputs[0];
403  const float* const inR = inputs[0];
404  /* */ float* const outL = outputs[0];
405  /* */ float* const outR = outputs[0];
406 
407  // apply gain against all samples
408  for (uint32_t i=0; i < frames; ++i)
409  {
410  outL[i] = inL[i] * fGainL;
411  outR[i] = inR[i] * fGainR;
412  }
413  }
414 
415  private:
416  float fGainL, fGainR;
417  };
418  @endcode
419 
420  This is a work-in-progress documentation page. States, MIDI, Latency, Time-Position and UI are still TODO.
421 */
422 
423 #if 0
424  @section States
425  describe them
426 
427  @section MIDI
428  describe them
429 
430  @section Latency
431  describe it
432 
433  @section Time-Position
434  describe it
435 
436  @section UI
437  describe them
438 #endif
439 
440 /* ------------------------------------------------------------------------------------------------------------
441  * Plugin Macros */
442 
443 /**
444  @defgroup PluginMacros Plugin Macros
445 
446  C Macros that describe your plugin. (defined in the "DistrhoPluginInfo.h" file)
447 
448  With these macros you can tell the host what features your plugin requires.@n
449  Depending on which macros you enable, new functions will be available to call and/or override.
450 
451  All values are either integer or strings.@n
452  For boolean-like values 1 means 'on' and 0 means 'off'.
453 
454  The values defined in this group are for documentation purposes only.@n
455  All macros are disabled by default.
456 
457  Only 4 macros are required, they are:
458  - @ref DISTRHO_PLUGIN_NAME
459  - @ref DISTRHO_PLUGIN_NUM_INPUTS
460  - @ref DISTRHO_PLUGIN_NUM_OUTPUTS
461  - @ref DISTRHO_PLUGIN_URI
462  @{
463  */
464 
465 /**
466  The plugin name.@n
467  This is used to identify your plugin before a Plugin instance can be created.
468  @note This macro is required.
469  */
470 #define DISTRHO_PLUGIN_NAME "Plugin Name"
471 
472 /**
473  Number of audio inputs the plugin has.
474  @note This macro is required.
475  */
476 #define DISTRHO_PLUGIN_NUM_INPUTS 2
477 
478 /**
479  Number of audio outputs the plugin has.
480  @note This macro is required.
481  */
482 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2
483 
484 /**
485  The plugin URI when exporting in LV2 format.
486  @note This macro is required.
487  */
488 #define DISTRHO_PLUGIN_URI "urn:distrho:name"
489 
490 /**
491  Whether the plugin has a custom %UI.
492  @see DISTRHO_UI_USE_NANOVG
493  @see UI
494  */
495 #define DISTRHO_PLUGIN_HAS_UI 1
496 
497 /**
498  Whether the plugin processing is realtime-safe.@n
499  TODO - list rtsafe requirements
500  */
501 #define DISTRHO_PLUGIN_IS_RT_SAFE 1
502 
503 /**
504  Whether the plugin is a synth.@n
505  @ref DISTRHO_PLUGIN_WANT_MIDI_INPUT is automatically enabled when this is too.
506  @see DISTRHO_PLUGIN_WANT_MIDI_INPUT
507  */
508 #define DISTRHO_PLUGIN_IS_SYNTH 1
509 
510 /**
511  Enable direct access between the %UI and plugin code.
512  @see UI::getPluginInstancePointer()
513  @note DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
514  Try to avoid it at all costs!
515  */
516 #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
517 
518 /**
519  Whether the plugin introduces latency during audio or midi processing.
520  @see Plugin::setLatency(uint32_t)
521  */
522 #define DISTRHO_PLUGIN_WANT_LATENCY 1
523 
524 /**
525  Whether the plugin wants MIDI input.@n
526  This is automatically enabled if @ref DISTRHO_PLUGIN_IS_SYNTH is true.
527  */
528 #define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
529 
530 /**
531  Whether the plugin wants MIDI output.
532  @see Plugin::writeMidiEvent(const MidiEvent&)
533  */
534 #define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
535 
536 /**
537  Whether the plugin wants to change its own parameter inputs.@n
538  Not all hosts or plugin formats support this,
539  so Plugin::canRequestParameterValueChanges() can be used to query support at runtime.
540  @see Plugin::requestParameterValueChange(uint32_t, float)
541  */
542 #define DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST 1
543 
544 /**
545  Whether the plugin provides its own internal programs.
546  @see Plugin::initProgramName(uint32_t, String&)
547  @see Plugin::loadProgram(uint32_t)
548  */
549 #define DISTRHO_PLUGIN_WANT_PROGRAMS 1
550 
551 /**
552  Whether the plugin uses internal non-parameter data.
553  @see Plugin::initState(uint32_t, String&, String&)
554  @see Plugin::setState(const char*, const char*)
555  */
556 #define DISTRHO_PLUGIN_WANT_STATE 1
557 
558 /**
559  Whether the plugin implements the full state API.
560  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.
561  This is useful for plugins that have custom internal values not exposed to the host as key-value state pairs or parameters.
562  Most simple effects and synths will not need this.
563  @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.
564  @see Plugin::getState(const char*)
565  */
566 #define DISTRHO_PLUGIN_WANT_FULL_STATE 1
567 
568 /**
569  Whether the plugin wants time position information from the host.
570  @see Plugin::getTimePosition()
571  */
572 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1
573 
574 /**
575  Whether the %UI uses a custom toolkit implementation based on OpenGL.@n
576  When enabled, the macros @ref DISTRHO_UI_CUSTOM_INCLUDE_PATH and @ref DISTRHO_UI_CUSTOM_WIDGET_TYPE are required.
577  */
578 #define DISTRHO_UI_USE_CUSTOM 1
579 
580 /**
581  The include path to the header file used by the custom toolkit implementation.
582  This path must be relative to dpf/distrho/DistrhoUI.hpp
583  @see DISTRHO_UI_USE_CUSTOM
584  */
585 #define DISTRHO_UI_CUSTOM_INCLUDE_PATH
586 
587 /**
588  The top-level-widget typedef to use for the custom toolkit.
589  This widget class MUST be a subclass of DGL TopLevelWindow class.
590  It is recommended that you keep this widget class inside the DGL namespace,
591  and define widget type as e.g. DGL_NAMESPACE::MyCustomTopLevelWidget.
592  @see DISTRHO_UI_USE_CUSTOM
593  */
594 #define DISTRHO_UI_CUSTOM_WIDGET_TYPE
595 
596 /**
597  Whether the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
598  When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
599  */
600 #define DISTRHO_UI_USE_NANOVG 1
601 
602 /**
603  Whether the %UI is resizable to any size by the user.@n
604  By default this is false, and resizing is only allowed under the plugin UI control,@n
605  Enabling this options makes it possible for the user to resize the plugin UI at anytime.
606  @see UI::setGeometryConstraints(uint, uint, bool, bool)
607  */
608 #define DISTRHO_UI_USER_RESIZABLE 1
609 
610 /**
611  The %UI URI when exporting in LV2 format.@n
612  By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
613  */
614 #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
615 
616 /** @} */
617 
618 // -----------------------------------------------------------------------------------------------------------
619 
620 END_NAMESPACE_DISTRHO
621 
622 #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
Plugin::loadProgram
virtual void loadProgram(uint32_t index)=0
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:549
Plugin
Definition: DistrhoPlugin.hpp:802
kParameterIsAutomable
static const uint32_t kParameterIsAutomable
Definition: DistrhoPlugin.hpp:90
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