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.

638 lines
21KB

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