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.

846 lines
21KB

  1. /*
  2. * Carla Plugin bridge code
  3. * Copyright (C) 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. #ifdef BUILD_BRIDGE_PLUGIN
  18. #include "carla_bridge_client.hpp"
  19. #include "carla_backend_utils.hpp"
  20. #include "carla_plugin.hpp"
  21. #include <set>
  22. #include <QtCore/QDir>
  23. #include <QtCore/QFile>
  24. #include <QtCore/QTextStream>
  25. #include <QtCore/QTimerEvent>
  26. #include <QtGui/QApplication>
  27. #include <QtGui/QMainWindow>
  28. #include <QtGui/QtEvents>
  29. #ifdef Q_OS_UNIX
  30. # include <signal.h>
  31. #endif
  32. static int qargc = 0;
  33. static char** qargv = nullptr;
  34. static bool qCloseNow = false;
  35. #if defined(Q_OS_UNIX)
  36. void closeSignalHandler(int)
  37. {
  38. qCloseNow = true;
  39. }
  40. #elif defined(Q_OS_WIN)
  41. BOOL WINAPI closeSignalHandler(DWORD dwCtrlType)
  42. {
  43. if (dwCtrlType == CTRL_C_EVENT)
  44. {
  45. qCloseNow = true;
  46. return TRUE;
  47. }
  48. return FALSE;
  49. }
  50. #endif
  51. void initSignalHandler()
  52. {
  53. #if defined(Q_OS_UNIX)
  54. struct sigaction sint;
  55. struct sigaction sterm;
  56. sint.sa_handler = closeSignalHandler;
  57. sint.sa_flags = SA_RESTART;
  58. sint.sa_restorer = nullptr;
  59. sigemptyset(&sint.sa_mask);
  60. sigaction(SIGINT, &sint, nullptr);
  61. sterm.sa_handler = closeSignalHandler;
  62. sterm.sa_flags = SA_RESTART;
  63. sterm.sa_restorer = nullptr;
  64. sigemptyset(&sterm.sa_mask);
  65. sigaction(SIGTERM, &sterm, nullptr);
  66. #elif defined(Q_OS_WIN)
  67. SetConsoleCtrlHandler(closeSignalHandler, TRUE);
  68. #endif
  69. }
  70. CARLA_BRIDGE_START_NAMESPACE
  71. // -------------------------------------------------------------------------
  72. class BridgePluginGUI : public QMainWindow
  73. {
  74. public:
  75. class Callback
  76. {
  77. public:
  78. virtual ~Callback() {}
  79. virtual void guiClosedCallback() = 0;
  80. };
  81. BridgePluginGUI(QWidget* const parent, Callback* const callback_)
  82. : QMainWindow(parent),
  83. callback(callback_)
  84. {
  85. qDebug("BridgePluginGUI::BridgePluginGUI(%p, %p", parent, callback);
  86. CARLA_ASSERT(callback);
  87. m_firstShow = true;
  88. m_resizable = true;
  89. container = new GuiContainer(this);
  90. setCentralWidget(container);
  91. setNewSize(50, 50);
  92. }
  93. ~BridgePluginGUI()
  94. {
  95. qDebug("BridgePluginGUI::~BridgePluginGUI()");
  96. CARLA_ASSERT(container);
  97. delete container;
  98. }
  99. GuiContainer* getContainer()
  100. {
  101. return container;
  102. }
  103. void setResizable(bool resizable)
  104. {
  105. m_resizable = resizable;
  106. setNewSize(width(), height());
  107. #ifdef Q_OS_WIN
  108. if (! resizable)
  109. setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
  110. #endif
  111. }
  112. void setTitle(const char* title)
  113. {
  114. CARLA_ASSERT(title);
  115. setWindowTitle(QString("%1 (GUI)").arg(title));
  116. }
  117. void setNewSize(int width, int height)
  118. {
  119. qDebug("BridgePluginGUI::setNewSize(%i, %i)", width, height);
  120. if (width < 30)
  121. width = 30;
  122. if (height < 30)
  123. height = 30;
  124. if (m_resizable)
  125. {
  126. resize(width, height);
  127. }
  128. else
  129. {
  130. setFixedSize(width, height);
  131. container->setFixedSize(width, height);
  132. }
  133. }
  134. void setVisible(const bool yesNo)
  135. {
  136. qDebug("BridgePluginGUI::setVisible(%s)", bool2str(yesNo));
  137. if (yesNo)
  138. {
  139. if (m_firstShow)
  140. {
  141. m_firstShow = false;
  142. restoreGeometry(QByteArray());
  143. }
  144. else if (! m_geometry.isNull())
  145. restoreGeometry(m_geometry);
  146. }
  147. else
  148. m_geometry = saveGeometry();
  149. QMainWindow::setVisible(yesNo);
  150. }
  151. protected:
  152. void hideEvent(QHideEvent* const event)
  153. {
  154. qDebug("BridgePluginGUI::hideEvent(%p)", event);
  155. event->accept();
  156. close();
  157. }
  158. void closeEvent(QCloseEvent* const event)
  159. {
  160. qDebug("BridgePluginGUI::closeEvent(%p)", event);
  161. if (event->spontaneous())
  162. {
  163. callback->guiClosedCallback();
  164. QMainWindow::closeEvent(event);
  165. return;
  166. }
  167. event->ignore();
  168. }
  169. private:
  170. Callback* const callback;
  171. GuiContainer* container;
  172. bool m_firstShow;
  173. bool m_resizable;
  174. QByteArray m_geometry;
  175. };
  176. // -------------------------------------------------------------------------
  177. class BridgePluginClient : public CarlaToolkit,
  178. public CarlaClient,
  179. public BridgePluginGUI::Callback,
  180. public QApplication
  181. {
  182. public:
  183. BridgePluginClient()
  184. : CarlaToolkit("carla-bridge-plugin"),
  185. CarlaClient(this),
  186. QApplication(qargc, qargv, true)
  187. {
  188. qDebug("BridgePluginClient::BridgePluginClient()");
  189. hasUI = false;
  190. msgTimerGUI = 0;
  191. msgTimerOSC = 0;
  192. engine = nullptr;
  193. plugin = nullptr;
  194. pluginGui = nullptr;
  195. m_client = this;
  196. m_needsResize = false;
  197. m_nextSize[0] = 0;
  198. m_nextSize[1] = 0;
  199. }
  200. ~BridgePluginClient()
  201. {
  202. qDebug("BridgePluginClient::~BridgePluginClient()");
  203. CARLA_ASSERT(msgTimerGUI == 0);
  204. CARLA_ASSERT(msgTimerOSC == 0);
  205. CARLA_ASSERT(! pluginGui);
  206. }
  207. void setStuff(CarlaBackend::CarlaEngine* const engine, CarlaBackend::CarlaPlugin* const plugin)
  208. {
  209. qDebug("BridgePluginClient::setStuff(%p, %p)", engine, plugin);
  210. CARLA_ASSERT(engine);
  211. CARLA_ASSERT(plugin);
  212. this->engine = engine;
  213. this->plugin = plugin;
  214. }
  215. // ---------------------------------------------------------------------
  216. // toolkit
  217. void init()
  218. {
  219. qDebug("BridgePluginClient::init()");
  220. pluginGui = new BridgePluginGUI(nullptr, this);
  221. pluginGui->hide();
  222. }
  223. void exec(CarlaClient* const, const bool showGui)
  224. {
  225. qDebug("BridgePluginClient::exec()");
  226. if (showGui)
  227. {
  228. if (hasUI)
  229. show();
  230. }
  231. else
  232. {
  233. CarlaClient::sendOscUpdate();
  234. CarlaClient::sendOscBridgeUpdate();
  235. QApplication::setQuitOnLastWindowClosed(false);
  236. }
  237. msgTimerGUI = startTimer(50);
  238. msgTimerOSC = startTimer(25);
  239. QApplication::exec();
  240. }
  241. void quit()
  242. {
  243. qDebug("BridgePluginClient::quit()");
  244. if (msgTimerGUI != 0)
  245. {
  246. QApplication::killTimer(msgTimerGUI);
  247. msgTimerGUI = 0;
  248. }
  249. if (msgTimerOSC != 0)
  250. {
  251. QApplication::killTimer(msgTimerOSC);
  252. msgTimerOSC = 0;
  253. }
  254. if (pluginGui)
  255. {
  256. if (pluginGui->isVisible())
  257. hide();
  258. pluginGui->close();
  259. delete pluginGui;
  260. pluginGui = nullptr;
  261. }
  262. if (! QApplication::closingDown())
  263. QApplication::quit();
  264. }
  265. void show()
  266. {
  267. qDebug("BridgePluginClient::show()");
  268. CARLA_ASSERT(pluginGui);
  269. if (plugin)
  270. plugin->showGui(true);
  271. if (pluginGui)
  272. pluginGui->show();
  273. }
  274. void hide()
  275. {
  276. qDebug("BridgePluginClient::hide()");
  277. CARLA_ASSERT(pluginGui);
  278. if (pluginGui)
  279. pluginGui->hide();
  280. if (plugin)
  281. plugin->showGui(false);
  282. }
  283. void resize(int width, int height)
  284. {
  285. qDebug("BridgePluginClient::resize(%i, %i)", width, height);
  286. CARLA_ASSERT(pluginGui);
  287. if (pluginGui)
  288. pluginGui->setNewSize(width, height);
  289. }
  290. // ---------------------------------------------------------------------
  291. void createWindow(const bool resizable)
  292. {
  293. qDebug("BridgePluginClient::createWindow(%s)", bool2str(resizable));
  294. CARLA_ASSERT(plugin);
  295. CARLA_ASSERT(pluginGui);
  296. if (! (plugin && pluginGui))
  297. return;
  298. hasUI = true;
  299. pluginGui->setResizable(resizable);
  300. pluginGui->setTitle(plugin->name());
  301. plugin->setGuiContainer(pluginGui->getContainer());
  302. }
  303. // ---------------------------------------------------------------------
  304. // processing
  305. void setParameter(const int32_t rindex, const double value)
  306. {
  307. qDebug("CarlaPluginClient::setParameter(%i, %g)", rindex, value);
  308. CARLA_ASSERT(plugin);
  309. if (! plugin)
  310. return;
  311. plugin->setParameterValueByRIndex(rindex, value, true, true, false);
  312. }
  313. void setProgram(const uint32_t index)
  314. {
  315. qDebug("CarlaPluginClient::setProgram(%i)", index);
  316. CARLA_ASSERT(engine);
  317. CARLA_ASSERT(plugin);
  318. CARLA_ASSERT(index < plugin->programCount());
  319. if (! (plugin && engine))
  320. return;
  321. if (index >= plugin->programCount())
  322. return;
  323. plugin->setProgram(index, true, true, false, true);
  324. double value;
  325. for (uint32_t i=0; i < plugin->parameterCount(); i++)
  326. {
  327. value = plugin->getParameterValue(i);
  328. engine->osc_send_bridge_set_parameter_value(i, value);
  329. engine->osc_send_bridge_set_default_value(i, value);
  330. }
  331. }
  332. void setMidiProgram(const uint32_t index)
  333. {
  334. qDebug("CarlaPluginClient::setMidiProgram(%i)", index);
  335. CARLA_ASSERT(engine);
  336. CARLA_ASSERT(plugin);
  337. if (! (plugin && engine))
  338. return;
  339. plugin->setMidiProgram(index, true, true, false, true);
  340. double value;
  341. for (uint32_t i=0; i < plugin->parameterCount(); i++)
  342. {
  343. value = plugin->getParameterValue(i);
  344. engine->osc_send_bridge_set_parameter_value(i, value);
  345. engine->osc_send_bridge_set_default_value(i, value);
  346. }
  347. }
  348. void noteOn(const uint8_t channel, const uint8_t note, const uint8_t velo)
  349. {
  350. qDebug("CarlaPluginClient::noteOn(%i, %i, %i)", channel, note, velo);
  351. CARLA_ASSERT(plugin);
  352. CARLA_ASSERT(velo > 0);
  353. if (! plugin)
  354. return;
  355. plugin->sendMidiSingleNote(channel, note, velo, true, true, false);
  356. }
  357. void noteOff(const uint8_t channel, const uint8_t note)
  358. {
  359. qDebug("CarlaPluginClient::noteOff(%i, %i)", channel, note);
  360. CARLA_ASSERT(plugin);
  361. if (! plugin)
  362. return;
  363. plugin->sendMidiSingleNote(channel, note, 0, true, true, false);
  364. }
  365. // ---------------------------------------------------------------------
  366. // plugin
  367. void saveNow()
  368. {
  369. qDebug("CarlaPluginClient::saveNow()");
  370. CARLA_ASSERT(plugin);
  371. CARLA_ASSERT(engine);
  372. if (! (plugin && engine))
  373. return;
  374. plugin->prepareForSave();
  375. for (uint32_t i=0; i < plugin->customDataCount(); i++)
  376. {
  377. const CarlaBackend::CustomData* const cdata = plugin->customData(i);
  378. engine->osc_send_bridge_set_custom_data(cdata->type, cdata->key, cdata->value);
  379. }
  380. if (plugin->hints() & CarlaBackend::PLUGIN_USES_CHUNKS)
  381. {
  382. void* data = nullptr;
  383. int32_t dataSize = plugin->chunkData(&data);
  384. if (data && dataSize >= 4)
  385. {
  386. QString filePath;
  387. filePath = QDir::tempPath();
  388. #ifdef Q_OS_WIN
  389. filePath += "\\.CarlaChunk_";
  390. #else
  391. filePath += "/.CarlaChunk_";
  392. #endif
  393. filePath += plugin->name();
  394. QFile file(filePath);
  395. if (file.open(QIODevice::WriteOnly))
  396. {
  397. QByteArray chunk((const char*)data, dataSize);
  398. file.write(chunk);
  399. file.close();
  400. engine->osc_send_bridge_set_chunk_data(filePath.toUtf8().constData());
  401. }
  402. }
  403. }
  404. engine->osc_send_bridge_configure(CarlaBackend::CARLA_BRIDGE_MSG_SAVED, "");
  405. }
  406. void setCustomData(const char* const type, const char* const key, const char* const value)
  407. {
  408. qDebug("CarlaPluginClient::setCustomData(\"%s\", \"%s\", \"%s\")", type, key, value);
  409. CARLA_ASSERT(plugin);
  410. if (! plugin)
  411. return;
  412. plugin->setCustomData(type, key, value, true);
  413. }
  414. void setChunkData(const char* const filePath)
  415. {
  416. qDebug("CarlaPluginClient::setChunkData(\"%s\")", filePath);
  417. CARLA_ASSERT(plugin);
  418. if (! plugin)
  419. return;
  420. QString chunkFilePath(filePath);
  421. #ifdef Q_OS_WIN
  422. if (chunkFilePath.startsWith("/"))
  423. {
  424. // running under Wine, posix host
  425. chunkFilePath = chunkFilePath.replace(0, 1, "Z:/");
  426. chunkFilePath = QDir::toNativeSeparators(chunkFilePath);
  427. }
  428. #endif
  429. QFile chunkFile(chunkFilePath);
  430. if (plugin && chunkFile.open(QIODevice::ReadOnly | QIODevice::Text))
  431. {
  432. QTextStream in(&chunkFile);
  433. QString stringData(in.readAll());
  434. chunkFile.close();
  435. chunkFile.remove();
  436. plugin->setChunkData(stringData.toUtf8().constData());
  437. }
  438. }
  439. // ---------------------------------------------------------------------
  440. // callback
  441. void handleCallback(const CarlaBackend::CallbackType action, const int value1, const int value2, const double value3, const char* const valueStr)
  442. {
  443. qDebug("CarlaPluginClient::handleCallback(%s, %i, %i, %g \"%s\")", CarlaBackend::CallbackType2Str(action), value1, value2, value3, valueStr);
  444. if (! engine)
  445. return;
  446. switch (action)
  447. {
  448. case CarlaBackend::CALLBACK_PARAMETER_VALUE_CHANGED:
  449. #if 0
  450. parametersToUpdate.insert(value1);
  451. #endif
  452. engine->osc_send_bridge_set_parameter_value(value1, value3);
  453. break;
  454. case CarlaBackend::CALLBACK_PROGRAM_CHANGED:
  455. engine->osc_send_bridge_set_program(value1);
  456. break;
  457. case CarlaBackend::CALLBACK_MIDI_PROGRAM_CHANGED:
  458. engine->osc_send_bridge_set_midi_program(value1);
  459. break;
  460. case CarlaBackend::CALLBACK_NOTE_ON:
  461. {
  462. //uint8_t mdata[4] = { 0, MIDI_STATUS_NOTE_ON, (uint8_t)value1, (uint8_t)value2 };
  463. //osc_send_midi(mdata);
  464. break;
  465. }
  466. case CarlaBackend::CALLBACK_NOTE_OFF:
  467. {
  468. //uint8_t mdata[4] = { 0, MIDI_STATUS_NOTE_OFF, (uint8_t)value1, (uint8_t)value2 };
  469. //osc_send_midi(mdata);
  470. break;
  471. }
  472. case CarlaBackend::CALLBACK_SHOW_GUI:
  473. if (value1 == 0)
  474. engine->osc_send_bridge_configure(CarlaBackend::CARLA_BRIDGE_MSG_HIDE_GUI, "");
  475. break;
  476. case CarlaBackend::CALLBACK_RESIZE_GUI:
  477. CARLA_ASSERT(value1 > 0 && value2 > 0);
  478. CARLA_ASSERT(pluginGui);
  479. if (value1 > 0 && value2 > 0 && pluginGui)
  480. {
  481. m_needsResize = true;
  482. m_nextSize[0] = value1;
  483. m_nextSize[1] = value2;
  484. }
  485. break;
  486. case CarlaBackend::CALLBACK_RELOAD_PARAMETERS:
  487. //if (CARLA_PLUGIN)
  488. //{
  489. // for (uint32_t i=0; i < CARLA_PLUGIN->parameterCount(); i++)
  490. // {
  491. // osc_send_control(i, CARLA_PLUGIN->getParameterValue(i));
  492. // }
  493. //}
  494. break;
  495. case CarlaBackend::CALLBACK_QUIT:
  496. //QApplication::quit();
  497. break;
  498. default:
  499. break;
  500. }
  501. }
  502. // ---------------------------------------------------------------------
  503. static void callback(void* const ptr, CarlaBackend::CallbackType const action, const unsigned short, const int value1, const int value2, const double value3, const char* const valueStr)
  504. {
  505. CARLA_ASSERT(ptr);
  506. if (! ptr)
  507. return;
  508. BridgePluginClient* const _this_ = (BridgePluginClient*)ptr;
  509. _this_->handleCallback(action, value1, value2, value3, valueStr);
  510. }
  511. protected:
  512. void guiClosedCallback()
  513. {
  514. if (engine)
  515. engine->osc_send_bridge_configure(CarlaBackend::CARLA_BRIDGE_MSG_HIDE_GUI, "");
  516. }
  517. void timerEvent(QTimerEvent* const event)
  518. {
  519. if (qCloseNow)
  520. return quit();
  521. if (event->timerId() == msgTimerGUI)
  522. {
  523. #if 0
  524. if (parametersToUpdate.size() > 0)
  525. {
  526. for (auto it = parametersToUpdate.begin(); it != parametersToUpdate.end(); it++)
  527. {
  528. const int32_t paramId(*it);
  529. engine->osc_send_bridge_set_parameter_value(paramId, plugin->getParameterValue(paramId));
  530. }
  531. parametersToUpdate.clear();
  532. }
  533. #endif
  534. if (plugin)
  535. plugin->idleGui();
  536. if (pluginGui && m_needsResize)
  537. {
  538. pluginGui->setNewSize(m_nextSize[0], m_nextSize[1]);
  539. m_needsResize = false;
  540. }
  541. }
  542. else if (event->timerId() == msgTimerOSC)
  543. {
  544. if (! CarlaClient::oscIdle())
  545. {
  546. CARLA_ASSERT(msgTimerOSC == 0);
  547. msgTimerOSC = 0;
  548. return;
  549. }
  550. }
  551. QApplication::timerEvent(event);
  552. }
  553. // ---------------------------------------------------------------------
  554. private:
  555. bool hasUI;
  556. int msgTimerGUI, msgTimerOSC;
  557. #if 0
  558. std::set<int32_t> parametersToUpdate;
  559. #endif
  560. bool m_needsResize;
  561. int m_nextSize[2];
  562. CarlaBackend::CarlaEngine* engine;
  563. CarlaBackend::CarlaPlugin* plugin;
  564. BridgePluginGUI* pluginGui;
  565. };
  566. // -------------------------------------------------------------------------
  567. CARLA_BRIDGE_END_NAMESPACE
  568. int main(int argc, char* argv[])
  569. {
  570. if (argc != 6)
  571. {
  572. qWarning("usage: %s <osc-url|\"null\"> <type> <filename> <name|\"(none)\"> <label>", argv[0]);
  573. return 1;
  574. }
  575. qargc = argc;
  576. qargv = argv;
  577. const char* const oscUrl = argv[1];
  578. const char* const stype = argv[2];
  579. const char* const filename = argv[3];
  580. const char* name = argv[4];
  581. const char* const label = argv[5];
  582. const bool useOsc = strcmp(oscUrl, "null");
  583. if (strcmp(name, "(none)") == 0)
  584. name = nullptr;
  585. CarlaBackend::PluginType itype;
  586. if (strcmp(stype, "LADSPA") == 0)
  587. itype = CarlaBackend::PLUGIN_LADSPA;
  588. else if (strcmp(stype, "DSSI") == 0)
  589. itype = CarlaBackend::PLUGIN_DSSI;
  590. else if (strcmp(stype, "LV2") == 0)
  591. itype = CarlaBackend::PLUGIN_LV2;
  592. else if (strcmp(stype, "VST") == 0)
  593. itype = CarlaBackend::PLUGIN_VST;
  594. else
  595. {
  596. itype = CarlaBackend::PLUGIN_NONE;
  597. qWarning("Invalid plugin type '%s'", stype);
  598. return 1;
  599. }
  600. // Init bridge client
  601. CarlaBridge::BridgePluginClient client;
  602. client.init();
  603. // Init OSC
  604. if (useOsc && ! client.oscInit(oscUrl))
  605. {
  606. client.quit();
  607. return -1;
  608. }
  609. // Listen for ctrl+c or sigint/sigterm events
  610. initSignalHandler();
  611. // Init backend engine
  612. CarlaBackend::CarlaEngine* engine = CarlaBackend::CarlaEngine::newDriverByName("JACK");
  613. engine->setCallback(client.callback, &client);
  614. // bridge client <-> engine
  615. client.registerOscEngine(engine);
  616. // Init engine
  617. QString engName = QString("%1 (master)").arg(name ? name : label);
  618. engName.truncate(engine->maxClientNameSize());
  619. if (! engine->init(engName.toUtf8().constData()))
  620. {
  621. const char* const lastError = engine->getLastError();
  622. qWarning("Bridge engine failed to start, error was:\n%s", lastError);
  623. engine->close();
  624. delete engine;
  625. client.sendOscBridgeError(lastError);
  626. client.quit();
  627. return 2;
  628. }
  629. // Init plugin
  630. short id = engine->addPlugin(itype, filename, name, label);
  631. int ret;
  632. if (id >= 0 && id < CarlaBackend::MAX_PLUGINS)
  633. {
  634. CarlaBackend::CarlaPlugin* const plugin = engine->getPlugin(id);
  635. client.setStuff(engine, plugin);
  636. // create window if needed
  637. bool guiResizable;
  638. CarlaBackend::GuiType guiType;
  639. plugin->getGuiInfo(&guiType, &guiResizable);
  640. if (guiType == CarlaBackend::GUI_INTERNAL_QT4 || guiType == CarlaBackend::GUI_INTERNAL_COCOA || guiType == CarlaBackend::GUI_INTERNAL_HWND || guiType == CarlaBackend::GUI_INTERNAL_X11)
  641. {
  642. client.createWindow(guiResizable);
  643. }
  644. if (! useOsc)
  645. plugin->setActive(true, false, false);
  646. client.exec(nullptr, !useOsc);
  647. ret = 0;
  648. }
  649. else
  650. {
  651. const char* const lastError = engine->getLastError();
  652. qWarning("Plugin failed to load, error was:\n%s", lastError);
  653. if (useOsc)
  654. client.sendOscBridgeError(lastError);
  655. ret = 1;
  656. }
  657. engine->removeAllPlugins();
  658. engine->close();
  659. delete engine;
  660. if (useOsc)
  661. {
  662. // Close OSC
  663. client.oscClose();
  664. // bridge client can't be closed manually, only by host
  665. }
  666. else
  667. {
  668. // Close bridge client
  669. client.quit();
  670. }
  671. return ret;
  672. }
  673. #endif // BUILD_BRIDGE_PLUGIN