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.

CarlaStandaloneNSM.cpp 23KB

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