DISTRHO Plugin Framework
 All Classes Functions Variables Modules Pages
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 "Mute";
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('M', 'u', 't', 'e');
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  }
212 
213  /* ----------------------------------------------------------------------------------------
214  * Internal data */
215 
216  /**
217  Get the current value of a parameter.
218  */
219  float getParameterValue(uint32_t index) const override
220  {
221  // same as before, ignore index check
222 
223  return fGain;
224  }
225 
226  /**
227  Change a parameter value.
228  */
229  void setParameterValue(uint32_t index, float value) override
230  {
231  // same as before, ignore index check
232 
233  fGain = value;
234  }
235 
236  /* ----------------------------------------------------------------------------------------
237  * Audio/MIDI Processing */
238 
239  void run(const float**, float** outputs, uint32_t frames) override
240  {
241  // get the mono input and output
242  const float* const in = inputs[0];
243  /* */ float* const out = outputs[0];
244 
245  // apply gain against all samples
246  for (uint32_t i=0; i < frames; ++i)
247  out[i] = in[i] * fGain;
248  }
249  };
250  @endcode
251 
252  See the Parameter struct for more information about parameters.
253 
254  @section Programs
255  describe them
256 
257  @section States
258  describe them
259 
260  @section MIDI
261  describe them
262 
263  @section Latency
264  describe it
265 
266  @section Time-Position
267  describe it
268 
269  @section UI
270  describe them
271 */
272 
273 /* ------------------------------------------------------------------------------------------------------------
274  * Plugin Macros */
275 
276 /**
277  @defgroup PluginMacros Plugin Macros
278 
279  C Macros that describe your plugin. (defined in the "DistrhoPluginInfo.h" file)
280 
281  With these macros you can tell the host what features your plugin requires.@n
282  Depending on which macros you enable, new functions will be available to call and/or override.
283 
284  All values are either integer or strings.@n
285  For boolean-like values 1 means 'on' and 0 means 'off'.
286 
287  The values defined in this group are for documentation purposes only.@n
288  All macros are disabled by default.
289 
290  Only 4 macros are required, they are:
291  - @ref DISTRHO_PLUGIN_NAME
292  - @ref DISTRHO_PLUGIN_NUM_INPUTS
293  - @ref DISTRHO_PLUGIN_NUM_OUTPUTS
294  - @ref DISTRHO_PLUGIN_URI
295  @{
296  */
297 
298 /**
299  The plugin name.@n
300  This is used to identify your plugin before a Plugin instance can be created.
301  @note This macro is required.
302  */
303 #define DISTRHO_PLUGIN_NAME "Plugin Name"
304 
305 /**
306  Number of audio inputs the plugin has.
307  @note This macro is required.
308  */
309 #define DISTRHO_PLUGIN_NUM_INPUTS 2
310 
311 /**
312  Number of audio outputs the plugin has.
313  @note This macro is required.
314  */
315 #define DISTRHO_PLUGIN_NUM_OUTPUTS 2
316 
317 /**
318  The plugin URI when exporting in LV2 format.
319  @note This macro is required.
320  */
321 #define DISTRHO_PLUGIN_URI "urn:distrho:name"
322 
323 /**
324  Wherever the plugin has a custom %UI.
325  @see DISTRHO_UI_USE_NANOVG
326  @see UI
327  */
328 #define DISTRHO_PLUGIN_HAS_UI 1
329 
330 /**
331  Wherever the plugin processing is realtime-safe.@n
332  TODO - list rtsafe requirements
333  */
334 #define DISTRHO_PLUGIN_IS_RT_SAFE 1
335 
336 /**
337  Wherever the plugin is a synth.@n
338  @ref DISTRHO_PLUGIN_WANT_MIDI_INPUT is automatically enabled when this is too.
339  @see DISTRHO_PLUGIN_WANT_MIDI_INPUT
340  */
341 #define DISTRHO_PLUGIN_IS_SYNTH 1
342 
343 /**
344  Enable direct access between the %UI and plugin code.
345  @see UI::getPluginInstancePointer()
346  @note DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
347  Try to avoid it at all costs!
348  */
349 #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
350 
351 /**
352  Wherever the plugin introduces latency during audio or midi processing.
353  @see Plugin::setLatency(uint32_t)
354  */
355 #define DISTRHO_PLUGIN_WANT_LATENCY 1
356 
357 /**
358  Wherever the plugin wants MIDI input.@n
359  This is automatically enabled if @ref DISTRHO_PLUGIN_IS_SYNTH is true.
360  */
361 #define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
362 
363 /**
364  Wherever the plugin wants MIDI output.
365  @see Plugin::writeMidiEvent(const MidiEvent&)
366  */
367 #define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
368 
369 /**
370  Wherever the plugin provides its own internal programs.
371  @see Plugin::initProgramName(uint32_t, String&)
372  @see Plugin::setProgram(uint32_t)
373  */
374 #define DISTRHO_PLUGIN_WANT_PROGRAMS 1
375 
376 /**
377  Wherever the plugin uses internal non-parameter data.
378  @see Plugin::initState(uint32_t, String&, String&)
379  @see Plugin::setState(const char*, const char*)
380  */
381 #define DISTRHO_PLUGIN_WANT_STATE 1
382 
383 /**
384  Wherever the plugin wants time position information from the host.
385  @see Plugin::getTimePosition()
386  */
387 #define DISTRHO_PLUGIN_WANT_TIMEPOS 1
388 
389 /**
390  Wherever the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
391  When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
392  */
393 #define DISTRHO_UI_USE_NANOVG 1
394 
395 /**
396  The %UI URI when exporting in LV2 format.@n
397  By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
398  */
399 #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
400 
401 /** @} */
402 
403 // -----------------------------------------------------------------------------------------------------------
404 
405 END_NAMESPACE_DISTRHO
406 
407 #endif // DOXYGEN