Audio plugin host https://kx.studio/carla
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.

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