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.

674 lines
24KB

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