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.

951 lines
26KB

  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. 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 short name of this parameter.@n
  326. Used when displaying the parameter name in a very limited space.
  327. @note This value is optional, the full name is used when the short one is missing.
  328. */
  329. String shortName;
  330. /**
  331. The symbol of this parameter.@n
  332. A parameter symbol is a short restricted name used as a machine and human readable identifier.@n
  333. 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.
  334. @note Parameter symbols MUST be unique within a plugin instance.
  335. */
  336. String symbol;
  337. /**
  338. The unit of this parameter.@n
  339. This means something like "dB", "kHz" and "ms".@n
  340. Can be left blank if a unit does not apply to this parameter.
  341. */
  342. String unit;
  343. /**
  344. An extensive description/comment about the parameter.
  345. @note This value is optional and only used for LV2.
  346. */
  347. String description;
  348. /**
  349. Ranges of this parameter.@n
  350. The ranges describe the default, minimum and maximum values.
  351. */
  352. ParameterRanges ranges;
  353. /**
  354. Enumeration values.@n
  355. Can be used to give meaning to parameter values, working as an enumeration.
  356. */
  357. ParameterEnumerationValues enumValues;
  358. /**
  359. Designation for this parameter.
  360. */
  361. ParameterDesignation designation;
  362. /**
  363. MIDI CC to use by default on this parameter.@n
  364. A value of 0 or 32 (bank change) is considered invalid.@n
  365. Must also be less or equal to 120.
  366. @note This value is only a hint! Hosts might map it automatically or completely ignore it.
  367. */
  368. uint8_t midiCC;
  369. /**
  370. Default constructor for a null parameter.
  371. */
  372. Parameter() noexcept
  373. : hints(0x0),
  374. name(),
  375. shortName(),
  376. symbol(),
  377. unit(),
  378. ranges(),
  379. enumValues(),
  380. designation(kParameterDesignationNull),
  381. midiCC(0) {}
  382. /**
  383. Constructor using custom values.
  384. */
  385. Parameter(uint32_t h, const char* n, const char* s, const char* u, float def, float min, float max) noexcept
  386. : hints(h),
  387. name(n),
  388. shortName(),
  389. symbol(s),
  390. unit(u),
  391. ranges(def, min, max),
  392. enumValues(),
  393. designation(kParameterDesignationNull),
  394. midiCC(0) {}
  395. /**
  396. Initialize a parameter for a specific designation.
  397. */
  398. void initDesignation(ParameterDesignation d) noexcept
  399. {
  400. designation = d;
  401. switch (d)
  402. {
  403. case kParameterDesignationNull:
  404. break;
  405. case kParameterDesignationBypass:
  406. hints = kParameterIsAutomable|kParameterIsBoolean|kParameterIsInteger;
  407. name = "Bypass";
  408. shortName = "Bypass";
  409. symbol = "dpf_bypass";
  410. unit = "";
  411. midiCC = 0;
  412. ranges.def = 0.0f;
  413. ranges.min = 0.0f;
  414. ranges.max = 1.0f;
  415. break;
  416. }
  417. }
  418. };
  419. /**
  420. MIDI event.
  421. */
  422. struct MidiEvent {
  423. /**
  424. Size of internal data.
  425. */
  426. static const uint32_t kDataSize = 4;
  427. /**
  428. Time offset in frames.
  429. */
  430. uint32_t frame;
  431. /**
  432. Number of bytes used.
  433. */
  434. uint32_t size;
  435. /**
  436. MIDI data.@n
  437. If size > kDataSize, dataExt is used (otherwise null).
  438. */
  439. uint8_t data[kDataSize];
  440. const uint8_t* dataExt;
  441. };
  442. /**
  443. Time position.@n
  444. The @a playing and @a frame values are always valid.@n
  445. BBT values are only valid when @a bbt.valid is true.
  446. This struct is inspired by the JACK Transport API.
  447. */
  448. struct TimePosition {
  449. /**
  450. Wherever the host transport is playing/rolling.
  451. */
  452. bool playing;
  453. /**
  454. Current host transport position in frames.
  455. */
  456. uint64_t frame;
  457. /**
  458. Bar-Beat-Tick time position.
  459. */
  460. struct BarBeatTick {
  461. /**
  462. Wherever the host transport is using BBT.@n
  463. If false you must not read from this struct.
  464. */
  465. bool valid;
  466. /**
  467. Current bar.@n
  468. Should always be > 0.@n
  469. The first bar is bar '1'.
  470. */
  471. int32_t bar;
  472. /**
  473. Current beat within bar.@n
  474. Should always be > 0 and <= @a beatsPerBar.@n
  475. The first beat is beat '1'.
  476. */
  477. int32_t beat;
  478. /**
  479. Current tick within beat.@n
  480. Should always be >= 0 and < @a ticksPerBeat.@n
  481. The first tick is tick '0'.
  482. */
  483. int32_t tick;
  484. /**
  485. Number of ticks that have elapsed between frame 0 and the first beat of the current measure.
  486. */
  487. double barStartTick;
  488. /**
  489. Time signature "numerator".
  490. */
  491. float beatsPerBar;
  492. /**
  493. Time signature "denominator".
  494. */
  495. float beatType;
  496. /**
  497. Number of ticks within a beat.@n
  498. Usually a moderately large integer with many denominators, such as 1920.0.
  499. */
  500. double ticksPerBeat;
  501. /**
  502. Number of beats per minute.
  503. */
  504. double beatsPerMinute;
  505. /**
  506. Default constructor for a null BBT time position.
  507. */
  508. BarBeatTick() noexcept
  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. Reinitialize this position using the default null initialization.
  520. */
  521. void clear() noexcept
  522. {
  523. valid = false;
  524. bar = 0;
  525. beat = 0;
  526. tick = 0;
  527. barStartTick = 0.0;
  528. beatsPerBar = 0.0f;
  529. beatType = 0.0f;
  530. ticksPerBeat = 0.0;
  531. beatsPerMinute = 0.0;
  532. }
  533. } bbt;
  534. /**
  535. Default constructor for a time position.
  536. */
  537. TimePosition() noexcept
  538. : playing(false),
  539. frame(0),
  540. bbt() {}
  541. /**
  542. Reinitialize this position using the default null initialization.
  543. */
  544. void clear() noexcept
  545. {
  546. playing = false;
  547. frame = 0;
  548. bbt.clear();
  549. }
  550. };
  551. /** @} */
  552. /* ------------------------------------------------------------------------------------------------------------
  553. * DPF Plugin */
  554. /**
  555. @defgroup MainClasses Main Classes
  556. @{
  557. */
  558. /**
  559. DPF Plugin class from where plugin instances are created.
  560. The public methods (Host state) are called from the plugin to get or set host information.@n
  561. They can be called from a plugin instance at anytime unless stated otherwise.@n
  562. All other methods are to be implemented by the plugin and will be called by the host.
  563. Shortly after a plugin instance is created, the various init* functions will be called by the host.@n
  564. Host will call activate() before run(), and deactivate() before the plugin instance is destroyed.@n
  565. The host may call deactivate right after activate and vice-versa, but never activate/deactivate consecutively.@n
  566. There is no limit on how many times run() is called, only that activate/deactivate will be called in between.
  567. The buffer size and sample rate values will remain constant between activate and deactivate.@n
  568. Buffer size is only a hint though, the host might call run() with a higher or lower number of frames.
  569. Some of this class functions are only available according to some macros.
  570. DISTRHO_PLUGIN_WANT_PROGRAMS activates program related features.@n
  571. When enabled you need to implement initProgramName() and loadProgram().
  572. DISTRHO_PLUGIN_WANT_STATE activates internal state features.@n
  573. When enabled you need to implement initStateKey() and setState().
  574. The process function run() changes wherever DISTRHO_PLUGIN_WANT_MIDI_INPUT is enabled or not.@n
  575. When enabled it provides midi input events.
  576. */
  577. class Plugin
  578. {
  579. public:
  580. /**
  581. Plugin class constructor.@n
  582. You must set all parameter values to their defaults, matching ParameterRanges::def.
  583. */
  584. Plugin(uint32_t parameterCount, uint32_t programCount, uint32_t stateCount);
  585. /**
  586. Destructor.
  587. */
  588. virtual ~Plugin();
  589. /* --------------------------------------------------------------------------------------------------------
  590. * Host state */
  591. /**
  592. Get the current buffer size that will probably be used during processing, in frames.@n
  593. This value will remain constant between activate and deactivate.
  594. @note This value is only a hint!@n
  595. Hosts might call run() with a higher or lower number of frames.
  596. @see bufferSizeChanged(uint32_t)
  597. */
  598. uint32_t getBufferSize() const noexcept;
  599. /**
  600. Get the current sample rate that will be used during processing.@n
  601. This value will remain constant between activate and deactivate.
  602. @see sampleRateChanged(double)
  603. */
  604. double getSampleRate() const noexcept;
  605. #if DISTRHO_PLUGIN_WANT_TIMEPOS
  606. /**
  607. Get the current host transport time position.@n
  608. This function should only be called during run().@n
  609. You can call this during other times, but the returned position is not guaranteed to be in sync.
  610. @note TimePosition is not supported in LADSPA and DSSI plugin formats.
  611. */
  612. const TimePosition& getTimePosition() const noexcept;
  613. #endif
  614. #if DISTRHO_PLUGIN_WANT_LATENCY
  615. /**
  616. Change the plugin audio output latency to @a frames.@n
  617. This function should only be called in the constructor, activate() and run().
  618. @note This function is only available if DISTRHO_PLUGIN_WANT_LATENCY is enabled.
  619. */
  620. void setLatency(uint32_t frames) noexcept;
  621. #endif
  622. #if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
  623. /**
  624. Write a MIDI output event.@n
  625. This function must only be called during run().@n
  626. Returns false when the host buffer is full, in which case do not call this again until the next run().
  627. */
  628. bool writeMidiEvent(const MidiEvent& midiEvent) noexcept;
  629. #endif
  630. protected:
  631. /* --------------------------------------------------------------------------------------------------------
  632. * Information */
  633. /**
  634. Get the plugin name.@n
  635. Returns DISTRHO_PLUGIN_NAME by default.
  636. */
  637. virtual const char* getName() const { return DISTRHO_PLUGIN_NAME; }
  638. /**
  639. Get the plugin label.@n
  640. This label is a short restricted name consisting of only _, a-z, A-Z and 0-9 characters.
  641. */
  642. virtual const char* getLabel() const = 0;
  643. /**
  644. Get an extensive comment/description about the plugin.@n
  645. Optional, returns nothing by default.
  646. */
  647. virtual const char* getDescription() const { return ""; }
  648. /**
  649. Get the plugin author/maker.
  650. */
  651. virtual const char* getMaker() const = 0;
  652. /**
  653. Get the plugin homepage.@n
  654. Optional, returns nothing by default.
  655. */
  656. virtual const char* getHomePage() const { return ""; }
  657. /**
  658. Get the plugin license (a single line of text or a URL).@n
  659. For commercial plugins this should return some short copyright information.
  660. */
  661. virtual const char* getLicense() const = 0;
  662. /**
  663. Get the plugin version, in hexadecimal.
  664. @see d_version()
  665. */
  666. virtual uint32_t getVersion() const = 0;
  667. /**
  668. Get the plugin unique Id.@n
  669. This value is used by LADSPA, DSSI and VST plugin formats.
  670. @see d_cconst()
  671. */
  672. virtual int64_t getUniqueId() const = 0;
  673. /* --------------------------------------------------------------------------------------------------------
  674. * Init */
  675. /**
  676. Initialize the audio port @a index.@n
  677. This function will be called once, shortly after the plugin is created.
  678. */
  679. virtual void initAudioPort(bool input, uint32_t index, AudioPort& port);
  680. /**
  681. Initialize the parameter @a index.@n
  682. This function will be called once, shortly after the plugin is created.
  683. */
  684. virtual void initParameter(uint32_t index, Parameter& parameter) = 0;
  685. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  686. /**
  687. Set the name of the program @a index.@n
  688. This function will be called once, shortly after the plugin is created.@n
  689. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  690. */
  691. virtual void initProgramName(uint32_t index, String& programName) = 0;
  692. #endif
  693. #if DISTRHO_PLUGIN_WANT_STATE
  694. /**
  695. Set the state key and default value of @a index.@n
  696. This function will be called once, shortly after the plugin is created.@n
  697. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  698. */
  699. virtual void initState(uint32_t index, String& stateKey, String& defaultStateValue) = 0;
  700. #endif
  701. /* --------------------------------------------------------------------------------------------------------
  702. * Internal data */
  703. /**
  704. Get the current value of a parameter.@n
  705. The host may call this function from any context, including realtime processing.
  706. */
  707. virtual float getParameterValue(uint32_t index) const = 0;
  708. /**
  709. Change a parameter value.@n
  710. The host may call this function from any context, including realtime processing.@n
  711. When a parameter is marked as automable, you must ensure no non-realtime operations are performed.
  712. @note This function will only be called for parameter inputs.
  713. */
  714. virtual void setParameterValue(uint32_t index, float value) = 0;
  715. #if DISTRHO_PLUGIN_WANT_PROGRAMS
  716. /**
  717. Load a program.@n
  718. The host may call this function from any context, including realtime processing.@n
  719. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_PROGRAMS is enabled.
  720. */
  721. virtual void loadProgram(uint32_t index) = 0;
  722. #endif
  723. #if DISTRHO_PLUGIN_WANT_FULL_STATE
  724. /**
  725. Get the value of an internal state.@n
  726. The host may call this function from any non-realtime context.@n
  727. Must be implemented by your plugin class if DISTRHO_PLUGIN_WANT_FULL_STATE is enabled.
  728. @note The use of this function breaks compatibility with the DSSI format.
  729. */
  730. virtual String getState(const char* key) const = 0;
  731. #endif
  732. #if DISTRHO_PLUGIN_WANT_STATE
  733. /**
  734. Change an internal state @a key to @a value.@n
  735. Must be implemented by your plugin class only if DISTRHO_PLUGIN_WANT_STATE is enabled.
  736. */
  737. virtual void setState(const char* key, const char* value) = 0;
  738. #endif
  739. /* --------------------------------------------------------------------------------------------------------
  740. * Audio/MIDI Processing */
  741. /**
  742. Activate this plugin.
  743. */
  744. virtual void activate() {}
  745. /**
  746. Deactivate this plugin.
  747. */
  748. virtual void deactivate() {}
  749. #if DISTRHO_PLUGIN_WANT_MIDI_INPUT
  750. /**
  751. Run/process function for plugins with MIDI input.
  752. @note Some parameters might be null if there are no audio inputs/outputs or MIDI events.
  753. */
  754. virtual void run(const float** inputs, float** outputs, uint32_t frames,
  755. const MidiEvent* midiEvents, uint32_t midiEventCount) = 0;
  756. #else
  757. /**
  758. Run/process function for plugins without MIDI input.
  759. @note Some parameters might be null if there are no audio inputs or outputs.
  760. */
  761. virtual void run(const float** inputs, float** outputs, uint32_t frames) = 0;
  762. #endif
  763. /* --------------------------------------------------------------------------------------------------------
  764. * Callbacks (optional) */
  765. /**
  766. Optional callback to inform the plugin about a buffer size change.@n
  767. This function will only be called when the plugin is deactivated.
  768. @note This value is only a hint!@n
  769. Hosts might call run() with a higher or lower number of frames.
  770. @see getBufferSize()
  771. */
  772. virtual void bufferSizeChanged(uint32_t newBufferSize);
  773. /**
  774. Optional callback to inform the plugin about a sample rate change.@n
  775. This function will only be called when the plugin is deactivated.
  776. @see getSampleRate()
  777. */
  778. virtual void sampleRateChanged(double newSampleRate);
  779. // -------------------------------------------------------------------------------------------------------
  780. private:
  781. struct PrivateData;
  782. PrivateData* const pData;
  783. friend class PluginExporter;
  784. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Plugin)
  785. };
  786. /** @} */
  787. /* ------------------------------------------------------------------------------------------------------------
  788. * Create plugin, entry point */
  789. /**
  790. @defgroup EntryPoints Entry Points
  791. @{
  792. */
  793. /**
  794. TODO.
  795. */
  796. extern Plugin* createPlugin();
  797. /** @} */
  798. // -----------------------------------------------------------------------------------------------------------
  799. END_NAMESPACE_DISTRHO
  800. #endif // DISTRHO_PLUGIN_HPP_INCLUDED