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.

864 lines
24KB

  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. #ifndef DISTRHO_PLUGIN_HPP_INCLUDED
  17. #define DISTRHO_PLUGIN_HPP_INCLUDED
  18. #include "extra/d_string.hpp"
  19. #include "src/DistrhoPluginChecks.h"
  20. #include <cmath>
  21. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  22. # include <cstdint>
  23. #else
  24. # include <stdint.h>
  25. #endif
  26. #ifndef M_PI
  27. # define M_PI 3.14159265358979323846
  28. #endif
  29. START_NAMESPACE_DISTRHO
  30. /**
  31. @mainpage DISTRHO %Plugin Framework
  32. DISTRHO %Plugin Framework (or @b DPF for short)
  33. is a plugin framework designed to make development of new plugins an easy and enjoyable task.@n
  34. It allows developers to create plugins with custom UIs using a simple C++ API.
  35. @section Macros
  36. You start by creating a "DistrhoPluginInfo.h" file describing the plugin via macros, see @ref PluginMacros.
  37. @section Plugin
  38. TODO
  39. @section Parameters
  40. describe input and output, automable and rt safe, boolean etc, cv
  41. */
  42. /* ------------------------------------------------------------------------------------------------------------
  43. * Plugin Macros */
  44. #ifdef DOXYGEN
  45. /**
  46. @defgroup PluginMacros Plugin Macros
  47. C Macros that describe your plugin. (defined in the "DistrhoPluginInfo.h" file)
  48. With these macros you can tell the host what features your plugin requires.@n
  49. Depending on which macros you enable, new functions will be available to call and/or override.
  50. All values are either integer or strings.@n
  51. For boolean-like values 1 means 'on' and 0 means 'off'.
  52. The values defined in this file are for documentation purposes only.@n
  53. All macros are disabled by default.
  54. Only 4 macros are required, they are:
  55. - @ref DISTRHO_PLUGIN_NAME
  56. - @ref DISTRHO_PLUGIN_NUM_INPUTS
  57. - @ref DISTRHO_PLUGIN_NUM_OUTPUTS
  58. - @ref DISTRHO_PLUGIN_URI
  59. @{
  60. */
  61. /**
  62. The plugin name.@n
  63. This is used to identify your plugin before a Plugin instance can be created.
  64. @note This macro is required.
  65. */
  66. #define DISTRHO_PLUGIN_NAME "Plugin Name"
  67. /**
  68. Number of audio inputs the plugin has.
  69. @note This macro is required.
  70. */
  71. #define DISTRHO_PLUGIN_NUM_INPUTS 2
  72. /**
  73. Number of audio outputs the plugin has.
  74. @note This macro is required.
  75. */
  76. #define DISTRHO_PLUGIN_NUM_OUTPUTS 2
  77. /**
  78. The plugin URI when exporting in LV2 format.
  79. @note This macro is required.
  80. */
  81. #define DISTRHO_PLUGIN_URI "urn:distrho:name"
  82. /**
  83. Wherever the plugin has a custom %UI.
  84. @see DISTRHO_UI_USE_NANOVG
  85. @see UI
  86. */
  87. #define DISTRHO_PLUGIN_HAS_UI 1
  88. /**
  89. Wherever the plugin processing is realtime-safe.@n
  90. TODO - list rtsafe requirements
  91. */
  92. #define DISTRHO_PLUGIN_IS_RT_SAFE 1
  93. /**
  94. Wherever the plugin is a synth.@n
  95. @ref DISTRHO_PLUGIN_WANT_MIDI_INPUT is automatically enabled when this is too.
  96. @see DISTRHO_PLUGIN_WANT_MIDI_INPUT
  97. */
  98. #define DISTRHO_PLUGIN_IS_SYNTH 1
  99. /**
  100. Enable direct access between the %UI and plugin code.
  101. @see UI::d_getPluginInstancePointer()
  102. @note DO NOT USE THIS UNLESS STRICTLY NECESSARY!!
  103. Try to avoid it at all costs!
  104. */
  105. #define DISTRHO_PLUGIN_WANT_DIRECT_ACCESS 0
  106. /**
  107. Wherever the plugin introduces latency during audio or midi processing.
  108. @see Plugin::d_setLatency(uint32_t)
  109. */
  110. #define DISTRHO_PLUGIN_WANT_LATENCY 1
  111. /**
  112. Wherever the plugin wants MIDI input.@n
  113. This is automatically enabled if @ref DISTRHO_PLUGIN_IS_SYNTH is true.
  114. */
  115. #define DISTRHO_PLUGIN_WANT_MIDI_INPUT 1
  116. /**
  117. Wherever the plugin wants MIDI output.
  118. @see Plugin::d_writeMidiEvent(const MidiEvent&)
  119. */
  120. #define DISTRHO_PLUGIN_WANT_MIDI_OUTPUT 1
  121. /**
  122. Wherever the plugin provides its own internal programs.
  123. @see Plugin::d_initProgramName(uint32_t, d_string&)
  124. @see Plugin::d_setProgram(uint32_t)
  125. */
  126. #define DISTRHO_PLUGIN_WANT_PROGRAMS 1
  127. /**
  128. Wherever the plugin uses internal non-parameter data.
  129. @see Plugin::d_initState(uint32_t, d_string&, d_string&)
  130. @see Plugin::d_setState(const char*, const char*)
  131. */
  132. #define DISTRHO_PLUGIN_WANT_STATE 1
  133. /**
  134. Wherever the plugin wants time position information from the host.
  135. @see Plugin::d_getTimePosition()
  136. */
  137. #define DISTRHO_PLUGIN_WANT_TIMEPOS 1
  138. /**
  139. Wherever the %UI uses NanoVG for drawing instead of the default raw OpenGL calls.@n
  140. When enabled your %UI instance will subclass @ref NanoWidget instead of @ref Widget.
  141. */
  142. #define DISTRHO_UI_USE_NANOVG 1
  143. /**
  144. The %UI URI when exporting in LV2 format.@n
  145. By default this is set to @ref DISTRHO_PLUGIN_URI with "#UI" as suffix.
  146. */
  147. #define DISTRHO_UI_URI DISTRHO_PLUGIN_URI "#UI"
  148. /** @} */
  149. #endif
  150. /* ------------------------------------------------------------------------------------------------------------
  151. * Audio Port Hints */
  152. /**
  153. @defgroup AudioPortHints Audio Port Hints
  154. Various audio port hints.
  155. @see AudioPort::hints
  156. @{
  157. */
  158. /**
  159. Audio port can be used as control voltage (LV2 only).
  160. */
  161. static const uint32_t kAudioPortIsCV = 0x1;
  162. /**
  163. Audio port should be used as sidechan (LV2 only).
  164. */
  165. static const uint32_t kAudioPortIsSidechain = 0x2;
  166. /** @} */
  167. /* ------------------------------------------------------------------------------------------------------------
  168. * Parameter Hints */
  169. /**
  170. @defgroup ParameterHints Parameter Hints
  171. Various parameter hints.
  172. @see Parameter::hints
  173. @{
  174. */
  175. /**
  176. Parameter is automable (real-time safe).
  177. @see Plugin::d_setParameterValue()
  178. */
  179. static const uint32_t kParameterIsAutomable = 0x01;
  180. /**
  181. Parameter value is boolean.
  182. It's always at either minimum or maximum value.
  183. */
  184. static const uint32_t kParameterIsBoolean = 0x02;
  185. /**
  186. Parameter value is integer.
  187. */
  188. static const uint32_t kParameterIsInteger = 0x04;
  189. /**
  190. Parameter value is logarithmic.
  191. */
  192. static const uint32_t kParameterIsLogarithmic = 0x08;
  193. /**
  194. Parameter is of output type.
  195. When unset, parameter is assumed to be of input type.
  196. Parameter inputs are changed by the host and must not be changed by the plugin.
  197. The only exception being when changing programs, see Plugin::d_setProgram().
  198. Outputs are changed by the plugin and never modified by the host.
  199. */
  200. static const uint32_t kParameterIsOutput = 0x10;
  201. /**
  202. Parameter can be used as control voltage (LV2 only).
  203. */
  204. static const uint32_t kParameterIsCV = 0x20;
  205. /** @} */
  206. /* ------------------------------------------------------------------------------------------------------------
  207. * DPF Base structs */
  208. /**
  209. @defgroup BaseStructs Base Structs
  210. @{
  211. */
  212. /**
  213. Audio Port.
  214. */
  215. struct AudioPort {
  216. /**
  217. Hints describing this audio port.
  218. @see AudioPortHints
  219. */
  220. uint32_t hints;
  221. /**
  222. The name of this audio port.
  223. An audio port name can contain any character, but hosts might have a hard time with non-ascii ones.
  224. The name doesn't have to be unique within a plugin instance, but it's recommended.
  225. */
  226. d_string name;
  227. /**
  228. The symbol of this audio port.
  229. An audio port symbol is a short restricted name used as a machine and human readable identifier.
  230. The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9.
  231. @note: Audio port and parameter symbols MUST be unique within a plugin instance.
  232. */
  233. d_string symbol;
  234. /**
  235. Default constructor for a regular audio port.
  236. */
  237. AudioPort() noexcept
  238. : hints(0x0),
  239. name(),
  240. symbol() {}
  241. };
  242. /**
  243. Parameter ranges.
  244. This is used to set the default, minimum and maximum values of a parameter.
  245. By default a parameter has 0.0 as minimum, 1.0 as maximum and 0.0 as default.
  246. When changing this struct values you must ensure maximum > minimum and default is within range.
  247. */
  248. struct ParameterRanges {
  249. /**
  250. Default value.
  251. */
  252. float def;
  253. /**
  254. Minimum value.
  255. */
  256. float min;
  257. /**
  258. Maximum value.
  259. */
  260. float max;
  261. /**
  262. Default constructor, using 0.0 as minimum, 1.0 as maximum and 0.0 as default.
  263. */
  264. ParameterRanges() noexcept
  265. : def(0.0f),
  266. min(0.0f),
  267. max(1.0f) {}
  268. /**
  269. Constructor using custom values.
  270. */
  271. ParameterRanges(const float df, const float mn, const float mx) noexcept
  272. : def(df),
  273. min(mn),
  274. max(mx) {}
  275. /**
  276. Fix the default value within range.
  277. */
  278. void fixDefault() noexcept
  279. {
  280. fixValue(def);
  281. }
  282. /**
  283. Fix a value within range.
  284. */
  285. void fixValue(float& value) const noexcept
  286. {
  287. if (value < min)
  288. value = min;
  289. else if (value > max)
  290. value = max;
  291. }
  292. /**
  293. Get a fixed value within range.
  294. */
  295. const float& getFixedValue(const float& value) const noexcept
  296. {
  297. if (value <= min)
  298. return min;
  299. if (value >= max)
  300. return max;
  301. return value;
  302. }
  303. /**
  304. Get a value normalized to 0.0<->1.0.
  305. */
  306. float getNormalizedValue(const float& value) const noexcept
  307. {
  308. const float normValue((value - min) / (max - min));
  309. if (normValue <= 0.0f)
  310. return 0.0f;
  311. if (normValue >= 1.0f)
  312. return 1.0f;
  313. return normValue;
  314. }
  315. /**
  316. Get a value normalized to 0.0<->1.0, fixed within range.
  317. */
  318. float getFixedAndNormalizedValue(const float& value) const noexcept
  319. {
  320. if (value <= min)
  321. return 0.0f;
  322. if (value >= max)
  323. return 1.0f;
  324. const float normValue((value - min) / (max - min));
  325. if (normValue <= 0.0f)
  326. return 0.0f;
  327. if (normValue >= 1.0f)
  328. return 1.0f;
  329. return normValue;
  330. }
  331. /**
  332. Get a proper value previously normalized to 0.0<->1.0.
  333. */
  334. float getUnnormalizedValue(const float& value) const noexcept
  335. {
  336. if (value <= 0.0f)
  337. return min;
  338. if (value >= 1.0f)
  339. return max;
  340. return value * (max - min) + min;
  341. }
  342. };
  343. /**
  344. Parameter.
  345. */
  346. struct Parameter {
  347. /**
  348. Hints describing this parameter.
  349. @see ParameterHints
  350. */
  351. uint32_t hints;
  352. /**
  353. The name of this parameter.
  354. A parameter name can contain any character, but hosts might have a hard time with non-ascii ones.
  355. The name doesn't have to be unique within a plugin instance, but it's recommended.
  356. */
  357. d_string name;
  358. /**
  359. The symbol of this parameter.
  360. A parameter symbol is a short restricted name used as a machine and human readable identifier.
  361. The first character must be one of _, a-z or A-Z and subsequent characters can be from _, a-z, A-Z and 0-9.
  362. @note: Parameter symbols MUST be unique within a plugin instance.
  363. */
  364. d_string symbol;
  365. /**
  366. The unit of this parameter.
  367. This means something like "dB", "kHz" and "ms".
  368. Can be left blank if a unit does not apply to this parameter.
  369. */
  370. d_string unit;
  371. /**
  372. Ranges of this parameter.
  373. The ranges describe the default, minimum and maximum values.
  374. */
  375. ParameterRanges ranges;
  376. /**
  377. Default constructor for a null parameter.
  378. */
  379. Parameter() noexcept
  380. : hints(0x0),
  381. name(),
  382. symbol(),
  383. unit(),
  384. ranges() {}
  385. };
  386. /**
  387. MIDI event.
  388. */
  389. struct MidiEvent {
  390. /**
  391. Size of internal data.
  392. */
  393. static const uint32_t kDataSize = 4;
  394. /**
  395. Time offset in frames.
  396. */
  397. uint32_t frame;
  398. /**
  399. Number of bytes used.
  400. */
  401. uint32_t size;
  402. /**
  403. MIDI data.
  404. If size > kDataSize, dataExt is used (otherwise null).
  405. */
  406. uint8_t data[kDataSize];
  407. const uint8_t* dataExt;
  408. };
  409. /**
  410. Time position.
  411. The @a playing and @a frame values are always valid.
  412. BBT values are only valid when @a bbt.valid is true.
  413. This struct is inspired by the JACK Transport API.
  414. */
  415. struct TimePosition {
  416. /**
  417. Wherever the host transport is playing/rolling.
  418. */
  419. bool playing;
  420. /**
  421. Current host transport position in frames.
  422. */
  423. uint64_t frame;
  424. /**
  425. Bar-Beat-Tick time position.
  426. */
  427. struct BarBeatTick {
  428. /**
  429. Wherever the host transport is using BBT.
  430. If false you must not read from this struct.
  431. */
  432. bool valid;
  433. /**
  434. Current bar.
  435. Should always be > 0.
  436. The first bar is bar '1'.
  437. */
  438. int32_t bar;
  439. /**
  440. Current beat within bar.
  441. Should always be > 0 and <= @a beatsPerBar.
  442. The first beat is beat '1'.
  443. */
  444. int32_t beat;
  445. /**
  446. Current tick within beat.
  447. Should always be > 0 and <= @a ticksPerBeat.
  448. The first tick is tick '0'.
  449. */
  450. int32_t tick;
  451. /**
  452. Number of ticks that have elapsed between frame 0 and the first beat of the current measure.
  453. */
  454. double barStartTick;
  455. /**
  456. Time signature "numerator".
  457. */
  458. float beatsPerBar;
  459. /**
  460. Time signature "denominator".
  461. */
  462. float beatType;
  463. /**
  464. Number of ticks within a bar.
  465. Usually a moderately large integer with many denominators, such as 1920.0.
  466. */
  467. double ticksPerBeat;
  468. /**
  469. Number of beats per minute.
  470. */
  471. double beatsPerMinute;
  472. /**
  473. Default constructor for a null BBT time position.
  474. */
  475. BarBeatTick() noexcept
  476. : valid(false),
  477. bar(0),
  478. beat(0),
  479. tick(0),
  480. barStartTick(0.0),
  481. beatsPerBar(0.0f),
  482. beatType(0.0f),
  483. ticksPerBeat(0.0),
  484. beatsPerMinute(0.0) {}
  485. } bbt;
  486. /**
  487. Default constructor for a time position.
  488. */
  489. TimePosition() noexcept
  490. : playing(false),
  491. frame(0),
  492. bbt() {}
  493. };
  494. /** @} */
  495. /* ------------------------------------------------------------------------------------------------------------
  496. * DPF Plugin */
  497. /**
  498. DPF Plugin class from where plugin instances are created.
  499. The public methods (Host state) are called from the plugin to get or set host information.
  500. They can be called from a plugin instance at anytime unless stated otherwise.
  501. All other methods are to be implemented by the plugin and will be called by the host.
  502. Shortly after a plugin instance is created, the various d_init* functions will be called by the host.
  503. Host will call d_activate() before d_run(), and d_deactivate() before the plugin instance is destroyed.
  504. The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.
  505. There is no limit on how many times d_run() is called, only that activate/deactivate will be called in between.
  506. The buffer size and sample rate values will remain constant between activate and deactivate.
  507. Buffer size is only a hint though, the host might call d_run() with a higher or lower number of frames.
  508. Some of this class functions are only available according to some macros.
  509. DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.
  510. When enabled you need to implement d_initProgramName() and d_setProgram().
  511. DISTRHO_PLUGIN_WANT_STATE activates internal state features.
  512. When enabled you need to implement d_initStateKey() and d_setState().
  513. The process function d_run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.
  514. When enabled it provides midi input events.
  515. */
  516. class Plugin
  517. {
  518. public:
  519. /**
  520. Plugin class constructor.
  521. You must set all parameter values to their defaults, matching ParameterRanges::def.
  522. */
  523. Plugin(const uint32_t parameterCount, const uint32_t programCount, const uint32_t stateCount);
  524. /**
  525. Destructor.
  526. */
  527. virtual ~Plugin();
  528. /* --------------------------------------------------------------------------------------------------------
  529. * Host state */
  530. /**
  531. Get the current buffer size that will probably be used during processing, in frames.
  532. This value will remain constant between activate and deactivate.
  533. @note: This value is only a hint!
  534. Hosts might call d_run() with a higher or lower number of frames.
  535. @see d_bufferSizeChanged(uint32_t)
  536. */
  537. uint32_t d_getBufferSize() const noexcept;
  538. /**
  539. Get the current sample rate that will be used during processing.
  540. This value will remain constant between activate and deactivate.
  541. @see d_sampleRateChanged(double)
  542. */
  543. double d_getSampleRate() const noexcept;
  544. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  545. /**
  546. Get the current host transport time position.
  547. This function should only be called during d_run().
  548. You can call this during other times, but the returned position is not guaranteed to be in sync.
  549. @note: TimePosition is not supported in LADSPA and DSSI plugin formats.
  550. */
  551. const TimePosition& d_getTimePosition() const noexcept;
  552. #endif
  553. #if DISTRHO_PLUGIN_WANT_LATENCY
  554. /**
  555. Change the plugin audio output latency to @a frames.
  556. This function should only be called in the constructor, d_activate() and d_run().
  557. @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
  558. */
  559. void d_setLatency(uint32_t frames) noexcept;
  560. #endif
  561. #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  562. /**
  563. Write a MIDI output event.
  564. This function must only be called during d_run().
  565. Returns false when the host buffer is full, in which case do not call this again until the next d_run().
  566. */
  567. bool d_writeMidiEvent(const MidiEvent& midiEvent) noexcept;
  568. #endif
  569. protected:
  570. /* --------------------------------------------------------------------------------------------------------
  571. * Information */
  572. /**
  573. Get the plugin name.
  574. Returns DISTRHO_PLUGIN_NAME by default.
  575. */
  576. virtual const char* d_getName() const { return DISTRHO_PLUGIN_NAME; }
  577. /**
  578. Get the plugin label.
  579. A plugin label follows the same rules as Parameter::symbol, with the exception that it can start with numbers.
  580. */
  581. virtual const char* d_getLabel() const = 0;
  582. /**
  583. Get the plugin author/maker.
  584. */
  585. virtual const char* d_getMaker() const = 0;
  586. /**
  587. Get the plugin license name (a single line of text).@n
  588. For commercial plugins this should return some copyright information.
  589. */
  590. virtual const char* d_getLicense() const = 0;
  591. /**
  592. Get the plugin version, in hexadecimal.
  593. TODO format to be defined
  594. */
  595. virtual uint32_t d_getVersion() const = 0;
  596. /**
  597. Get the plugin unique Id.
  598. This value is used by LADSPA, DSSI and VST plugin formats.
  599. */
  600. virtual int64_t d_getUniqueId() const = 0;
  601. /* --------------------------------------------------------------------------------------------------------
  602. * Init */
  603. /**
  604. Initialize the audio port @a index.
  605. This function will be called once, shortly after the plugin is created.
  606. */
  607. virtual void d_initAudioPort(bool input, uint32_t index, AudioPort& port);
  608. /**
  609. Initialize the parameter @a index.
  610. This function will be called once, shortly after the plugin is created.
  611. */
  612. virtual void d_initParameter(uint32_t index, Parameter& parameter) = 0;
  613. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  614. /**
  615. Set the name of the program @a index.
  616. This function will be called once, shortly after the plugin is created.
  617. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  618. */
  619. virtual void d_initProgramName(uint32_t index, d_string& programName) = 0;
  620. #endif
  621. #if DISTRHO_PLUGIN_WANT_STATE
  622. /**
  623. Set the state key and default value of @a index.
  624. This function will be called once, shortly after the plugin is created.
  625. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  626. */
  627. virtual void d_initState(uint32_t index, d_string& stateKey, d_string& defaultStateValue) = 0;
  628. #endif
  629. /* --------------------------------------------------------------------------------------------------------
  630. * Internal data */
  631. /**
  632. Get the current value of a parameter.
  633. The host may call this function from any context, including realtime processing.
  634. */
  635. virtual float d_getParameterValue(uint32_t index) const = 0;
  636. /**
  637. Change a parameter value.
  638. The host may call this function from any context, including realtime processing.
  639. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  640. @note This function will only be called for parameter inputs.
  641. */
  642. virtual void d_setParameterValue(uint32_t index, float value) = 0;
  643. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  644. /**
  645. Change the currently used program to @a index.
  646. The host may call this function from any context, including realtime processing.
  647. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  648. */
  649. virtual void d_setProgram(uint32_t index) = 0;
  650. #endif
  651. #if DISTRHO_PLUGIN_WANT_STATE
  652. /**
  653. Change an internal state @a key to @a value.
  654. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  655. */
  656. virtual void d_setState(const char* key, const char* value) = 0;
  657. #endif
  658. /* --------------------------------------------------------------------------------------------------------
  659. * Process */
  660. /**
  661. Activate this plugin.
  662. */
  663. virtual void d_activate() {}
  664. /**
  665. Deactivate this plugin.
  666. */
  667. virtual void d_deactivate() {}
  668. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  669. /**
  670. Run/process function for plugins with MIDI input.
  671. @note: Some parameters might be null if there are no audio inputs/outputs or MIDI events.
  672. */
  673. virtual void d_run(const float** inputs, float** outputs, uint32_t frames,
  674. const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  675. #else
  676. /**
  677. Run/process function for plugins without MIDI input.
  678. @note: Some parameters might be null if there are no audio inputs or outputs.
  679. */
  680. virtual void d_run(const float** inputs, float** outputs, uint32_t frames) = 0;
  681. #endif
  682. /* --------------------------------------------------------------------------------------------------------
  683. * Callbacks (optional) */
  684. /**
  685. Optional callback to inform the plugin about a buffer size change.
  686. This function will only be called when the plugin is deactivated.
  687. @note: This value is only a hint!
  688. Hosts might call d_run() with a higher or lower number of frames.
  689. @see d_getBufferSize()
  690. */
  691. virtual void d_bufferSizeChanged(uint32_t newBufferSize);
  692. /**
  693. Optional callback to inform the plugin about a sample rate change.
  694. This function will only be called when the plugin is deactivated.
  695. @see d_getSampleRate()
  696. */
  697. virtual void d_sampleRateChanged(double newSampleRate);
  698. // -------------------------------------------------------------------------------------------------------
  699. private:
  700. struct PrivateData;
  701. PrivateData* const pData;
  702. friend class PluginExporter;
  703. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
  704. };
  705. /* ------------------------------------------------------------------------------------------------------------
  706. * Create plugin, entry point */
  707. /**
  708. TODO.
  709. */
  710. extern Plugin* createPlugin();
  711. // -----------------------------------------------------------------------------------------------------------
  712. END_NAMESPACE_DISTRHO
  713. #endif // DISTRHO_PLUGIN_HPP_INCLUDED