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.

235 lines
8.0KB

  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. Plugin to demonstrate parameter outputs using meters.
  21. */
  22. class ExamplePluginInfo : public Plugin
  23. {
  24. public:
  25. ExamplePluginInfo()
  26. : Plugin(kParameterCount, 0, 0)
  27. {
  28. std::memset(fParameters, 0, sizeof(float)*kParameterCount);
  29. }
  30. protected:
  31. /* --------------------------------------------------------------------------------------------------------
  32. * Information */
  33. /**
  34. Get the plugin label.
  35. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  36. */
  37. const char* getLabel() const override
  38. {
  39. return "info";
  40. }
  41. /**
  42. Get the plugin author/maker.
  43. */
  44. const char* getMaker() const override
  45. {
  46. return "DISTRHO";
  47. }
  48. /**
  49. Get the plugin license name (a single line of text).
  50. */
  51. const char* getLicense() const override
  52. {
  53. return "ISC";
  54. }
  55. /**
  56. Get the plugin version, in hexadecimal.
  57. TODO format to be defined
  58. */
  59. uint32_t getVersion() const override
  60. {
  61. return 0x1000;
  62. }
  63. /**
  64. Get the plugin unique Id.
  65. This value is used by LADSPA, DSSI and VST plugin formats.
  66. */
  67. int64_t getUniqueId() const override
  68. {
  69. return d_cconst('d', 'N', 'f', 'o');
  70. }
  71. /* --------------------------------------------------------------------------------------------------------
  72. * Init */
  73. /**
  74. Initialize the parameter @a index.
  75. This function will be called once, shortly after the plugin is created.
  76. */
  77. void initParameter(uint32_t index, Parameter& parameter) override
  78. {
  79. parameter.hints = kParameterIsAutomable|kParameterIsOutput;
  80. parameter.ranges.def = 0.0f;
  81. parameter.ranges.min = 0.0f;
  82. parameter.ranges.max = 16777216.0f;
  83. switch (index)
  84. {
  85. case kParameterBufferSize:
  86. parameter.name = "BufferSize";
  87. parameter.symbol = "buffer_size";
  88. break;
  89. case kParameterTimePlaying:
  90. parameter.hints |= kParameterIsBoolean;
  91. parameter.name = "TimePlaying";
  92. parameter.symbol = "time_playing";
  93. parameter.ranges.min = 0.0f;
  94. parameter.ranges.max = 1.0f;
  95. break;
  96. case kParameterTimeFrame:
  97. parameter.name = "TimeFrame";
  98. parameter.symbol = "time_frame";
  99. break;
  100. case kParameterTimeValidBBT:
  101. parameter.hints |= kParameterIsBoolean;
  102. parameter.name = "TimeValidBBT";
  103. parameter.symbol = "time_validbbt";
  104. parameter.ranges.min = 0.0f;
  105. parameter.ranges.max = 1.0f;
  106. break;
  107. case kParameterTimeBar:
  108. parameter.name = "TimeBar";
  109. parameter.symbol = "time_bar";
  110. break;
  111. case kParameterTimeBeat:
  112. parameter.name = "TimeBeat";
  113. parameter.symbol = "time_beat";
  114. break;
  115. case kParameterTimeTick:
  116. parameter.name = "TimeTick";
  117. parameter.symbol = "time_tick";
  118. break;
  119. case kParameterTimeBarStartTick:
  120. parameter.name = "TimeBarStartTick";
  121. parameter.symbol = "time_barstarttick";
  122. break;
  123. case kParameterTimeBeatsPerBar:
  124. parameter.name = "TimeBeatsPerBar";
  125. parameter.symbol = "time_beatsperbar";
  126. break;
  127. case kParameterTimeBeatType:
  128. parameter.name = "TimeBeatType";
  129. parameter.symbol = "time_beattype";
  130. break;
  131. case kParameterTimeTicksPerBeat:
  132. parameter.name = "TimeTicksPerBeat";
  133. parameter.symbol = "time_ticksperbeat";
  134. break;
  135. case kParameterTimeBeatsPerMinute:
  136. parameter.name = "TimeBeatsPerMinute";
  137. parameter.symbol = "time_beatsperminute";
  138. break;
  139. }
  140. }
  141. /* --------------------------------------------------------------------------------------------------------
  142. * Internal data */
  143. /**
  144. Get the current value of a parameter.
  145. */
  146. float getParameterValue(uint32_t index) const override
  147. {
  148. return fParameters[index];
  149. }
  150. /**
  151. Change a parameter value.
  152. */
  153. void setParameterValue(uint32_t, float) override
  154. {
  155. // this is only called for input paramters, which we have none of.
  156. }
  157. /* --------------------------------------------------------------------------------------------------------
  158. * Process */
  159. /**
  160. Run/process function for plugins without MIDI input.
  161. */
  162. void run(const float** inputs, float** outputs, uint32_t frames) override
  163. {
  164. /**
  165. This plugin does nothing, it just demonstrates information usage.
  166. So here we directly copy inputs over outputs, leaving the audio untouched.
  167. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  168. */
  169. if (outputs[0] != inputs[0])
  170. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  171. if (outputs[1] != inputs[1])
  172. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  173. // set info
  174. fParameters[kParameterBufferSize] = getBufferSize();
  175. const TimePosition& timePos(getTimePosition());
  176. fParameters[kParameterTimePlaying] = timePos.playing ? 1.0f : 0.0f;
  177. fParameters[kParameterTimeFrame] = timePos.frame;
  178. fParameters[kParameterTimeValidBBT] = timePos.bbt.valid ? 1.0f : 0.0f;
  179. fParameters[kParameterTimeBar] = timePos.bbt.bar;
  180. fParameters[kParameterTimeBeat] = timePos.bbt.beat;
  181. fParameters[kParameterTimeTick] = timePos.bbt.tick;
  182. fParameters[kParameterTimeBarStartTick] = timePos.bbt.barStartTick;
  183. fParameters[kParameterTimeBeatsPerBar] = timePos.bbt.beatsPerBar;
  184. fParameters[kParameterTimeBeatType] = timePos.bbt.beatType;
  185. fParameters[kParameterTimeTicksPerBeat] = timePos.bbt.ticksPerBeat;
  186. fParameters[kParameterTimeBeatsPerMinute] = timePos.bbt.beatsPerMinute;
  187. }
  188. // -------------------------------------------------------------------------------------------------------
  189. private:
  190. // Parameters
  191. float fParameters[kParameterCount];
  192. /**
  193. Set our plugin class as non-copyable and add a leak detector just in case.
  194. */
  195. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ExamplePluginInfo)
  196. };
  197. /* ------------------------------------------------------------------------------------------------------------
  198. * Plugin entry point, called by DPF to create a new plugin instance. */
  199. Plugin* createPlugin()
  200. {
  201. return new ExamplePluginInfo();
  202. }
  203. // -----------------------------------------------------------------------------------------------------------
  204. END_NAMESPACE_DISTRHO