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.

623 lines
20KB

  1. /*
  2. * Carla Plugin Host
  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. #include "CarlaEngine.hpp"
  20. #include "CarlaEngineOsc.hpp"
  21. #include "CarlaPlugin.hpp"
  22. #include "CarlaMIDI.h"
  23. #include <cctype>
  24. CARLA_BACKEND_START_NAMESPACE
  25. // -----------------------------------------------------------------------
  26. CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine) noexcept
  27. : fEngine(engine),
  28. fControlData(),
  29. fName(),
  30. fServerPathTCP(),
  31. fServerPathUDP(),
  32. fServerTCP(nullptr),
  33. fServerUDP(nullptr)
  34. {
  35. CARLA_SAFE_ASSERT(engine != nullptr);
  36. carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine);
  37. }
  38. CarlaEngineOsc::~CarlaEngineOsc() noexcept
  39. {
  40. CARLA_SAFE_ASSERT(fName.isEmpty());
  41. CARLA_SAFE_ASSERT(fServerPathTCP.isEmpty());
  42. CARLA_SAFE_ASSERT(fServerPathUDP.isEmpty());
  43. CARLA_SAFE_ASSERT(fServerTCP == nullptr);
  44. CARLA_SAFE_ASSERT(fServerUDP == nullptr);
  45. carla_debug("CarlaEngineOsc::~CarlaEngineOsc()");
  46. }
  47. // -----------------------------------------------------------------------
  48. void CarlaEngineOsc::init(const char* const name, int tcpPort, int udpPort) noexcept
  49. {
  50. CARLA_SAFE_ASSERT_RETURN(fName.isEmpty(),);
  51. CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isEmpty(),);
  52. CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isEmpty(),);
  53. CARLA_SAFE_ASSERT_RETURN(fServerTCP == nullptr,);
  54. CARLA_SAFE_ASSERT_RETURN(fServerUDP == nullptr,);
  55. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  56. carla_debug("CarlaEngineOsc::init(\"%s\")", name);
  57. fName = name;
  58. fName.toBasic();
  59. if (fEngine->getType() != kEngineTypePlugin)
  60. {
  61. const char* const tcpPortEnv = std::getenv("CARLA_OSC_TCP_PORT");
  62. const char* const udpPortEnv = std::getenv("CARLA_OSC_UDP_PORT");
  63. if (tcpPortEnv != nullptr)
  64. tcpPort = std::atoi(tcpPortEnv);
  65. if (udpPortEnv != nullptr)
  66. udpPort = std::atoi(udpPortEnv);
  67. }
  68. // port == 0 means to pick a random one
  69. // port < 0 will get osc disabled
  70. static const int kRetryAttempts = 5;
  71. // ----------------------------------------------------------------------------------------------------------------
  72. if (tcpPort == 0)
  73. {
  74. for (int i=0; i < kRetryAttempts && fServerTCP == nullptr; ++i)
  75. fServerTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP);
  76. }
  77. else if (tcpPort >= 1024)
  78. {
  79. char strBuf[0xff];
  80. for (int i=0; i < kRetryAttempts && tcpPort < 32767 && fServerTCP == nullptr; ++i, ++tcpPort)
  81. {
  82. std::snprintf(strBuf, 0xff-1, "%d", tcpPort);
  83. strBuf[0xff-1] = '\0';
  84. fServerTCP = lo_server_new_with_proto(strBuf, LO_TCP, osc_error_handler_TCP);
  85. }
  86. }
  87. if (fServerTCP != nullptr)
  88. {
  89. if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP))
  90. {
  91. fServerPathTCP = tmpServerPathTCP;
  92. fServerPathTCP += fName;
  93. std::free(tmpServerPathTCP);
  94. }
  95. lo_server_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this);
  96. }
  97. // ----------------------------------------------------------------------------------------------------------------
  98. if (udpPort == 0)
  99. {
  100. for (int i=0; i < kRetryAttempts && fServerUDP == nullptr; ++i)
  101. fServerUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP);
  102. }
  103. else if (udpPort >= 1024)
  104. {
  105. char strBuf[0xff];
  106. for (int i=0; i < kRetryAttempts && udpPort < 32768 && fServerUDP == nullptr; ++i, ++udpPort)
  107. {
  108. std::snprintf(strBuf, 0xff-1, "%d", udpPort);
  109. strBuf[0xff-1] = '\0';
  110. fServerUDP = lo_server_new_with_proto(strBuf, LO_UDP, osc_error_handler_UDP);
  111. }
  112. }
  113. if (fServerUDP != nullptr)
  114. {
  115. if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP))
  116. {
  117. fServerPathUDP = tmpServerPathUDP;
  118. fServerPathUDP += fName;
  119. std::free(tmpServerPathUDP);
  120. }
  121. lo_server_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this);
  122. }
  123. // ----------------------------------------------------------------------------------------------------------------
  124. CARLA_SAFE_ASSERT(fName.isNotEmpty());
  125. }
  126. void CarlaEngineOsc::idle() const noexcept
  127. {
  128. if (fServerTCP != nullptr)
  129. {
  130. for (;;)
  131. {
  132. try {
  133. if (lo_server_recv_noblock(fServerTCP, 0) == 0)
  134. break;
  135. } CARLA_SAFE_EXCEPTION_CONTINUE("OSC idle TCP")
  136. }
  137. }
  138. if (fServerUDP != nullptr)
  139. {
  140. for (;;)
  141. {
  142. try {
  143. if (lo_server_recv_noblock(fServerUDP, 0) == 0)
  144. break;
  145. } CARLA_SAFE_EXCEPTION_CONTINUE("OSC idle UDP")
  146. }
  147. }
  148. }
  149. void CarlaEngineOsc::close() noexcept
  150. {
  151. CARLA_SAFE_ASSERT(fName.isNotEmpty());
  152. CARLA_SAFE_ASSERT(fServerPathTCP.isNotEmpty());
  153. CARLA_SAFE_ASSERT(fServerPathUDP.isNotEmpty());
  154. CARLA_SAFE_ASSERT(fServerTCP != nullptr);
  155. CARLA_SAFE_ASSERT(fServerUDP != nullptr);
  156. carla_debug("CarlaEngineOsc::close()");
  157. fName.clear();
  158. if (fServerTCP != nullptr)
  159. {
  160. lo_server_del_method(fServerTCP, nullptr, nullptr);
  161. lo_server_free(fServerTCP);
  162. fServerTCP = nullptr;
  163. }
  164. if (fServerUDP != nullptr)
  165. {
  166. lo_server_del_method(fServerUDP, nullptr, nullptr);
  167. lo_server_free(fServerUDP);
  168. fServerUDP = nullptr;
  169. }
  170. fServerPathTCP.clear();
  171. fServerPathUDP.clear();
  172. fControlData.clear();
  173. }
  174. // -----------------------------------------------------------------------
  175. int CarlaEngineOsc::handleMessage(const bool isTCP, const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg)
  176. {
  177. CARLA_SAFE_ASSERT_RETURN(fName.isNotEmpty(), 1);
  178. CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', 1);
  179. #ifdef DEBUG
  180. if (std::strstr(path, "/bridge_pong") == nullptr) {
  181. carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg);
  182. }
  183. #endif
  184. if (isTCP)
  185. {
  186. CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isNotEmpty(), 1);
  187. CARLA_SAFE_ASSERT_RETURN(fServerTCP != nullptr, 1);
  188. }
  189. else
  190. {
  191. CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1);
  192. CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1);
  193. }
  194. // Initial path check
  195. if (std::strcmp(path, "/register") == 0)
  196. return handleMsgRegister(isTCP, argc, argv, types);
  197. if (std::strcmp(path, "/unregister") == 0)
  198. return handleMsgUnregister(argc, argv, types);
  199. const std::size_t nameSize(fName.length());
  200. // Check if message is for this client
  201. if (std::strlen(path) <= nameSize || std::strncmp(path+1, fName, nameSize) != 0)
  202. {
  203. carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, fName.buffer());
  204. return 1;
  205. }
  206. // Get plugin id from path, "/carla/23/method" -> 23
  207. uint pluginId = 0;
  208. std::size_t offset;
  209. if (std::isdigit(path[nameSize+2]))
  210. {
  211. if (std::isdigit(path[nameSize+3]))
  212. {
  213. if (std::isdigit(path[nameSize+5]))
  214. {
  215. carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", path+(nameSize+1));
  216. return 1;
  217. }
  218. else if (std::isdigit(path[nameSize+4]))
  219. {
  220. // 3 digits, /xyz/method
  221. offset = 6;
  222. pluginId += uint(path[nameSize+2]-'0')*100;
  223. pluginId += uint(path[nameSize+3]-'0')*10;
  224. pluginId += uint(path[nameSize+4]-'0');
  225. }
  226. else
  227. {
  228. // 2 digits, /xy/method
  229. offset = 5;
  230. pluginId += uint(path[nameSize+2]-'0')*10;
  231. pluginId += uint(path[nameSize+3]-'0');
  232. }
  233. }
  234. else
  235. {
  236. // single digit, /x/method
  237. offset = 4;
  238. pluginId += uint(path[nameSize+2]-'0');
  239. }
  240. }
  241. else
  242. {
  243. carla_stderr("CarlaEngineOsc::handleMessage() - invalid message '%s'", path);
  244. return 1;
  245. }
  246. if (pluginId > fEngine->getCurrentPluginCount())
  247. {
  248. carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId);
  249. return 0;
  250. }
  251. // Get plugin
  252. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(pluginId));
  253. if (plugin == nullptr || plugin->getId() != pluginId)
  254. {
  255. carla_stderr("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed (path: '%s')", pluginId, path);
  256. return 0;
  257. }
  258. // Get method from path, "/Carla/i/method" -> "method"
  259. char method[32+1];
  260. method[32] = '\0';
  261. std::strncpy(method, path + (nameSize + offset), 32);
  262. if (method[0] == '\0')
  263. {
  264. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message without method", bool2str(isTCP), path);
  265. return 0;
  266. }
  267. // Internal methods
  268. if (std::strcmp(method, "set_option") == 0)
  269. return 0; //handleMsgSetOption(plugin, argc, argv, types); // TODO
  270. if (std::strcmp(method, "set_active") == 0)
  271. return handleMsgSetActive(plugin, argc, argv, types);
  272. if (std::strcmp(method, "set_drywet") == 0)
  273. return handleMsgSetDryWet(plugin, argc, argv, types);
  274. if (std::strcmp(method, "set_volume") == 0)
  275. return handleMsgSetVolume(plugin, argc, argv, types);
  276. if (std::strcmp(method, "set_balance_left") == 0)
  277. return handleMsgSetBalanceLeft(plugin, argc, argv, types);
  278. if (std::strcmp(method, "set_balance_right") == 0)
  279. return handleMsgSetBalanceRight(plugin, argc, argv, types);
  280. if (std::strcmp(method, "set_panning") == 0)
  281. return handleMsgSetPanning(plugin, argc, argv, types);
  282. if (std::strcmp(method, "set_ctrl_channel") == 0)
  283. return 0; //handleMsgSetControlChannel(plugin, argc, argv, types); // TODO
  284. if (std::strcmp(method, "set_parameter_value") == 0)
  285. return handleMsgSetParameterValue(plugin, argc, argv, types);
  286. if (std::strcmp(method, "set_parameter_midi_cc") == 0)
  287. return handleMsgSetParameterMidiCC(plugin, argc, argv, types);
  288. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  289. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  290. if (std::strcmp(method, "set_program") == 0)
  291. return handleMsgSetProgram(plugin, argc, argv, types);
  292. if (std::strcmp(method, "set_midi_program") == 0)
  293. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  294. if (std::strcmp(method, "set_custom_data") == 0)
  295. return 0; //handleMsgSetCustomData(plugin, argc, argv, types); // TODO
  296. if (std::strcmp(method, "set_chunk") == 0)
  297. return 0; //handleMsgSetChunk(plugin, argc, argv, types); // TODO
  298. if (std::strcmp(method, "note_on") == 0)
  299. return handleMsgNoteOn(plugin, argc, argv, types);
  300. if (std::strcmp(method, "note_off") == 0)
  301. return handleMsgNoteOff(plugin, argc, argv, types);
  302. // Send all other methods to plugins, TODO
  303. plugin->handleOscMessage(method, argc, argv, types, msg);
  304. return 0;
  305. }
  306. // -----------------------------------------------------------------------
  307. int CarlaEngineOsc::handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types)
  308. {
  309. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  310. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  311. const char* const url = &argv[0]->s;
  312. const lo_address addr = lo_address_new_from_url(url);
  313. if (fControlData.owner != nullptr)
  314. {
  315. carla_stderr("OSC backend already registered to %s", fControlData.owner);
  316. char* const path = lo_url_get_path(url);
  317. char targetPath[std::strlen(path)+18];
  318. std::strcpy(targetPath, path);
  319. std::strcat(targetPath, "/exit-error");
  320. lo_send_from(addr, isTCP ? fServerTCP : fServerUDP, LO_TT_IMMEDIATE,
  321. targetPath, "s", "OSC already registered to another client");
  322. free(path);
  323. }
  324. else
  325. {
  326. carla_stdout("OSC backend registered to %s", url);
  327. const char* const host = lo_address_get_hostname(addr);
  328. const char* const port = lo_address_get_port(addr);
  329. const lo_address target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  330. fControlData.owner = carla_strdup_safe(url);
  331. fControlData.path = carla_strdup_free(lo_url_get_path(url));
  332. fControlData.source = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  333. fControlData.target = target;
  334. for (uint i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  335. {
  336. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  337. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
  338. fEngine->callback(false, true, ENGINE_CALLBACK_PLUGIN_ADDED, i, 0, 0, 0, 0.0f, plugin->getName());
  339. }
  340. const EngineOptions& opts(fEngine->getOptions());
  341. fEngine->callback(false, true,
  342. ENGINE_CALLBACK_ENGINE_STARTED, 0,
  343. opts.processMode,
  344. opts.transportMode,
  345. static_cast<int>(fEngine->getBufferSize()),
  346. static_cast<float>(fEngine->getSampleRate()),
  347. fEngine->getCurrentDriverName());
  348. // TODO
  349. // fEngine->patchbayRefresh();
  350. }
  351. lo_address_free(addr);
  352. return 0;
  353. }
  354. int CarlaEngineOsc::handleMsgUnregister(const int argc, const lo_arg* const* const argv, const char* const types)
  355. {
  356. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  357. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  358. if (fControlData.owner == nullptr)
  359. {
  360. carla_stderr("OSC backend is not registered yet, unregister failed");
  361. return 0;
  362. }
  363. const char* const url = &argv[0]->s;
  364. if (std::strcmp(fControlData.owner, url) == 0)
  365. {
  366. carla_stdout("OSC client %s unregistered", url);
  367. fControlData.clear();
  368. return 0;
  369. }
  370. carla_stderr("OSC backend unregister failed, current owner %s does not match requested %s", fControlData.owner, url);
  371. return 0;
  372. }
  373. // -----------------------------------------------------------------------
  374. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  375. {
  376. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  377. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  378. const bool active = (argv[0]->i != 0);
  379. plugin->setActive(active, false, true);
  380. return 0;
  381. }
  382. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  383. {
  384. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  385. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  386. const float value = argv[0]->f;
  387. plugin->setDryWet(value, false, true);
  388. return 0;
  389. }
  390. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  391. {
  392. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  393. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  394. const float value = argv[0]->f;
  395. plugin->setVolume(value, false, true);
  396. return 0;
  397. }
  398. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  399. {
  400. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  401. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  402. const float value = argv[0]->f;
  403. plugin->setBalanceLeft(value, false, true);
  404. return 0;
  405. }
  406. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  407. {
  408. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  409. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  410. const float value = argv[0]->f;
  411. plugin->setBalanceRight(value, false, true);
  412. return 0;
  413. }
  414. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  415. {
  416. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  417. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  418. const float value = argv[0]->f;
  419. plugin->setPanning(value, false, true);
  420. return 0;
  421. }
  422. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  423. {
  424. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  425. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  426. const int32_t index = argv[0]->i;
  427. const float value = argv[1]->f;
  428. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  429. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  430. return 0;
  431. }
  432. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS)
  433. {
  434. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  435. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  436. const int32_t index = argv[0]->i;
  437. const int32_t cc = argv[1]->i;
  438. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  439. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL, 0);
  440. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  441. return 0;
  442. }
  443. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  444. {
  445. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  446. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  447. const int32_t index = argv[0]->i;
  448. const int32_t channel = argv[1]->i;
  449. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  450. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  451. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  452. return 0;
  453. }
  454. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  455. {
  456. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  457. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  458. const int32_t index = argv[0]->i;
  459. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  460. plugin->setProgram(index, true, false, true);
  461. return 0;
  462. }
  463. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  464. {
  465. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  466. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  467. const int32_t index = argv[0]->i;
  468. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  469. plugin->setMidiProgram(index, true, false, true);
  470. return 0;
  471. }
  472. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  473. {
  474. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  475. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  476. const int32_t channel = argv[0]->i;
  477. const int32_t note = argv[1]->i;
  478. const int32_t velo = argv[2]->i;
  479. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  480. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  481. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  482. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  483. return 0;
  484. }
  485. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  486. {
  487. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  488. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  489. const int32_t channel = argv[0]->i;
  490. const int32_t note = argv[1]->i;
  491. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  492. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  493. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  494. return 0;
  495. }
  496. // -----------------------------------------------------------------------
  497. CARLA_BACKEND_END_NAMESPACE
  498. #endif // HAVE_LIBLO