DISTRHO Plugin Framework
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.

211 lines
5.7KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2015 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include "DistrhoPlugin.hpp"
  17. START_NAMESPACE_DISTRHO
  18. // -----------------------------------------------------------------------------------------------------------
  19. /**
  20. Plugin that demonstrates the basic API in DPF.
  21. */
  22. class GainExamplePlugin : public Plugin
  23. {
  24. public:
  25. GainExamplePlugin()
  26. : Plugin(1, 0, 0), // 1 parameter
  27. fGain(1.0)
  28. {
  29. }
  30. ~GainExamplePlugin() override
  31. {
  32. }
  33. protected:
  34. /* --------------------------------------------------------------------------------------------------------
  35. * Information */
  36. /**
  37. Get the plugin label.
  38. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  39. */
  40. const char* getLabel() const override
  41. {
  42. return "Gain";
  43. }
  44. /**
  45. Get an extensive comment/description about the plugin.
  46. */
  47. const char* getDescription() const override
  48. {
  49. return "Plugin that demonstrates the basic API in DPF.";
  50. }
  51. /**
  52. Get the plugin author/maker.
  53. */
  54. const char* getMaker() const override
  55. {
  56. return "DISTRHO";
  57. }
  58. /**
  59. Get the plugin homepage.
  60. */
  61. const char* getHomePage() const override
  62. {
  63. return "https://github.com/DISTRHO/DPF";
  64. }
  65. /**
  66. Get the plugin license name (a single line of text).
  67. For commercial plugins this should return some short copyright information.
  68. */
  69. const char* getLicense() const override
  70. {
  71. return "ISC";
  72. }
  73. /**
  74. Get the plugin version, in hexadecimal.
  75. */
  76. uint32_t getVersion() const override
  77. {
  78. return d_version(1, 0, 0);
  79. }
  80. /**
  81. Get the plugin unique Id.
  82. This value is used by LADSPA, DSSI and VST plugin formats.
  83. */
  84. int64_t getUniqueId() const override
  85. {
  86. return d_cconst('d', 'G', 'a', 'i');
  87. }
  88. /* --------------------------------------------------------------------------------------------------------
  89. * Init */
  90. /**
  91. Initialize the parameter @a index.
  92. This function will be called once, shortly after the plugin is created.
  93. */
  94. void initParameter(uint32_t index, Parameter& parameter) override
  95. {
  96. if (index != 0)
  97. return;
  98. parameter.hints = kParameterIsAutomable;
  99. parameter.name = "Gain";
  100. parameter.symbol = "gain";
  101. parameter.unit = "dB";
  102. parameter.ranges.def = 1.0f;
  103. parameter.ranges.min = 0.0f;
  104. parameter.ranges.max = 1.0f;
  105. }
  106. void initProgramName(uint32_t index, String& programName) override
  107. {
  108. if (index != 0) {
  109. programName = "";
  110. return;
  111. }
  112. programName = "Default";
  113. }
  114. void loadProgram(uint32_t index) override
  115. {
  116. if (index != 0)
  117. return;
  118. fGain = 1.0;
  119. }
  120. /* --------------------------------------------------------------------------------------------------------
  121. * Internal data */
  122. /**
  123. Get the current value of a parameter.
  124. The host may call this function from any context, including realtime processing.
  125. */
  126. float getParameterValue(uint32_t index) const override
  127. {
  128. if (index != 0)
  129. return 0.0f;
  130. return fGain;
  131. }
  132. /**
  133. Change a parameter value.
  134. The host may call this function from any context, including realtime processing.
  135. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  136. @note This function will only be called for parameter inputs.
  137. */
  138. void setParameterValue(uint32_t index, float value) override
  139. {
  140. if (index != 0)
  141. return;
  142. fGain = value;
  143. }
  144. /* --------------------------------------------------------------------------------------------------------
  145. * Audio/MIDI Processing */
  146. /**
  147. Run/process function for plugins without MIDI input.
  148. @note Some parameters might be null if there are no audio inputs or outputs.
  149. */
  150. void run(const float** inputs, float** outputs, uint32_t frames) override
  151. {
  152. const float* const in = inputs[0];
  153. /* */ float* const out = outputs[0];
  154. uint32_t i;
  155. for (i = 0; i < frames; i++) {
  156. out[i] = in[i] * fGain;
  157. }
  158. }
  159. // -------------------------------------------------------------------------------------------------------
  160. private:
  161. // Parameters
  162. float fGain;
  163. /**
  164. Set our plugin class as non-copyable and add a leak detector just in case.
  165. */
  166. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GainExamplePlugin)
  167. };
  168. /* ------------------------------------------------------------------------------------------------------------
  169. * Plugin entry point, called by DPF to create a new plugin instance. */
  170. Plugin* createPlugin()
  171. {
  172. return new GainExamplePlugin();
  173. }
  174. // -----------------------------------------------------------------------------------------------------------
  175. END_NAMESPACE_DISTRHO