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.

732 lines
21KB

  1. /*
  2. * Carla Bridge Plugin
  3. * Copyright (C) 2012-2021 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. #ifndef BUILD_BRIDGE
  18. # error This file should not be compiled if not building bridge
  19. #endif
  20. #include "CarlaEngine.hpp"
  21. #include "CarlaHost.h"
  22. #include "CarlaBackendUtils.hpp"
  23. #include "CarlaJuceUtils.hpp"
  24. #include "CarlaMainLoop.hpp"
  25. #include "CarlaMIDI.h"
  26. #ifdef CARLA_OS_MAC
  27. # include "CarlaMacUtils.hpp"
  28. #endif
  29. #ifdef CARLA_OS_UNIX
  30. # include <signal.h>
  31. #endif
  32. #ifdef CARLA_OS_LINUX
  33. # include <sched.h>
  34. # define SCHED_RESET_ON_FORK 0x40000000
  35. #endif
  36. #ifdef CARLA_OS_WIN
  37. # include <pthread.h>
  38. # include <objbase.h>
  39. #endif
  40. #ifdef HAVE_X11
  41. # include <X11/Xlib.h>
  42. #endif
  43. #ifdef USING_JUCE
  44. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  45. # pragma GCC diagnostic push
  46. # pragma GCC diagnostic ignored "-Wconversion"
  47. # pragma GCC diagnostic ignored "-Weffc++"
  48. # pragma GCC diagnostic ignored "-Wsign-conversion"
  49. # pragma GCC diagnostic ignored "-Wundef"
  50. # pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
  51. # endif
  52. # include "AppConfig.h"
  53. # if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  54. # include "juce_gui_basics/juce_gui_basics.h"
  55. # else
  56. # include "juce_events/juce_events.h"
  57. # endif
  58. # if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))
  59. # pragma GCC diagnostic pop
  60. # endif
  61. #endif
  62. #include "jackbridge/JackBridge.hpp"
  63. #include "water/files/File.h"
  64. #include "water/misc/Time.h"
  65. using CarlaBackend::CarlaEngine;
  66. using CarlaBackend::EngineCallbackOpcode;
  67. using CarlaBackend::EngineCallbackOpcode2Str;
  68. using CarlaBackend::runMainLoopOnce;
  69. using water::CharPointer_UTF8;
  70. using water::File;
  71. using water::String;
  72. // -------------------------------------------------------------------------
  73. static bool gIsInitiated = false;
  74. static volatile bool gCloseNow = false;
  75. static volatile bool gSaveNow = false;
  76. #if defined(CARLA_OS_UNIX)
  77. static void closeSignalHandler(int) noexcept
  78. {
  79. gCloseNow = true;
  80. }
  81. static void saveSignalHandler(int) noexcept
  82. {
  83. gSaveNow = true;
  84. }
  85. #elif defined(CARLA_OS_WIN)
  86. static BOOL WINAPI winSignalHandler(DWORD dwCtrlType) noexcept
  87. {
  88. if (dwCtrlType == CTRL_C_EVENT)
  89. {
  90. gCloseNow = true;
  91. return TRUE;
  92. }
  93. return FALSE;
  94. }
  95. #endif
  96. static void initSignalHandler()
  97. {
  98. #if defined(CARLA_OS_UNIX)
  99. struct sigaction sig;
  100. carla_zeroStruct(sig);
  101. sig.sa_handler = closeSignalHandler;
  102. sig.sa_flags = SA_RESTART;
  103. sigemptyset(&sig.sa_mask);
  104. sigaction(SIGTERM, &sig, nullptr);
  105. sigaction(SIGINT, &sig, nullptr);
  106. sig.sa_handler = saveSignalHandler;
  107. sig.sa_flags = SA_RESTART;
  108. sigemptyset(&sig.sa_mask);
  109. sigaction(SIGUSR1, &sig, nullptr);
  110. #elif defined(CARLA_OS_WIN)
  111. SetConsoleCtrlHandler(winSignalHandler, TRUE);
  112. #endif
  113. }
  114. // -------------------------------------------------------------------------
  115. static String gProjectFilename;
  116. static CarlaHostHandle gHostHandle;
  117. static void gIdle()
  118. {
  119. carla_engine_idle(gHostHandle);
  120. if (gSaveNow)
  121. {
  122. gSaveNow = false;
  123. if (gProjectFilename.isNotEmpty())
  124. {
  125. if (! carla_save_plugin_state(gHostHandle, 0, gProjectFilename.toRawUTF8()))
  126. carla_stderr("Plugin preset save failed, error was:\n%s", carla_get_last_error(gHostHandle));
  127. }
  128. }
  129. }
  130. // -------------------------------------------------------------------------
  131. #if defined(USING_JUCE) && (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  132. class CarlaJuceApp : public juce::JUCEApplication,
  133. private juce::Timer
  134. {
  135. public:
  136. CarlaJuceApp() {}
  137. ~CarlaJuceApp() {}
  138. void initialise(const juce::String&) override
  139. {
  140. startTimer(8);
  141. }
  142. void shutdown() override
  143. {
  144. gCloseNow = true;
  145. stopTimer();
  146. }
  147. const juce::String getApplicationName() override
  148. {
  149. return "CarlaPlugin";
  150. }
  151. const juce::String getApplicationVersion() override
  152. {
  153. return CARLA_VERSION_STRING;
  154. }
  155. void timerCallback() override
  156. {
  157. gIdle();
  158. if (gCloseNow)
  159. {
  160. quit();
  161. gCloseNow = false;
  162. }
  163. }
  164. };
  165. static juce::JUCEApplicationBase* juce_CreateApplication() { return new CarlaJuceApp(); }
  166. #endif
  167. // -------------------------------------------------------------------------
  168. class CarlaBridgePlugin
  169. {
  170. public:
  171. CarlaBridgePlugin(const bool useBridge, const char* const clientName, const char* const audioPoolBaseName,
  172. const char* const rtClientBaseName, const char* const nonRtClientBaseName, const char* const nonRtServerBaseName)
  173. : fEngine(nullptr),
  174. #ifdef USING_JUCE
  175. fJuceInitialiser(),
  176. #endif
  177. fUsingBridge(false),
  178. fUsingExec(false)
  179. {
  180. CARLA_ASSERT(clientName != nullptr && clientName[0] != '\0');
  181. carla_debug("CarlaBridgePlugin::CarlaBridgePlugin(%s, \"%s\", %s, %s, %s, %s)",
  182. bool2str(useBridge), clientName, audioPoolBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName);
  183. carla_set_engine_callback(gHostHandle, callback, this);
  184. if (useBridge)
  185. {
  186. carla_engine_init_bridge(gHostHandle,
  187. audioPoolBaseName,
  188. rtClientBaseName,
  189. nonRtClientBaseName,
  190. nonRtServerBaseName,
  191. clientName);
  192. }
  193. else if (std::getenv("CARLA_BRIDGE_DUMMY") != nullptr)
  194. {
  195. carla_engine_init(gHostHandle, "Dummy", clientName);
  196. }
  197. else
  198. {
  199. carla_engine_init(gHostHandle, "JACK", clientName);
  200. }
  201. fEngine = carla_get_engine_from_handle(gHostHandle);
  202. }
  203. ~CarlaBridgePlugin()
  204. {
  205. carla_debug("CarlaBridgePlugin::~CarlaBridgePlugin()");
  206. if (fEngine != nullptr && ! fUsingExec)
  207. carla_engine_close(gHostHandle);
  208. }
  209. bool isOk() const noexcept
  210. {
  211. return (fEngine != nullptr);
  212. }
  213. // ---------------------------------------------------------------------
  214. void exec(const bool useBridge)
  215. {
  216. fUsingBridge = useBridge;
  217. fUsingExec = true;
  218. const bool testing = std::getenv("CARLA_BRIDGE_TESTING") != nullptr;
  219. if (! useBridge && ! testing)
  220. {
  221. const CarlaPluginInfo* const pInfo = carla_get_plugin_info(gHostHandle, 0);
  222. CARLA_SAFE_ASSERT_RETURN(pInfo != nullptr,);
  223. gProjectFilename = CharPointer_UTF8(pInfo->name);
  224. gProjectFilename += ".carxs";
  225. if (! File::isAbsolutePath(gProjectFilename))
  226. gProjectFilename = File::getCurrentWorkingDirectory().getChildFile(gProjectFilename).getFullPathName();
  227. if (File(gProjectFilename).existsAsFile())
  228. {
  229. if (carla_load_plugin_state(gHostHandle, 0, gProjectFilename.toRawUTF8()))
  230. carla_stdout("Plugin state loaded successfully");
  231. else
  232. carla_stderr("Plugin state load failed, error was:\n%s", carla_get_last_error(gHostHandle));
  233. }
  234. else
  235. {
  236. carla_stdout("Previous plugin state in '%s' is non-existent, will start from default state",
  237. gProjectFilename.toRawUTF8());
  238. }
  239. }
  240. gIsInitiated = true;
  241. #if defined(USING_JUCE) && (defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN))
  242. # ifndef CARLA_OS_WIN
  243. static const int argc = 0;
  244. static const char* argv[] = {};
  245. # endif
  246. juce::JUCEApplicationBase::createInstance = &juce_CreateApplication;
  247. juce::JUCEApplicationBase::main(JUCE_MAIN_FUNCTION_ARGS);
  248. #else
  249. int64_t timeToEnd = 0;
  250. if (testing)
  251. {
  252. timeToEnd = water::Time::currentTimeMillis() + 5 * 1000;
  253. fEngine->transportPlay();
  254. }
  255. for (; runMainLoopOnce() && ! gCloseNow;)
  256. {
  257. gIdle();
  258. # if defined(CARLA_OS_MAC) || defined(CARLA_OS_WIN)
  259. // MacOS and Win32 have event-loops to run, so minimize sleep time
  260. carla_msleep(1);
  261. # else
  262. carla_msleep(5);
  263. # endif
  264. if (testing && timeToEnd - water::Time::currentTimeMillis() < 0)
  265. break;
  266. }
  267. #endif
  268. carla_engine_close(gHostHandle);
  269. }
  270. // ---------------------------------------------------------------------
  271. protected:
  272. void handleCallback(const EngineCallbackOpcode action,
  273. const int value1,
  274. const int, const int, const float, const char* const)
  275. {
  276. CARLA_BACKEND_USE_NAMESPACE;
  277. switch (action)
  278. {
  279. case ENGINE_CALLBACK_ENGINE_STOPPED:
  280. case ENGINE_CALLBACK_PLUGIN_REMOVED:
  281. case ENGINE_CALLBACK_QUIT:
  282. gCloseNow = true;
  283. break;
  284. case ENGINE_CALLBACK_UI_STATE_CHANGED:
  285. if (gIsInitiated && value1 != 1 && ! fUsingBridge)
  286. gCloseNow = true;
  287. break;
  288. default:
  289. break;
  290. }
  291. }
  292. private:
  293. CarlaEngine* fEngine;
  294. #ifdef USING_JUCE
  295. const juce::ScopedJuceInitialiser_GUI fJuceInitialiser;
  296. #endif
  297. bool fUsingBridge;
  298. bool fUsingExec;
  299. static void callback(void* ptr, EngineCallbackOpcode action, unsigned int pluginId,
  300. int value1, int value2, int value3,
  301. float valuef, const char* valueStr)
  302. {
  303. carla_debug("CarlaBridgePlugin::callback(%p, %i:%s, %i, %i, %i, %i, %f, \"%s\")",
  304. ptr, action, EngineCallbackOpcode2Str(action),
  305. pluginId, value1, value2, value3, static_cast<double>(valuef), valueStr);
  306. // ptr must not be null
  307. CARLA_SAFE_ASSERT_RETURN(ptr != nullptr,);
  308. #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH
  309. // pluginId must be 0 (first), except for patchbay things
  310. if (action < CarlaBackend::ENGINE_CALLBACK_PATCHBAY_CLIENT_ADDED ||
  311. action > CarlaBackend::ENGINE_CALLBACK_PATCHBAY_CONNECTION_REMOVED)
  312. #endif
  313. {
  314. CARLA_SAFE_ASSERT_UINT_RETURN(pluginId == 0, pluginId,);
  315. }
  316. return ((CarlaBridgePlugin*)ptr)->handleCallback(action, value1, value2, value3, valuef, valueStr);
  317. }
  318. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaBridgePlugin)
  319. };
  320. // -------------------------------------------------------------------------
  321. int main(int argc, char* argv[])
  322. {
  323. // ---------------------------------------------------------------------
  324. // Check argument count
  325. if (argc != 4 && argc != 5)
  326. {
  327. carla_stdout("usage: %s <type> <filename> <label> [uniqueId]", argv[0]);
  328. return 1;
  329. }
  330. #if defined(CARLA_OS_WIN) && defined(BUILDING_CARLA_FOR_WINE)
  331. // ---------------------------------------------------------------------
  332. // Test if bridge is working
  333. if (! jackbridge_is_ok())
  334. {
  335. carla_stderr("A JACK or Wine library is missing, cannot continue");
  336. return 1;
  337. }
  338. #endif
  339. // ---------------------------------------------------------------------
  340. // Get args
  341. const char* const stype = argv[1];
  342. const char* filename = argv[2];
  343. const char* label = argv[3];
  344. const int64_t uniqueId = (argc == 5) ? static_cast<int64_t>(std::atoll(argv[4])) : 0;
  345. if (filename[0] == '\0' || std::strcmp(filename, "(none)") == 0)
  346. filename = nullptr;
  347. if (label[0] == '\0' || std::strcmp(label, "(none)") == 0)
  348. label = nullptr;
  349. // ---------------------------------------------------------------------
  350. // Check binary type
  351. CarlaBackend::BinaryType btype = CarlaBackend::BINARY_NATIVE;
  352. if (const char* const binaryTypeStr = std::getenv("CARLA_BRIDGE_PLUGIN_BINARY_TYPE"))
  353. btype = CarlaBackend::getBinaryTypeFromString(binaryTypeStr);
  354. if (btype == CarlaBackend::BINARY_NONE)
  355. {
  356. carla_stderr("Invalid binary type '%i'", btype);
  357. return 1;
  358. }
  359. // ---------------------------------------------------------------------
  360. // Check plugin type
  361. CarlaBackend::PluginType itype(CarlaBackend::getPluginTypeFromString(stype));
  362. if (itype == CarlaBackend::PLUGIN_NONE)
  363. {
  364. carla_stderr("Invalid plugin type '%s'", stype);
  365. return 1;
  366. }
  367. // ---------------------------------------------------------------------
  368. // Set file
  369. const File file(filename != nullptr ? filename : "");
  370. // ---------------------------------------------------------------------
  371. // Set name
  372. const char* name(std::getenv("CARLA_CLIENT_NAME"));
  373. if (name != nullptr && (name[0] == '\0' || std::strcmp(name, "(none)") == 0))
  374. name = nullptr;
  375. // ---------------------------------------------------------------------
  376. // Setup options
  377. const char* const shmIds(std::getenv("ENGINE_BRIDGE_SHM_IDS"));
  378. const bool useBridge = (shmIds != nullptr);
  379. // ---------------------------------------------------------------------
  380. // Setup bridge ids
  381. char audioPoolBaseName[6+1];
  382. char rtClientBaseName[6+1];
  383. char nonRtClientBaseName[6+1];
  384. char nonRtServerBaseName[6+1];
  385. if (useBridge)
  386. {
  387. CARLA_SAFE_ASSERT_RETURN(std::strlen(shmIds) == 6*4, 1);
  388. std::strncpy(audioPoolBaseName, shmIds+6*0, 6);
  389. std::strncpy(rtClientBaseName, shmIds+6*1, 6);
  390. std::strncpy(nonRtClientBaseName, shmIds+6*2, 6);
  391. std::strncpy(nonRtServerBaseName, shmIds+6*3, 6);
  392. audioPoolBaseName[6] = '\0';
  393. rtClientBaseName[6] = '\0';
  394. nonRtClientBaseName[6] = '\0';
  395. nonRtServerBaseName[6] = '\0';
  396. jackbridge_parent_deathsig(false);
  397. }
  398. else
  399. {
  400. audioPoolBaseName[0] = '\0';
  401. rtClientBaseName[0] = '\0';
  402. nonRtClientBaseName[0] = '\0';
  403. nonRtServerBaseName[0] = '\0';
  404. jackbridge_init();
  405. }
  406. // ---------------------------------------------------------------------
  407. // Set client name
  408. CarlaString clientName;
  409. if (name != nullptr)
  410. {
  411. clientName = name;
  412. }
  413. else if (itype == CarlaBackend::PLUGIN_LV2)
  414. {
  415. // LV2 requires URI
  416. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', 1);
  417. // LV2 URI is not usable as client name, create a usable name from URI
  418. CarlaString label2(label);
  419. // truncate until last valid char
  420. for (std::size_t i=label2.length()-1; i != 0; --i)
  421. {
  422. if (! std::isalnum(label2[i]))
  423. continue;
  424. label2.truncate(i+1);
  425. break;
  426. }
  427. // get last used separator
  428. bool found;
  429. std::size_t septmp, sep = 0;
  430. septmp = label2.rfind('#', &found)+1;
  431. if (found && septmp > sep)
  432. sep = septmp;
  433. septmp = label2.rfind('/', &found)+1;
  434. if (found && septmp > sep)
  435. sep = septmp;
  436. septmp = label2.rfind('=', &found)+1;
  437. if (found && septmp > sep)
  438. sep = septmp;
  439. septmp = label2.rfind(':', &found)+1;
  440. if (found && septmp > sep)
  441. sep = septmp;
  442. // make name starting from the separator and first valid char
  443. const char* name2 = label2.buffer() + sep;
  444. for (; *name2 != '\0' && ! std::isalnum(*name2); ++name2) {}
  445. if (*name2 != '\0')
  446. clientName = name2;
  447. }
  448. else if (label != nullptr)
  449. {
  450. clientName = label;
  451. }
  452. else
  453. {
  454. clientName = file.getFileNameWithoutExtension().toRawUTF8();
  455. }
  456. // if we still have no client name by now, use a dummy one
  457. if (clientName.isEmpty())
  458. clientName = "carla-plugin";
  459. // just to be safe
  460. clientName.toBasic();
  461. // ---------------------------------------------------------------------
  462. // Set extraStuff
  463. const void* extraStuff = nullptr;
  464. if (itype == CarlaBackend::PLUGIN_SF2)
  465. {
  466. if (label == nullptr)
  467. label = clientName;
  468. if (std::strstr(label, " (16 outs)") != nullptr)
  469. extraStuff = "true";
  470. }
  471. // ---------------------------------------------------------------------
  472. // Initialize OS features
  473. const bool testing = std::getenv("CARLA_BRIDGE_TESTING") != nullptr;
  474. #ifdef CARLA_OS_MAC
  475. initStandaloneApplication();
  476. #endif
  477. #ifdef CARLA_OS_WIN
  478. OleInitialize(nullptr);
  479. CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
  480. # ifndef __WINPTHREADS_VERSION
  481. // (non-portable) initialization of statically linked pthread library
  482. pthread_win32_process_attach_np();
  483. pthread_win32_thread_attach_np();
  484. # endif
  485. #endif
  486. #ifdef HAVE_X11
  487. if (std::getenv("DISPLAY") != nullptr)
  488. XInitThreads();
  489. #endif
  490. // ---------------------------------------------------------------------
  491. // Set ourselves with high priority
  492. #ifdef CARLA_OS_LINUX
  493. // reset scheduler to normal mode
  494. struct sched_param sparam;
  495. carla_zeroStruct(sparam);
  496. sched_setscheduler(0, SCHED_OTHER|SCHED_RESET_ON_FORK, &sparam);
  497. // try niceness first, if it fails, try SCHED_RR
  498. if (nice(-5) < 0)
  499. {
  500. sparam.sched_priority = (sched_get_priority_max(SCHED_RR) + sched_get_priority_min(SCHED_RR*7)) / 8;
  501. if (sparam.sched_priority > 0)
  502. {
  503. if (sched_setscheduler(0, SCHED_RR|SCHED_RESET_ON_FORK, &sparam) < 0 && ! testing)
  504. {
  505. CarlaString error(std::strerror(errno));
  506. carla_stderr("Failed to set high priority, error %i: %s", errno, error.buffer());
  507. }
  508. }
  509. }
  510. #endif
  511. #ifdef CARLA_OS_WIN
  512. if (! SetPriorityClass(GetCurrentProcess(), ABOVE_NORMAL_PRIORITY_CLASS) && ! testing)
  513. carla_stderr("Failed to set high priority.");
  514. #endif
  515. // ---------------------------------------------------------------------
  516. // Listen for ctrl+c or sigint/sigterm events
  517. initSignalHandler();
  518. // ---------------------------------------------------------------------
  519. // Init plugin bridge
  520. int ret;
  521. {
  522. gHostHandle = carla_standalone_host_init();
  523. CarlaBridgePlugin bridge(useBridge, clientName,
  524. audioPoolBaseName, rtClientBaseName, nonRtClientBaseName, nonRtServerBaseName);
  525. if (! bridge.isOk())
  526. {
  527. carla_stderr("Failed to init engine, error was:\n%s", carla_get_last_error(gHostHandle));
  528. return 1;
  529. }
  530. // -----------------------------------------------------------------
  531. // Init plugin
  532. if (carla_add_plugin(gHostHandle,
  533. btype, itype,
  534. file.getFullPathName().toRawUTF8(), name, label, uniqueId, extraStuff, CarlaBackend::PLUGIN_OPTIONS_NULL))
  535. {
  536. ret = 0;
  537. if (! useBridge)
  538. {
  539. carla_set_active(gHostHandle, 0, true);
  540. carla_set_engine_option(gHostHandle, CarlaBackend::ENGINE_OPTION_PLUGINS_ARE_STANDALONE, 1, nullptr);
  541. if (const CarlaPluginInfo* const pluginInfo = carla_get_plugin_info(gHostHandle, 0))
  542. {
  543. if (itype == CarlaBackend::PLUGIN_INTERNAL && (std::strcmp(label, "audiofile") == 0 || std::strcmp(label, "midifile") == 0))
  544. {
  545. if (file.exists())
  546. carla_set_custom_data(gHostHandle, 0,
  547. CarlaBackend::CUSTOM_DATA_TYPE_STRING,
  548. "file", file.getFullPathName().toRawUTF8());
  549. }
  550. else if (pluginInfo->hints & CarlaBackend::PLUGIN_HAS_CUSTOM_UI)
  551. {
  552. #ifdef HAVE_X11
  553. if (std::getenv("DISPLAY") != nullptr)
  554. #endif
  555. if (! testing)
  556. carla_show_custom_ui(gHostHandle, 0, true);
  557. }
  558. // on standalone usage, enable everything that makes sense
  559. const uint optsAvailable = pluginInfo->optionsAvailable;
  560. if (optsAvailable & CarlaBackend::PLUGIN_OPTION_FIXED_BUFFERS)
  561. carla_set_option(gHostHandle, 0, CarlaBackend::PLUGIN_OPTION_FIXED_BUFFERS, true);
  562. }
  563. }
  564. bridge.exec(useBridge);
  565. }
  566. else
  567. {
  568. ret = 1;
  569. const char* const lastError(carla_get_last_error(gHostHandle));
  570. carla_stderr("Plugin failed to load, error was:\n%s", lastError);
  571. if (useBridge)
  572. {
  573. // do a single idle so that we can send error message to server
  574. gIdle();
  575. #ifdef CARLA_OS_UNIX
  576. // kill ourselves now if we can't load plugin in bridge mode
  577. ::kill(::getpid(), SIGKILL);
  578. #endif
  579. }
  580. }
  581. }
  582. #ifdef CARLA_OS_WIN
  583. #ifndef __WINPTHREADS_VERSION
  584. pthread_win32_thread_detach_np();
  585. pthread_win32_process_detach_np();
  586. #endif
  587. CoUninitialize();
  588. OleUninitialize();
  589. #endif
  590. return ret;
  591. }