Collection of DPF-based plugins for packaging
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.

454 lines
16KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2024 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. #ifndef DISTRHO_PLUGIN_HPP_INCLUDED
  17. #define DISTRHO_PLUGIN_HPP_INCLUDED
  18. #include "DistrhoDetails.hpp"
  19. #include "extra/LeakDetector.hpp"
  20. #include "src/DistrhoPluginChecks.h"
  21. START_NAMESPACE_DISTRHO
  22. /* ------------------------------------------------------------------------------------------------------------
  23. * DPF Plugin */
  24. /**
  25. @defgroup MainClasses Main Classes
  26. @{
  27. */
  28. /**
  29. DPF Plugin class from where plugin instances are created.
  30. The public methods (Host state) are called from the plugin to get or set host information.@n
  31. They can be called from a plugin instance at anytime unless stated otherwise.@n
  32. All other methods are to be implemented by the plugin and will be called by the host.
  33. Shortly after a plugin instance is created, the various init* functions will be called by the host.@n
  34. Host will call activate() before run(), and deactivate() before the plugin instance is destroyed.@n
  35. The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.@n
  36. There is no limit on how many times run() is called, only that activate/deactivate will be called in between.
  37. The buffer size and sample rate values will remain constant between activate and deactivate.@n
  38. Buffer size is only a hint though, the host might call run() with a higher or lower number of frames.
  39. Some of this class functions are only available according to some macros.
  40. DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.@n
  41. When enabled you need to implement initProgramName() and loadProgram().
  42. DISTRHO_PLUGIN_WANT_STATE activates internal state features.@n
  43. When enabled you need to implement initState() and setState().
  44. The process function run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.@n
  45. When enabled it provides midi input events.
  46. */
  47. class Plugin
  48. {
  49. public:
  50. /**
  51. Plugin class constructor.@n
  52. You must set all parameter values to their defaults, matching ParameterRanges::def.
  53. */
  54. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  55. /**
  56. Destructor.
  57. */
  58. virtual ~Plugin();
  59. /* --------------------------------------------------------------------------------------------------------
  60. * Host state */
  61. /**
  62. Get the current buffer size that will probably be used during processing, in frames.@n
  63. This value will remain constant between activate and deactivate.
  64. @note This value is only a hint!@n
  65. Hosts might call run() with a higher or lower number of frames.
  66. @see bufferSizeChanged(uint32_t)
  67. */
  68. uint32_t getBufferSize() const noexcept;
  69. /**
  70. Get the current sample rate that will be used during processing.@n
  71. This value will remain constant between activate and deactivate.
  72. @see sampleRateChanged(double)
  73. */
  74. double getSampleRate() const noexcept;
  75. /**
  76. Get the bundle path where the plugin resides.
  77. Can return null if the plugin is not available in a bundle (if it is a single binary).
  78. @see getBinaryFilename
  79. @see getResourcePath
  80. */
  81. const char* getBundlePath() const noexcept;
  82. /**
  83. Check if this plugin instance is a "dummy" one used for plugin meta-data/information export.@n
  84. When true no processing will be done, the plugin is created only to extract information.@n
  85. In DPF, LADSPA/DSSI, VST2 and VST3 formats create one global instance per plugin binary
  86. while LV2 creates one when generating turtle meta-data.
  87. */
  88. bool isDummyInstance() const noexcept;
  89. /**
  90. Check if this plugin instance is a "selftest" one used for automated plugin tests.@n
  91. To enable this mode build with `DPF_RUNTIME_TESTING` macro defined (i.e. set as compiler build flag),
  92. and run the JACK/Standalone executable with "selftest" as its only and single argument.
  93. A few basic DSP and UI tests will run in self-test mode, with once instance having this function returning true.@n
  94. You can use this chance to do a few tests of your own as well.
  95. */
  96. bool isSelfTestInstance() const noexcept;
  97. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  98. /**
  99. Get the current host transport time position.@n
  100. This function should only be called during run().@n
  101. You can call this during other times, but the returned position is not guaranteed to be in sync.
  102. @note TimePosition is not supported in LADSPA and DSSI plugin formats.
  103. */
  104. const TimePosition& getTimePosition() const noexcept;
  105. #endif
  106. #if DISTRHO_PLUGIN_WANT_LATENCY
  107. /**
  108. Change the plugin audio output latency to @a frames.@n
  109. This function should only be called in the constructor, activate() and run().
  110. @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
  111. */
  112. void setLatency(uint32_t frames) noexcept;
  113. #endif
  114. #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  115. /**
  116. Write a MIDI output event.@n
  117. This function must only be called during run().@n
  118. Returns false when the host buffer is full, in which case do not call this again until the next run().
  119. */
  120. bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
  121. #endif
  122. #if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
  123. /**
  124. Check if parameter value change requests will work with the current plugin host.
  125. @note This function is only available if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST is enabled.
  126. @see requestParameterValueChange(uint32_t, float)
  127. */
  128. bool canRequestParameterValueChanges() const noexcept;
  129. /**
  130. Request a parameter value change from the host.
  131. If successful, this function will automatically trigger a parameter update on the UI side as well.
  132. This function can fail, for example if the host is busy with the parameter for read-only automation.
  133. Some hosts simply do not have this functionality, which can be verified with canRequestParameterValueChanges().
  134. @note This function is only available if DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST is enabled.
  135. */
  136. bool requestParameterValueChange(uint32_t index, float value) noexcept;
  137. #endif
  138. #if DISTRHO_PLUGIN_WANT_STATE
  139. /**
  140. Set state value and notify the host about the change.@n
  141. This function will call `setState()` and also trigger an update on the UI side as necessary.@n
  142. It must not be called during run.@n
  143. The state must be host readable.
  144. @note this function does nothing on DSSI plugin format, as DSSI only supports UI->DSP messages.
  145. TODO API under construction
  146. */
  147. bool updateStateValue(const char* key, const char* value) noexcept;
  148. #endif
  149. protected:
  150. /* --------------------------------------------------------------------------------------------------------
  151. * Information */
  152. /**
  153. Get the plugin name.@n
  154. Returns DISTRHO_PLUGIN_NAME by default.
  155. */
  156. virtual const char* getName() const { return DISTRHO_PLUGIN_NAME; }
  157. /**
  158. Get the plugin label.@n
  159. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  160. */
  161. #ifdef DISTRHO_PLUGIN_LABEL
  162. virtual const char* getLabel() const
  163. {
  164. return DISTRHO_PLUGIN_LABEL;
  165. }
  166. #else
  167. virtual const char* getLabel() const = 0;
  168. #endif
  169. /**
  170. Get an extensive comment/description about the plugin.@n
  171. Optional, returns nothing by default.
  172. */
  173. virtual const char* getDescription() const
  174. {
  175. #ifdef DISTRHO_PLUGIN_DESCRIPTION
  176. return DISTRHO_PLUGIN_DESCRIPTION;
  177. #else
  178. return "";
  179. #endif
  180. }
  181. /**
  182. Get the plugin author/maker.
  183. */
  184. #ifdef DISTRHO_PLUGIN_MAKER
  185. virtual const char* getMaker() const
  186. {
  187. return DISTRHO_PLUGIN_MAKER;
  188. }
  189. #else
  190. virtual const char* getMaker() const = 0;
  191. #endif
  192. /**
  193. Get the plugin homepage.@n
  194. Optional, returns nothing by default.
  195. */
  196. virtual const char* getHomePage() const
  197. {
  198. #ifdef DISTRHO_PLUGIN_HOMEPAGE
  199. return DISTRHO_PLUGIN_HOMEPAGE;
  200. #else
  201. return "";
  202. #endif
  203. }
  204. /**
  205. Get the plugin license (a single line of text or a URL).@n
  206. For commercial plugins this should return some short copyright information.
  207. */
  208. #ifdef DISTRHO_PLUGIN_LICENSE
  209. virtual const char* getLicense() const
  210. {
  211. return DISTRHO_PLUGIN_LICENSE;
  212. }
  213. #else
  214. virtual const char* getLicense() const = 0;
  215. #endif
  216. /**
  217. Get the plugin version, in hexadecimal.
  218. @see d_version()
  219. */
  220. virtual uint32_t getVersion() const = 0;
  221. /**
  222. Get the plugin unique Id.@n
  223. This value is used by LADSPA, DSSI, VST2, VST3 and AUv2 plugin formats.@n
  224. @note It is preferred that you set DISTRHO_PLUGIN_UNIQUE_ID macro instead of overriding this call,
  225. as that is required for AUv2 plugins anyhow.
  226. @see d_cconst()
  227. */
  228. #ifdef DISTRHO_PLUGIN_UNIQUE_ID
  229. virtual int64_t getUniqueId() const
  230. {
  231. return d_cconst(STRINGIFY(DISTRHO_PLUGIN_UNIQUE_ID));
  232. }
  233. #else
  234. virtual int64_t getUniqueId() const = 0;
  235. #endif
  236. /* --------------------------------------------------------------------------------------------------------
  237. * Init */
  238. /**
  239. Initialize the audio port @a index.@n
  240. This function will be called once, shortly after the plugin is created.
  241. */
  242. virtual void initAudioPort(bool input, uint32_t index, AudioPort& port);
  243. /**
  244. Initialize the parameter @a index.@n
  245. This function will be called once, shortly after the plugin is created.
  246. */
  247. virtual void initParameter(uint32_t index, Parameter& parameter);
  248. /**
  249. Initialize the port group @a groupId.@n
  250. This function will be called once,
  251. shortly after the plugin is created and all audio ports and parameters have been enumerated.
  252. */
  253. virtual void initPortGroup(uint32_t groupId, PortGroup& portGroup);
  254. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  255. /**
  256. Set the name of the program @a index.@n
  257. This function will be called once, shortly after the plugin is created.@n
  258. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  259. */
  260. virtual void initProgramName(uint32_t index, String& programName) = 0;
  261. #endif
  262. #if DISTRHO_PLUGIN_WANT_STATE
  263. /**
  264. Initialize the state @a index.@n
  265. This function will be called once, shortly after the plugin is created.@n
  266. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  267. */
  268. virtual void initState(uint32_t index, State& state);
  269. DISTRHO_DEPRECATED_BY("initState(uint32_t,State&)")
  270. virtual void initState(uint32_t, String&, String&) {}
  271. DISTRHO_DEPRECATED_BY("initState(uint32_t,State&)")
  272. virtual bool isStateFile(uint32_t) { return false; }
  273. #endif
  274. /* --------------------------------------------------------------------------------------------------------
  275. * Internal data */
  276. /**
  277. Get the current value of a parameter.@n
  278. The host may call this function from any context, including realtime processing.
  279. */
  280. virtual float getParameterValue(uint32_t index) const;
  281. /**
  282. Change a parameter value.@n
  283. The host may call this function from any context, including realtime processing.@n
  284. When a parameter is marked as automatable, you must ensure no non-realtime operations are performed.
  285. @note This function will only be called for parameter inputs.
  286. */
  287. virtual void setParameterValue(uint32_t index, float value);
  288. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  289. /**
  290. Load a program.@n
  291. The host may call this function from any context, including realtime processing.@n
  292. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  293. */
  294. virtual void loadProgram(uint32_t index);
  295. #endif
  296. #if DISTRHO_PLUGIN_WANT_FULL_STATE
  297. /**
  298. Get the value of an internal state.@n
  299. The host may call this function from any non-realtime context.@n
  300. Must be implemented by your plugin class if DISTRHO_PLUGIN_WANT_FULL_STATE is enabled.
  301. @note The use of this function breaks compatibility with the DSSI format.
  302. */
  303. virtual String getState(const char* key) const;
  304. #endif
  305. #if DISTRHO_PLUGIN_WANT_STATE
  306. /**
  307. Change an internal state @a key to @a value.@n
  308. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  309. */
  310. virtual void setState(const char* key, const char* value);
  311. #endif
  312. /* --------------------------------------------------------------------------------------------------------
  313. * Audio/MIDI Processing */
  314. /**
  315. Activate this plugin.
  316. */
  317. virtual void activate() {}
  318. /**
  319. Deactivate this plugin.
  320. */
  321. virtual void deactivate() {}
  322. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  323. /**
  324. Run/process function for plugins with MIDI input.
  325. @note Some parameters might be null if there are no audio inputs/outputs or MIDI events.
  326. */
  327. virtual void run(const float** inputs, float** outputs, uint32_t frames,
  328. const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  329. #else
  330. /**
  331. Run/process function for plugins without MIDI input.
  332. @note Some parameters might be null if there are no audio inputs or outputs.
  333. */
  334. virtual void run(const float** inputs, float** outputs, uint32_t frames) = 0;
  335. #endif
  336. /* --------------------------------------------------------------------------------------------------------
  337. * Callbacks (optional) */
  338. /**
  339. Optional callback to inform the plugin about a buffer size change.@n
  340. This function will only be called when the plugin is deactivated.
  341. @note This value is only a hint!@n
  342. Hosts might call run() with a higher or lower number of frames.
  343. @see getBufferSize()
  344. */
  345. virtual void bufferSizeChanged(uint32_t newBufferSize);
  346. /**
  347. Optional callback to inform the plugin about a sample rate change.@n
  348. This function will only be called when the plugin is deactivated.
  349. @see getSampleRate()
  350. */
  351. virtual void sampleRateChanged(double newSampleRate);
  352. /**
  353. Optional callback to inform the plugin about audio port IO changes.@n
  354. This function will only be called when the plugin is deactivated.@n
  355. Only used in AU (AudioUnit) format when DISTRHO_PLUGIN_EXTRA_IO is defined.
  356. @see DISTRHO_PLUGIN_EXTRA_IO
  357. */
  358. virtual void ioChanged(uint16_t numInputs, uint16_t numOutputs);
  359. // -------------------------------------------------------------------------------------------------------
  360. private:
  361. struct PrivateData;
  362. PrivateData* const pData;
  363. friend class PluginExporter;
  364. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
  365. };
  366. /** @} */
  367. /* ------------------------------------------------------------------------------------------------------------
  368. * Create plugin, entry point */
  369. /**
  370. @defgroup EntryPoints Entry Points
  371. @{
  372. */
  373. /**
  374. Create an instance of the Plugin class.@n
  375. This is the entry point for DPF plugins.@n
  376. DPF will call this to either create an instance of your plugin for the host
  377. or to fetch some initial information for internal caching.
  378. */
  379. extern Plugin* createPlugin();
  380. /** @} */
  381. // -----------------------------------------------------------------------------------------------------------
  382. END_NAMESPACE_DISTRHO
  383. #endif // DISTRHO_PLUGIN_HPP_INCLUDED