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.

317 lines
10.0KB

  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 state usage (including UI).
  21. The plugin will be treated as an effect, but it will not change the host audio.
  22. */
  23. class ExamplePluginStates : public Plugin
  24. {
  25. public:
  26. ExamplePluginStates()
  27. : Plugin(0, 2, 9) // 0 parameters, 2 programs, 9 states
  28. {
  29. /**
  30. Initialize all our parameters to their defaults.
  31. In this example all default values are false, so we can simply zero them.
  32. */
  33. std::memset(fParamGrid, 0, sizeof(bool)*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* getLabel() const override
  43. {
  44. return "states";
  45. }
  46. /**
  47. Get an extensive comment/description about the plugin.
  48. */
  49. const char* getDescription() const override
  50. {
  51. return "Simple plugin to demonstrate state usage (including UI).\n\
  52. The plugin will be treated as an effect, but it will not change the host audio.";
  53. }
  54. /**
  55. Get the plugin author/maker.
  56. */
  57. const char* getMaker() const override
  58. {
  59. return "DISTRHO";
  60. }
  61. /**
  62. Get the plugin homepage.
  63. */
  64. const char* getHomePage() const override
  65. {
  66. return "https://github.com/DISTRHO/plugin-examples";
  67. }
  68. /**
  69. Get the plugin license name (a single line of text).
  70. For commercial plugins this should return some short copyright information.
  71. */
  72. const char* getLicense() const override
  73. {
  74. return "ISC";
  75. }
  76. /**
  77. Get the plugin version, in hexadecimal.
  78. */
  79. uint32_t getVersion() const override
  80. {
  81. return d_version(1, 0, 0);
  82. }
  83. /**
  84. Get the plugin unique Id.
  85. This value is used by LADSPA, DSSI and VST plugin formats.
  86. */
  87. int64_t getUniqueId() const override
  88. {
  89. return d_cconst('d', 'S', 't', 's');
  90. }
  91. /* --------------------------------------------------------------------------------------------------------
  92. * Init */
  93. /**
  94. This plugin has no parameters..
  95. */
  96. void initParameter(uint32_t, Parameter&) override {}
  97. /**
  98. Set the name of the program @a index.
  99. This function will be called once, shortly after the plugin is created.
  100. */
  101. void initProgramName(uint32_t index, String& programName) override
  102. {
  103. switch (index)
  104. {
  105. case 0:
  106. programName = "Default";
  107. break;
  108. case 1:
  109. programName = "Custom";
  110. break;
  111. }
  112. }
  113. /**
  114. Set the state key and default value of @a index.
  115. This function will be called once, shortly after the plugin is created.
  116. */
  117. void initState(uint32_t index, String& stateKey, String& defaultStateValue) override
  118. {
  119. switch (index)
  120. {
  121. case 0:
  122. stateKey = "top-left";
  123. break;
  124. case 1:
  125. stateKey = "top-center";
  126. break;
  127. case 2:
  128. stateKey = "top-right";
  129. break;
  130. case 3:
  131. stateKey = "middle-left";
  132. break;
  133. case 4:
  134. stateKey = "middle-center";
  135. break;
  136. case 5:
  137. stateKey = "middle-right";
  138. break;
  139. case 6:
  140. stateKey = "bottom-left";
  141. break;
  142. case 7:
  143. stateKey = "bottom-center";
  144. break;
  145. case 8:
  146. stateKey = "bottom-right";
  147. break;
  148. }
  149. defaultStateValue = "false";
  150. }
  151. /* --------------------------------------------------------------------------------------------------------
  152. * Internal data */
  153. /**
  154. This plugin has no parameters..
  155. */
  156. void setParameterValue(uint32_t, float) override {}
  157. float getParameterValue(uint32_t) const override { return 0.0f; }
  158. /**
  159. Load a program.
  160. The host may call this function from any context, including realtime processing.
  161. */
  162. void loadProgram(uint32_t index) override
  163. {
  164. switch (index)
  165. {
  166. case 0:
  167. fParamGrid[0] = false;
  168. fParamGrid[1] = false;
  169. fParamGrid[2] = false;
  170. fParamGrid[3] = false;
  171. fParamGrid[4] = false;
  172. fParamGrid[5] = false;
  173. fParamGrid[6] = false;
  174. fParamGrid[7] = false;
  175. fParamGrid[8] = false;
  176. break;
  177. case 1:
  178. fParamGrid[0] = true;
  179. fParamGrid[1] = true;
  180. fParamGrid[2] = false;
  181. fParamGrid[3] = false;
  182. fParamGrid[4] = true;
  183. fParamGrid[5] = true;
  184. fParamGrid[6] = true;
  185. fParamGrid[7] = false;
  186. fParamGrid[8] = true;
  187. break;
  188. }
  189. }
  190. /**
  191. Get the value of an internal state.
  192. The host may call this function from any non-realtime context.
  193. */
  194. String getState(const char* key) const override
  195. {
  196. static const String sTrue ("true");
  197. static const String sFalse("false");
  198. // check which block changed
  199. /**/ if (std::strcmp(key, "top-left") == 0)
  200. return fParamGrid[0] ? sTrue : sFalse;
  201. else if (std::strcmp(key, "top-center") == 0)
  202. return fParamGrid[1] ? sTrue : sFalse;
  203. else if (std::strcmp(key, "top-right") == 0)
  204. return fParamGrid[2] ? sTrue : sFalse;
  205. else if (std::strcmp(key, "middle-left") == 0)
  206. return fParamGrid[3] ? sTrue : sFalse;
  207. else if (std::strcmp(key, "middle-center") == 0)
  208. return fParamGrid[4] ? sTrue : sFalse;
  209. else if (std::strcmp(key, "middle-right") == 0)
  210. return fParamGrid[5] ? sTrue : sFalse;
  211. else if (std::strcmp(key, "bottom-left") == 0)
  212. return fParamGrid[6] ? sTrue : sFalse;
  213. else if (std::strcmp(key, "bottom-center") == 0)
  214. return fParamGrid[7] ? sTrue : sFalse;
  215. else if (std::strcmp(key, "bottom-right") == 0)
  216. return fParamGrid[8] ? sTrue : sFalse;
  217. return sFalse;
  218. }
  219. /**
  220. Change an internal state.
  221. */
  222. void setState(const char* key, const char* value) override
  223. {
  224. const bool valueOnOff = (std::strcmp(value, "true") == 0);
  225. // check which block changed
  226. /**/ if (std::strcmp(key, "top-left") == 0)
  227. fParamGrid[0] = valueOnOff;
  228. else if (std::strcmp(key, "top-center") == 0)
  229. fParamGrid[1] = valueOnOff;
  230. else if (std::strcmp(key, "top-right") == 0)
  231. fParamGrid[2] = valueOnOff;
  232. else if (std::strcmp(key, "middle-left") == 0)
  233. fParamGrid[3] = valueOnOff;
  234. else if (std::strcmp(key, "middle-center") == 0)
  235. fParamGrid[4] = valueOnOff;
  236. else if (std::strcmp(key, "middle-right") == 0)
  237. fParamGrid[5] = valueOnOff;
  238. else if (std::strcmp(key, "bottom-left") == 0)
  239. fParamGrid[6] = valueOnOff;
  240. else if (std::strcmp(key, "bottom-center") == 0)
  241. fParamGrid[7] = valueOnOff;
  242. else if (std::strcmp(key, "bottom-right") == 0)
  243. fParamGrid[8] = valueOnOff;
  244. }
  245. /* --------------------------------------------------------------------------------------------------------
  246. * Process */
  247. /**
  248. Run/process function for plugins without MIDI input.
  249. */
  250. void run(const float** inputs, float** outputs, uint32_t frames) override
  251. {
  252. /**
  253. This plugin does nothing, it just demonstrates parameter usage.
  254. So here we directly copy inputs over outputs, leaving the audio untouched.
  255. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  256. */
  257. if (outputs[0] != inputs[0])
  258. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  259. if (outputs[1] != inputs[1])
  260. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  261. }
  262. // -------------------------------------------------------------------------------------------------------
  263. private:
  264. /**
  265. Our parameters used to display the grid on/off states.
  266. */
  267. bool fParamGrid[9];
  268. /**
  269. Set our plugin class as non-copyable and add a leak detector just in case.
  270. */
  271. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExamplePluginStates)
  272. };
  273. /* ------------------------------------------------------------------------------------------------------------
  274. * Plugin entry point, called by DPF to create a new plugin instance. */
  275. Plugin* createPlugin()
  276. {
  277. return new ExamplePluginStates();
  278. }
  279. // -----------------------------------------------------------------------------------------------------------
  280. END_NAMESPACE_DISTRHO