DPF Plugin examples
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.

205 lines
5.8KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2014 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. #include "dsp/dsp_reverb.hxx"
  18. START_NAMESPACE_DISTRHO
  19. // -----------------------------------------------------------------------------------------------------------
  20. class ArtyFxPluginRoomy : public Plugin
  21. {
  22. public:
  23. ArtyFxPluginRoomy()
  24. : Plugin(3, 0, 0), // 3 parameters, 0 programs, 0 states
  25. dspReverb(d_getSampleRate())
  26. {
  27. // Initialize all our parameters to their defaults.
  28. controlTime = 0.5f;
  29. controlDamping = 0.5f;
  30. controlDryWet = 0.5f;
  31. }
  32. protected:
  33. /* --------------------------------------------------------------------------------------------------------
  34. * Information */
  35. /**
  36. Get the plugin label.
  37. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  38. */
  39. const char* d_getLabel() const override
  40. {
  41. return "roomy";
  42. }
  43. /**
  44. Get the plugin author/maker.
  45. */
  46. const char* d_getMaker() const override
  47. {
  48. return "OpenAV Productions";
  49. }
  50. /**
  51. Get the plugin license name (a single line of text).
  52. */
  53. const char* d_getLicense() const override
  54. {
  55. return "ISC";
  56. }
  57. /**
  58. Get the plugin version, in hexadecimal.
  59. TODO format to be defined
  60. */
  61. uint32_t d_getVersion() const override
  62. {
  63. return 0x1000;
  64. }
  65. /**
  66. Get the plugin unique Id.
  67. This value is used by LADSPA, DSSI and VST plugin formats.
  68. */
  69. int64_t d_getUniqueId() const override
  70. {
  71. return d_cconst('O', 'V', 'r', 'm');
  72. }
  73. /* --------------------------------------------------------------------------------------------------------
  74. * Init */
  75. /**
  76. Initialize the parameter @a index.
  77. This function will be called once, shortly after the plugin is created.
  78. */
  79. void d_initParameter(uint32_t index, Parameter& parameter) override
  80. {
  81. parameter.hints = kParameterIsAutomable;
  82. parameter.ranges.def = 0.5f;
  83. parameter.ranges.min = 0.0f;
  84. parameter.ranges.max = 1.0f;
  85. switch (index)
  86. {
  87. case 0:
  88. parameter.name = "Time";
  89. parameter.symbol = "time";
  90. break;
  91. case 1:
  92. parameter.name = "Damping";
  93. parameter.symbol = "damping";
  94. break;
  95. case 2:
  96. parameter.name = "Dry Wet Mix";
  97. parameter.symbol = "dry_wet";
  98. break;
  99. }
  100. }
  101. /* --------------------------------------------------------------------------------------------------------
  102. * Internal data */
  103. /**
  104. Get the current value of a parameter.
  105. */
  106. float d_getParameterValue(uint32_t index) const override
  107. {
  108. switch (index)
  109. {
  110. case 0: return controlTime;
  111. case 1: return controlDamping;
  112. case 2: return controlDryWet;
  113. }
  114. return 0.0f;
  115. }
  116. /**
  117. Change a parameter value.
  118. */
  119. void d_setParameterValue(uint32_t index, float value) override
  120. {
  121. switch (index)
  122. {
  123. case 0:
  124. controlTime = value;
  125. break;
  126. case 1:
  127. controlDamping = value;
  128. break;
  129. case 2:
  130. controlDryWet = value;
  131. break;
  132. }
  133. }
  134. /* --------------------------------------------------------------------------------------------------------
  135. * Process */
  136. /**
  137. Run/process function for plugins without MIDI input.
  138. */
  139. void d_run(const float** inputs, float** outputs, uint32_t frames) override
  140. {
  141. dspReverb.rt60 ( controlTime );
  142. dspReverb.damping ( controlDamping );
  143. dspReverb.dryWet ( controlDryWet );
  144. dspReverb.process(frames, inputs, outputs);
  145. }
  146. /* --------------------------------------------------------------------------------------------------------
  147. * Callbacks */
  148. /**
  149. Optional callback to inform the plugin about a sample rate change.
  150. This function will only be called when the plugin is deactivated.
  151. */
  152. void d_sampleRateChanged(double /*newSampleRate*/) override
  153. {
  154. // TODO - reinit dspReverb
  155. }
  156. // -------------------------------------------------------------------------------------------------------
  157. private:
  158. // our parameters
  159. float controlTime;
  160. float controlDamping;
  161. float controlDryWet;
  162. // the reverb
  163. Reverb dspReverb;
  164. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ArtyFxPluginRoomy)
  165. };
  166. /* ------------------------------------------------------------------------------------------------------------
  167. * Plugin entry point, called by DPF to create a new plugin instance. */
  168. Plugin* createPlugin()
  169. {
  170. return new ArtyFxPluginRoomy();
  171. }
  172. // -----------------------------------------------------------------------------------------------------------
  173. END_NAMESPACE_DISTRHO