Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1061 lines
31KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2020 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_PLUGIN_HPP_INCLUDED
  18. #define CARLA_PLUGIN_HPP_INCLUDED
  19. #include "CarlaBackend.h"
  20. #include "CarlaPluginPtr.hpp"
  21. // -----------------------------------------------------------------------
  22. // Avoid including extra libs here
  23. typedef void* lo_message;
  24. typedef struct _NativePluginDescriptor NativePluginDescriptor;
  25. struct LADSPA_RDF_Descriptor;
  26. // -----------------------------------------------------------------------
  27. CARLA_BACKEND_START_NAMESPACE
  28. #if 0
  29. } /* Fix editor indentation */
  30. #endif
  31. // -----------------------------------------------------------------------
  32. /*!
  33. * @defgroup CarlaPluginAPI Carla Plugin API
  34. *
  35. * The Carla Plugin API.
  36. * @{
  37. */
  38. class CarlaEngineAudioPort;
  39. class CarlaEngineCVPort;
  40. class CarlaEngineEventPort;
  41. class CarlaEngineCVSourcePorts;
  42. class CarlaEngineBridge;
  43. struct CarlaStateSave;
  44. // -----------------------------------------------------------------------
  45. /*!
  46. * Carla Backend base plugin class
  47. *
  48. * This is the base class for all available plugin types available in Carla Backend.
  49. * All virtual calls are implemented in this class as fallback (except reload and process),
  50. * so it's safe to only override needed calls.
  51. *
  52. * @see PluginType
  53. */
  54. class CARLA_API CarlaPlugin
  55. {
  56. protected:
  57. /*!
  58. * This is the constructor of the base plugin class.
  59. *
  60. * @param engine The engine which this plugin belongs to, must not be null
  61. * @param id The 'id' of this plugin, must be between 0 and CarlaEngine::maxPluginNumber()
  62. */
  63. CarlaPlugin(CarlaEngine* engine, uint id);
  64. public:
  65. /*!
  66. * This is the destructor of the base plugin class.
  67. */
  68. virtual ~CarlaPlugin();
  69. // -------------------------------------------------------------------
  70. // Information (base)
  71. /*!
  72. * Get the plugin's type (a subclass of CarlaPlugin).
  73. *
  74. * @note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".
  75. * To check if a plugin is a bridge use:
  76. * @code
  77. * if (getHints() & PLUGIN_IS_BRIDGE)
  78. * ...
  79. * @endcode
  80. */
  81. virtual PluginType getType() const noexcept = 0;
  82. /*!
  83. * Get the plugin's id (as passed in the constructor).
  84. *
  85. * @see setId()
  86. */
  87. uint getId() const noexcept;
  88. /*!
  89. * Get the plugin's hints.
  90. *
  91. * @see PluginHints
  92. */
  93. uint getHints() const noexcept;
  94. /*!
  95. * Get the plugin's options (currently in use).
  96. *
  97. * @see PluginOptions, getOptionsAvailable() and setOption()
  98. */
  99. uint getOptionsEnabled() const noexcept;
  100. /*!
  101. * Check if the plugin is enabled.
  102. * When a plugin is disabled, it will never be processed or managed in any way.
  103. *
  104. * @see setEnabled()
  105. */
  106. bool isEnabled() const noexcept;
  107. /*!
  108. * Get the plugin's internal name.
  109. * This name is unique within all plugins in an engine.
  110. *
  111. * @see getRealName() and setName()
  112. */
  113. const char* getName() const noexcept;
  114. /*!
  115. * Get the currently loaded DLL filename for this plugin.
  116. * (Sound kits return their exact filename).
  117. */
  118. const char* getFilename() const noexcept;
  119. /*!
  120. * Get the plugins's icon name.
  121. */
  122. const char* getIconName() const noexcept;
  123. /*!
  124. * Get the plugin's category (delay, filter, synth, etc).
  125. */
  126. virtual PluginCategory getCategory() const noexcept;
  127. /*!
  128. * Get the plugin's native unique Id.
  129. * May return 0 on plugin types that don't support Ids.
  130. */
  131. virtual int64_t getUniqueId() const noexcept;
  132. /*!
  133. * Get the plugin's latency, in sample frames.
  134. */
  135. virtual uint32_t getLatencyInFrames() const noexcept;
  136. // -------------------------------------------------------------------
  137. // Information (count)
  138. /*!
  139. * Get the number of audio inputs.
  140. */
  141. uint32_t getAudioInCount() const noexcept;
  142. /*!
  143. * Get the number of audio outputs.
  144. */
  145. uint32_t getAudioOutCount() const noexcept;
  146. /*!
  147. * Get the number of CV inputs.
  148. */
  149. uint32_t getCVInCount() const noexcept;
  150. /*!
  151. * Get the number of CV outputs.
  152. */
  153. uint32_t getCVOutCount() const noexcept;
  154. /*!
  155. * Get the number of MIDI inputs.
  156. */
  157. virtual uint32_t getMidiInCount() const noexcept;
  158. /*!
  159. * Get the number of MIDI outputs.
  160. */
  161. virtual uint32_t getMidiOutCount() const noexcept;
  162. /*!
  163. * Get the number of parameters.
  164. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  165. */
  166. uint32_t getParameterCount() const noexcept;
  167. /*!
  168. * Get the number of scalepoints for parameter @a parameterId.
  169. */
  170. virtual uint32_t getParameterScalePointCount(uint32_t parameterId) const noexcept;
  171. /*!
  172. * Get the number of programs.
  173. */
  174. uint32_t getProgramCount() const noexcept;
  175. /*!
  176. * Get the number of MIDI programs.
  177. */
  178. uint32_t getMidiProgramCount() const noexcept;
  179. /*!
  180. * Get the number of custom data sets.
  181. */
  182. uint32_t getCustomDataCount() const noexcept;
  183. // -------------------------------------------------------------------
  184. // Information (current data)
  185. /*!
  186. * Get the current program number (-1 if unset).
  187. *
  188. * @see setProgram()
  189. */
  190. int32_t getCurrentProgram() const noexcept;
  191. /*!
  192. * Get the current MIDI program number (-1 if unset).
  193. *
  194. * @see setMidiProgram()
  195. * @see setMidiProgramById()
  196. */
  197. int32_t getCurrentMidiProgram() const noexcept;
  198. /*!
  199. * Get the parameter data of @a parameterId.
  200. */
  201. const ParameterData& getParameterData(uint32_t parameterId) const noexcept;
  202. /*!
  203. * Get the parameter ranges of @a parameterId.
  204. */
  205. const ParameterRanges& getParameterRanges(uint32_t parameterId) const noexcept;
  206. /*!
  207. * Check if parameter @a parameterId is of output type.
  208. */
  209. bool isParameterOutput(uint32_t parameterId) const noexcept;
  210. /*!
  211. * Get the MIDI program at @a index.
  212. *
  213. * @see getMidiProgramName()
  214. */
  215. const MidiProgramData& getMidiProgramData(uint32_t index) const noexcept;
  216. /*!
  217. * Get the custom data set at @a index.
  218. *
  219. * @see getCustomDataCount() and setCustomData()
  220. */
  221. const CustomData& getCustomData(uint32_t index) const noexcept;
  222. /*!
  223. * Get the complete plugin chunk data into @a dataPtr.
  224. *
  225. * @note Make sure to verify the plugin supports chunks before calling this function!
  226. * @return The size of the chunk or 0 if invalid.
  227. *
  228. * @see setChunkData()
  229. */
  230. virtual std::size_t getChunkData(void** dataPtr) noexcept;
  231. // -------------------------------------------------------------------
  232. // Information (per-plugin data)
  233. /*!
  234. * Get the plugin available options.
  235. *
  236. * @see PluginOptions, getOptions() and setOption()
  237. */
  238. virtual uint getOptionsAvailable() const noexcept;
  239. /*!
  240. * Get the current parameter value of @a parameterId.
  241. */
  242. virtual float getParameterValue(uint32_t parameterId) const noexcept;
  243. /*!
  244. * Get the scalepoint @a scalePointId value of the parameter @a parameterId.
  245. */
  246. virtual float getParameterScalePointValue(uint32_t parameterId, uint32_t scalePointId) const noexcept;
  247. /*!
  248. * Get the plugin's label (URI for LV2 plugins).
  249. */
  250. __attribute__((warn_unused_result))
  251. virtual bool getLabel(char* strBuf) const noexcept;
  252. /*!
  253. * Get the plugin's maker.
  254. */
  255. __attribute__((warn_unused_result))
  256. virtual bool getMaker(char* strBuf) const noexcept;
  257. /*!
  258. * Get the plugin's copyright/license.
  259. */
  260. __attribute__((warn_unused_result))
  261. virtual bool getCopyright(char* strBuf) const noexcept;
  262. /*!
  263. * Get the plugin's (real) name.
  264. *
  265. * @see getName() and setName()
  266. */
  267. __attribute__((warn_unused_result))
  268. virtual bool getRealName(char* strBuf) const noexcept;
  269. /*!
  270. * Get the name of the parameter @a parameterId.
  271. */
  272. __attribute__((warn_unused_result))
  273. virtual bool getParameterName(uint32_t parameterId, char* strBuf) const noexcept;
  274. /*!
  275. * Get the symbol of the parameter @a parameterId.
  276. */
  277. __attribute__((warn_unused_result))
  278. virtual bool getParameterSymbol(uint32_t parameterId, char* strBuf) const noexcept;
  279. /*!
  280. * Get the custom text of the parameter @a parameterId.
  281. * @see PARAMETER_USES_CUSTOM_TEXT
  282. */
  283. __attribute__((warn_unused_result))
  284. virtual bool getParameterText(uint32_t parameterId, char* strBuf) noexcept;
  285. /*!
  286. * Get the unit of the parameter @a parameterId.
  287. */
  288. __attribute__((warn_unused_result))
  289. virtual bool getParameterUnit(uint32_t parameterId, char* strBuf) const noexcept;
  290. /*!
  291. * Get the comment (documentation) of the parameter @a parameterId.
  292. */
  293. __attribute__((warn_unused_result))
  294. virtual bool getParameterComment(uint32_t parameterId, char* strBuf) const noexcept;
  295. /*!
  296. * Get the group name of the parameter @a parameterId.
  297. * @note The group name is prefixed by a unique symbol and ":".
  298. */
  299. __attribute__((warn_unused_result))
  300. virtual bool getParameterGroupName(uint32_t parameterId, char* strBuf) const noexcept;
  301. /*!
  302. * Get the scalepoint @a scalePointId label of the parameter @a parameterId.
  303. */
  304. __attribute__((warn_unused_result))
  305. virtual bool getParameterScalePointLabel(uint32_t parameterId, uint32_t scalePointId, char* strBuf) const noexcept;
  306. /*!
  307. * Get the current parameter value of @a parameterId.
  308. * @a parameterId can be negative to allow internal parameters.
  309. * @see InternalParametersIndex
  310. */
  311. float getInternalParameterValue(int32_t parameterId) const noexcept;
  312. /*!
  313. * Get the name of the program at @a index.
  314. */
  315. __attribute__((warn_unused_result))
  316. bool getProgramName(uint32_t index, char* strBuf) const noexcept;
  317. /*!
  318. * Get the name of the MIDI program at @a index.
  319. *
  320. * @see getMidiProgramInfo()
  321. */
  322. __attribute__((warn_unused_result))
  323. bool getMidiProgramName(uint32_t index, char* strBuf) const noexcept;
  324. /*!
  325. * Get information about the plugin's parameter count.
  326. * This is used to check how many input, output and total parameters are available.
  327. *
  328. * @note Some parameters might not be input or output (ie, invalid).
  329. *
  330. * @see getParameterCount()
  331. */
  332. void getParameterCountInfo(uint32_t& ins, uint32_t& outs) const noexcept;
  333. // -------------------------------------------------------------------
  334. // Set data (state)
  335. /*!
  336. * Tell the plugin to prepare for save.
  337. * @param temporary Wherever we are saving into a temporary location
  338. * (for duplication, renaming or similar)
  339. */
  340. virtual void prepareForSave(bool temporary);
  341. /*!
  342. * Reset all possible parameters.
  343. */
  344. virtual void resetParameters() noexcept;
  345. /*!
  346. * Randomize all possible parameters.
  347. */
  348. virtual void randomizeParameters() noexcept;
  349. /*!
  350. * Get the plugin's save state.
  351. * The plugin will automatically call prepareForSave() if requested.
  352. *
  353. * @see loadStateSave()
  354. */
  355. const CarlaStateSave& getStateSave(bool callPrepareForSave = true);
  356. /*!
  357. * Get the plugin's save state.
  358. *
  359. * @see getStateSave()
  360. */
  361. void loadStateSave(const CarlaStateSave& stateSave);
  362. /*!
  363. * Save the current plugin state to @a filename.
  364. *
  365. * @see loadStateFromFile()
  366. */
  367. bool saveStateToFile(const char* filename);
  368. /*!
  369. * Save the plugin state from @a filename.
  370. *
  371. * @see saveStateToFile()
  372. */
  373. bool loadStateFromFile(const char* filename);
  374. /*!
  375. * Export this plugin as LV2.
  376. */
  377. bool exportAsLV2(const char* lv2path);
  378. // -------------------------------------------------------------------
  379. // Set data (internal stuff)
  380. /*!
  381. * Set the plugin's id to @a newId.
  382. *
  383. * @see getId()
  384. * @note RT call
  385. */
  386. virtual void setId(uint newId) noexcept;
  387. /*!
  388. * Set the plugin's name to @a newName.
  389. *
  390. * @see getName() and getRealName()
  391. */
  392. virtual void setName(const char* newName);
  393. /*!
  394. * Set a plugin's option.
  395. *
  396. * @see getOptions() and getOptionsAvailable()
  397. */
  398. virtual void setOption(uint option, bool yesNo, bool sendCallback);
  399. /*!
  400. * Enable or disable the plugin according to @a yesNo.
  401. * When a plugin is disabled, it will never be processed or managed in any way.
  402. *
  403. * @see isEnabled()
  404. */
  405. void setEnabled(bool yesNo) noexcept;
  406. /*!
  407. * Set plugin as active according to @a active.
  408. *
  409. * @param sendOsc Send message change over OSC
  410. * @param sendCallback Send message change to registered callback
  411. */
  412. void setActive(bool active, bool sendOsc, bool sendCallback) noexcept;
  413. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  414. /*!
  415. * Set the plugin's dry/wet signal value to @a value.
  416. * @a value must be between 0.0 and 1.0.
  417. *
  418. * @param sendOsc Send message change over OSC
  419. * @param sendCallback Send message change to registered callback
  420. */
  421. void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept;
  422. /*!
  423. * Set the plugin's output volume to @a value.
  424. * @a value must be between 0.0 and 1.27.
  425. *
  426. * @param sendOsc Send message change over OSC
  427. * @param sendCallback Send message change to registered callback
  428. */
  429. void setVolume(float value, bool sendOsc, bool sendCallback) noexcept;
  430. /*!
  431. * Set the plugin's output left balance value to @a value.
  432. * @a value must be between -1.0 and 1.0.
  433. *
  434. * @param sendOsc Send message change over OSC
  435. * @param sendCallback Send message change to registered callback
  436. *
  437. * @note Pure-Stereo plugins only!
  438. */
  439. void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept;
  440. /*!
  441. * Set the plugin's output right balance value to @a value.
  442. * @a value must be between -1.0 and 1.0.
  443. *
  444. * @param sendOsc Send message change over OSC
  445. * @param sendCallback Send message change to registered callback
  446. *
  447. * @note Pure-Stereo plugins only!
  448. */
  449. void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept;
  450. /*!
  451. * Set the plugin's output panning value to @a value.
  452. * @a value must be between -1.0 and 1.0.
  453. *
  454. * @param sendOsc Send message change over OSC
  455. * @param sendCallback Send message change to registered callback
  456. *
  457. * @note Force-Stereo plugins only!
  458. */
  459. void setPanning(float value, bool sendOsc, bool sendCallback) noexcept;
  460. /*!
  461. * Overloaded functions, to be called from within RT context only.
  462. */
  463. void setDryWetRT(float value, bool sendCallbackLater) noexcept;
  464. void setVolumeRT(float value, bool sendCallbackLater) noexcept;
  465. void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept;
  466. void setBalanceRightRT(float value, bool sendCallbackLater) noexcept;
  467. void setPanningRT(float value, bool sendCallbackLater) noexcept;
  468. #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
  469. /*!
  470. * Set the plugin's midi control channel.
  471. *
  472. * @param sendOsc Send message change over OSC
  473. * @param sendCallback Send message change to registered callback
  474. */
  475. virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept;
  476. // -------------------------------------------------------------------
  477. // Set data (plugin-specific stuff)
  478. /*!
  479. * Set a plugin's parameter value.
  480. *
  481. * @param parameterId The parameter to change
  482. * @param value The new parameter value, must be within the parameter's range
  483. * @param sendGui Send message change to plugin's custom GUI, if any
  484. * @param sendOsc Send message change over OSC
  485. * @param sendCallback Send message change to registered callback
  486. *
  487. * @see getParameterValue()
  488. */
  489. virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  490. /*!
  491. * Overloaded function, to be called from within RT context only.
  492. */
  493. virtual void setParameterValueRT(uint32_t parameterId, float value, bool sendCallbackLater) noexcept;
  494. /*!
  495. * Set a plugin's parameter value, including internal parameters.
  496. * @a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  497. *
  498. * @see setParameterValue()
  499. * @see setActive()
  500. * @see setDryWet()
  501. * @see setVolume()
  502. * @see setBalanceLeft()
  503. * @see setBalanceRight()
  504. */
  505. void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  506. /*!
  507. * Set parameter's @a parameterId MIDI channel to @a channel.
  508. * @a channel must be between 0 and 15.
  509. */
  510. virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
  511. /*!
  512. * Set parameter's @a parameterId mapped control index to @a index.
  513. * @see ParameterData::mappedControlIndex
  514. */
  515. virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index,
  516. bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept;
  517. /*!
  518. * Set parameter's @a parameterId mapped range to @a minimum and @a maximum.
  519. */
  520. virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum,
  521. bool sendOsc, bool sendCallback) noexcept;
  522. /*!
  523. * Add a custom data set.
  524. * If @a key already exists, its current value will be swapped with @a value.
  525. *
  526. * @param type Type of data used in @a value.
  527. * @param key A key identifying this data set.
  528. * @param value The value of the data set, of type @a type.
  529. * @param sendGui Send message change to plugin's custom GUI, if any
  530. *
  531. * @see getCustomDataCount() and getCustomData()
  532. */
  533. virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
  534. /*!
  535. * Set the complete chunk data as @a data.
  536. *
  537. * @see getChunkData()
  538. *
  539. * @note Make sure to verify the plugin supports chunks before calling this function
  540. */
  541. virtual void setChunkData(const void* data, std::size_t dataSize);
  542. /*!
  543. * Change the current plugin program to @a index.
  544. *
  545. * If @a index is negative the plugin's program will be considered unset.
  546. * The plugin's default parameter values will be updated when this function is called.
  547. *
  548. * @param index New program index to use
  549. * @param sendGui Send message change to plugin's custom GUI, if any
  550. * @param sendOsc Send message change over OSC
  551. * @param sendCallback Send message change to registered callback
  552. */
  553. virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  554. /*!
  555. * Change the current MIDI plugin program to @a index.
  556. *
  557. * If @a index is negative the plugin's program will be considered unset.
  558. * The plugin's default parameter values will be updated when this function is called.
  559. *
  560. * @param index New program index to use
  561. * @param sendGui Send message change to plugin's custom GUI, if any
  562. * @param sendOsc Send message change over OSC
  563. * @param sendCallback Send message change to registered callback
  564. */
  565. virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  566. /*!
  567. * This is an overloaded call to setMidiProgram().
  568. * It changes the current MIDI program using @a bank and @a program values instead of index.
  569. */
  570. void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  571. /*!
  572. * Overloaded functions, to be called from within RT context only.
  573. */
  574. virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  575. virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  576. // -------------------------------------------------------------------
  577. // Plugin state
  578. /*!
  579. * Reload the plugin's entire state (including programs).
  580. * The plugin will be disabled during this call.
  581. */
  582. virtual void reload() = 0;
  583. /*!
  584. * Reload the plugin's programs state.
  585. */
  586. virtual void reloadPrograms(bool doInit);
  587. // -------------------------------------------------------------------
  588. // Plugin processing
  589. protected:
  590. /*!
  591. * Plugin activate call.
  592. */
  593. virtual void activate() noexcept;
  594. /*!
  595. * Plugin activate call.
  596. */
  597. virtual void deactivate() noexcept;
  598. public:
  599. /*!
  600. * Plugin process call.
  601. */
  602. virtual void process(const float* const* audioIn, float** audioOut,
  603. const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
  604. /*!
  605. * Tell the plugin the current buffer size changed.
  606. */
  607. virtual void bufferSizeChanged(uint32_t newBufferSize);
  608. /*!
  609. * Tell the plugin the current sample rate changed.
  610. */
  611. virtual void sampleRateChanged(double newSampleRate);
  612. /*!
  613. * Tell the plugin the current offline mode changed.
  614. */
  615. virtual void offlineModeChanged(bool isOffline);
  616. // -------------------------------------------------------------------
  617. // Misc
  618. /*!
  619. * Idle function (non-UI), called at regular intervals.
  620. * @note: This function is NOT called from the main thread.
  621. */
  622. virtual void idle();
  623. /*!
  624. * Try to lock the plugin's master mutex.
  625. * @param forcedOffline When true, always locks and returns true
  626. */
  627. bool tryLock(bool forcedOffline) noexcept;
  628. /*!
  629. * Unlock the plugin's master mutex.
  630. */
  631. void unlock() noexcept;
  632. // -------------------------------------------------------------------
  633. // Plugin buffers
  634. /*!
  635. * Initialize all RT buffers of the plugin.
  636. */
  637. virtual void initBuffers() const noexcept;
  638. /*!
  639. * Delete and clear all RT buffers.
  640. */
  641. virtual void clearBuffers() noexcept;
  642. // -------------------------------------------------------------------
  643. // OSC stuff
  644. /*!
  645. * Handle an OSC message.
  646. * FIXME
  647. */
  648. virtual void handleOscMessage(const char* method,
  649. int argc,
  650. const void* argv,
  651. const char* types,
  652. lo_message msg);
  653. // -------------------------------------------------------------------
  654. // MIDI events
  655. /*!
  656. * Send a single midi note to be processed in the next audio callback.
  657. * A note with 0 velocity means note-off.
  658. * @note Non-RT call
  659. */
  660. void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
  661. bool sendGui, bool sendOsc, bool sendCallback);
  662. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  663. /*!
  664. * Send all midi notes off to the host callback.
  665. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  666. * @note RT call
  667. */
  668. void postponeRtAllNotesOff();
  669. #endif
  670. // -------------------------------------------------------------------
  671. // UI Stuff
  672. /*!
  673. * Set a custom title for the plugin UI window created by Carla.
  674. */
  675. virtual void setCustomUITitle(const char* title) noexcept;
  676. /*!
  677. * Show (or hide) the plugin's custom UI according to @a yesNo.
  678. * This function is always called from the main thread.
  679. */
  680. virtual void showCustomUI(bool yesNo);
  681. /*!
  682. * Embed the plugin's custom UI to the system pointer @a ptr.
  683. * This function is always called from the main thread.
  684. * @note This is very experimental and subject to change at this point
  685. */
  686. virtual void* embedCustomUI(void* ptr);
  687. /*!
  688. * UI idle function, called at regular intervals.
  689. * This function is only called from the main thread if PLUGIN_NEEDS_UI_MAIN_THREAD is set.
  690. * @note This function may sometimes be called even if the UI is not visible yet.
  691. */
  692. virtual void uiIdle();
  693. /*!
  694. * Tell the UI a parameter has changed.
  695. * @see uiIdle
  696. */
  697. virtual void uiParameterChange(uint32_t index, float value) noexcept;
  698. /*!
  699. * Tell the UI the current program has changed.
  700. * @see uiIdle
  701. */
  702. virtual void uiProgramChange(uint32_t index) noexcept;
  703. /*!
  704. * Tell the UI the current midi program has changed.
  705. * @see uiIdle
  706. */
  707. virtual void uiMidiProgramChange(uint32_t index) noexcept;
  708. /*!
  709. * Tell the UI a note has been pressed.
  710. * @see uiIdle
  711. */
  712. virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
  713. /*!
  714. * Tell the UI a note has been released.
  715. * @see uiIdle
  716. */
  717. virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
  718. // -------------------------------------------------------------------
  719. // Helper functions
  720. /*!
  721. * Get the plugin's engine, as passed in the constructor.
  722. */
  723. CarlaEngine* getEngine() const noexcept;
  724. /*!
  725. * Get the plugin's engine client.
  726. */
  727. CarlaEngineClient* getEngineClient() const noexcept;
  728. /*!
  729. * Get a plugin's audio input port.
  730. */
  731. CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
  732. /*!
  733. * Get a plugin's audio output port.
  734. */
  735. CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
  736. /*!
  737. * Get a plugin's CV input port.
  738. */
  739. CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
  740. /*!
  741. * Get a plugin's CV output port.
  742. */
  743. CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
  744. /*!
  745. * Get the plugin's default event input port.
  746. */
  747. CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
  748. /*!
  749. * Get the plugin's default event output port.
  750. */
  751. CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
  752. /*!
  753. * Get the plugin's type native handle.
  754. * This will be LADSPA_Handle, LV2_Handle, etc.
  755. */
  756. virtual void* getNativeHandle() const noexcept;
  757. /*!
  758. * Get the plugin's type native descriptor.
  759. * This will be LADSPA_Descriptor, DSSI_Descriptor, LV2_Descriptor, AEffect, etc.
  760. */
  761. virtual const void* getNativeDescriptor() const noexcept;
  762. /*!
  763. * Get the plugin UI bridge process Id.
  764. */
  765. virtual uintptr_t getUiBridgeProcessId() const noexcept;
  766. // -------------------------------------------------------------------
  767. /*!
  768. * Get the plugin's patchbay nodeId.
  769. * @see setPatchbayNodeId()
  770. */
  771. uint32_t getPatchbayNodeId() const noexcept;
  772. /*!
  773. * Set the plugin's patchbay nodeId.
  774. * @see getPatchbayNodeId()
  775. */
  776. void setPatchbayNodeId(uint32_t nodeId) noexcept;
  777. // -------------------------------------------------------------------
  778. // Plugin initializers
  779. /*!
  780. * Get a plugin's binary type.
  781. * This is always BINARY_NATIVE unless the plugin is a bridge.
  782. */
  783. virtual BinaryType getBinaryType() const noexcept
  784. {
  785. return BINARY_NATIVE;
  786. }
  787. /*!
  788. * Handy function required by CarlaEngine::clonePlugin().
  789. */
  790. virtual const void* getExtraStuff() const noexcept
  791. {
  792. return nullptr;
  793. }
  794. #ifndef DOXYGEN
  795. struct Initializer {
  796. CarlaEngine* const engine;
  797. const uint id;
  798. const char* const filename;
  799. const char* const name;
  800. const char* const label;
  801. const int64_t uniqueId;
  802. const uint options; // see PluginOptions
  803. };
  804. static CarlaPluginPtr newNative(const Initializer& init);
  805. static CarlaPluginPtr newBridge(const Initializer& init,
  806. BinaryType btype, PluginType ptype, const char* bridgeBinary);
  807. static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
  808. static CarlaPluginPtr newDSSI(const Initializer& init);
  809. static CarlaPluginPtr newLV2(const Initializer& init);
  810. static CarlaPluginPtr newVST2(const Initializer& init);
  811. static CarlaPluginPtr newVST3(const Initializer& init);
  812. static CarlaPluginPtr newAU(const Initializer& init);
  813. static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
  814. static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
  815. static CarlaPluginPtr newSFZero(const Initializer& init);
  816. static CarlaPluginPtr newJackApp(const Initializer& init);
  817. #endif
  818. // -------------------------------------------------------------------
  819. protected:
  820. /*!
  821. * Internal data, for CarlaPlugin subclasses only.
  822. */
  823. struct ProtectedData;
  824. ProtectedData* const pData;
  825. // -------------------------------------------------------------------
  826. // Internal helper functions
  827. protected:
  828. /*!
  829. * Clone/copy files from another LV2 plugin into this one..
  830. */
  831. virtual void cloneLV2Files(const CarlaPlugin& other);
  832. /*!
  833. * Call LV2 restore.
  834. * @param temporary Wherever we are saving into a temporary location
  835. * (for duplication, renaming or similar)
  836. */
  837. virtual void restoreLV2State(bool temporary) noexcept;
  838. /*!
  839. * Allow engine to signal that plugin will be deleted soon.
  840. */
  841. virtual void prepareForDeletion() noexcept;
  842. /*!
  843. * Give plugin bridges a change to update their custom data sets.
  844. */
  845. virtual void waitForBridgeSaveSignal() noexcept;
  846. // -------------------------------------------------------------------
  847. // Helper classes
  848. /*!
  849. * Fully disable plugin in scope and also its engine client.
  850. * May wait-block on constructor for plugin process to end.
  851. */
  852. class ScopedDisabler
  853. {
  854. public:
  855. ScopedDisabler(CarlaPlugin* plugin) noexcept;
  856. ~ScopedDisabler() noexcept;
  857. private:
  858. CarlaPlugin* const fPlugin;
  859. bool fWasEnabled;
  860. CARLA_PREVENT_HEAP_ALLOCATION
  861. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  862. };
  863. /*!
  864. * Lock the plugin's own run/process call.
  865. * Plugin will still work as normal, but output only silence.
  866. * On destructor needsReset flag might be set if the plugin might have missed some events.
  867. */
  868. class ScopedSingleProcessLocker
  869. {
  870. public:
  871. ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
  872. ~ScopedSingleProcessLocker() noexcept;
  873. private:
  874. CarlaPlugin* const fPlugin;
  875. const bool fBlock;
  876. CARLA_PREVENT_HEAP_ALLOCATION
  877. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  878. };
  879. friend class CarlaEngine;
  880. friend class CarlaEngineBridge;
  881. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  882. };
  883. /**@}*/
  884. // -----------------------------------------------------------------------
  885. CARLA_BACKEND_END_NAMESPACE
  886. #endif // CARLA_PLUGIN_HPP_INCLUDED