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.

201 lines
6.3KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2019 Filipe Coelho <falktx@falktx.com>
  4. * Copyright (C) 2019-2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  7. * or without fee is hereby granted, provided that the above copyright notice and this
  8. * permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  11. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  12. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  15. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include "DistrhoPlugin.hpp"
  18. #include <string.h>
  19. START_NAMESPACE_DISTRHO
  20. class CairoExamplePlugin : public Plugin
  21. {
  22. float fParameters[kParameterCount];
  23. public:
  24. CairoExamplePlugin()
  25. : Plugin(kParameterCount, 0, 0)
  26. {
  27. std::memset(fParameters, 0, sizeof(fParameters));
  28. }
  29. /**
  30. Get the plugin label.@n
  31. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  32. */
  33. const char* getLabel() const override
  34. {
  35. return "cairo_ui";
  36. }
  37. /**
  38. Get an extensive comment/description about the plugin.
  39. */
  40. const char* getDescription() const override
  41. {
  42. return "Cairo DPF Example";
  43. }
  44. /**
  45. Get the plugin author/maker.
  46. */
  47. const char* getMaker() const override
  48. {
  49. return "DISTRHO";
  50. }
  51. /**
  52. Get the plugin license (a single line of text or a URL).@n
  53. For commercial plugins this should return some short copyright information.
  54. */
  55. const char* getLicense() const override
  56. {
  57. return "ISC";
  58. }
  59. /**
  60. Get the plugin version, in hexadecimal.
  61. */
  62. uint32_t getVersion() const override
  63. {
  64. return d_version(1, 0, 0);
  65. }
  66. /**
  67. Get the plugin unique Id.@n
  68. This value is used by LADSPA, DSSI, VST2 and VST3 plugin formats.
  69. */
  70. int64_t getUniqueId() const override
  71. {
  72. return d_cconst('d', 'C', 'a', 'i');
  73. }
  74. /**
  75. Initialize the audio port @a index.@n
  76. This function will be called once, shortly after the plugin is created.
  77. */
  78. void initAudioPort(const bool input, const uint32_t index, AudioPort& port) override
  79. {
  80. // treat meter audio ports as stereo
  81. port.groupId = kPortGroupMono;
  82. // everything else is as default
  83. Plugin::initAudioPort(input, index, port);
  84. }
  85. /**
  86. Initialize the parameter @a index.@n
  87. This function will be called once, shortly after the plugin is created.
  88. */
  89. void initParameter(const uint32_t index, Parameter& parameter) override
  90. {
  91. /**
  92. All parameters in this plugin have the same ranges.
  93. */
  94. switch (index)
  95. {
  96. case kParameterKnob:
  97. parameter.hints = kParameterIsAutomatable;
  98. parameter.name = "Knob";
  99. parameter.symbol = "knob";
  100. parameter.ranges.min = 0.0f;
  101. parameter.ranges.max = 1.0f;
  102. parameter.ranges.def = 0.0f;
  103. break;
  104. case kParameterTriState:
  105. parameter.hints = kParameterIsAutomatable|kParameterIsInteger;
  106. parameter.name = "Color";
  107. parameter.symbol = "color";
  108. parameter.ranges.min = 0.0f;
  109. parameter.ranges.max = 2.0f;
  110. parameter.ranges.def = 0.0f;
  111. parameter.enumValues.count = 3;
  112. parameter.enumValues.restrictedMode = true;
  113. {
  114. ParameterEnumerationValue* const values = new ParameterEnumerationValue[3];
  115. parameter.enumValues.values = values;
  116. values[0].label = "Red";
  117. values[0].value = 0;
  118. values[1].label = "Green";
  119. values[1].value = 1;
  120. values[2].label = "Blue";
  121. values[2].value = 2;
  122. }
  123. break;
  124. case kParameterButton:
  125. parameter.hints = kParameterIsAutomatable|kParameterIsBoolean;
  126. parameter.name = "Button";
  127. parameter.symbol = "button";
  128. parameter.ranges.min = 0.0f;
  129. parameter.ranges.max = 1.0f;
  130. parameter.ranges.def = 0.0f;
  131. parameter.enumValues.count = 2;
  132. parameter.enumValues.restrictedMode = true;
  133. {
  134. ParameterEnumerationValue* const values = new ParameterEnumerationValue[2];
  135. parameter.enumValues.values = values;
  136. values[0].label = "Off";
  137. values[0].value = 0;
  138. values[1].label = "On";
  139. values[1].value = 1;
  140. }
  141. break;
  142. }
  143. }
  144. /**
  145. Get the current value of a parameter.@n
  146. The host may call this function from any context, including realtime processing.
  147. */
  148. float getParameterValue(const uint32_t index) const override
  149. {
  150. return fParameters[index];
  151. }
  152. /**
  153. Change a parameter value.@n
  154. The host may call this function from any context, including realtime processing.@n
  155. When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
  156. @note This function will only be called for parameter inputs.
  157. */
  158. void setParameterValue(const uint32_t index, const float value) override
  159. {
  160. fParameters[index] = value;
  161. }
  162. /**
  163. Run/process function for plugins without MIDI input.
  164. @note Some parameters might be null if there are no audio inputs or outputs.
  165. */
  166. void run(const float** const inputs, float** const outputs, const uint32_t frames) override
  167. {
  168. /**
  169. This plugin does nothing, it just demonstrates cairo UI usage.
  170. So here we directly copy inputs over outputs, leaving the audio untouched.
  171. We need to be careful in case the host re-uses the same buffer for both inputs and outputs.
  172. */
  173. if (outputs[0] != inputs[0])
  174. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  175. }
  176. };
  177. Plugin* createPlugin()
  178. {
  179. return new CairoExamplePlugin;
  180. }
  181. END_NAMESPACE_DISTRHO