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.

2260 lines
62KB

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