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.

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