Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
5.2KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the license see the GPL.txt file
  16. */
  17. #ifndef __DISTRHO_PLUGIN_H__
  18. #define __DISTRHO_PLUGIN_H__
  19. #include "DistrhoUtils.h"
  20. START_NAMESPACE_DISTRHO
  21. // -------------------------------------------------
  22. // Parameter Hints
  23. const uint32_t PARAMETER_IS_AUTOMABLE = 1 << 0;
  24. const uint32_t PARAMETER_IS_BOOLEAN = 1 << 1;
  25. const uint32_t PARAMETER_IS_INTEGER = 1 << 2;
  26. const uint32_t PARAMETER_IS_LOGARITHMIC = 1 << 3;
  27. const uint32_t PARAMETER_IS_OUTPUT = 1 << 4;
  28. // -------------------------------------------------
  29. // Parameter Ranges
  30. struct ParameterRanges {
  31. float def;
  32. float min;
  33. float max;
  34. float step;
  35. float stepSmall;
  36. float stepLarge;
  37. ParameterRanges()
  38. : def(0.0f),
  39. min(0.0f),
  40. max(1.0f),
  41. step(0.001f),
  42. stepSmall(0.00001f),
  43. stepLarge(0.01f) {}
  44. ParameterRanges(float def, float min, float max)
  45. : step(0.001f),
  46. stepSmall(0.00001f),
  47. stepLarge(0.01f)
  48. {
  49. this->def = def;
  50. this->min = min;
  51. this->max = max;
  52. }
  53. ParameterRanges(float def, float min, float max, float step, float stepSmall, float stepLarge)
  54. {
  55. this->def = def;
  56. this->min = min;
  57. this->max = max;
  58. this->step = step;
  59. this->stepSmall = stepSmall;
  60. this->stepLarge = stepLarge;
  61. }
  62. void fixRange(float& value) const
  63. {
  64. if (value < min)
  65. value = min;
  66. else if (value > max)
  67. value = max;
  68. }
  69. };
  70. // -------------------------------------------------
  71. // Parameter
  72. struct Parameter {
  73. uint32_t hints;
  74. d_string name;
  75. d_string symbol;
  76. d_string unit;
  77. ParameterRanges ranges;
  78. Parameter()
  79. : hints(0x0),
  80. name(nullptr),
  81. symbol(nullptr),
  82. unit(nullptr) {}
  83. };
  84. // -------------------------------------------------
  85. // MidiEvent
  86. struct MidiEvent {
  87. uint32_t frame;
  88. uint8_t buffer[3];
  89. MidiEvent()
  90. : frame(0),
  91. buffer{0} {}
  92. void clear()
  93. {
  94. frame = 0;
  95. buffer[0] = 0;
  96. buffer[1] = 0;
  97. buffer[2] = 0;
  98. }
  99. };
  100. // -------------------------------------------------
  101. // TimePos
  102. struct TimePos {
  103. double bpm;
  104. TimePos()
  105. : bpm(120.0) {}
  106. };
  107. // -------------------------------------------------
  108. // Plugin
  109. struct PluginPrivateData;
  110. class Plugin
  111. {
  112. public:
  113. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  114. virtual ~Plugin();
  115. // ---------------------------------------------
  116. // Host state
  117. uint32_t d_bufferSize() const;
  118. double d_sampleRate() const;
  119. const TimePos& d_timePos() const;
  120. #if DISTRHO_PLUGIN_WANT_LATENCY
  121. void d_setLatency(uint32_t samples);
  122. #endif
  123. protected:
  124. // ---------------------------------------------
  125. // Information
  126. virtual const char* d_name() const { return DISTRHO_PLUGIN_NAME; }
  127. virtual const char* d_label() const = 0;
  128. virtual const char* d_maker() const = 0;
  129. virtual const char* d_license() const = 0;
  130. virtual uint32_t d_version() const = 0;
  131. virtual long d_uniqueId() const = 0;
  132. // ---------------------------------------------
  133. // Init
  134. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  135. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  136. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  137. #endif
  138. #if DISTRHO_PLUGIN_WANT_STATE
  139. virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
  140. #endif
  141. // ---------------------------------------------
  142. // Internal data
  143. virtual float d_parameterValue(uint32_t index) = 0;
  144. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  145. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  146. virtual void d_setProgram(uint32_t index) = 0;
  147. #endif
  148. #if DISTRHO_PLUGIN_WANT_STATE
  149. virtual void d_setState(const char* key, const char* value) = 0;
  150. #endif
  151. // ---------------------------------------------
  152. // Process
  153. virtual void d_activate() {}
  154. virtual void d_deactivate() {}
  155. virtual void d_run(float** inputs, float** outputs, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents) = 0;
  156. // ---------------------------------------------
  157. // Callbacks
  158. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  159. virtual void d_sampleRateChanged(double newSampleRate);
  160. // ---------------------------------------------
  161. private:
  162. PluginPrivateData* data;
  163. friend class PluginInternal;
  164. };
  165. Plugin* createPlugin();
  166. // -------------------------------------------------
  167. END_NAMESPACE_DISTRHO
  168. #endif // __DISTRHO_PLUGIN_H__