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.

2312 lines
63KB

  1. /*
  2. * Carla Backend
  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_H
  18. #define CARLA_PLUGIN_H
  19. #include "carla_engine.h"
  20. #include "carla_midi.h"
  21. #include "carla_shared.h"
  22. #include "carla_lib_includes.h"
  23. #ifdef BUILD_BRIDGE
  24. # include "carla_bridge_osc.h"
  25. #endif
  26. // common includes
  27. #include <cmath>
  28. #include <cstdio>
  29. #include <cstdlib>
  30. #include <vector>
  31. #include <QtGui/QDialog>
  32. #ifdef Q_WS_X11
  33. #include <QtGui/QX11EmbedContainer>
  34. typedef QX11EmbedContainer GuiContainer;
  35. #else
  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); 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. // fallback data
  153. static ParameterData paramDataNull;
  154. static ParameterRanges paramRangesNull;
  155. static MidiProgramData midiProgramDataNull;
  156. static CustomData customDataNull;
  157. /*!
  158. * \class CarlaPlugin
  159. *
  160. * \brief Carla Backend base plugin class
  161. *
  162. * This is the base class for all available plugin types available in Carla Backend.\n
  163. * All virtual calls are implemented in this class as fallback, so it's safe to only override needed calls.
  164. *
  165. * \see PluginType
  166. */
  167. class CarlaPlugin
  168. {
  169. public:
  170. /*!
  171. * This is the constructor of the base plugin class.
  172. *
  173. * \param engine The engine which this plugin belongs to, must not be null
  174. * \param id The 'id' of this plugin, must between 0 and CarlaEngine::maxPluginNumber()
  175. */
  176. CarlaPlugin(CarlaEngine* const engine, const unsigned short id)
  177. : m_id(id),
  178. x_engine(engine),
  179. x_client(nullptr),
  180. x_dryWet(1.0),
  181. x_volume(1.0),
  182. x_balanceLeft(-1.0),
  183. x_balanceRight(1.0)
  184. {
  185. CARLA_ASSERT(engine);
  186. CARLA_ASSERT(id < CarlaEngine::maxPluginNumber());
  187. qDebug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  188. m_type = PLUGIN_NONE;
  189. m_hints = 0;
  190. m_active = false;
  191. m_activeBefore = false;
  192. m_enabled = false;
  193. m_lib = nullptr;
  194. m_name = nullptr;
  195. m_filename = nullptr;
  196. #ifndef BUILD_BRIDGE
  197. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  198. m_ctrlInChannel = m_id;
  199. else
  200. #endif
  201. m_ctrlInChannel = 0;
  202. m_latency = 0;
  203. m_tempBufferIn = nullptr;
  204. m_tempBufferOut = nullptr;
  205. #ifndef BUILD_BRIDGE
  206. osc.data.path = nullptr;
  207. osc.data.source = nullptr;
  208. osc.data.target = nullptr;
  209. osc.thread = nullptr;
  210. #endif
  211. m_count += 1;
  212. }
  213. /*!
  214. * This is the de-constructor of the base plugin class.
  215. */
  216. virtual ~CarlaPlugin()
  217. {
  218. qDebug("CarlaPlugin::~CarlaPlugin()");
  219. // Remove client and ports
  220. if (x_client)
  221. {
  222. if (x_client->isActive())
  223. x_client->deactivate();
  224. removeClientPorts();
  225. delete x_client;
  226. }
  227. // Delete data
  228. deleteBuffers();
  229. // Unload DLL
  230. libClose();
  231. if (m_name)
  232. free((void*)m_name);
  233. if (m_filename)
  234. free((void*)m_filename);
  235. if (prog.count > 0)
  236. {
  237. for (uint32_t i=0; i < prog.count; i++)
  238. {
  239. if (prog.names[i])
  240. free((void*)prog.names[i]);
  241. }
  242. delete[] prog.names;
  243. }
  244. if (midiprog.count > 0)
  245. {
  246. for (uint32_t i=0; i < midiprog.count; i++)
  247. {
  248. if (midiprog.data[i].name)
  249. free((void*)midiprog.data[i].name);
  250. }
  251. delete[] midiprog.data;
  252. }
  253. if (custom.size() > 0)
  254. {
  255. for (size_t i=0; i < custom.size(); i++)
  256. {
  257. if (custom[i].key)
  258. free((void*)custom[i].key);
  259. if (custom[i].value)
  260. free((void*)custom[i].value);
  261. }
  262. custom.clear();
  263. }
  264. if (m_tempBufferIn)
  265. {
  266. for (uint32_t i=0; i < aIn.count; i++)
  267. delete[] m_tempBufferIn[i];
  268. delete[] m_tempBufferIn;
  269. }
  270. if (m_tempBufferOut)
  271. {
  272. for (uint32_t i=0; i < aOut.count; i++)
  273. delete[] m_tempBufferOut[i];
  274. delete[] m_tempBufferOut;
  275. }
  276. m_count -= 1;
  277. }
  278. // -------------------------------------------------------------------
  279. // Information (base)
  280. /*!
  281. * Get the plugin's type (ie, a subclass of CarlaPlugin).
  282. *
  283. * \note Plugin bridges will return their respective plugin type, there is no plugin type such as "bridge".\n
  284. * To check if a plugin is a bridge use:
  285. * \code
  286. * if (m_hints & PLUGIN_IS_BRIDGE)
  287. * ...
  288. * \endcode
  289. */
  290. PluginType type() const
  291. {
  292. return m_type;
  293. }
  294. /*!
  295. * Get the plugin's id (as passed in the constructor).
  296. *
  297. * \see setId()
  298. */
  299. unsigned short id() const
  300. {
  301. return m_id;
  302. }
  303. /*!
  304. * Get the plugin's hints.
  305. *
  306. * \see PluginHints
  307. */
  308. unsigned int hints() const
  309. {
  310. return m_hints;
  311. }
  312. /*!
  313. * Check if the plugin is enabled.
  314. *
  315. * \see setEnabled()
  316. */
  317. bool enabled() const
  318. {
  319. return m_enabled;
  320. }
  321. /*!
  322. * Get the plugin's internal name.\n
  323. * This name is unique within all plugins in an engine.
  324. *
  325. * \see getRealName()
  326. */
  327. const char* name() const
  328. {
  329. return m_name;
  330. }
  331. /*!
  332. * Get the currently loaded DLL filename for this plugin.\n
  333. * (Sound kits return their exact filename).
  334. */
  335. const char* filename() const
  336. {
  337. return m_filename;
  338. }
  339. /*!
  340. * Get the plugin's category (delay, filter, synth, etc).
  341. */
  342. virtual PluginCategory category()
  343. {
  344. return PLUGIN_CATEGORY_NONE;
  345. }
  346. /*!
  347. * Get the plugin's native unique Id.\n
  348. * May return 0 on plugin types that don't support Ids.
  349. */
  350. virtual long uniqueId()
  351. {
  352. return 0;
  353. }
  354. // -------------------------------------------------------------------
  355. // Information (count)
  356. /*!
  357. * Get the number of audio inputs.
  358. */
  359. virtual uint32_t audioInCount()
  360. {
  361. return aIn.count;
  362. }
  363. /*!
  364. * Get the number of audio outputs.
  365. */
  366. virtual uint32_t audioOutCount()
  367. {
  368. return aOut.count;
  369. }
  370. /*!
  371. * Get the number of MIDI inputs.
  372. */
  373. virtual uint32_t midiInCount()
  374. {
  375. return midi.portMin ? 1 : 0;
  376. }
  377. /*!
  378. * Get the number of MIDI outputs.
  379. */
  380. virtual uint32_t midiOutCount()
  381. {
  382. return midi.portMout ? 1 : 0;
  383. }
  384. /*!
  385. * Get the number of parameters.\n
  386. * To know the number of parameter inputs and outputs separately use getParameterCountInfo() instead.
  387. */
  388. uint32_t parameterCount() const
  389. {
  390. return param.count;
  391. }
  392. /*!
  393. * Get the number of scalepoints for parameter \a parameterId.
  394. */
  395. virtual uint32_t parameterScalePointCount(const uint32_t parameterId)
  396. {
  397. CARLA_ASSERT(parameterId < param.count);
  398. return 0;
  399. }
  400. /*!
  401. * Get the number of programs.
  402. */
  403. uint32_t programCount() const
  404. {
  405. return prog.count;
  406. }
  407. /*!
  408. * Get the number of MIDI programs.
  409. */
  410. uint32_t midiProgramCount() const
  411. {
  412. return midiprog.count;
  413. }
  414. /*!
  415. * Get the number of custom data sets.
  416. */
  417. size_t customDataCount() const
  418. {
  419. return custom.size();
  420. }
  421. // -------------------------------------------------------------------
  422. // Information (current data)
  423. /*!
  424. * Get the current program number (-1 if unset).
  425. *
  426. * \see setProgram()
  427. */
  428. int32_t currentProgram() const
  429. {
  430. return prog.current;
  431. }
  432. /*!
  433. * Get the current MIDI program number (-1 if unset).
  434. *
  435. * \see setMidiProgram()
  436. * \see setMidiProgramById()
  437. */
  438. int32_t currentMidiProgram() const
  439. {
  440. return midiprog.current;
  441. }
  442. /*!
  443. * Get the parameter data of \a parameterId.
  444. */
  445. const ParameterData* parameterData(const uint32_t parameterId) const
  446. {
  447. CARLA_ASSERT(parameterId < param.count);
  448. if (parameterId < param.count)
  449. return &param.data[parameterId];
  450. return &paramDataNull;
  451. }
  452. /*!
  453. * Get the parameter ranges of \a parameterId.
  454. */
  455. const ParameterRanges* parameterRanges(const uint32_t parameterId) const
  456. {
  457. CARLA_ASSERT(parameterId < param.count);
  458. if (parameterId < param.count)
  459. return &param.ranges[parameterId];
  460. return &paramRangesNull;
  461. }
  462. /*!
  463. * Check if parameter \a parameterId is of output type.
  464. */
  465. bool parameterIsOutput(const uint32_t parameterId) const
  466. {
  467. CARLA_ASSERT(parameterId < param.count);
  468. if (parameterId < param.count)
  469. return (param.data[parameterId].type == PARAMETER_OUTPUT);
  470. return false;
  471. }
  472. /*!
  473. * Get the MIDI program at \a index.
  474. *
  475. * \see getMidiProgramName()
  476. */
  477. const MidiProgramData* midiProgramData(const uint32_t index) const
  478. {
  479. CARLA_ASSERT(index < midiprog.count);
  480. if (index < midiprog.count)
  481. return &midiprog.data[index];
  482. return &midiProgramDataNull;
  483. }
  484. /*!
  485. * Get the custom data set at \a index.
  486. *
  487. * \see setCustomData()
  488. */
  489. const CustomData* customData(const size_t index) const
  490. {
  491. CARLA_ASSERT(index < custom.size());
  492. if (index < custom.size())
  493. return &custom[index];
  494. return &customDataNull;
  495. }
  496. /*!
  497. * Get the complete plugin chunk data into \a dataPtr.
  498. *
  499. * \return The size of the chunk or 0 if invalid.
  500. *
  501. * \note Make sure to verify the plugin supports chunks before calling this function!
  502. *
  503. * \see setChunkData()
  504. */
  505. virtual int32_t chunkData(void** const dataPtr)
  506. {
  507. CARLA_ASSERT(dataPtr);
  508. return 0;
  509. }
  510. // -------------------------------------------------------------------
  511. // Information (per-plugin data)
  512. /*!
  513. * Get the current parameter value of \a parameterId.
  514. */
  515. virtual double getParameterValue(const uint32_t parameterId)
  516. {
  517. CARLA_ASSERT(parameterId < param.count);
  518. return 0.0;
  519. }
  520. /*!
  521. * Get the scalepoint \a scalePointId value of the parameter \a parameterId.
  522. */
  523. virtual double getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  524. {
  525. CARLA_ASSERT(parameterId < param.count);
  526. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  527. return 0.0;
  528. }
  529. /*!
  530. * Get the plugin's label (URI for PLUGIN_LV2).
  531. */
  532. virtual void getLabel(char* const strBuf)
  533. {
  534. *strBuf = 0;
  535. }
  536. /*!
  537. * Get the plugin's maker.
  538. */
  539. virtual void getMaker(char* const strBuf)
  540. {
  541. *strBuf = 0;
  542. }
  543. /*!
  544. * Get the plugin's copyright/license.
  545. */
  546. virtual void getCopyright(char* const strBuf)
  547. {
  548. *strBuf = 0;
  549. }
  550. /*!
  551. * Get the plugin's (real) name.
  552. *
  553. * \see name()
  554. */
  555. virtual void getRealName(char* const strBuf)
  556. {
  557. *strBuf = 0;;
  558. }
  559. /*!
  560. * Get the name of the parameter \a parameterId.
  561. */
  562. virtual void getParameterName(const uint32_t parameterId, char* const strBuf)
  563. {
  564. CARLA_ASSERT(parameterId < param.count);
  565. *strBuf = 0;
  566. }
  567. /*!
  568. * Get the symbol of the parameter \a parameterId.
  569. */
  570. virtual void getParameterSymbol(const uint32_t parameterId, char* const strBuf)
  571. {
  572. CARLA_ASSERT(parameterId < param.count);
  573. *strBuf = 0;
  574. }
  575. /*!
  576. * Get the custom text of the parameter \a parameterId.
  577. */
  578. virtual void getParameterText(const uint32_t parameterId, char* const strBuf)
  579. {
  580. CARLA_ASSERT(parameterId < param.count);
  581. *strBuf = 0;
  582. }
  583. /*!
  584. * Get the unit of the parameter \a parameterId.
  585. */
  586. virtual void getParameterUnit(const uint32_t parameterId, char* const strBuf)
  587. {
  588. CARLA_ASSERT(parameterId < param.count);
  589. *strBuf = 0;
  590. }
  591. /*!
  592. * Get the scalepoint \a scalePointId label of the parameter \a parameterId.
  593. */
  594. virtual void getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  595. {
  596. CARLA_ASSERT(parameterId < param.count);
  597. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  598. *strBuf = 0;
  599. }
  600. /*!
  601. * Get the name of the program at \a index.
  602. */
  603. void getProgramName(const uint32_t index, char* const strBuf)
  604. {
  605. CARLA_ASSERT(index < prog.count);
  606. if (index < prog.count && prog.names[index])
  607. strncpy(strBuf, prog.names[index], STR_MAX);
  608. else
  609. *strBuf = 0;
  610. }
  611. /*!
  612. * Get the name of the MIDI program at \a index.
  613. *
  614. * \see getMidiProgramInfo()
  615. */
  616. void getMidiProgramName(const uint32_t index, char* const strBuf)
  617. {
  618. CARLA_ASSERT(index < midiprog.count);
  619. if (index < midiprog.count && midiprog.data[index].name)
  620. strncpy(strBuf, midiprog.data[index].name, STR_MAX);
  621. else
  622. *strBuf = 0;
  623. }
  624. /*!
  625. * Get information about the plugin's parameter count.\n
  626. * This is used to check how many input, output and total parameters are available.\n
  627. *
  628. * \note Some parameters might not be input or output (ie, invalid).
  629. *
  630. * \see parameterCount()
  631. */
  632. void getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total)
  633. {
  634. *ins = 0;
  635. *outs = 0;
  636. *total = param.count;
  637. for (uint32_t i=0; i < param.count; i++)
  638. {
  639. if (param.data[i].type == PARAMETER_INPUT)
  640. *ins += 1;
  641. else if (param.data[i].type == PARAMETER_OUTPUT)
  642. *outs += 1;
  643. }
  644. }
  645. /*!
  646. * Get information about the plugin's custom GUI, if provided.
  647. */
  648. virtual void getGuiInfo(GuiType* const type, bool* const resizable)
  649. {
  650. *type = GUI_NONE;
  651. *resizable = false;
  652. }
  653. // -------------------------------------------------------------------
  654. // Set data (internal stuff)
  655. #ifndef BUILD_BRIDGE
  656. /*!
  657. * Set the plugin's id to \a id.
  658. *
  659. * \see id()
  660. */
  661. void setId(const unsigned short id)
  662. {
  663. m_id = id;
  664. if (carlaOptions.processMode == PROCESS_MODE_CONTINUOUS_RACK)
  665. m_ctrlInChannel = id;
  666. }
  667. #endif
  668. /*!
  669. * Enable or disable the plugin according to \a yesNo.
  670. *
  671. * When a plugin is disabled, it will never be processed or managed in any way.\n
  672. * To 'bypass' a plugin use setActive() instead.
  673. *
  674. * \see enabled()
  675. */
  676. void setEnabled(const bool yesNo)
  677. {
  678. m_enabled = yesNo;
  679. }
  680. /*!
  681. * Set plugin as active according to \a active.
  682. *
  683. * \param sendOsc Send message change over OSC
  684. * \param sendCallback Send message change to registered callback
  685. */
  686. void setActive(const bool active, const bool sendOsc, const bool sendCallback)
  687. {
  688. m_active = active;
  689. double value = active ? 1.0 : 0.0;
  690. #ifndef BUILD_BRIDGE
  691. if (sendOsc)
  692. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, value);
  693. #else
  694. Q_UNUSED(sendOsc);
  695. #endif
  696. if (sendCallback)
  697. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_ACTIVE, 0, value);
  698. #ifndef BUILD_BRIDGE
  699. else if (m_hints & PLUGIN_IS_BRIDGE)
  700. osc_send_control(&osc.data, PARAMETER_ACTIVE, value);
  701. #endif
  702. }
  703. /*!
  704. * Set the plugin's dry/wet signal value to \a value.\n
  705. * \a value must be between 0.0 and 1.0.
  706. *
  707. * \param sendOsc Send message change over OSC
  708. * \param sendCallback Send message change to registered callback
  709. */
  710. void setDryWet(double value, const bool sendOsc, const bool sendCallback)
  711. {
  712. CARLA_ASSERT(value >= 0.0 && value <= 1.0);
  713. if (value < 0.0)
  714. value = 0.0;
  715. else if (value > 1.0)
  716. value = 1.0;
  717. x_dryWet = value;
  718. #ifndef BUILD_BRIDGE
  719. if (sendOsc)
  720. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, value);
  721. #else
  722. Q_UNUSED(sendOsc);
  723. #endif
  724. if (sendCallback)
  725. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_DRYWET, 0, value);
  726. #ifndef BUILD_BRIDGE
  727. else if (m_hints & PLUGIN_IS_BRIDGE)
  728. osc_send_control(&osc.data, PARAMETER_DRYWET, value);
  729. #endif
  730. }
  731. /*!
  732. * Set the plugin's output volume to \a value.\n
  733. * \a value must be between 0.0 and 1.27.
  734. *
  735. * \param sendOsc Send message change over OSC
  736. * \param sendCallback Send message change to registered callback
  737. */
  738. void setVolume(double value, const bool sendOsc, const bool sendCallback)
  739. {
  740. CARLA_ASSERT(value >= 0.0 && value <= 1.27);
  741. if (value < 0.0)
  742. value = 0.0;
  743. else if (value > 1.27)
  744. value = 1.27;
  745. x_volume = value;
  746. #ifndef BUILD_BRIDGE
  747. if (sendOsc)
  748. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, value);
  749. #else
  750. Q_UNUSED(sendOsc);
  751. #endif
  752. if (sendCallback)
  753. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_VOLUME, 0, value);
  754. #ifndef BUILD_BRIDGE
  755. else if (m_hints & PLUGIN_IS_BRIDGE)
  756. osc_send_control(&osc.data, PARAMETER_VOLUME, value);
  757. #endif
  758. }
  759. /*!
  760. * Set the plugin's output left balance value to \a value.\n
  761. * \a value must be between -1.0 and 1.0.
  762. *
  763. * \param sendOsc Send message change over OSC
  764. * \param sendCallback Send message change to registered callback
  765. */
  766. void setBalanceLeft(double value, const bool sendOsc, const bool sendCallback)
  767. {
  768. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  769. if (value < -1.0)
  770. value = -1.0;
  771. else if (value > 1.0)
  772. value = 1.0;
  773. x_balanceLeft = value;
  774. #ifndef BUILD_BRIDGE
  775. if (sendOsc)
  776. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, value);
  777. #else
  778. Q_UNUSED(sendOsc);
  779. #endif
  780. if (sendCallback)
  781. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_LEFT, 0, value);
  782. #ifndef BUILD_BRIDGE
  783. else if (m_hints & PLUGIN_IS_BRIDGE)
  784. osc_send_control(&osc.data, PARAMETER_BALANCE_LEFT, value);
  785. #endif
  786. }
  787. /*!
  788. * Set the plugin's output right balance value to \a value.\n
  789. * \a value must be between -1.0 and 1.0.
  790. *
  791. * \param sendOsc Send message change over OSC
  792. * \param sendCallback Send message change to registered callback
  793. */
  794. void setBalanceRight(double value, const bool sendOsc, const bool sendCallback)
  795. {
  796. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  797. if (value < -1.0)
  798. value = -1.0;
  799. else if (value > 1.0)
  800. value = 1.0;
  801. x_balanceRight = value;
  802. #ifndef BUILD_BRIDGE
  803. if (sendOsc)
  804. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, value);
  805. #else
  806. Q_UNUSED(sendOsc);
  807. #endif
  808. if (sendCallback)
  809. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_RIGHT, 0, value);
  810. #ifndef BUILD_BRIDGE
  811. else if (m_hints & PLUGIN_IS_BRIDGE)
  812. osc_send_control(&osc.data, PARAMETER_BALANCE_RIGHT, value);
  813. #endif
  814. }
  815. #ifndef BUILD_BRIDGE
  816. /*!
  817. * BridgePlugin call used to set internal data.
  818. */
  819. virtual int setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types)
  820. {
  821. return 1;
  822. Q_UNUSED(type);
  823. Q_UNUSED(argc);
  824. Q_UNUSED(argv);
  825. Q_UNUSED(types);
  826. }
  827. #endif
  828. // -------------------------------------------------------------------
  829. // Set data (plugin-specific stuff)
  830. /*!
  831. * Set a plugin's parameter value.
  832. *
  833. * \param parameterId The parameter to change
  834. * \param value The new parameter value, must be within the parameter's range
  835. * \param sendGui Send message change to plugin's custom GUI, if any
  836. * \param sendOsc Send message change over OSC
  837. * \param sendCallback Send message change to registered callback
  838. *
  839. * \see getParameterValue()
  840. */
  841. virtual void setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  842. {
  843. CARLA_ASSERT(parameterId < param.count);
  844. if (sendGui)
  845. uiParameterChange(parameterId, value);
  846. #ifndef BUILD_BRIDGE
  847. if (sendOsc)
  848. x_engine->osc_send_control_set_parameter_value(m_id, parameterId, value);
  849. #else
  850. Q_UNUSED(sendOsc);
  851. #endif
  852. if (sendCallback)
  853. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, parameterId, 0, value);
  854. }
  855. /*!
  856. * Set a plugin's parameter value, including internal parameters.\n
  857. * \a rindex can be negative to allow internal parameters change (as defined in InternalParametersIndex).
  858. *
  859. * \see setParameterValue()
  860. * \see setActive()
  861. * \see setDryWet()
  862. * \see setVolume()
  863. * \see setBalanceLeft()
  864. * \see setBalanceRight()
  865. */
  866. void setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  867. {
  868. CARLA_ASSERT(rindex >= PARAMETER_BALANCE_RIGHT && rindex != PARAMETER_NULL);
  869. if (rindex == PARAMETER_ACTIVE)
  870. return setActive(value > 0.0, sendOsc, sendCallback);
  871. if (rindex == PARAMETER_DRYWET)
  872. return setDryWet(value, sendOsc, sendCallback);
  873. if (rindex == PARAMETER_VOLUME)
  874. return setVolume(value, sendOsc, sendCallback);
  875. if (rindex == PARAMETER_BALANCE_LEFT)
  876. return setBalanceLeft(value, sendOsc, sendCallback);
  877. if (rindex == PARAMETER_BALANCE_RIGHT)
  878. return setBalanceRight(value, sendOsc, sendCallback);
  879. for (uint32_t i=0; i < param.count; i++)
  880. {
  881. if (param.data[i].rindex == rindex)
  882. return setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  883. }
  884. }
  885. /*!
  886. * Set parameter's \a parameterId MIDI channel to \a channel.\n
  887. * \a channel must be between 0 and 15.
  888. */
  889. void setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback)
  890. {
  891. CARLA_ASSERT(parameterId < param.count);
  892. CARLA_ASSERT(channel < 16);
  893. if (channel >= 16)
  894. channel = 16;
  895. param.data[parameterId].midiChannel = channel;
  896. #ifndef BUILD_BRIDGE
  897. if (sendOsc)
  898. x_engine->osc_send_control_set_parameter_midi_channel(m_id, parameterId, channel);
  899. #else
  900. Q_UNUSED(sendOsc);
  901. #endif
  902. if (sendCallback)
  903. x_engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, m_id, parameterId, channel, 0.0);
  904. }
  905. /*!
  906. * Set parameter's \a parameterId MIDI CC to \a cc.\n
  907. * \a cc must be between 0 and 95 (0x5F), or -1 for invalid.
  908. */
  909. void setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback)
  910. {
  911. CARLA_ASSERT(parameterId < param.count);
  912. CARLA_ASSERT(cc >= -1);
  913. if (cc < -1 || cc > 0x5F)
  914. cc = -1;
  915. param.data[parameterId].midiCC = cc;
  916. #ifndef BUILD_BRIDGE
  917. if (sendOsc)
  918. x_engine->osc_send_control_set_parameter_midi_cc(m_id, parameterId, cc);
  919. #else
  920. Q_UNUSED(sendOsc);
  921. #endif
  922. if (sendCallback)
  923. x_engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, m_id, parameterId, cc, 0.0);
  924. }
  925. /*!
  926. * Add a custom data set.\n
  927. * If \a key already exists, its current value will be swapped with \a value.
  928. *
  929. * \param type Type of data used in \a value.
  930. * \param key A key identifing this data set.
  931. * \param value The value of the data set, of type \a type.
  932. * \param sendGui Send message change to plugin's custom GUI, if any
  933. *
  934. * \see customData()
  935. */
  936. virtual void setCustomData(const CustomDataType type, const char* const key, const char* const value, const bool sendGui)
  937. {
  938. CARLA_ASSERT(type != CUSTOM_DATA_INVALID);
  939. CARLA_ASSERT(key);
  940. CARLA_ASSERT(value);
  941. if (type == CUSTOM_DATA_INVALID)
  942. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - type is invalid", CustomDataType2str(type), key, value, bool2str(sendGui));
  943. if (! key)
  944. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - key is null", CustomDataType2str(type), key, value, bool2str(sendGui));
  945. if (! value)
  946. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - value is null", CustomDataType2str(type), key, value, bool2str(sendGui));
  947. bool saveData = true;
  948. switch (type)
  949. {
  950. case CUSTOM_DATA_INVALID:
  951. saveData = false;
  952. break;
  953. case CUSTOM_DATA_STRING:
  954. // Ignore some keys
  955. if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0)
  956. saveData = false;
  957. else if (strcmp(key, CARLA_BRIDGE_MSG_SAVE_NOW) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CHUNK) == 0 || strcmp(key, CARLA_BRIDGE_MSG_SET_CUSTOM) == 0)
  958. saveData = false;
  959. break;
  960. default:
  961. break;
  962. }
  963. if (saveData)
  964. {
  965. // Check if we already have this key
  966. for (size_t i=0; i < custom.size(); i++)
  967. {
  968. if (strcmp(custom[i].key, key) == 0)
  969. {
  970. free((void*)custom[i].value);
  971. custom[i].value = strdup(value);
  972. return;
  973. }
  974. }
  975. // Otherwise store it
  976. CustomData newData;
  977. newData.type = type;
  978. newData.key = strdup(key);
  979. newData.value = strdup(value);
  980. custom.push_back(newData);
  981. }
  982. }
  983. /*!
  984. * Set the complete chunk data as \a stringData.\n
  985. * \a stringData must a base64 encoded string of binary data.
  986. *
  987. * \see chunkData()
  988. *
  989. * \note Make sure to verify the plugin supports chunks before calling this function!
  990. */
  991. virtual void setChunkData(const char* const stringData)
  992. {
  993. CARLA_ASSERT(stringData);
  994. }
  995. /*!
  996. * Change the current plugin program to \a index.
  997. *
  998. * If \a index is negative the plugin's program will be considered unset.\n
  999. * The plugin's default parameter values will be updated when this function is called.
  1000. *
  1001. * \param index New program index to use
  1002. * \param sendGui Send message change to plugin's custom GUI, if any
  1003. * \param sendOsc Send message change over OSC
  1004. * \param sendCallback Send message change to registered callback
  1005. * \param block Block the audio callback
  1006. */
  1007. virtual void setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1008. {
  1009. CARLA_ASSERT(index >= -1 && index < (int32_t)prog.count);
  1010. if (index < -1)
  1011. index = -1;
  1012. else if (index > (int32_t)prog.count)
  1013. return;
  1014. prog.current = index;
  1015. if (sendGui && index >= 0)
  1016. uiProgramChange(index);
  1017. // Change default parameter values
  1018. if (index >= 0)
  1019. {
  1020. for (uint32_t i=0; i < param.count; i++)
  1021. {
  1022. param.ranges[i].def = getParameterValue(i);
  1023. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  1024. #ifndef BUILD_BRIDGE
  1025. if (sendOsc)
  1026. {
  1027. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  1028. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  1029. }
  1030. #endif
  1031. }
  1032. }
  1033. #ifndef BUILD_BRIDGE
  1034. if (sendOsc)
  1035. x_engine->osc_send_control_set_program(m_id, index);
  1036. #else
  1037. Q_UNUSED(sendOsc);
  1038. #endif
  1039. if (sendCallback)
  1040. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  1041. Q_UNUSED(block);
  1042. }
  1043. /*!
  1044. * Change the current MIDI plugin program to \a index.
  1045. *
  1046. * If \a index is negative the plugin's program will be considered unset.\n
  1047. * The plugin's default parameter values will be updated when this function is called.
  1048. *
  1049. * \param index New program index to use
  1050. * \param sendGui Send message change to plugin's custom GUI, if any
  1051. * \param sendOsc Send message change over OSC
  1052. * \param sendCallback Send message change to registered callback
  1053. * \param block Block the audio callback
  1054. */
  1055. virtual void setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1056. {
  1057. CARLA_ASSERT(index >= -1 && index < (int32_t)midiprog.count);
  1058. if (index < -1)
  1059. index = -1;
  1060. else if (index > (int32_t)midiprog.count)
  1061. return;
  1062. midiprog.current = index;
  1063. if (sendGui && index >= 0)
  1064. uiMidiProgramChange(index);
  1065. // Change default parameter values (sound banks never change defaults)
  1066. if (index >= 0 && m_type != PLUGIN_GIG && m_type != PLUGIN_SF2 && m_type != PLUGIN_SFZ)
  1067. {
  1068. for (uint32_t i=0; i < param.count; i++)
  1069. {
  1070. param.ranges[i].def = getParameterValue(i);
  1071. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  1072. #ifndef BUILD_BRIDGE
  1073. if (sendOsc)
  1074. {
  1075. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  1076. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  1077. }
  1078. #endif
  1079. }
  1080. }
  1081. #ifndef BUILD_BRIDGE
  1082. if (sendOsc)
  1083. x_engine->osc_send_control_set_midi_program(m_id, index);
  1084. #else
  1085. Q_UNUSED(sendOsc);
  1086. #endif
  1087. if (sendCallback)
  1088. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  1089. Q_UNUSED(block);
  1090. }
  1091. /*!
  1092. * This is an overloaded call to setMidiProgram().\n
  1093. * It changes the current MIDI program using \a bank and \a program values instead of index.
  1094. */
  1095. void setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  1096. {
  1097. CARLA_ASSERT(program < 128);
  1098. for (uint32_t i=0; i < midiprog.count; i++)
  1099. {
  1100. if (midiprog.data[i].bank == bank && midiprog.data[i].program == program)
  1101. return setMidiProgram(i, sendGui, sendOsc, sendCallback, block);
  1102. }
  1103. }
  1104. // -------------------------------------------------------------------
  1105. // Set gui stuff
  1106. /*!
  1107. * Set the plugin's custom GUI container.\n
  1108. *
  1109. * \note This function must be always called from the main thread.
  1110. */
  1111. virtual void setGuiContainer(GuiContainer* const container)
  1112. {
  1113. Q_UNUSED(container);
  1114. }
  1115. /*!
  1116. * Show (or hide) the plugin's custom GUI according to \a yesNo.
  1117. *
  1118. * \note This function must be always called from the main thread.
  1119. */
  1120. virtual void showGui(const bool yesNo)
  1121. {
  1122. Q_UNUSED(yesNo);
  1123. }
  1124. /*!
  1125. * Idle the plugin's custom GUI.
  1126. *
  1127. * \note This function must be always called from the main thread.
  1128. */
  1129. virtual void idleGui()
  1130. {
  1131. if (! m_enabled)
  1132. return;
  1133. if (m_hints & PLUGIN_USES_SINGLE_THREAD)
  1134. {
  1135. // Process postponed events
  1136. postEventsRun();
  1137. // Update parameter outputs
  1138. for (uint32_t i=0; i < param.count; i++)
  1139. {
  1140. if (param.data[i].type == PARAMETER_OUTPUT)
  1141. uiParameterChange(i, getParameterValue(i));
  1142. }
  1143. }
  1144. }
  1145. // -------------------------------------------------------------------
  1146. // Plugin state
  1147. /*!
  1148. * Reload the plugin's entire state (including programs).\n
  1149. * The plugin will be disabled during this call.
  1150. */
  1151. virtual void reload()
  1152. {
  1153. }
  1154. /*!
  1155. * Reload the plugin's programs state.
  1156. */
  1157. virtual void reloadPrograms(const bool init)
  1158. {
  1159. Q_UNUSED(init);
  1160. }
  1161. /*!
  1162. * Tell the plugin to prepare for save.
  1163. */
  1164. virtual void prepareForSave()
  1165. {
  1166. }
  1167. // -------------------------------------------------------------------
  1168. // Plugin processing
  1169. /*!
  1170. * Plugin process callback.
  1171. */
  1172. virtual void process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset = 0)
  1173. {
  1174. Q_UNUSED(inBuffer);
  1175. Q_UNUSED(outBuffer);
  1176. Q_UNUSED(frames);
  1177. Q_UNUSED(framesOffset);
  1178. }
  1179. /*!
  1180. * Tell the plugin the current buffer size has changed.
  1181. */
  1182. virtual void bufferSizeChanged(const uint32_t newBufferSize)
  1183. {
  1184. recreateTempBuffers(newBufferSize);
  1185. }
  1186. /*!
  1187. * Recreate temporary audio buffers.
  1188. */
  1189. void recreateTempBuffers(const uint32_t bufferSize)
  1190. {
  1191. if (m_tempBufferIn)
  1192. {
  1193. for (uint32_t i=0; i < aIn.count; i++)
  1194. delete[] m_tempBufferIn[i];
  1195. delete[] m_tempBufferIn;
  1196. }
  1197. if (m_tempBufferOut)
  1198. {
  1199. for (uint32_t i=0; i < aOut.count; i++)
  1200. delete[] m_tempBufferOut[i];
  1201. delete[] m_tempBufferOut;
  1202. }
  1203. if (aIn.count > 0)
  1204. {
  1205. m_tempBufferIn = new float* [aIn.count];
  1206. for (uint32_t i=0; i < aIn.count; i++)
  1207. m_tempBufferIn[i] = new float [bufferSize];
  1208. }
  1209. else
  1210. m_tempBufferIn = nullptr;
  1211. if (aOut.count > 0)
  1212. {
  1213. m_tempBufferOut = new float* [aOut.count];
  1214. for (uint32_t i=0; i < aOut.count; i++)
  1215. m_tempBufferOut[i] = new float [bufferSize];
  1216. }
  1217. else
  1218. m_tempBufferOut = nullptr;
  1219. }
  1220. // -------------------------------------------------------------------
  1221. // OSC stuff
  1222. /*!
  1223. * Register this plugin to the engine's OSC controller.
  1224. */
  1225. void registerToOscControl()
  1226. {
  1227. if (! x_engine->isOscControlRegisted())
  1228. return;
  1229. #ifndef BUILD_BRIDGE
  1230. x_engine->osc_send_control_add_plugin_start(m_id, m_name);
  1231. #endif
  1232. // Base data
  1233. {
  1234. char bufName[STR_MAX] = { 0 };
  1235. char bufLabel[STR_MAX] = { 0 };
  1236. char bufMaker[STR_MAX] = { 0 };
  1237. char bufCopyright[STR_MAX] = { 0 };
  1238. getRealName(bufName);
  1239. getLabel(bufLabel);
  1240. getMaker(bufMaker);
  1241. getCopyright(bufCopyright);
  1242. #ifdef BUILD_BRIDGE
  1243. x_engine->osc_send_bridge_plugin_info(category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  1244. #else
  1245. x_engine->osc_send_control_set_plugin_data(m_id, m_type, category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  1246. #endif
  1247. }
  1248. // Base count
  1249. {
  1250. uint32_t cIns, cOuts, cTotals;
  1251. getParameterCountInfo(&cIns, &cOuts, &cTotals);
  1252. #ifdef BUILD_BRIDGE
  1253. x_engine->osc_send_bridge_audio_count(audioInCount(), audioOutCount(), audioInCount() + audioOutCount());
  1254. x_engine->osc_send_bridge_midi_count(midiInCount(), midiOutCount(), midiInCount() + midiOutCount());
  1255. x_engine->osc_send_bridge_parameter_count(cIns, cOuts, cTotals);
  1256. #else
  1257. x_engine->osc_send_control_set_plugin_ports(m_id, audioInCount(), audioOutCount(), midiInCount(), midiOutCount(), cIns, cOuts, cTotals);
  1258. #endif
  1259. }
  1260. // Plugin Parameters
  1261. #ifdef BUILD_BRIDGE
  1262. uint32_t maxParameters = MAX_PARAMETERS;
  1263. #else
  1264. uint32_t maxParameters = carlaOptions.maxParameters;
  1265. #endif
  1266. if (param.count > 0 && param.count < maxParameters)
  1267. {
  1268. char bufName[STR_MAX], bufUnit[STR_MAX];
  1269. for (uint32_t i=0; i < param.count; i++)
  1270. {
  1271. getParameterName(i, bufName);
  1272. getParameterUnit(i, bufUnit);
  1273. #ifdef BUILD_BRIDGE
  1274. x_engine->osc_send_bridge_parameter_info(i, bufName, bufUnit);
  1275. x_engine->osc_send_bridge_parameter_data(i, param.data[i].type, param.data[i].rindex, param.data[i].hints, param.data[i].midiChannel, param.data[i].midiCC);
  1276. x_engine->osc_send_bridge_parameter_ranges(i, param.ranges[i].def, param.ranges[i].min, param.ranges[i].max, param.ranges[i].step, param.ranges[i].stepSmall, param.ranges[i].stepLarge);
  1277. x_engine->osc_send_bridge_set_parameter_value(i, getParameterValue(i));
  1278. #else
  1279. x_engine->osc_send_control_set_parameter_data(m_id, i, param.data[i].type, param.data[i].hints, bufName, bufUnit, getParameterValue(i));
  1280. x_engine->osc_send_control_set_parameter_ranges(m_id, i, param.ranges[i].min, param.ranges[i].max, param.ranges[i].def, param.ranges[i].step, param.ranges[i].stepSmall, param.ranges[i].stepLarge);
  1281. x_engine->osc_send_control_set_parameter_midi_cc(m_id, i, param.data[i].midiCC);
  1282. x_engine->osc_send_control_set_parameter_midi_channel(m_id, i, param.data[i].midiChannel);
  1283. x_engine->osc_send_control_set_parameter_value(m_id, i, getParameterValue(i));
  1284. #endif
  1285. }
  1286. }
  1287. // Programs
  1288. if (prog.count > 0)
  1289. {
  1290. #ifdef BUILD_BRIDGE
  1291. x_engine->osc_send_bridge_program_count(prog.count);
  1292. for (uint32_t i=0; i < prog.count; i++)
  1293. x_engine->osc_send_bridge_program_info(i, prog.names[i]);
  1294. x_engine->osc_send_bridge_set_program(prog.current);
  1295. #else
  1296. x_engine->osc_send_control_set_program_count(m_id, prog.count);
  1297. for (uint32_t i=0; i < prog.count; i++)
  1298. x_engine->osc_send_control_set_program_name(m_id, i, prog.names[i]);
  1299. x_engine->osc_send_control_set_program(m_id, prog.current);
  1300. #endif
  1301. }
  1302. // MIDI Programs
  1303. if (midiprog.count > 0)
  1304. {
  1305. #ifdef BUILD_BRIDGE
  1306. x_engine->osc_send_bridge_midi_program_count(midiprog.count);
  1307. for (uint32_t i=0; i < midiprog.count; i++)
  1308. x_engine->osc_send_bridge_midi_program_info(i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  1309. x_engine->osc_send_bridge_set_midi_program(prog.current);
  1310. #else
  1311. x_engine->osc_send_control_set_midi_program_count(m_id, midiprog.count);
  1312. for (uint32_t i=0; i < midiprog.count; i++)
  1313. x_engine->osc_send_control_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  1314. x_engine->osc_send_control_set_midi_program(m_id, midiprog.current);
  1315. #endif
  1316. }
  1317. #ifndef BUILD_BRIDGE
  1318. x_engine->osc_send_control_add_plugin_end(m_id);
  1319. // Internal Parameters
  1320. {
  1321. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0 : 0.0);
  1322. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, x_dryWet);
  1323. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, x_volume);
  1324. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, x_balanceLeft);
  1325. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, x_balanceRight);
  1326. }
  1327. #endif
  1328. }
  1329. #ifndef BUILD_BRIDGE
  1330. /*!
  1331. * Update the plugin's internal OSC data according to \a source and \a url.\n
  1332. * This is used for OSC-GUI bridges.
  1333. */
  1334. void updateOscData(const lo_address source, const char* const url)
  1335. {
  1336. // FIXME - remove debug prints later
  1337. qWarning("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
  1338. const char* host;
  1339. const char* port;
  1340. const int proto = lo_address_get_protocol(source);
  1341. osc.data.free();
  1342. host = lo_address_get_hostname(source);
  1343. port = lo_address_get_port(source);
  1344. osc.data.source = lo_address_new_with_proto(proto, host, port);
  1345. qWarning("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  1346. host = lo_url_get_hostname(url);
  1347. port = lo_url_get_port(url);
  1348. osc.data.path = lo_url_get_path(url);
  1349. osc.data.target = lo_address_new_with_proto(proto, host, port);
  1350. qWarning("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, osc.data.path);
  1351. free((void*)host);
  1352. free((void*)port);
  1353. if (m_hints & PLUGIN_IS_BRIDGE)
  1354. return;
  1355. osc_send_sample_rate(&osc.data, x_engine->getSampleRate());
  1356. for (size_t i=0; i < custom.size(); i++)
  1357. {
  1358. // TODO
  1359. //if (m_type == PLUGIN_LV2)
  1360. //osc_send_lv2_transfer_event(&osc.data, getCustomDataTypeString(custom[i].type), /*custom[i].key,*/ custom[i].value);
  1361. //else
  1362. if (custom[i].type == CUSTOM_DATA_STRING)
  1363. osc_send_configure(&osc.data, custom[i].key, custom[i].value);
  1364. }
  1365. if (prog.current >= 0)
  1366. osc_send_program(&osc.data, prog.current);
  1367. if (midiprog.current >= 0)
  1368. {
  1369. if (m_type == PLUGIN_DSSI)
  1370. osc_send_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  1371. else
  1372. osc_send_midi_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  1373. }
  1374. for (uint32_t i=0; i < param.count; i++)
  1375. osc_send_control(&osc.data, param.data[i].rindex, getParameterValue(i));
  1376. qWarning("CarlaPlugin::updateOscData() - done");
  1377. }
  1378. /*!
  1379. * Free the plugin's internal OSC memory data.
  1380. */
  1381. void freeOscData()
  1382. {
  1383. osc.data.free();
  1384. }
  1385. /*!
  1386. * Show the plugin's OSC based GUI.\n
  1387. * This is a handy function that waits for the GUI to respond and automatically asks it to show itself.
  1388. */
  1389. bool showOscGui()
  1390. {
  1391. qWarning("CarlaPlugin::showOscGui()");
  1392. // wait for UI 'update' call
  1393. for (uint i=0; i < carlaOptions.oscUiTimeout; i++)
  1394. {
  1395. if (osc.data.target)
  1396. {
  1397. qWarning("CarlaPlugin::showOscGui() - got response, asking UI to show itself now");
  1398. osc_send_show(&osc.data);
  1399. return true;
  1400. }
  1401. else
  1402. carla_msleep(100);
  1403. }
  1404. qWarning("CarlaPlugin::showOscGui() - Timeout while waiting for UI to respond");
  1405. return false;
  1406. }
  1407. #endif
  1408. // -------------------------------------------------------------------
  1409. // MIDI events
  1410. /*!
  1411. * Send a single midi note to be processed in the next audio callback.\n
  1412. * A note with 0 velocity means note-off.
  1413. */
  1414. void sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  1415. {
  1416. CARLA_ASSERT(channel < 16);
  1417. CARLA_ASSERT(note < 128);
  1418. CARLA_ASSERT(velo < 128);
  1419. if (! m_active)
  1420. return;
  1421. engineMidiLock();
  1422. for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++)
  1423. {
  1424. if (extMidiNotes[i].channel < 0)
  1425. {
  1426. extMidiNotes[i].channel = channel;
  1427. extMidiNotes[i].note = note;
  1428. extMidiNotes[i].velo = velo;
  1429. break;
  1430. }
  1431. }
  1432. engineMidiUnlock();
  1433. if (sendGui)
  1434. {
  1435. if (velo > 0)
  1436. uiNoteOn(channel, note, velo);
  1437. else
  1438. uiNoteOff(channel, note);
  1439. }
  1440. #ifndef BUILD_BRIDGE
  1441. if (sendOsc)
  1442. {
  1443. if (velo > 0)
  1444. x_engine->osc_send_control_note_on(m_id, channel, note, velo);
  1445. else
  1446. x_engine->osc_send_control_note_off(m_id, channel, note);
  1447. }
  1448. #else
  1449. Q_UNUSED(sendOsc);
  1450. #endif
  1451. if (sendCallback)
  1452. x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo);
  1453. }
  1454. /*!
  1455. * Send all midi notes off for the next audio callback.\n
  1456. * This doesn't send the actual MIDI All-Notes-Off event, but 128 note-offs instead.
  1457. */
  1458. void sendMidiAllNotesOff()
  1459. {
  1460. engineMidiLock();
  1461. postEvents.mutex.lock();
  1462. unsigned short postPad = 0;
  1463. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1464. {
  1465. if (postEvents.data[i].type == PluginPostEventNull)
  1466. {
  1467. postPad = i;
  1468. break;
  1469. }
  1470. }
  1471. if (postPad == MAX_POST_EVENTS - 1)
  1472. {
  1473. qWarning("post-events buffer full, making room for all notes off now");
  1474. postPad -= 128;
  1475. }
  1476. for (unsigned short i=0; i < 128; i++)
  1477. {
  1478. extMidiNotes[i].channel = m_ctrlInChannel;
  1479. extMidiNotes[i].note = i;
  1480. extMidiNotes[i].velo = 0;
  1481. postEvents.data[i + postPad].type = PluginPostEventNoteOff;
  1482. postEvents.data[i + postPad].value1 = m_ctrlInChannel;
  1483. postEvents.data[i + postPad].value2 = i;
  1484. postEvents.data[i + postPad].value3 = 0.0;
  1485. }
  1486. postEvents.mutex.unlock();
  1487. engineMidiUnlock();
  1488. }
  1489. // -------------------------------------------------------------------
  1490. // Post-poned events
  1491. /*!
  1492. * Post pone an event of type \a type.\n
  1493. * The event will be processed later, but as soon as possible.
  1494. */
  1495. void postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata = nullptr)
  1496. {
  1497. postEvents.mutex.lock();
  1498. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1499. {
  1500. if (postEvents.data[i].type == PluginPostEventNull)
  1501. {
  1502. postEvents.data[i].type = type;
  1503. postEvents.data[i].value1 = value1;
  1504. postEvents.data[i].value2 = value2;
  1505. postEvents.data[i].value3 = value3;
  1506. postEvents.data[i].cdata = cdata;
  1507. break;
  1508. }
  1509. }
  1510. postEvents.mutex.unlock();
  1511. }
  1512. /*!
  1513. * Process all the post-poned events.
  1514. * This function will only be called from the main thread if PLUGIN_USES_SINGLE_THREAD is set.
  1515. */
  1516. void postEventsRun()
  1517. {
  1518. PluginPostEvent newPostEvents[MAX_POST_EVENTS];
  1519. // Make a safe copy of events, and clear them
  1520. postEvents.mutex.lock();
  1521. memcpy(newPostEvents, postEvents.data, sizeof(PluginPostEvent)*MAX_POST_EVENTS);
  1522. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  1523. postEvents.data[i].type = PluginPostEventNull;
  1524. postEvents.mutex.unlock();
  1525. // Handle events now
  1526. for (uint32_t i=0; i < MAX_POST_EVENTS; i++)
  1527. {
  1528. const PluginPostEvent* const event = &newPostEvents[i];
  1529. switch (event->type)
  1530. {
  1531. case PluginPostEventNull:
  1532. break;
  1533. case PluginPostEventDebug:
  1534. x_engine->callback(CALLBACK_DEBUG, m_id, event->value1, event->value2, event->value3);
  1535. break;
  1536. case PluginPostEventParameterChange:
  1537. // Update UI
  1538. if (event->value1 >= 0)
  1539. uiParameterChange(event->value1, event->value3);
  1540. #ifndef BUILD_BRIDGE
  1541. // Update OSC control client
  1542. if (x_engine->isOscControlRegisted())
  1543. x_engine->osc_send_control_set_parameter_value(m_id, event->value1, event->value3);
  1544. #endif
  1545. // Update Host
  1546. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, event->value1, 0, event->value3);
  1547. break;
  1548. case PluginPostEventProgramChange:
  1549. // Update UI
  1550. if (event->value1 >= 0)
  1551. uiProgramChange(event->value1);
  1552. #ifndef BUILD_BRIDGE
  1553. // Update OSC control client
  1554. if (x_engine->isOscControlRegisted())
  1555. {
  1556. x_engine->osc_send_control_set_program(m_id, event->value1);
  1557. for (uint32_t j=0; j < param.count; j++)
  1558. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1559. }
  1560. #endif
  1561. // Update Host
  1562. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1563. break;
  1564. case PluginPostEventMidiProgramChange:
  1565. // Update UI
  1566. if (event->value1 >= 0)
  1567. uiMidiProgramChange(event->value1);
  1568. #ifndef BUILD_BRIDGE
  1569. // Update OSC control client
  1570. if (x_engine->isOscControlRegisted())
  1571. {
  1572. x_engine->osc_send_control_set_midi_program(m_id, event->value1);
  1573. for (uint32_t j=0; j < param.count; j++)
  1574. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1575. }
  1576. #endif
  1577. // Update Host
  1578. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1579. break;
  1580. case PluginPostEventNoteOn:
  1581. // Update UI
  1582. uiNoteOn(event->value1, event->value2, rint(event->value3));
  1583. #ifndef BUILD_BRIDGE
  1584. // Update OSC control client
  1585. if (x_engine->isOscControlRegisted())
  1586. x_engine->osc_send_control_note_on(m_id, event->value1, event->value2, rint(event->value3));
  1587. #endif
  1588. // Update Host
  1589. x_engine->callback(CALLBACK_NOTE_ON, m_id, event->value1, event->value2, rint(event->value3));
  1590. break;
  1591. case PluginPostEventNoteOff:
  1592. // Update UI
  1593. uiNoteOff(event->value1, event->value2);
  1594. #ifndef BUILD_BRIDGE
  1595. // Update OSC control client
  1596. if (x_engine->isOscControlRegisted())
  1597. x_engine->osc_send_control_note_off(m_id, event->value1, event->value2);
  1598. #endif
  1599. // Update Host
  1600. x_engine->callback(CALLBACK_NOTE_OFF, m_id, event->value1, event->value2, 0.0);
  1601. break;
  1602. case PluginPostEventCustom:
  1603. // Handle custom event
  1604. postEventHandleCustom(event->value1, event->value2, event->value3, event->cdata);
  1605. break;
  1606. }
  1607. }
  1608. }
  1609. /*!
  1610. * Handle custom post event.\n
  1611. * Implementation depends on plugin type.
  1612. */
  1613. virtual void postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  1614. {
  1615. Q_UNUSED(value1);
  1616. Q_UNUSED(value2);
  1617. Q_UNUSED(value3);
  1618. Q_UNUSED(cdata);
  1619. }
  1620. /*!
  1621. * Tell the UI a parameter has changed.
  1622. */
  1623. virtual void uiParameterChange(const uint32_t index, const double value)
  1624. {
  1625. CARLA_ASSERT(index < param.count);
  1626. Q_UNUSED(value);
  1627. }
  1628. /*!
  1629. * Tell the UI the current program has changed.
  1630. */
  1631. virtual void uiProgramChange(const uint32_t index)
  1632. {
  1633. CARLA_ASSERT(index < prog.count);
  1634. }
  1635. /*!
  1636. * Tell the UI the current midi program has changed.
  1637. */
  1638. virtual void uiMidiProgramChange(const uint32_t index)
  1639. {
  1640. CARLA_ASSERT(index < midiprog.count);
  1641. }
  1642. /*!
  1643. * Tell the UI a note has been pressed.
  1644. */
  1645. virtual void uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1646. {
  1647. CARLA_ASSERT(channel < 16);
  1648. CARLA_ASSERT(note < 128);
  1649. CARLA_ASSERT(velo > 0 && velo < 128);
  1650. }
  1651. /*!
  1652. * Tell the UI a note has been released.
  1653. */
  1654. virtual void uiNoteOff(const uint8_t channel, const uint8_t note)
  1655. {
  1656. CARLA_ASSERT(channel < 16);
  1657. CARLA_ASSERT(note < 128);
  1658. }
  1659. // -------------------------------------------------------------------
  1660. // Cleanup
  1661. /*!
  1662. * Clear the engine client ports of the plugin.
  1663. */
  1664. virtual void removeClientPorts()
  1665. {
  1666. qDebug("CarlaPlugin::removeClientPorts() - start");
  1667. for (uint32_t i=0; i < aIn.count; i++)
  1668. {
  1669. delete aIn.ports[i];
  1670. aIn.ports[i] = nullptr;
  1671. }
  1672. for (uint32_t i=0; i < aOut.count; i++)
  1673. {
  1674. delete aOut.ports[i];
  1675. aOut.ports[i] = nullptr;
  1676. }
  1677. if (midi.portMin)
  1678. {
  1679. delete midi.portMin;
  1680. midi.portMin = nullptr;
  1681. }
  1682. if (midi.portMout)
  1683. {
  1684. delete midi.portMout;
  1685. midi.portMout = nullptr;
  1686. }
  1687. if (param.portCin)
  1688. {
  1689. delete param.portCin;
  1690. param.portCin = nullptr;
  1691. }
  1692. if (param.portCout)
  1693. {
  1694. delete param.portCout;
  1695. param.portCout = nullptr;
  1696. }
  1697. qDebug("CarlaPlugin::removeClientPorts() - end");
  1698. }
  1699. /*!
  1700. * Initialize all RT buffers of the plugin.
  1701. */
  1702. virtual void initBuffers()
  1703. {
  1704. for (uint32_t i=0; i < aIn.count; i++)
  1705. {
  1706. if (aIn.ports[i])
  1707. aIn.ports[i]->initBuffer(x_engine);
  1708. }
  1709. for (uint32_t i=0; i < aOut.count; i++)
  1710. {
  1711. if (aOut.ports[i])
  1712. aOut.ports[i]->initBuffer(x_engine);
  1713. }
  1714. if (param.portCin)
  1715. param.portCin->initBuffer(x_engine);
  1716. if (param.portCout)
  1717. param.portCout->initBuffer(x_engine);
  1718. if (midi.portMin)
  1719. midi.portMin->initBuffer(x_engine);
  1720. if (midi.portMout)
  1721. midi.portMout->initBuffer(x_engine);
  1722. }
  1723. /*!
  1724. * Delete all temporary buffers of the plugin.
  1725. */
  1726. virtual void deleteBuffers()
  1727. {
  1728. qDebug("CarlaPlugin::deleteBuffers() - start");
  1729. if (aIn.count > 0)
  1730. {
  1731. delete[] aIn.ports;
  1732. delete[] aIn.rindexes;
  1733. }
  1734. if (aOut.count > 0)
  1735. {
  1736. delete[] aOut.ports;
  1737. delete[] aOut.rindexes;
  1738. }
  1739. if (param.count > 0)
  1740. {
  1741. delete[] param.data;
  1742. delete[] param.ranges;
  1743. }
  1744. aIn.count = 0;
  1745. aIn.ports = nullptr;
  1746. aIn.rindexes = nullptr;
  1747. aOut.count = 0;
  1748. aOut.ports = nullptr;
  1749. aOut.rindexes = nullptr;
  1750. param.count = 0;
  1751. param.data = nullptr;
  1752. param.ranges = nullptr;
  1753. param.portCin = nullptr;
  1754. param.portCout = nullptr;
  1755. qDebug("CarlaPlugin::deleteBuffers() - end");
  1756. }
  1757. // -------------------------------------------------------------------
  1758. // Library functions
  1759. /*!
  1760. * Open the DLL \a filename.
  1761. */
  1762. bool libOpen(const char* const filename)
  1763. {
  1764. m_lib = lib_open(filename);
  1765. return bool(m_lib);
  1766. }
  1767. /*!
  1768. * Close the DLL previously loaded in libOpen().
  1769. */
  1770. bool libClose()
  1771. {
  1772. if (m_lib)
  1773. return lib_close(m_lib);
  1774. return false;
  1775. }
  1776. /*!
  1777. * Get the symbol entry \a symbol of the currently loaded DLL.
  1778. */
  1779. void* libSymbol(const char* const symbol)
  1780. {
  1781. if (m_lib)
  1782. return lib_symbol(m_lib, symbol);
  1783. return nullptr;
  1784. }
  1785. /*!
  1786. * Get the last DLL related error.
  1787. */
  1788. const char* libError(const char* const filename)
  1789. {
  1790. return lib_error(filename);
  1791. }
  1792. // -------------------------------------------------------------------
  1793. // Locks
  1794. void engineProcessLock()
  1795. {
  1796. x_engine->processLock();
  1797. }
  1798. void engineProcessUnlock()
  1799. {
  1800. x_engine->processUnlock();
  1801. }
  1802. void engineMidiLock()
  1803. {
  1804. x_engine->midiLock();
  1805. }
  1806. void engineMidiUnlock()
  1807. {
  1808. x_engine->midiUnlock();
  1809. }
  1810. // -------------------------------------------------------------------
  1811. // Plugin initializers
  1812. struct initializer {
  1813. CarlaEngine* const engine;
  1814. const char* const filename;
  1815. const char* const name;
  1816. const char* const label;
  1817. };
  1818. static CarlaPlugin* newLADSPA(const initializer& init, const void* const extra);
  1819. static CarlaPlugin* newDSSI(const initializer& init, const void* const extra);
  1820. static CarlaPlugin* newLV2(const initializer& init);
  1821. static CarlaPlugin* newVST(const initializer& init);
  1822. static CarlaPlugin* newGIG(const initializer& init);
  1823. static CarlaPlugin* newSF2(const initializer& init);
  1824. static CarlaPlugin* newSFZ(const initializer& init);
  1825. #ifndef BUILD_BRIDGE
  1826. static CarlaPlugin* newBridge(const initializer& init, const BinaryType btype, const PluginType ptype);
  1827. #endif
  1828. static CarlaPlugin* newNative(const initializer& init);
  1829. static size_t getNativePluginCount();
  1830. static const PluginDescriptor* getNativePlugin(size_t index);
  1831. // -------------------------------------------------------------------
  1832. /*!
  1833. * \class ScopedDisabler
  1834. *
  1835. * \brief Carla plugin scoped disabler
  1836. *
  1837. * This is a handy class that temporarily disables a plugin during a function scope.\n
  1838. * It should be used when the plugin needs reload or state change, something like this:
  1839. * \code
  1840. * {
  1841. * const CarlaPlugin::ScopedDisabler m(plugin);
  1842. * plugin->setChunkData(data);
  1843. * }
  1844. * \endcode
  1845. */
  1846. class ScopedDisabler
  1847. {
  1848. public:
  1849. /*!
  1850. * Disable plugin \a plugin if \a disable is true.
  1851. * The plugin is re-enabled in the deconstructor of this class if \a disable is true.
  1852. *
  1853. * \param plugin The plugin to disable
  1854. * \param disable Wherever to disable the plugin or not, true by default
  1855. */
  1856. ScopedDisabler(CarlaPlugin* const plugin, const bool disable = true)
  1857. : m_plugin(plugin),
  1858. m_disable(disable)
  1859. {
  1860. if (m_disable)
  1861. {
  1862. m_plugin->engineProcessLock();
  1863. m_plugin->setEnabled(false);
  1864. m_plugin->engineProcessUnlock();
  1865. }
  1866. }
  1867. ~ScopedDisabler()
  1868. {
  1869. if (m_disable)
  1870. {
  1871. m_plugin->engineProcessLock();
  1872. m_plugin->setEnabled(true);
  1873. m_plugin->engineProcessUnlock();
  1874. }
  1875. }
  1876. private:
  1877. CarlaPlugin* const m_plugin;
  1878. const bool m_disable;
  1879. };
  1880. // -------------------------------------------------------------------
  1881. protected:
  1882. unsigned short m_id;
  1883. CarlaEngine* const x_engine;
  1884. CarlaEngineClient* x_client;
  1885. double x_dryWet, x_volume;
  1886. double x_balanceLeft, x_balanceRight;
  1887. PluginType m_type;
  1888. unsigned int m_hints;
  1889. bool m_active;
  1890. bool m_activeBefore;
  1891. bool m_enabled;
  1892. void* m_lib;
  1893. const char* m_name;
  1894. const char* m_filename;
  1895. int8_t m_ctrlInChannel;
  1896. uint32_t m_latency;
  1897. float** m_tempBufferIn;
  1898. float** m_tempBufferOut;
  1899. // -------------------------------------------------------------------
  1900. // Storage Data
  1901. PluginAudioData aIn;
  1902. PluginAudioData aOut;
  1903. PluginMidiData midi;
  1904. PluginParameterData param;
  1905. PluginProgramData prog;
  1906. PluginMidiProgramData midiprog;
  1907. std::vector<CustomData> custom;
  1908. // -------------------------------------------------------------------
  1909. // Extra
  1910. #ifndef BUILD_BRIDGE
  1911. struct {
  1912. CarlaOscData data;
  1913. CarlaPluginThread* thread;
  1914. } osc;
  1915. #endif
  1916. struct {
  1917. QMutex mutex;
  1918. PluginPostEvent data[MAX_POST_EVENTS];
  1919. } postEvents;
  1920. ExternalMidiNote extMidiNotes[MAX_MIDI_EVENTS];
  1921. // -------------------------------------------------------------------
  1922. // Utilities
  1923. static unsigned int m_count;
  1924. static double fixParameterValue(double& value, const ParameterRanges& ranges)
  1925. {
  1926. if (value < ranges.min)
  1927. value = ranges.min;
  1928. else if (value > ranges.max)
  1929. value = ranges.max;
  1930. return value;
  1931. }
  1932. static float fixParameterValue(float& value, const ParameterRanges& ranges)
  1933. {
  1934. if (value < ranges.min)
  1935. value = ranges.min;
  1936. else if (value > ranges.max)
  1937. value = ranges.max;
  1938. return value;
  1939. }
  1940. static double abs(const double& value)
  1941. {
  1942. return (value < 0.0) ? -value : value;
  1943. }
  1944. friend class CarlaEngineJack;
  1945. };
  1946. /**@}*/
  1947. CARLA_BACKEND_END_NAMESPACE
  1948. #endif // CARLA_PLUGIN_H