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.

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