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.

1045 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. */
  338. virtual void prepareForSave();
  339. /*!
  340. * Reset all possible parameters.
  341. */
  342. virtual void resetParameters() noexcept;
  343. /*!
  344. * Randomize all possible parameters.
  345. */
  346. virtual void randomizeParameters() noexcept;
  347. /*!
  348. * Get the plugin's save state.
  349. * The plugin will automatically call prepareForSave() if requested.
  350. *
  351. * @see loadStateSave()
  352. */
  353. const CarlaStateSave& getStateSave(bool callPrepareForSave = true);
  354. /*!
  355. * Get the plugin's save state.
  356. *
  357. * @see getStateSave()
  358. */
  359. void loadStateSave(const CarlaStateSave& stateSave);
  360. /*!
  361. * Save the current plugin state to @a filename.
  362. *
  363. * @see loadStateFromFile()
  364. */
  365. bool saveStateToFile(const char* filename);
  366. /*!
  367. * Save the plugin state from @a filename.
  368. *
  369. * @see saveStateToFile()
  370. */
  371. bool loadStateFromFile(const char* filename);
  372. /*!
  373. * Export this plugin as LV2.
  374. */
  375. bool exportAsLV2(const char* lv2path);
  376. // -------------------------------------------------------------------
  377. // Set data (internal stuff)
  378. /*!
  379. * Set the plugin's id to @a newId.
  380. *
  381. * @see getId()
  382. * @note RT call
  383. */
  384. virtual void setId(uint newId) noexcept;
  385. /*!
  386. * Set the plugin's name to @a newName.
  387. *
  388. * @see getName() and getRealName()
  389. */
  390. virtual void setName(const char* newName);
  391. /*!
  392. * Set a plugin's option.
  393. *
  394. * @see getOptions() and getOptionsAvailable()
  395. */
  396. virtual void setOption(uint option, bool yesNo, bool sendCallback);
  397. /*!
  398. * Enable or disable the plugin according to @a yesNo.
  399. * When a plugin is disabled, it will never be processed or managed in any way.
  400. *
  401. * @see isEnabled()
  402. */
  403. void setEnabled(bool yesNo) noexcept;
  404. /*!
  405. * Set plugin as active according to @a active.
  406. *
  407. * @param sendOsc Send message change over OSC
  408. * @param sendCallback Send message change to registered callback
  409. */
  410. void setActive(bool active, bool sendOsc, bool sendCallback) noexcept;
  411. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  412. /*!
  413. * Set the plugin's dry/wet signal value to @a value.
  414. * @a value must be between 0.0 and 1.0.
  415. *
  416. * @param sendOsc Send message change over OSC
  417. * @param sendCallback Send message change to registered callback
  418. */
  419. void setDryWet(float value, bool sendOsc, bool sendCallback) noexcept;
  420. /*!
  421. * Set the plugin's output volume to @a value.
  422. * @a value must be between 0.0 and 1.27.
  423. *
  424. * @param sendOsc Send message change over OSC
  425. * @param sendCallback Send message change to registered callback
  426. */
  427. void setVolume(float value, bool sendOsc, bool sendCallback) noexcept;
  428. /*!
  429. * Set the plugin's output left balance value to @a value.
  430. * @a value must be between -1.0 and 1.0.
  431. *
  432. * @param sendOsc Send message change over OSC
  433. * @param sendCallback Send message change to registered callback
  434. *
  435. * @note Pure-Stereo plugins only!
  436. */
  437. void setBalanceLeft(float value, bool sendOsc, bool sendCallback) noexcept;
  438. /*!
  439. * Set the plugin's output right balance value to @a value.
  440. * @a value must be between -1.0 and 1.0.
  441. *
  442. * @param sendOsc Send message change over OSC
  443. * @param sendCallback Send message change to registered callback
  444. *
  445. * @note Pure-Stereo plugins only!
  446. */
  447. void setBalanceRight(float value, bool sendOsc, bool sendCallback) noexcept;
  448. /*!
  449. * Set the plugin's output panning value to @a value.
  450. * @a value must be between -1.0 and 1.0.
  451. *
  452. * @param sendOsc Send message change over OSC
  453. * @param sendCallback Send message change to registered callback
  454. *
  455. * @note Force-Stereo plugins only!
  456. */
  457. void setPanning(float value, bool sendOsc, bool sendCallback) noexcept;
  458. /*!
  459. * Overloaded functions, to be called from within RT context only.
  460. */
  461. void setDryWetRT(float value, bool sendCallbackLater) noexcept;
  462. void setVolumeRT(float value, bool sendCallbackLater) noexcept;
  463. void setBalanceLeftRT(float value, bool sendCallbackLater) noexcept;
  464. void setBalanceRightRT(float value, bool sendCallbackLater) noexcept;
  465. void setPanningRT(float value, bool sendCallbackLater) noexcept;
  466. #endif // ! BUILD_BRIDGE_ALTERNATIVE_ARCH
  467. /*!
  468. * Set the plugin's midi control channel.
  469. *
  470. * @param sendOsc Send message change over OSC
  471. * @param sendCallback Send message change to registered callback
  472. */
  473. virtual void setCtrlChannel(int8_t channel, bool sendOsc, bool sendCallback) noexcept;
  474. // -------------------------------------------------------------------
  475. // Set data (plugin-specific stuff)
  476. /*!
  477. * Set a plugin's parameter value.
  478. *
  479. * @param parameterId The parameter to change
  480. * @param value The new parameter value, must be within the parameter's range
  481. * @param sendGui Send message change to plugin's custom GUI, if any
  482. * @param sendOsc Send message change over OSC
  483. * @param sendCallback Send message change to registered callback
  484. *
  485. * @see getParameterValue()
  486. */
  487. virtual void setParameterValue(uint32_t parameterId, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  488. /*!
  489. * Overloaded function, to be called from within RT context only.
  490. */
  491. virtual void setParameterValueRT(uint32_t parameterId, float value, bool sendCallbackLater) noexcept;
  492. /*!
  493. * Set a plugin's parameter value, including internal parameters.
  494. * @a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  495. *
  496. * @see setParameterValue()
  497. * @see setActive()
  498. * @see setDryWet()
  499. * @see setVolume()
  500. * @see setBalanceLeft()
  501. * @see setBalanceRight()
  502. */
  503. void setParameterValueByRealIndex(int32_t rindex, float value, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  504. /*!
  505. * Set parameter's @a parameterId MIDI channel to @a channel.
  506. * @a channel must be between 0 and 15.
  507. */
  508. virtual void setParameterMidiChannel(uint32_t parameterId, uint8_t channel, bool sendOsc, bool sendCallback) noexcept;
  509. /*!
  510. * Set parameter's @a parameterId mapped control index to @a index.
  511. * @see ParameterData::mappedControlIndex
  512. */
  513. virtual void setParameterMappedControlIndex(uint32_t parameterId, int16_t index, bool sendOsc, bool sendCallback) noexcept;
  514. /*!
  515. * Set parameter's @a parameterId mapped range to @a minimum and @a maximum.
  516. */
  517. virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum, bool sendOsc, bool sendCallback) noexcept;
  518. /*!
  519. * Add a custom data set.
  520. * If @a key already exists, its current value will be swapped with @a value.
  521. *
  522. * @param type Type of data used in @a value.
  523. * @param key A key identifying this data set.
  524. * @param value The value of the data set, of type @a type.
  525. * @param sendGui Send message change to plugin's custom GUI, if any
  526. *
  527. * @see getCustomDataCount() and getCustomData()
  528. */
  529. virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
  530. /*!
  531. * Set the complete chunk data as @a data.
  532. *
  533. * @see getChunkData()
  534. *
  535. * @note Make sure to verify the plugin supports chunks before calling this function
  536. */
  537. virtual void setChunkData(const void* data, std::size_t dataSize);
  538. /*!
  539. * Change the current plugin program to @a index.
  540. *
  541. * If @a index is negative the plugin's program will be considered unset.
  542. * The plugin's default parameter values will be updated when this function is called.
  543. *
  544. * @param index New program index to use
  545. * @param sendGui Send message change to plugin's custom GUI, if any
  546. * @param sendOsc Send message change over OSC
  547. * @param sendCallback Send message change to registered callback
  548. */
  549. virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  550. /*!
  551. * Change the current MIDI plugin program to @a index.
  552. *
  553. * If @a index is negative the plugin's program will be considered unset.
  554. * The plugin's default parameter values will be updated when this function is called.
  555. *
  556. * @param index New program index to use
  557. * @param sendGui Send message change to plugin's custom GUI, if any
  558. * @param sendOsc Send message change over OSC
  559. * @param sendCallback Send message change to registered callback
  560. */
  561. virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  562. /*!
  563. * This is an overloaded call to setMidiProgram().
  564. * It changes the current MIDI program using @a bank and @a program values instead of index.
  565. */
  566. void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  567. /*!
  568. * Overloaded functions, to be called from within RT context only.
  569. */
  570. virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  571. virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  572. // -------------------------------------------------------------------
  573. // Plugin state
  574. /*!
  575. * Reload the plugin's entire state (including programs).
  576. * The plugin will be disabled during this call.
  577. */
  578. virtual void reload() = 0;
  579. /*!
  580. * Reload the plugin's programs state.
  581. */
  582. virtual void reloadPrograms(bool doInit);
  583. // -------------------------------------------------------------------
  584. // Plugin processing
  585. protected:
  586. /*!
  587. * Plugin activate call.
  588. */
  589. virtual void activate() noexcept;
  590. /*!
  591. * Plugin activate call.
  592. */
  593. virtual void deactivate() noexcept;
  594. public:
  595. /*!
  596. * Plugin process call.
  597. */
  598. virtual void process(const float* const* audioIn, float** audioOut,
  599. const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
  600. /*!
  601. * Tell the plugin the current buffer size changed.
  602. */
  603. virtual void bufferSizeChanged(uint32_t newBufferSize);
  604. /*!
  605. * Tell the plugin the current sample rate changed.
  606. */
  607. virtual void sampleRateChanged(double newSampleRate);
  608. /*!
  609. * Tell the plugin the current offline mode changed.
  610. */
  611. virtual void offlineModeChanged(bool isOffline);
  612. // -------------------------------------------------------------------
  613. // Misc
  614. /*!
  615. * Idle function (non-UI), called at regular intervals.
  616. * @note: This function is NOT called from the main thread.
  617. */
  618. virtual void idle();
  619. /*!
  620. * Try to lock the plugin's master mutex.
  621. * @param forcedOffline When true, always locks and returns true
  622. */
  623. bool tryLock(bool forcedOffline) noexcept;
  624. /*!
  625. * Unlock the plugin's master mutex.
  626. */
  627. void unlock() noexcept;
  628. // -------------------------------------------------------------------
  629. // Plugin buffers
  630. /*!
  631. * Initialize all RT buffers of the plugin.
  632. */
  633. virtual void initBuffers() const noexcept;
  634. /*!
  635. * Delete and clear all RT buffers.
  636. */
  637. virtual void clearBuffers() noexcept;
  638. // -------------------------------------------------------------------
  639. // OSC stuff
  640. /*!
  641. * Handle an OSC message.
  642. * FIXME
  643. */
  644. virtual void handleOscMessage(const char* method,
  645. int argc,
  646. const void* argv,
  647. const char* types,
  648. lo_message msg);
  649. // -------------------------------------------------------------------
  650. // MIDI events
  651. /*!
  652. * Send a single midi note to be processed in the next audio callback.
  653. * A note with 0 velocity means note-off.
  654. * @note Non-RT call
  655. */
  656. void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
  657. bool sendGui, bool sendOsc, bool sendCallback);
  658. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  659. /*!
  660. * Send all midi notes off to the host callback.
  661. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  662. * @note RT call
  663. */
  664. void postponeRtAllNotesOff();
  665. #endif
  666. // -------------------------------------------------------------------
  667. // UI Stuff
  668. /*!
  669. * Set a custom title for the plugin UI window created by Carla.
  670. */
  671. virtual void setCustomUITitle(const char* title) noexcept;
  672. /*!
  673. * Show (or hide) the plugin's custom UI according to @a yesNo.
  674. * This function is always called from the main thread.
  675. */
  676. virtual void showCustomUI(bool yesNo);
  677. /*!
  678. * UI idle function, called at regular intervals.
  679. * This function is only called from the main thread if PLUGIN_NEEDS_UI_MAIN_THREAD is set.
  680. * @note This function may sometimes be called even if the UI is not visible yet.
  681. */
  682. virtual void uiIdle();
  683. /*!
  684. * Tell the UI a parameter has changed.
  685. * @see uiIdle
  686. */
  687. virtual void uiParameterChange(uint32_t index, float value) noexcept;
  688. /*!
  689. * Tell the UI the current program has changed.
  690. * @see uiIdle
  691. */
  692. virtual void uiProgramChange(uint32_t index) noexcept;
  693. /*!
  694. * Tell the UI the current midi program has changed.
  695. * @see uiIdle
  696. */
  697. virtual void uiMidiProgramChange(uint32_t index) noexcept;
  698. /*!
  699. * Tell the UI a note has been pressed.
  700. * @see uiIdle
  701. */
  702. virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
  703. /*!
  704. * Tell the UI a note has been released.
  705. * @see uiIdle
  706. */
  707. virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
  708. // -------------------------------------------------------------------
  709. // Helper functions
  710. /*!
  711. * Get the plugin's engine, as passed in the constructor.
  712. */
  713. CarlaEngine* getEngine() const noexcept;
  714. /*!
  715. * Get the plugin's engine client.
  716. */
  717. CarlaEngineClient* getEngineClient() const noexcept;
  718. /*!
  719. * Get a plugin's audio input port.
  720. */
  721. CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
  722. /*!
  723. * Get a plugin's audio output port.
  724. */
  725. CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
  726. /*!
  727. * Get a plugin's CV input port.
  728. */
  729. CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
  730. /*!
  731. * Get a plugin's CV output port.
  732. */
  733. CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
  734. /*!
  735. * Get the plugin's default event input port.
  736. */
  737. CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
  738. /*!
  739. * Get the plugin's default event output port.
  740. */
  741. CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
  742. /*!
  743. * Get the plugin's type native handle.
  744. * This will be LADSPA_Handle, LV2_Handle, etc.
  745. */
  746. virtual void* getNativeHandle() const noexcept;
  747. /*!
  748. * Get the plugin's type native descriptor.
  749. * This will be LADSPA_Descriptor, DSSI_Descriptor, LV2_Descriptor, AEffect, etc.
  750. */
  751. virtual const void* getNativeDescriptor() const noexcept;
  752. /*!
  753. * Get the plugin UI bridge process Id.
  754. */
  755. virtual uintptr_t getUiBridgeProcessId() const noexcept;
  756. // -------------------------------------------------------------------
  757. /*!
  758. * Get the plugin's patchbay nodeId.
  759. * @see setPatchbayNodeId()
  760. */
  761. uint32_t getPatchbayNodeId() const noexcept;
  762. /*!
  763. * Set the plugin's patchbay nodeId.
  764. * @see getPatchbayNodeId()
  765. */
  766. void setPatchbayNodeId(uint32_t nodeId) noexcept;
  767. // -------------------------------------------------------------------
  768. // Plugin initializers
  769. /*!
  770. * Get a plugin's binary type.
  771. * This is always BINARY_NATIVE unless the plugin is a bridge.
  772. */
  773. virtual BinaryType getBinaryType() const noexcept
  774. {
  775. return BINARY_NATIVE;
  776. }
  777. /*!
  778. * Handy function required by CarlaEngine::clonePlugin().
  779. */
  780. virtual const void* getExtraStuff() const noexcept
  781. {
  782. return nullptr;
  783. }
  784. #ifndef DOXYGEN
  785. struct Initializer {
  786. CarlaEngine* const engine;
  787. const uint id;
  788. const char* const filename;
  789. const char* const name;
  790. const char* const label;
  791. const int64_t uniqueId;
  792. const uint options; // see PluginOptions
  793. };
  794. static CarlaPluginPtr newNative(const Initializer& init);
  795. static CarlaPluginPtr newBridge(const Initializer& init,
  796. BinaryType btype, PluginType ptype, const char* bridgeBinary);
  797. static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
  798. static CarlaPluginPtr newDSSI(const Initializer& init);
  799. static CarlaPluginPtr newLV2(const Initializer& init);
  800. static CarlaPluginPtr newVST2(const Initializer& init);
  801. static CarlaPluginPtr newVST3(const Initializer& init);
  802. static CarlaPluginPtr newAU(const Initializer& init);
  803. static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
  804. static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
  805. static CarlaPluginPtr newSFZero(const Initializer& init);
  806. static CarlaPluginPtr 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. * Allow engine to signal that plugin will be deleted soon.
  826. */
  827. virtual void prepareForDeletion() noexcept;
  828. /*!
  829. * Give plugin bridges a change to update their custom data sets.
  830. */
  831. virtual void waitForBridgeSaveSignal() noexcept;
  832. // -------------------------------------------------------------------
  833. // Helper classes
  834. /*!
  835. * Fully disable plugin in scope and also its engine client.
  836. * May wait-block on constructor for plugin process to end.
  837. */
  838. class ScopedDisabler
  839. {
  840. public:
  841. ScopedDisabler(CarlaPlugin* plugin) noexcept;
  842. ~ScopedDisabler() noexcept;
  843. private:
  844. CarlaPlugin* const fPlugin;
  845. bool fWasEnabled;
  846. CARLA_PREVENT_HEAP_ALLOCATION
  847. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  848. };
  849. /*!
  850. * Lock the plugin's own run/process call.
  851. * Plugin will still work as normal, but output only silence.
  852. * On destructor needsReset flag might be set if the plugin might have missed some events.
  853. */
  854. class ScopedSingleProcessLocker
  855. {
  856. public:
  857. ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
  858. ~ScopedSingleProcessLocker() noexcept;
  859. private:
  860. CarlaPlugin* const fPlugin;
  861. const bool fBlock;
  862. CARLA_PREVENT_HEAP_ALLOCATION
  863. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  864. };
  865. friend class CarlaEngine;
  866. friend class CarlaEngineBridge;
  867. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  868. };
  869. /**@}*/
  870. // -----------------------------------------------------------------------
  871. CARLA_BACKEND_END_NAMESPACE
  872. #endif // CARLA_PLUGIN_HPP_INCLUDED