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.

289 lines
10KB

  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. Plugin to show how to get some basic information sent to the UI.
  21. */
  22. class InfoExamplePlugin : public Plugin
  23. {
  24. public:
  25. InfoExamplePlugin()
  26. : Plugin(kParameterCount, 0, 0)
  27. {
  28. // clear all parameters
  29. std::memset(fParameters, 0, sizeof(float)*kParameterCount);
  30. // we can know buffer-size right at the start
  31. fParameters[kParameterBufferSize] = getBufferSize();
  32. }
  33. protected:
  34. /* --------------------------------------------------------------------------------------------------------
  35. * Information */
  36. /**
  37. Get the plugin label.
  38. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  39. */
  40. const char* getLabel() const override
  41. {
  42. return "Info";
  43. }
  44. /**
  45. Get an extensive comment/description about the plugin.
  46. */
  47. const char* getDescription() const override
  48. {
  49. return "Plugin to show how to get some basic information sent to the UI.";
  50. }
  51. /**
  52. Get the plugin author/maker.
  53. */
  54. const char* getMaker() const override
  55. {
  56. return "DISTRHO";
  57. }
  58. /**
  59. Get the plugin homepage.
  60. */
  61. const char* getHomePage() const override
  62. {
  63. return "https://github.com/DISTRHO/DPF";
  64. }
  65. /**
  66. Get the plugin license name (a single line of text).
  67. For commercial plugins this should return some short copyright information.
  68. */
  69. const char* getLicense() const override
  70. {
  71. return "ISC";
  72. }
  73. /**
  74. Get the plugin version, in hexadecimal.
  75. */
  76. uint32_t getVersion() const override
  77. {
  78. return d_version(1, 0, 0);
  79. }
  80. /**
  81. Get the plugin unique Id.
  82. This value is used by LADSPA, DSSI and VST plugin formats.
  83. */
  84. int64_t getUniqueId() const override
  85. {
  86. return d_cconst('d', 'N', 'f', 'o');
  87. }
  88. /* --------------------------------------------------------------------------------------------------------
  89. * Init */
  90. /**
  91. Initialize the parameter @a index.
  92. This function will be called once, shortly after the plugin is created.
  93. */
  94. void initParameter(uint32_t index, Parameter& parameter) override
  95. {
  96. parameter.hints = kParameterIsAutomable|kParameterIsOutput;
  97. parameter.ranges.def = 0.0f;
  98. parameter.ranges.min = 0.0f;
  99. parameter.ranges.max = 16777216.0f;
  100. switch (index)
  101. {
  102. case kParameterBufferSize:
  103. parameter.name = "BufferSize";
  104. parameter.symbol = "buffer_size";
  105. break;
  106. case kParameterTimePlaying:
  107. parameter.hints |= kParameterIsBoolean;
  108. parameter.name = "TimePlaying";
  109. parameter.symbol = "time_playing";
  110. parameter.ranges.min = 0.0f;
  111. parameter.ranges.max = 1.0f;
  112. break;
  113. case kParameterTimeFrame:
  114. parameter.name = "TimeFrame";
  115. parameter.symbol = "time_frame";
  116. break;
  117. case kParameterTimeValidBBT:
  118. parameter.hints |= kParameterIsBoolean;
  119. parameter.name = "TimeValidBBT";
  120. parameter.symbol = "time_validbbt";
  121. parameter.ranges.min = 0.0f;
  122. parameter.ranges.max = 1.0f;
  123. break;
  124. case kParameterTimeBar:
  125. parameter.name = "TimeBar";
  126. parameter.symbol = "time_bar";
  127. break;
  128. case kParameterTimeBeat:
  129. parameter.name = "TimeBeat";
  130. parameter.symbol = "time_beat";
  131. break;
  132. case kParameterTimeTick:
  133. parameter.name = "TimeTick";
  134. parameter.symbol = "time_tick";
  135. break;
  136. case kParameterTimeBarStartTick:
  137. parameter.name = "TimeBarStartTick";
  138. parameter.symbol = "time_barstarttick";
  139. break;
  140. case kParameterTimeBeatsPerBar:
  141. parameter.name = "TimeBeatsPerBar";
  142. parameter.symbol = "time_beatsperbar";
  143. break;
  144. case kParameterTimeBeatType:
  145. parameter.name = "TimeBeatType";
  146. parameter.symbol = "time_beattype";
  147. break;
  148. case kParameterTimeTicksPerBeat:
  149. parameter.name = "TimeTicksPerBeat";
  150. parameter.symbol = "time_ticksperbeat";
  151. break;
  152. case kParameterTimeBeatsPerMinute:
  153. parameter.name = "TimeBeatsPerMinute";
  154. parameter.symbol = "time_beatsperminute";
  155. break;
  156. }
  157. }
  158. /* --------------------------------------------------------------------------------------------------------
  159. * Internal data */
  160. /**
  161. Get the current value of a parameter.
  162. The host may call this function from any context, including realtime processing.
  163. */
  164. float getParameterValue(uint32_t index) const override
  165. {
  166. return fParameters[index];
  167. }
  168. /**
  169. Change a parameter value.
  170. The host may call this function from any context, including realtime processing.
  171. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  172. @note This function will only be called for parameter inputs.
  173. */
  174. void setParameterValue(uint32_t, float) override
  175. {
  176. // this is only called for input parameters, which we have none of.
  177. }
  178. /* --------------------------------------------------------------------------------------------------------
  179. * Audio/MIDI Processing */
  180. /**
  181. Run/process function for plugins without MIDI input.
  182. @note Some parameters might be null if there are no audio inputs or outputs.
  183. */
  184. void run(const float** inputs, float** outputs, uint32_t frames) override
  185. {
  186. /**
  187. This plugin does nothing, it just demonstrates information usage.
  188. So here we directly copy inputs over outputs, leaving the audio untouched.
  189. We need to be careful in case the host re-uses the same buffer for both ins and outs.
  190. */
  191. if (outputs[0] != inputs[0])
  192. std::memcpy(outputs[0], inputs[0], sizeof(float)*frames);
  193. if (outputs[1] != inputs[1])
  194. std::memcpy(outputs[1], inputs[1], sizeof(float)*frames);
  195. // get time position
  196. const TimePosition& timePos(getTimePosition());
  197. // set basic values
  198. fParameters[kParameterTimePlaying] = timePos.playing ? 1.0f : 0.0f;
  199. fParameters[kParameterTimeFrame] = timePos.frame;
  200. fParameters[kParameterTimeValidBBT] = timePos.bbt.valid ? 1.0f : 0.0f;
  201. // set bbt
  202. if (timePos.bbt.valid)
  203. {
  204. fParameters[kParameterTimeBar] = timePos.bbt.bar;
  205. fParameters[kParameterTimeBeat] = timePos.bbt.beat;
  206. fParameters[kParameterTimeTick] = timePos.bbt.tick;
  207. fParameters[kParameterTimeBarStartTick] = timePos.bbt.barStartTick;
  208. fParameters[kParameterTimeBeatsPerBar] = timePos.bbt.beatsPerBar;
  209. fParameters[kParameterTimeBeatType] = timePos.bbt.beatType;
  210. fParameters[kParameterTimeTicksPerBeat] = timePos.bbt.ticksPerBeat;
  211. fParameters[kParameterTimeBeatsPerMinute] = timePos.bbt.beatsPerMinute;
  212. }
  213. else
  214. {
  215. fParameters[kParameterTimeBar] = 0.0f;
  216. fParameters[kParameterTimeBeat] = 0.0f;
  217. fParameters[kParameterTimeTick] = 0.0f;
  218. fParameters[kParameterTimeBarStartTick] = 0.0f;
  219. fParameters[kParameterTimeBeatsPerBar] = 0.0f;
  220. fParameters[kParameterTimeBeatType] = 0.0f;
  221. fParameters[kParameterTimeTicksPerBeat] = 0.0f;
  222. fParameters[kParameterTimeBeatsPerMinute] = 0.0f;
  223. }
  224. }
  225. /* --------------------------------------------------------------------------------------------------------
  226. * Callbacks (optional) */
  227. /**
  228. Optional callback to inform the plugin about a buffer size change.
  229. This function will only be called when the plugin is deactivated.
  230. @note This value is only a hint!
  231. Hosts might call run() with a higher or lower number of frames.
  232. */
  233. void bufferSizeChanged(uint32_t newBufferSize) override
  234. {
  235. fParameters[kParameterBufferSize] = newBufferSize;
  236. }
  237. // -------------------------------------------------------------------------------------------------------
  238. private:
  239. // Parameters
  240. float fParameters[kParameterCount];
  241. /**
  242. Set our plugin class as non-copyable and add a leak detector just in case.
  243. */
  244. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(InfoExamplePlugin)
  245. };
  246. /* ------------------------------------------------------------------------------------------------------------
  247. * Plugin entry point, called by DPF to create a new plugin instance. */
  248. Plugin* createPlugin()
  249. {
  250. return new InfoExamplePlugin();
  251. }
  252. // -----------------------------------------------------------------------------------------------------------
  253. END_NAMESPACE_DISTRHO