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