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.

906 lines
25KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2018 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/String.hpp"
  19. #include "extra/LeakDetector.hpp"
  20. #include "src/DistrhoPluginChecks.h"
  21. START_NAMESPACE_DISTRHO
  22. /* ------------------------------------------------------------------------------------------------------------
  23. * Audio Port Hints */
  24. /**
  25. @defgroup AudioPortHints Audio Port Hints
  26. Various audio port hints.
  27. @see AudioPort::hints
  28. @{
  29. */
  30. /**
  31. Audio port can be used as control voltage (LV2 only).
  32. */
  33. static const uint32_t kAudioPortIsCV = 0x1;
  34. /**
  35. Audio port should be used as sidechan (LV2 only).
  36. */
  37. static const uint32_t kAudioPortIsSidechain = 0x2;
  38. /** @} */
  39. /* ------------------------------------------------------------------------------------------------------------
  40. * Parameter Hints */
  41. /**
  42. @defgroup ParameterHints Parameter Hints
  43. Various parameter hints.
  44. @see Parameter::hints
  45. @{
  46. */
  47. /**
  48. Parameter is automable (real-time safe).
  49. @see Plugin::setParameterValue(uint32_t, float)
  50. */
  51. static const uint32_t kParameterIsAutomable = 0x01;
  52. /**
  53. Parameter value is boolean.@n
  54. It's always at either minimum or maximum value.
  55. */
  56. static const uint32_t kParameterIsBoolean = 0x02;
  57. /**
  58. Parameter value is integer.
  59. */
  60. static const uint32_t kParameterIsInteger = 0x04;
  61. /**
  62. Parameter value is logarithmic.
  63. */
  64. static const uint32_t kParameterIsLogarithmic = 0x08;
  65. /**
  66. Parameter is of output type.@n
  67. When unset, parameter is assumed to be of input type.
  68. Parameter inputs are changed by the host and must not be changed by the plugin.@n
  69. The only exception being when changing programs, see Plugin::loadProgram().@n
  70. Outputs are changed by the plugin and never modified by the host.
  71. */
  72. static const uint32_t kParameterIsOutput = 0x10;
  73. /**
  74. Parameter value is a trigger.
  75. @note Cannot be used for output parameters
  76. */
  77. static const uint32_t kParameterIsTrigger = 0x20 | kParameterIsBoolean;
  78. /** @} */
  79. /* ------------------------------------------------------------------------------------------------------------
  80. * Base Plugin structs */
  81. /**
  82. @defgroup BasePluginStructs Base Plugin Structs
  83. @{
  84. */
  85. /**
  86. Audio Port.
  87. */
  88. struct AudioPort {
  89. /**
  90. Hints describing this audio port.
  91. @see AudioPortHints
  92. */
  93. uint32_t hints;
  94. /**
  95. The name of this audio port.@n
  96. An audio port name can contain any character, but hosts might have a hard time with non-ascii ones.@n
  97. The name doesn't have to be unique within a plugin instance, but it's recommended.
  98. */
  99. String name;
  100. /**
  101. The symbol of this audio port.@n
  102. An audio port symbol is a short restricted name used as a machine and human readable identifier.@n
  103. 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.
  104. @note Audio port and parameter symbols MUST be unique within a plugin instance.
  105. */
  106. String symbol;
  107. /**
  108. Default constructor for a regular audio port.
  109. */
  110. AudioPort() noexcept
  111. : hints(0x0),
  112. name(),
  113. symbol() {}
  114. };
  115. /**
  116. Parameter designation.@n
  117. Allows a parameter to be specially designated for a task, like bypass.
  118. Each designation is unique, there must be only one parameter that uses it.@n
  119. The use of designated parameters is completely optional.
  120. @note Designated parameters have strict ranges.
  121. @see ParameterRanges::adjustForDesignation()
  122. */
  123. enum ParameterDesignation {
  124. /**
  125. Null or unset designation.
  126. */
  127. kParameterDesignationNull = 0,
  128. /**
  129. Bypass designation.@n
  130. When on (> 0.5f), it means the plugin must run in a bypassed state.
  131. */
  132. kParameterDesignationBypass = 1
  133. };
  134. /**
  135. Parameter ranges.@n
  136. This is used to set the default, minimum and maximum values of a parameter.
  137. By default a parameter has 0.0 as minimum, 1.0 as maximum and 0.0 as default.@n
  138. When changing this struct values you must ensure maximum > minimum and default is within range.
  139. */
  140. struct ParameterRanges {
  141. /**
  142. Default value.
  143. */
  144. float def;
  145. /**
  146. Minimum value.
  147. */
  148. float min;
  149. /**
  150. Maximum value.
  151. */
  152. float max;
  153. /**
  154. Default constructor, using 0.0 as minimum, 1.0 as maximum and 0.0 as default.
  155. */
  156. ParameterRanges() noexcept
  157. : def(0.0f),
  158. min(0.0f),
  159. max(1.0f) {}
  160. /**
  161. Constructor using custom values.
  162. */
  163. ParameterRanges(float df, float mn, float mx) noexcept
  164. : def(df),
  165. min(mn),
  166. max(mx) {}
  167. /**
  168. Fix the default value within range.
  169. */
  170. void fixDefault() noexcept
  171. {
  172. fixValue(def);
  173. }
  174. /**
  175. Fix a value within range.
  176. */
  177. void fixValue(float& value) const noexcept
  178. {
  179. if (value < min)
  180. value = min;
  181. else if (value > max)
  182. value = max;
  183. }
  184. /**
  185. Get a fixed value within range.
  186. */
  187. const float& getFixedValue(const float& value) const noexcept
  188. {
  189. if (value <= min)
  190. return min;
  191. if (value >= max)
  192. return max;
  193. return value;
  194. }
  195. /**
  196. Get a value normalized to 0.0<->1.0.
  197. */
  198. float getNormalizedValue(const float& value) const noexcept
  199. {
  200. const float normValue((value - min) / (max - min));
  201. if (normValue <= 0.0f)
  202. return 0.0f;
  203. if (normValue >= 1.0f)
  204. return 1.0f;
  205. return normValue;
  206. }
  207. /**
  208. Get a value normalized to 0.0<->1.0, fixed within range.
  209. */
  210. float getFixedAndNormalizedValue(const float& value) const noexcept
  211. {
  212. if (value <= min)
  213. return 0.0f;
  214. if (value >= max)
  215. return 1.0f;
  216. const float normValue((value - min) / (max - min));
  217. if (normValue <= 0.0f)
  218. return 0.0f;
  219. if (normValue >= 1.0f)
  220. return 1.0f;
  221. return normValue;
  222. }
  223. /**
  224. Get a proper value previously normalized to 0.0<->1.0.
  225. */
  226. float getUnnormalizedValue(const float& value) const noexcept
  227. {
  228. if (value <= 0.0f)
  229. return min;
  230. if (value >= 1.0f)
  231. return max;
  232. return value * (max - min) + min;
  233. }
  234. };
  235. /**
  236. Parameter enumeration value.@n
  237. A string representation of a plugin parameter value.@n
  238. Used together can be used to give meaning to parameter values, working as an enumeration.
  239. */
  240. struct ParameterEnumerationValue {
  241. /**
  242. Parameter value.
  243. */
  244. float value;
  245. /**
  246. String representation of this value.
  247. */
  248. String label;
  249. /**
  250. Default constructor, using 0.0 as value and empty label.
  251. */
  252. ParameterEnumerationValue() noexcept
  253. : value(0.0f),
  254. label() {}
  255. /**
  256. Constructor using custom values.
  257. */
  258. ParameterEnumerationValue(float v, const char* l) noexcept
  259. : value(v),
  260. label(l) {}
  261. };
  262. /**
  263. Collection of parameter enumeration values.@n
  264. Handy class to handle the lifetime and count of all enumeration values.
  265. */
  266. struct ParameterEnumerationValues {
  267. /**
  268. Number of elements allocated in @values.
  269. */
  270. uint8_t count;
  271. /**
  272. Wherever the host is to be restricted to only use enumeration values.
  273. @note This mode is only a hint! Not all hosts and plugin formats support this mode.
  274. */
  275. bool restrictedMode;
  276. /**
  277. Array of @ParameterEnumerationValue items.@n
  278. This pointer must be null or have been allocated on the heap with `new`.
  279. */
  280. const ParameterEnumerationValue* values;
  281. /**
  282. Default constructor, for zero enumeration values.
  283. */
  284. ParameterEnumerationValues() noexcept
  285. : count(0),
  286. restrictedMode(false),
  287. values() {}
  288. /**
  289. Constructor using custom values.@n
  290. The pointer to @values must have been allocated on the heap with `new`.
  291. */
  292. ParameterEnumerationValues(uint32_t c, bool r, const ParameterEnumerationValue* v) noexcept
  293. : count(c),
  294. restrictedMode(r),
  295. values(v) {}
  296. ~ParameterEnumerationValues() noexcept
  297. {
  298. count = 0;
  299. restrictedMode = false;
  300. if (values != nullptr)
  301. {
  302. delete[] values;
  303. values = nullptr;
  304. }
  305. }
  306. };
  307. /**
  308. Parameter.
  309. */
  310. struct Parameter {
  311. /**
  312. Hints describing this parameter.
  313. @see ParameterHints
  314. */
  315. uint32_t hints;
  316. /**
  317. The name of this parameter.@n
  318. A parameter name can contain any character, but hosts might have a hard time with non-ascii ones.@n
  319. The name doesn't have to be unique within a plugin instance, but it's recommended.
  320. */
  321. String name;
  322. /**
  323. The symbol of this parameter.@n
  324. A parameter symbol is a short restricted name used as a machine and human readable identifier.@n
  325. 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.
  326. @note Parameter symbols MUST be unique within a plugin instance.
  327. */
  328. String symbol;
  329. /**
  330. The unit of this parameter.@n
  331. This means something like "dB", "kHz" and "ms".@n
  332. Can be left blank if a unit does not apply to this parameter.
  333. */
  334. String unit;
  335. /**
  336. Ranges of this parameter.@n
  337. The ranges describe the default, minimum and maximum values.
  338. */
  339. ParameterRanges ranges;
  340. /**
  341. Enumeration values.@n
  342. Can be used to give meaning to parameter values, working as an enumeration.
  343. */
  344. ParameterEnumerationValues enumValues;
  345. /**
  346. Designation for this parameter.
  347. */
  348. ParameterDesignation designation;
  349. /**
  350. MIDI CC to use by default on this parameter.@n
  351. A value of 0 or 32 (bank change) is considered invalid.@n
  352. Must also be less or equal to 120.
  353. @note This value is only a hint! Hosts might map it automatically or completely ignore it.
  354. */
  355. uint8_t midiCC;
  356. /**
  357. Default constructor for a null parameter.
  358. */
  359. Parameter() noexcept
  360. : hints(0x0),
  361. name(),
  362. symbol(),
  363. unit(),
  364. ranges(),
  365. enumValues(),
  366. designation(kParameterDesignationNull),
  367. midiCC(0) {}
  368. /**
  369. Constructor using custom values.
  370. */
  371. Parameter(uint32_t h, const char* n, const char* s, const char* u, float def, float min, float max) noexcept
  372. : hints(h),
  373. name(n),
  374. symbol(s),
  375. unit(u),
  376. ranges(def, min, max),
  377. enumValues(),
  378. designation(kParameterDesignationNull),
  379. midiCC(0) {}
  380. /**
  381. Initialize a parameter for a specific designation.
  382. */
  383. void initDesignation(ParameterDesignation d) noexcept
  384. {
  385. designation = d;
  386. switch (d)
  387. {
  388. case kParameterDesignationNull:
  389. break;
  390. case kParameterDesignationBypass:
  391. hints = kParameterIsAutomable|kParameterIsBoolean|kParameterIsInteger;
  392. name = "Bypass";
  393. symbol = "dpf_bypass";
  394. unit = "";
  395. midiCC = 0;
  396. ranges.def = 0.0f;
  397. ranges.min = 0.0f;
  398. ranges.max = 1.0f;
  399. break;
  400. }
  401. }
  402. };
  403. /**
  404. MIDI event.
  405. */
  406. struct MidiEvent {
  407. /**
  408. Size of internal data.
  409. */
  410. static const uint32_t kDataSize = 4;
  411. /**
  412. Time offset in frames.
  413. */
  414. uint32_t frame;
  415. /**
  416. Number of bytes used.
  417. */
  418. uint32_t size;
  419. /**
  420. MIDI data.@n
  421. If size > kDataSize, dataExt is used (otherwise null).
  422. */
  423. uint8_t data[kDataSize];
  424. const uint8_t* dataExt;
  425. };
  426. /**
  427. Time position.@n
  428. The @a playing and @a frame values are always valid.@n
  429. BBT values are only valid when @a bbt.valid is true.
  430. This struct is inspired by the JACK Transport API.
  431. */
  432. struct TimePosition {
  433. /**
  434. Wherever the host transport is playing/rolling.
  435. */
  436. bool playing;
  437. /**
  438. Current host transport position in frames.
  439. */
  440. uint64_t frame;
  441. /**
  442. Bar-Beat-Tick time position.
  443. */
  444. struct BarBeatTick {
  445. /**
  446. Wherever the host transport is using BBT.@n
  447. If false you must not read from this struct.
  448. */
  449. bool valid;
  450. /**
  451. Current bar.@n
  452. Should always be > 0.@n
  453. The first bar is bar '1'.
  454. */
  455. int32_t bar;
  456. /**
  457. Current beat within bar.@n
  458. Should always be > 0 and <= @a beatsPerBar.@n
  459. The first beat is beat '1'.
  460. */
  461. int32_t beat;
  462. /**
  463. Current tick within beat.@n
  464. Should always be > 0 and <= @a ticksPerBeat.@n
  465. The first tick is tick '0'.
  466. */
  467. int32_t tick;
  468. /**
  469. Number of ticks that have elapsed between frame 0 and the first beat of the current measure.
  470. */
  471. double barStartTick;
  472. /**
  473. Time signature "numerator".
  474. */
  475. float beatsPerBar;
  476. /**
  477. Time signature "denominator".
  478. */
  479. float beatType;
  480. /**
  481. Number of ticks within a bar.@n
  482. Usually a moderately large integer with many denominators, such as 1920.0.
  483. */
  484. double ticksPerBeat;
  485. /**
  486. Number of beats per minute.
  487. */
  488. double beatsPerMinute;
  489. /**
  490. Default constructor for a null BBT time position.
  491. */
  492. BarBeatTick() noexcept
  493. : valid(false),
  494. bar(0),
  495. beat(0),
  496. tick(0),
  497. barStartTick(0.0),
  498. beatsPerBar(0.0f),
  499. beatType(0.0f),
  500. ticksPerBeat(0.0),
  501. beatsPerMinute(0.0) {}
  502. } bbt;
  503. /**
  504. Default constructor for a time position.
  505. */
  506. TimePosition() noexcept
  507. : playing(false),
  508. frame(0),
  509. bbt() {}
  510. };
  511. /** @} */
  512. /* ------------------------------------------------------------------------------------------------------------
  513. * DPF Plugin */
  514. /**
  515. @defgroup MainClasses Main Classes
  516. @{
  517. */
  518. /**
  519. DPF Plugin class from where plugin instances are created.
  520. The public methods (Host state) are called from the plugin to get or set host information.@n
  521. They can be called from a plugin instance at anytime unless stated otherwise.@n
  522. All other methods are to be implemented by the plugin and will be called by the host.
  523. Shortly after a plugin instance is created, the various init* functions will be called by the host.@n
  524. Host will call activate() before run(), and deactivate() before the plugin instance is destroyed.@n
  525. The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.@n
  526. There is no limit on how many times run() is called, only that activate/deactivate will be called in between.
  527. The buffer size and sample rate values will remain constant between activate and deactivate.@n
  528. Buffer size is only a hint though, the host might call run() with a higher or lower number of frames.
  529. Some of this class functions are only available according to some macros.
  530. DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.@n
  531. When enabled you need to implement initProgramName() and loadProgram().
  532. DISTRHO_PLUGIN_WANT_STATE activates internal state features.@n
  533. When enabled you need to implement initStateKey() and setState().
  534. The process function run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.@n
  535. When enabled it provides midi input events.
  536. */
  537. class Plugin
  538. {
  539. public:
  540. /**
  541. Plugin class constructor.@n
  542. You must set all parameter values to their defaults, matching ParameterRanges::def.
  543. */
  544. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  545. /**
  546. Destructor.
  547. */
  548. virtual ~Plugin();
  549. /* --------------------------------------------------------------------------------------------------------
  550. * Host state */
  551. /**
  552. Get the current buffer size that will probably be used during processing, in frames.@n
  553. This value will remain constant between activate and deactivate.
  554. @note This value is only a hint!@n
  555. Hosts might call run() with a higher or lower number of frames.
  556. @see bufferSizeChanged(uint32_t)
  557. */
  558. uint32_t getBufferSize() const noexcept;
  559. /**
  560. Get the current sample rate that will be used during processing.@n
  561. This value will remain constant between activate and deactivate.
  562. @see sampleRateChanged(double)
  563. */
  564. double getSampleRate() const noexcept;
  565. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  566. /**
  567. Get the current host transport time position.@n
  568. This function should only be called during run().@n
  569. You can call this during other times, but the returned position is not guaranteed to be in sync.
  570. @note TimePosition is not supported in LADSPA and DSSI plugin formats.
  571. */
  572. const TimePosition& getTimePosition() const noexcept;
  573. #endif
  574. #if DISTRHO_PLUGIN_WANT_LATENCY
  575. /**
  576. Change the plugin audio output latency to @a frames.@n
  577. This function should only be called in the constructor, activate() and run().
  578. @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
  579. */
  580. void setLatency(uint32_t frames) noexcept;
  581. #endif
  582. #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  583. /**
  584. Write a MIDI output event.@n
  585. This function must only be called during run().@n
  586. Returns false when the host buffer is full, in which case do not call this again until the next run().
  587. */
  588. bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
  589. #endif
  590. protected:
  591. /* --------------------------------------------------------------------------------------------------------
  592. * Information */
  593. /**
  594. Get the plugin name.@n
  595. Returns DISTRHO_PLUGIN_NAME by default.
  596. */
  597. virtual const char* getName() const { return DISTRHO_PLUGIN_NAME; }
  598. /**
  599. Get the plugin label.@n
  600. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  601. */
  602. virtual const char* getLabel() const = 0;
  603. /**
  604. Get an extensive comment/description about the plugin.@n
  605. Optional, returns nothing by default.
  606. */
  607. virtual const char* getDescription() const { return ""; }
  608. /**
  609. Get the plugin author/maker.
  610. */
  611. virtual const char* getMaker() const = 0;
  612. /**
  613. Get the plugin homepage.@n
  614. Optional, returns nothing by default.
  615. */
  616. virtual const char* getHomePage() const { return ""; }
  617. /**
  618. Get the plugin license (a single line of text or a URL).@n
  619. For commercial plugins this should return some short copyright information.
  620. */
  621. virtual const char* getLicense() const = 0;
  622. /**
  623. Get the plugin version, in hexadecimal.
  624. @see d_version()
  625. */
  626. virtual uint32_t getVersion() const = 0;
  627. /**
  628. Get the plugin unique Id.@n
  629. This value is used by LADSPA, DSSI and VST plugin formats.
  630. @see d_cconst()
  631. */
  632. virtual int64_t getUniqueId() const = 0;
  633. /* --------------------------------------------------------------------------------------------------------
  634. * Init */
  635. /**
  636. Initialize the audio port @a index.@n
  637. This function will be called once, shortly after the plugin is created.
  638. */
  639. virtual void initAudioPort(bool input, uint32_t index, AudioPort& port);
  640. /**
  641. Initialize the parameter @a index.@n
  642. This function will be called once, shortly after the plugin is created.
  643. */
  644. virtual void initParameter(uint32_t index, Parameter& parameter) = 0;
  645. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  646. /**
  647. Set the name of the program @a index.@n
  648. This function will be called once, shortly after the plugin is created.@n
  649. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  650. */
  651. virtual void initProgramName(uint32_t index, String& programName) = 0;
  652. #endif
  653. #if DISTRHO_PLUGIN_WANT_STATE
  654. /**
  655. Set the state key and default value of @a index.@n
  656. This function will be called once, shortly after the plugin is created.@n
  657. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  658. */
  659. virtual void initState(uint32_t index, String& stateKey, String& defaultStateValue) = 0;
  660. #endif
  661. /* --------------------------------------------------------------------------------------------------------
  662. * Internal data */
  663. /**
  664. Get the current value of a parameter.@n
  665. The host may call this function from any context, including realtime processing.
  666. */
  667. virtual float getParameterValue(uint32_t index) const = 0;
  668. /**
  669. Change a parameter value.@n
  670. The host may call this function from any context, including realtime processing.@n
  671. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  672. @note This function will only be called for parameter inputs.
  673. */
  674. virtual void setParameterValue(uint32_t index, float value) = 0;
  675. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  676. /**
  677. Load a program.@n
  678. The host may call this function from any context, including realtime processing.@n
  679. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  680. */
  681. virtual void loadProgram(uint32_t index) = 0;
  682. #endif
  683. #if DISTRHO_PLUGIN_WANT_FULL_STATE
  684. /**
  685. Get the value of an internal state.@n
  686. The host may call this function from any non-realtime context.@n
  687. Must be implemented by your plugin class if DISTRHO_PLUGIN_WANT_FULL_STATE is enabled.
  688. @note The use of this function breaks compatibility with the DSSI format.
  689. */
  690. virtual String getState(const char* key) const = 0;
  691. #endif
  692. #if DISTRHO_PLUGIN_WANT_STATE
  693. /**
  694. Change an internal state @a key to @a value.@n
  695. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  696. */
  697. virtual void setState(const char* key, const char* value) = 0;
  698. #endif
  699. /* --------------------------------------------------------------------------------------------------------
  700. * Audio/MIDI Processing */
  701. /**
  702. Activate this plugin.
  703. */
  704. virtual void activate() {}
  705. /**
  706. Deactivate this plugin.
  707. */
  708. virtual void deactivate() {}
  709. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  710. /**
  711. Run/process function for plugins with MIDI input.
  712. @note Some parameters might be null if there are no audio inputs/outputs or MIDI events.
  713. */
  714. virtual void run(const float** inputs, float** outputs, uint32_t frames,
  715. const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  716. #else
  717. /**
  718. Run/process function for plugins without MIDI input.
  719. @note Some parameters might be null if there are no audio inputs or outputs.
  720. */
  721. virtual void run(const float** inputs, float** outputs, uint32_t frames) = 0;
  722. #endif
  723. /* --------------------------------------------------------------------------------------------------------
  724. * Callbacks (optional) */
  725. /**
  726. Optional callback to inform the plugin about a buffer size change.@n
  727. This function will only be called when the plugin is deactivated.
  728. @note This value is only a hint!@n
  729. Hosts might call run() with a higher or lower number of frames.
  730. @see getBufferSize()
  731. */
  732. virtual void bufferSizeChanged(uint32_t newBufferSize);
  733. /**
  734. Optional callback to inform the plugin about a sample rate change.@n
  735. This function will only be called when the plugin is deactivated.
  736. @see getSampleRate()
  737. */
  738. virtual void sampleRateChanged(double newSampleRate);
  739. // -------------------------------------------------------------------------------------------------------
  740. private:
  741. struct PrivateData;
  742. PrivateData* const pData;
  743. friend class PluginExporter;
  744. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
  745. };
  746. /** @} */
  747. /* ------------------------------------------------------------------------------------------------------------
  748. * Create plugin, entry point */
  749. /**
  750. @defgroup EntryPoints Entry Points
  751. @{
  752. */
  753. /**
  754. TODO.
  755. */
  756. extern Plugin* createPlugin();
  757. /** @} */
  758. // -----------------------------------------------------------------------------------------------------------
  759. END_NAMESPACE_DISTRHO
  760. #endif // DISTRHO_PLUGIN_HPP_INCLUDED