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.

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