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.

705 lines
21KB

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