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.

981 lines
27KB

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