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.

1074 lines
29KB

  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.hpp"
  25. #endif
  26. // common includes
  27. #include <cmath>
  28. #include <vector>
  29. #include <QtCore/QMutex>
  30. #include <QtGui/QMainWindow>
  31. #ifdef Q_WS_X11
  32. # include <QtGui/QX11EmbedContainer>
  33. typedef QX11EmbedContainer GuiContainer;
  34. #else
  35. # include <QtGui/QWidget>
  36. typedef QWidget GuiContainer;
  37. #endif
  38. typedef struct _PluginDescriptor PluginDescriptor;
  39. CARLA_BACKEND_START_NAMESPACE
  40. /*!
  41. * @defgroup CarlaBackendPlugin Carla Backend Plugin
  42. *
  43. * The Carla Backend Plugin.
  44. * @{
  45. */
  46. #define CARLA_PROCESS_CONTINUE_CHECK if (! m_enabled) { x_engine->callback(CALLBACK_DEBUG, m_id, m_enabled, 0, 0.0, nullptr); return; }
  47. const unsigned short MAX_MIDI_EVENTS = 512;
  48. const unsigned short MAX_POST_EVENTS = 152;
  49. #ifndef BUILD_BRIDGE
  50. enum PluginBridgeInfoType {
  51. PluginBridgeAudioCount,
  52. PluginBridgeMidiCount,
  53. PluginBridgeParameterCount,
  54. PluginBridgeProgramCount,
  55. PluginBridgeMidiProgramCount,
  56. PluginBridgePluginInfo,
  57. PluginBridgeParameterInfo,
  58. PluginBridgeParameterData,
  59. PluginBridgeParameterRanges,
  60. PluginBridgeProgramInfo,
  61. PluginBridgeMidiProgramInfo,
  62. PluginBridgeConfigure,
  63. PluginBridgeSetParameterValue,
  64. PluginBridgeSetDefaultValue,
  65. PluginBridgeSetProgram,
  66. PluginBridgeSetMidiProgram,
  67. PluginBridgeSetCustomData,
  68. PluginBridgeSetChunkData,
  69. PluginBridgeUpdateNow,
  70. PluginBridgeError
  71. };
  72. #endif
  73. enum PluginPostEventType {
  74. PluginPostEventNull,
  75. PluginPostEventDebug,
  76. PluginPostEventParameterChange, // param, N, value
  77. PluginPostEventProgramChange, // index
  78. PluginPostEventMidiProgramChange, // index
  79. PluginPostEventNoteOn, // channel, note, velo
  80. PluginPostEventNoteOff, // channel, note
  81. PluginPostEventCustom
  82. };
  83. struct PluginAudioData {
  84. uint32_t count;
  85. uint32_t* rindexes;
  86. CarlaEngineAudioPort** ports;
  87. PluginAudioData()
  88. : count(0),
  89. rindexes(nullptr),
  90. ports(nullptr) {}
  91. };
  92. struct PluginMidiData {
  93. CarlaEngineMidiPort* portMin;
  94. CarlaEngineMidiPort* portMout;
  95. PluginMidiData()
  96. : portMin(nullptr),
  97. portMout(nullptr) {}
  98. };
  99. struct PluginParameterData {
  100. uint32_t count;
  101. ParameterData* data;
  102. ParameterRanges* ranges;
  103. CarlaEngineControlPort* portCin;
  104. CarlaEngineControlPort* portCout;
  105. PluginParameterData()
  106. : count(0),
  107. data(nullptr),
  108. ranges(nullptr),
  109. portCin(nullptr),
  110. portCout(nullptr) {}
  111. };
  112. struct PluginProgramData {
  113. uint32_t count;
  114. int32_t current;
  115. const char** names;
  116. PluginProgramData()
  117. : count(0),
  118. current(-1),
  119. names(nullptr) {}
  120. };
  121. struct PluginMidiProgramData {
  122. uint32_t count;
  123. int32_t current;
  124. MidiProgramData* data;
  125. PluginMidiProgramData()
  126. : count(0),
  127. current(-1),
  128. data(nullptr) {}
  129. };
  130. struct PluginPostEvent {
  131. PluginPostEventType type;
  132. int32_t value1;
  133. int32_t value2;
  134. double value3;
  135. const void* cdata;
  136. PluginPostEvent()
  137. : type(PluginPostEventNull),
  138. value1(-1),
  139. value2(-1),
  140. value3(0.0),
  141. cdata(nullptr) {}
  142. };
  143. struct ExternalMidiNote {
  144. int8_t channel; // invalid = -1
  145. uint8_t note;
  146. uint8_t velo;
  147. ExternalMidiNote()
  148. : channel(-1),
  149. note(0),
  150. velo(0) {}
  151. };
  152. /*!
  153. * \class CarlaPlugin
  154. *
  155. * \brief Carla Backend base plugin class
  156. *
  157. * This is the base class for all available plugin types available in Carla Backend.\n
  158. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  159. *
  160. * \see PluginType
  161. */
  162. class CarlaPlugin
  163. {
  164. public:
  165. /*!
  166. * This is the constructor of the base plugin class.
  167. *
  168. * \param engine The engine which this plugin belongs to, must not be null
  169. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  170. */
  171. CarlaPlugin(CarlaEngine* const engine, const unsigned short id);
  172. /*!
  173. * This is the de-constructor of the base plugin class.
  174. */
  175. virtual ~CarlaPlugin();
  176. // -------------------------------------------------------------------
  177. // Information (base)
  178. /*!
  179. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  180. *
  181. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  182. * To check if a plugin is a bridge use:
  183. * \code
  184. * if (m_hints & PLUGIN_IS_BRIDGE)
  185. * ...
  186. * \endcode
  187. */
  188. PluginType type() const;
  189. /*!
  190. * Get the plugin's id (as passed in the constructor).
  191. *
  192. * \see setId()
  193. */
  194. unsigned short id() const;
  195. /*!
  196. * Get the plugin's hints.
  197. *
  198. * \see PluginHints
  199. */
  200. unsigned int hints() const;
  201. /*!
  202. * Check if the plugin is enabled.
  203. *
  204. * \see setEnabled()
  205. */
  206. bool enabled() const;
  207. /*!
  208. * Get the plugin's internal name.\n
  209. * This name is unique within all plugins in an engine.
  210. *
  211. * \see getRealName()
  212. */
  213. const char* name() const;
  214. /*!
  215. * Get the currently loaded DLL filename for this plugin.\n
  216. * (Sound kits return their exact filename).
  217. */
  218. const char* filename() const;
  219. /*!
  220. * Get the plugin's category (delay, filter, synth, etc).
  221. */
  222. virtual PluginCategory category();
  223. /*!
  224. * Get the plugin's native unique Id.\n
  225. * May return 0 on plugin types that don't support Ids.
  226. */
  227. virtual long uniqueId();
  228. // -------------------------------------------------------------------
  229. // Information (count)
  230. /*!
  231. * Get the number of audio inputs.
  232. */
  233. virtual uint32_t audioInCount();
  234. /*!
  235. * Get the number of audio outputs.
  236. */
  237. virtual uint32_t audioOutCount();
  238. /*!
  239. * Get the number of MIDI inputs.
  240. */
  241. virtual uint32_t midiInCount();
  242. /*!
  243. * Get the number of MIDI outputs.
  244. */
  245. virtual uint32_t midiOutCount();
  246. /*!
  247. * Get the number of parameters.\n
  248. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  249. */
  250. uint32_t parameterCount() const;
  251. /*!
  252. * Get the number of scalepoints for parameter \a parameterId.
  253. */
  254. virtual uint32_t parameterScalePointCount(const uint32_t parameterId);
  255. /*!
  256. * Get the number of programs.
  257. */
  258. uint32_t programCount() const;
  259. /*!
  260. * Get the number of MIDI programs.
  261. */
  262. uint32_t midiProgramCount() const;
  263. /*!
  264. * Get the number of custom data sets.
  265. */
  266. size_t customDataCount() const;
  267. // -------------------------------------------------------------------
  268. // Information (current data)
  269. /*!
  270. * Get the current program number (-1 if unset).
  271. *
  272. * \see setProgram()
  273. */
  274. int32_t currentProgram() const;
  275. /*!
  276. * Get the current MIDI program number (-1 if unset).
  277. *
  278. * \see setMidiProgram()
  279. * \see setMidiProgramById()
  280. */
  281. int32_t currentMidiProgram() const;
  282. /*!
  283. * Get the parameter data of \a parameterId.
  284. */
  285. const ParameterData* parameterData(const uint32_t parameterId) const;
  286. /*!
  287. * Get the parameter ranges of \a parameterId.
  288. */
  289. const ParameterRanges* parameterRanges(const uint32_t parameterId) const;
  290. /*!
  291. * Check if parameter \a parameterId is of output type.
  292. */
  293. bool parameterIsOutput(const uint32_t parameterId) const;
  294. /*!
  295. * Get the MIDI program at \a index.
  296. *
  297. * \see getMidiProgramName()
  298. */
  299. const MidiProgramData* midiProgramData(const uint32_t index) const;
  300. /*!
  301. * Get the custom data set at \a index.
  302. *
  303. * \see setCustomData()
  304. */
  305. const CustomData* customData(const size_t index) const;
  306. /*!
  307. * Get the complete plugin chunk data into \a dataPtr.
  308. *
  309. * \return The size of the chunk or 0 if invalid.
  310. *
  311. * \note Make sure to verify the plugin supports chunks before calling this function!
  312. *
  313. * \see setChunkData()
  314. */
  315. virtual int32_t chunkData(void** const dataPtr);
  316. // -------------------------------------------------------------------
  317. // Information (per-plugin data)
  318. /*!
  319. * Get the current parameter value of \a parameterId.
  320. */
  321. virtual double getParameterValue(const uint32_t parameterId);
  322. /*!
  323. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  324. */
  325. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId);
  326. /*!
  327. * Get the plugin's label (URI for PLUGIN_LV2).
  328. */
  329. virtual void getLabel(char* const strBuf);
  330. /*!
  331. * Get the plugin's maker.
  332. */
  333. virtual void getMaker(char* const strBuf);
  334. /*!
  335. * Get the plugin's copyright/license.
  336. */
  337. virtual void getCopyright(char* const strBuf);
  338. /*!
  339. * Get the plugin's (real) name.
  340. *
  341. * \see name()
  342. */
  343. virtual void getRealName(char* const strBuf);
  344. /*!
  345. * Get the name of the parameter \a parameterId.
  346. */
  347. virtual void getParameterName(const uint32_t parameterId, char* const strBuf);
  348. /*!
  349. * Get the symbol of the parameter \a parameterId.
  350. */
  351. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf);
  352. /*!
  353. * Get the custom text of the parameter \a parameterId.
  354. */
  355. virtual void getParameterText(const uint32_t parameterId, char* const strBuf);
  356. /*!
  357. * Get the unit of the parameter \a parameterId.
  358. */
  359. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf);
  360. /*!
  361. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  362. */
  363. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf);
  364. /*!
  365. * Get the name of the program at \a index.
  366. */
  367. void getProgramName(const uint32_t index, char* const strBuf);
  368. /*!
  369. * Get the name of the MIDI program at \a index.
  370. *
  371. * \see getMidiProgramInfo()
  372. */
  373. void getMidiProgramName(const uint32_t index, char* const strBuf);
  374. /*!
  375. * Get information about the plugin's parameter count.\n
  376. * This is used to check how many input, output and total parameters are available.\n
  377. *
  378. * \note Some parameters might not be input or output (ie, invalid).
  379. *
  380. * \see parameterCount()
  381. */
  382. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total);
  383. /*!
  384. * Get information about the plugin's custom GUI, if provided.
  385. */
  386. virtual void getGuiInfo(GuiType* const type, bool* const resizable);
  387. // -------------------------------------------------------------------
  388. // Set data (internal stuff)
  389. /*!
  390. * Set the plugin's id to \a id.
  391. *
  392. * \see id()
  393. */
  394. void setId(const unsigned short id);
  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 char* const 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 client (controller or bridge).
  590. */
  591. void registerToOscClient();
  592. /*!
  593. * Update the plugin's internal OSC data according to \a source and \a url.\n
  594. * This is used for OSC-GUI bridges.
  595. */
  596. void updateOscData(const lo_address source, const char* const url);
  597. /*!
  598. * Free the plugin's internal OSC memory data.
  599. */
  600. void freeOscData();
  601. /*!
  602. * Show the plugin's OSC based GUI.\n
  603. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  604. */
  605. bool waitForOscGuiShow();
  606. // -------------------------------------------------------------------
  607. // MIDI events
  608. /*!
  609. * Send a single midi note to be processed in the next audio callback.\n
  610. * A note with 0 velocity means note-off.
  611. */
  612. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback);
  613. /*!
  614. * Send all midi notes off for the next audio callback.\n
  615. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead.
  616. */
  617. void sendMidiAllNotesOff();
  618. // -------------------------------------------------------------------
  619. // Post-poned events
  620. /*!
  621. * Post pone an event of type \a type.\n
  622. * The event will be processed later, but as soon as possible.
  623. */
  624. void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr);
  625. /*!
  626. * Process all the post-poned events.
  627. * This function must be called from the main thread (ie, idleGui()) if PLUGIN_USES_SINGLE_THREAD is set.
  628. */
  629. void postEventsRun();
  630. /*!
  631. * Handle custom post event.\n
  632. * Implementation depends on plugin type.
  633. */
  634. virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata);
  635. /*!
  636. * Tell the UI a parameter has changed.
  637. */
  638. virtual void uiParameterChange(const uint32_t index, const double value);
  639. /*!
  640. * Tell the UI the current program has changed.
  641. */
  642. virtual void uiProgramChange(const uint32_t index);
  643. /*!
  644. * Tell the UI the current midi program has changed.
  645. */
  646. virtual void uiMidiProgramChange(const uint32_t index);
  647. /*!
  648. * Tell the UI a note has been pressed.
  649. */
  650. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo);
  651. /*!
  652. * Tell the UI a note has been released.
  653. */
  654. virtual void uiNoteOff(const uint8_t channel, const uint8_t note);
  655. // -------------------------------------------------------------------
  656. // Cleanup
  657. /*!
  658. * Clear the engine client ports of the plugin.
  659. */
  660. virtual void removeClientPorts();
  661. /*!
  662. * Initialize all RT buffers of the plugin.
  663. */
  664. virtual void initBuffers();
  665. /*!
  666. * Delete all temporary buffers of the plugin.
  667. */
  668. virtual void deleteBuffers();
  669. // -------------------------------------------------------------------
  670. // Library functions
  671. /*!
  672. * Open the DLL \a filename.
  673. */
  674. bool libOpen(const char* const filename);
  675. /*!
  676. * Close the DLL previously loaded in libOpen().
  677. */
  678. bool libClose();
  679. /*!
  680. * Get the symbol entry \a symbol of the currently loaded DLL.
  681. */
  682. void* libSymbol(const char* const symbol);
  683. /*!
  684. * Get the last DLL related error.
  685. */
  686. const char* libError(const char* const filename);
  687. // -------------------------------------------------------------------
  688. // Locks
  689. void engineProcessLock();
  690. void engineProcessUnlock();
  691. void engineMidiLock();
  692. void engineMidiUnlock();
  693. // -------------------------------------------------------------------
  694. // Plugin initializers
  695. struct initializer {
  696. CarlaEngine* const engine;
  697. const char* const filename;
  698. const char* const name;
  699. const char* const label;
  700. };
  701. //#ifndef BUILD_BRIDGE
  702. static CarlaPlugin* newNative(const initializer& init);
  703. //#endif
  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. //#ifndef BUILD_BRIDGE
  709. static CarlaPlugin* newGIG(const initializer& init);
  710. static CarlaPlugin* newSF2(const initializer& init);
  711. static CarlaPlugin* newSFZ(const initializer& init);
  712. static CarlaPlugin* newBridge(const initializer& init, const BinaryType btype, const PluginType ptype, const void* const extra);
  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. // options
  781. int8_t m_ctrlInChannel;
  782. bool m_fixedBufferSize;
  783. bool m_processHighPrecision;
  784. // latency
  785. uint32_t m_latency;
  786. float** m_latencyBuffers;
  787. // -------------------------------------------------------------------
  788. // Storage Data
  789. PluginAudioData aIn;
  790. PluginAudioData aOut;
  791. PluginMidiData midi;
  792. PluginParameterData param;
  793. PluginProgramData prog;
  794. PluginMidiProgramData midiprog;
  795. std::vector<CustomData> custom;
  796. // -------------------------------------------------------------------
  797. // Extra
  798. struct {
  799. CarlaOscData data;
  800. CarlaPluginThread* thread;
  801. } osc;
  802. struct {
  803. QMutex mutex;
  804. PluginPostEvent data[MAX_POST_EVENTS];
  805. } postEvents;
  806. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  807. // -------------------------------------------------------------------
  808. // Utilities
  809. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  810. {
  811. if (value < ranges.min)
  812. value = ranges.min;
  813. else if (value > ranges.max)
  814. value = ranges.max;
  815. return value;
  816. }
  817. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  818. {
  819. if (value < ranges.min)
  820. value = ranges.min;
  821. else if (value > ranges.max)
  822. value = ranges.max;
  823. return value;
  824. }
  825. friend class CarlaEngine; // FIXME
  826. friend class CarlaEngineJack;
  827. };
  828. /*!
  829. * \class CarlaPluginGUI
  830. *
  831. * \brief Carla Backend gui plugin class
  832. *
  833. * \see CarlaPlugin
  834. */
  835. class CarlaPluginGUI : public QMainWindow
  836. {
  837. public:
  838. /*!
  839. * \class Callback
  840. *
  841. * \brief Carla plugin GUI callback
  842. */
  843. class Callback
  844. {
  845. public:
  846. virtual ~Callback() {}
  847. virtual void guiClosedCallback() = 0;
  848. };
  849. // -------------------------------------------------------------------
  850. // Constructor and destructor
  851. /*!
  852. * TODO
  853. */
  854. CarlaPluginGUI(QWidget* const parent, Callback* const callback);
  855. /*!
  856. * TODO
  857. */
  858. ~CarlaPluginGUI();
  859. // -------------------------------------------------------------------
  860. // Get data
  861. /*!
  862. * TODO
  863. */
  864. GuiContainer* getContainer() const;
  865. /*!
  866. * TODO
  867. */
  868. WId getWinId() const;
  869. // -------------------------------------------------------------------
  870. // Set data
  871. /*!
  872. * TODO
  873. */
  874. void setNewSize(const int width, const int height);
  875. /*!
  876. * TODO
  877. */
  878. void setResizable(const bool resizable);
  879. /*!
  880. * TODO
  881. */
  882. void setTitle(const char* const title);
  883. /*!
  884. * TODO
  885. */
  886. void setVisible(const bool yesNo);
  887. // -------------------------------------------------------------------
  888. private:
  889. Callback* const m_callback;
  890. GuiContainer* m_container;
  891. QByteArray m_geometry;
  892. bool m_resizable;
  893. void hideEvent(QHideEvent* const event);
  894. void closeEvent(QCloseEvent* const event);
  895. };
  896. /**@}*/
  897. CARLA_BACKEND_END_NAMESPACE
  898. #endif // CARLA_PLUGIN_HPP