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.

935 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 beat.@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. /**
  505. Reinitialize this position using the default null initialization.
  506. */
  507. void clear() noexcept
  508. {
  509. valid = false;
  510. bar = 0;
  511. beat = 0;
  512. tick = 0;
  513. barStartTick = 0.0;
  514. beatsPerBar = 0.0f;
  515. beatType = 0.0f;
  516. ticksPerBeat = 0.0;
  517. beatsPerMinute = 0.0;
  518. }
  519. } bbt;
  520. /**
  521. Default constructor for a time position.
  522. */
  523. TimePosition() noexcept
  524. : playing(false),
  525. frame(0),
  526. bbt() {}
  527. /**
  528. Reinitialize this position using the default null initialization.
  529. */
  530. void clear() noexcept
  531. {
  532. playing = false;
  533. frame = 0;
  534. bbt.clear();
  535. }
  536. };
  537. /** @} */
  538. /* ------------------------------------------------------------------------------------------------------------
  539. * DPF Plugin */
  540. /**
  541. @defgroup MainClasses Main Classes
  542. @{
  543. */
  544. /**
  545. DPF Plugin class from where plugin instances are created.
  546. The public methods (Host state) are called from the plugin to get or set host information.@n
  547. They can be called from a plugin instance at anytime unless stated otherwise.@n
  548. All other methods are to be implemented by the plugin and will be called by the host.
  549. Shortly after a plugin instance is created, the various init* functions will be called by the host.@n
  550. Host will call activate() before run(), and deactivate() before the plugin instance is destroyed.@n
  551. The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.@n
  552. There is no limit on how many times run() is called, only that activate/deactivate will be called in between.
  553. The buffer size and sample rate values will remain constant between activate and deactivate.@n
  554. Buffer size is only a hint though, the host might call run() with a higher or lower number of frames.
  555. Some of this class functions are only available according to some macros.
  556. DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.@n
  557. When enabled you need to implement initProgramName() and loadProgram().
  558. DISTRHO_PLUGIN_WANT_STATE activates internal state features.@n
  559. When enabled you need to implement initStateKey() and setState().
  560. The process function run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.@n
  561. When enabled it provides midi input events.
  562. */
  563. class Plugin
  564. {
  565. public:
  566. /**
  567. Plugin class constructor.@n
  568. You must set all parameter values to their defaults, matching ParameterRanges::def.
  569. */
  570. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  571. /**
  572. Destructor.
  573. */
  574. virtual ~Plugin();
  575. /* --------------------------------------------------------------------------------------------------------
  576. * Host state */
  577. /**
  578. Get the current buffer size that will probably be used during processing, in frames.@n
  579. This value will remain constant between activate and deactivate.
  580. @note This value is only a hint!@n
  581. Hosts might call run() with a higher or lower number of frames.
  582. @see bufferSizeChanged(uint32_t)
  583. */
  584. uint32_t getBufferSize() const noexcept;
  585. /**
  586. Get the current sample rate that will be used during processing.@n
  587. This value will remain constant between activate and deactivate.
  588. @see sampleRateChanged(double)
  589. */
  590. double getSampleRate() const noexcept;
  591. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  592. /**
  593. Get the current host transport time position.@n
  594. This function should only be called during run().@n
  595. You can call this during other times, but the returned position is not guaranteed to be in sync.
  596. @note TimePosition is not supported in LADSPA and DSSI plugin formats.
  597. */
  598. const TimePosition& getTimePosition() const noexcept;
  599. #endif
  600. #if DISTRHO_PLUGIN_WANT_LATENCY
  601. /**
  602. Change the plugin audio output latency to @a frames.@n
  603. This function should only be called in the constructor, activate() and run().
  604. @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
  605. */
  606. void setLatency(uint32_t frames) noexcept;
  607. #endif
  608. #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  609. /**
  610. Write a MIDI output event.@n
  611. This function must only be called during run().@n
  612. Returns false when the host buffer is full, in which case do not call this again until the next run().
  613. */
  614. bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
  615. #endif
  616. protected:
  617. /* --------------------------------------------------------------------------------------------------------
  618. * Information */
  619. /**
  620. Get the plugin name.@n
  621. Returns DISTRHO_PLUGIN_NAME by default.
  622. */
  623. virtual const char* getName() const { return DISTRHO_PLUGIN_NAME; }
  624. /**
  625. Get the plugin label.@n
  626. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  627. */
  628. virtual const char* getLabel() const = 0;
  629. /**
  630. Get an extensive comment/description about the plugin.@n
  631. Optional, returns nothing by default.
  632. */
  633. virtual const char* getDescription() const { return ""; }
  634. /**
  635. Get the plugin author/maker.
  636. */
  637. virtual const char* getMaker() const = 0;
  638. /**
  639. Get the plugin homepage.@n
  640. Optional, returns nothing by default.
  641. */
  642. virtual const char* getHomePage() const { return ""; }
  643. /**
  644. Get the plugin license (a single line of text or a URL).@n
  645. For commercial plugins this should return some short copyright information.
  646. */
  647. virtual const char* getLicense() const = 0;
  648. /**
  649. Get the plugin version, in hexadecimal.
  650. @see d_version()
  651. */
  652. virtual uint32_t getVersion() const = 0;
  653. /**
  654. Get the plugin unique Id.@n
  655. This value is used by LADSPA, DSSI and VST plugin formats.
  656. @see d_cconst()
  657. */
  658. virtual int64_t getUniqueId() const = 0;
  659. /* --------------------------------------------------------------------------------------------------------
  660. * Init */
  661. /**
  662. Initialize the audio port @a index.@n
  663. This function will be called once, shortly after the plugin is created.
  664. */
  665. virtual void initAudioPort(bool input, uint32_t index, AudioPort& port);
  666. /**
  667. Initialize the parameter @a index.@n
  668. This function will be called once, shortly after the plugin is created.
  669. */
  670. virtual void initParameter(uint32_t index, Parameter& parameter) = 0;
  671. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  672. /**
  673. Set the name of the program @a index.@n
  674. This function will be called once, shortly after the plugin is created.@n
  675. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  676. */
  677. virtual void initProgramName(uint32_t index, String& programName) = 0;
  678. #endif
  679. #if DISTRHO_PLUGIN_WANT_STATE
  680. /**
  681. Set the state key and default value of @a index.@n
  682. This function will be called once, shortly after the plugin is created.@n
  683. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  684. */
  685. virtual void initState(uint32_t index, String& stateKey, String& defaultStateValue) = 0;
  686. #endif
  687. /* --------------------------------------------------------------------------------------------------------
  688. * Internal data */
  689. /**
  690. Get the current value of a parameter.@n
  691. The host may call this function from any context, including realtime processing.
  692. */
  693. virtual float getParameterValue(uint32_t index) const = 0;
  694. /**
  695. Change a parameter value.@n
  696. The host may call this function from any context, including realtime processing.@n
  697. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  698. @note This function will only be called for parameter inputs.
  699. */
  700. virtual void setParameterValue(uint32_t index, float value) = 0;
  701. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  702. /**
  703. Load a program.@n
  704. The host may call this function from any context, including realtime processing.@n
  705. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  706. */
  707. virtual void loadProgram(uint32_t index) = 0;
  708. #endif
  709. #if DISTRHO_PLUGIN_WANT_FULL_STATE
  710. /**
  711. Get the value of an internal state.@n
  712. The host may call this function from any non-realtime context.@n
  713. Must be implemented by your plugin class if DISTRHO_PLUGIN_WANT_FULL_STATE is enabled.
  714. @note The use of this function breaks compatibility with the DSSI format.
  715. */
  716. virtual String getState(const char* key) const = 0;
  717. #endif
  718. #if DISTRHO_PLUGIN_WANT_STATE
  719. /**
  720. Change an internal state @a key to @a value.@n
  721. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  722. */
  723. virtual void setState(const char* key, const char* value) = 0;
  724. #endif
  725. /* --------------------------------------------------------------------------------------------------------
  726. * Audio/MIDI Processing */
  727. /**
  728. Activate this plugin.
  729. */
  730. virtual void activate() {}
  731. /**
  732. Deactivate this plugin.
  733. */
  734. virtual void deactivate() {}
  735. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  736. /**
  737. Run/process function for plugins with MIDI input.
  738. @note Some parameters might be null if there are no audio inputs/outputs or MIDI events.
  739. */
  740. virtual void run(const float** inputs, float** outputs, uint32_t frames,
  741. const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  742. #else
  743. /**
  744. Run/process function for plugins without MIDI input.
  745. @note Some parameters might be null if there are no audio inputs or outputs.
  746. */
  747. virtual void run(const float** inputs, float** outputs, uint32_t frames) = 0;
  748. #endif
  749. /* --------------------------------------------------------------------------------------------------------
  750. * Callbacks (optional) */
  751. /**
  752. Optional callback to inform the plugin about a buffer size change.@n
  753. This function will only be called when the plugin is deactivated.
  754. @note This value is only a hint!@n
  755. Hosts might call run() with a higher or lower number of frames.
  756. @see getBufferSize()
  757. */
  758. virtual void bufferSizeChanged(uint32_t newBufferSize);
  759. /**
  760. Optional callback to inform the plugin about a sample rate change.@n
  761. This function will only be called when the plugin is deactivated.
  762. @see getSampleRate()
  763. */
  764. virtual void sampleRateChanged(double newSampleRate);
  765. // -------------------------------------------------------------------------------------------------------
  766. private:
  767. struct PrivateData;
  768. PrivateData* const pData;
  769. friend class PluginExporter;
  770. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
  771. };
  772. /** @} */
  773. /* ------------------------------------------------------------------------------------------------------------
  774. * Create plugin, entry point */
  775. /**
  776. @defgroup EntryPoints Entry Points
  777. @{
  778. */
  779. /**
  780. TODO.
  781. */
  782. extern Plugin* createPlugin();
  783. /** @} */
  784. // -----------------------------------------------------------------------------------------------------------
  785. END_NAMESPACE_DISTRHO
  786. #endif // DISTRHO_PLUGIN_HPP_INCLUDED