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.

263 lines
7.0KB

  1. /*
  2. * DISTRHO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012-2013 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. #ifndef DISTRHO_PLUGIN_HPP_INCLUDED
  17. #define DISTRHO_PLUGIN_HPP_INCLUDED
  18. #include "DistrhoUtils.hpp"
  19. START_NAMESPACE_DISTRHO
  20. // -----------------------------------------------------------------------
  21. // Parameter Hints
  22. const uint32_t PARAMETER_IS_AUTOMABLE = 1 << 0;
  23. const uint32_t PARAMETER_IS_BOOLEAN = 1 << 1;
  24. const uint32_t PARAMETER_IS_INTEGER = 1 << 2;
  25. const uint32_t PARAMETER_IS_LOGARITHMIC = 1 << 3;
  26. const uint32_t PARAMETER_IS_OUTPUT = 1 << 4;
  27. // -----------------------------------------------------------------------
  28. // Parameter Ranges
  29. struct ParameterRanges {
  30. float def;
  31. float min;
  32. float max;
  33. float step;
  34. float stepSmall;
  35. float stepLarge;
  36. ParameterRanges() noexcept
  37. : def(0.0f),
  38. min(0.0f),
  39. max(1.0f),
  40. step(0.001f),
  41. stepSmall(0.00001f),
  42. stepLarge(0.01f) {}
  43. ParameterRanges(float def, float min, float max) noexcept
  44. : step(0.001f),
  45. stepSmall(0.00001f),
  46. stepLarge(0.01f)
  47. {
  48. this->def = def;
  49. this->min = min;
  50. this->max = max;
  51. }
  52. ParameterRanges(float def, float min, float max, float step, float stepSmall, float stepLarge) noexcept
  53. {
  54. this->def = def;
  55. this->min = min;
  56. this->max = max;
  57. this->step = step;
  58. this->stepSmall = stepSmall;
  59. this->stepLarge = stepLarge;
  60. }
  61. void clear() noexcept
  62. {
  63. def = 0.0f;
  64. min = 0.0f;
  65. max = 1.0f;
  66. step = 0.001f;
  67. stepSmall = 0.00001f;
  68. stepLarge = 0.01f;
  69. }
  70. void fixValue(float& value) const noexcept
  71. {
  72. if (value < min)
  73. value = min;
  74. else if (value > max)
  75. value = max;
  76. }
  77. float getFixedValue(const float& value) const noexcept
  78. {
  79. if (value < min)
  80. return min;
  81. else if (value > max)
  82. return max;
  83. return value;
  84. }
  85. float getNormalizedValue(const float& value) const noexcept
  86. {
  87. const float newValue((value - min) / (max - min));
  88. if (newValue <= 0.0f)
  89. return 0.0f;
  90. if (newValue >= 1.0f)
  91. return 1.0f;
  92. return newValue;
  93. }
  94. float getUnnormalizedValue(const float& value) const noexcept
  95. {
  96. return value * (max - min) + min;
  97. }
  98. };
  99. // -----------------------------------------------------------------------
  100. // Parameter
  101. struct Parameter {
  102. uint32_t hints;
  103. d_string name;
  104. d_string symbol;
  105. d_string unit;
  106. ParameterRanges ranges;
  107. Parameter()
  108. : hints(0x0) {}
  109. void clear() noexcept
  110. {
  111. hints = 0x0;
  112. name = "";
  113. symbol = "";
  114. unit = "";
  115. ranges.clear();
  116. }
  117. };
  118. // -----------------------------------------------------------------------
  119. // MidiEvent
  120. struct MidiEvent {
  121. uint32_t frame;
  122. uint8_t buf[4];
  123. uint8_t size;
  124. MidiEvent() noexcept
  125. {
  126. clear();
  127. }
  128. void clear() noexcept
  129. {
  130. frame = 0;
  131. buf[0] = 0;
  132. buf[1] = 0;
  133. buf[2] = 0;
  134. buf[3] = 0;
  135. size = 0;
  136. }
  137. };
  138. // -----------------------------------------------------------------------
  139. // TimePos
  140. struct TimePos {
  141. bool playing;
  142. uint64_t frame;
  143. double bpm;
  144. TimePos() noexcept
  145. : playing(false),
  146. frame(0),
  147. bpm(120.0) {}
  148. };
  149. // -----------------------------------------------------------------------
  150. // Plugin
  151. class Plugin
  152. {
  153. public:
  154. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  155. virtual ~Plugin();
  156. // -------------------------------------------------------------------
  157. // Host state
  158. uint32_t d_getBufferSize() const noexcept;
  159. double d_getSampleRate() const noexcept;
  160. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  161. const TimePos& d_getTimePos() const noexcept;
  162. #endif
  163. #if DISTRHO_PLUGIN_WANT_LATENCY
  164. void d_setLatency(uint32_t frames) noexcept;
  165. #endif
  166. protected:
  167. // -------------------------------------------------------------------
  168. // Information
  169. virtual const char* d_getName() const noexcept { return DISTRHO_PLUGIN_NAME; }
  170. virtual const char* d_getLabel() const noexcept = 0;
  171. virtual const char* d_getMaker() const noexcept = 0;
  172. virtual const char* d_getLicense() const noexcept = 0;
  173. virtual uint32_t d_getVersion() const noexcept = 0;
  174. virtual long d_getUniqueId() const noexcept = 0;
  175. // -------------------------------------------------------------------
  176. // Init
  177. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  178. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  179. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  180. #endif
  181. #if DISTRHO_PLUGIN_WANT_STATE
  182. virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
  183. #endif
  184. // -------------------------------------------------------------------
  185. // Internal data
  186. virtual float d_getParameterValue(uint32_t index) const = 0;
  187. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  188. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  189. virtual void d_setProgram(uint32_t index) = 0;
  190. #endif
  191. #if DISTRHO_PLUGIN_WANT_STATE
  192. virtual void d_setState(const char* key, const char* value) = 0;
  193. #endif
  194. // -------------------------------------------------------------------
  195. // Process
  196. virtual void d_activate() {}
  197. virtual void d_deactivate() {}
  198. virtual void d_run(float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  199. // -------------------------------------------------------------------
  200. // Callbacks (optional)
  201. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  202. virtual void d_sampleRateChanged(double newSampleRate);
  203. // -------------------------------------------------------------------
  204. private:
  205. struct PrivateData;
  206. PrivateData* const pData;
  207. friend class PluginInternal;
  208. };
  209. // -----------------------------------------------------------------------
  210. // Create plugin, entry point
  211. extern Plugin* createPlugin();
  212. // -----------------------------------------------------------------------
  213. END_NAMESPACE_DISTRHO
  214. #endif // DISTRHO_PLUGIN_HPP_INCLUDED