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.

1551 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);
  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);
  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);
  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);
  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);
  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);
  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);
  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);
  525. }
  526. void CarlaPlugin::setCustomData(const CustomDataType type, const char* const key, const char* const value, const bool sendGui)
  527. {
  528. CARLA_ASSERT(type != CUSTOM_DATA_INVALID);
  529. CARLA_ASSERT(key);
  530. CARLA_ASSERT(value);
  531. if (type == CUSTOM_DATA_INVALID)
  532. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - type is invalid", CustomDataType2Str(type), key, value, bool2str(sendGui));
  533. if (! key)
  534. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - key is null", CustomDataType2Str(type), key, value, bool2str(sendGui));
  535. if (! value)
  536. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - value is null", CustomDataType2Str(type), key, value, bool2str(sendGui));
  537. bool saveData = true;
  538. switch (type)
  539. {
  540. case CUSTOM_DATA_INVALID:
  541. saveData = false;
  542. break;
  543. case CUSTOM_DATA_STRING:
  544. // Ignore some keys
  545. if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0)
  546. saveData = false;
  547. 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)
  548. saveData = false;
  549. break;
  550. default:
  551. break;
  552. }
  553. if (saveData)
  554. {
  555. // Check if we already have this key
  556. for (size_t i=0; i < custom.size(); i++)
  557. {
  558. if (strcmp(custom[i].key, key) == 0)
  559. {
  560. free((void*)custom[i].value);
  561. custom[i].value = strdup(value);
  562. return;
  563. }
  564. }
  565. // Otherwise store it
  566. CustomData newData;
  567. newData.type = type;
  568. newData.key = strdup(key);
  569. newData.value = strdup(value);
  570. custom.push_back(newData);
  571. }
  572. }
  573. void CarlaPlugin::setChunkData(const char* const stringData)
  574. {
  575. CARLA_ASSERT(stringData);
  576. }
  577. void CarlaPlugin::setProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  578. {
  579. CARLA_ASSERT(index >= -1 && index < (int32_t)prog.count);
  580. if (index < -1)
  581. index = -1;
  582. else if (index > (int32_t)prog.count)
  583. return;
  584. prog.current = index;
  585. if (sendGui && index >= 0)
  586. uiProgramChange(index);
  587. // Change default parameter values
  588. if (index >= 0)
  589. {
  590. for (uint32_t i=0; i < param.count; i++)
  591. {
  592. param.ranges[i].def = getParameterValue(i);
  593. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  594. #ifndef BUILD_BRIDGE
  595. if (sendOsc)
  596. {
  597. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  598. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  599. }
  600. #endif
  601. }
  602. }
  603. #ifndef BUILD_BRIDGE
  604. if (sendOsc)
  605. x_engine->osc_send_control_set_program(m_id, index);
  606. #else
  607. Q_UNUSED(sendOsc);
  608. #endif
  609. if (sendCallback)
  610. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  611. Q_UNUSED(block);
  612. }
  613. void CarlaPlugin::setMidiProgram(int32_t index, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  614. {
  615. CARLA_ASSERT(index >= -1 && index < (int32_t)midiprog.count);
  616. if (index < -1)
  617. index = -1;
  618. else if (index > (int32_t)midiprog.count)
  619. return;
  620. midiprog.current = index;
  621. if (sendGui && index >= 0)
  622. uiMidiProgramChange(index);
  623. // Change default parameter values (sound banks never change defaults)
  624. if (index >= 0 && m_type != PLUGIN_GIG && m_type != PLUGIN_SF2 && m_type != PLUGIN_SFZ)
  625. {
  626. for (uint32_t i=0; i < param.count; i++)
  627. {
  628. param.ranges[i].def = getParameterValue(i);
  629. fixParameterValue(param.ranges[i].def, param.ranges[i]);
  630. #ifndef BUILD_BRIDGE
  631. if (sendOsc)
  632. {
  633. x_engine->osc_send_control_set_default_value(m_id, i, param.ranges[i].def);
  634. x_engine->osc_send_control_set_parameter_value(m_id, i, param.ranges[i].def);
  635. }
  636. #endif
  637. }
  638. }
  639. #ifndef BUILD_BRIDGE
  640. if (sendOsc)
  641. x_engine->osc_send_control_set_midi_program(m_id, index);
  642. #else
  643. Q_UNUSED(sendOsc);
  644. #endif
  645. if (sendCallback)
  646. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, index, 0, 0.0);
  647. Q_UNUSED(block);
  648. }
  649. void CarlaPlugin::setMidiProgramById(const uint32_t bank, const uint32_t program, const bool sendGui, const bool sendOsc, const bool sendCallback, const bool block)
  650. {
  651. CARLA_ASSERT(program < 128);
  652. for (uint32_t i=0; i < midiprog.count; i++)
  653. {
  654. if (midiprog.data[i].bank == bank && midiprog.data[i].program == program)
  655. return setMidiProgram(i, sendGui, sendOsc, sendCallback, block);
  656. }
  657. }
  658. // -------------------------------------------------------------------
  659. // Set gui stuff
  660. void CarlaPlugin::setGuiContainer(GuiContainer* const container)
  661. {
  662. Q_UNUSED(container);
  663. }
  664. void CarlaPlugin::showGui(const bool yesNo)
  665. {
  666. Q_UNUSED(yesNo);
  667. }
  668. void CarlaPlugin::idleGui()
  669. {
  670. if (! m_enabled)
  671. return;
  672. if (m_hints & PLUGIN_USES_SINGLE_THREAD)
  673. {
  674. // Process postponed events
  675. postEventsRun();
  676. // Update parameter outputs
  677. for (uint32_t i=0; i < param.count; i++)
  678. {
  679. if (param.data[i].type == PARAMETER_OUTPUT)
  680. uiParameterChange(i, getParameterValue(i));
  681. }
  682. }
  683. }
  684. // -------------------------------------------------------------------
  685. // Plugin state
  686. void CarlaPlugin::reload()
  687. {
  688. }
  689. void CarlaPlugin::reloadPrograms(const bool init)
  690. {
  691. Q_UNUSED(init);
  692. }
  693. void CarlaPlugin::prepareForSave()
  694. {
  695. }
  696. // -------------------------------------------------------------------
  697. // Plugin processing
  698. void CarlaPlugin::process(float** const inBuffer, float** const outBuffer, const uint32_t frames, const uint32_t framesOffset)
  699. {
  700. Q_UNUSED(inBuffer);
  701. Q_UNUSED(outBuffer);
  702. Q_UNUSED(frames);
  703. Q_UNUSED(framesOffset);
  704. }
  705. void CarlaPlugin::bufferSizeChanged(const uint32_t newBufferSize)
  706. {
  707. Q_UNUSED(newBufferSize);
  708. }
  709. void CarlaPlugin::recreateLatencyBuffers()
  710. {
  711. if (m_latencyBuffers)
  712. {
  713. for (uint32_t i=0; i < aIn.count; i++)
  714. delete[] m_latencyBuffers[i];
  715. delete[] m_latencyBuffers;
  716. }
  717. if (aIn.count > 0 && m_latency > 0)
  718. {
  719. m_latencyBuffers = new float* [aIn.count];
  720. for (uint32_t i=0; i < aIn.count; i++)
  721. m_latencyBuffers[i] = new float [m_latency];
  722. }
  723. else
  724. m_latencyBuffers = nullptr;
  725. }
  726. // -------------------------------------------------------------------
  727. // OSC stuff
  728. void CarlaPlugin::registerToOscControl()
  729. {
  730. if (! x_engine->isOscControlRegisted())
  731. return;
  732. #ifndef BUILD_BRIDGE
  733. x_engine->osc_send_control_add_plugin_start(m_id, m_name);
  734. #endif
  735. // Base data
  736. {
  737. char bufName[STR_MAX] = { 0 };
  738. char bufLabel[STR_MAX] = { 0 };
  739. char bufMaker[STR_MAX] = { 0 };
  740. char bufCopyright[STR_MAX] = { 0 };
  741. getRealName(bufName);
  742. getLabel(bufLabel);
  743. getMaker(bufMaker);
  744. getCopyright(bufCopyright);
  745. #ifdef BUILD_BRIDGE
  746. x_engine->osc_send_bridge_plugin_info(category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  747. #else
  748. x_engine->osc_send_control_set_plugin_data(m_id, m_type, category(), m_hints, bufName, bufLabel, bufMaker, bufCopyright, uniqueId());
  749. #endif
  750. }
  751. // Base count
  752. {
  753. uint32_t cIns, cOuts, cTotals;
  754. getParameterCountInfo(&cIns, &cOuts, &cTotals);
  755. #ifdef BUILD_BRIDGE
  756. x_engine->osc_send_bridge_audio_count(audioInCount(), audioOutCount(), audioInCount() + audioOutCount());
  757. x_engine->osc_send_bridge_midi_count(midiInCount(), midiOutCount(), midiInCount() + midiOutCount());
  758. x_engine->osc_send_bridge_parameter_count(cIns, cOuts, cTotals);
  759. #else
  760. x_engine->osc_send_control_set_plugin_ports(m_id, audioInCount(), audioOutCount(), midiInCount(), midiOutCount(), cIns, cOuts, cTotals);
  761. #endif
  762. }
  763. // Plugin Parameters
  764. #ifdef BUILD_BRIDGE
  765. uint32_t maxParameters = MAX_PARAMETERS;
  766. #else
  767. uint32_t maxParameters = x_engine->maxParameters();
  768. #endif
  769. if (param.count > 0 && param.count < maxParameters)
  770. {
  771. char bufName[STR_MAX], bufUnit[STR_MAX];
  772. for (uint32_t i=0; i < param.count; i++)
  773. {
  774. getParameterName(i, bufName);
  775. getParameterUnit(i, bufUnit);
  776. #ifdef BUILD_BRIDGE
  777. x_engine->osc_send_bridge_parameter_info(i, bufName, bufUnit);
  778. 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);
  779. 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);
  780. x_engine->osc_send_bridge_set_parameter_value(i, getParameterValue(i));
  781. #else
  782. x_engine->osc_send_control_set_parameter_data(m_id, i, param.data[i].type, param.data[i].hints, bufName, bufUnit, getParameterValue(i));
  783. 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);
  784. x_engine->osc_send_control_set_parameter_midi_cc(m_id, i, param.data[i].midiCC);
  785. x_engine->osc_send_control_set_parameter_midi_channel(m_id, i, param.data[i].midiChannel);
  786. x_engine->osc_send_control_set_parameter_value(m_id, i, getParameterValue(i));
  787. #endif
  788. }
  789. }
  790. // Programs
  791. if (prog.count > 0)
  792. {
  793. #ifdef BUILD_BRIDGE
  794. x_engine->osc_send_bridge_program_count(prog.count);
  795. for (uint32_t i=0; i < prog.count; i++)
  796. x_engine->osc_send_bridge_program_info(i, prog.names[i]);
  797. x_engine->osc_send_bridge_set_program(prog.current);
  798. #else
  799. x_engine->osc_send_control_set_program_count(m_id, prog.count);
  800. for (uint32_t i=0; i < prog.count; i++)
  801. x_engine->osc_send_control_set_program_name(m_id, i, prog.names[i]);
  802. x_engine->osc_send_control_set_program(m_id, prog.current);
  803. #endif
  804. }
  805. // MIDI Programs
  806. if (midiprog.count > 0)
  807. {
  808. #ifdef BUILD_BRIDGE
  809. x_engine->osc_send_bridge_midi_program_count(midiprog.count);
  810. for (uint32_t i=0; i < midiprog.count; i++)
  811. x_engine->osc_send_bridge_midi_program_info(i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  812. x_engine->osc_send_bridge_set_midi_program(prog.current);
  813. #else
  814. x_engine->osc_send_control_set_midi_program_count(m_id, midiprog.count);
  815. for (uint32_t i=0; i < midiprog.count; i++)
  816. x_engine->osc_send_control_set_midi_program_data(m_id, i, midiprog.data[i].bank, midiprog.data[i].program, midiprog.data[i].name);
  817. x_engine->osc_send_control_set_midi_program(m_id, midiprog.current);
  818. #endif
  819. }
  820. #ifndef BUILD_BRIDGE
  821. x_engine->osc_send_control_add_plugin_end(m_id);
  822. // Internal Parameters
  823. {
  824. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, m_active ? 1.0 : 0.0);
  825. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, x_dryWet);
  826. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, x_volume);
  827. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, x_balanceLeft);
  828. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, x_balanceRight);
  829. }
  830. #endif
  831. }
  832. #ifndef BUILD_BRIDGE
  833. void CarlaPlugin::updateOscData(const lo_address source, const char* const url)
  834. {
  835. // FIXME - remove debug prints later
  836. qWarning("CarlaPlugin::updateOscData(%p, \"%s\")", source, url);
  837. const char* host;
  838. const char* port;
  839. const int proto = lo_address_get_protocol(source);
  840. osc.data.free();
  841. host = lo_address_get_hostname(source);
  842. port = lo_address_get_port(source);
  843. osc.data.source = lo_address_new_with_proto(proto, host, port);
  844. qWarning("CarlaPlugin::updateOscData() - source: host \"%s\", port \"%s\"", host, port);
  845. host = lo_url_get_hostname(url);
  846. port = lo_url_get_port(url);
  847. osc.data.path = lo_url_get_path(url);
  848. osc.data.target = lo_address_new_with_proto(proto, host, port);
  849. qWarning("CarlaPlugin::updateOscData() - target: host \"%s\", port \"%s\", path \"%s\"", host, port, osc.data.path);
  850. free((void*)host);
  851. free((void*)port);
  852. if (m_hints & PLUGIN_IS_BRIDGE)
  853. return;
  854. osc_send_sample_rate(&osc.data, x_engine->getSampleRate());
  855. for (size_t i=0; i < custom.size(); i++)
  856. {
  857. // TODO
  858. //if (m_type == PLUGIN_LV2)
  859. //osc_send_lv2_transfer_event(&osc.data, getCustomDataTypeString(custom[i].type), /*custom[i].key,*/ custom[i].value);
  860. //else
  861. if (custom[i].type == CUSTOM_DATA_STRING)
  862. osc_send_configure(&osc.data, custom[i].key, custom[i].value);
  863. }
  864. if (prog.current >= 0)
  865. osc_send_program(&osc.data, prog.current);
  866. if (midiprog.current >= 0)
  867. {
  868. if (m_type == PLUGIN_DSSI)
  869. osc_send_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  870. else
  871. osc_send_midi_program(&osc.data, midiprog.data[midiprog.current].bank, midiprog.data[midiprog.current].program);
  872. }
  873. for (uint32_t i=0; i < param.count; i++)
  874. osc_send_control(&osc.data, param.data[i].rindex, getParameterValue(i));
  875. qWarning("CarlaPlugin::updateOscData() - done");
  876. }
  877. void CarlaPlugin::freeOscData()
  878. {
  879. osc.data.free();
  880. }
  881. bool CarlaPlugin::waitForOscGuiShow()
  882. {
  883. qWarning("CarlaPlugin::waitForOscGuiShow()");
  884. // wait for UI 'update' call
  885. for (uint i=0; i < x_engine->oscUiTimeout(); i++)
  886. {
  887. if (osc.data.target)
  888. {
  889. qWarning("CarlaPlugin::waitForOscGuiShow() - got response, asking UI to show itself now");
  890. osc_send_show(&osc.data);
  891. return true;
  892. }
  893. else
  894. carla_msleep(100);
  895. }
  896. qWarning("CarlaPlugin::waitForOscGuiShow() - Timeout while waiting for UI to respond (waited %i msecs)", x_engine->oscUiTimeout());
  897. return false;
  898. }
  899. #endif
  900. // -------------------------------------------------------------------
  901. // MIDI events
  902. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  903. {
  904. CARLA_ASSERT(channel < 16);
  905. CARLA_ASSERT(note < 128);
  906. CARLA_ASSERT(velo < 128);
  907. if (! m_active)
  908. return;
  909. engineMidiLock();
  910. for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++)
  911. {
  912. if (extMidiNotes[i].channel < 0)
  913. {
  914. extMidiNotes[i].channel = channel;
  915. extMidiNotes[i].note = note;
  916. extMidiNotes[i].velo = velo;
  917. break;
  918. }
  919. }
  920. engineMidiUnlock();
  921. if (sendGui)
  922. {
  923. if (velo > 0)
  924. uiNoteOn(channel, note, velo);
  925. else
  926. uiNoteOff(channel, note);
  927. }
  928. #ifndef BUILD_BRIDGE
  929. if (sendOsc)
  930. {
  931. if (velo > 0)
  932. x_engine->osc_send_control_note_on(m_id, channel, note, velo);
  933. else
  934. x_engine->osc_send_control_note_off(m_id, channel, note);
  935. }
  936. #else
  937. Q_UNUSED(sendOsc);
  938. #endif
  939. if (sendCallback)
  940. x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo);
  941. }
  942. void CarlaPlugin::sendMidiAllNotesOff()
  943. {
  944. engineMidiLock();
  945. postEvents.mutex.lock();
  946. unsigned short postPad = 0;
  947. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  948. {
  949. if (postEvents.data[i].type == PluginPostEventNull)
  950. {
  951. postPad = i;
  952. break;
  953. }
  954. }
  955. if (postPad == MAX_POST_EVENTS - 1)
  956. {
  957. qWarning("post-events buffer full, making room for all notes off now");
  958. postPad -= 128;
  959. }
  960. for (unsigned short i=0; i < 128; i++)
  961. {
  962. extMidiNotes[i].channel = m_ctrlInChannel;
  963. extMidiNotes[i].note = i;
  964. extMidiNotes[i].velo = 0;
  965. postEvents.data[i + postPad].type = PluginPostEventNoteOff;
  966. postEvents.data[i + postPad].value1 = m_ctrlInChannel;
  967. postEvents.data[i + postPad].value2 = i;
  968. postEvents.data[i + postPad].value3 = 0.0;
  969. }
  970. postEvents.mutex.unlock();
  971. engineMidiUnlock();
  972. }
  973. // -------------------------------------------------------------------
  974. // Post-poned events
  975. void CarlaPlugin::postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  976. {
  977. postEvents.mutex.lock();
  978. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  979. {
  980. if (postEvents.data[i].type == PluginPostEventNull)
  981. {
  982. postEvents.data[i].type = type;
  983. postEvents.data[i].value1 = value1;
  984. postEvents.data[i].value2 = value2;
  985. postEvents.data[i].value3 = value3;
  986. postEvents.data[i].cdata = cdata;
  987. break;
  988. }
  989. }
  990. postEvents.mutex.unlock();
  991. }
  992. void CarlaPlugin::postEventsRun()
  993. {
  994. PluginPostEvent newPostEvents[MAX_POST_EVENTS];
  995. // Make a safe copy of events, and clear them
  996. postEvents.mutex.lock();
  997. memcpy(newPostEvents, postEvents.data, sizeof(PluginPostEvent)*MAX_POST_EVENTS);
  998. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  999. postEvents.data[i].type = PluginPostEventNull;
  1000. postEvents.mutex.unlock();
  1001. // Handle events now
  1002. for (uint32_t i=0; i < MAX_POST_EVENTS; i++)
  1003. {
  1004. const PluginPostEvent* const event = &newPostEvents[i];
  1005. switch (event->type)
  1006. {
  1007. case PluginPostEventNull:
  1008. break;
  1009. case PluginPostEventDebug:
  1010. x_engine->callback(CALLBACK_DEBUG, m_id, event->value1, event->value2, event->value3);
  1011. break;
  1012. case PluginPostEventParameterChange:
  1013. // Update UI
  1014. if (event->value1 >= 0)
  1015. uiParameterChange(event->value1, event->value3);
  1016. #ifndef BUILD_BRIDGE
  1017. // Update OSC control client
  1018. if (x_engine->isOscControlRegisted())
  1019. x_engine->osc_send_control_set_parameter_value(m_id, event->value1, event->value3);
  1020. #endif
  1021. // Update Host
  1022. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, event->value1, 0, event->value3);
  1023. break;
  1024. case PluginPostEventProgramChange:
  1025. // Update UI
  1026. if (event->value1 >= 0)
  1027. uiProgramChange(event->value1);
  1028. #ifndef BUILD_BRIDGE
  1029. // Update OSC control client
  1030. if (x_engine->isOscControlRegisted())
  1031. {
  1032. x_engine->osc_send_control_set_program(m_id, event->value1);
  1033. for (uint32_t j=0; j < param.count; j++)
  1034. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1035. }
  1036. #endif
  1037. // Update Host
  1038. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1039. break;
  1040. case PluginPostEventMidiProgramChange:
  1041. // Update UI
  1042. if (event->value1 >= 0)
  1043. uiMidiProgramChange(event->value1);
  1044. #ifndef BUILD_BRIDGE
  1045. // Update OSC control client
  1046. if (x_engine->isOscControlRegisted())
  1047. {
  1048. x_engine->osc_send_control_set_midi_program(m_id, event->value1);
  1049. for (uint32_t j=0; j < param.count; j++)
  1050. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1051. }
  1052. #endif
  1053. // Update Host
  1054. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1055. break;
  1056. case PluginPostEventNoteOn:
  1057. // Update UI
  1058. uiNoteOn(event->value1, event->value2, rint(event->value3));
  1059. #ifndef BUILD_BRIDGE
  1060. // Update OSC control client
  1061. if (x_engine->isOscControlRegisted())
  1062. x_engine->osc_send_control_note_on(m_id, event->value1, event->value2, rint(event->value3));
  1063. #endif
  1064. // Update Host
  1065. x_engine->callback(CALLBACK_NOTE_ON, m_id, event->value1, event->value2, rint(event->value3));
  1066. break;
  1067. case PluginPostEventNoteOff:
  1068. // Update UI
  1069. uiNoteOff(event->value1, event->value2);
  1070. #ifndef BUILD_BRIDGE
  1071. // Update OSC control client
  1072. if (x_engine->isOscControlRegisted())
  1073. x_engine->osc_send_control_note_off(m_id, event->value1, event->value2);
  1074. #endif
  1075. // Update Host
  1076. x_engine->callback(CALLBACK_NOTE_OFF, m_id, event->value1, event->value2, 0.0);
  1077. break;
  1078. case PluginPostEventCustom:
  1079. // Handle custom event
  1080. postEventHandleCustom(event->value1, event->value2, event->value3, event->cdata);
  1081. break;
  1082. }
  1083. }
  1084. }
  1085. void CarlaPlugin::postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  1086. {
  1087. Q_UNUSED(value1);
  1088. Q_UNUSED(value2);
  1089. Q_UNUSED(value3);
  1090. Q_UNUSED(cdata);
  1091. }
  1092. void CarlaPlugin::uiParameterChange(const uint32_t index, const double value)
  1093. {
  1094. CARLA_ASSERT(index < param.count);
  1095. Q_UNUSED(value);
  1096. }
  1097. void CarlaPlugin::uiProgramChange(const uint32_t index)
  1098. {
  1099. CARLA_ASSERT(index < prog.count);
  1100. }
  1101. void CarlaPlugin::uiMidiProgramChange(const uint32_t index)
  1102. {
  1103. CARLA_ASSERT(index < midiprog.count);
  1104. }
  1105. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1106. {
  1107. CARLA_ASSERT(channel < 16);
  1108. CARLA_ASSERT(note < 128);
  1109. CARLA_ASSERT(velo > 0 && velo < 128);
  1110. }
  1111. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note)
  1112. {
  1113. CARLA_ASSERT(channel < 16);
  1114. CARLA_ASSERT(note < 128);
  1115. }
  1116. // -------------------------------------------------------------------
  1117. // Cleanup
  1118. void CarlaPlugin::removeClientPorts()
  1119. {
  1120. qDebug("CarlaPlugin::removeClientPorts() - start");
  1121. for (uint32_t i=0; i < aIn.count; i++)
  1122. {
  1123. delete aIn.ports[i];
  1124. aIn.ports[i] = nullptr;
  1125. }
  1126. for (uint32_t i=0; i < aOut.count; i++)
  1127. {
  1128. delete aOut.ports[i];
  1129. aOut.ports[i] = nullptr;
  1130. }
  1131. if (midi.portMin)
  1132. {
  1133. delete midi.portMin;
  1134. midi.portMin = nullptr;
  1135. }
  1136. if (midi.portMout)
  1137. {
  1138. delete midi.portMout;
  1139. midi.portMout = nullptr;
  1140. }
  1141. if (param.portCin)
  1142. {
  1143. delete param.portCin;
  1144. param.portCin = nullptr;
  1145. }
  1146. if (param.portCout)
  1147. {
  1148. delete param.portCout;
  1149. param.portCout = nullptr;
  1150. }
  1151. qDebug("CarlaPlugin::removeClientPorts() - end");
  1152. }
  1153. void CarlaPlugin::initBuffers()
  1154. {
  1155. for (uint32_t i=0; i < aIn.count; i++)
  1156. {
  1157. if (aIn.ports[i])
  1158. aIn.ports[i]->initBuffer(x_engine);
  1159. }
  1160. for (uint32_t i=0; i < aOut.count; i++)
  1161. {
  1162. if (aOut.ports[i])
  1163. aOut.ports[i]->initBuffer(x_engine);
  1164. }
  1165. if (param.portCin)
  1166. param.portCin->initBuffer(x_engine);
  1167. if (param.portCout)
  1168. param.portCout->initBuffer(x_engine);
  1169. if (midi.portMin)
  1170. midi.portMin->initBuffer(x_engine);
  1171. if (midi.portMout)
  1172. midi.portMout->initBuffer(x_engine);
  1173. }
  1174. void CarlaPlugin::deleteBuffers()
  1175. {
  1176. qDebug("CarlaPlugin::deleteBuffers() - start");
  1177. if (aIn.count > 0)
  1178. {
  1179. delete[] aIn.ports;
  1180. delete[] aIn.rindexes;
  1181. }
  1182. if (aOut.count > 0)
  1183. {
  1184. delete[] aOut.ports;
  1185. delete[] aOut.rindexes;
  1186. }
  1187. if (param.count > 0)
  1188. {
  1189. delete[] param.data;
  1190. delete[] param.ranges;
  1191. }
  1192. aIn.count = 0;
  1193. aIn.ports = nullptr;
  1194. aIn.rindexes = nullptr;
  1195. aOut.count = 0;
  1196. aOut.ports = nullptr;
  1197. aOut.rindexes = nullptr;
  1198. param.count = 0;
  1199. param.data = nullptr;
  1200. param.ranges = nullptr;
  1201. param.portCin = nullptr;
  1202. param.portCout = nullptr;
  1203. qDebug("CarlaPlugin::deleteBuffers() - end");
  1204. }
  1205. // -------------------------------------------------------------------
  1206. // Library functions
  1207. bool CarlaPlugin::libOpen(const char* const filename)
  1208. {
  1209. m_lib = lib_open(filename);
  1210. return bool(m_lib);
  1211. }
  1212. bool CarlaPlugin::libClose()
  1213. {
  1214. if (m_lib)
  1215. return lib_close(m_lib);
  1216. return false;
  1217. }
  1218. void* CarlaPlugin::libSymbol(const char* const symbol)
  1219. {
  1220. if (m_lib)
  1221. return lib_symbol(m_lib, symbol);
  1222. return nullptr;
  1223. }
  1224. const char* CarlaPlugin::libError(const char* const filename)
  1225. {
  1226. return lib_error(filename);
  1227. }
  1228. // -------------------------------------------------------------------
  1229. // Locks
  1230. void CarlaPlugin::engineProcessLock()
  1231. {
  1232. x_engine->processLock();
  1233. }
  1234. void CarlaPlugin::engineProcessUnlock()
  1235. {
  1236. x_engine->processUnlock();
  1237. }
  1238. void CarlaPlugin::engineMidiLock()
  1239. {
  1240. x_engine->midiLock();
  1241. }
  1242. void CarlaPlugin::engineMidiUnlock()
  1243. {
  1244. x_engine->midiUnlock();
  1245. }
  1246. CARLA_BACKEND_END_NAMESPACE