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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /*
  2. * Carla Standalone
  3. * Copyright (C) 2011-2020 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. }
  148. }
  149. static CarlaNSM& getInstance(CarlaHostStandalone& shandle)
  150. {
  151. static CarlaNSM sInstance(shandle);
  152. return sInstance;
  153. }
  154. protected:
  155. int handleError(const char* const method, const int code, const char* const message)
  156. {
  157. carla_stdout("CarlaNSM::handleError(\"%s\", %i, \"%s\")", method, code, message);
  158. if (gStandalone.engineCallback != nullptr)
  159. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  160. CB::ENGINE_CALLBACK_NSM,
  161. 0,
  162. CB::NSM_CALLBACK_ERROR,
  163. code,
  164. 0, 0.0f,
  165. message);
  166. return 0;
  167. // may be unused
  168. (void)method;
  169. }
  170. int handleReply(const char* const method, const char* const message, const char* const smName, const char* const features,
  171. const lo_message msg)
  172. {
  173. CARLA_SAFE_ASSERT_RETURN(fServerThread != nullptr, 1);
  174. carla_stdout("CarlaNSM::handleReply(\"%s\", \"%s\", \"%s\", \"%s\")", method, message, smName, features);
  175. if (std::strcmp(method, "/nsm/server/announce") == 0)
  176. {
  177. const lo_address msgAddress(lo_message_get_source(msg));
  178. CARLA_SAFE_ASSERT_RETURN(msgAddress != nullptr, 0);
  179. char* const msgURL(lo_address_get_url(msgAddress));
  180. CARLA_SAFE_ASSERT_RETURN(msgURL != nullptr, 0);
  181. if (fReplyAddress != nullptr)
  182. lo_address_free(fReplyAddress);
  183. fReplyAddress = lo_address_new_from_url(msgURL);
  184. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 0);
  185. fHasBroadcast = std::strstr(features, ":broadcast:") != nullptr;
  186. fHasOptionalGui = std::strstr(features, ":optional-gui:") != nullptr;
  187. fHasServerControl = std::strstr(features, ":server_control:") != nullptr;
  188. #if 0
  189. // UI starts visible
  190. if (fHasOptionalGui)
  191. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/client/gui_is_shown", "");
  192. #endif
  193. carla_stdout("Carla started via '%s', message: %s", smName, message);
  194. if (gStandalone.engineCallback != nullptr)
  195. {
  196. int flags = 0;
  197. if (fHasBroadcast)
  198. flags |= 1 << 0;
  199. if (fHasOptionalGui)
  200. flags |= 1 << 1;
  201. if (fHasServerControl)
  202. flags |= 1 << 2;
  203. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  204. CB::ENGINE_CALLBACK_NSM,
  205. 0,
  206. CB::NSM_CALLBACK_ANNOUNCE,
  207. flags,
  208. 0, 0.0f,
  209. smName);
  210. }
  211. std::free(msgURL);
  212. }
  213. else
  214. {
  215. carla_stdout("Got unknown NSM reply method '%s'", method);
  216. }
  217. return 0;
  218. }
  219. int handleOpen(const char* const projectPath, const char* const displayName, const char* const clientNameId)
  220. {
  221. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  222. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  223. carla_stdout("CarlaNSM::handleOpen(\"%s\", \"%s\", \"%s\")", projectPath, displayName, clientNameId);
  224. if (gStandalone.engineCallback != nullptr)
  225. {
  226. fReadyActionOpen = false;
  227. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  228. CB::ENGINE_CALLBACK_NSM,
  229. 0,
  230. CB::NSM_CALLBACK_OPEN,
  231. 0, 0, 0.0f,
  232. projectPath);
  233. for (; ! fReadyActionOpen;)
  234. carla_msleep(10);
  235. }
  236. else
  237. {
  238. using namespace water;
  239. const CarlaHostHandle handle = (CarlaHostHandle)&gStandalone;
  240. if (carla_is_engine_running(handle))
  241. carla_engine_close(handle);
  242. carla_engine_init(handle, "JACK", clientNameId);
  243. fProjectPath = projectPath;
  244. fProjectPath += ".carxp";
  245. const String jfilename = String(CharPointer_UTF8(fProjectPath));
  246. if (File(jfilename).existsAsFile())
  247. carla_load_project(handle, fProjectPath);
  248. }
  249. fClientNameId = clientNameId;
  250. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/open", "OK");
  251. // Broadcast ourselves
  252. if (fHasBroadcast)
  253. {
  254. const char* appName = std::getenv("CARLA_NSM_NAME");
  255. if (appName == nullptr)
  256. appName = "Carla";
  257. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/nsm/server/broadcast", "sssss",
  258. "/non/hello", fServerURL, appName, CARLA_VERSION_STRING, fClientNameId.buffer());
  259. }
  260. return 0;
  261. }
  262. int handleSave()
  263. {
  264. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  265. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  266. carla_stdout("CarlaNSM::handleSave()");
  267. if (gStandalone.engineCallback != nullptr)
  268. {
  269. fReadyActionSave = false;
  270. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  271. CB::ENGINE_CALLBACK_NSM,
  272. 0,
  273. CB::NSM_CALLBACK_SAVE,
  274. 0, 0, 0.0f, nullptr);
  275. for (; ! fReadyActionSave;)
  276. carla_msleep(10);
  277. }
  278. else
  279. {
  280. CARLA_SAFE_ASSERT_RETURN(fProjectPath.isNotEmpty(), 0);
  281. const CarlaHostHandle handle = (CarlaHostHandle)&gStandalone;
  282. carla_save_project(handle, fProjectPath);
  283. }
  284. lo_send_from(fReplyAddress, fServer, LO_TT_IMMEDIATE, "/reply", "ss", "/nsm/client/save", "OK");
  285. return 0;
  286. }
  287. int handleSessionIsLoaded()
  288. {
  289. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  290. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  291. carla_stdout("CarlaNSM::handleSessionIsLoaded()");
  292. if (gStandalone.engineCallback != nullptr)
  293. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  294. CB::ENGINE_CALLBACK_NSM,
  295. 0,
  296. CB::NSM_CALLBACK_SESSION_IS_LOADED,
  297. 0, 0, 0.0f, nullptr);
  298. return 0;
  299. }
  300. int handleShowOptionalGui()
  301. {
  302. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  303. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  304. carla_stdout("CarlaNSM::handleShowOptionalGui()");
  305. if (gStandalone.engineCallback != nullptr)
  306. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  307. CB::ENGINE_CALLBACK_NSM,
  308. 0,
  309. CB::NSM_CALLBACK_SHOW_OPTIONAL_GUI,
  310. 0, 0, 0.0f, nullptr);
  311. return 0;
  312. }
  313. int handleHideOptionalGui()
  314. {
  315. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  316. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  317. carla_stdout("CarlaNSM::handleHideOptionalGui()");
  318. if (gStandalone.engineCallback != nullptr)
  319. gStandalone.engineCallback(gStandalone.engineCallbackPtr,
  320. CB::ENGINE_CALLBACK_NSM,
  321. 0,
  322. CB::NSM_CALLBACK_HIDE_OPTIONAL_GUI,
  323. 0, 0, 0.0f, nullptr);
  324. return 0;
  325. }
  326. int handleBroadcast(const char* const path, const char* const types, lo_arg** const argv, const int argc,
  327. const lo_message msg)
  328. {
  329. CARLA_SAFE_ASSERT_RETURN(fReplyAddress != nullptr, 1);
  330. CARLA_SAFE_ASSERT_RETURN(fServer != nullptr, 1);
  331. CARLA_SAFE_ASSERT_RETURN(argc >= 0, 0);
  332. carla_stdout("CarlaNSM::handleBroadcast(%s, %s, %p, %i)", path, types, argv, argc);
  333. #if 0
  334. if (std::strcmp(path, "/non/hello") == 0)
  335. {
  336. CARLA_SAFE_ASSERT_RETURN(argc == 4, 0);
  337. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ssss") == 0, 0);
  338. const char* const url = &argv[0]->s;
  339. //const char* const name = &argv[1]->s;
  340. //const char* const version = &argv[2]->s;
  341. //const char* const clientId = &argv[3]->s;
  342. const lo_address targetAddress(lo_address_new_from_url(url));
  343. CARLA_SAFE_ASSERT_RETURN(targetAddress != nullptr, 0);
  344. lo_send_from(targetAddress, fServer, LO_TT_IMMEDIATE, "/signal/hello", "ss",
  345. fClientNameId.buffer(), fServerURL);
  346. lo_address_free(targetAddress);
  347. return 0;
  348. }
  349. if (std::strcmp(path, "/signal/hello") == 0)
  350. {
  351. //const char* const name = &argv[0]->s;
  352. const char* const url = &argv[1]->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/list") == 0)
  361. {
  362. carla_stdout("CarlaNSM::handleBroadcast - got list");
  363. CARLA_SAFE_ASSERT_RETURN(carla_is_engine_running(), 0);
  364. const char* prefix = nullptr;
  365. if (argc > 0)
  366. prefix = &argv[0]->s;
  367. const lo_address msgAddress(lo_message_get_source(msg));
  368. CARLA_SAFE_ASSERT_RETURN(msgAddress != nullptr, 0);
  369. for (uint32_t i = 0, pluginCount = carla_get_current_plugin_count(); i < pluginCount; ++i)
  370. {
  371. const CarlaPluginInfo* const pluginInfo(carla_get_plugin_info(i));
  372. CARLA_SAFE_ASSERT_CONTINUE(pluginInfo != nullptr);
  373. /*const*/ CarlaString pluginNameId(fClientNameId + "/" + CarlaString(pluginInfo->name).replace('/','_') + "/");
  374. for (uint32_t j=0, paramCount = carla_get_parameter_count(i); j < paramCount; ++j)
  375. {
  376. const CarlaParameterInfo* const paramInfo(carla_get_parameter_info(i, j));
  377. CARLA_SAFE_ASSERT_CONTINUE(paramInfo != nullptr);
  378. const ParameterData* const paramData(carla_get_parameter_data(i, j));
  379. CARLA_SAFE_ASSERT_CONTINUE(paramData != nullptr);
  380. const ParameterRanges* const paramRanges(carla_get_parameter_ranges(i, j));
  381. CARLA_SAFE_ASSERT_CONTINUE(paramRanges != nullptr);
  382. if (paramData->type != CB::PARAMETER_INPUT /*&& paramData->type != CB::PARAMETER_OUTPUT*/)
  383. continue;
  384. if ((paramData->hints & CB::PARAMETER_IS_ENABLED) == 0)
  385. continue;
  386. if ((paramData->hints & CB::PARAMETER_IS_AUTOMABLE) == 0)
  387. continue;
  388. if (paramData->hints & CB::PARAMETER_IS_READ_ONLY)
  389. continue;
  390. const char* const dir = paramData->type == CB::PARAMETER_INPUT ? "in" : "out";
  391. const CarlaString paramNameId = pluginNameId + CarlaString(paramInfo->name).replace('/','_');
  392. const float defNorm = paramRanges->getNormalizedValue(paramRanges->def);
  393. if (prefix == nullptr || std::strncmp(paramNameId, prefix, std::strlen(prefix)) == 0)
  394. {
  395. lo_send_from(msgAddress, fServer, LO_TT_IMMEDIATE, "/reply", "sssfff",
  396. path, paramNameId.buffer(), dir, 0.0f, 1.0f, defNorm);
  397. }
  398. }
  399. }
  400. lo_send_from(msgAddress, fServer, LO_TT_IMMEDIATE, "/reply", "s", path);
  401. //return 0;
  402. }
  403. for (int i=0; i<argc; ++i)
  404. if (types[i] == 's')
  405. carla_stdout("%i: %s", i+1, &argv[i]->s);
  406. #endif
  407. return 0;
  408. // unused
  409. (void)msg;
  410. }
  411. private:
  412. CarlaHostStandalone& gStandalone;
  413. lo_address fReplyAddress;
  414. lo_server fServer;
  415. lo_server_thread fServerThread;
  416. char* fServerURL;
  417. CarlaString fClientNameId;
  418. CarlaString fProjectPath;
  419. bool fHasBroadcast;
  420. bool fHasOptionalGui;
  421. bool fHasServerControl;
  422. bool fStarted;
  423. volatile bool fReadyActionOpen;
  424. volatile bool fReadyActionSave;
  425. #define handlePtr ((CarlaNSM*)data)
  426. static void _osc_error_handler(int num, const char* msg, const char* path)
  427. {
  428. carla_stderr2("CarlaNSM::_osc_error_handler(%i, \"%s\", \"%s\")", num, msg, path);
  429. }
  430. static int _error_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message, void* data)
  431. {
  432. CARLA_SAFE_ASSERT_RETURN(argc == 3, 1);
  433. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "sis") == 0, 1);
  434. const char* const method = &argv[0]->s;
  435. const int code = argv[1]->i;
  436. const char* const message = &argv[2]->s;
  437. return handlePtr->handleError(method, code, message);
  438. }
  439. static int _reply_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  440. {
  441. CARLA_SAFE_ASSERT_RETURN(argc == 4, 1);
  442. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "ssss") == 0, 1);
  443. const char* const method = &argv[0]->s;
  444. const char* const message = &argv[1]->s;
  445. const char* const smName = &argv[2]->s;
  446. const char* const features = &argv[3]->s;
  447. return handlePtr->handleReply(method, message, smName, features, msg);
  448. }
  449. static int _open_handler(const char*, const char* types, lo_arg** argv, int argc, lo_message, void* data)
  450. {
  451. CARLA_SAFE_ASSERT_RETURN(argc == 3, 1);
  452. CARLA_SAFE_ASSERT_RETURN(std::strcmp(types, "sss") == 0, 1);
  453. const char* const projectPath = &argv[0]->s;
  454. const char* const displayName = &argv[1]->s;
  455. const char* const clientNameId = &argv[2]->s;
  456. return handlePtr->handleOpen(projectPath, displayName, clientNameId);
  457. }
  458. static int _save_handler(const char*, const char*, lo_arg**, int argc, lo_message, void* data)
  459. {
  460. CARLA_SAFE_ASSERT_RETURN(argc == 0, 1);
  461. return handlePtr->handleSave();
  462. }
  463. static int _loaded_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->handleSessionIsLoaded();
  467. }
  468. static int _show_gui_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->handleShowOptionalGui();
  472. }
  473. static int _hide_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->handleHideOptionalGui();
  477. }
  478. static int _broadcast_handler(const char* path, const char* types, lo_arg** argv, int argc, lo_message msg, void* data)
  479. {
  480. return handlePtr->handleBroadcast(path, types, argv, argc, msg);
  481. }
  482. #undef handlePtr
  483. CARLA_PREVENT_HEAP_ALLOCATION
  484. CARLA_DECLARE_NON_COPY_CLASS(CarlaNSM)
  485. };
  486. #endif // HAVE_LIBLO
  487. // -------------------------------------------------------------------------------------------------------------------
  488. bool carla_nsm_init(CarlaHostHandle handle, uint64_t pid, const char* executableName)
  489. {
  490. CARLA_SAFE_ASSERT_RETURN(handle->isStandalone, false);
  491. #ifdef HAVE_LIBLO
  492. return CarlaNSM::getInstance(*(CarlaHostStandalone*)handle).announce(pid, executableName);
  493. #else
  494. return false;
  495. // unused
  496. (void)pid; (void)executableName;
  497. #endif
  498. }
  499. void carla_nsm_ready(CarlaHostHandle handle, NsmCallbackOpcode action)
  500. {
  501. CARLA_SAFE_ASSERT_RETURN(handle->isStandalone,);
  502. #ifdef HAVE_LIBLO
  503. CarlaNSM::getInstance(*(CarlaHostStandalone*)handle).ready(action);
  504. #else
  505. // unused
  506. return; (void)action;
  507. #endif
  508. }
  509. // -------------------------------------------------------------------------------------------------------------------