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.

195 lines
5.5KB

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