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.

1054 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,
  514. bool sendOsc, bool sendCallback, bool reconfigureNow) noexcept;
  515. /*!
  516. * Set parameter's @a parameterId mapped range to @a minimum and @a maximum.
  517. */
  518. virtual void setParameterMappedRange(uint32_t parameterId, float minimum, float maximum,
  519. bool sendOsc, bool sendCallback) noexcept;
  520. /*!
  521. * Add a custom data set.
  522. * If @a key already exists, its current value will be swapped with @a value.
  523. *
  524. * @param type Type of data used in @a value.
  525. * @param key A key identifying this data set.
  526. * @param value The value of the data set, of type @a type.
  527. * @param sendGui Send message change to plugin's custom GUI, if any
  528. *
  529. * @see getCustomDataCount() and getCustomData()
  530. */
  531. virtual void setCustomData(const char* type, const char* key, const char* value, bool sendGui);
  532. /*!
  533. * Set the complete chunk data as @a data.
  534. *
  535. * @see getChunkData()
  536. *
  537. * @note Make sure to verify the plugin supports chunks before calling this function
  538. */
  539. virtual void setChunkData(const void* data, std::size_t dataSize);
  540. /*!
  541. * Change the current plugin program to @a index.
  542. *
  543. * If @a index is negative the plugin's program will be considered unset.
  544. * The plugin's default parameter values will be updated when this function is called.
  545. *
  546. * @param index New program index to use
  547. * @param sendGui Send message change to plugin's custom GUI, if any
  548. * @param sendOsc Send message change over OSC
  549. * @param sendCallback Send message change to registered callback
  550. */
  551. virtual void setProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  552. /*!
  553. * Change the current MIDI plugin program to @a index.
  554. *
  555. * If @a index is negative the plugin's program will be considered unset.
  556. * The plugin's default parameter values will be updated when this function is called.
  557. *
  558. * @param index New program index to use
  559. * @param sendGui Send message change to plugin's custom GUI, if any
  560. * @param sendOsc Send message change over OSC
  561. * @param sendCallback Send message change to registered callback
  562. */
  563. virtual void setMidiProgram(int32_t index, bool sendGui, bool sendOsc, bool sendCallback, bool doingInit = false) noexcept;
  564. /*!
  565. * This is an overloaded call to setMidiProgram().
  566. * It changes the current MIDI program using @a bank and @a program values instead of index.
  567. */
  568. void setMidiProgramById(uint32_t bank, uint32_t program, bool sendGui, bool sendOsc, bool sendCallback) noexcept;
  569. /*!
  570. * Overloaded functions, to be called from within RT context only.
  571. */
  572. virtual void setProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  573. virtual void setMidiProgramRT(uint32_t index, bool sendCallbackLater) noexcept;
  574. // -------------------------------------------------------------------
  575. // Plugin state
  576. /*!
  577. * Reload the plugin's entire state (including programs).
  578. * The plugin will be disabled during this call.
  579. */
  580. virtual void reload() = 0;
  581. /*!
  582. * Reload the plugin's programs state.
  583. */
  584. virtual void reloadPrograms(bool doInit);
  585. // -------------------------------------------------------------------
  586. // Plugin processing
  587. protected:
  588. /*!
  589. * Plugin activate call.
  590. */
  591. virtual void activate() noexcept;
  592. /*!
  593. * Plugin activate call.
  594. */
  595. virtual void deactivate() noexcept;
  596. public:
  597. /*!
  598. * Plugin process call.
  599. */
  600. virtual void process(const float* const* audioIn, float** audioOut,
  601. const float* const* cvIn, float** cvOut, uint32_t frames) = 0;
  602. /*!
  603. * Tell the plugin the current buffer size changed.
  604. */
  605. virtual void bufferSizeChanged(uint32_t newBufferSize);
  606. /*!
  607. * Tell the plugin the current sample rate changed.
  608. */
  609. virtual void sampleRateChanged(double newSampleRate);
  610. /*!
  611. * Tell the plugin the current offline mode changed.
  612. */
  613. virtual void offlineModeChanged(bool isOffline);
  614. // -------------------------------------------------------------------
  615. // Misc
  616. /*!
  617. * Idle function (non-UI), called at regular intervals.
  618. * @note: This function is NOT called from the main thread.
  619. */
  620. virtual void idle();
  621. /*!
  622. * Try to lock the plugin's master mutex.
  623. * @param forcedOffline When true, always locks and returns true
  624. */
  625. bool tryLock(bool forcedOffline) noexcept;
  626. /*!
  627. * Unlock the plugin's master mutex.
  628. */
  629. void unlock() noexcept;
  630. // -------------------------------------------------------------------
  631. // Plugin buffers
  632. /*!
  633. * Initialize all RT buffers of the plugin.
  634. */
  635. virtual void initBuffers() const noexcept;
  636. /*!
  637. * Delete and clear all RT buffers.
  638. */
  639. virtual void clearBuffers() noexcept;
  640. // -------------------------------------------------------------------
  641. // OSC stuff
  642. /*!
  643. * Handle an OSC message.
  644. * FIXME
  645. */
  646. virtual void handleOscMessage(const char* method,
  647. int argc,
  648. const void* argv,
  649. const char* types,
  650. lo_message msg);
  651. // -------------------------------------------------------------------
  652. // MIDI events
  653. /*!
  654. * Send a single midi note to be processed in the next audio callback.
  655. * A note with 0 velocity means note-off.
  656. * @note Non-RT call
  657. */
  658. void sendMidiSingleNote(uint8_t channel, uint8_t note, uint8_t velo,
  659. bool sendGui, bool sendOsc, bool sendCallback);
  660. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  661. /*!
  662. * Send all midi notes off to the host callback.
  663. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead (IFF ctrlChannel is valid).
  664. * @note RT call
  665. */
  666. void postponeRtAllNotesOff();
  667. #endif
  668. // -------------------------------------------------------------------
  669. // UI Stuff
  670. /*!
  671. * Set a custom title for the plugin UI window created by Carla.
  672. */
  673. virtual void setCustomUITitle(const char* title) noexcept;
  674. /*!
  675. * Show (or hide) the plugin's custom UI according to @a yesNo.
  676. * This function is always called from the main thread.
  677. */
  678. virtual void showCustomUI(bool yesNo);
  679. /*!
  680. * Embed the plugin's custom UI to the system pointer @a ptr.
  681. * This function is always called from the main thread.
  682. * @note This is very experimental and subject to change at this point
  683. */
  684. virtual void* embedCustomUI(void* ptr);
  685. /*!
  686. * UI idle function, called at regular intervals.
  687. * This function is only called from the main thread if PLUGIN_NEEDS_UI_MAIN_THREAD is set.
  688. * @note This function may sometimes be called even if the UI is not visible yet.
  689. */
  690. virtual void uiIdle();
  691. /*!
  692. * Tell the UI a parameter has changed.
  693. * @see uiIdle
  694. */
  695. virtual void uiParameterChange(uint32_t index, float value) noexcept;
  696. /*!
  697. * Tell the UI the current program has changed.
  698. * @see uiIdle
  699. */
  700. virtual void uiProgramChange(uint32_t index) noexcept;
  701. /*!
  702. * Tell the UI the current midi program has changed.
  703. * @see uiIdle
  704. */
  705. virtual void uiMidiProgramChange(uint32_t index) noexcept;
  706. /*!
  707. * Tell the UI a note has been pressed.
  708. * @see uiIdle
  709. */
  710. virtual void uiNoteOn(uint8_t channel, uint8_t note, uint8_t velo) noexcept;
  711. /*!
  712. * Tell the UI a note has been released.
  713. * @see uiIdle
  714. */
  715. virtual void uiNoteOff(uint8_t channel, uint8_t note) noexcept;
  716. // -------------------------------------------------------------------
  717. // Helper functions
  718. /*!
  719. * Get the plugin's engine, as passed in the constructor.
  720. */
  721. CarlaEngine* getEngine() const noexcept;
  722. /*!
  723. * Get the plugin's engine client.
  724. */
  725. CarlaEngineClient* getEngineClient() const noexcept;
  726. /*!
  727. * Get a plugin's audio input port.
  728. */
  729. CarlaEngineAudioPort* getAudioInPort(uint32_t index) const noexcept;
  730. /*!
  731. * Get a plugin's audio output port.
  732. */
  733. CarlaEngineAudioPort* getAudioOutPort(uint32_t index) const noexcept;
  734. /*!
  735. * Get a plugin's CV input port.
  736. */
  737. CarlaEngineCVPort* getCVInPort(uint32_t index) const noexcept;
  738. /*!
  739. * Get a plugin's CV output port.
  740. */
  741. CarlaEngineCVPort* getCVOutPort(uint32_t index) const noexcept;
  742. /*!
  743. * Get the plugin's default event input port.
  744. */
  745. CarlaEngineEventPort* getDefaultEventInPort() const noexcept;
  746. /*!
  747. * Get the plugin's default event output port.
  748. */
  749. CarlaEngineEventPort* getDefaultEventOutPort() const noexcept;
  750. /*!
  751. * Get the plugin's type native handle.
  752. * This will be LADSPA_Handle, LV2_Handle, etc.
  753. */
  754. virtual void* getNativeHandle() const noexcept;
  755. /*!
  756. * Get the plugin's type native descriptor.
  757. * This will be LADSPA_Descriptor, DSSI_Descriptor, LV2_Descriptor, AEffect, etc.
  758. */
  759. virtual const void* getNativeDescriptor() const noexcept;
  760. /*!
  761. * Get the plugin UI bridge process Id.
  762. */
  763. virtual uintptr_t getUiBridgeProcessId() const noexcept;
  764. // -------------------------------------------------------------------
  765. /*!
  766. * Get the plugin's patchbay nodeId.
  767. * @see setPatchbayNodeId()
  768. */
  769. uint32_t getPatchbayNodeId() const noexcept;
  770. /*!
  771. * Set the plugin's patchbay nodeId.
  772. * @see getPatchbayNodeId()
  773. */
  774. void setPatchbayNodeId(uint32_t nodeId) noexcept;
  775. // -------------------------------------------------------------------
  776. // Plugin initializers
  777. /*!
  778. * Get a plugin's binary type.
  779. * This is always BINARY_NATIVE unless the plugin is a bridge.
  780. */
  781. virtual BinaryType getBinaryType() const noexcept
  782. {
  783. return BINARY_NATIVE;
  784. }
  785. /*!
  786. * Handy function required by CarlaEngine::clonePlugin().
  787. */
  788. virtual const void* getExtraStuff() const noexcept
  789. {
  790. return nullptr;
  791. }
  792. #ifndef DOXYGEN
  793. struct Initializer {
  794. CarlaEngine* const engine;
  795. const uint id;
  796. const char* const filename;
  797. const char* const name;
  798. const char* const label;
  799. const int64_t uniqueId;
  800. const uint options; // see PluginOptions
  801. };
  802. static CarlaPluginPtr newNative(const Initializer& init);
  803. static CarlaPluginPtr newBridge(const Initializer& init,
  804. BinaryType btype, PluginType ptype, const char* bridgeBinary);
  805. static CarlaPluginPtr newLADSPA(const Initializer& init, const LADSPA_RDF_Descriptor* rdfDescriptor);
  806. static CarlaPluginPtr newDSSI(const Initializer& init);
  807. static CarlaPluginPtr newLV2(const Initializer& init);
  808. static CarlaPluginPtr newVST2(const Initializer& init);
  809. static CarlaPluginPtr newVST3(const Initializer& init);
  810. static CarlaPluginPtr newAU(const Initializer& init);
  811. static CarlaPluginPtr newJuce(const Initializer& init, const char* format);
  812. static CarlaPluginPtr newFluidSynth(const Initializer& init, PluginType ptype, bool use16Outs);
  813. static CarlaPluginPtr newSFZero(const Initializer& init);
  814. static CarlaPluginPtr newJackApp(const Initializer& init);
  815. #endif
  816. // -------------------------------------------------------------------
  817. protected:
  818. /*!
  819. * Internal data, for CarlaPlugin subclasses only.
  820. */
  821. struct ProtectedData;
  822. ProtectedData* const pData;
  823. // -------------------------------------------------------------------
  824. // Internal helper functions
  825. public:
  826. // FIXME: remove public exception on 2.1 release
  827. /*!
  828. * Call LV2 restore.
  829. */
  830. virtual void restoreLV2State() noexcept;
  831. protected:
  832. /*!
  833. * Allow engine to signal that plugin will be deleted soon.
  834. */
  835. virtual void prepareForDeletion() noexcept;
  836. /*!
  837. * Give plugin bridges a change to update their custom data sets.
  838. */
  839. virtual void waitForBridgeSaveSignal() noexcept;
  840. // -------------------------------------------------------------------
  841. // Helper classes
  842. /*!
  843. * Fully disable plugin in scope and also its engine client.
  844. * May wait-block on constructor for plugin process to end.
  845. */
  846. class ScopedDisabler
  847. {
  848. public:
  849. ScopedDisabler(CarlaPlugin* plugin) noexcept;
  850. ~ScopedDisabler() noexcept;
  851. private:
  852. CarlaPlugin* const fPlugin;
  853. bool fWasEnabled;
  854. CARLA_PREVENT_HEAP_ALLOCATION
  855. CARLA_DECLARE_NON_COPY_CLASS(ScopedDisabler)
  856. };
  857. /*!
  858. * Lock the plugin's own run/process call.
  859. * Plugin will still work as normal, but output only silence.
  860. * On destructor needsReset flag might be set if the plugin might have missed some events.
  861. */
  862. class ScopedSingleProcessLocker
  863. {
  864. public:
  865. ScopedSingleProcessLocker(CarlaPlugin* plugin, bool block) noexcept;
  866. ~ScopedSingleProcessLocker() noexcept;
  867. private:
  868. CarlaPlugin* const fPlugin;
  869. const bool fBlock;
  870. CARLA_PREVENT_HEAP_ALLOCATION
  871. CARLA_DECLARE_NON_COPY_CLASS(ScopedSingleProcessLocker)
  872. };
  873. friend class CarlaEngine;
  874. friend class CarlaEngineBridge;
  875. CARLA_DECLARE_NON_COPY_CLASS(CarlaPlugin)
  876. };
  877. /**@}*/
  878. // -----------------------------------------------------------------------
  879. CARLA_BACKEND_END_NAMESPACE
  880. #endif // CARLA_PLUGIN_HPP_INCLUDED