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.

225 lines
5.4KB

  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. #include <cstdint>
  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 fixValue(float& value) const
  63. {
  64. if (value < min)
  65. value = min;
  66. else if (value > max)
  67. value = max;
  68. }
  69. float normalizeValue(const float& value) const
  70. {
  71. return (value - min) / (max - min);
  72. }
  73. float unnormalizeValue(const float& value) const
  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. };
  89. // -------------------------------------------------
  90. // MidiEvent
  91. struct MidiEvent {
  92. uint32_t frame;
  93. uint8_t buf[4];
  94. uint8_t size;
  95. MidiEvent()
  96. {
  97. clear();
  98. }
  99. void clear()
  100. {
  101. frame = 0;
  102. buf[0] = 0;
  103. buf[1] = 0;
  104. buf[2] = 0;
  105. buf[3] = 0;
  106. size = 0;
  107. }
  108. };
  109. // -------------------------------------------------
  110. // TimePos
  111. struct TimePos {
  112. double bpm;
  113. TimePos()
  114. : bpm(120.0) {}
  115. };
  116. // -------------------------------------------------
  117. // Plugin
  118. struct PluginPrivateData;
  119. class Plugin
  120. {
  121. public:
  122. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  123. virtual ~Plugin();
  124. // ---------------------------------------------
  125. // Host state
  126. uint32_t d_bufferSize() const;
  127. double d_sampleRate() const;
  128. const TimePos& d_timePos() const;
  129. #if DISTRHO_PLUGIN_WANT_LATENCY
  130. void d_setLatency(uint32_t frames);
  131. #endif
  132. protected:
  133. // ---------------------------------------------
  134. // Information
  135. virtual const char* d_name() const { return DISTRHO_PLUGIN_NAME; }
  136. virtual const char* d_label() const = 0;
  137. virtual const char* d_maker() const = 0;
  138. virtual const char* d_license() const = 0;
  139. virtual uint32_t d_version() const = 0;
  140. virtual long d_uniqueId() const = 0;
  141. // ---------------------------------------------
  142. // Init
  143. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  144. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  145. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  146. #endif
  147. #if DISTRHO_PLUGIN_WANT_STATE
  148. virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
  149. #endif
  150. // ---------------------------------------------
  151. // Internal data
  152. virtual float d_parameterValue(uint32_t index) = 0;
  153. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  154. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  155. virtual void d_setProgram(uint32_t index) = 0;
  156. #endif
  157. #if DISTRHO_PLUGIN_WANT_STATE
  158. virtual void d_setState(const char* key, const char* value) = 0;
  159. #endif
  160. // ---------------------------------------------
  161. // Process
  162. virtual void d_activate() {}
  163. virtual void d_deactivate() {}
  164. virtual void d_run(float** inputs, float** outputs, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents) = 0;
  165. // ---------------------------------------------
  166. // Callbacks (optional)
  167. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  168. virtual void d_sampleRateChanged(double newSampleRate);
  169. // ---------------------------------------------
  170. private:
  171. PluginPrivateData* const pData;
  172. friend class PluginInternal;
  173. };
  174. // -------------------------------------------------
  175. Plugin* createPlugin();
  176. // -------------------------------------------------
  177. END_NAMESPACE_DISTRHO
  178. #endif // __DISTRHO_PLUGIN_HPP__