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.

227 lines
7.1KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 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 to show how to get some basic information sent to the UI.
  21. */
  22. class EmbedExternalExamplePlugin : public Plugin
  23. {
  24. public:
  25. EmbedExternalExamplePlugin()
  26. : Plugin(kParameterCount, 0, 0),
  27. fWidth(512.0f),
  28. fHeight(256.0f)
  29. {
  30. }
  31. protected:
  32. /* --------------------------------------------------------------------------------------------------------
  33. * Information */
  34. /**
  35. Get the plugin label.
  36. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  37. */
  38. const char* getLabel() const override
  39. {
  40. return "EmbedExternalUI";
  41. }
  42. /**
  43. Get an extensive comment/description about the plugin.
  44. */
  45. const char* getDescription() const override
  46. {
  47. return "Plugin to show how to use an embedable dpf-external UI.";
  48. }
  49. /**
  50. Get the plugin author/maker.
  51. */
  52. const char* getMaker() const override
  53. {
  54. return "DISTRHO";
  55. }
  56. /**
  57. Get the plugin homepage.
  58. */
  59. const char* getHomePage() const override
  60. {
  61. return "https://github.com/DISTRHO/DPF";
  62. }
  63. /**
  64. Get the plugin license name (a single line of text).
  65. For commercial plugins this should return some short copyright information.
  66. */
  67. const char* getLicense() const override
  68. {
  69. return "ISC";
  70. }
  71. /**
  72. Get the plugin version, in hexadecimal.
  73. */
  74. uint32_t getVersion() const override
  75. {
  76. return d_version(1, 0, 0);
  77. }
  78. /**
  79. Get the plugin unique Id.
  80. This value is used by LADSPA, DSSI and VST plugin formats.
  81. */
  82. int64_t getUniqueId() const override
  83. {
  84. return d_cconst('d', 'b', 'x', 't');
  85. }
  86. /* --------------------------------------------------------------------------------------------------------
  87. * Init */
  88. /**
  89. Initialize the audio port @a index.@n
  90. This function will be called once, shortly after the plugin is created.
  91. */
  92. void initAudioPort(bool input, uint32_t index, AudioPort& port) override
  93. {
  94. // treat meter audio ports as stereo
  95. port.groupId = kPortGroupStereo;
  96. // everything else is as default
  97. Plugin::initAudioPort(input, index, port);
  98. }
  99. /**
  100. Initialize the parameter @a index.
  101. This function will be called once, shortly after the plugin is created.
  102. */
  103. void initParameter(uint32_t index, Parameter& parameter) override
  104. {
  105. switch (index)
  106. {
  107. case kParameterWidth:
  108. parameter.hints = kParameterIsAutomatable|kParameterIsInteger;
  109. parameter.ranges.def = 512.0f;
  110. parameter.ranges.min = 256.0f;
  111. parameter.ranges.max = 4096.0f;
  112. parameter.name = "Width";
  113. parameter.symbol = "width";
  114. parameter.unit = "px";
  115. break;
  116. case kParameterHeight:
  117. parameter.hints = kParameterIsAutomatable|kParameterIsInteger;
  118. parameter.ranges.def = 256.0f;
  119. parameter.ranges.min = 256.0f;
  120. parameter.ranges.max = 4096.0f;
  121. parameter.name = "Height";
  122. parameter.symbol = "height";
  123. parameter.unit = "px";
  124. break;
  125. }
  126. }
  127. /* --------------------------------------------------------------------------------------------------------
  128. * Internal data */
  129. /**
  130. Get the current value of a parameter.
  131. The host may call this function from any context, including realtime processing.
  132. */
  133. float getParameterValue(uint32_t index) const override
  134. {
  135. switch (index)
  136. {
  137. case kParameterWidth:
  138. return fWidth;
  139. case kParameterHeight:
  140. return fHeight;
  141. }
  142. return 0.0f;
  143. }
  144. /**
  145. Change a parameter value.
  146. The host may call this function from any context, including realtime processing.
  147. When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
  148. @note This function will only be called for parameter inputs.
  149. */
  150. void setParameterValue(uint32_t index, float value) override
  151. {
  152. switch (index)
  153. {
  154. case kParameterWidth:
  155. fWidth = value;
  156. break;
  157. case kParameterHeight:
  158. fHeight = value;
  159. break;
  160. }
  161. }
  162. /* --------------------------------------------------------------------------------------------------------
  163. * Audio/MIDI Processing */
  164. /**
  165. Run/process function for plugins without MIDI input.
  166. @note Some parameters might be null if there are no audio inputs or outputs.
  167. */
  168. void run(const float** inputs, float** outputs, uint32_t frames) override
  169. {
  170. /**
  171. This plugin does nothing, it just demonstrates information usage.
  172. So here we directly copy inputs over outputs, leaving the audio untouched.
  173. We need to be careful in case the host re-uses the same buffer for both inputs and outputs.
  174. */
  175. if (outputs[0] != inputs[0])
  176. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  177. if (outputs[1] != inputs[1])
  178. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  179. }
  180. // -------------------------------------------------------------------------------------------------------
  181. private:
  182. // Parameters
  183. float fWidth, fHeight;
  184. /**
  185. Set our plugin class as non-copyable and add a leak detector just in case.
  186. */
  187. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(EmbedExternalExamplePlugin)
  188. };
  189. /* ------------------------------------------------------------------------------------------------------------
  190. * Plugin entry point, called by DPF to create a new plugin instance. */
  191. Plugin* createPlugin()
  192. {
  193. return new EmbedExternalExamplePlugin();
  194. }
  195. // -----------------------------------------------------------------------------------------------------------
  196. END_NAMESPACE_DISTRHO