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.

969 lines
28KB

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