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.

1039 lines
30KB

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