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.

DistrhoPlugin.hpp 7.1KB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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. struct BeatBarTick {
  119. bool valid;
  120. int32_t bar; /*!< current bar */
  121. int32_t beat; /*!< current beat-within-bar */
  122. int32_t tick; /*!< current tick-within-beat */
  123. double barStartTick;
  124. float beatsPerBar; /*!< time signature "numerator" */
  125. float beatType; /*!< time signature "denominator" */
  126. double ticksPerBeat;
  127. double beatsPerMinute;
  128. BeatBarTick() noexcept
  129. : valid(false),
  130. bar(0),
  131. beat(0),
  132. tick(0),
  133. barStartTick(0.0),
  134. beatsPerBar(0.0f),
  135. beatType(0.0f),
  136. ticksPerBeat(0.0),
  137. beatsPerMinute(0.0) {}
  138. } bbt;
  139. TimePos() noexcept
  140. : playing(false),
  141. frame(0) {}
  142. };
  143. // -----------------------------------------------------------------------
  144. // Plugin
  145. class Plugin
  146. {
  147. public:
  148. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  149. virtual ~Plugin();
  150. // -------------------------------------------------------------------
  151. // Host state
  152. uint32_t d_getBufferSize() const noexcept;
  153. double d_getSampleRate() const noexcept;
  154. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  155. const TimePos& d_getTimePos() const noexcept;
  156. #endif
  157. #if DISTRHO_PLUGIN_WANT_LATENCY
  158. void d_setLatency(uint32_t frames) noexcept;
  159. #endif
  160. protected:
  161. // -------------------------------------------------------------------
  162. // Information
  163. virtual const char* d_getName() const noexcept { return DISTRHO_PLUGIN_NAME; }
  164. virtual const char* d_getLabel() const noexcept = 0;
  165. virtual const char* d_getMaker() const noexcept = 0;
  166. virtual const char* d_getLicense() const noexcept = 0;
  167. virtual uint32_t d_getVersion() const noexcept = 0;
  168. virtual long d_getUniqueId() const noexcept = 0;
  169. // -------------------------------------------------------------------
  170. // Init
  171. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  172. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  173. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  174. #endif
  175. #if DISTRHO_PLUGIN_WANT_STATE
  176. virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
  177. #endif
  178. // -------------------------------------------------------------------
  179. // Internal data
  180. virtual float d_getParameterValue(uint32_t index) const = 0;
  181. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  182. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  183. virtual void d_setProgram(uint32_t index) = 0;
  184. #endif
  185. #if DISTRHO_PLUGIN_WANT_STATE
  186. virtual void d_setState(const char* key, const char* value) = 0;
  187. #endif
  188. // -------------------------------------------------------------------
  189. // Process
  190. virtual void d_activate() {}
  191. virtual void d_deactivate() {}
  192. #if DISTRHO_PLUGIN_IS_SYNTH
  193. virtual void d_run(float** inputs, float** outputs, uint32_t frames, const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  194. #else
  195. virtual void d_run(float** inputs, float** outputs, uint32_t frames) = 0;
  196. #endif
  197. // -------------------------------------------------------------------
  198. // Callbacks (optional)
  199. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  200. virtual void d_sampleRateChanged(double newSampleRate);
  201. // -------------------------------------------------------------------
  202. private:
  203. struct PrivateData;
  204. PrivateData* const pData;
  205. friend class PluginExporter;
  206. };
  207. // -----------------------------------------------------------------------
  208. // Create plugin, entry point
  209. extern Plugin* createPlugin();
  210. // -----------------------------------------------------------------------
  211. END_NAMESPACE_DISTRHO
  212. #endif // DISTRHO_PLUGIN_HPP_INCLUDED