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.

193 lines
5.4KB

  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. /* --------------------------------------------------------------------------------------------------------
  107. * Internal data */
  108. /**
  109. Get the current value of a parameter.
  110. The host may call this function from any context, including realtime processing.
  111. */
  112. float getParameterValue(uint32_t index) const override
  113. {
  114. if (index != 0)
  115. return 0.0f;
  116. return fGain;
  117. }
  118. /**
  119. Change a parameter value.
  120. The host may call this function from any context, including realtime processing.
  121. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  122. @note This function will only be called for parameter inputs.
  123. */
  124. void setParameterValue(uint32_t index, float value) override
  125. {
  126. if (index != 0)
  127. return;
  128. fGain = value;
  129. }
  130. /* --------------------------------------------------------------------------------------------------------
  131. * Audio/MIDI Processing */
  132. /**
  133. Run/process function for plugins without MIDI input.
  134. @note Some parameters might be null if there are no audio inputs or outputs.
  135. */
  136. void run(const float** inputs, float** outputs, uint32_t frames) override
  137. {
  138. const float* const in = inputs[0];
  139. /* */ float* const out = outputs[0];
  140. uint32_t i;
  141. for (i = 0; i < frames; i++) {
  142. out[i] = in[i] * fGain;
  143. }
  144. }
  145. // -------------------------------------------------------------------------------------------------------
  146. private:
  147. // Parameters
  148. float fGain;
  149. /**
  150. Set our plugin class as non-copyable and add a leak detector just in case.
  151. */
  152. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(GainExamplePlugin)
  153. };
  154. /* ------------------------------------------------------------------------------------------------------------
  155. * Plugin entry point, called by DPF to create a new plugin instance. */
  156. Plugin* createPlugin()
  157. {
  158. return new GainExamplePlugin();
  159. }
  160. // -----------------------------------------------------------------------------------------------------------
  161. END_NAMESPACE_DISTRHO