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 < CarlaEngine::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. #ifndef BUILD_BRIDGE
  48. if (engine->processMode == PROCESS_MODE_CONTINUOUS_RACK)
  49. m_ctrlInChannel = m_id;
  50. else
  51. #endif
  52. m_ctrlInChannel = 0;
  53. m_latency = 0;
  54. m_latencyBuffers = nullptr;
  55. #ifndef BUILD_BRIDGE
  56. osc.data.path = nullptr;
  57. osc.data.source = nullptr;
  58. osc.data.target = nullptr;
  59. osc.thread = nullptr;
  60. #endif
  61. }
  62. CarlaPlugin::~CarlaPlugin()
  63. {
  64. qDebug("CarlaPlugin::~CarlaPlugin()");
  65. // Remove client and ports
  66. if (x_client)
  67. {
  68. if (x_client->isActive())
  69. x_client->deactivate();
  70. removeClientPorts();
  71. delete x_client;
  72. }
  73. // Delete data
  74. deleteBuffers();
  75. // Unload DLL
  76. libClose();
  77. if (m_name)
  78. free((void*)m_name);
  79. if (m_filename)
  80. free((void*)m_filename);
  81. if (prog.count > 0)
  82. {
  83. for (uint32_t i=0; i < prog.count; i++)
  84. {
  85. if (prog.names[i])
  86. free((void*)prog.names[i]);
  87. }
  88. delete[] prog.names;
  89. }
  90. if (midiprog.count > 0)
  91. {
  92. for (uint32_t i=0; i < midiprog.count; i++)
  93. {
  94. if (midiprog.data[i].name)
  95. free((void*)midiprog.data[i].name);
  96. }
  97. delete[] midiprog.data;
  98. }
  99. if (custom.size() > 0)
  100. {
  101. for (size_t i=0; i < custom.size(); i++)
  102. {
  103. if (custom[i].key)
  104. free((void*)custom[i].key);
  105. if (custom[i].value)
  106. free((void*)custom[i].value);
  107. }
  108. custom.clear();
  109. }
  110. if (m_latencyBuffers)
  111. {
  112. for (uint32_t i=0; i < aIn.count; i++)
  113. delete[] m_latencyBuffers[i];
  114. delete[] m_latencyBuffers;
  115. }
  116. }
  117. // -------------------------------------------------------------------
  118. // Information (base)
  119. PluginType CarlaPlugin::type() const
  120. {
  121. return m_type;
  122. }
  123. unsigned short CarlaPlugin::id() const
  124. {
  125. return m_id;
  126. }
  127. unsigned int CarlaPlugin::hints() const
  128. {
  129. return m_hints;
  130. }
  131. bool CarlaPlugin::enabled() const
  132. {
  133. return m_enabled;
  134. }
  135. const char* CarlaPlugin::name() const
  136. {
  137. return m_name;
  138. }
  139. const char* CarlaPlugin::filename() const
  140. {
  141. return m_filename;
  142. }
  143. PluginCategory CarlaPlugin::category()
  144. {
  145. return PLUGIN_CATEGORY_NONE;
  146. }
  147. long CarlaPlugin::uniqueId()
  148. {
  149. return 0;
  150. }
  151. // -------------------------------------------------------------------
  152. // Information (count)
  153. uint32_t CarlaPlugin::audioInCount()
  154. {
  155. return aIn.count;
  156. }
  157. uint32_t CarlaPlugin::audioOutCount()
  158. {
  159. return aOut.count;
  160. }
  161. uint32_t CarlaPlugin::midiInCount()
  162. {
  163. return midi.portMin ? 1 : 0;
  164. }
  165. uint32_t CarlaPlugin::midiOutCount()
  166. {
  167. return midi.portMout ? 1 : 0;
  168. }
  169. uint32_t CarlaPlugin::parameterCount() const
  170. {
  171. return param.count;
  172. }
  173. uint32_t CarlaPlugin::parameterScalePointCount(const uint32_t parameterId)
  174. {
  175. CARLA_ASSERT(parameterId < param.count);
  176. return 0;
  177. }
  178. uint32_t CarlaPlugin::programCount() const
  179. {
  180. return prog.count;
  181. }
  182. uint32_t CarlaPlugin::midiProgramCount() const
  183. {
  184. return midiprog.count;
  185. }
  186. size_t CarlaPlugin::customDataCount() const
  187. {
  188. return custom.size();
  189. }
  190. // -------------------------------------------------------------------
  191. // Information (current data)
  192. int32_t CarlaPlugin::currentProgram() const
  193. {
  194. return prog.current;
  195. }
  196. int32_t CarlaPlugin::currentMidiProgram() const
  197. {
  198. return midiprog.current;
  199. }
  200. const ParameterData* CarlaPlugin::parameterData(const uint32_t parameterId) const
  201. {
  202. CARLA_ASSERT(parameterId < param.count);
  203. if (parameterId < param.count)
  204. return &param.data[parameterId];
  205. return &paramDataNull;
  206. }
  207. const ParameterRanges* CarlaPlugin::parameterRanges(const uint32_t parameterId) const
  208. {
  209. CARLA_ASSERT(parameterId < param.count);
  210. if (parameterId < param.count)
  211. return &param.ranges[parameterId];
  212. return &paramRangesNull;
  213. }
  214. bool CarlaPlugin::parameterIsOutput(const uint32_t parameterId) const
  215. {
  216. CARLA_ASSERT(parameterId < param.count);
  217. if (parameterId < param.count)
  218. return (param.data[parameterId].type == PARAMETER_OUTPUT);
  219. return false;
  220. }
  221. const MidiProgramData* CarlaPlugin::midiProgramData(const uint32_t index) const
  222. {
  223. CARLA_ASSERT(index < midiprog.count);
  224. if (index < midiprog.count)
  225. return &midiprog.data[index];
  226. return &midiProgramDataNull;
  227. }
  228. const CustomData* CarlaPlugin::customData(const size_t index) const
  229. {
  230. CARLA_ASSERT(index < custom.size());
  231. if (index < custom.size())
  232. return &custom[index];
  233. return &customDataNull;
  234. }
  235. int32_t CarlaPlugin::chunkData(void** const dataPtr)
  236. {
  237. CARLA_ASSERT(dataPtr);
  238. return 0;
  239. }
  240. // -------------------------------------------------------------------
  241. // Information (per-plugin data)
  242. double CarlaPlugin::getParameterValue(const uint32_t parameterId)
  243. {
  244. CARLA_ASSERT(parameterId < param.count);
  245. return 0.0;
  246. }
  247. double CarlaPlugin::getParameterScalePointValue(const uint32_t parameterId, const uint32_t scalePointId)
  248. {
  249. CARLA_ASSERT(parameterId < param.count);
  250. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  251. return 0.0;
  252. }
  253. void CarlaPlugin::getLabel(char* const strBuf)
  254. {
  255. *strBuf = 0;
  256. }
  257. void CarlaPlugin::getMaker(char* const strBuf)
  258. {
  259. *strBuf = 0;
  260. }
  261. void CarlaPlugin::getCopyright(char* const strBuf)
  262. {
  263. *strBuf = 0;
  264. }
  265. void CarlaPlugin::getRealName(char* const strBuf)
  266. {
  267. *strBuf = 0;;
  268. }
  269. void CarlaPlugin::getParameterName(const uint32_t parameterId, char* const strBuf)
  270. {
  271. CARLA_ASSERT(parameterId < param.count);
  272. *strBuf = 0;
  273. }
  274. void CarlaPlugin::getParameterSymbol(const uint32_t parameterId, char* const strBuf)
  275. {
  276. CARLA_ASSERT(parameterId < param.count);
  277. *strBuf = 0;
  278. }
  279. void CarlaPlugin::getParameterText(const uint32_t parameterId, char* const strBuf)
  280. {
  281. CARLA_ASSERT(parameterId < param.count);
  282. *strBuf = 0;
  283. }
  284. void CarlaPlugin::getParameterUnit(const uint32_t parameterId, char* const strBuf)
  285. {
  286. CARLA_ASSERT(parameterId < param.count);
  287. *strBuf = 0;
  288. }
  289. void CarlaPlugin::getParameterScalePointLabel(const uint32_t parameterId, const uint32_t scalePointId, char* const strBuf)
  290. {
  291. CARLA_ASSERT(parameterId < param.count);
  292. CARLA_ASSERT(scalePointId < parameterScalePointCount(parameterId));
  293. *strBuf = 0;
  294. }
  295. void CarlaPlugin::getProgramName(const uint32_t index, char* const strBuf)
  296. {
  297. CARLA_ASSERT(index < prog.count);
  298. if (index < prog.count && prog.names[index])
  299. strncpy(strBuf, prog.names[index], STR_MAX);
  300. else
  301. *strBuf = 0;
  302. }
  303. void CarlaPlugin::getMidiProgramName(const uint32_t index, char* const strBuf)
  304. {
  305. CARLA_ASSERT(index < midiprog.count);
  306. if (index < midiprog.count && midiprog.data[index].name)
  307. strncpy(strBuf, midiprog.data[index].name, STR_MAX);
  308. else
  309. *strBuf = 0;
  310. }
  311. void CarlaPlugin::getParameterCountInfo(uint32_t* const ins, uint32_t* const outs, uint32_t* const total)
  312. {
  313. *ins = 0;
  314. *outs = 0;
  315. *total = param.count;
  316. for (uint32_t i=0; i < param.count; i++)
  317. {
  318. if (param.data[i].type == PARAMETER_INPUT)
  319. *ins += 1;
  320. else if (param.data[i].type == PARAMETER_OUTPUT)
  321. *outs += 1;
  322. }
  323. }
  324. void CarlaPlugin::getGuiInfo(GuiType* const type, bool* const resizable)
  325. {
  326. *type = GUI_NONE;
  327. *resizable = false;
  328. }
  329. // -------------------------------------------------------------------
  330. // Set data (internal stuff)
  331. #ifndef BUILD_BRIDGE
  332. void CarlaPlugin::setId(const unsigned short id)
  333. {
  334. m_id = id;
  335. if (x_engine->processMode == PROCESS_MODE_CONTINUOUS_RACK)
  336. m_ctrlInChannel = id;
  337. }
  338. #endif
  339. void CarlaPlugin::setEnabled(const bool yesNo)
  340. {
  341. m_enabled = yesNo;
  342. }
  343. void CarlaPlugin::setActive(const bool active, const bool sendOsc, const bool sendCallback)
  344. {
  345. m_active = active;
  346. double value = active ? 1.0 : 0.0;
  347. #ifndef BUILD_BRIDGE
  348. if (sendOsc)
  349. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_ACTIVE, value);
  350. #else
  351. Q_UNUSED(sendOsc);
  352. #endif
  353. if (sendCallback)
  354. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_ACTIVE, 0, value);
  355. #ifndef BUILD_BRIDGE
  356. else if (m_hints & PLUGIN_IS_BRIDGE)
  357. osc_send_control(&osc.data, PARAMETER_ACTIVE, value);
  358. #endif
  359. }
  360. void CarlaPlugin::setDryWet(double value, const bool sendOsc, const bool sendCallback)
  361. {
  362. CARLA_ASSERT(value >= 0.0 && value <= 1.0);
  363. if (value < 0.0)
  364. value = 0.0;
  365. else if (value > 1.0)
  366. value = 1.0;
  367. x_dryWet = value;
  368. #ifndef BUILD_BRIDGE
  369. if (sendOsc)
  370. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_DRYWET, value);
  371. #else
  372. Q_UNUSED(sendOsc);
  373. #endif
  374. if (sendCallback)
  375. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_DRYWET, 0, value);
  376. #ifndef BUILD_BRIDGE
  377. else if (m_hints & PLUGIN_IS_BRIDGE)
  378. osc_send_control(&osc.data, PARAMETER_DRYWET, value);
  379. #endif
  380. }
  381. void CarlaPlugin::setVolume(double value, const bool sendOsc, const bool sendCallback)
  382. {
  383. CARLA_ASSERT(value >= 0.0 && value <= 1.27);
  384. if (value < 0.0)
  385. value = 0.0;
  386. else if (value > 1.27)
  387. value = 1.27;
  388. x_volume = value;
  389. #ifndef BUILD_BRIDGE
  390. if (sendOsc)
  391. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_VOLUME, value);
  392. #else
  393. Q_UNUSED(sendOsc);
  394. #endif
  395. if (sendCallback)
  396. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_VOLUME, 0, value);
  397. #ifndef BUILD_BRIDGE
  398. else if (m_hints & PLUGIN_IS_BRIDGE)
  399. osc_send_control(&osc.data, PARAMETER_VOLUME, value);
  400. #endif
  401. }
  402. void CarlaPlugin::setBalanceLeft(double value, const bool sendOsc, const bool sendCallback)
  403. {
  404. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  405. if (value < -1.0)
  406. value = -1.0;
  407. else if (value > 1.0)
  408. value = 1.0;
  409. x_balanceLeft = value;
  410. #ifndef BUILD_BRIDGE
  411. if (sendOsc)
  412. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_LEFT, value);
  413. #else
  414. Q_UNUSED(sendOsc);
  415. #endif
  416. if (sendCallback)
  417. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_LEFT, 0, value);
  418. #ifndef BUILD_BRIDGE
  419. else if (m_hints & PLUGIN_IS_BRIDGE)
  420. osc_send_control(&osc.data, PARAMETER_BALANCE_LEFT, value);
  421. #endif
  422. }
  423. void CarlaPlugin::setBalanceRight(double value, const bool sendOsc, const bool sendCallback)
  424. {
  425. CARLA_ASSERT(value >= -1.0 && value <= 1.0);
  426. if (value < -1.0)
  427. value = -1.0;
  428. else if (value > 1.0)
  429. value = 1.0;
  430. x_balanceRight = value;
  431. #ifndef BUILD_BRIDGE
  432. if (sendOsc)
  433. x_engine->osc_send_control_set_parameter_value(m_id, PARAMETER_BALANCE_RIGHT, value);
  434. #else
  435. Q_UNUSED(sendOsc);
  436. #endif
  437. if (sendCallback)
  438. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, PARAMETER_BALANCE_RIGHT, 0, value);
  439. #ifndef BUILD_BRIDGE
  440. else if (m_hints & PLUGIN_IS_BRIDGE)
  441. osc_send_control(&osc.data, PARAMETER_BALANCE_RIGHT, value);
  442. #endif
  443. }
  444. #ifndef BUILD_BRIDGE
  445. int CarlaPlugin::setOscBridgeInfo(const PluginBridgeInfoType type, const int argc, const lo_arg* const* const argv, const char* const types)
  446. {
  447. return 1;
  448. Q_UNUSED(type);
  449. Q_UNUSED(argc);
  450. Q_UNUSED(argv);
  451. Q_UNUSED(types);
  452. }
  453. #endif
  454. // -------------------------------------------------------------------
  455. // Set data (plugin-specific stuff)
  456. void CarlaPlugin::setParameterValue(const uint32_t parameterId, double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  457. {
  458. CARLA_ASSERT(parameterId < param.count);
  459. if (sendGui)
  460. uiParameterChange(parameterId, value);
  461. #ifndef BUILD_BRIDGE
  462. if (sendOsc)
  463. x_engine->osc_send_control_set_parameter_value(m_id, parameterId, value);
  464. #else
  465. Q_UNUSED(sendOsc);
  466. #endif
  467. if (sendCallback)
  468. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, parameterId, 0, value);
  469. }
  470. void CarlaPlugin::setParameterValueByRIndex(const int32_t rindex, const double value, const bool sendGui, const bool sendOsc, const bool sendCallback)
  471. {
  472. CARLA_ASSERT(rindex >= PARAMETER_BALANCE_RIGHT && rindex != PARAMETER_NULL);
  473. if (rindex == PARAMETER_ACTIVE)
  474. return setActive(value > 0.0, sendOsc, sendCallback);
  475. if (rindex == PARAMETER_DRYWET)
  476. return setDryWet(value, sendOsc, sendCallback);
  477. if (rindex == PARAMETER_VOLUME)
  478. return setVolume(value, sendOsc, sendCallback);
  479. if (rindex == PARAMETER_BALANCE_LEFT)
  480. return setBalanceLeft(value, sendOsc, sendCallback);
  481. if (rindex == PARAMETER_BALANCE_RIGHT)
  482. return setBalanceRight(value, sendOsc, sendCallback);
  483. for (uint32_t i=0; i < param.count; i++)
  484. {
  485. if (param.data[i].rindex == rindex)
  486. return setParameterValue(i, value, sendGui, sendOsc, sendCallback);
  487. }
  488. }
  489. void CarlaPlugin::setParameterMidiChannel(const uint32_t parameterId, uint8_t channel, const bool sendOsc, const bool sendCallback)
  490. {
  491. CARLA_ASSERT(parameterId < param.count);
  492. CARLA_ASSERT(channel < 16);
  493. if (channel >= 16)
  494. channel = 16;
  495. param.data[parameterId].midiChannel = channel;
  496. #ifndef BUILD_BRIDGE
  497. if (sendOsc)
  498. x_engine->osc_send_control_set_parameter_midi_channel(m_id, parameterId, channel);
  499. #else
  500. Q_UNUSED(sendOsc);
  501. #endif
  502. if (sendCallback)
  503. x_engine->callback(CALLBACK_PARAMETER_MIDI_CHANNEL_CHANGED, m_id, parameterId, channel, 0.0);
  504. }
  505. void CarlaPlugin::setParameterMidiCC(const uint32_t parameterId, int16_t cc, const bool sendOsc, const bool sendCallback)
  506. {
  507. CARLA_ASSERT(parameterId < param.count);
  508. CARLA_ASSERT(cc >= -1);
  509. if (cc < -1 || cc > 0x5F)
  510. cc = -1;
  511. param.data[parameterId].midiCC = cc;
  512. #ifndef BUILD_BRIDGE
  513. if (sendOsc)
  514. x_engine->osc_send_control_set_parameter_midi_cc(m_id, parameterId, cc);
  515. #else
  516. Q_UNUSED(sendOsc);
  517. #endif
  518. if (sendCallback)
  519. x_engine->callback(CALLBACK_PARAMETER_MIDI_CC_CHANGED, m_id, parameterId, cc, 0.0);
  520. }
  521. void CarlaPlugin::setCustomData(const CustomDataType type, const char* const key, const char* const value, const bool sendGui)
  522. {
  523. CARLA_ASSERT(type != CUSTOM_DATA_INVALID);
  524. CARLA_ASSERT(key);
  525. CARLA_ASSERT(value);
  526. if (type == CUSTOM_DATA_INVALID)
  527. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - type is invalid", CustomDataType2Str(type), key, value, bool2str(sendGui));
  528. if (! key)
  529. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - key is null", CustomDataType2Str(type), key, value, bool2str(sendGui));
  530. if (! value)
  531. return qCritical("CarlaPlugin::setCustomData(%s, \"%s\", \"%s\", %s) - value is null", CustomDataType2Str(type), key, value, bool2str(sendGui));
  532. bool saveData = true;
  533. switch (type)
  534. {
  535. case CUSTOM_DATA_INVALID:
  536. saveData = false;
  537. break;
  538. case CUSTOM_DATA_STRING:
  539. // Ignore some keys
  540. if (strncmp(key, "OSC:", 4) == 0 || strcmp(key, "guiVisible") == 0)
  541. saveData = false;
  542. 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)
  543. saveData = false;
  544. break;
  545. default:
  546. break;
  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 = 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);
  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);
  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. uint32_t maxParameters = MAX_PARAMETERS;
  761. #else
  762. uint32_t maxParameters = x_engine->options.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::showOscGui()
  877. {
  878. qWarning("CarlaPlugin::showOscGui()");
  879. // wait for UI 'update' call
  880. for (uint i=0; i < x_engine->options.oscUiTimeout; i++)
  881. {
  882. if (osc.data.target)
  883. {
  884. qWarning("CarlaPlugin::showOscGui() - got response, asking UI to show itself now");
  885. osc_send_show(&osc.data);
  886. return true;
  887. }
  888. else
  889. carla_msleep(100);
  890. }
  891. qWarning("CarlaPlugin::showOscGui() - Timeout while waiting for UI to respond");
  892. return false;
  893. }
  894. #endif
  895. // -------------------------------------------------------------------
  896. // MIDI events
  897. void CarlaPlugin::sendMidiSingleNote(const uint8_t channel, const uint8_t note, const uint8_t velo, const bool sendGui, const bool sendOsc, const bool sendCallback)
  898. {
  899. CARLA_ASSERT(channel < 16);
  900. CARLA_ASSERT(note < 128);
  901. CARLA_ASSERT(velo < 128);
  902. if (! m_active)
  903. return;
  904. engineMidiLock();
  905. for (unsigned short i=0; i < MAX_MIDI_EVENTS; i++)
  906. {
  907. if (extMidiNotes[i].channel < 0)
  908. {
  909. extMidiNotes[i].channel = channel;
  910. extMidiNotes[i].note = note;
  911. extMidiNotes[i].velo = velo;
  912. break;
  913. }
  914. }
  915. engineMidiUnlock();
  916. if (sendGui)
  917. {
  918. if (velo > 0)
  919. uiNoteOn(channel, note, velo);
  920. else
  921. uiNoteOff(channel, note);
  922. }
  923. #ifndef BUILD_BRIDGE
  924. if (sendOsc)
  925. {
  926. if (velo > 0)
  927. x_engine->osc_send_control_note_on(m_id, channel, note, velo);
  928. else
  929. x_engine->osc_send_control_note_off(m_id, channel, note);
  930. }
  931. #else
  932. Q_UNUSED(sendOsc);
  933. #endif
  934. if (sendCallback)
  935. x_engine->callback(velo ? CALLBACK_NOTE_ON : CALLBACK_NOTE_OFF, m_id, channel, note, velo);
  936. }
  937. void CarlaPlugin::sendMidiAllNotesOff()
  938. {
  939. engineMidiLock();
  940. postEvents.mutex.lock();
  941. unsigned short postPad = 0;
  942. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  943. {
  944. if (postEvents.data[i].type == PluginPostEventNull)
  945. {
  946. postPad = i;
  947. break;
  948. }
  949. }
  950. if (postPad == MAX_POST_EVENTS - 1)
  951. {
  952. qWarning("post-events buffer full, making room for all notes off now");
  953. postPad -= 128;
  954. }
  955. for (unsigned short i=0; i < 128; i++)
  956. {
  957. extMidiNotes[i].channel = m_ctrlInChannel;
  958. extMidiNotes[i].note = i;
  959. extMidiNotes[i].velo = 0;
  960. postEvents.data[i + postPad].type = PluginPostEventNoteOff;
  961. postEvents.data[i + postPad].value1 = m_ctrlInChannel;
  962. postEvents.data[i + postPad].value2 = i;
  963. postEvents.data[i + postPad].value3 = 0.0;
  964. }
  965. postEvents.mutex.unlock();
  966. engineMidiUnlock();
  967. }
  968. // -------------------------------------------------------------------
  969. // Post-poned events
  970. void CarlaPlugin::postponeEvent(const PluginPostEventType type, const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  971. {
  972. postEvents.mutex.lock();
  973. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  974. {
  975. if (postEvents.data[i].type == PluginPostEventNull)
  976. {
  977. postEvents.data[i].type = type;
  978. postEvents.data[i].value1 = value1;
  979. postEvents.data[i].value2 = value2;
  980. postEvents.data[i].value3 = value3;
  981. postEvents.data[i].cdata = cdata;
  982. break;
  983. }
  984. }
  985. postEvents.mutex.unlock();
  986. }
  987. void CarlaPlugin::postEventsRun()
  988. {
  989. PluginPostEvent newPostEvents[MAX_POST_EVENTS];
  990. // Make a safe copy of events, and clear them
  991. postEvents.mutex.lock();
  992. memcpy(newPostEvents, postEvents.data, sizeof(PluginPostEvent)*MAX_POST_EVENTS);
  993. for (unsigned short i=0; i < MAX_POST_EVENTS; i++)
  994. postEvents.data[i].type = PluginPostEventNull;
  995. postEvents.mutex.unlock();
  996. // Handle events now
  997. for (uint32_t i=0; i < MAX_POST_EVENTS; i++)
  998. {
  999. const PluginPostEvent* const event = &newPostEvents[i];
  1000. switch (event->type)
  1001. {
  1002. case PluginPostEventNull:
  1003. break;
  1004. case PluginPostEventDebug:
  1005. x_engine->callback(CALLBACK_DEBUG, m_id, event->value1, event->value2, event->value3);
  1006. break;
  1007. case PluginPostEventParameterChange:
  1008. // Update UI
  1009. if (event->value1 >= 0)
  1010. uiParameterChange(event->value1, event->value3);
  1011. #ifndef BUILD_BRIDGE
  1012. // Update OSC control client
  1013. if (x_engine->isOscControlRegisted())
  1014. x_engine->osc_send_control_set_parameter_value(m_id, event->value1, event->value3);
  1015. #endif
  1016. // Update Host
  1017. x_engine->callback(CALLBACK_PARAMETER_VALUE_CHANGED, m_id, event->value1, 0, event->value3);
  1018. break;
  1019. case PluginPostEventProgramChange:
  1020. // Update UI
  1021. if (event->value1 >= 0)
  1022. uiProgramChange(event->value1);
  1023. #ifndef BUILD_BRIDGE
  1024. // Update OSC control client
  1025. if (x_engine->isOscControlRegisted())
  1026. {
  1027. x_engine->osc_send_control_set_program(m_id, event->value1);
  1028. for (uint32_t j=0; j < param.count; j++)
  1029. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1030. }
  1031. #endif
  1032. // Update Host
  1033. x_engine->callback(CALLBACK_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1034. break;
  1035. case PluginPostEventMidiProgramChange:
  1036. // Update UI
  1037. if (event->value1 >= 0)
  1038. uiMidiProgramChange(event->value1);
  1039. #ifndef BUILD_BRIDGE
  1040. // Update OSC control client
  1041. if (x_engine->isOscControlRegisted())
  1042. {
  1043. x_engine->osc_send_control_set_midi_program(m_id, event->value1);
  1044. for (uint32_t j=0; j < param.count; j++)
  1045. x_engine->osc_send_control_set_default_value(m_id, j, param.ranges[j].def);
  1046. }
  1047. #endif
  1048. // Update Host
  1049. x_engine->callback(CALLBACK_MIDI_PROGRAM_CHANGED, m_id, event->value1, 0, 0.0);
  1050. break;
  1051. case PluginPostEventNoteOn:
  1052. // Update UI
  1053. uiNoteOn(event->value1, event->value2, rint(event->value3));
  1054. #ifndef BUILD_BRIDGE
  1055. // Update OSC control client
  1056. if (x_engine->isOscControlRegisted())
  1057. x_engine->osc_send_control_note_on(m_id, event->value1, event->value2, rint(event->value3));
  1058. #endif
  1059. // Update Host
  1060. x_engine->callback(CALLBACK_NOTE_ON, m_id, event->value1, event->value2, rint(event->value3));
  1061. break;
  1062. case PluginPostEventNoteOff:
  1063. // Update UI
  1064. uiNoteOff(event->value1, event->value2);
  1065. #ifndef BUILD_BRIDGE
  1066. // Update OSC control client
  1067. if (x_engine->isOscControlRegisted())
  1068. x_engine->osc_send_control_note_off(m_id, event->value1, event->value2);
  1069. #endif
  1070. // Update Host
  1071. x_engine->callback(CALLBACK_NOTE_OFF, m_id, event->value1, event->value2, 0.0);
  1072. break;
  1073. case PluginPostEventCustom:
  1074. // Handle custom event
  1075. postEventHandleCustom(event->value1, event->value2, event->value3, event->cdata);
  1076. break;
  1077. }
  1078. }
  1079. }
  1080. void CarlaPlugin::postEventHandleCustom(const int32_t value1, const int32_t value2, const double value3, const void* const cdata)
  1081. {
  1082. Q_UNUSED(value1);
  1083. Q_UNUSED(value2);
  1084. Q_UNUSED(value3);
  1085. Q_UNUSED(cdata);
  1086. }
  1087. void CarlaPlugin::uiParameterChange(const uint32_t index, const double value)
  1088. {
  1089. CARLA_ASSERT(index < param.count);
  1090. Q_UNUSED(value);
  1091. }
  1092. void CarlaPlugin::uiProgramChange(const uint32_t index)
  1093. {
  1094. CARLA_ASSERT(index < prog.count);
  1095. }
  1096. void CarlaPlugin::uiMidiProgramChange(const uint32_t index)
  1097. {
  1098. CARLA_ASSERT(index < midiprog.count);
  1099. }
  1100. void CarlaPlugin::uiNoteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  1101. {
  1102. CARLA_ASSERT(channel < 16);
  1103. CARLA_ASSERT(note < 128);
  1104. CARLA_ASSERT(velo > 0 && velo < 128);
  1105. }
  1106. void CarlaPlugin::uiNoteOff(const uint8_t channel, const uint8_t note)
  1107. {
  1108. CARLA_ASSERT(channel < 16);
  1109. CARLA_ASSERT(note < 128);
  1110. }
  1111. // -------------------------------------------------------------------
  1112. // Cleanup
  1113. void CarlaPlugin::removeClientPorts()
  1114. {
  1115. qDebug("CarlaPlugin::removeClientPorts() - start");
  1116. for (uint32_t i=0; i < aIn.count; i++)
  1117. {
  1118. delete aIn.ports[i];
  1119. aIn.ports[i] = nullptr;
  1120. }
  1121. for (uint32_t i=0; i < aOut.count; i++)
  1122. {
  1123. delete aOut.ports[i];
  1124. aOut.ports[i] = nullptr;
  1125. }
  1126. if (midi.portMin)
  1127. {
  1128. delete midi.portMin;
  1129. midi.portMin = nullptr;
  1130. }
  1131. if (midi.portMout)
  1132. {
  1133. delete midi.portMout;
  1134. midi.portMout = nullptr;
  1135. }
  1136. if (param.portCin)
  1137. {
  1138. delete param.portCin;
  1139. param.portCin = nullptr;
  1140. }
  1141. if (param.portCout)
  1142. {
  1143. delete param.portCout;
  1144. param.portCout = nullptr;
  1145. }
  1146. qDebug("CarlaPlugin::removeClientPorts() - end");
  1147. }
  1148. void CarlaPlugin::initBuffers()
  1149. {
  1150. for (uint32_t i=0; i < aIn.count; i++)
  1151. {
  1152. if (aIn.ports[i])
  1153. aIn.ports[i]->initBuffer(x_engine);
  1154. }
  1155. for (uint32_t i=0; i < aOut.count; i++)
  1156. {
  1157. if (aOut.ports[i])
  1158. aOut.ports[i]->initBuffer(x_engine);
  1159. }
  1160. if (param.portCin)
  1161. param.portCin->initBuffer(x_engine);
  1162. if (param.portCout)
  1163. param.portCout->initBuffer(x_engine);
  1164. if (midi.portMin)
  1165. midi.portMin->initBuffer(x_engine);
  1166. if (midi.portMout)
  1167. midi.portMout->initBuffer(x_engine);
  1168. }
  1169. void CarlaPlugin::deleteBuffers()
  1170. {
  1171. qDebug("CarlaPlugin::deleteBuffers() - start");
  1172. if (aIn.count > 0)
  1173. {
  1174. delete[] aIn.ports;
  1175. delete[] aIn.rindexes;
  1176. }
  1177. if (aOut.count > 0)
  1178. {
  1179. delete[] aOut.ports;
  1180. delete[] aOut.rindexes;
  1181. }
  1182. if (param.count > 0)
  1183. {
  1184. delete[] param.data;
  1185. delete[] param.ranges;
  1186. }
  1187. aIn.count = 0;
  1188. aIn.ports = nullptr;
  1189. aIn.rindexes = nullptr;
  1190. aOut.count = 0;
  1191. aOut.ports = nullptr;
  1192. aOut.rindexes = nullptr;
  1193. param.count = 0;
  1194. param.data = nullptr;
  1195. param.ranges = nullptr;
  1196. param.portCin = nullptr;
  1197. param.portCout = nullptr;
  1198. qDebug("CarlaPlugin::deleteBuffers() - end");
  1199. }
  1200. // -------------------------------------------------------------------
  1201. // Library functions
  1202. bool CarlaPlugin::libOpen(const char* const filename)
  1203. {
  1204. m_lib = lib_open(filename);
  1205. return bool(m_lib);
  1206. }
  1207. bool CarlaPlugin::libClose()
  1208. {
  1209. if (m_lib)
  1210. return lib_close(m_lib);
  1211. return false;
  1212. }
  1213. void* CarlaPlugin::libSymbol(const char* const symbol)
  1214. {
  1215. if (m_lib)
  1216. return lib_symbol(m_lib, symbol);
  1217. return nullptr;
  1218. }
  1219. const char* CarlaPlugin::libError(const char* const filename)
  1220. {
  1221. return lib_error(filename);
  1222. }
  1223. // -------------------------------------------------------------------
  1224. // Locks
  1225. void CarlaPlugin::engineProcessLock()
  1226. {
  1227. x_engine->processLock();
  1228. }
  1229. void CarlaPlugin::engineProcessUnlock()
  1230. {
  1231. x_engine->processUnlock();
  1232. }
  1233. void CarlaPlugin::engineMidiLock()
  1234. {
  1235. x_engine->midiLock();
  1236. }
  1237. void CarlaPlugin::engineMidiUnlock()
  1238. {
  1239. x_engine->midiUnlock();
  1240. }
  1241. CARLA_BACKEND_END_NAMESPACE