Collection of tools useful for audio production
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.

189 lines
4.6KB

  1. /*
  2. * DISTHRO Plugin Toolkit (DPT)
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the license see the GPL.txt file
  16. */
  17. #ifndef __DISTRHO_PLUGIN_H__
  18. #define __DISTRHO_PLUGIN_H__
  19. #include "DistrhoUtils.h"
  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. // 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 fixRange(float& value) const
  62. {
  63. if (value < min)
  64. value = min;
  65. else if (value > max)
  66. value = max;
  67. }
  68. };
  69. // Parameter
  70. struct Parameter {
  71. uint32_t hints;
  72. d_string name;
  73. d_string symbol;
  74. d_string unit;
  75. ParameterRanges ranges;
  76. Parameter()
  77. : hints(0x0),
  78. name(nullptr),
  79. symbol(nullptr),
  80. unit(nullptr) {}
  81. };
  82. // MidiEvent
  83. struct MidiEvent {
  84. uint32_t frame;
  85. uint8_t buffer[3];
  86. MidiEvent()
  87. #if 0 // FIXME - code below is valid C++11
  88. : frame(0),
  89. buffer{0} {}
  90. #else
  91. : frame(0) { buffer[0] = buffer[1] = buffer[2] = 0; }
  92. #endif
  93. };
  94. // TimePos
  95. struct TimePos {
  96. double bpm;
  97. TimePos()
  98. : bpm(120.0) {}
  99. };
  100. // -------------------------------------------------
  101. struct PluginPrivateData;
  102. class Plugin
  103. {
  104. public:
  105. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  106. virtual ~Plugin();
  107. // ---------------------------------------------
  108. // Host state
  109. uint32_t d_bufferSize() const;
  110. double d_sampleRate() const;
  111. const TimePos* d_timePos() const;
  112. #if DISTRHO_PLUGIN_WANT_LATENCY
  113. void d_setLatency(uint32_t samples);
  114. #endif
  115. // ---------------------------------------------
  116. protected:
  117. // Information
  118. virtual const char* d_name() { return DISTRHO_PLUGIN_NAME; }
  119. virtual const char* d_label() = 0;
  120. virtual const char* d_maker() = 0;
  121. virtual const char* d_license() = 0;
  122. virtual uint32_t d_version() = 0;
  123. virtual long d_uniqueId() = 0;
  124. // Init
  125. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  126. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  127. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  128. #endif
  129. #if DISTRHO_PLUGIN_WANT_STATE
  130. virtual void d_initStateKey(uint32_t index, d_string& stateKey) = 0;
  131. #endif
  132. // Internal data
  133. virtual float d_parameterValue(uint32_t index) = 0;
  134. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  135. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  136. virtual void d_setProgram(uint32_t index) = 0;
  137. #endif
  138. #if DISTRHO_PLUGIN_WANT_STATE
  139. virtual void d_setState(const char* key, const char* value) = 0;
  140. #endif
  141. // Process
  142. virtual void d_activate() = 0;
  143. virtual void d_deactivate() = 0;
  144. virtual void d_run(float** inputs, float** outputs, uint32_t frames, uint32_t midiEventCount, const MidiEvent* midiEvents) = 0;
  145. // Callbacks
  146. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  147. // ---------------------------------------------
  148. private:
  149. PluginPrivateData* data;
  150. friend class PluginInternal;
  151. };
  152. Plugin* createPlugin();
  153. // -------------------------------------------------
  154. END_NAMESPACE_DISTRHO
  155. #endif // __DISTRHO_PLUGIN_H__