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.

672 lines
23KB

  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2022 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 "CarlaHostImpl.hpp"
  18. #ifdef HAVE_LIBLO
  19. #define NSM_API_VERSION_MAJOR 1
  20. #define NSM_API_VERSION_MINOR 2
  21. // #define NSM_CLIENT_FEATURES ":switch:"
  22. #define NSM_CLIENT_FEATURES ":switch:optional-gui:"
  23. #include "CarlaOscUtils.hpp"
  24. #include "CarlaString.hpp"
  25. #include "water/files/File.h"
  26. // -------------------------------------------------------------------------------------------------------------------
  27. class CarlaNSM
  28. {
  29. public:
  30. CarlaNSM(CarlaHostStandalone& shandle) noexcept
  31. : gStandalone(shandle),
  32. fReplyAddress(nullptr),
  33. fServer(nullptr),
  34. fServerThread(nullptr),
  35. fServerURL(nullptr),
  36. fClientNameId(),
  37. fProjectPath(),
  38. fHasBroadcast(false),
  39. fHasOptionalGui(false),
  40. fHasServerControl(false),
  41. fStarted(),
  42. fReadyActionOpen(true),
  43. fReadyActionSave(true) {}
  44. ~CarlaNSM()
  45. {
  46. CARLA_SAFE_ASSERT(fReadyActionOpen);
  47. CARLA_SAFE_ASSERT(fReadyActionSave);
  48. if (fServerThread != nullptr)
  49. {
  50. lo_server_thread_stop(fServerThread);
  51. lo_server_thread_free(fServerThread);
  52. fServerThread = nullptr;
  53. fServer = nullptr;
  54. }
  55. if (fServerURL != nullptr)
  56. {
  57. std::free(fServerURL);
  58. fServerURL = nullptr;
  59. }
  60. if (fReplyAddress != nullptr)
  61. {
  62. lo_address_free(fReplyAddress);
  63. fReplyAddress = nullptr;
  64. }
  65. }
  66. bool announce(const uint64_t pid, const char* const executableName)
  67. {
  68. CARLA_SAFE_ASSERT_RETURN(pid != 0, false);
  69. CARLA_SAFE_ASSERT_RETURN(executableName != nullptr && executableName[0] != '\0', false);
  70. const char* const NSM_URL(std::getenv("NSM_URL"));
  71. if (NSM_URL == nullptr)
  72. return false;
  73. const lo_address nsmAddress(lo_address_new_from_url(NSM_URL));
  74. CARLA_SAFE_ASSERT_RETURN(nsmAddress != nullptr, false);
  75. const int proto = lo_address_get_protocol(nsmAddress);
  76. if (fServerThread == nullptr)
  77. {
  78. // create new OSC server
  79. fServerThread = lo_server_thread_new_with_proto(nullptr, proto, _osc_error_handler);
  80. CARLA_SAFE_ASSERT_RETURN(fServerThread != nullptr, false);
  81. // register message handlers
  82. lo_server_thread_add_method(fServerThread, "/error", "sis", _error_handler, this);
  83. lo_server_thread_add_method(fServerThread, "/reply", "ssss", _reply_handler, this);
  84. lo_server_thread_add_method(fServerThread, "/nsm/client/open", "sss", _open_handler, this);
  85. lo_server_thread_add_method(fServerThread, "/nsm/client/save", "", _save_handler, this);
  86. lo_server_thread_add_method(fServerThread, "/nsm/client/session_is_loaded", "", _loaded_handler, this);
  87. lo_server_thread_add_method(fServerThread, "/nsm/client/show_optional_gui", "", _show_gui_handler, this);
  88. lo_server_thread_add_method(fServerThread, "/nsm/client/hide_optional_gui", "", _hide_gui_handler, this);
  89. lo_server_thread_add_method(fServerThread, nullptr, nullptr, _broadcast_handler, this);
  90. fServer = lo_server_thread_get_server(fServerThread);
  91. fServerURL = lo_server_thread_get_url(fServerThread);
  92. }
  93. const char* appName = std::getenv("CARLA_NSM_NAME");
  94. if (appName == nullptr)
  95. appName = "Carla";
  96. lo_send_from(nsmAddress, fServer, LO_TT_IMMEDIATE, "/nsm/server/announce", "sssiii",
  97. appName, NSM_CLIENT_FEATURES, executableName, NSM_API_VERSION_MAJOR, NSM_API_VERSION_MINOR, pid);
  98. lo_address_free(nsmAddress);
  99. if (gStandalone.engineCallback != nullptr)
  100. {
  101. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  102. CB::ENGINE_CALLBACK_NSM,
  103. 0,
  104. CB::NSM_CALLBACK_INIT,
  105. 0, 0, 0.0f, nullptr);
  106. }
  107. return true;
  108. }
  109. void ready(const NsmCallbackOpcode action)
  110. {
  111. CARLA_SAFE_ASSERT_RETURN(fServerThread != nullptr,);
  112. switch (action)
  113. {
  114. case CB::NSM_CALLBACK_INIT:
  115. CARLA_SAFE_ASSERT_BREAK(! fStarted);
  116. fStarted = true;
  117. lo_server_thread_start(fServerThread);
  118. break;
  119. case CB::NSM_CALLBACK_ERROR:
  120. break;
  121. case CB::NSM_CALLBACK_ANNOUNCE:
  122. break;
  123. case CB::NSM_CALLBACK_OPEN:
  124. fReadyActionOpen = true;
  125. break;
  126. case CB::NSM_CALLBACK_SAVE:
  127. fReadyActionSave = true;
  128. break;
  129. case CB::NSM_CALLBACK_SESSION_IS_LOADED:
  130. break;
  131. case CB::NSM_CALLBACK_SHOW_OPTIONAL_GUI:
  132. CARLA_SAFE_ASSERT_BREAK(fReplyAddress != nullptr);
  133. CARLA_SAFE_ASSERT_BREAK(fServer != nullptr);
  134. {
  135. // NOTE: lo_send_from is a macro that creates local variables
  136. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/client/gui_is_shown", "");
  137. }
  138. break;
  139. case CB::NSM_CALLBACK_HIDE_OPTIONAL_GUI:
  140. CARLA_SAFE_ASSERT_BREAK(fReplyAddress != nullptr);
  141. CARLA_SAFE_ASSERT_BREAK(fServer != nullptr);
  142. {
  143. // NOTE: lo_send_from is a macro that creates local variables
  144. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/client/gui_is_hidden", "");
  145. }
  146. break;
  147. case CB::NSM_CALLBACK_SET_CLIENT_NAME_ID:
  148. break;
  149. }
  150. }
  151. static CarlaNSM& getInstance(CarlaHostStandalone& shandle)
  152. {
  153. static CarlaNSM sInstance(shandle);
  154. return sInstance;
  155. }
  156. protected:
  157. int handleError(const char* const method, const int code, const char* const message)
  158. {
  159. carla_stdout("CarlaNSM::handleError(\"%s\", %i, \"%s\")", method, code, message);
  160. if (gStandalone.engineCallback != nullptr)
  161. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  162. CB::ENGINE_CALLBACK_NSM,
  163. 0,
  164. CB::NSM_CALLBACK_ERROR,
  165. code,
  166. 0, 0.0f,
  167. message);
  168. return 0;
  169. // may be unused
  170. (void)method;
  171. }
  172. int handleReply(const char* const method, const char* const message, const char* const smName, const char* const features,
  173. const lo_message msg)
  174. {
  175. CARLA_SAFE_ASSERT_RETURN(fServerThread != nullptr, 1);
  176. carla_stdout("CarlaNSM::handleReply(\"%s\", \"%s\", \"%s\", \"%s\")", method, message, smName, features);
  177. if (std::strcmp(method, "/nsm/server/announce") == 0)
  178. {
  179. const lo_address msgAddress(lo_message_get_source(msg));
  180. CARLA_SAFE_ASSERT_RETURN(msgAddress != nullptr, 0);
  181. char* const msgURL(lo_address_get_url(msgAddress));
  182. CARLA_SAFE_ASSERT_RETURN(msgURL != nullptr, 0);
  183. if (fReplyAddress != nullptr)
  184. lo_address_free(fReplyAddress);
  185. fReplyAddress = lo_address_new_from_url(msgURL);
  186. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 0);
  187. fHasBroadcast = std::strstr(features, ":broadcast:") != nullptr;
  188. fHasOptionalGui = std::strstr(features, ":optional-gui:") != nullptr;
  189. fHasServerControl = std::strstr(features, ":server-control:") != nullptr;
  190. // UI starts hidden
  191. if (fHasOptionalGui)
  192. {
  193. // NOTE: lo_send_from is a macro that creates local variables
  194. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/client/gui_is_hidden", "");
  195. }
  196. carla_stdout("Carla started via '%s', message: %s", smName, message);
  197. if (gStandalone.engineCallback != nullptr)
  198. {
  199. int flags = 0;
  200. if (fHasBroadcast)
  201. flags |= 1 << 0;
  202. if (fHasOptionalGui)
  203. flags |= 1 << 1;
  204. if (fHasServerControl)
  205. flags |= 1 << 2;
  206. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  207. CB::ENGINE_CALLBACK_NSM,
  208. 0,
  209. CB::NSM_CALLBACK_ANNOUNCE,
  210. flags,
  211. 0, 0.0f,
  212. smName);
  213. }
  214. std::free(msgURL);
  215. }
  216. else
  217. {
  218. carla_stdout("Got unknown NSM reply method '%s'", method);
  219. }
  220. return 0;
  221. }
  222. int handleOpen(const char* const projectPath, const char* const displayName, const char* const clientNameId)
  223. {
  224. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  225. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  226. carla_stdout("CarlaNSM::handleOpen(\"%s\", \"%s\", \"%s\")", projectPath, displayName, clientNameId);
  227. const CarlaHostHandle handle = (CarlaHostHandle)&gStandalone;
  228. carla_set_engine_option(handle, CB::ENGINE_OPTION_CLIENT_NAME_PREFIX, 0, clientNameId);
  229. if (gStandalone.engineCallback != nullptr)
  230. {
  231. fReadyActionOpen = false;
  232. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  233. CB::ENGINE_CALLBACK_NSM,
  234. 0,
  235. CB::NSM_CALLBACK_SET_CLIENT_NAME_ID,
  236. 0, 0, 0.0f,
  237. clientNameId);
  238. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  239. CB::ENGINE_CALLBACK_NSM,
  240. 0,
  241. CB::NSM_CALLBACK_OPEN,
  242. 0, 0, 0.0f,
  243. projectPath);
  244. for (; ! fReadyActionOpen;)
  245. carla_msleep(10);
  246. }
  247. else
  248. {
  249. using namespace water;
  250. if (carla_is_engine_running(handle))
  251. carla_engine_close(handle);
  252. // TODO send error if engine failed to initialize
  253. carla_engine_init(handle, "JACK", clientNameId);
  254. fProjectPath = projectPath;
  255. fProjectPath += ".carxp";
  256. const String jfilename = String(CharPointer_UTF8(fProjectPath));
  257. if (File(jfilename).existsAsFile())
  258. carla_load_project(handle, fProjectPath);
  259. }
  260. fClientNameId = clientNameId;
  261. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  262. // Broadcast ourselves
  263. if (fHasBroadcast)
  264. {
  265. const char* appName = std::getenv("CARLA_NSM_NAME");
  266. if (appName == nullptr)
  267. appName = "Carla";
  268. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/server/broadcast", "sssss",
  269. "/non/hello", fServerURL, appName, CARLA_VERSION_STRING, fClientNameId.buffer());
  270. }
  271. return 0;
  272. }
  273. int handleSave()
  274. {
  275. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  276. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  277. carla_stdout("CarlaNSM::handleSave()");
  278. if (gStandalone.engineCallback != nullptr)
  279. {
  280. fReadyActionSave = false;
  281. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  282. CB::ENGINE_CALLBACK_NSM,
  283. 0,
  284. CB::NSM_CALLBACK_SAVE,
  285. 0, 0, 0.0f, nullptr);
  286. for (; ! fReadyActionSave;)
  287. carla_msleep(10);
  288. }
  289. else
  290. {
  291. CARLA_SAFE_ASSERT_RETURN(fProjectPath.isNotEmpty(), 0);
  292. const CarlaHostHandle handle = (CarlaHostHandle)&gStandalone;
  293. carla_save_project(handle, fProjectPath);
  294. }
  295. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  296. return 0;
  297. }
  298. int handleSessionIsLoaded()
  299. {
  300. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  301. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  302. carla_stdout("CarlaNSM::handleSessionIsLoaded()");
  303. if (gStandalone.engineCallback != nullptr)
  304. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  305. CB::ENGINE_CALLBACK_NSM,
  306. 0,
  307. CB::NSM_CALLBACK_SESSION_IS_LOADED,
  308. 0, 0, 0.0f, nullptr);
  309. return 0;
  310. }
  311. int handleShowOptionalGui()
  312. {
  313. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  314. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  315. carla_stdout("CarlaNSM::handleShowOptionalGui()");
  316. if (gStandalone.engineCallback != nullptr)
  317. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  318. CB::ENGINE_CALLBACK_NSM,
  319. 0,
  320. CB::NSM_CALLBACK_SHOW_OPTIONAL_GUI,
  321. 0, 0, 0.0f, nullptr);
  322. return 0;
  323. }
  324. int handleHideOptionalGui()
  325. {
  326. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  327. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  328. carla_stdout("CarlaNSM::handleHideOptionalGui()");
  329. if (gStandalone.engineCallback != nullptr)
  330. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  331. CB::ENGINE_CALLBACK_NSM,
  332. 0,
  333. CB::NSM_CALLBACK_HIDE_OPTIONAL_GUI,
  334. 0, 0, 0.0f, nullptr);
  335. return 0;
  336. }
  337. int handleBroadcast(const char* const path, const char* const types, lo_arg** const argv, const int argc,
  338. const lo_message msg)
  339. {
  340. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  341. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  342. CARLA_SAFE_ASSERT_RETURN(argc >= 0, 0);
  343. carla_stdout("CarlaNSM::handleBroadcast(%s, %s, %p, %i)", path, types, argv, argc);
  344. #if 0
  345. if (std::strcmp(path, "/non/hello") == 0)
  346. {
  347. CARLA_SAFE_ASSERT_RETURN(argc == 4, 0);
  348. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ssss") == 0, 0);
  349. const char* const url = &argv[0]->s;
  350. //const char* const name = &argv[1]->s;
  351. //const char* const version = &argv[2]->s;
  352. //const char* const clientId = &argv[3]->s;
  353. const lo_address targetAddress(lo_address_new_from_url(url));
  354. CARLA_SAFE_ASSERT_RETURN(targetAddress != nullptr, 0);
  355. lo_send_from(targetAddress, fServer, LO_TT_IMMEDIATE, "/signal/hello", "ss",
  356. fClientNameId.buffer(), fServerURL);
  357. lo_address_free(targetAddress);
  358. return 0;
  359. }
  360. if (std::strcmp(path, "/signal/hello") == 0)
  361. {
  362. //const char* const name = &argv[0]->s;
  363. const char* const url = &argv[1]->s;
  364. const lo_address targetAddress(lo_address_new_from_url(url));
  365. CARLA_SAFE_ASSERT_RETURN(targetAddress != nullptr, 0);
  366. lo_send_from(targetAddress, fServer, LO_TT_IMMEDIATE, "/signal/hello", "ss",
  367. fClientNameId.buffer(), fServerURL);
  368. lo_address_free(targetAddress);
  369. return 0;
  370. }
  371. if (std::strcmp(path, "/signal/list") == 0)
  372. {
  373. carla_stdout("CarlaNSM::handleBroadcast - got list");
  374. CARLA_SAFE_ASSERT_RETURN(carla_is_engine_running(), 0);
  375. const char* prefix = nullptr;
  376. if (argc > 0)
  377. prefix = &argv[0]->s;
  378. const lo_address msgAddress(lo_message_get_source(msg));
  379. CARLA_SAFE_ASSERT_RETURN(msgAddress != nullptr, 0);
  380. for (uint32_t i = 0, pluginCount = carla_get_current_plugin_count(); i < pluginCount; ++i)
  381. {
  382. const CarlaPluginInfo* const pluginInfo(carla_get_plugin_info(i));
  383. CARLA_SAFE_ASSERT_CONTINUE(pluginInfo != nullptr);
  384. /*const*/ CarlaString pluginNameId(fClientNameId + "/" + CarlaString(pluginInfo->name).replace('/','_') + "/");
  385. for (uint32_t j=0, paramCount = carla_get_parameter_count(i); j < paramCount; ++j)
  386. {
  387. const CarlaParameterInfo* const paramInfo(carla_get_parameter_info(i, j));
  388. CARLA_SAFE_ASSERT_CONTINUE(paramInfo != nullptr);
  389. const ParameterData* const paramData(carla_get_parameter_data(i, j));
  390. CARLA_SAFE_ASSERT_CONTINUE(paramData != nullptr);
  391. const ParameterRanges* const paramRanges(carla_get_parameter_ranges(i, j));
  392. CARLA_SAFE_ASSERT_CONTINUE(paramRanges != nullptr);
  393. if (paramData->type != CB::PARAMETER_INPUT /*&& paramData->type != CB::PARAMETER_OUTPUT*/)
  394. continue;
  395. if ((paramData->hints & CB::PARAMETER_IS_ENABLED) == 0)
  396. continue;
  397. if ((paramData->hints & CB::PARAMETER_IS_AUTOMATABLE) == 0)
  398. continue;
  399. if (paramData->hints & CB::PARAMETER_IS_READ_ONLY)
  400. continue;
  401. const char* const dir = paramData->type == CB::PARAMETER_INPUT ? "in" : "out";
  402. const CarlaString paramNameId = pluginNameId + CarlaString(paramInfo->name).replace('/','_');
  403. const float defNorm = paramRanges->getNormalizedValue(paramRanges->def);
  404. if (prefix == nullptr || std::strncmp(paramNameId, prefix, std::strlen(prefix)) == 0)
  405. {
  406. lo_send_from(msgAddress, fServer, LO_TT_IMMEDIATE, "/reply", "sssfff",
  407. path, paramNameId.buffer(), dir, 0.0f, 1.0f, defNorm);
  408. }
  409. }
  410. }
  411. lo_send_from(msgAddress, fServer, LO_TT_IMMEDIATE, "/reply", "s", path);
  412. //return 0;
  413. }
  414. for (int i=0; i<argc; ++i)
  415. if (types[i] == 's')
  416. carla_stdout("%i: %s", i+1, &argv[i]->s);
  417. #endif
  418. return 0;
  419. // unused
  420. (void)msg;
  421. }
  422. private:
  423. CarlaHostStandalone& gStandalone;
  424. lo_address fReplyAddress;
  425. lo_server fServer;
  426. lo_server_thread fServerThread;
  427. char* fServerURL;
  428. CarlaString fClientNameId;
  429. CarlaString fProjectPath;
  430. bool fHasBroadcast;
  431. bool fHasOptionalGui;
  432. bool fHasServerControl;
  433. bool fStarted;
  434. volatile bool fReadyActionOpen;
  435. volatile bool fReadyActionSave;
  436. #define handlePtr ((CarlaNSM*)data)
  437. static void _osc_error_handler(int num, const char* msg, const char* path)
  438. {
  439. carla_stderr2("CarlaNSM::_osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  440. }
  441. static int _error_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message, void* data)
  442. {
  443. CARLA_SAFE_ASSERT_RETURN(argc == 3, 1);
  444. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "sis") == 0, 1);
  445. const char* const method = &argv[0]->s;
  446. const int code = argv[1]->i;
  447. const char* const message = &argv[2]->s;
  448. return handlePtr->handleError(method, code, message);
  449. }
  450. static int _reply_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  451. {
  452. CARLA_SAFE_ASSERT_RETURN(argc == 4, 1);
  453. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ssss") == 0, 1);
  454. const char* const method = &argv[0]->s;
  455. const char* const message = &argv[1]->s;
  456. const char* const smName = &argv[2]->s;
  457. const char* const features = &argv[3]->s;
  458. return handlePtr->handleReply(method, message, smName, features, msg);
  459. }
  460. static int _open_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message, void* data)
  461. {
  462. CARLA_SAFE_ASSERT_RETURN(argc == 3, 1);
  463. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "sss") == 0, 1);
  464. const char* const projectPath = &argv[0]->s;
  465. const char* const displayName = &argv[1]->s;
  466. const char* const clientNameId = &argv[2]->s;
  467. return handlePtr->handleOpen(projectPath, displayName, clientNameId);
  468. }
  469. static int _save_handler(const char*, const char*, lo_arg**, int argc, lo_message, void* data)
  470. {
  471. CARLA_SAFE_ASSERT_RETURN(argc == 0, 1);
  472. return handlePtr->handleSave();
  473. }
  474. static int _loaded_handler(const char*, const char*, lo_arg**, int argc, lo_message, void* data)
  475. {
  476. CARLA_SAFE_ASSERT_RETURN(argc == 0, 1);
  477. return handlePtr->handleSessionIsLoaded();
  478. }
  479. static int _show_gui_handler(const char*, const char*, lo_arg**, int argc, lo_message, void* data)
  480. {
  481. CARLA_SAFE_ASSERT_RETURN(argc == 0, 1);
  482. return handlePtr->handleShowOptionalGui();
  483. }
  484. static int _hide_gui_handler(const char*, const char*, lo_arg**, int argc, lo_message, void* data)
  485. {
  486. CARLA_SAFE_ASSERT_RETURN(argc == 0, 1);
  487. return handlePtr->handleHideOptionalGui();
  488. }
  489. static int _broadcast_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  490. {
  491. return handlePtr->handleBroadcast(path, types, argv, argc, msg);
  492. }
  493. #undef handlePtr
  494. CARLA_PREVENT_HEAP_ALLOCATION
  495. CARLA_DECLARE_NON_COPYABLE(CarlaNSM)
  496. };
  497. #endif // HAVE_LIBLO
  498. // -------------------------------------------------------------------------------------------------------------------
  499. bool carla_nsm_init(CarlaHostHandle handle, uint64_t pid, const char* executableName)
  500. {
  501. CARLA_SAFE_ASSERT_RETURN(handle->isStandalone, false);
  502. #ifdef HAVE_LIBLO
  503. return CarlaNSM::getInstance(*(CarlaHostStandalone*)handle).announce(pid, executableName);
  504. #else
  505. return false;
  506. // unused
  507. (void)pid; (void)executableName;
  508. #endif
  509. }
  510. void carla_nsm_ready(CarlaHostHandle handle, NsmCallbackOpcode action)
  511. {
  512. CARLA_SAFE_ASSERT_RETURN(handle->isStandalone,);
  513. #ifdef HAVE_LIBLO
  514. CarlaNSM::getInstance(*(CarlaHostStandalone*)handle).ready(action);
  515. #else
  516. // unused
  517. return; (void)action;
  518. #endif
  519. }
  520. // -------------------------------------------------------------------------------------------------------------------