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.

696 lines
23KB

  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,
  196. fEngine->getCurrentPluginCount(),
  197. opts.processMode,
  198. opts.transportMode,
  199. static_cast<int>(fEngine->getBufferSize()),
  200. static_cast<float>(fEngine->getSampleRate()),
  201. fEngine->getCurrentDriverName());
  202. for (uint i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  203. {
  204. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  205. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
  206. fEngine->callback(false, true, ENGINE_CALLBACK_PLUGIN_ADDED, i, 0, 0, 0, 0.0f, plugin->getName());
  207. }
  208. fEngine->patchbayRefresh(false, true, fEngine->pData->graph.isUsingExternalOSC());
  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 == 5, 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. CARLA_SAFE_ASSERT_RETURN(types[4] == 'i', 0);
  262. const bool ext = argv[0]->i != 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. const int32_t i4 = argv[4]->i;
  270. CARLA_SAFE_ASSERT_RETURN(i4 >= 0, 0);
  271. fEngine->patchbayConnect(ext,
  272. static_cast<uint32_t>(i1),
  273. static_cast<uint32_t>(i2),
  274. static_cast<uint32_t>(i3),
  275. static_cast<uint32_t>(i4));
  276. }
  277. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  278. {
  279. CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0);
  280. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  281. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  282. const bool ext = argv[0]->i != 0;
  283. const int32_t id = argv[1]->i;
  284. CARLA_SAFE_ASSERT_RETURN(id >= 0, 0);
  285. fEngine->patchbayDisconnect(ext, static_cast<uint32_t>(id));
  286. }
  287. else if (std::strcmp(method, "patchbay_refresh") == 0)
  288. {
  289. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  290. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  291. const bool ext = argv[0]->i != 0;
  292. fEngine->patchbayRefresh(false, true, ext);
  293. }
  294. else if (std::strcmp(method, "transport_play") == 0)
  295. {
  296. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  297. fEngine->transportPlay();
  298. }
  299. else if (std::strcmp(method, "transport_pause") == 0)
  300. {
  301. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  302. fEngine->transportPause();
  303. }
  304. else if (std::strcmp(method, "transport_bpm") == 0)
  305. {
  306. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  307. CARLA_SAFE_ASSERT_RETURN(types[0] == 'f', 0);
  308. const double f = argv[0]->f;
  309. CARLA_SAFE_ASSERT_RETURN(f >= 0.0, 0);
  310. fEngine->transportBPM(f);
  311. }
  312. else if (std::strcmp(method, "transport_relocate") == 0)
  313. {
  314. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  315. uint64_t frame;
  316. /**/ if (types[0] == 'i')
  317. {
  318. const int32_t i = argv[0]->i;
  319. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  320. frame = static_cast<uint64_t>(i);
  321. }
  322. else if (types[0] == 'h')
  323. {
  324. const int64_t h = argv[0]->h;
  325. CARLA_SAFE_ASSERT_RETURN(h >= 0, 0);
  326. frame = static_cast<uint64_t>(h);
  327. }
  328. else
  329. {
  330. carla_stderr2("Wrong OSC type used for '%s'", method);
  331. return 0;
  332. }
  333. fEngine->transportRelocate(frame);
  334. }
  335. else if (std::strcmp(method, "add_plugin") == 0)
  336. {
  337. CARLA_SAFE_ASSERT_INT_RETURN(argc == 7, argc, 0);
  338. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  339. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  340. CARLA_SAFE_ASSERT_RETURN(types[2] == 's', 0);
  341. CARLA_SAFE_ASSERT_RETURN(types[3] == 's', 0);
  342. CARLA_SAFE_ASSERT_RETURN(types[4] == 's', 0);
  343. CARLA_SAFE_ASSERT_RETURN(types[6] == 'i', 0);
  344. const int32_t btype = argv[0]->i;
  345. CARLA_SAFE_ASSERT_RETURN(btype >= 0, 0);
  346. const int32_t ptype = argv[1]->i;
  347. CARLA_SAFE_ASSERT_RETURN(ptype >= 0, 0);
  348. const char* filename = &argv[2]->s;
  349. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  350. filename = nullptr;
  351. const char* name = &argv[3]->s;
  352. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  353. name = nullptr;
  354. const char* const label = &argv[4]->s;
  355. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', 0);
  356. int64_t uniqueId;
  357. /**/ if (types[5] == 'i')
  358. {
  359. uniqueId = argv[5]->i;
  360. }
  361. else if (types[5] == 'h')
  362. {
  363. uniqueId = argv[5]->h;
  364. }
  365. else
  366. {
  367. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  368. return 0;
  369. }
  370. const int32_t options = argv[6]->i;
  371. CARLA_SAFE_ASSERT_RETURN(options >= 0, 0);
  372. fEngine->addPlugin(static_cast<BinaryType>(btype),
  373. static_cast<PluginType>(ptype),
  374. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  375. }
  376. else if (std::strcmp(method, "remove_plugin") == 0)
  377. {
  378. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  379. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  380. const int32_t i = argv[0]->i;
  381. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  382. fEngine->removePlugin(static_cast<uint32_t>(i));
  383. }
  384. else if (std::strcmp(method, "remove_all_plugins") == 0)
  385. {
  386. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  387. fEngine->removeAllPlugins();
  388. }
  389. else if (std::strcmp(method, "rename_plugin") == 0)
  390. {
  391. CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0);
  392. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  393. CARLA_SAFE_ASSERT_RETURN(types[1] == 's', 0);
  394. const int32_t i = argv[0]->i;
  395. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  396. const char* const s = &argv[1]->s;
  397. CARLA_SAFE_ASSERT_RETURN(s != nullptr && s[0] != '\0', 0);
  398. fEngine->renamePlugin(static_cast<uint32_t>(i), s);
  399. }
  400. else if (std::strcmp(method, "clone_plugin") == 0)
  401. {
  402. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  403. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  404. const int32_t i = argv[0]->i;
  405. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  406. fEngine->clonePlugin(static_cast<uint32_t>(i));
  407. }
  408. else if (std::strcmp(method, "replace_plugin") == 0)
  409. {
  410. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  411. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  412. const int32_t i = argv[0]->i;
  413. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  414. fEngine->replacePlugin(static_cast<uint32_t>(i));
  415. }
  416. else if (std::strcmp(method, "switch_plugins") == 0)
  417. {
  418. CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0);
  419. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  420. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  421. const int32_t i0 = argv[0]->i;
  422. CARLA_SAFE_ASSERT_RETURN(i0 >= 0, 0);
  423. const int32_t i1 = argv[1]->i;
  424. CARLA_SAFE_ASSERT_RETURN(i1 >= 0, 0);
  425. fEngine->switchPlugins(static_cast<uint32_t>(i0), static_cast<uint32_t>(i1));
  426. }
  427. else
  428. {
  429. carla_stderr2("Unhandled OSC control for '%s'", method);
  430. }
  431. return 0;
  432. }
  433. // -----------------------------------------------------------------------
  434. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  435. {
  436. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  437. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  438. const bool active = (argv[0]->i != 0);
  439. plugin->setActive(active, false, true);
  440. return 0;
  441. }
  442. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  443. {
  444. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  445. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  446. const float value = argv[0]->f;
  447. plugin->setDryWet(value, false, true);
  448. return 0;
  449. }
  450. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  451. {
  452. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  453. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  454. const float value = argv[0]->f;
  455. plugin->setVolume(value, false, true);
  456. return 0;
  457. }
  458. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  459. {
  460. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  461. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  462. const float value = argv[0]->f;
  463. plugin->setBalanceLeft(value, false, true);
  464. return 0;
  465. }
  466. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  467. {
  468. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  469. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  470. const float value = argv[0]->f;
  471. plugin->setBalanceRight(value, false, true);
  472. return 0;
  473. }
  474. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  475. {
  476. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  477. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  478. const float value = argv[0]->f;
  479. plugin->setPanning(value, false, true);
  480. return 0;
  481. }
  482. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  483. {
  484. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  485. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  486. const int32_t index = argv[0]->i;
  487. const float value = argv[1]->f;
  488. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  489. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  490. return 0;
  491. }
  492. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS)
  493. {
  494. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  495. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  496. const int32_t index = argv[0]->i;
  497. const int32_t cc = argv[1]->i;
  498. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  499. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL, 0);
  500. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  501. return 0;
  502. }
  503. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  504. {
  505. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  506. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  507. const int32_t index = argv[0]->i;
  508. const int32_t channel = argv[1]->i;
  509. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  510. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  511. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  512. return 0;
  513. }
  514. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  515. {
  516. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  517. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  518. const int32_t index = argv[0]->i;
  519. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  520. plugin->setProgram(index, true, false, true);
  521. return 0;
  522. }
  523. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  524. {
  525. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  526. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  527. const int32_t index = argv[0]->i;
  528. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  529. plugin->setMidiProgram(index, true, false, true);
  530. return 0;
  531. }
  532. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  533. {
  534. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  535. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  536. const int32_t channel = argv[0]->i;
  537. const int32_t note = argv[1]->i;
  538. const int32_t velo = argv[2]->i;
  539. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  540. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  541. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  542. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  543. return 0;
  544. }
  545. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  546. {
  547. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  548. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  549. const int32_t channel = argv[0]->i;
  550. const int32_t note = argv[1]->i;
  551. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  552. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  553. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  554. return 0;
  555. }
  556. // -----------------------------------------------------------------------
  557. CARLA_BACKEND_END_NAMESPACE
  558. #endif // HAVE_LIBLO