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.

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