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.

208 lines
5.0KB

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