Audio plugin host https://kx.studio/carla
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.

719 lines
20KB

  1. /*
  2. * Carla Bridge Plugin
  3. * Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaBridgeClient.hpp"
  18. #include "CarlaEngine.hpp"
  19. #include "CarlaPlugin.hpp"
  20. #include "CarlaHost.h"
  21. #include "CarlaBackendUtils.hpp"
  22. #include "CarlaBridgeUtils.hpp"
  23. #include "CarlaMIDI.h"
  24. #ifdef CARLA_OS_UNIX
  25. # include <signal.h>
  26. #endif
  27. #ifdef HAVE_JUCE
  28. # include "juce_gui_basics.h"
  29. using juce::JUCEApplication;
  30. using juce::JUCEApplicationBase;
  31. using juce::String;
  32. using juce::Timer;
  33. #endif
  34. // -------------------------------------------------------------------------
  35. static bool gIsInitiated = false;
  36. static volatile bool gCloseNow = false;
  37. static volatile bool gSaveNow = false;
  38. #ifdef CARLA_OS_WIN
  39. static BOOL WINAPI winSignalHandler(DWORD dwCtrlType)
  40. {
  41. if (dwCtrlType == CTRL_C_EVENT)
  42. {
  43. gCloseNow = true;
  44. return TRUE;
  45. }
  46. return FALSE;
  47. }
  48. #elif defined(CARLA_OS_LINUX)
  49. static void closeSignalHandler(int)
  50. {
  51. gCloseNow = true;
  52. }
  53. static void saveSignalHandler(int)
  54. {
  55. gSaveNow = true;
  56. }
  57. #endif
  58. static void initSignalHandler()
  59. {
  60. #ifdef CARLA_OS_WIN
  61. SetConsoleCtrlHandler(winSignalHandler, TRUE);
  62. #elif defined(CARLA_OS_LINUX)
  63. struct sigaction sint;
  64. struct sigaction sterm;
  65. struct sigaction susr1;
  66. sint.sa_handler = closeSignalHandler;
  67. sint.sa_flags = SA_RESTART;
  68. sint.sa_restorer = nullptr;
  69. sigemptyset(&sint.sa_mask);
  70. sigaction(SIGINT, &sint, nullptr);
  71. sterm.sa_handler = closeSignalHandler;
  72. sterm.sa_flags = SA_RESTART;
  73. sterm.sa_restorer = nullptr;
  74. sigemptyset(&sterm.sa_mask);
  75. sigaction(SIGTERM, &sterm, nullptr);
  76. susr1.sa_handler = saveSignalHandler;
  77. susr1.sa_flags = SA_RESTART;
  78. susr1.sa_restorer = nullptr;
  79. sigemptyset(&susr1.sa_mask);
  80. sigaction(SIGUSR1, &susr1, nullptr);
  81. #endif
  82. }
  83. // -------------------------------------------------------------------------
  84. #ifdef HAVE_JUCE
  85. static CarlaBridge::CarlaBridgeClient* gBridgeClient = nullptr;
  86. class CarlaJuceApp : public JUCEApplication,
  87. Timer
  88. {
  89. public:
  90. CarlaJuceApp() {}
  91. ~CarlaJuceApp() {}
  92. void initialise(const String&) override
  93. {
  94. startTimer(30);
  95. }
  96. void shutdown() override
  97. {
  98. gCloseNow = true;
  99. stopTimer();
  100. }
  101. const String getApplicationName() override
  102. {
  103. return "CarlaPlugin";
  104. }
  105. const String getApplicationVersion() override
  106. {
  107. return CARLA_VERSION_STRING;
  108. }
  109. void timerCallback() override
  110. {
  111. carla_engine_idle();
  112. if (gBridgeClient != nullptr)
  113. gBridgeClient->oscIdle();
  114. if (gCloseNow)
  115. {
  116. quit();
  117. gCloseNow = false;
  118. }
  119. }
  120. };
  121. static JUCEApplicationBase* juce_CreateApplication() { return new CarlaJuceApp(); }
  122. #endif
  123. // -------------------------------------------------------------------------
  124. CARLA_BRIDGE_START_NAMESPACE
  125. #if 0
  126. } // Fix editor indentation
  127. #endif
  128. // -------------------------------------------------------------------------
  129. class CarlaPluginClient : public CarlaBridgeClient
  130. {
  131. public:
  132. CarlaPluginClient(const bool useBridge, const char* const clientName, const char* audioBaseName, const char* controlBaseName)
  133. : CarlaBridgeClient(nullptr),
  134. fPlugin(nullptr),
  135. fEngine(nullptr)
  136. {
  137. CARLA_ASSERT(clientName != nullptr && clientName[0] != '\0');
  138. carla_debug("CarlaPluginClient::CarlaPluginClient(%s, \"%s\", %s, %s)", bool2str(useBridge), clientName, audioBaseName, controlBaseName);
  139. carla_set_engine_callback(callback, this);
  140. #if 0
  141. File curDir(File::getSpecialLocation(File::currentApplicationFile).getParentDirectory());
  142. if (curDir.getChildFile("resources").exists())
  143. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("resources").getFullPathName().toRawUTF8());
  144. else if (curDir.getChildFile("../../modules/daz-plugins/resources").exists())
  145. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../../modules/daz-plugins/resources").getFullPathName().toRawUTF8());
  146. else
  147. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../modules/daz-plugins/resources").getFullPathName().toRawUTF8());
  148. #endif
  149. if (useBridge)
  150. carla_engine_init_bridge(audioBaseName, controlBaseName, clientName);
  151. else
  152. carla_engine_init("JACK", clientName);
  153. fEngine = carla_get_engine();
  154. }
  155. ~CarlaPluginClient() override
  156. {
  157. carla_debug("CarlaPluginClient::~CarlaPluginClient()");
  158. #ifdef HAVE_JUCE
  159. gBridgeClient = nullptr;
  160. #endif
  161. carla_engine_close();
  162. }
  163. bool isOk() const noexcept
  164. {
  165. return (fEngine != nullptr);
  166. }
  167. void oscInit(const char* const url)
  168. {
  169. CarlaBridgeClient::oscInit(url);
  170. fEngine->setOscBridgeData(&fOscData);
  171. }
  172. void ready(const bool doSaveLoad)
  173. {
  174. fPlugin = fEngine->getPlugin(0);
  175. if (doSaveLoad)
  176. {
  177. fProjFileName = fPlugin->getName();
  178. fProjFileName += ".carxs";
  179. //if (! File::isAbsolutePath((const char*)fProjFileName))
  180. // fProjFileName = File::getCurrentWorkingDirectory().getChildFile((const char*)fProjFileName).getFullPathName().toRawUTF8();
  181. //if (! fPlugin->loadStateFromFile(fProjFileName))
  182. // carla_stderr("Plugin preset load failed, error was:\n%s", fEngine->getLastError());
  183. }
  184. }
  185. #ifndef HAVE_JUCE
  186. void idle()
  187. {
  188. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  189. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  190. carla_engine_idle();
  191. CarlaBridgeClient::oscIdle();
  192. if (gSaveNow)
  193. {
  194. gSaveNow = false;
  195. if (fProjFileName.isNotEmpty())
  196. {
  197. if (! fPlugin->saveStateToFile(fProjFileName))
  198. carla_stderr("Plugin preset save failed, error was:\n%s", fEngine->getLastError());
  199. }
  200. }
  201. if (gCloseNow)
  202. {
  203. //gCloseNow = false;
  204. // close something?
  205. }
  206. }
  207. #endif
  208. void exec(int argc, char* argv[])
  209. {
  210. #ifdef HAVE_JUCE
  211. gBridgeClient = this;
  212. JUCEApplicationBase::createInstance = &juce_CreateApplication;
  213. JUCEApplicationBase::main(JUCE_MAIN_FUNCTION_ARGS);
  214. #else
  215. for (; ! gCloseNow;)
  216. {
  217. idle();
  218. carla_msleep(24);
  219. }
  220. #endif
  221. return; (void)argc; (void)argv;
  222. }
  223. // ---------------------------------------------------------------------
  224. // plugin management
  225. void saveNow()
  226. {
  227. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  228. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  229. carla_debug("CarlaPluginClient::saveNow()");
  230. fPlugin->prepareForSave();
  231. for (uint32_t i=0; i < fPlugin->getCustomDataCount(); ++i)
  232. {
  233. const CarlaBackend::CustomData& cdata(fPlugin->getCustomData(i));
  234. fEngine->oscSend_bridge_set_custom_data(cdata.type, cdata.key, cdata.value);
  235. }
  236. if (fPlugin->getOptionsEnabled() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  237. {
  238. void* data = nullptr;
  239. int32_t dataSize = fPlugin->getChunkData(&data);
  240. if (data && dataSize >= 4)
  241. {
  242. #if 0
  243. QString filePath;
  244. filePath = QDir::tempPath();
  245. #ifdef Q_OS_WIN
  246. filePath += "\\.CarlaChunk_";
  247. #else
  248. filePath += "/.CarlaChunk_";
  249. #endif
  250. filePath += fPlugin->getName();
  251. QFile file(filePath);
  252. if (file.open(QIODevice::WriteOnly))
  253. {
  254. QByteArray chunk((const char*)data, dataSize);
  255. file.write(chunk);
  256. file.close();
  257. fEngine->oscSend_bridge_set_chunk_data(filePath.toUtf8().constData());
  258. }
  259. #endif
  260. }
  261. }
  262. fEngine->oscSend_bridge_configure(CARLA_BRIDGE_MSG_SAVED, "");
  263. }
  264. void setParameterMidiChannel(const uint32_t index, const uint8_t channel)
  265. {
  266. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  267. carla_debug("CarlaPluginClient::setParameterMidiChannel(%i, %i)", index, channel);
  268. fPlugin->setParameterMidiChannel(index, channel, false, false);
  269. }
  270. void setParameterMidiCC(const uint32_t index, const int16_t cc)
  271. {
  272. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  273. carla_debug("CarlaPluginClient::setParameterMidiCC(%i, %i)", index, cc);
  274. fPlugin->setParameterMidiCC(index, cc, false, false);
  275. }
  276. void setCustomData(const char* const type, const char* const key, const char* const value)
  277. {
  278. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  279. carla_debug("CarlaPluginClient::setCustomData(\"%s\", \"%s\", \"%s\")", type, key, value);
  280. fPlugin->setCustomData(type, key, value, true);
  281. }
  282. void setChunkData(const char* const filePath)
  283. {
  284. CARLA_SAFE_ASSERT_RETURN(filePath != nullptr && filePath[0] != '\0',);
  285. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  286. carla_debug("CarlaPluginClient::setChunkData(\"%s\")", filePath);
  287. #if 0
  288. QString chunkFilePath(filePath);
  289. #ifdef CARLA_OS_WIN
  290. if (chunkFilePath.startsWith("/"))
  291. {
  292. // running under Wine, posix host
  293. chunkFilePath = chunkFilePath.replace(0, 1, "Z:/");
  294. chunkFilePath = QDir::toNativeSeparators(chunkFilePath);
  295. }
  296. #endif
  297. QFile chunkFile(chunkFilePath);
  298. if (fPlugin != nullptr && chunkFile.open(QIODevice::ReadOnly | QIODevice::Text))
  299. {
  300. QTextStream in(&chunkFile);
  301. QString stringData(in.readAll());
  302. chunkFile.close();
  303. chunkFile.remove();
  304. fPlugin->setChunkData(stringData.toUtf8().constData());
  305. }
  306. #endif
  307. }
  308. // ---------------------------------------------------------------------
  309. protected:
  310. void handleCallback(const CarlaBackend::EngineCallbackOpcode action, const int value1, const int value2, const float value3, const char* const valueStr)
  311. {
  312. CARLA_BACKEND_USE_NAMESPACE;
  313. // TODO
  314. switch (action)
  315. {
  316. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  317. if (isOscControlRegistered())
  318. sendOscControl(value1, value3);
  319. break;
  320. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  321. if (! isOscControlRegistered())
  322. {
  323. if (value1 != 1 && gIsInitiated)
  324. gCloseNow = true;
  325. }
  326. else
  327. {
  328. // show-gui button
  329. fEngine->oscSend_bridge_configure(CARLA_BRIDGE_MSG_HIDE_GUI, "");
  330. }
  331. break;
  332. default:
  333. break;
  334. }
  335. return;
  336. (void)value2;
  337. (void)value3;
  338. (void)valueStr;
  339. }
  340. private:
  341. CarlaBackend::CarlaPlugin* fPlugin;
  342. const CarlaBackend::CarlaEngine* fEngine;
  343. CarlaString fProjFileName;
  344. static void callback(void* ptr, CarlaBackend::EngineCallbackOpcode action, unsigned int pluginId, int value1, int value2, float value3, const char* valueStr)
  345. {
  346. carla_debug("CarlaPluginClient::callback(%p, %i:%s, %i, %i, %i, %f, \"%s\")", ptr, action, CarlaBackend::EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  347. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr,);
  348. CARLA_SAFE_ASSERT_RETURN(pluginId == 0,);
  349. return ((CarlaPluginClient*)ptr)->handleCallback(action, value1, value2, value3, valueStr);
  350. }
  351. };
  352. // -------------------------------------------------------------------------
  353. int CarlaBridgeOsc::handleMsgShow()
  354. {
  355. carla_debug("CarlaBridgeOsc::handleMsgShow()");
  356. #ifdef HAVE_JUCE
  357. const juce::MessageManagerLock mmLock;
  358. #endif
  359. if (carla_get_plugin_info(0)->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  360. carla_show_custom_ui(0, true);
  361. return 0;
  362. }
  363. int CarlaBridgeOsc::handleMsgHide()
  364. {
  365. carla_debug("CarlaBridgeOsc::handleMsgHide()");
  366. #ifdef HAVE_JUCE
  367. const juce::MessageManagerLock mmLock;
  368. #endif
  369. if (carla_get_plugin_info(0)->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  370. carla_show_custom_ui(0, false);
  371. return 0;
  372. }
  373. int CarlaBridgeOsc::handleMsgQuit()
  374. {
  375. carla_debug("CarlaBridgeOsc::handleMsgQuit()");
  376. gCloseNow = true;
  377. return 0;
  378. }
  379. // -------------------------------------------------------------------------
  380. int CarlaBridgeOsc::handleMsgPluginSaveNow()
  381. {
  382. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  383. carla_debug("CarlaBridgeOsc::handleMsgPluginSaveNow()");
  384. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  385. plugClient->saveNow();
  386. return 0;
  387. }
  388. int CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  389. {
  390. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii");
  391. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  392. carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel()");
  393. const int32_t index = argv[0]->i;
  394. const int32_t channel = argv[1]->i;
  395. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  396. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  397. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  398. plugClient->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel));
  399. return 0;
  400. }
  401. int CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  402. {
  403. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii");
  404. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  405. carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC()");
  406. const int32_t index = argv[0]->i;
  407. const int32_t cc = argv[1]->i;
  408. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  409. CARLA_SAFE_ASSERT_RETURN(cc >= 1 && cc < 0x5F, 0);
  410. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  411. plugClient->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc));
  412. return 0;
  413. }
  414. int CarlaBridgeOsc::handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  415. {
  416. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(1, "s");
  417. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  418. carla_debug("CarlaBridgeOsc::handleMsgPluginSetChunk()");
  419. const char* const chunkFile = (const char*)&argv[0]->s;
  420. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  421. plugClient->setChunkData(chunkFile);
  422. return 0;
  423. }
  424. int CarlaBridgeOsc::handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  425. {
  426. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(3, "sss");
  427. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  428. carla_debug("CarlaBridgeOsc::handleMsgPluginSetCustomData()");
  429. const char* const type = (const char*)&argv[0]->s;
  430. const char* const key = (const char*)&argv[1]->s;
  431. const char* const value = (const char*)&argv[2]->s;
  432. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  433. plugClient->setCustomData(type, key, value);
  434. return 0;
  435. }
  436. CARLA_BRIDGE_END_NAMESPACE
  437. // -------------------------------------------------------------------------
  438. CarlaPlugin* CarlaPlugin::newJACK(const CarlaPlugin::Initializer&)
  439. {
  440. return nullptr;
  441. }
  442. // -------------------------------------------------------------------------
  443. int main(int argc, char* argv[])
  444. {
  445. CARLA_BRIDGE_USE_NAMESPACE;
  446. // ---------------------------------------------------------------------
  447. // Check argument count
  448. if (argc != 6 && argc != 7)
  449. {
  450. carla_stdout("usage: %s <osc-url|\"null\"> <type> <filename> <name|\"(none)\"> <label>", argv[0]);
  451. return 1;
  452. }
  453. // ---------------------------------------------------------------------
  454. // Get args
  455. const char* const oscUrl = argv[1];
  456. const char* const stype = argv[2];
  457. const char* const filename = argv[3];
  458. const char* name = argv[4];
  459. const char* label = argv[5];
  460. // ---------------------------------------------------------------------
  461. // Setup args
  462. const char* const shmIds(std::getenv("ENGINE_BRIDGE_SHM_IDS"));
  463. const bool useBridge = (shmIds != nullptr);
  464. const bool useOsc = (std::strcmp(oscUrl, "null") != 0 && std::strcmp(oscUrl, "(null)") != 0 && std::strcmp(oscUrl, "NULL") != 0);
  465. if (std::strcmp(name, "(none)") == 0)
  466. name = nullptr;
  467. if (std::strlen(label) == 0)
  468. label = nullptr;
  469. char bridgeBaseAudioName[6+1];
  470. char bridgeBaseControlName[6+1];
  471. if (useBridge)
  472. {
  473. CARLA_SAFE_ASSERT_RETURN(std::strlen(shmIds) == 6*2, 1);
  474. std::strncpy(bridgeBaseAudioName, shmIds, 6);
  475. std::strncpy(bridgeBaseControlName, shmIds+6, 6);
  476. bridgeBaseAudioName[6] = '\0';
  477. bridgeBaseControlName[6] = '\0';
  478. }
  479. else
  480. {
  481. bridgeBaseAudioName[0] = '\0';
  482. bridgeBaseControlName[0] = '\0';
  483. }
  484. // ---------------------------------------------------------------------
  485. // Check plugin type
  486. CarlaBackend::PluginType itype(CarlaBackend::getPluginTypeFromString(stype));
  487. if (itype == CarlaBackend::PLUGIN_NONE)
  488. {
  489. carla_stderr("Invalid plugin type '%s'", stype);
  490. return 1;
  491. }
  492. // ---------------------------------------------------------------------
  493. // Set client name
  494. CarlaString clientName((name != nullptr) ? name : label);
  495. //if (clientName.isEmpty())
  496. // clientName = File(filename).getFileNameWithoutExtension().toRawUTF8();
  497. // ---------------------------------------------------------------------
  498. // Set extraStuff
  499. const void* extraStuff = nullptr;
  500. if (itype == CarlaBackend::PLUGIN_FILE_GIG || itype == CarlaBackend::PLUGIN_FILE_SF2)
  501. {
  502. if (label == nullptr)
  503. label = clientName;
  504. if (std::strstr(label, " (16 outs)") == 0)
  505. extraStuff = "true";
  506. }
  507. // ---------------------------------------------------------------------
  508. // Init plugin client
  509. CarlaPluginClient client(useBridge, clientName.getBuffer(), bridgeBaseAudioName, bridgeBaseControlName);
  510. if (! client.isOk())
  511. {
  512. carla_stderr("Failed to init engine, error was:\n%s", carla_get_last_error());
  513. return 1;
  514. }
  515. // ---------------------------------------------------------------------
  516. // Init OSC
  517. if (useOsc)
  518. client.oscInit(oscUrl);
  519. // ---------------------------------------------------------------------
  520. // Listen for ctrl+c or sigint/sigterm events
  521. initSignalHandler();
  522. // ---------------------------------------------------------------------
  523. // Init plugin
  524. int ret;
  525. if (carla_add_plugin(CarlaBackend::BINARY_NATIVE, itype, filename, name, label, extraStuff))
  526. {
  527. if (useOsc)
  528. {
  529. client.sendOscUpdate();
  530. client.sendOscBridgeUpdate();
  531. }
  532. else
  533. {
  534. carla_set_active(0, true);
  535. if (const CarlaPluginInfo* const pluginInfo = carla_get_plugin_info(0))
  536. {
  537. if (pluginInfo->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  538. carla_show_custom_ui(0, true);
  539. }
  540. }
  541. client.ready(!useOsc);
  542. gIsInitiated = true;
  543. client.exec(argc, argv);
  544. carla_set_engine_about_to_close();
  545. carla_remove_plugin(0);
  546. ret = 0;
  547. }
  548. else
  549. {
  550. const char* const lastError(carla_get_last_error());
  551. carla_stderr("Plugin failed to load, error was:\n%s", lastError);
  552. if (useOsc)
  553. client.sendOscBridgeError(lastError);
  554. ret = 1;
  555. }
  556. // ---------------------------------------------------------------------
  557. // Close OSC
  558. if (useOsc)
  559. client.oscClose();
  560. return ret;
  561. }