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.

657 lines
23KB

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