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.

1544 lines
40KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the COPYING file
  16. */
  17. #include "carla_plugin.hpp"
  18. #include "carla_lib_utils.hpp"
  19. CARLA_BACKEND_START_NAMESPACE
  20. // -------------------------------------------------------------------
  21. // fallback data
  22. static ParameterData paramDataNull;
  23. static ParameterRanges paramRangesNull;
  24. static MidiProgramData midiProgramDataNull;
  25. static CustomData customDataNull;
  26. // -------------------------------------------------------------------
  27. CarlaPlugin::CarlaPlugin(CarlaEngine* const engine, const unsigned short id)
  28. : m_id(id),
  29. x_engine(engine),
  30. x_client(nullptr),
  31. x_dryWet(1.0),
  32. x_volume(1.0),
  33. x_balanceLeft(-1.0),
  34. x_balanceRight(1.0)
  35. {
  36. CARLA_ASSERT(engine);
  37. CARLA_ASSERT(id < x_engine->maxPluginNumber());
  38. qDebug("CarlaPlugin::CarlaPlugin(%p, %i)", engine, id);
  39. m_type = PLUGIN_NONE;
  40. m_hints = 0;
  41. m_active = false;
  42. m_activeBefore = false;
  43. m_enabled = false;
  44. m_lib = nullptr;
  45. m_name = nullptr;
  46. m_filename = nullptr;
  47. // options
  48. m_ctrlInChannel = 0;
  49. m_fixedBufferSize = true;
  50. #ifdef BUILD_BRIDGE
  51. m_processHighPrecision = false;
  52. #else
  53. m_processHighPrecision = x_engine->processHighPrecision();
  54. if (engine->processMode() == PROCESS_MODE_CONTINUOUS_RACK)
  55. m_ctrlInChannel = m_id;
  56. #endif
  57. // latency
  58. m_latency = 0;
  59. m_latencyBuffers = nullptr;
  60. #ifndef BUILD_BRIDGE
  61. osc.data.path = nullptr;
  62. osc.data.source = nullptr;
  63. osc.data.target = nullptr;
  64. osc.thread = nullptr;
  65. #endif
  66. }
  67. CarlaPlugin::~CarlaPlugin()
  68. {
  69. qDebug("CarlaPlugin::~CarlaPlugin()");
  70. // Remove client and ports
  71. if (x_client)
  72. {
  73. if (x_client->isActive())
  74. x_client->deactivate();
  75. removeClientPorts();
  76. delete x_client;
  77. }
  78. // Delete data
  79. deleteBuffers();
  80. // Unload DLL
  81. libClose();
  82. if (m_name)
  83. free((void*)m_name);
  84. if (m_filename)
  85. free((void*)m_filename);
  86. if (prog.count > 0)
  87. {
  88. for (uint32_t i=0; i < prog.count; i++)
  89. {
  90. if (prog.names[i])
  91. free((void*)prog.names[i]);
  92. }
  93. delete[] prog.names;
  94. }
  95. if (midiprog.count > 0)
  96. {
  97. for (uint32_t i=0; i < midiprog.count; i++)
  98. {
  99. if (midiprog.data[i].name)
  100. free((void*)midiprog.data[i].name);
  101. }
  102. delete[] midiprog.data;
  103. }
  104. if (custom.size() > 0)
  105. {
  106. for (size_t i=0; i < custom.size(); i++)
  107. {
  108. if (custom[i].key)
  109. free((void*)custom[i].key);
  110. if (custom[i].value)
  111. free((void*)custom[i].value);
  112. }
  113. custom.clear();
  114. }
  115. if (m_latencyBuffers)
  116. {
  117. for (uint32_t i=0; i < aIn.count; i++)
  118. delete[] m_latencyBuffers[i];
  119. delete[] m_latencyBuffers;
  120. }
  121. }
  122. // -------------------------------------------------------------------
  123. // Information (base)
  124. PluginType CarlaPlugin::type() const
  125. {
  126. return m_type;
  127. }
  128. unsigned short CarlaPlugin::id() const
  129. {
  130. return m_id;
  131. }
  132. unsigned int CarlaPlugin::hints() const
  133. {
  134. return m_hints;
  135. }
  136. bool CarlaPlugin::enabled() const
  137. {
  138. return m_enabled;
  139. }
  140. const char* CarlaPlugin::name() const
  141. {
  142. return m_name;
  143. }
  144. const char* CarlaPlugin::filename() const
  145. {
  146. return m_filename;
  147. }
  148. PluginCategory CarlaPlugin::category()
  149. {
  150. return PLUGIN_CATEGORY_NONE;
  151. }
  152. long CarlaPlugin::uniqueId()
  153. {
  154. return 0;
  155. }
  156. // -------------------------------------------------------------------
  157. // Information (count)
  158. uint32_t CarlaPlugin::audioInCount()
  159. {
  160. return aIn.count;
  161. }
  162. uint32_t CarlaPlugin::audioOutCount()
  163. {
  164. return aOut.count;
  165. }
  166. uint32_t CarlaPlugin::midiInCount()
  167. {
  168. return midi.portMin ? 1 : 0;
  169. }
  170. uint32_t CarlaPlugin::midiOutCount()
  171. {
  172. return midi.portMout ? 1 : 0;
  173. }
  174. uint32_t CarlaPlugin::parameterCount() const
  175. {
  176. return param.count;
  177. }
  178. uint32_t CarlaPlugin::parameterScalePointCount(const uint32_t parameterId)
  179. {
  180. CARLA_ASSERT(parameterId < param.count);
  181. return 0;
  182. }
  183. uint32_t CarlaPlugin::programCount() const
  184. {
  185. return prog.count;
  186. }
  187. uint32_t CarlaPlugin::midiProgramCount() const
  188. {
  189. return midiprog.count;
  190. }
  191. size_t CarlaPlugin::customDataCount() const
  192. {
  193. return custom.size();
  194. }
  195. // -------------------------------------------------------------------
  196. // Information (current data)
  197. int32_t CarlaPlugin::currentProgram() const
  198. {
  199. return prog.current;
  200. }
  201. int32_t CarlaPlugin::currentMidiProgram() const
  202. {
  203. return midiprog.current;
  204. }
  205. const ParameterData* CarlaPlugin::parameterData(const uint32_t parameterId) const
  206. {
  207. CARLA_ASSERT(parameterId < param.count);
  208. if (parameterId < param.count)
  209. return &param.data[parameterId];
  210. return &paramDataNull;
  211. }
  212. const ParameterRanges* CarlaPlugin::parameterRanges(const uint32_t parameterId) const
  213. {
  214. CARLA_ASSERT(parameterId < param.count);
  215. if (parameterId < param.count)
  216. return &param.ranges[parameterId];
  217. return &paramRangesNull;
  218. }
  219. bool CarlaPlugin::parameterIsOutput(const uint32_t parameterId) const
  220. {
  221. CARLA_ASSERT(parameterId < param.count);
  222. if (parameterId < param.count)
  223. return (param.data[parameterId].type == PARAMETER_OUTPUT);
  224. return false;
  225. }
  226. const MidiProgramData* CarlaPlugin::midiProgramData(const uint32_t index) const
  227. {
  228. CARLA_ASSERT(index < midiprog.count);
  229. if (index < midiprog.count)
  230. return &midiprog.data[index];
  231. return &midiProgramDataNull;
  232. }
  233. const CustomData* CarlaPlugin::customData(const size_t index) const
  234. {
  235. CARLA_ASSERT(index < custom.size());
  236. if (index < custom.size())
  237. return &custom[index];
  238. return &customDataNull;
  239. }
  240. int32_t CarlaPlugin::chunkData(void** const dataPtr)
  241. {
  242. CARLA_ASSERT(dataPtr);
  243. return 0;
  244. }
  245. // -------------------------------------------------------------------
  246. // Information (per-plugin data)
  247. double CarlaPlugin::getParameterValue(const uint32_t parameterId)
  248. {
  249. CARLA_ASSERT(parameterId < param.count);
  250. return 0.0;
  251. }
  252. double CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  253. {
  254. CARLA_ASSERT(parameterId < param.count);
  255. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  256. return 0.0;
  257. }
  258. void CarlaPlugin::getLabel(char* const strBuf)
  259. {
  260. *strBuf = 0;
  261. }
  262. void CarlaPlugin::getMaker(char* const strBuf)
  263. {
  264. *strBuf = 0;
  265. }
  266. void CarlaPlugin::getCopyright(char* const strBuf)
  267. {
  268. *strBuf = 0;
  269. }
  270. void CarlaPlugin::getRealName(char* const strBuf)
  271. {
  272. *strBuf = 0;;
  273. }
  274. void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf)
  275. {
  276. CARLA_ASSERT(parameterId < param.count);
  277. *strBuf = 0;
  278. }
  279. void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf)
  280. {
  281. CARLA_ASSERT(parameterId < param.count);
  282. *strBuf = 0;
  283. }
  284. void CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf)
  285. {
  286. CARLA_ASSERT(parameterId < param.count);
  287. *strBuf = 0;
  288. }
  289. void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf)
  290. {
  291. CARLA_ASSERT(parameterId < param.count);
  292. *strBuf = 0;
  293. }
  294. void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  295. {
  296. CARLA_ASSERT(parameterId < param.count);
  297. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  298. *strBuf = 0;
  299. }
  300. void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf)
  301. {
  302. CARLA_ASSERT(index < prog.count);
  303. if (index < prog.count && prog.names[index])
  304. strncpy(strBuf, prog.names[index], STR_MAX);
  305. else
  306. *strBuf = 0;
  307. }
  308. void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf)
  309. {
  310. CARLA_ASSERT(index < midiprog.count);
  311. if (index < midiprog.count && midiprog.data[index].name)
  312. strncpy(strBuf, midiprog.data[index].name, STR_MAX);
  313. else
  314. *strBuf = 0;
  315. }
  316. void CarlaPlugin::getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total)
  317. {
  318. *ins = 0;
  319. *outs = 0;
  320. *total = param.count;
  321. for (uint32_t i=0; i < param.count; i++)
  322. {
  323. if (param.data[i].type == PARAMETER_INPUT)
  324. *ins += 1;
  325. else if (param.data[i].type == PARAMETER_OUTPUT)
  326. *outs += 1;
  327. }
  328. }
  329. void CarlaPlugin::getGuiInfo(GuiType* const type, bool* const resizable)
  330. {
  331. *type = GUI_NONE;
  332. *resizable = false;
  333. }
  334. // -------------------------------------------------------------------
  335. // Set data (internal stuff)
  336. #ifndef BUILD_BRIDGE
  337. void CarlaPlugin::setId(const unsigned short id)
  338. {
  339. m_id = id;
  340. if (x_engine->processMode() == PROCESS_MODE_CONTINUOUS_RACK)
  341. m_ctrlInChannel = id;
  342. }
  343. #endif
  344. void CarlaPlugin::setEnabled(const bool yesNo)
  345. {
  346. m_enabled = yesNo;
  347. }
  348. void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback)
  349. {
  350. m_active = active;
  351. double value = active ? 1.0 : 0.0;
  352. #ifndef BUILD_BRIDGE
  353. if (sendOsc)
  354. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, value);
  355. #else
  356. Q_UNUSED(sendOsc);
  357. #endif
  358. if (sendCallback)
  359. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_ACTIVE, 0, value, nullptr);
  360. #ifndef BUILD_BRIDGE
  361. else if (m_hints & PLUGIN_IS_BRIDGE)
  362. osc_send_control(&osc.data, PARAMETER_ACTIVE, value);
  363. #endif
  364. }
  365. void CarlaPlugin::setDryWet(double value, const bool sendOsc, const bool sendCallback)
  366. {
  367. CARLA_ASSERT(value >= 0.0 && value <= 1.0);
  368. if (value < 0.0)
  369. value = 0.0;
  370. else if (value > 1.0)
  371. value = 1.0;
  372. x_dryWet = value;
  373. #ifndef BUILD_BRIDGE
  374. if (sendOsc)
  375. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, value);
  376. #else
  377. Q_UNUSED(sendOsc);
  378. #endif
  379. if (sendCallback)
  380. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_DRYWET, 0, value, nullptr);
  381. #ifndef BUILD_BRIDGE
  382. else if (m_hints & PLUGIN_IS_BRIDGE)
  383. osc_send_control(&osc.data, PARAMETER_DRYWET, value);
  384. #endif
  385. }
  386. void CarlaPlugin::setVolume(double value, const bool sendOsc, const bool sendCallback)
  387. {
  388. CARLA_ASSERT(value >= 0.0 && value <= 1.27);
  389. if (value < 0.0)
  390. value = 0.0;
  391. else if (value > 1.27)
  392. value = 1.27;
  393. x_volume = value;
  394. #ifndef BUILD_BRIDGE
  395. if (sendOsc)
  396. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, value);
  397. #else
  398. Q_UNUSED(sendOsc);
  399. #endif
  400. if (sendCallback)
  401. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_VOLUME, 0, value, nullptr);
  402. #ifndef BUILD_BRIDGE
  403. else if (m_hints & PLUGIN_IS_BRIDGE)
  404. osc_send_control(&osc.data, PARAMETER_VOLUME, value);
  405. #endif
  406. }
  407. void CarlaPlugin::setBalanceLeft(double value, const bool sendOsc, const bool sendCallback)
  408. {
  409. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  410. if (value < -1.0)
  411. value = -1.0;
  412. else if (value > 1.0)
  413. value = 1.0;
  414. x_balanceLeft = value;
  415. #ifndef BUILD_BRIDGE
  416. if (sendOsc)
  417. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, value);
  418. #else
  419. Q_UNUSED(sendOsc);
  420. #endif
  421. if (sendCallback)
  422. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_LEFT, 0, value, nullptr);
  423. #ifndef BUILD_BRIDGE
  424. else if (m_hints & PLUGIN_IS_BRIDGE)
  425. osc_send_control(&osc.data, PARAMETER_BALANCE_LEFT, value);
  426. #endif
  427. }
  428. void CarlaPlugin::setBalanceRight(double value, const bool sendOsc, const bool sendCallback)
  429. {
  430. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  431. if (value < -1.0)
  432. value = -1.0;
  433. else if (value > 1.0)
  434. value = 1.0;
  435. x_balanceRight = value;
  436. #ifndef BUILD_BRIDGE
  437. if (sendOsc)
  438. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, value);
  439. #else
  440. Q_UNUSED(sendOsc);
  441. #endif
  442. if (sendCallback)
  443. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_RIGHT, 0, value, nullptr);
  444. #ifndef BUILD_BRIDGE
  445. else if (m_hints & PLUGIN_IS_BRIDGE)
  446. osc_send_control(&osc.data, PARAMETER_BALANCE_RIGHT, value);
  447. #endif
  448. }
  449. #ifndef BUILD_BRIDGE
  450. int CarlaPlugin::setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types)
  451. {
  452. return 1;
  453. Q_UNUSED(type);
  454. Q_UNUSED(argc);
  455. Q_UNUSED(argv);
  456. Q_UNUSED(types);
  457. }
  458. #endif
  459. // -------------------------------------------------------------------
  460. // Set data (plugin-specific stuff)
  461. void CarlaPlugin::setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  462. {
  463. CARLA_ASSERT(parameterId < param.count);
  464. if (sendGui)
  465. uiParameterChange(parameterId, value);
  466. #ifndef BUILD_BRIDGE
  467. if (sendOsc)
  468. x_engine->osc_send_control_set_parameter_value(m_id, parameterId, value);
  469. #else
  470. Q_UNUSED(sendOsc);
  471. #endif
  472. if (sendCallback)
  473. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, parameterId, 0, value, nullptr);
  474. }
  475. void CarlaPlugin::setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  476. {
  477. CARLA_ASSERT(rindex >= PARAMETER_BALANCE_RIGHT && rindex != PARAMETER_NULL);
  478. if (rindex == PARAMETER_ACTIVE)
  479. return setActive(value > 0.0, sendOsc, sendCallback);
  480. if (rindex == PARAMETER_DRYWET)
  481. return setDryWet(value, sendOsc, sendCallback);
  482. if (rindex == PARAMETER_VOLUME)
  483. return setVolume(value, sendOsc, sendCallback);
  484. if (rindex == PARAMETER_BALANCE_LEFT)
  485. return setBalanceLeft(value, sendOsc, sendCallback);
  486. if (rindex == PARAMETER_BALANCE_RIGHT)
  487. return setBalanceRight(value, sendOsc, sendCallback);
  488. for (uint32_t i=0; i < param.count; i++)
  489. {
  490. if (param.data[i].rindex == rindex)
  491. return setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  492. }
  493. }
  494. void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback)
  495. {
  496. CARLA_ASSERT(parameterId < param.count);
  497. CARLA_ASSERT(channel < 16);
  498. if (channel >= 16)
  499. channel = 16;
  500. param.data[parameterId].midiChannel = channel;
  501. #ifndef BUILD_BRIDGE
  502. if (sendOsc)
  503. x_engine->osc_send_control_set_parameter_midi_channel(m_id, parameterId, channel);
  504. #else
  505. Q_UNUSED(sendOsc);
  506. #endif
  507. if (sendCallback)
  508. x_engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, m_id, parameterId, channel, 0.0, nullptr);
  509. }
  510. void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback)
  511. {
  512. CARLA_ASSERT(parameterId < param.count);
  513. CARLA_ASSERT(cc >= -1);
  514. if (cc < -1 || cc > 0x5F)
  515. cc = -1;
  516. param.data[parameterId].midiCC = cc;
  517. #ifndef BUILD_BRIDGE
  518. if (sendOsc)
  519. x_engine->osc_send_control_set_parameter_midi_cc(m_id, parameterId, cc);
  520. #else
  521. Q_UNUSED(sendOsc);
  522. #endif
  523. if (sendCallback)
  524. x_engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, m_id, parameterId, cc, 0.0, nullptr);
  525. }
  526. void CarlaPlugin::setCustomData(const char* const type, const char* const key, const char* const value, const bool sendGui)
  527. {
  528. CARLA_ASSERT(type);
  529. CARLA_ASSERT(key);
  530. CARLA_ASSERT(value);
  531. if (! type)
  532. return qCritical("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - type is invalid", type, key, value, bool2str(sendGui));
  533. if (! key)
  534. return qCritical("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - key is null", type, key, value, bool2str(sendGui));
  535. if (! value)
  536. return qCritical("CarlaPlugin::setCustomData(\"%s\", \"%s\", \"%s\", %s) - value is null", type, key, value, bool2str(sendGui));
  537. bool saveData = true;
  538. if (strcmp(type, CUSTOM_DATA_STRING) == 0)
  539. {
  540. // Ignore some keys
  541. if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0)
  542. saveData = false;
  543. 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)
  544. saveData = false;
  545. }
  546. if (saveData)
  547. {
  548. // Check if we already have this key
  549. for (size_t i=0; i < custom.size(); i++)
  550. {
  551. if (strcmp(custom[i].key, key) == 0)
  552. {
  553. free((void*)custom[i].value);
  554. custom[i].value = strdup(value);
  555. return;
  556. }
  557. }
  558. // Otherwise store it
  559. CustomData newData;
  560. newData.type = strdup(type);
  561. newData.key = strdup(key);
  562. newData.value = strdup(value);
  563. custom.push_back(newData);
  564. }
  565. }
  566. void CarlaPlugin::setChunkData(const char* const stringData)
  567. {
  568. CARLA_ASSERT(stringData);
  569. }
  570. void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  571. {
  572. CARLA_ASSERT(index >= -1 && index < (int32_t)prog.count);
  573. if (index < -1)
  574. index = -1;
  575. else if (index > (int32_t)prog.count)
  576. return;
  577. prog.current = index;
  578. if (sendGui && index >= 0)
  579. uiProgramChange(index);
  580. // Change default parameter values
  581. if (index >= 0)
  582. {
  583. for (uint32_t i=0; i < param.count; i++)
  584. {
  585. param.ranges[i].def = getParameterValue(i);
  586. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  587. #ifndef BUILD_BRIDGE
  588. if (sendOsc)
  589. {
  590. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  591. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  592. }
  593. #endif
  594. }
  595. }
  596. #ifndef BUILD_BRIDGE
  597. if (sendOsc)
  598. x_engine->osc_send_control_set_program(m_id, index);
  599. #else
  600. Q_UNUSED(sendOsc);
  601. #endif
  602. if (sendCallback)
  603. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, index, 0, 0.0, nullptr);
  604. Q_UNUSED(block);
  605. }
  606. void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  607. {
  608. CARLA_ASSERT(index >= -1 && index < (int32_t)midiprog.count);
  609. if (index < -1)
  610. index = -1;
  611. else if (index > (int32_t)midiprog.count)
  612. return;
  613. midiprog.current = index;
  614. if (sendGui && index >= 0)
  615. uiMidiProgramChange(index);
  616. // Change default parameter values (sound banks never change defaults)
  617. if (index >= 0 && m_type != PLUGIN_GIG && m_type != PLUGIN_SF2 && m_type != PLUGIN_SFZ)
  618. {
  619. for (uint32_t i=0; i < param.count; i++)
  620. {
  621. param.ranges[i].def = getParameterValue(i);
  622. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  623. #ifndef BUILD_BRIDGE
  624. if (sendOsc)
  625. {
  626. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  627. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  628. }
  629. #endif
  630. }
  631. }
  632. #ifndef BUILD_BRIDGE
  633. if (sendOsc)
  634. x_engine->osc_send_control_set_midi_program(m_id, index);
  635. #else
  636. Q_UNUSED(sendOsc);
  637. #endif
  638. if (sendCallback)
  639. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, index, 0, 0.0, nullptr);
  640. Q_UNUSED(block);
  641. }
  642. void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  643. {
  644. CARLA_ASSERT(program < 128);
  645. for (uint32_t i=0; i < midiprog.count; i++)
  646. {
  647. if (midiprog.data[i].bank == bank && midiprog.data[i].program == program)
  648. return setMidiProgram(i, sendGui, sendOsc, sendCallback, block);
  649. }
  650. }
  651. // -------------------------------------------------------------------
  652. // Set gui stuff
  653. void CarlaPlugin::setGuiContainer(GuiContainer* const container)
  654. {
  655. Q_UNUSED(container);
  656. }
  657. void CarlaPlugin::showGui(const bool yesNo)
  658. {
  659. Q_UNUSED(yesNo);
  660. }
  661. void CarlaPlugin::idleGui()
  662. {
  663. if (! m_enabled)
  664. return;
  665. if (m_hints & PLUGIN_USES_SINGLE_THREAD)
  666. {
  667. // Process postponed events
  668. postEventsRun();
  669. // Update parameter outputs
  670. for (uint32_t i=0; i < param.count; i++)
  671. {
  672. if (param.data[i].type == PARAMETER_OUTPUT)
  673. uiParameterChange(i, getParameterValue(i));
  674. }
  675. }
  676. }
  677. // -------------------------------------------------------------------
  678. // Plugin state
  679. void CarlaPlugin::reload()
  680. {
  681. }
  682. void CarlaPlugin::reloadPrograms(const bool init)
  683. {
  684. Q_UNUSED(init);
  685. }
  686. void CarlaPlugin::prepareForSave()
  687. {
  688. }
  689. // -------------------------------------------------------------------
  690. // Plugin processing
  691. void CarlaPlugin::process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset)
  692. {
  693. Q_UNUSED(inBuffer);
  694. Q_UNUSED(outBuffer);
  695. Q_UNUSED(frames);
  696. Q_UNUSED(framesOffset);
  697. }
  698. void CarlaPlugin::bufferSizeChanged(const uint32_t newBufferSize)
  699. {
  700. Q_UNUSED(newBufferSize);
  701. }
  702. void CarlaPlugin::recreateLatencyBuffers()
  703. {
  704. if (m_latencyBuffers)
  705. {
  706. for (uint32_t i=0; i < aIn.count; i++)
  707. delete[] m_latencyBuffers[i];
  708. delete[] m_latencyBuffers;
  709. }
  710. if (aIn.count > 0 && m_latency > 0)
  711. {
  712. m_latencyBuffers = new float* [aIn.count];
  713. for (uint32_t i=0; i < aIn.count; i++)
  714. m_latencyBuffers[i] = new float [m_latency];
  715. }
  716. else
  717. m_latencyBuffers = nullptr;
  718. }
  719. // -------------------------------------------------------------------
  720. // OSC stuff
  721. void CarlaPlugin::registerToOscControl()
  722. {
  723. if (! x_engine->isOscControlRegisted())
  724. return;
  725. #ifndef BUILD_BRIDGE
  726. x_engine->osc_send_control_add_plugin_start(m_id, m_name);
  727. #endif
  728. // Base data
  729. {
  730. char bufName[STR_MAX] = { 0 };
  731. char bufLabel[STR_MAX] = { 0 };
  732. char bufMaker[STR_MAX] = { 0 };
  733. char bufCopyright[STR_MAX] = { 0 };
  734. getRealName(bufName);
  735. getLabel(bufLabel);
  736. getMaker(bufMaker);
  737. getCopyright(bufCopyright);
  738. #ifdef BUILD_BRIDGE
  739. x_engine->osc_send_bridge_plugin_info(category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  740. #else
  741. x_engine->osc_send_control_set_plugin_data(m_id, m_type, category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  742. #endif
  743. }
  744. // Base count
  745. {
  746. uint32_t cIns, cOuts, cTotals;
  747. getParameterCountInfo(&cIns, &cOuts, &cTotals);
  748. #ifdef BUILD_BRIDGE
  749. x_engine->osc_send_bridge_audio_count(audioInCount(), audioOutCount(), audioInCount() + audioOutCount());
  750. x_engine->osc_send_bridge_midi_count(midiInCount(), midiOutCount(), midiInCount() + midiOutCount());
  751. x_engine->osc_send_bridge_parameter_count(cIns, cOuts, cTotals);
  752. #else
  753. x_engine->osc_send_control_set_plugin_ports(m_id, audioInCount(), audioOutCount(), midiInCount(), midiOutCount(), cIns, cOuts, cTotals);
  754. #endif
  755. }
  756. // Plugin Parameters
  757. #ifdef BUILD_BRIDGE
  758. uint32_t maxParameters = MAX_PARAMETERS;
  759. #else
  760. uint32_t maxParameters = x_engine->maxParameters();
  761. #endif
  762. if (param.count > 0 && param.count < maxParameters)
  763. {
  764. char bufName[STR_MAX], bufUnit[STR_MAX];
  765. for (uint32_t i=0; i < param.count; i++)
  766. {
  767. getParameterName(i, bufName);
  768. getParameterUnit(i, bufUnit);
  769. #ifdef BUILD_BRIDGE
  770. x_engine->osc_send_bridge_parameter_info(i, bufName, bufUnit);
  771. 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);
  772. 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);
  773. x_engine->osc_send_bridge_set_parameter_value(i, getParameterValue(i));
  774. #else
  775. x_engine->osc_send_control_set_parameter_data(m_id, i, param.data[i].type, param.data[i].hints, bufName, bufUnit, getParameterValue(i));
  776. 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);
  777. x_engine->osc_send_control_set_parameter_midi_cc(m_id, i, param.data[i].midiCC);
  778. x_engine->osc_send_control_set_parameter_midi_channel(m_id, i, param.data[i].midiChannel);
  779. x_engine->osc_send_control_set_parameter_value(m_id, i, getParameterValue(i));
  780. #endif
  781. }
  782. }
  783. // Programs
  784. if (prog.count > 0)
  785. {
  786. #ifdef BUILD_BRIDGE
  787. x_engine->osc_send_bridge_program_count(prog.count);
  788. for (uint32_t i=0; i < prog.count; i++)
  789. x_engine->osc_send_bridge_program_info(i, prog.names[i]);
  790. x_engine->osc_send_bridge_set_program(prog.current);
  791. #else
  792. x_engine->osc_send_control_set_program_count(m_id, prog.count);
  793. for (uint32_t i=0; i < prog.count; i++)
  794. x_engine->osc_send_control_set_program_name(m_id, i, prog.names[i]);
  795. x_engine->osc_send_control_set_program(m_id, prog.current);
  796. #endif
  797. }
  798. // MIDI Programs
  799. if (midiprog.count > 0)
  800. {
  801. #ifdef BUILD_BRIDGE
  802. x_engine->osc_send_bridge_midi_program_count(midiprog.count);
  803. for (uint32_t i=0; i < midiprog.count; i++)
  804. x_engine->osc_send_bridge_midi_program_info(i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  805. x_engine->osc_send_bridge_set_midi_program(prog.current);
  806. #else
  807. x_engine->osc_send_control_set_midi_program_count(m_id, midiprog.count);
  808. for (uint32_t i=0; i < midiprog.count; i++)
  809. x_engine->osc_send_control_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  810. x_engine->osc_send_control_set_midi_program(m_id, midiprog.current);
  811. #endif
  812. }
  813. #ifndef BUILD_BRIDGE
  814. x_engine->osc_send_control_add_plugin_end(m_id);
  815. // Internal Parameters
  816. {
  817. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0 : 0.0);
  818. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, x_dryWet);
  819. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, x_volume);
  820. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, x_balanceLeft);
  821. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, x_balanceRight);
  822. }
  823. #endif
  824. }
  825. #ifndef BUILD_BRIDGE
  826. void CarlaPlugin::updateOscData(const lo_address source, const char* const url)
  827. {
  828. // FIXME - remove debug prints later
  829. qWarning("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
  830. const char* host;
  831. const char* port;
  832. const int proto = lo_address_get_protocol(source);
  833. osc.data.free();
  834. host = lo_address_get_hostname(source);
  835. port = lo_address_get_port(source);
  836. osc.data.source = lo_address_new_with_proto(proto, host, port);
  837. qWarning("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  838. host = lo_url_get_hostname(url);
  839. port = lo_url_get_port(url);
  840. osc.data.path = lo_url_get_path(url);
  841. osc.data.target = lo_address_new_with_proto(proto, host, port);
  842. qWarning("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, osc.data.path);
  843. free((void*)host);
  844. free((void*)port);
  845. if (m_hints & PLUGIN_IS_BRIDGE)
  846. return;
  847. osc_send_sample_rate(&osc.data, x_engine->getSampleRate());
  848. for (size_t i=0; i < custom.size(); i++)
  849. {
  850. // TODO
  851. //if (m_type == PLUGIN_LV2)
  852. //osc_send_lv2_transfer_event(&osc.data, getCustomDataTypeString(custom[i].type), /*custom[i].key,*/ custom[i].value);
  853. //else
  854. if (custom[i].type == CUSTOM_DATA_STRING)
  855. osc_send_configure(&osc.data, custom[i].key, custom[i].value);
  856. }
  857. if (prog.current >= 0)
  858. osc_send_program(&osc.data, prog.current);
  859. if (midiprog.current >= 0)
  860. {
  861. if (m_type == PLUGIN_DSSI)
  862. osc_send_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  863. else
  864. osc_send_midi_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  865. }
  866. for (uint32_t i=0; i < param.count; i++)
  867. osc_send_control(&osc.data, param.data[i].rindex, getParameterValue(i));
  868. qWarning("CarlaPlugin::updateOscData() - done");
  869. }
  870. void CarlaPlugin::freeOscData()
  871. {
  872. osc.data.free();
  873. }
  874. bool CarlaPlugin::waitForOscGuiShow()
  875. {
  876. qWarning("CarlaPlugin::waitForOscGuiShow()");
  877. // wait for UI 'update' call
  878. for (uint i=0; i < x_engine->oscUiTimeout(); i++)
  879. {
  880. if (osc.data.target)
  881. {
  882. qWarning("CarlaPlugin::waitForOscGuiShow() - got response, asking UI to show itself now");
  883. osc_send_show(&osc.data);
  884. return true;
  885. }
  886. else
  887. carla_msleep(100);
  888. }
  889. qWarning("CarlaPlugin::waitForOscGuiShow() - Timeout while waiting for UI to respond (waited %i msecs)", x_engine->oscUiTimeout());
  890. return false;
  891. }
  892. #endif
  893. // -------------------------------------------------------------------
  894. // MIDI events
  895. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  896. {
  897. CARLA_ASSERT(channel < 16);
  898. CARLA_ASSERT(note < 128);
  899. CARLA_ASSERT(velo < 128);
  900. if (! m_active)
  901. return;
  902. engineMidiLock();
  903. for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++)
  904. {
  905. if (extMidiNotes[i].channel < 0)
  906. {
  907. extMidiNotes[i].channel = channel;
  908. extMidiNotes[i].note = note;
  909. extMidiNotes[i].velo = velo;
  910. break;
  911. }
  912. }
  913. engineMidiUnlock();
  914. if (sendGui)
  915. {
  916. if (velo > 0)
  917. uiNoteOn(channel, note, velo);
  918. else
  919. uiNoteOff(channel, note);
  920. }
  921. #ifndef BUILD_BRIDGE
  922. if (sendOsc)
  923. {
  924. if (velo > 0)
  925. x_engine->osc_send_control_note_on(m_id, channel, note, velo);
  926. else
  927. x_engine->osc_send_control_note_off(m_id, channel, note);
  928. }
  929. #else
  930. Q_UNUSED(sendOsc);
  931. #endif
  932. if (sendCallback)
  933. x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo, nullptr);
  934. }
  935. void CarlaPlugin::sendMidiAllNotesOff()
  936. {
  937. engineMidiLock();
  938. postEvents.mutex.lock();
  939. unsigned short postPad = 0;
  940. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  941. {
  942. if (postEvents.data[i].type == PluginPostEventNull)
  943. {
  944. postPad = i;
  945. break;
  946. }
  947. }
  948. if (postPad == MAX_POST_EVENTS - 1)
  949. {
  950. qWarning("post-events buffer full, making room for all notes off now");
  951. postPad -= 128;
  952. }
  953. for (unsigned short i=0; i < 128; i++)
  954. {
  955. extMidiNotes[i].channel = m_ctrlInChannel;
  956. extMidiNotes[i].note = i;
  957. extMidiNotes[i].velo = 0;
  958. postEvents.data[i + postPad].type = PluginPostEventNoteOff;
  959. postEvents.data[i + postPad].value1 = m_ctrlInChannel;
  960. postEvents.data[i + postPad].value2 = i;
  961. postEvents.data[i + postPad].value3 = 0.0;
  962. }
  963. postEvents.mutex.unlock();
  964. engineMidiUnlock();
  965. }
  966. // -------------------------------------------------------------------
  967. // Post-poned events
  968. void CarlaPlugin::postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  969. {
  970. postEvents.mutex.lock();
  971. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  972. {
  973. if (postEvents.data[i].type == PluginPostEventNull)
  974. {
  975. postEvents.data[i].type = type;
  976. postEvents.data[i].value1 = value1;
  977. postEvents.data[i].value2 = value2;
  978. postEvents.data[i].value3 = value3;
  979. postEvents.data[i].cdata = cdata;
  980. break;
  981. }
  982. }
  983. postEvents.mutex.unlock();
  984. }
  985. void CarlaPlugin::postEventsRun()
  986. {
  987. PluginPostEvent newPostEvents[MAX_POST_EVENTS];
  988. // Make a safe copy of events, and clear them
  989. postEvents.mutex.lock();
  990. memcpy(newPostEvents, postEvents.data, sizeof(PluginPostEvent)*MAX_POST_EVENTS);
  991. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  992. postEvents.data[i].type = PluginPostEventNull;
  993. postEvents.mutex.unlock();
  994. // Handle events now
  995. for (uint32_t i=0; i < MAX_POST_EVENTS; i++)
  996. {
  997. const PluginPostEvent* const event = &newPostEvents[i];
  998. switch (event->type)
  999. {
  1000. case PluginPostEventNull:
  1001. break;
  1002. case PluginPostEventDebug:
  1003. x_engine->callback(CALLBACK_DEBUG, m_id, event->value1, event->value2, event->value3, nullptr);
  1004. break;
  1005. case PluginPostEventParameterChange:
  1006. // Update UI
  1007. if (event->value1 >= 0)
  1008. uiParameterChange(event->value1, event->value3);
  1009. #ifndef BUILD_BRIDGE
  1010. // Update OSC control client
  1011. if (x_engine->isOscControlRegisted())
  1012. x_engine->osc_send_control_set_parameter_value(m_id, event->value1, event->value3);
  1013. #endif
  1014. // Update Host
  1015. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, event->value1, 0, event->value3, nullptr);
  1016. break;
  1017. case PluginPostEventProgramChange:
  1018. // Update UI
  1019. if (event->value1 >= 0)
  1020. uiProgramChange(event->value1);
  1021. #ifndef BUILD_BRIDGE
  1022. // Update OSC control client
  1023. if (x_engine->isOscControlRegisted())
  1024. {
  1025. x_engine->osc_send_control_set_program(m_id, event->value1);
  1026. for (uint32_t j=0; j < param.count; j++)
  1027. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1028. }
  1029. #endif
  1030. // Update Host
  1031. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0, nullptr);
  1032. break;
  1033. case PluginPostEventMidiProgramChange:
  1034. // Update UI
  1035. if (event->value1 >= 0)
  1036. uiMidiProgramChange(event->value1);
  1037. #ifndef BUILD_BRIDGE
  1038. // Update OSC control client
  1039. if (x_engine->isOscControlRegisted())
  1040. {
  1041. x_engine->osc_send_control_set_midi_program(m_id, event->value1);
  1042. for (uint32_t j=0; j < param.count; j++)
  1043. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1044. }
  1045. #endif
  1046. // Update Host
  1047. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0, nullptr);
  1048. break;
  1049. case PluginPostEventNoteOn:
  1050. // Update UI
  1051. uiNoteOn(event->value1, event->value2, rint(event->value3));
  1052. #ifndef BUILD_BRIDGE
  1053. // Update OSC control client
  1054. if (x_engine->isOscControlRegisted())
  1055. x_engine->osc_send_control_note_on(m_id, event->value1, event->value2, rint(event->value3));
  1056. #endif
  1057. // Update Host
  1058. x_engine->callback(CALLBACK_NOTE_ON, m_id, event->value1, event->value2, rint(event->value3), nullptr);
  1059. break;
  1060. case PluginPostEventNoteOff:
  1061. // Update UI
  1062. uiNoteOff(event->value1, event->value2);
  1063. #ifndef BUILD_BRIDGE
  1064. // Update OSC control client
  1065. if (x_engine->isOscControlRegisted())
  1066. x_engine->osc_send_control_note_off(m_id, event->value1, event->value2);
  1067. #endif
  1068. // Update Host
  1069. x_engine->callback(CALLBACK_NOTE_OFF, m_id, event->value1, event->value2, 0.0, nullptr);
  1070. break;
  1071. case PluginPostEventCustom:
  1072. // Handle custom event
  1073. postEventHandleCustom(event->value1, event->value2, event->value3, event->cdata);
  1074. break;
  1075. }
  1076. }
  1077. }
  1078. void CarlaPlugin::postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  1079. {
  1080. Q_UNUSED(value1);
  1081. Q_UNUSED(value2);
  1082. Q_UNUSED(value3);
  1083. Q_UNUSED(cdata);
  1084. }
  1085. void CarlaPlugin::uiParameterChange(const uint32_t index, const double value)
  1086. {
  1087. CARLA_ASSERT(index < param.count);
  1088. Q_UNUSED(value);
  1089. }
  1090. void CarlaPlugin::uiProgramChange(const uint32_t index)
  1091. {
  1092. CARLA_ASSERT(index < prog.count);
  1093. }
  1094. void CarlaPlugin::uiMidiProgramChange(const uint32_t index)
  1095. {
  1096. CARLA_ASSERT(index < midiprog.count);
  1097. }
  1098. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1099. {
  1100. CARLA_ASSERT(channel < 16);
  1101. CARLA_ASSERT(note < 128);
  1102. CARLA_ASSERT(velo > 0 && velo < 128);
  1103. }
  1104. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note)
  1105. {
  1106. CARLA_ASSERT(channel < 16);
  1107. CARLA_ASSERT(note < 128);
  1108. }
  1109. // -------------------------------------------------------------------
  1110. // Cleanup
  1111. void CarlaPlugin::removeClientPorts()
  1112. {
  1113. qDebug("CarlaPlugin::removeClientPorts() - start");
  1114. for (uint32_t i=0; i < aIn.count; i++)
  1115. {
  1116. delete aIn.ports[i];
  1117. aIn.ports[i] = nullptr;
  1118. }
  1119. for (uint32_t i=0; i < aOut.count; i++)
  1120. {
  1121. delete aOut.ports[i];
  1122. aOut.ports[i] = nullptr;
  1123. }
  1124. if (midi.portMin)
  1125. {
  1126. delete midi.portMin;
  1127. midi.portMin = nullptr;
  1128. }
  1129. if (midi.portMout)
  1130. {
  1131. delete midi.portMout;
  1132. midi.portMout = nullptr;
  1133. }
  1134. if (param.portCin)
  1135. {
  1136. delete param.portCin;
  1137. param.portCin = nullptr;
  1138. }
  1139. if (param.portCout)
  1140. {
  1141. delete param.portCout;
  1142. param.portCout = nullptr;
  1143. }
  1144. qDebug("CarlaPlugin::removeClientPorts() - end");
  1145. }
  1146. void CarlaPlugin::initBuffers()
  1147. {
  1148. for (uint32_t i=0; i < aIn.count; i++)
  1149. {
  1150. if (aIn.ports[i])
  1151. aIn.ports[i]->initBuffer(x_engine);
  1152. }
  1153. for (uint32_t i=0; i < aOut.count; i++)
  1154. {
  1155. if (aOut.ports[i])
  1156. aOut.ports[i]->initBuffer(x_engine);
  1157. }
  1158. if (param.portCin)
  1159. param.portCin->initBuffer(x_engine);
  1160. if (param.portCout)
  1161. param.portCout->initBuffer(x_engine);
  1162. if (midi.portMin)
  1163. midi.portMin->initBuffer(x_engine);
  1164. if (midi.portMout)
  1165. midi.portMout->initBuffer(x_engine);
  1166. }
  1167. void CarlaPlugin::deleteBuffers()
  1168. {
  1169. qDebug("CarlaPlugin::deleteBuffers() - start");
  1170. if (aIn.count > 0)
  1171. {
  1172. delete[] aIn.ports;
  1173. delete[] aIn.rindexes;
  1174. }
  1175. if (aOut.count > 0)
  1176. {
  1177. delete[] aOut.ports;
  1178. delete[] aOut.rindexes;
  1179. }
  1180. if (param.count > 0)
  1181. {
  1182. delete[] param.data;
  1183. delete[] param.ranges;
  1184. }
  1185. aIn.count = 0;
  1186. aIn.ports = nullptr;
  1187. aIn.rindexes = nullptr;
  1188. aOut.count = 0;
  1189. aOut.ports = nullptr;
  1190. aOut.rindexes = nullptr;
  1191. param.count = 0;
  1192. param.data = nullptr;
  1193. param.ranges = nullptr;
  1194. param.portCin = nullptr;
  1195. param.portCout = nullptr;
  1196. qDebug("CarlaPlugin::deleteBuffers() - end");
  1197. }
  1198. // -------------------------------------------------------------------
  1199. // Library functions
  1200. bool CarlaPlugin::libOpen(const char* const filename)
  1201. {
  1202. m_lib = lib_open(filename);
  1203. return bool(m_lib);
  1204. }
  1205. bool CarlaPlugin::libClose()
  1206. {
  1207. if (m_lib)
  1208. return lib_close(m_lib);
  1209. return false;
  1210. }
  1211. void* CarlaPlugin::libSymbol(const char* const symbol)
  1212. {
  1213. if (m_lib)
  1214. return lib_symbol(m_lib, symbol);
  1215. return nullptr;
  1216. }
  1217. const char* CarlaPlugin::libError(const char* const filename)
  1218. {
  1219. return lib_error(filename);
  1220. }
  1221. // -------------------------------------------------------------------
  1222. // Locks
  1223. void CarlaPlugin::engineProcessLock()
  1224. {
  1225. x_engine->processLock();
  1226. }
  1227. void CarlaPlugin::engineProcessUnlock()
  1228. {
  1229. x_engine->processUnlock();
  1230. }
  1231. void CarlaPlugin::engineMidiLock()
  1232. {
  1233. x_engine->midiLock();
  1234. }
  1235. void CarlaPlugin::engineMidiUnlock()
  1236. {
  1237. x_engine->midiUnlock();
  1238. }
  1239. CARLA_BACKEND_END_NAMESPACE