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.

322 lines
9.3KB

  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. 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(10, 2, 0) // 9 parameters, 2 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. fBypass = 0;
  35. }
  36. protected:
  37. /* --------------------------------------------------------------------------------------------------------
  38. * Information */
  39. /**
  40. Get the plugin label.
  41. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  42. */
  43. const char* getLabel() const override
  44. {
  45. return "parameters";
  46. }
  47. /**
  48. Get an extensive comment/description about the plugin.
  49. */
  50. const char* getDescription() const override
  51. {
  52. return "Simple plugin to demonstrate parameter usage (including UI).\n\
  53. The plugin will be treated as an effect, but it will not change the host audio.";
  54. }
  55. /**
  56. Get the plugin author/maker.
  57. */
  58. const char* getMaker() const override
  59. {
  60. return "DISTRHO";
  61. }
  62. /**
  63. Get the plugin homepage.
  64. */
  65. const char* getHomePage() const override
  66. {
  67. return "https://github.com/DISTRHO/DPF";
  68. }
  69. /**
  70. Get the plugin license name (a single line of text).
  71. For commercial plugins this should return some short copyright information.
  72. */
  73. const char* getLicense() const override
  74. {
  75. return "ISC";
  76. }
  77. /**
  78. Get the plugin version, in hexadecimal.
  79. */
  80. uint32_t getVersion() const override
  81. {
  82. return d_version(1, 0, 0);
  83. }
  84. /**
  85. Get the plugin unique Id.
  86. This value is used by LADSPA, DSSI and VST plugin formats.
  87. */
  88. int64_t getUniqueId() const override
  89. {
  90. return d_cconst('d', 'P', 'r', 'm');
  91. }
  92. /* --------------------------------------------------------------------------------------------------------
  93. * Init */
  94. /**
  95. Initialize the parameter @a index.
  96. This function will be called once, shortly after the plugin is created.
  97. */
  98. void initParameter(uint32_t index, Parameter& parameter) override
  99. {
  100. /**
  101. All parameters in this plugin are similar except for name.
  102. As such, we initialize the common details first, then set the unique name later.
  103. */
  104. /**
  105. Changing parameters does not cause any realtime-unsafe operations, so we can mark them as automable.
  106. Also set as boolean because they work as on/off switches.
  107. */
  108. parameter.hints = kParameterIsAutomable|kParameterIsBoolean;
  109. /**
  110. Minimum 0 (off), maximum 1 (on).
  111. Default is off.
  112. */
  113. parameter.ranges.min = 0.0f;
  114. parameter.ranges.max = 1.0f;
  115. parameter.ranges.def = 0.0f;
  116. /**
  117. Set the (unique) parameter name.
  118. @see fParamGrid
  119. */
  120. switch (index)
  121. {
  122. case 0:
  123. parameter.name = "top-left";
  124. break;
  125. case 1:
  126. parameter.name = "top-center";
  127. break;
  128. case 2:
  129. parameter.name = "top-right";
  130. break;
  131. case 3:
  132. parameter.name = "middle-left";
  133. break;
  134. case 4:
  135. parameter.name = "middle-center";
  136. break;
  137. case 5:
  138. parameter.name = "middle-right";
  139. break;
  140. case 6:
  141. parameter.name = "bottom-left";
  142. break;
  143. case 7:
  144. parameter.name = "bottom-center";
  145. break;
  146. case 8:
  147. parameter.name = "bottom-right";
  148. break;
  149. case 9:
  150. parameter.initDesignation(kParameterDesignationBypass);
  151. break;
  152. }
  153. /**
  154. Our parameter names are valid symbols except for "-".
  155. */
  156. parameter.symbol = parameter.name;
  157. parameter.symbol.replace('-', '_');
  158. }
  159. /**
  160. Set the name of the program @a index.
  161. This function will be called once, shortly after the plugin is created.
  162. */
  163. void initProgramName(uint32_t index, String& programName) override
  164. {
  165. switch (index)
  166. {
  167. case 0:
  168. programName = "Default";
  169. break;
  170. case 1:
  171. programName = "Custom";
  172. break;
  173. }
  174. }
  175. /* --------------------------------------------------------------------------------------------------------
  176. * Internal data */
  177. /**
  178. Get the current value of a parameter.
  179. */
  180. float getParameterValue(uint32_t index) const override
  181. {
  182. switch (index)
  183. {
  184. case 9:
  185. return fBypass;
  186. }
  187. DISTRHO_SAFE_ASSERT_RETURN(index < 9, 0);
  188. return fParamGrid[index];
  189. }
  190. /**
  191. Change a parameter value.
  192. */
  193. void setParameterValue(uint32_t index, float value) override
  194. {
  195. switch (index)
  196. {
  197. case 9:
  198. fBypass = value;
  199. return;
  200. }
  201. DISTRHO_SAFE_ASSERT_RETURN(index < 9,);
  202. fParamGrid[index] = value;
  203. }
  204. /**
  205. Load a program.
  206. The host may call this function from any context, including realtime processing.
  207. */
  208. void loadProgram(uint32_t index) override
  209. {
  210. switch (index)
  211. {
  212. case 0:
  213. fParamGrid[0] = 0.0f;
  214. fParamGrid[1] = 0.0f;
  215. fParamGrid[2] = 0.0f;
  216. fParamGrid[3] = 0.0f;
  217. fParamGrid[4] = 0.0f;
  218. fParamGrid[5] = 0.0f;
  219. fParamGrid[6] = 0.0f;
  220. fParamGrid[7] = 0.0f;
  221. fParamGrid[8] = 0.0f;
  222. fBypass = 0.0f;
  223. break;
  224. case 1:
  225. fParamGrid[0] = 1.0f;
  226. fParamGrid[1] = 1.0f;
  227. fParamGrid[2] = 0.0f;
  228. fParamGrid[3] = 0.0f;
  229. fParamGrid[4] = 1.0f;
  230. fParamGrid[5] = 1.0f;
  231. fParamGrid[6] = 1.0f;
  232. fParamGrid[7] = 0.0f;
  233. fParamGrid[8] = 1.0f;
  234. fBypass = 0.0f;
  235. break;
  236. }
  237. }
  238. /* --------------------------------------------------------------------------------------------------------
  239. * Process */
  240. /**
  241. Run/process function for plugins without MIDI input.
  242. */
  243. void run(const float** inputs, float** outputs, uint32_t frames) override
  244. {
  245. /**
  246. This plugin does nothing, it just demonstrates parameter usage.
  247. So here we directly copy inputs over outputs, leaving the audio untouched.
  248. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  249. */
  250. if (outputs[0] != inputs[0])
  251. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  252. if (outputs[1] != inputs[1])
  253. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  254. }
  255. // -------------------------------------------------------------------------------------------------------
  256. private:
  257. /**
  258. Our parameters are used to display a 3x3 grid like this:
  259. 0 1 2
  260. 3 4 5
  261. 6 7 8
  262. The index matches its grid position.
  263. */
  264. float fParamGrid[9];
  265. /**
  266. This special parameter indicates the bypassed state of the plugin.
  267. A plugin turns its effect off under the condition fBypass > 0.5.
  268. */
  269. float fBypass;
  270. /**
  271. Set our plugin class as non-copyable and add a leak detector just in case.
  272. */
  273. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExamplePluginParameters)
  274. };
  275. /* ------------------------------------------------------------------------------------------------------------
  276. * Plugin entry point, called by DPF to create a new plugin instance. */
  277. Plugin* createPlugin()
  278. {
  279. return new ExamplePluginParameters();
  280. }
  281. // -----------------------------------------------------------------------------------------------------------
  282. END_NAMESPACE_DISTRHO