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