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.

662 lines
23KB

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