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