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.

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