DISTRHO Plugin Framework
DistrhoPlugin.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 #ifndef DISTRHO_PLUGIN_HPP_INCLUDED
18 #define DISTRHO_PLUGIN_HPP_INCLUDED
19 
20 #include "extra/String.hpp"
21 #include "extra/LeakDetector.hpp"
22 #include "src/DistrhoPluginChecks.h"
23 
24 START_NAMESPACE_DISTRHO
25 
26 /* ------------------------------------------------------------------------------------------------------------
27  * Audio Port Hints */
28 
29 /**
30  @defgroup AudioPortHints Audio Port Hints
31 
32  Various audio port hints.
33  @see AudioPort::hints
34  @{
35  */
36 
37 /**
38  Audio port can be used as control voltage (LV2 and JACK standalone only).
39  */
40 static const uint32_t kAudioPortIsCV = 0x1;
41 
42 /**
43  Audio port should be used as sidechan (LV2 only).
44  */
45 static const uint32_t kAudioPortIsSidechain = 0x2;
46 
47 /**
48  CV port has bipolar range (-1 to +1, or -5 to +5 if scaled).
49  This is merely a hint to tell the host what value range to expect.
50  */
51 static const uint32_t kCVPortHasBipolarRange = 0x10;
52 
53 /**
54  CV port has negative unipolar range (-1 to 0, or -10 to 0 if scaled).
55  This is merely a hint to tell the host what value range to expect.
56  */
57 static const uint32_t kCVPortHasNegativeUnipolarRange = 0x20;
58 
59 /**
60  CV port has positive unipolar range (0 to +1, or 0 to +10 if scaled).
61  This is merely a hint to tell the host what value range to expect.
62  */
63 static const uint32_t kCVPortHasPositiveUnipolarRange = 0x40;
64 
65 /**
66  CV port has scaled range to match real values (-5 to +5v bipolar, +/-10 to 0v unipolar).
67  One other range flag is required if this flag is set.
68 
69  When enabled, this makes the port a mod:CVPort, compatible with the MOD Devices platform.
70  */
71 static const uint32_t kCVPortHasScaledRange = 0x80;
72 
73 /** @} */
74 
75 /* ------------------------------------------------------------------------------------------------------------
76  * Parameter Hints */
77 
78 /**
79  @defgroup ParameterHints Parameter Hints
80 
81  Various parameter hints.
82  @see Parameter::hints
83  @{
84  */
85 
86 /**
87  Parameter is automable (real-time safe).
88  @see Plugin::setParameterValue(uint32_t, float)
89  */
90 static const uint32_t kParameterIsAutomable = 0x01;
91 
92 /**
93  Parameter value is boolean.@n
94  It's always at either minimum or maximum value.
95  */
96 static const uint32_t kParameterIsBoolean = 0x02;
97 
98 /**
99  Parameter value is integer.
100  */
101 static const uint32_t kParameterIsInteger = 0x04;
102 
103 /**
104  Parameter value is logarithmic.
105  */
106 static const uint32_t kParameterIsLogarithmic = 0x08;
107 
108 /**
109  Parameter is of output type.@n
110  When unset, parameter is assumed to be of input type.
111 
112  Parameter inputs are changed by the host and typically should not be changed by the plugin.@n
113  One exception is when changing programs, see Plugin::loadProgram().@n
114  The other exception is with parameter change requests, see Plugin::requestParameterValueChange().@n
115  Outputs are changed by the plugin and never modified by the host.
116 
117  If you are targetting VST2, make sure to order your parameters so that all inputs are before any outputs.
118  */
119 static const uint32_t kParameterIsOutput = 0x10;
120 
121 /**
122  Parameter value is a trigger.@n
123  This means the value resets back to its default after each process/run call.@n
124  Cannot be used for output parameters.
125 
126  @note Only officially supported under LV2. For other formats DPF simulates the behaviour.
127 */
128 static const uint32_t kParameterIsTrigger = 0x20 | kParameterIsBoolean;
129 
130 /** @} */
131 
132 /* ------------------------------------------------------------------------------------------------------------
133  * Base Plugin structs */
134 
135 /**
136  @defgroup BasePluginStructs Base Plugin Structs
137  @{
138  */
139 
140 /**
141  Parameter designation.@n
142  Allows a parameter to be specially designated for a task, like bypass.
143 
144  Each designation is unique, there must be only one parameter that uses it.@n
145  The use of designated parameters is completely optional.
146 
147  @note Designated parameters have strict ranges.
148  @see ParameterRanges::adjustForDesignation()
149  */
151  /**
152  Null or unset designation.
153  */
155 
156  /**
157  Bypass designation.@n
158  When on (> 0.5f), it means the plugin must run in a bypassed state.
159  */
161 };
162 
163 /**
164  Predefined Port Groups Ids.
165 
166  This enumeration provides a few commonly used groups for convenient use in plugins.
167  For preventing conflicts with user code, negative values are used here.
168  When rolling your own port groups, you MUST start their group ids from 0 and they MUST be sequential.
169 
170  @see PortGroup
171  */
173  /**
174  Null or unset port group.
175  */
176  kPortGroupNone = (uint32_t)-1,
177 
178  /**
179  A single channel audio group.
180  */
181  kPortGroupMono = (uint32_t)-2,
182 
183  /**
184  A 2-channel discrete stereo audio group,
185  where the 1st audio port is the left channel and the 2nd port is the right channel.
186  */
187  kPortGroupStereo = (uint32_t)-3
188 };
189 
190 /**
191  Audio Port.
192 
193  Can be used as CV port by specifying kAudioPortIsCV in hints,@n
194  but this is only supported in LV2 and JACK standalone formats.
195  */
196 struct AudioPort {
197  /**
198  Hints describing this audio port.
199  @see AudioPortHints
200  */
201  uint32_t hints;
202 
203  /**
204  The name of this audio port.@n
205  An audio port name can contain any character, but hosts might have a hard time with non-ascii ones.@n
206  The name doesn't have to be unique within a plugin instance, but it's recommended.
207  */
209 
210  /**
211  The symbol of this audio port.@n
212  An audio port symbol is a short restricted name used as a machine and human readable identifier.@n
213  The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9.
214  @note Audio port and parameter symbols MUST be unique within a plugin instance.
215  */
217 
218  /**
219  The group id that this audio/cv port belongs to.
220  No group is assigned by default.
221 
222  You can use a group from PredefinedPortGroups or roll your own.@n
223  When rolling your own port groups, you MUST start their group ids from 0 and they MUST be sequential.
224  @see PortGroup, Plugin::initPortGroup
225  */
226  uint32_t groupId;
227 
228  /**
229  Default constructor for a regular audio port.
230  */
231  AudioPort() noexcept
232  : hints(0x0),
233  name(),
234  symbol(),
236 };
237 
238 /**
239  Parameter ranges.@n
240  This is used to set the default, minimum and maximum values of a parameter.
241 
242  By default a parameter has 0.0 as minimum, 1.0 as maximum and 0.0 as default.@n
243  When changing this struct values you must ensure maximum > minimum and default is within range.
244  */
246  /**
247  Default value.
248  */
249  float def;
250 
251  /**
252  Minimum value.
253  */
254  float min;
255 
256  /**
257  Maximum value.
258  */
259  float max;
260 
261  /**
262  Default constructor, using 0.0 as default, 0.0 as minimum, 1.0 as maximum.
263  */
264  ParameterRanges() noexcept
265  : def(0.0f),
266  min(0.0f),
267  max(1.0f) {}
268 
269  /**
270  Constructor using custom values.
271  */
272  ParameterRanges(float df, float mn, float mx) noexcept
273  : def(df),
274  min(mn),
275  max(mx) {}
276 
277  /**
278  Fix the default value within range.
279  */
280  void fixDefault() noexcept
281  {
282  fixValue(def);
283  }
284 
285  /**
286  Fix a value within range.
287  */
288  void fixValue(float& value) const noexcept
289  {
290  if (value < min)
291  value = min;
292  else if (value > max)
293  value = max;
294  }
295 
296  /**
297  Get a fixed value within range.
298  */
299  float getFixedValue(const float& value) const noexcept
300  {
301  if (value <= min)
302  return min;
303  if (value >= max)
304  return max;
305  return value;
306  }
307 
308  /**
309  Get a value normalized to 0.0<->1.0.
310  */
311  float getNormalizedValue(const float& value) const noexcept
312  {
313  const float normValue((value - min) / (max - min));
314 
315  if (normValue <= 0.0f)
316  return 0.0f;
317  if (normValue >= 1.0f)
318  return 1.0f;
319  return normValue;
320  }
321 
322  /**
323  Get a value normalized to 0.0<->1.0, fixed within range.
324  */
325  float getFixedAndNormalizedValue(const float& value) const noexcept
326  {
327  if (value <= min)
328  return 0.0f;
329  if (value >= max)
330  return 1.0f;
331 
332  const float normValue((value - min) / (max - min));
333 
334  if (normValue <= 0.0f)
335  return 0.0f;
336  if (normValue >= 1.0f)
337  return 1.0f;
338 
339  return normValue;
340  }
341 
342  /**
343  Get a proper value previously normalized to 0.0<->1.0.
344  */
345  float getUnnormalizedValue(const float& value) const noexcept
346  {
347  if (value <= 0.0f)
348  return min;
349  if (value >= 1.0f)
350  return max;
351 
352  return value * (max - min) + min;
353  }
354 };
355 
356 /**
357  Parameter enumeration value.@n
358  A string representation of a plugin parameter value.@n
359  Used together can be used to give meaning to parameter values, working as an enumeration.
360  */
362  /**
363  Parameter value.
364  */
365  float value;
366 
367  /**
368  String representation of this value.
369  */
371 
372  /**
373  Default constructor, using 0.0 as value and empty label.
374  */
376  : value(0.0f),
377  label() {}
378 
379  /**
380  Constructor using custom values.
381  */
382  ParameterEnumerationValue(float v, const char* l) noexcept
383  : value(v),
384  label(l) {}
385 };
386 
387 /**
388  Collection of parameter enumeration values.@n
389  Handy class to handle the lifetime and count of all enumeration values.
390  */
392  /**
393  Number of elements allocated in @values.
394  */
395  uint8_t count;
396 
397  /**
398  Wherever the host is to be restricted to only use enumeration values.
399 
400  @note This mode is only a hint! Not all hosts and plugin formats support this mode.
401  */
403 
404  /**
405  Array of @ParameterEnumerationValue items.@n
406  This pointer must be null or have been allocated on the heap with `new ParameterEnumerationValue[count]`.
407  */
409 
410  /**
411  Default constructor, for zero enumeration values.
412  */
414  : count(0),
415  restrictedMode(false),
416  values() {}
417 
418  /**
419  Constructor using custom values.@n
420  The pointer to @values must have been allocated on the heap with `new`.
421  */
422  ParameterEnumerationValues(uint32_t c, bool r, const ParameterEnumerationValue* v) noexcept
423  : count(c),
424  restrictedMode(r),
425  values(v) {}
426 
427  ~ParameterEnumerationValues() noexcept
428  {
429  count = 0;
430  restrictedMode = false;
431 
432  if (values != nullptr)
433  {
434  delete[] values;
435  values = nullptr;
436  }
437  }
438 
439  DISTRHO_DECLARE_NON_COPYABLE(ParameterEnumerationValues)
440 };
441 
442 /**
443  Parameter.
444  */
445 struct Parameter {
446  /**
447  Hints describing this parameter.
448  @see ParameterHints
449  */
450  uint32_t hints;
451 
452  /**
453  The name of this parameter.@n
454  A parameter name can contain any character, but hosts might have a hard time with non-ascii ones.@n
455  The name doesn't have to be unique within a plugin instance, but it's recommended.
456  */
458 
459  /**
460  The short name of this parameter.@n
461  Used when displaying the parameter name in a very limited space.
462  @note This value is optional, the full name is used when the short one is missing.
463  */
465 
466  /**
467  The symbol of this parameter.@n
468  A parameter symbol is a short restricted name used as a machine and human readable identifier.@n
469  The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9.
470  @note Parameter symbols MUST be unique within a plugin instance.
471  */
473 
474  /**
475  The unit of this parameter.@n
476  This means something like "dB", "kHz" and "ms".@n
477  Can be left blank if a unit does not apply to this parameter.
478  */
480 
481  /**
482  An extensive description/comment about the parameter.
483  @note This value is optional and only used for LV2.
484  */
486 
487  /**
488  Ranges of this parameter.@n
489  The ranges describe the default, minimum and maximum values.
490  */
492 
493  /**
494  Enumeration values.@n
495  Can be used to give meaning to parameter values, working as an enumeration.
496  */
498 
499  /**
500  Designation for this parameter.
501  */
503 
504  /**
505  MIDI CC to use by default on this parameter.@n
506  A value of 0 or 32 (bank change) is considered invalid.@n
507  Must also be less or equal to 120.
508  @note This value is only a hint! Hosts might map it automatically or completely ignore it.
509  */
510  uint8_t midiCC;
511 
512  /**
513  The group id that this parameter belongs to.
514  No group is assigned by default.
515 
516  You can use a group from PredefinedPortGroups or roll your own.@n
517  When rolling your own port groups, you MUST start their group ids from 0 and they MUST be sequential.
518  @see PortGroup, Plugin::initPortGroup
519  */
520  uint32_t groupId;
521 
522  /**
523  Default constructor for a null parameter.
524  */
525  Parameter() noexcept
526  : hints(0x0),
527  name(),
528  shortName(),
529  symbol(),
530  unit(),
531  ranges(),
532  enumValues(),
534  midiCC(0),
536 
537  /**
538  Constructor using custom values.
539  */
540  Parameter(uint32_t h, const char* n, const char* s, const char* u, float def, float min, float max) noexcept
541  : hints(h),
542  name(n),
543  shortName(),
544  symbol(s),
545  unit(u),
546  ranges(def, min, max),
547  enumValues(),
549  midiCC(0),
551 
552  /**
553  Initialize a parameter for a specific designation.
554  */
556  {
557  designation = d;
558 
559  switch (d)
560  {
562  break;
565  name = "Bypass";
566  shortName = "Bypass";
567  symbol = "dpf_bypass";
568  unit = "";
569  midiCC = 0;
571  ranges.def = 0.0f;
572  ranges.min = 0.0f;
573  ranges.max = 1.0f;
574  break;
575  }
576  }
577 };
578 
579 /**
580  Port Group.@n
581  Allows to group together audio/cv ports or parameters.
582 
583  Each unique group MUST have an unique symbol and a name.
584  A group can be applied to both inputs and outputs (at the same time).
585  The same group cannot be used in audio ports and parameters.
586 
587  An audio port group logically combines ports which should be considered part of the same stream.@n
588  For example, two audio ports in a group may form a stereo stream.
589 
590  A parameter group provides meta-data to the host to indicate that some parameters belong together.
591 
592  The use of port groups is completely optional.
593 
594  @see Plugin::initPortGroup, AudioPort::group, Parameter::group
595  */
596 struct PortGroup {
597  /**
598  The name of this port group.@n
599  A port group name can contain any character, but hosts might have a hard time with non-ascii ones.@n
600  The name doesn't have to be unique within a plugin instance, but it's recommended.
601  */
603 
604  /**
605  The symbol of this port group.@n
606  A port group symbol is a short restricted name used as a machine and human readable identifier.@n
607  The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9.
608  @note Port group symbols MUST be unique within a plugin instance.
609  */
611 };
612 
613 /**
614  MIDI event.
615  */
616 struct MidiEvent {
617  /**
618  Size of internal data.
619  */
620  static const uint32_t kDataSize = 4;
621 
622  /**
623  Time offset in frames.
624  */
625  uint32_t frame;
626 
627  /**
628  Number of bytes used.
629  */
630  uint32_t size;
631 
632  /**
633  MIDI data.@n
634  If size > kDataSize, dataExt is used (otherwise null).
635  */
636  uint8_t data[kDataSize];
637  const uint8_t* dataExt;
638 };
639 
640 /**
641  Time position.@n
642  The @a playing and @a frame values are always valid.@n
643  BBT values are only valid when @a bbt.valid is true.
644 
645  This struct is inspired by the [JACK Transport API](https://jackaudio.org/api/structjack__position__t.html).
646  */
647 struct TimePosition {
648  /**
649  Wherever the host transport is playing/rolling.
650  */
651  bool playing;
652 
653  /**
654  Current host transport position in frames.
655  */
656  uint64_t frame;
657 
658  /**
659  Bar-Beat-Tick time position.
660  */
661  struct BarBeatTick {
662  /**
663  Wherever the host transport is using BBT.@n
664  If false you must not read from this struct.
665  */
666  bool valid;
667 
668  /**
669  Current bar.@n
670  Should always be > 0.@n
671  The first bar is bar '1'.
672  */
673  int32_t bar;
674 
675  /**
676  Current beat within bar.@n
677  Should always be > 0 and <= @a beatsPerBar.@n
678  The first beat is beat '1'.
679  */
680  int32_t beat;
681 
682  /**
683  Current tick within beat.@n
684  Should always be >= 0 and < @a ticksPerBeat.@n
685  The first tick is tick '0'.
686  @note Fraction part of tick is only available on some plugin formats.
687  */
688  double tick;
689 
690  /**
691  Number of ticks that have elapsed between frame 0 and the first beat of the current measure.
692  */
693  double barStartTick;
694 
695  /**
696  Time signature "numerator".
697  */
698  float beatsPerBar;
699 
700  /**
701  Time signature "denominator".
702  */
703  float beatType;
704 
705  /**
706  Number of ticks within a beat.@n
707  Usually a moderately large integer with many denominators, such as 1920.0.
708  */
709  double ticksPerBeat;
710 
711  /**
712  Number of beats per minute.
713  */
715 
716  /**
717  Default constructor for a null BBT time position.
718  */
719  BarBeatTick() noexcept
720  : valid(false),
721  bar(0),
722  beat(0),
723  tick(0),
724  barStartTick(0.0),
725  beatsPerBar(0.0f),
726  beatType(0.0f),
727  ticksPerBeat(0.0),
728  beatsPerMinute(0.0) {}
729 
730  /**
731  Reinitialize this position using the default null initialization.
732  */
733  void clear() noexcept
734  {
735  valid = false;
736  bar = 0;
737  beat = 0;
738  tick = 0;
739  barStartTick = 0.0;
740  beatsPerBar = 0.0f;
741  beatType = 0.0f;
742  ticksPerBeat = 0.0;
743  beatsPerMinute = 0.0;
744  }
745  } bbt;
746 
747  /**
748  Default constructor for a time position.
749  */
750  TimePosition() noexcept
751  : playing(false),
752  frame(0),
753  bbt() {}
754 
755  /**
756  Reinitialize this position using the default null initialization.
757  */
758  void clear() noexcept
759  {
760  playing = false;
761  frame = 0;
762  bbt.clear();
763  }
764 };
765 
766 /** @} */
767 
768 /* ------------------------------------------------------------------------------------------------------------
769  * DPF Plugin */
770 
771 /**
772  @defgroup MainClasses Main Classes
773  @{
774  */
775 
776 /**
777  DPF Plugin class from where plugin instances are created.
778 
779  The public methods (Host state) are called from the plugin to get or set host information.@n
780  They can be called from a plugin instance at anytime unless stated otherwise.@n
781  All other methods are to be implemented by the plugin and will be called by the host.
782 
783  Shortly after a plugin instance is created, the various init* functions will be called by the host.@n
784  Host will call activate() before run(), and deactivate() before the plugin instance is destroyed.@n
785  The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.@n
786  There is no limit on how many times run() is called, only that activate/deactivate will be called in between.
787 
788  The buffer size and sample rate values will remain constant between activate and deactivate.@n
789  Buffer size is only a hint though, the host might call run() with a higher or lower number of frames.
790 
791  Some of this class functions are only available according to some macros.
792 
793  DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.@n
794  When enabled you need to implement initProgramName() and loadProgram().
795 
796  DISTRHO_PLUGIN_WANT_STATE activates internal state features.@n
797  When enabled you need to implement initStateKey() and setState().
798 
799  The process function run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.@n
800  When enabled it provides midi input events.
801  */
802 class Plugin
803 {
804 public:
805  /**
806  Plugin class constructor.@n
807  You must set all parameter values to their defaults, matching ParameterRanges::def.
808  */
809  Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
810 
811  /**
812  Destructor.
813  */
814  virtual ~Plugin();
815 
816  /* --------------------------------------------------------------------------------------------------------
817  * Host state */
818 
819  /**
820  Get the current buffer size that will probably be used during processing, in frames.@n
821  This value will remain constant between activate and deactivate.
822  @note This value is only a hint!@n
823  Hosts might call run() with a higher or lower number of frames.
824  @see bufferSizeChanged(uint32_t)
825  */
826  uint32_t getBufferSize() const noexcept;
827 
828  /**
829  Get the current sample rate that will be used during processing.@n
830  This value will remain constant between activate and deactivate.
831  @see sampleRateChanged(double)
832  */
833  double getSampleRate() const noexcept;
834 
835 #if DISTRHO_PLUGIN_WANT_TIMEPOS
836  /**
837  Get the current host transport time position.@n
838  This function should only be called during run().@n
839  You can call this during other times, but the returned position is not guaranteed to be in sync.
840  @note TimePosition is not supported in LADSPA and DSSI plugin formats.
841  */
842  const TimePosition& getTimePosition() const noexcept;
843 #endif
844 
845 #if DISTRHO_PLUGIN_WANT_LATENCY
846  /**
847  Change the plugin audio output latency to @a frames.@n
848  This function should only be called in the constructor, activate() and run().
849  @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
850  */
851  void setLatency(uint32_t frames) noexcept;
852 #endif
853 
854 #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
855  /**
856  Write a MIDI output event.@n
857  This function must only be called during run().@n
858  Returns false when the host buffer is full, in which case do not call this again until the next run().
859  */
860  bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
861 #endif
862 
863 #if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
864  /**
865  Check if parameter value change requests will work with the current plugin host.
866  @note This function is only available if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST is enabled.
867  @see requestParameterValueChange(uint32_t, float)
868  */
869  bool canRequestParameterValueChanges() const noexcept;
870 
871  /**
872  Request a parameter value change from the host.
873  If successful, this function will automatically trigger a parameter update on the UI side as well.
874  This function can fail, for example if the host is busy with the parameter for read-only automation.
875  Some hosts simply do not have this functionality, which can be verified with canRequestParameterValueChanges().
876  @note This function is only available if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST is enabled.
877  */
878  bool requestParameterValueChange(uint32_t index, float value) noexcept;
879 #endif
880 
881 protected:
882  /* --------------------------------------------------------------------------------------------------------
883  * Information */
884 
885  /**
886  Get the plugin name.@n
887  Returns DISTRHO_PLUGIN_NAME by default.
888  */
889  virtual const char* getName() const { return DISTRHO_PLUGIN_NAME; }
890 
891  /**
892  Get the plugin label.@n
893  This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
894  */
895  virtual const char* getLabel() const = 0;
896 
897  /**
898  Get an extensive comment/description about the plugin.@n
899  Optional, returns nothing by default.
900  */
901  virtual const char* getDescription() const { return ""; }
902 
903  /**
904  Get the plugin author/maker.
905  */
906  virtual const char* getMaker() const = 0;
907 
908  /**
909  Get the plugin homepage.@n
910  Optional, returns nothing by default.
911  */
912  virtual const char* getHomePage() const { return ""; }
913 
914  /**
915  Get the plugin license (a single line of text or a URL).@n
916  For commercial plugins this should return some short copyright information.
917  */
918  virtual const char* getLicense() const = 0;
919 
920  /**
921  Get the plugin version, in hexadecimal.
922  @see d_version()
923  */
924  virtual uint32_t getVersion() const = 0;
925 
926  /**
927  Get the plugin unique Id.@n
928  This value is used by LADSPA, DSSI and VST plugin formats.
929  @see d_cconst()
930  */
931  virtual int64_t getUniqueId() const = 0;
932 
933  /* --------------------------------------------------------------------------------------------------------
934  * Init */
935 
936  /**
937  Initialize the audio port @a index.@n
938  This function will be called once, shortly after the plugin is created.
939  */
940  virtual void initAudioPort(bool input, uint32_t index, AudioPort& port);
941 
942  /**
943  Initialize the parameter @a index.@n
944  This function will be called once, shortly after the plugin is created.
945  */
946  virtual void initParameter(uint32_t index, Parameter& parameter) = 0;
947 
948  /**
949  Initialize the port group @a groupId.@n
950  This function will be called once,
951  shortly after the plugin is created and all audio ports and parameters have been enumerated.
952  */
953  virtual void initPortGroup(uint32_t groupId, PortGroup& portGroup);
954 
955 #if DISTRHO_PLUGIN_WANT_PROGRAMS
956  /**
957  Set the name of the program @a index.@n
958  This function will be called once, shortly after the plugin is created.@n
959  Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
960  */
961  virtual void initProgramName(uint32_t index, String& programName) = 0;
962 #endif
963 
964 #if DISTRHO_PLUGIN_WANT_STATE
965  /**
966  Set the state key and default value of @a index.@n
967  This function will be called once, shortly after the plugin is created.@n
968  Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
969  */
970  virtual void initState(uint32_t index, String& stateKey, String& defaultStateValue) = 0;
971 #endif
972 
973 #if DISTRHO_PLUGIN_WANT_STATEFILES
974  /**
975  TODO API under construction
976  */
977  virtual bool isStateFile(uint32_t index) = 0;
978 #endif
979 
980  /* --------------------------------------------------------------------------------------------------------
981  * Internal data */
982 
983  /**
984  Get the current value of a parameter.@n
985  The host may call this function from any context, including realtime processing.
986  */
987  virtual float getParameterValue(uint32_t index) const = 0;
988 
989  /**
990  Change a parameter value.@n
991  The host may call this function from any context, including realtime processing.@n
992  When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
993  @note This function will only be called for parameter inputs.
994  */
995  virtual void setParameterValue(uint32_t index, float value) = 0;
996 
997 #if DISTRHO_PLUGIN_WANT_PROGRAMS
998  /**
999  Load a program.@n
1000  The host may call this function from any context, including realtime processing.@n
1001  Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
1002  */
1003  virtual void loadProgram(uint32_t index) = 0;
1004 #endif
1005 
1006 #if DISTRHO_PLUGIN_WANT_FULL_STATE
1007  /**
1008  Get the value of an internal state.@n
1009  The host may call this function from any non-realtime context.@n
1010  Must be implemented by your plugin class if DISTRHO_PLUGIN_WANT_FULL_STATE is enabled.
1011  @note The use of this function breaks compatibility with the DSSI format.
1012  */
1013  virtual String getState(const char* key) const = 0;
1014 #endif
1015 
1016 #if DISTRHO_PLUGIN_WANT_STATE
1017  /**
1018  Change an internal state @a key to @a value.@n
1019  Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
1020  */
1021  virtual void setState(const char* key, const char* value) = 0;
1022 #endif
1023 
1024  /* --------------------------------------------------------------------------------------------------------
1025  * Audio/MIDI Processing */
1026 
1027  /**
1028  Activate this plugin.
1029  */
1030  virtual void activate() {}
1031 
1032  /**
1033  Deactivate this plugin.
1034  */
1035  virtual void deactivate() {}
1036 
1037 #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
1038  /**
1039  Run/process function for plugins with MIDI input.
1040  @note Some parameters might be null if there are no audio inputs/outputs or MIDI events.
1041  */
1042  virtual void run(const float** inputs, float** outputs, uint32_t frames,
1043  const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
1044 #else
1045  /**
1046  Run/process function for plugins without MIDI input.
1047  @note Some parameters might be null if there are no audio inputs or outputs.
1048  */
1049  virtual void run(const float** inputs, float** outputs, uint32_t frames) = 0;
1050 #endif
1051 
1052  /* --------------------------------------------------------------------------------------------------------
1053  * Callbacks (optional) */
1054 
1055  /**
1056  Optional callback to inform the plugin about a buffer size change.@n
1057  This function will only be called when the plugin is deactivated.
1058  @note This value is only a hint!@n
1059  Hosts might call run() with a higher or lower number of frames.
1060  @see getBufferSize()
1061  */
1062  virtual void bufferSizeChanged(uint32_t newBufferSize);
1063 
1064  /**
1065  Optional callback to inform the plugin about a sample rate change.@n
1066  This function will only be called when the plugin is deactivated.
1067  @see getSampleRate()
1068  */
1069  virtual void sampleRateChanged(double newSampleRate);
1070 
1071  // -------------------------------------------------------------------------------------------------------
1072 
1073 private:
1074  struct PrivateData;
1075  PrivateData* const pData;
1076  friend class PluginExporter;
1077 
1078  DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
1079 };
1080 
1081 /** @} */
1082 
1083 /* ------------------------------------------------------------------------------------------------------------
1084  * Create plugin, entry point */
1085 
1086 /**
1087  @defgroup EntryPoints Entry Points
1088  @{
1089  */
1090 
1091 /**
1092  TODO.
1093  */
1094 extern Plugin* createPlugin();
1095 
1096 /** @} */
1097 
1098 // -----------------------------------------------------------------------------------------------------------
1099 
1100 END_NAMESPACE_DISTRHO
1101 
1102 #endif // DISTRHO_PLUGIN_HPP_INCLUDED
ParameterRanges::fixDefault
void fixDefault() noexcept
Definition: DistrhoPlugin.hpp:280
kParameterIsLogarithmic
static const uint32_t kParameterIsLogarithmic
Definition: DistrhoPlugin.hpp:106
PredefinedPortGroupsIds
PredefinedPortGroupsIds
Definition: DistrhoPlugin.hpp:172
Plugin::sampleRateChanged
virtual void sampleRateChanged(double newSampleRate)
Plugin::getTimePosition
const TimePosition & getTimePosition() const noexcept
Plugin::deactivate
virtual void deactivate()
Definition: DistrhoPlugin.hpp:1035
Parameter::enumValues
ParameterEnumerationValues enumValues
Definition: DistrhoPlugin.hpp:497
kParameterIsOutput
static const uint32_t kParameterIsOutput
Definition: DistrhoPlugin.hpp:119
Plugin::getVersion
virtual uint32_t getVersion() const =0
MidiEvent
Definition: DistrhoPlugin.hpp:616
Plugin::setLatency
void setLatency(uint32_t frames) noexcept
kParameterIsTrigger
static const uint32_t kParameterIsTrigger
Definition: DistrhoPlugin.hpp:128
ParameterEnumerationValues::ParameterEnumerationValues
ParameterEnumerationValues() noexcept
Definition: DistrhoPlugin.hpp:413
kPortGroupStereo
@ kPortGroupStereo
Definition: DistrhoPlugin.hpp:187
ParameterEnumerationValues
Definition: DistrhoPlugin.hpp:391
String
Definition: String.hpp:30
Plugin::writeMidiEvent
bool writeMidiEvent(const MidiEvent &midiEvent) noexcept
ParameterRanges::getFixedValue
float getFixedValue(const float &value) const noexcept
Definition: DistrhoPlugin.hpp:299
MidiEvent::kDataSize
static const uint32_t kDataSize
Definition: DistrhoPlugin.hpp:620
Parameter::Parameter
Parameter(uint32_t h, const char *n, const char *s, const char *u, float def, float min, float max) noexcept
Definition: DistrhoPlugin.hpp:540
Plugin::getState
virtual String getState(const char *key) const =0
TimePosition::BarBeatTick::beatsPerMinute
double beatsPerMinute
Definition: DistrhoPlugin.hpp:714
TimePosition::BarBeatTick::bar
int32_t bar
Definition: DistrhoPlugin.hpp:673
Plugin::getParameterValue
virtual float getParameterValue(uint32_t index) const =0
Parameter::ranges
ParameterRanges ranges
Definition: DistrhoPlugin.hpp:491
AudioPort::symbol
String symbol
Definition: DistrhoPlugin.hpp:216
createPlugin
Plugin * createPlugin()
Plugin::Plugin
Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount)
kAudioPortIsSidechain
static const uint32_t kAudioPortIsSidechain
Definition: DistrhoPlugin.hpp:45
TimePosition::playing
bool playing
Definition: DistrhoPlugin.hpp:651
ParameterEnumerationValue
Definition: DistrhoPlugin.hpp:361
kParameterDesignationNull
@ kParameterDesignationNull
Definition: DistrhoPlugin.hpp:154
kPortGroupMono
@ kPortGroupMono
Definition: DistrhoPlugin.hpp:181
Parameter::unit
String unit
Definition: DistrhoPlugin.hpp:479
Plugin::~Plugin
virtual ~Plugin()
Parameter
Definition: DistrhoPlugin.hpp:445
TimePosition::clear
void clear() noexcept
Definition: DistrhoPlugin.hpp:758
MidiEvent::frame
uint32_t frame
Definition: DistrhoPlugin.hpp:625
TimePosition::frame
uint64_t frame
Definition: DistrhoPlugin.hpp:656
Plugin::getBufferSize
uint32_t getBufferSize() const noexcept
ParameterRanges::fixValue
void fixValue(float &value) const noexcept
Definition: DistrhoPlugin.hpp:288
Plugin::getMaker
virtual const char * getMaker() const =0
kCVPortHasScaledRange
static const uint32_t kCVPortHasScaledRange
Definition: DistrhoPlugin.hpp:71
Plugin::loadProgram
virtual void loadProgram(uint32_t index)=0
Plugin::initPortGroup
virtual void initPortGroup(uint32_t groupId, PortGroup &portGroup)
DISTRHO_PLUGIN_NAME
#define DISTRHO_PLUGIN_NAME
Definition: DistrhoInfo.hpp:470
TimePosition::BarBeatTick::ticksPerBeat
double ticksPerBeat
Definition: DistrhoPlugin.hpp:709
Plugin::initProgramName
virtual void initProgramName(uint32_t index, String &programName)=0
Plugin::getLabel
virtual const char * getLabel() const =0
Parameter::designation
ParameterDesignation designation
Definition: DistrhoPlugin.hpp:502
ParameterRanges::def
float def
Definition: DistrhoPlugin.hpp:249
TimePosition::BarBeatTick::beatType
float beatType
Definition: DistrhoPlugin.hpp:703
Parameter::initDesignation
void initDesignation(ParameterDesignation d) noexcept
Definition: DistrhoPlugin.hpp:555
Plugin::bufferSizeChanged
virtual void bufferSizeChanged(uint32_t newBufferSize)
Parameter::name
String name
Definition: DistrhoPlugin.hpp:457
Plugin::canRequestParameterValueChanges
bool canRequestParameterValueChanges() const noexcept
Parameter::Parameter
Parameter() noexcept
Definition: DistrhoPlugin.hpp:525
ParameterRanges::ParameterRanges
ParameterRanges() noexcept
Definition: DistrhoPlugin.hpp:264
TimePosition::BarBeatTick::beat
int32_t beat
Definition: DistrhoPlugin.hpp:680
ParameterEnumerationValues::restrictedMode
bool restrictedMode
Definition: DistrhoPlugin.hpp:402
Plugin::initParameter
virtual void initParameter(uint32_t index, Parameter &parameter)=0
kParameterDesignationBypass
@ kParameterDesignationBypass
Definition: DistrhoPlugin.hpp:160
ParameterRanges::getNormalizedValue
float getNormalizedValue(const float &value) const noexcept
Definition: DistrhoPlugin.hpp:311
Plugin::getDescription
virtual const char * getDescription() const
Definition: DistrhoPlugin.hpp:901
Plugin::getName
virtual const char * getName() const
Definition: DistrhoPlugin.hpp:889
ParameterEnumerationValue::ParameterEnumerationValue
ParameterEnumerationValue() noexcept
Definition: DistrhoPlugin.hpp:375
PortGroup::symbol
String symbol
Definition: DistrhoPlugin.hpp:610
Parameter::symbol
String symbol
Definition: DistrhoPlugin.hpp:472
Plugin::getLicense
virtual const char * getLicense() const =0
ParameterDesignation
ParameterDesignation
Definition: DistrhoPlugin.hpp:150
ParameterEnumerationValues::count
uint8_t count
Definition: DistrhoPlugin.hpp:395
Parameter::midiCC
uint8_t midiCC
Definition: DistrhoPlugin.hpp:510
TimePosition::BarBeatTick::tick
double tick
Definition: DistrhoPlugin.hpp:688
ParameterRanges::getUnnormalizedValue
float getUnnormalizedValue(const float &value) const noexcept
Definition: DistrhoPlugin.hpp:345
Plugin::initAudioPort
virtual void initAudioPort(bool input, uint32_t index, AudioPort &port)
Plugin::getUniqueId
virtual int64_t getUniqueId() const =0
AudioPort::hints
uint32_t hints
Definition: DistrhoPlugin.hpp:201
Plugin
Definition: DistrhoPlugin.hpp:802
AudioPort::groupId
uint32_t groupId
Definition: DistrhoPlugin.hpp:226
TimePosition::BarBeatTick::beatsPerBar
float beatsPerBar
Definition: DistrhoPlugin.hpp:698
Parameter::description
String description
Definition: DistrhoPlugin.hpp:485
Plugin::run
virtual void run(const float **inputs, float **outputs, uint32_t frames, const MidiEvent *midiEvents, uint32_t midiEventCount)=0
ParameterEnumerationValue::value
float value
Definition: DistrhoPlugin.hpp:365
TimePosition::BarBeatTick::barStartTick
double barStartTick
Definition: DistrhoPlugin.hpp:693
kAudioPortIsCV
static const uint32_t kAudioPortIsCV
Definition: DistrhoPlugin.hpp:40
TimePosition::BarBeatTick::clear
void clear() noexcept
Definition: DistrhoPlugin.hpp:733
ParameterRanges::ParameterRanges
ParameterRanges(float df, float mn, float mx) noexcept
Definition: DistrhoPlugin.hpp:272
AudioPort::AudioPort
AudioPort() noexcept
Definition: DistrhoPlugin.hpp:231
TimePosition::BarBeatTick
Definition: DistrhoPlugin.hpp:661
Plugin::setParameterValue
virtual void setParameterValue(uint32_t index, float value)=0
kParameterIsAutomable
static const uint32_t kParameterIsAutomable
Definition: DistrhoPlugin.hpp:90
TimePosition
Definition: DistrhoPlugin.hpp:647
ParameterEnumerationValues::ParameterEnumerationValues
ParameterEnumerationValues(uint32_t c, bool r, const ParameterEnumerationValue *v) noexcept
Definition: DistrhoPlugin.hpp:422
Plugin::getHomePage
virtual const char * getHomePage() const
Definition: DistrhoPlugin.hpp:912
Parameter::groupId
uint32_t groupId
Definition: DistrhoPlugin.hpp:520
kParameterIsBoolean
static const uint32_t kParameterIsBoolean
Definition: DistrhoPlugin.hpp:96
kPortGroupNone
@ kPortGroupNone
Definition: DistrhoPlugin.hpp:176
AudioPort
Definition: DistrhoPlugin.hpp:196
ParameterEnumerationValues::values
const ParameterEnumerationValue * values
Definition: DistrhoPlugin.hpp:408
ParameterRanges::getFixedAndNormalizedValue
float getFixedAndNormalizedValue(const float &value) const noexcept
Definition: DistrhoPlugin.hpp:325
ParameterRanges::max
float max
Definition: DistrhoPlugin.hpp:259
ParameterRanges::min
float min
Definition: DistrhoPlugin.hpp:254
Plugin::getSampleRate
double getSampleRate() const noexcept
TimePosition::BarBeatTick::BarBeatTick
BarBeatTick() noexcept
Definition: DistrhoPlugin.hpp:719
Plugin::activate
virtual void activate()
Definition: DistrhoPlugin.hpp:1030
TimePosition::BarBeatTick::valid
bool valid
Definition: DistrhoPlugin.hpp:666
kCVPortHasPositiveUnipolarRange
static const uint32_t kCVPortHasPositiveUnipolarRange
Definition: DistrhoPlugin.hpp:63
ParameterEnumerationValue::ParameterEnumerationValue
ParameterEnumerationValue(float v, const char *l) noexcept
Definition: DistrhoPlugin.hpp:382
ParameterEnumerationValue::label
String label
Definition: DistrhoPlugin.hpp:370
PortGroup
Definition: DistrhoPlugin.hpp:596
Plugin::initState
virtual void initState(uint32_t index, String &stateKey, String &defaultStateValue)=0
kCVPortHasNegativeUnipolarRange
static const uint32_t kCVPortHasNegativeUnipolarRange
Definition: DistrhoPlugin.hpp:57
MidiEvent::size
uint32_t size
Definition: DistrhoPlugin.hpp:630
Plugin::setState
virtual void setState(const char *key, const char *value)=0
PortGroup::name
String name
Definition: DistrhoPlugin.hpp:602
kParameterIsInteger
static const uint32_t kParameterIsInteger
Definition: DistrhoPlugin.hpp:101
kCVPortHasBipolarRange
static const uint32_t kCVPortHasBipolarRange
Definition: DistrhoPlugin.hpp:51
AudioPort::name
String name
Definition: DistrhoPlugin.hpp:208
Parameter::shortName
String shortName
Definition: DistrhoPlugin.hpp:464
MidiEvent::data
uint8_t data[kDataSize]
Definition: DistrhoPlugin.hpp:636
Plugin::requestParameterValueChange
bool requestParameterValueChange(uint32_t index, float value) noexcept
Parameter::hints
uint32_t hints
Definition: DistrhoPlugin.hpp:450
ParameterRanges
Definition: DistrhoPlugin.hpp:245
TimePosition::TimePosition
TimePosition() noexcept
Definition: DistrhoPlugin.hpp:750