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.

720 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 BUILD_BRIDGE
  28. // # undef HAVE_JUCE
  29. // #endif
  30. #ifdef HAVE_JUCE
  31. # include "juce_gui_basics.h"
  32. using juce::JUCEApplication;
  33. using juce::JUCEApplicationBase;
  34. using juce::String;
  35. using juce::Timer;
  36. #endif
  37. //using juce::File;
  38. // -------------------------------------------------------------------------
  39. static bool gIsInitiated = false;
  40. static volatile bool gCloseNow = false;
  41. static volatile bool gSaveNow = false;
  42. #ifdef CARLA_OS_WIN
  43. static BOOL WINAPI winSignalHandler(DWORD dwCtrlType)
  44. {
  45. if (dwCtrlType == CTRL_C_EVENT)
  46. {
  47. gCloseNow = true;
  48. return TRUE;
  49. }
  50. return FALSE;
  51. }
  52. #elif defined(CARLA_OS_LINUX)
  53. static void closeSignalHandler(int)
  54. {
  55. gCloseNow = true;
  56. }
  57. static void saveSignalHandler(int)
  58. {
  59. gSaveNow = true;
  60. }
  61. #endif
  62. static void initSignalHandler()
  63. {
  64. #ifdef CARLA_OS_WIN
  65. SetConsoleCtrlHandler(winSignalHandler, TRUE);
  66. #elif defined(CARLA_OS_LINUX)
  67. struct sigaction sint;
  68. struct sigaction sterm;
  69. struct sigaction susr1;
  70. sint.sa_handler = closeSignalHandler;
  71. sint.sa_flags = SA_RESTART;
  72. sint.sa_restorer = nullptr;
  73. sigemptyset(&sint.sa_mask);
  74. sigaction(SIGINT, &sint, nullptr);
  75. sterm.sa_handler = closeSignalHandler;
  76. sterm.sa_flags = SA_RESTART;
  77. sterm.sa_restorer = nullptr;
  78. sigemptyset(&sterm.sa_mask);
  79. sigaction(SIGTERM, &sterm, nullptr);
  80. susr1.sa_handler = saveSignalHandler;
  81. susr1.sa_flags = SA_RESTART;
  82. susr1.sa_restorer = nullptr;
  83. sigemptyset(&susr1.sa_mask);
  84. sigaction(SIGUSR1, &susr1, nullptr);
  85. #endif
  86. }
  87. // -------------------------------------------------------------------------
  88. #ifdef HAVE_JUCE
  89. static CarlaBridge::CarlaBridgeClient* gBridgeClient = nullptr;
  90. class CarlaJuceApp : public JUCEApplication,
  91. Timer
  92. {
  93. public:
  94. CarlaJuceApp() {}
  95. ~CarlaJuceApp() {}
  96. void initialise(const String&) override
  97. {
  98. startTimer(30);
  99. }
  100. void shutdown() override
  101. {
  102. gCloseNow = true;
  103. stopTimer();
  104. }
  105. const String getApplicationName() override
  106. {
  107. return "CarlaPlugin";
  108. }
  109. const String getApplicationVersion() override
  110. {
  111. return CARLA_VERSION_STRING;
  112. }
  113. void timerCallback() override
  114. {
  115. carla_engine_idle();
  116. if (gBridgeClient != nullptr)
  117. gBridgeClient->oscIdle();
  118. if (gCloseNow)
  119. {
  120. quit();
  121. gCloseNow = false;
  122. }
  123. }
  124. };
  125. static JUCEApplicationBase* juce_CreateApplication() { return new CarlaJuceApp(); }
  126. #endif
  127. // -------------------------------------------------------------------------
  128. CARLA_BRIDGE_START_NAMESPACE
  129. #if 0
  130. } // Fix editor indentation
  131. #endif
  132. // -------------------------------------------------------------------------
  133. class CarlaPluginClient : public CarlaBridgeClient
  134. {
  135. public:
  136. CarlaPluginClient(const bool useBridge, const char* const driverName, const char* audioBaseName, const char* controlBaseName)
  137. : CarlaBridgeClient(nullptr),
  138. fPlugin(nullptr),
  139. fEngine(nullptr)
  140. {
  141. CARLA_ASSERT(driverName != nullptr && driverName[0] != '\0');
  142. carla_debug("CarlaPluginClient::CarlaPluginClient(%s, \"%s\", %s, %s)", bool2str(useBridge), driverName, audioBaseName, controlBaseName);
  143. carla_set_engine_callback(callback, this);
  144. #if 0
  145. File curDir(File::getSpecialLocation(File::currentApplicationFile).getParentDirectory());
  146. if (curDir.getChildFile("resources").exists())
  147. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("resources").getFullPathName().toRawUTF8());
  148. else if (curDir.getChildFile("../../modules/daz-plugins/resources").exists())
  149. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../../modules/daz-plugins/resources").getFullPathName().toRawUTF8());
  150. else
  151. carla_set_engine_option(CarlaBackend::OPTION_PATH_RESOURCES, 0, curDir.getChildFile("../modules/daz-plugins/resources").getFullPathName().toRawUTF8());
  152. #endif
  153. if (useBridge)
  154. carla_engine_init_bridge(audioBaseName, controlBaseName, driverName);
  155. else
  156. carla_engine_init("JACK", driverName);
  157. fEngine = carla_get_engine();
  158. }
  159. ~CarlaPluginClient() override
  160. {
  161. carla_debug("CarlaPluginClient::~CarlaPluginClient()");
  162. #ifdef HAVE_JUCE
  163. gBridgeClient = nullptr;
  164. #endif
  165. carla_engine_close();
  166. }
  167. bool isOk() const noexcept
  168. {
  169. return (fEngine != nullptr);
  170. }
  171. void oscInit(const char* const url)
  172. {
  173. CarlaBridgeClient::oscInit(url);
  174. fEngine->setOscBridgeData(&fOscData);
  175. }
  176. void ready(const bool doSaveLoad)
  177. {
  178. fPlugin = fEngine->getPlugin(0);
  179. if (doSaveLoad)
  180. {
  181. fProjFileName = fPlugin->getName();
  182. fProjFileName += ".carxs";
  183. //if (! File::isAbsolutePath((const char*)fProjFileName))
  184. // fProjFileName = File::getCurrentWorkingDirectory().getChildFile((const char*)fProjFileName).getFullPathName().toRawUTF8();
  185. //if (! fPlugin->loadStateFromFile(fProjFileName))
  186. // carla_stderr("Plugin preset load failed, error was:\n%s", fEngine->getLastError());
  187. }
  188. }
  189. #ifndef HAVE_JUCE
  190. void idle()
  191. {
  192. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  193. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  194. carla_engine_idle();
  195. CarlaBridgeClient::oscIdle();
  196. if (gSaveNow)
  197. {
  198. gSaveNow = false;
  199. if (fProjFileName.isNotEmpty())
  200. {
  201. if (! fPlugin->saveStateToFile(fProjFileName))
  202. carla_stderr("Plugin preset save failed, error was:\n%s", fEngine->getLastError());
  203. }
  204. }
  205. if (gCloseNow)
  206. {
  207. //gCloseNow = false;
  208. // close something?
  209. }
  210. }
  211. #endif
  212. void exec(int argc, char* argv[])
  213. {
  214. #ifdef HAVE_JUCE
  215. gBridgeClient = this;
  216. JUCEApplicationBase::createInstance = &juce_CreateApplication;
  217. JUCEApplicationBase::main(JUCE_MAIN_FUNCTION_ARGS);
  218. #else
  219. for (; ! gCloseNow;)
  220. {
  221. idle();
  222. carla_msleep(24);
  223. }
  224. #endif
  225. return; (void)argc; (void)argv;
  226. }
  227. // ---------------------------------------------------------------------
  228. // plugin management
  229. void saveNow()
  230. {
  231. CARLA_SAFE_ASSERT_RETURN(fEngine != nullptr,);
  232. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  233. carla_debug("CarlaPluginClient::saveNow()");
  234. fPlugin->prepareForSave();
  235. for (uint32_t i=0; i < fPlugin->getCustomDataCount(); ++i)
  236. {
  237. const CarlaBackend::CustomData& cdata(fPlugin->getCustomData(i));
  238. fEngine->oscSend_bridge_set_custom_data(cdata.type, cdata.key, cdata.value);
  239. }
  240. if (fPlugin->getOptionsEnabled() & CarlaBackend::PLUGIN_OPTION_USE_CHUNKS)
  241. {
  242. void* data = nullptr;
  243. int32_t dataSize = fPlugin->getChunkData(&data);
  244. if (data && dataSize >= 4)
  245. {
  246. #if 0
  247. QString filePath;
  248. filePath = QDir::tempPath();
  249. #ifdef Q_OS_WIN
  250. filePath += "\\.CarlaChunk_";
  251. #else
  252. filePath += "/.CarlaChunk_";
  253. #endif
  254. filePath += fPlugin->getName();
  255. QFile file(filePath);
  256. if (file.open(QIODevice::WriteOnly))
  257. {
  258. QByteArray chunk((const char*)data, dataSize);
  259. file.write(chunk);
  260. file.close();
  261. fEngine->oscSend_bridge_set_chunk_data(filePath.toUtf8().constData());
  262. }
  263. #endif
  264. }
  265. }
  266. fEngine->oscSend_bridge_configure(CARLA_BRIDGE_MSG_SAVED, "");
  267. }
  268. void setParameterMidiChannel(const uint32_t index, const uint8_t channel)
  269. {
  270. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  271. carla_debug("CarlaPluginClient::setParameterMidiChannel(%i, %i)", index, channel);
  272. fPlugin->setParameterMidiChannel(index, channel, false, false);
  273. }
  274. void setParameterMidiCC(const uint32_t index, const int16_t cc)
  275. {
  276. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  277. carla_debug("CarlaPluginClient::setParameterMidiCC(%i, %i)", index, cc);
  278. fPlugin->setParameterMidiCC(index, cc, false, false);
  279. }
  280. void setCustomData(const char* const type, const char* const key, const char* const value)
  281. {
  282. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  283. carla_debug("CarlaPluginClient::setCustomData(\"%s\", \"%s\", \"%s\")", type, key, value);
  284. fPlugin->setCustomData(type, key, value, true);
  285. }
  286. void setChunkData(const char* const filePath)
  287. {
  288. CARLA_SAFE_ASSERT_RETURN(filePath != nullptr && filePath[0] != '\0',);
  289. CARLA_SAFE_ASSERT_RETURN(fPlugin != nullptr,);
  290. carla_debug("CarlaPluginClient::setChunkData(\"%s\")", filePath);
  291. #if 0
  292. QString chunkFilePath(filePath);
  293. #ifdef CARLA_OS_WIN
  294. if (chunkFilePath.startsWith("/"))
  295. {
  296. // running under Wine, posix host
  297. chunkFilePath = chunkFilePath.replace(0, 1, "Z:/");
  298. chunkFilePath = QDir::toNativeSeparators(chunkFilePath);
  299. }
  300. #endif
  301. QFile chunkFile(chunkFilePath);
  302. if (fPlugin != nullptr && chunkFile.open(QIODevice::ReadOnly | QIODevice::Text))
  303. {
  304. QTextStream in(&chunkFile);
  305. QString stringData(in.readAll());
  306. chunkFile.close();
  307. chunkFile.remove();
  308. fPlugin->setChunkData(stringData.toUtf8().constData());
  309. }
  310. #endif
  311. }
  312. // ---------------------------------------------------------------------
  313. protected:
  314. void handleCallback(const CarlaBackend::EngineCallbackOpcode action, const int value1, const int value2, const float value3, const char* const valueStr)
  315. {
  316. CARLA_BACKEND_USE_NAMESPACE;
  317. // TODO
  318. switch (action)
  319. {
  320. case ENGINE_CALLBACK_PARAMETER_VALUE_CHANGED:
  321. if (isOscControlRegistered())
  322. sendOscControl(value1, value3);
  323. break;
  324. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  325. if (! isOscControlRegistered())
  326. {
  327. if (value1 != 1 && gIsInitiated)
  328. gCloseNow = true;
  329. }
  330. else
  331. {
  332. // show-gui button
  333. fEngine->oscSend_bridge_configure(CARLA_BRIDGE_MSG_HIDE_GUI, "");
  334. }
  335. break;
  336. default:
  337. break;
  338. }
  339. return;
  340. (void)value2;
  341. (void)value3;
  342. (void)valueStr;
  343. }
  344. private:
  345. CarlaBackend::CarlaPlugin* fPlugin;
  346. const CarlaBackend::CarlaEngine* fEngine;
  347. CarlaString fProjFileName;
  348. static void callback(void* ptr, CarlaBackend::EngineCallbackOpcode action, unsigned int pluginId, int value1, int value2, float value3, const char* valueStr)
  349. {
  350. carla_debug("CarlaPluginClient::callback(%p, %i:%s, %i, %i, %i, %f, \"%s\")", ptr, action, CarlaBackend::EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  351. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr,);
  352. CARLA_SAFE_ASSERT_RETURN(pluginId == 0,);
  353. return ((CarlaPluginClient*)ptr)->handleCallback(action, value1, value2, value3, valueStr);
  354. }
  355. };
  356. // -------------------------------------------------------------------------
  357. int CarlaBridgeOsc::handleMsgShow()
  358. {
  359. carla_debug("CarlaBridgeOsc::handleMsgShow()");
  360. #ifdef HAVE_JUCE
  361. const juce::MessageManagerLock mmLock;
  362. #endif
  363. if (carla_get_plugin_info(0)->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  364. carla_show_custom_ui(0, true);
  365. return 0;
  366. }
  367. int CarlaBridgeOsc::handleMsgHide()
  368. {
  369. carla_debug("CarlaBridgeOsc::handleMsgHide()");
  370. #ifdef HAVE_JUCE
  371. const juce::MessageManagerLock mmLock;
  372. #endif
  373. if (carla_get_plugin_info(0)->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  374. carla_show_custom_ui(0, false);
  375. return 0;
  376. }
  377. int CarlaBridgeOsc::handleMsgQuit()
  378. {
  379. carla_debug("CarlaBridgeOsc::handleMsgQuit()");
  380. gCloseNow = true;
  381. return 0;
  382. }
  383. // -------------------------------------------------------------------------
  384. int CarlaBridgeOsc::handleMsgPluginSaveNow()
  385. {
  386. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  387. carla_debug("CarlaBridgeOsc::handleMsgPluginSaveNow()");
  388. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  389. plugClient->saveNow();
  390. return 0;
  391. }
  392. int CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  393. {
  394. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii");
  395. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  396. carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiChannel()");
  397. const int32_t index = argv[0]->i;
  398. const int32_t channel = argv[1]->i;
  399. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  400. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  401. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  402. plugClient->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel));
  403. return 0;
  404. }
  405. int CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  406. {
  407. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(2, "ii");
  408. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  409. carla_debug("CarlaBridgeOsc::handleMsgPluginSetParameterMidiCC()");
  410. const int32_t index = argv[0]->i;
  411. const int32_t cc = argv[1]->i;
  412. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  413. CARLA_SAFE_ASSERT_RETURN(cc >= 1 && cc < 0x5F, 0);
  414. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  415. plugClient->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc));
  416. return 0;
  417. }
  418. int CarlaBridgeOsc::handleMsgPluginSetChunk(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  419. {
  420. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(1, "s");
  421. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  422. carla_debug("CarlaBridgeOsc::handleMsgPluginSetChunk()");
  423. const char* const chunkFile = (const char*)&argv[0]->s;
  424. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  425. plugClient->setChunkData(chunkFile);
  426. return 0;
  427. }
  428. int CarlaBridgeOsc::handleMsgPluginSetCustomData(CARLA_BRIDGE_OSC_HANDLE_ARGS)
  429. {
  430. CARLA_BRIDGE_OSC_CHECK_OSC_TYPES(3, "sss");
  431. CARLA_SAFE_ASSERT_RETURN(fClient != nullptr, 1);
  432. carla_debug("CarlaBridgeOsc::handleMsgPluginSetCustomData()");
  433. const char* const type = (const char*)&argv[0]->s;
  434. const char* const key = (const char*)&argv[1]->s;
  435. const char* const value = (const char*)&argv[2]->s;
  436. CarlaPluginClient* const plugClient((CarlaPluginClient*)fClient);
  437. plugClient->setCustomData(type, key, value);
  438. return 0;
  439. }
  440. // -------------------------------------------------------------------------
  441. CARLA_BRIDGE_END_NAMESPACE
  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, (const char*)clientName, 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. }