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.

187 lines
5.7KB

  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 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, 0, 9) // 0 parameters, 0 programs, 9 states
  28. {
  29. // nothing here
  30. }
  31. protected:
  32. /* --------------------------------------------------------------------------------------------------------
  33. * Information */
  34. /**
  35. Get the plugin label.
  36. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  37. */
  38. const char* d_getLabel() const override
  39. {
  40. return "states";
  41. }
  42. /**
  43. Get the plugin author/maker.
  44. */
  45. const char* d_getMaker() const override
  46. {
  47. return "DISTRHO";
  48. }
  49. /**
  50. Get the plugin license name (a single line of text).
  51. */
  52. const char* d_getLicense() const override
  53. {
  54. return "ISC";
  55. }
  56. /**
  57. Get the plugin version, in hexadecimal.
  58. TODO format to be defined
  59. */
  60. uint32_t d_getVersion() const override
  61. {
  62. return 0x1000;
  63. }
  64. /**
  65. Get the plugin unique Id.
  66. This value is used by LADSPA, DSSI and VST plugin formats.
  67. */
  68. int64_t d_getUniqueId() const override
  69. {
  70. return d_cconst('d', 'S', 't', 's');
  71. }
  72. /* --------------------------------------------------------------------------------------------------------
  73. * Parameters */
  74. /**
  75. This plugin has no parameters, so we can safely ignore some functions.
  76. */
  77. void d_initParameter(uint32_t, Parameter&) override {}
  78. void d_setParameterValue(uint32_t, float) override {}
  79. float d_getParameterValue(uint32_t) const override { return 0.0f; }
  80. /* --------------------------------------------------------------------------------------------------------
  81. * State */
  82. /**
  83. Set the state key and default value of @a index.
  84. This function will be called once, shortly after the plugin is created.
  85. */
  86. void d_initState(uint32_t index, d_string& stateKey, d_string& defaultStateValue) override
  87. {
  88. switch (index)
  89. {
  90. case 0:
  91. stateKey = "top-left";
  92. break;
  93. case 1:
  94. stateKey = "top-center";
  95. break;
  96. case 2:
  97. stateKey = "top-right";
  98. break;
  99. case 3:
  100. stateKey = "middle-left";
  101. break;
  102. case 4:
  103. stateKey = "middle-center";
  104. break;
  105. case 5:
  106. stateKey = "middle-right";
  107. break;
  108. case 6:
  109. stateKey = "bottom-left";
  110. break;
  111. case 7:
  112. stateKey = "bottom-center";
  113. break;
  114. case 8:
  115. stateKey = "bottom-right";
  116. break;
  117. }
  118. defaultStateValue = "false";
  119. }
  120. /**
  121. Change an internal state.
  122. */
  123. void d_setState(const char*, const char*) override
  124. {
  125. // there is no plugin side state here.
  126. // states on this plugin will only change the UI grid, so we do nothing here
  127. }
  128. /* --------------------------------------------------------------------------------------------------------
  129. * Process */
  130. /**
  131. Run/process function for plugins without MIDI input.
  132. */
  133. void d_run(const float** inputs, float** outputs, uint32_t frames) override
  134. {
  135. /**
  136. This plugin does nothing, it just demonstrates parameter usage.
  137. So here we directly copy inputs over outputs, leaving the audio untouched.
  138. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  139. */
  140. if (outputs[0] != inputs[0])
  141. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  142. if (outputs[1] != inputs[1])
  143. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  144. }
  145. // -------------------------------------------------------------------------------------------------------
  146. private:
  147. // nothing here
  148. /**
  149. Set our plugin class as non-copyable and add a leak detector just in case.
  150. */
  151. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExamplePluginStates)
  152. };
  153. /* ------------------------------------------------------------------------------------------------------------
  154. * Plugin entry point, called by DPF to create a new plugin instance. */
  155. Plugin* createPlugin()
  156. {
  157. return new ExamplePluginStates();
  158. }
  159. // -----------------------------------------------------------------------------------------------------------
  160. END_NAMESPACE_DISTRHO