Collection of tools useful for audio production
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.

995 lines
28KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef CARLA_PLUGIN_HPP
  18. #define CARLA_PLUGIN_HPP
  19. #include "carla_midi.h"
  20. #include "carla_engine.hpp"
  21. #include "carla_osc_utils.hpp"
  22. #ifdef BUILD_BRIDGE
  23. # include "carla_backend_utils.hpp"
  24. # include "carla_bridge_osc.hpp"
  25. #else
  26. # include "carla_plugin_thread.hpp"
  27. #endif
  28. // common includes
  29. #include <cmath>
  30. #include <vector>
  31. #include <QtCore/QMutex>
  32. #ifdef Q_WS_X11
  33. #include <QtGui/QX11EmbedContainer>
  34. typedef QX11EmbedContainer GuiContainer;
  35. #else
  36. #include <QtGui/QWidget>
  37. typedef QWidget GuiContainer;
  38. #endif
  39. typedef struct _PluginDescriptor PluginDescriptor;
  40. CARLA_BACKEND_START_NAMESPACE
  41. /*!
  42. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  43. *
  44. * The Carla Backend Plugin.
  45. * @{
  46. */
  47. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0, nullptr); return; }
  48. const unsigned short MAX_MIDI_EVENTS = 512;
  49. const unsigned short MAX_POST_EVENTS = 152;
  50. #ifndef BUILD_BRIDGE
  51. enum PluginBridgeInfoType {
  52. PluginBridgeAudioCount,
  53. PluginBridgeMidiCount,
  54. PluginBridgeParameterCount,
  55. PluginBridgeProgramCount,
  56. PluginBridgeMidiProgramCount,
  57. PluginBridgePluginInfo,
  58. PluginBridgeParameterInfo,
  59. PluginBridgeParameterData,
  60. PluginBridgeParameterRanges,
  61. PluginBridgeProgramInfo,
  62. PluginBridgeMidiProgramInfo,
  63. PluginBridgeConfigure,
  64. PluginBridgeSetParameterValue,
  65. PluginBridgeSetDefaultValue,
  66. PluginBridgeSetProgram,
  67. PluginBridgeSetMidiProgram,
  68. PluginBridgeSetCustomData,
  69. PluginBridgeSetChunkData,
  70. PluginBridgeUpdateNow,
  71. PluginBridgeError
  72. };
  73. #endif
  74. enum PluginPostEventType {
  75. PluginPostEventNull,
  76. PluginPostEventDebug,
  77. PluginPostEventParameterChange, // param, N, value
  78. PluginPostEventProgramChange, // index
  79. PluginPostEventMidiProgramChange, // index
  80. PluginPostEventNoteOn, // channel, note, velo
  81. PluginPostEventNoteOff, // channel, note
  82. PluginPostEventCustom
  83. };
  84. struct PluginAudioData {
  85. uint32_t count;
  86. uint32_t* rindexes;
  87. CarlaEngineAudioPort** ports;
  88. PluginAudioData()
  89. : count(0),
  90. rindexes(nullptr),
  91. ports(nullptr) {}
  92. };
  93. struct PluginMidiData {
  94. CarlaEngineMidiPort* portMin;
  95. CarlaEngineMidiPort* portMout;
  96. PluginMidiData()
  97. : portMin(nullptr),
  98. portMout(nullptr) {}
  99. };
  100. struct PluginParameterData {
  101. uint32_t count;
  102. ParameterData* data;
  103. ParameterRanges* ranges;
  104. CarlaEngineControlPort* portCin;
  105. CarlaEngineControlPort* portCout;
  106. PluginParameterData()
  107. : count(0),
  108. data(nullptr),
  109. ranges(nullptr),
  110. portCin(nullptr),
  111. portCout(nullptr) {}
  112. };
  113. struct PluginProgramData {
  114. uint32_t count;
  115. int32_t current;
  116. const char** names;
  117. PluginProgramData()
  118. : count(0),
  119. current(-1),
  120. names(nullptr) {}
  121. };
  122. struct PluginMidiProgramData {
  123. uint32_t count;
  124. int32_t current;
  125. MidiProgramData* data;
  126. PluginMidiProgramData()
  127. : count(0),
  128. current(-1),
  129. data(nullptr) {}
  130. };
  131. struct PluginPostEvent {
  132. PluginPostEventType type;
  133. int32_t value1;
  134. int32_t value2;
  135. double value3;
  136. const void* cdata;
  137. PluginPostEvent()
  138. : type(PluginPostEventNull),
  139. value1(-1),
  140. value2(-1),
  141. value3(0.0),
  142. cdata(nullptr) {}
  143. };
  144. struct ExternalMidiNote {
  145. int8_t channel; // invalid = -1
  146. uint8_t note;
  147. uint8_t velo;
  148. ExternalMidiNote()
  149. : channel(-1),
  150. note(0),
  151. velo(0) {}
  152. };
  153. /*!
  154. * \class CarlaPlugin
  155. *
  156. * \brief Carla Backend base plugin class
  157. *
  158. * This is the base class for all available plugin types available in Carla Backend.\n
  159. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  160. *
  161. * \see PluginType
  162. */
  163. class CarlaPlugin
  164. {
  165. public:
  166. /*!
  167. * This is the constructor of the base plugin class.
  168. *
  169. * \param engine The engine which this plugin belongs to, must not be null
  170. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  171. */
  172. CarlaPlugin(CarlaEngine* const engine, const unsigned short id);
  173. /*!
  174. * This is the de-constructor of the base plugin class.
  175. */
  176. virtual ~CarlaPlugin();
  177. // -------------------------------------------------------------------
  178. // Information (base)
  179. /*!
  180. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  181. *
  182. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  183. * To check if a plugin is a bridge use:
  184. * \code
  185. * if (m_hints & PLUGIN_IS_BRIDGE)
  186. * ...
  187. * \endcode
  188. */
  189. PluginType type() const;
  190. /*!
  191. * Get the plugin's id (as passed in the constructor).
  192. *
  193. * \see setId()
  194. */
  195. unsigned short id() const;
  196. /*!
  197. * Get the plugin's hints.
  198. *
  199. * \see PluginHints
  200. */
  201. unsigned int hints() const;
  202. /*!
  203. * Check if the plugin is enabled.
  204. *
  205. * \see setEnabled()
  206. */
  207. bool enabled() const;
  208. /*!
  209. * Get the plugin's internal name.\n
  210. * This name is unique within all plugins in an engine.
  211. *
  212. * \see getRealName()
  213. */
  214. const char* name() const;
  215. /*!
  216. * Get the currently loaded DLL filename for this plugin.\n
  217. * (Sound kits return their exact filename).
  218. */
  219. const char* filename() const;
  220. /*!
  221. * Get the plugin's category (delay, filter, synth, etc).
  222. */
  223. virtual PluginCategory category();
  224. /*!
  225. * Get the plugin's native unique Id.\n
  226. * May return 0 on plugin types that don't support Ids.
  227. */
  228. virtual long uniqueId();
  229. // -------------------------------------------------------------------
  230. // Information (count)
  231. /*!
  232. * Get the number of audio inputs.
  233. */
  234. virtual uint32_t audioInCount();
  235. /*!
  236. * Get the number of audio outputs.
  237. */
  238. virtual uint32_t audioOutCount();
  239. /*!
  240. * Get the number of MIDI inputs.
  241. */
  242. virtual uint32_t midiInCount();
  243. /*!
  244. * Get the number of MIDI outputs.
  245. */
  246. virtual uint32_t midiOutCount();
  247. /*!
  248. * Get the number of parameters.\n
  249. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  250. */
  251. uint32_t parameterCount() const;
  252. /*!
  253. * Get the number of scalepoints for parameter \a parameterId.
  254. */
  255. virtual uint32_t parameterScalePointCount(const uint32_t parameterId);
  256. /*!
  257. * Get the number of programs.
  258. */
  259. uint32_t programCount() const;
  260. /*!
  261. * Get the number of MIDI programs.
  262. */
  263. uint32_t midiProgramCount() const;
  264. /*!
  265. * Get the number of custom data sets.
  266. */
  267. size_t customDataCount() const;
  268. // -------------------------------------------------------------------
  269. // Information (current data)
  270. /*!
  271. * Get the current program number (-1 if unset).
  272. *
  273. * \see setProgram()
  274. */
  275. int32_t currentProgram() const;
  276. /*!
  277. * Get the current MIDI program number (-1 if unset).
  278. *
  279. * \see setMidiProgram()
  280. * \see setMidiProgramById()
  281. */
  282. int32_t currentMidiProgram() const;
  283. /*!
  284. * Get the parameter data of \a parameterId.
  285. */
  286. const ParameterData* parameterData(const uint32_t parameterId) const;
  287. /*!
  288. * Get the parameter ranges of \a parameterId.
  289. */
  290. const ParameterRanges* parameterRanges(const uint32_t parameterId) const;
  291. /*!
  292. * Check if parameter \a parameterId is of output type.
  293. */
  294. bool parameterIsOutput(const uint32_t parameterId) const;
  295. /*!
  296. * Get the MIDI program at \a index.
  297. *
  298. * \see getMidiProgramName()
  299. */
  300. const MidiProgramData* midiProgramData(const uint32_t index) const;
  301. /*!
  302. * Get the custom data set at \a index.
  303. *
  304. * \see setCustomData()
  305. */
  306. const CustomData* customData(const size_t index) const;
  307. /*!
  308. * Get the complete plugin chunk data into \a dataPtr.
  309. *
  310. * \return The size of the chunk or 0 if invalid.
  311. *
  312. * \note Make sure to verify the plugin supports chunks before calling this function!
  313. *
  314. * \see setChunkData()
  315. */
  316. virtual int32_t chunkData(void** const dataPtr);
  317. // -------------------------------------------------------------------
  318. // Information (per-plugin data)
  319. /*!
  320. * Get the current parameter value of \a parameterId.
  321. */
  322. virtual double getParameterValue(const uint32_t parameterId);
  323. /*!
  324. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  325. */
  326. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  327. /*!
  328. * Get the plugin's label (URI for PLUGIN_LV2).
  329. */
  330. virtual void getLabel(char* const strBuf);
  331. /*!
  332. * Get the plugin's maker.
  333. */
  334. virtual void getMaker(char* const strBuf);
  335. /*!
  336. * Get the plugin's copyright/license.
  337. */
  338. virtual void getCopyright(char* const strBuf);
  339. /*!
  340. * Get the plugin's (real) name.
  341. *
  342. * \see name()
  343. */
  344. virtual void getRealName(char* const strBuf);
  345. /*!
  346. * Get the name of the parameter \a parameterId.
  347. */
  348. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  349. /*!
  350. * Get the symbol of the parameter \a parameterId.
  351. */
  352. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  353. /*!
  354. * Get the custom text of the parameter \a parameterId.
  355. */
  356. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  357. /*!
  358. * Get the unit of the parameter \a parameterId.
  359. */
  360. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  361. /*!
  362. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  363. */
  364. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  365. /*!
  366. * Get the name of the program at \a index.
  367. */
  368. void getProgramName(const uint32_t index, char* const strBuf);
  369. /*!
  370. * Get the name of the MIDI program at \a index.
  371. *
  372. * \see getMidiProgramInfo()
  373. */
  374. void getMidiProgramName(const uint32_t index, char* const strBuf);
  375. /*!
  376. * Get information about the plugin's parameter count.\n
  377. * This is used to check how many input, output and total parameters are available.\n
  378. *
  379. * \note Some parameters might not be input or output (ie, invalid).
  380. *
  381. * \see parameterCount()
  382. */
  383. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  384. /*!
  385. * Get information about the plugin's custom GUI, if provided.
  386. */
  387. virtual void getGuiInfo(GuiType* const type, bool* const resizable);
  388. // -------------------------------------------------------------------
  389. // Set data (internal stuff)
  390. #ifndef BUILD_BRIDGE
  391. /*!
  392. * Set the plugin's id to \a id.
  393. *
  394. * \see id()
  395. */
  396. void setId(const unsigned short id);
  397. #endif
  398. /*!
  399. * Enable or disable the plugin according to \a yesNo.
  400. *
  401. * When a plugin is disabled, it will never be processed or managed in any way.\n
  402. * To 'bypass' a plugin use setActive() instead.
  403. *
  404. * \see enabled()
  405. */
  406. void setEnabled(const bool yesNo);
  407. /*!
  408. * Set plugin as active according to \a active.
  409. *
  410. * \param sendOsc Send message change over OSC
  411. * \param sendCallback Send message change to registered callback
  412. */
  413. void setActive(const bool active, const bool sendOsc, const bool sendCallback);
  414. /*!
  415. * Set the plugin's dry/wet signal value to \a value.\n
  416. * \a value must be between 0.0 and 1.0.
  417. *
  418. * \param sendOsc Send message change over OSC
  419. * \param sendCallback Send message change to registered callback
  420. */
  421. void setDryWet(double value, const bool sendOsc, const bool sendCallback);
  422. /*!
  423. * Set the plugin's output volume to \a value.\n
  424. * \a value must be between 0.0 and 1.27.
  425. *
  426. * \param sendOsc Send message change over OSC
  427. * \param sendCallback Send message change to registered callback
  428. */
  429. void setVolume(double value, const bool sendOsc, const bool sendCallback);
  430. /*!
  431. * Set the plugin's output left balance value to \a value.\n
  432. * \a value must be between -1.0 and 1.0.
  433. *
  434. * \param sendOsc Send message change over OSC
  435. * \param sendCallback Send message change to registered callback
  436. */
  437. void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback);
  438. /*!
  439. * Set the plugin's output right balance value to \a value.\n
  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. void setBalanceRight(double value, const bool sendOsc, const bool sendCallback);
  446. #ifndef BUILD_BRIDGE
  447. /*!
  448. * BridgePlugin call used to set internal data.
  449. */
  450. virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types);
  451. #endif
  452. // -------------------------------------------------------------------
  453. // Set data (plugin-specific stuff)
  454. /*!
  455. * Set a plugin's parameter value.
  456. *
  457. * \param parameterId The parameter to change
  458. * \param value The new parameter value, must be within the parameter's range
  459. * \param sendGui Send message change to plugin's custom GUI, if any
  460. * \param sendOsc Send message change over OSC
  461. * \param sendCallback Send message change to registered callback
  462. *
  463. * \see getParameterValue()
  464. */
  465. virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  466. /*!
  467. * Set a plugin's parameter value, including internal parameters.\n
  468. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  469. *
  470. * \see setParameterValue()
  471. * \see setActive()
  472. * \see setDryWet()
  473. * \see setVolume()
  474. * \see setBalanceLeft()
  475. * \see setBalanceRight()
  476. */
  477. void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback);
  478. /*!
  479. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  480. * \a channel must be between 0 and 15.
  481. */
  482. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback);
  483. /*!
  484. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  485. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  486. */
  487. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback);
  488. /*!
  489. * Add a custom data set.\n
  490. * If \a key already exists, its current value will be swapped with \a value.
  491. *
  492. * \param type Type of data used in \a value.
  493. * \param key A key identifing this data set.
  494. * \param value The value of the data set, of type \a type.
  495. * \param sendGui Send message change to plugin's custom GUI, if any
  496. *
  497. * \see customData()
  498. */
  499. virtual void setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui);
  500. /*!
  501. * Set the complete chunk data as \a stringData.\n
  502. * \a stringData must a base64 encoded string of binary data.
  503. *
  504. * \see chunkData()
  505. *
  506. * \note Make sure to verify the plugin supports chunks before calling this function!
  507. */
  508. virtual void setChunkData(const char* const stringData);
  509. /*!
  510. * Change the current plugin program to \a index.
  511. *
  512. * If \a index is negative the plugin's program will be considered unset.\n
  513. * The plugin's default parameter values will be updated when this function is called.
  514. *
  515. * \param index New program index to use
  516. * \param sendGui Send message change to plugin's custom GUI, if any
  517. * \param sendOsc Send message change over OSC
  518. * \param sendCallback Send message change to registered callback
  519. * \param block Block the audio callback
  520. */
  521. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  522. /*!
  523. * Change the current MIDI plugin program to \a index.
  524. *
  525. * If \a index is negative the plugin's program will be considered unset.\n
  526. * The plugin's default parameter values will be updated when this function is called.
  527. *
  528. * \param index New program index to use
  529. * \param sendGui Send message change to plugin's custom GUI, if any
  530. * \param sendOsc Send message change over OSC
  531. * \param sendCallback Send message change to registered callback
  532. * \param block Block the audio callback
  533. */
  534. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  535. /*!
  536. * This is an overloaded call to setMidiProgram().\n
  537. * It changes the current MIDI program using \a bank and \a program values instead of index.
  538. */
  539. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block);
  540. // -------------------------------------------------------------------
  541. // Set gui stuff
  542. /*!
  543. * Set the plugin's custom GUI container.\n
  544. *
  545. * \note This function must be always called from the main thread.
  546. */
  547. virtual void setGuiContainer(GuiContainer* const container);
  548. /*!
  549. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  550. *
  551. * \note This function must be always called from the main thread.
  552. */
  553. virtual void showGui(const bool yesNo);
  554. /*!
  555. * Idle the plugin's custom GUI.
  556. *
  557. * \note This function must be always called from the main thread.
  558. */
  559. virtual void idleGui();
  560. // -------------------------------------------------------------------
  561. // Plugin state
  562. /*!
  563. * Reload the plugin's entire state (including programs).\n
  564. * The plugin will be disabled during this call.
  565. */
  566. virtual void reload();
  567. /*!
  568. * Reload the plugin's programs state.
  569. */
  570. virtual void reloadPrograms(const bool init);
  571. /*!
  572. * Tell the plugin to prepare for save.
  573. */
  574. virtual void prepareForSave();
  575. // -------------------------------------------------------------------
  576. // Plugin processing
  577. /*!
  578. * Plugin process callback.
  579. */
  580. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset = 0);
  581. /*!
  582. * Tell the plugin the current buffer size has changed.
  583. */
  584. virtual void bufferSizeChanged(const uint32_t newBufferSize);
  585. /*!
  586. * Recreate latency audio buffers.
  587. */
  588. void recreateLatencyBuffers();
  589. // -------------------------------------------------------------------
  590. // OSC stuff
  591. /*!
  592. * Register this plugin to the engine's OSC controller.
  593. */
  594. void registerToOscControl();
  595. #ifndef BUILD_BRIDGE
  596. /*!
  597. * Update the plugin's internal OSC data according to \a source and \a url.\n
  598. * This is used for OSC-GUI bridges.
  599. */
  600. void updateOscData(const lo_address source, const char* const url);
  601. /*!
  602. * Free the plugin's internal OSC memory data.
  603. */
  604. void freeOscData();
  605. /*!
  606. * Show the plugin's OSC based GUI.\n
  607. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  608. */
  609. bool waitForOscGuiShow();
  610. #endif
  611. // -------------------------------------------------------------------
  612. // MIDI events
  613. /*!
  614. * Send a single midi note to be processed in the next audio callback.\n
  615. * A note with 0 velocity means note-off.
  616. */
  617. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback);
  618. /*!
  619. * Send all midi notes off for the next audio callback.\n
  620. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead.
  621. */
  622. void sendMidiAllNotesOff();
  623. // -------------------------------------------------------------------
  624. // Post-poned events
  625. /*!
  626. * Post pone an event of type \a type.\n
  627. * The event will be processed later, but as soon as possible.
  628. */
  629. void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr);
  630. /*!
  631. * Process all the post-poned events.
  632. * This function must be called from the main thread (ie, idleGui()) if PLUGIN_USES_SINGLE_THREAD is set.
  633. */
  634. void postEventsRun();
  635. /*!
  636. * Handle custom post event.\n
  637. * Implementation depends on plugin type.
  638. */
  639. virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata);
  640. /*!
  641. * Tell the UI a parameter has changed.
  642. */
  643. virtual void uiParameterChange(const uint32_t index, const double value);
  644. /*!
  645. * Tell the UI the current program has changed.
  646. */
  647. virtual void uiProgramChange(const uint32_t index);
  648. /*!
  649. * Tell the UI the current midi program has changed.
  650. */
  651. virtual void uiMidiProgramChange(const uint32_t index);
  652. /*!
  653. * Tell the UI a note has been pressed.
  654. */
  655. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo);
  656. /*!
  657. * Tell the UI a note has been released.
  658. */
  659. virtual void uiNoteOff(const uint8_t channel, const uint8_t note);
  660. // -------------------------------------------------------------------
  661. // Cleanup
  662. /*!
  663. * Clear the engine client ports of the plugin.
  664. */
  665. virtual void removeClientPorts();
  666. /*!
  667. * Initialize all RT buffers of the plugin.
  668. */
  669. virtual void initBuffers();
  670. /*!
  671. * Delete all temporary buffers of the plugin.
  672. */
  673. virtual void deleteBuffers();
  674. // -------------------------------------------------------------------
  675. // Library functions
  676. /*!
  677. * Open the DLL \a filename.
  678. */
  679. bool libOpen(const char* const filename);
  680. /*!
  681. * Close the DLL previously loaded in libOpen().
  682. */
  683. bool libClose();
  684. /*!
  685. * Get the symbol entry \a symbol of the currently loaded DLL.
  686. */
  687. void* libSymbol(const char* const symbol);
  688. /*!
  689. * Get the last DLL related error.
  690. */
  691. const char* libError(const char* const filename);
  692. // -------------------------------------------------------------------
  693. // Locks
  694. void engineProcessLock();
  695. void engineProcessUnlock();
  696. void engineMidiLock();
  697. void engineMidiUnlock();
  698. // -------------------------------------------------------------------
  699. // Plugin initializers
  700. struct initializer {
  701. CarlaEngine* const engine;
  702. const char* const filename;
  703. const char* const name;
  704. const char* const label;
  705. };
  706. static CarlaPlugin* newNative(const initializer& init);
  707. static CarlaPlugin* newLADSPA(const initializer& init, const void* const extra);
  708. static CarlaPlugin* newDSSI(const initializer& init, const void* const extra);
  709. static CarlaPlugin* newLV2(const initializer& init);
  710. static CarlaPlugin* newVST(const initializer& init);
  711. static CarlaPlugin* newGIG(const initializer& init);
  712. static CarlaPlugin* newSF2(const initializer& init);
  713. static CarlaPlugin* newSFZ(const initializer& init);
  714. //#ifndef BUILD_BRIDGE
  715. static CarlaPlugin* newBridge(const initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra);
  716. //#endif
  717. static size_t getNativePluginCount();
  718. static const PluginDescriptor* getNativePluginDescriptor(const size_t index);
  719. // -------------------------------------------------------------------
  720. /*!
  721. * \class ScopedDisabler
  722. *
  723. * \brief Carla plugin scoped disabler
  724. *
  725. * This is a handy class that temporarily disables a plugin during a function scope.\n
  726. * It should be used when the plugin needs reload or state change, something like this:
  727. * \code
  728. * {
  729. * const CarlaPlugin::ScopedDisabler m(plugin);
  730. * plugin->setChunkData(data);
  731. * }
  732. * \endcode
  733. */
  734. class ScopedDisabler
  735. {
  736. public:
  737. /*!
  738. * Disable plugin \a plugin if \a disable is true.
  739. * The plugin is re-enabled in the deconstructor of this class if \a disable is true.
  740. *
  741. * \param plugin The plugin to disable
  742. * \param disable Wherever to disable the plugin or not, true by default
  743. */
  744. ScopedDisabler(CarlaPlugin* const plugin, const bool disable = true)
  745. : m_plugin(plugin),
  746. m_disable(disable)
  747. {
  748. if (m_disable)
  749. {
  750. m_plugin->engineProcessLock();
  751. m_plugin->setEnabled(false);
  752. m_plugin->engineProcessUnlock();
  753. }
  754. }
  755. ~ScopedDisabler()
  756. {
  757. if (m_disable)
  758. {
  759. m_plugin->engineProcessLock();
  760. m_plugin->setEnabled(true);
  761. m_plugin->engineProcessUnlock();
  762. }
  763. }
  764. private:
  765. CarlaPlugin* const m_plugin;
  766. const bool m_disable;
  767. };
  768. // -------------------------------------------------------------------
  769. protected:
  770. unsigned short m_id;
  771. CarlaEngine* const x_engine;
  772. CarlaEngineClient* x_client;
  773. double x_dryWet, x_volume;
  774. double x_balanceLeft, x_balanceRight;
  775. PluginType m_type;
  776. unsigned int m_hints;
  777. bool m_active;
  778. bool m_activeBefore;
  779. bool m_enabled;
  780. void* m_lib;
  781. const char* m_name;
  782. const char* m_filename;
  783. // options
  784. int8_t m_ctrlInChannel;
  785. bool m_fixedBufferSize;
  786. bool m_processHighPrecision;
  787. // latency
  788. uint32_t m_latency;
  789. float** m_latencyBuffers;
  790. // -------------------------------------------------------------------
  791. // Storage Data
  792. PluginAudioData aIn;
  793. PluginAudioData aOut;
  794. PluginMidiData midi;
  795. PluginParameterData param;
  796. PluginProgramData prog;
  797. PluginMidiProgramData midiprog;
  798. std::vector<CustomData> custom;
  799. // -------------------------------------------------------------------
  800. // Extra
  801. #ifndef BUILD_BRIDGE
  802. struct {
  803. CarlaOscData data;
  804. CarlaPluginThread* thread;
  805. } osc;
  806. #endif
  807. struct {
  808. QMutex mutex;
  809. PluginPostEvent data[MAX_POST_EVENTS];
  810. } postEvents;
  811. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  812. // -------------------------------------------------------------------
  813. // Utilities
  814. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  815. {
  816. if (value < ranges.min)
  817. value = ranges.min;
  818. else if (value > ranges.max)
  819. value = ranges.max;
  820. return value;
  821. }
  822. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  823. {
  824. if (value < ranges.min)
  825. value = ranges.min;
  826. else if (value > ranges.max)
  827. value = ranges.max;
  828. return value;
  829. }
  830. friend class CarlaEngine; // FIXME
  831. friend class CarlaEngineJack;
  832. };
  833. /**@}*/
  834. CARLA_BACKEND_END_NAMESPACE
  835. #endif // CARLA_PLUGIN_HPP