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.

226 lines
6.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. START_NAMESPACE_DISTRHO
  18. // -----------------------------------------------------------------------------------------------------------
  19. /**
  20. Simple plugin to demonstrate parameter usage (including UI).
  21. The plugin will be treated as an effect, but it will not change the host audio.
  22. */
  23. class ExamplePluginParameters : public Plugin
  24. {
  25. public:
  26. ExamplePluginParameters()
  27. : Plugin(9, 0, 0) // 9 parameters, 0 programs, 0 states
  28. {
  29. /**
  30. Initialize all our parameters to their defaults.
  31. In this example all parameters have 0 as default, so we can simply zero them.
  32. */
  33. std::memset(fParamGrid, 0, sizeof(float)*9);
  34. }
  35. protected:
  36. /* --------------------------------------------------------------------------------------------------------
  37. * Information */
  38. /**
  39. Get the plugin label.
  40. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  41. */
  42. const char* d_getLabel() const override
  43. {
  44. return "parameters";
  45. }
  46. /**
  47. Get the plugin author/maker.
  48. */
  49. const char* d_getMaker() const override
  50. {
  51. return "DISTRHO";
  52. }
  53. /**
  54. Get the plugin license name (a single line of text).
  55. */
  56. const char* d_getLicense() const override
  57. {
  58. return "ISC";
  59. }
  60. /**
  61. Get the plugin version, in hexadecimal.
  62. TODO format to be defined
  63. */
  64. uint32_t d_getVersion() const override
  65. {
  66. return 0x1000;
  67. }
  68. /**
  69. Get the plugin unique Id.
  70. This value is used by LADSPA, DSSI and VST plugin formats.
  71. */
  72. int64_t d_getUniqueId() const override
  73. {
  74. return d_cconst('d', 'P', 'r', 'm');
  75. }
  76. /* --------------------------------------------------------------------------------------------------------
  77. * Init */
  78. /**
  79. Initialize the parameter @a index.
  80. This function will be called once, shortly after the plugin is created.
  81. */
  82. void d_initParameter(uint32_t index, Parameter& parameter) override
  83. {
  84. /**
  85. All parameters in this plugin are similar except for name.
  86. As such, we initialize the common details first, then set the unique name later.
  87. */
  88. /**
  89. Changing parameters does not cause any realtime-unsafe operations, so we can mark them as automable.
  90. Also set as boolean because they work are on/off switches.
  91. */
  92. parameter.hints = kParameterIsAutomable|kParameterIsBoolean;
  93. /**
  94. Minimum 0 (off), maximum 1 (on).
  95. Default is off.
  96. */
  97. parameter.ranges.min = 0.0f;
  98. parameter.ranges.max = 1.0f;
  99. parameter.ranges.def = 0.0f;
  100. /**
  101. Set the (unique) parameter name.
  102. @see fParamGrid
  103. */
  104. switch (index)
  105. {
  106. case 0:
  107. parameter.name = "top-left";
  108. break;
  109. case 1:
  110. parameter.name = "top-center";
  111. break;
  112. case 2:
  113. parameter.name = "top-right";
  114. break;
  115. case 3:
  116. parameter.name = "middle-left";
  117. break;
  118. case 4:
  119. parameter.name = "middle-center";
  120. break;
  121. case 5:
  122. parameter.name = "middle-right";
  123. break;
  124. case 6:
  125. parameter.name = "bottom-left";
  126. break;
  127. case 7:
  128. parameter.name = "bottom-center";
  129. break;
  130. case 8:
  131. parameter.name = "bottom-right";
  132. break;
  133. }
  134. /**
  135. Our parameter names are valid symbols except for "-".
  136. */
  137. parameter.symbol = parameter.name;
  138. parameter.symbol.replace('-', '_');
  139. }
  140. /* --------------------------------------------------------------------------------------------------------
  141. * Internal data */
  142. /**
  143. Get the current value of a parameter.
  144. */
  145. float d_getParameterValue(uint32_t index) const override
  146. {
  147. return fParamGrid[index];
  148. }
  149. /**
  150. Change a parameter value.
  151. */
  152. void d_setParameterValue(uint32_t index, float value) override
  153. {
  154. fParamGrid[index] = value;
  155. }
  156. /* --------------------------------------------------------------------------------------------------------
  157. * Process */
  158. /**
  159. Run/process function for plugins without MIDI input.
  160. */
  161. void d_run(const float** inputs, float** outputs, uint32_t frames) override
  162. {
  163. /**
  164. This plugin does nothing, it just demonstrates parameter usage.
  165. So here we directly copy inputs over outputs, leaving the audio untouched.
  166. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  167. */
  168. if (outputs[0] != inputs[0])
  169. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  170. if (outputs[1] != inputs[1])
  171. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  172. }
  173. // -------------------------------------------------------------------------------------------------------
  174. private:
  175. /**
  176. Our parameters are used to display a 3x3 grid like this:
  177. 0 1 2
  178. 3 4 5
  179. 6 7 8
  180. The index matches its grid position.
  181. */
  182. float fParamGrid[9];
  183. /**
  184. Set our plugin class as non-copyable and add a leak detector just in case.
  185. */
  186. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExamplePluginParameters)
  187. };
  188. /* ------------------------------------------------------------------------------------------------------------
  189. * Plugin entry point, called by DPF to create a new plugin instance. */
  190. Plugin* createPlugin()
  191. {
  192. return new ExamplePluginParameters();
  193. }
  194. // -----------------------------------------------------------------------------------------------------------
  195. END_NAMESPACE_DISTRHO