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  @section States
421  describe them
422 
423  @section MIDI
424  describe them
425 
426  @section Latency
427  describe it
428 
429  @section Time-Position
430  describe it
431 
432  @section UI
433  describe them
434 */
435 
436 /* ------------------------------------------------------------------------------------------------------------
437  * Plugin Macros */
438 
439 /**
440  @defgroup PluginMacros Plugin Macros
441 
442  C Macros that describe your plugin. (defined in the "DistrhoPluginInfo.h" file)
443 
444  With these macros you can tell the host what features your plugin requires.@n
445  Depending on which macros you enable, new functions will be available to call and/or override.
446 
447  All values are either integer or strings.@n
448  For boolean-like values 1 means 'on' and 0 means 'off'.
449 
450  The values defined in this group are for documentation purposes only.@n
451  All macros are disabled by default.
452 
453  Only 4 macros are required, they are:
454  - @ref DISTRHO_PLUGIN_NAME
455  - @ref DISTRHO_PLUGIN_NUM_INPUTS
456  - @ref DISTRHO_PLUGIN_NUM_OUTPUTS
457  - @ref DISTRHO_PLUGIN_URI
458  @{
459  */
460 
461 /**
462  The plugin name.@n
463  This is used to identify your plugin before a Plugin instance can be created.
464  @note This macro is required.
465  */
466 #define DISTRHO_PLUGIN_NAME "Plugin Name"
467 
468 /**
469  Number of audio inputs the plugin has.
470  @note This macro is required.
471  */
472 #define DISTRHO_PLUGIN_NUM_INPUTS 2
473 
474 /**
475  Number of audio outputs the plugin has.
476  @note This macro is required.
477  */
478 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2
479 
480 /**
481  The plugin URI when exporting in LV2 format.
482  @note This macro is required.
483  */
484 #define DISTRHO_PLUGIN_URI "urn:distrho:name"
485 
486 /**
487  Wherever the plugin has a custom %UI.
488  @see DISTRHO_UI_USE_NANOVG
489  @see UI
490  */
491 #define DISTRHO_PLUGIN_HAS_UI 1
492 
493 /**
494  Wherever the plugin processing is realtime-safe.@n
495  TODO - list rtsafe requirements
496  */
497 #define DISTRHO_PLUGIN_IS_RT_SAFE 1
498 
499 /**
500  Wherever the plugin is a synth.@n
501  @ref DISTRHO_PLUGIN_WANT_MIDI_INPUT is automatically enabled when this is too.
502  @see DISTRHO_PLUGIN_WANT_MIDI_INPUT
503  */
504 #define DISTRHO_PLUGIN_IS_SYNTH 1
505 
506 /**
507  Enable direct access between the %UI and plugin code.
508  @see UI::getPluginInstancePointer()
509  @note DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
510  Try to avoid it at all costs!
511  */
512 #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
513 
514 /**
515  Wherever the plugin introduces latency during audio or midi processing.
516  @see Plugin::setLatency(uint32_t)
517  */
518 #define DISTRHO_PLUGIN_WANT_LATENCY 1
519 
520 /**
521  Wherever the plugin wants MIDI input.@n
522  This is automatically enabled if @ref DISTRHO_PLUGIN_IS_SYNTH is true.
523  */
524 #define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
525 
526 /**
527  Wherever the plugin wants MIDI output.
528  @see Plugin::writeMidiEvent(const MidiEvent&)
529  */
530 #define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
531 
532 /**
533  Wherever the plugin provides its own internal programs.
534  @see Plugin::initProgramName(uint32_t, String&)
535  @see Plugin::loadProgram(uint32_t)
536  */
537 #define DISTRHO_PLUGIN_WANT_PROGRAMS 1
538 
539 /**
540  Wherever the plugin uses internal non-parameter data.
541  @see Plugin::initState(uint32_t, String&, String&)
542  @see Plugin::setState(const char*, const char*)
543  */
544 #define DISTRHO_PLUGIN_WANT_STATE 1
545 
546 /**
547  Wherever the plugin implements the full state API.
548  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.
549  This is useful for plugins that have custom internal values not exposed to the host as key-value state pairs or parameters.
550  Most simple effects and synths will not need this.
551  @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.
552  @see Plugin::getState(const char*)
553  */
554 #define DISTRHO_PLUGIN_WANT_FULL_STATE 1
555 
556 /**
557  Wherever the plugin wants time position information from the host.
558  @see Plugin::getTimePosition()
559  */
560 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1
561 
562 /**
563  Wherever the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
564  When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
565  */
566 #define DISTRHO_UI_USE_NANOVG 1
567 
568 /**
569  Wherever the %UI is resizable to any size by the user.@n
570  By default this is false, and resizing is only allowed under the plugin UI control,@n
571  Enabling this options makes it possible for the user to resize the plugin UI at anytime.
572  @see UI::setGeometryConstraints(uint, uint, bool, bool)
573  */
574 #define DISTRHO_UI_USER_RESIZABLE 1
575 
576 /**
577  The %UI URI when exporting in LV2 format.@n
578  By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
579  */
580 #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
581 
582 /** @} */
583 
584 // -----------------------------------------------------------------------------------------------------------
585 
586 END_NAMESPACE_DISTRHO
587 
588 #endif // DOXYGEN