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.

220 lines
5.3KB

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