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
6.1KB

  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 Lesser General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * For a full copy of the license see the LGPL.txt file
  15. */
  16. #ifndef __DISTRHO_PLUGIN_HPP__
  17. #define __DISTRHO_PLUGIN_HPP__
  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()
  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)
  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)
  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()
  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
  71. {
  72. if (value < min)
  73. value = min;
  74. else if (value > max)
  75. value = max;
  76. }
  77. float fixedValue(const float& value) const
  78. {
  79. if (value < min)
  80. return min;
  81. else if (value > max)
  82. return max;
  83. return value;
  84. }
  85. float normalizedValue(const float& value) const
  86. {
  87. const float newValue((value - min) / (max - min));
  88. if (newValue < 0.0f)
  89. return 0.0f;
  90. else if (newValue > 1.0f)
  91. return 1.0f;
  92. return newValue;
  93. }
  94. float unnormalizedValue(const float& value) const
  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()
  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()
  125. {
  126. clear();
  127. }
  128. void clear()
  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()
  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_bufferSize() const;
  159. double d_sampleRate() const;
  160. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  161. const TimePos& d_timePos() const;
  162. #endif
  163. #if DISTRHO_PLUGIN_WANT_LATENCY
  164. void d_setLatency(uint32_t frames);
  165. #endif
  166. protected:
  167. // ---------------------------------------------
  168. // Information
  169. virtual const char* d_name() const { return DISTRHO_PLUGIN_NAME; }
  170. virtual const char* d_label() const = 0;
  171. virtual const char* d_maker() const = 0;
  172. virtual const char* d_license() const = 0;
  173. virtual uint32_t d_version() const = 0;
  174. virtual long d_uniqueId() const = 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_parameterValue(uint32_t index) = 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, uint32_t midiEventCount, const MidiEvent* midiEvents) = 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. Plugin* createPlugin();
  211. // -------------------------------------------------
  212. END_NAMESPACE_DISTRHO
  213. #endif // __DISTRHO_PLUGIN_HPP__