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.

240 lines
6.4KB

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