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.

726 lines
24KB

  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. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  242. if (fControlDataTCP.owner == nullptr)
  243. {
  244. carla_stderr("OSC backend is not registered yet, control failed");
  245. return 0;
  246. }
  247. const int32_t messageId = argv[0]->i;
  248. bool ok;
  249. #define CARLA_SAFE_ASSERT_RETURN_OSC_ERR(cond) \
  250. if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); sendResponse(messageId, #cond); return 0; }
  251. /**/ if (std::strcmp(method, "clear_engine_xruns") == 0)
  252. {
  253. ok = true;
  254. fEngine->clearXruns();
  255. }
  256. else if (std::strcmp(method, "cancel_engine_action") == 0)
  257. {
  258. ok = true;
  259. fEngine->setActionCanceled(true);
  260. }
  261. else if (std::strcmp(method, "patchbay_connect") == 0)
  262. {
  263. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 6);
  264. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  265. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  266. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  267. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  268. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  269. const bool external = argv[1]->i != 0;
  270. const int32_t groupA = argv[2]->i;
  271. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupA >= 0);
  272. const int32_t portA = argv[3]->i;
  273. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portA >= 0);
  274. const int32_t groupB = argv[4]->i;
  275. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupB >= 0);
  276. const int32_t portB = argv[5]->i;
  277. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portB >= 0);
  278. ok = fEngine->patchbayConnect(external,
  279. static_cast<uint32_t>(groupA),
  280. static_cast<uint32_t>(portA),
  281. static_cast<uint32_t>(groupB),
  282. static_cast<uint32_t>(portB));
  283. }
  284. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  285. {
  286. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  287. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  288. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  289. const bool external = argv[1]->i != 0;
  290. const int32_t connectionId = argv[2]->i;
  291. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(connectionId >= 0);
  292. ok = fEngine->patchbayDisconnect(external, static_cast<uint32_t>(connectionId));
  293. }
  294. else if (std::strcmp(method, "patchbay_refresh") == 0)
  295. {
  296. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  297. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  298. const bool external = argv[1]->i != 0;
  299. ok = fEngine->patchbayRefresh(false, true, external);
  300. }
  301. else if (std::strcmp(method, "transport_play") == 0)
  302. {
  303. ok = true;
  304. fEngine->transportPlay();
  305. }
  306. else if (std::strcmp(method, "transport_pause") == 0)
  307. {
  308. ok = true;
  309. fEngine->transportPause();
  310. }
  311. else if (std::strcmp(method, "transport_bpm") == 0)
  312. {
  313. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  314. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f');
  315. const double bpm = argv[1]->f;
  316. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0);
  317. ok = true;
  318. fEngine->transportBPM(bpm);
  319. }
  320. else if (std::strcmp(method, "transport_relocate") == 0)
  321. {
  322. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  323. uint64_t frame;
  324. /**/ if (types[1] == 'i')
  325. {
  326. const int32_t i = argv[1]->i;
  327. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0);
  328. frame = static_cast<uint64_t>(i);
  329. }
  330. else if (types[1] == 'h')
  331. {
  332. const int64_t h = argv[1]->h;
  333. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0);
  334. frame = static_cast<uint64_t>(h);
  335. }
  336. else
  337. {
  338. carla_stderr2("Wrong OSC type used for '%s'", method);
  339. sendResponse(messageId, "Wrong OSC type");
  340. return 0;
  341. }
  342. ok = true;
  343. fEngine->transportRelocate(frame);
  344. }
  345. else if (std::strcmp(method, "add_plugin") == 0)
  346. {
  347. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8);
  348. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  349. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  350. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's');
  351. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's');
  352. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's');
  353. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i');
  354. int32_t btype = argv[1]->i;
  355. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0);
  356. const int32_t ptype = argv[2]->i;
  357. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0);
  358. // Force binary type to be native in some cases
  359. switch (ptype)
  360. {
  361. case PLUGIN_INTERNAL:
  362. case PLUGIN_LV2:
  363. case PLUGIN_SF2:
  364. case PLUGIN_SFZ:
  365. case PLUGIN_JACK:
  366. btype = BINARY_NATIVE;
  367. break;
  368. }
  369. const char* filename = &argv[3]->s;
  370. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  371. filename = nullptr;
  372. const char* name = &argv[4]->s;
  373. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  374. name = nullptr;
  375. const char* const label = &argv[5]->s;
  376. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0');
  377. int64_t uniqueId;
  378. /**/ if (types[6] == 'i')
  379. {
  380. uniqueId = argv[6]->i;
  381. }
  382. else if (types[6] == 'h')
  383. {
  384. uniqueId = argv[6]->h;
  385. }
  386. else
  387. {
  388. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  389. sendResponse(messageId, "Wrong OSC type");
  390. return 0;
  391. }
  392. const int32_t options = argv[7]->i;
  393. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0);
  394. ok = fEngine->addPlugin(static_cast<BinaryType>(btype),
  395. static_cast<PluginType>(ptype),
  396. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  397. }
  398. else if (std::strcmp(method, "remove_plugin") == 0)
  399. {
  400. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  401. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  402. const int32_t id = argv[1]->i;
  403. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  404. ok = fEngine->removePlugin(static_cast<uint32_t>(id));
  405. }
  406. else if (std::strcmp(method, "remove_all_plugins") == 0)
  407. {
  408. ok = fEngine->removeAllPlugins();
  409. }
  410. else if (std::strcmp(method, "rename_plugin") == 0)
  411. {
  412. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  413. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  414. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's');
  415. const int32_t id = argv[1]->i;
  416. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  417. const char* const newName = &argv[2]->s;
  418. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0');
  419. ok = fEngine->renamePlugin(static_cast<uint32_t>(id), newName);
  420. }
  421. else if (std::strcmp(method, "clone_plugin") == 0)
  422. {
  423. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  424. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  425. const int32_t id = argv[1]->i;
  426. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  427. ok = fEngine->clonePlugin(static_cast<uint32_t>(id));
  428. }
  429. else if (std::strcmp(method, "replace_plugin") == 0)
  430. {
  431. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  432. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  433. const int32_t id = argv[1]->i;
  434. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  435. ok = fEngine->replacePlugin(static_cast<uint32_t>(id));
  436. }
  437. else if (std::strcmp(method, "switch_plugins") == 0)
  438. {
  439. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  440. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  441. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  442. const int32_t idA = argv[1]->i;
  443. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0);
  444. const int32_t idB = argv[2]->i;
  445. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0);
  446. ok = fEngine->switchPlugins(static_cast<uint32_t>(idA), static_cast<uint32_t>(idB));
  447. }
  448. else
  449. {
  450. carla_stderr2("Unhandled OSC control for '%s'", method);
  451. sendResponse(messageId, "Unhandled OSC control method");
  452. return 0;
  453. }
  454. #undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR
  455. sendResponse(messageId, ok ? "" : fEngine->getLastError());
  456. return 0;
  457. }
  458. // -----------------------------------------------------------------------
  459. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  460. {
  461. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  462. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  463. const bool active = (argv[0]->i != 0);
  464. plugin->setActive(active, false, true);
  465. return 0;
  466. }
  467. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  468. {
  469. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  470. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  471. const float value = argv[0]->f;
  472. plugin->setDryWet(value, false, true);
  473. return 0;
  474. }
  475. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  476. {
  477. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  478. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  479. const float value = argv[0]->f;
  480. plugin->setVolume(value, false, true);
  481. return 0;
  482. }
  483. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  484. {
  485. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  486. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  487. const float value = argv[0]->f;
  488. plugin->setBalanceLeft(value, false, true);
  489. return 0;
  490. }
  491. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  492. {
  493. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  494. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  495. const float value = argv[0]->f;
  496. plugin->setBalanceRight(value, false, true);
  497. return 0;
  498. }
  499. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  500. {
  501. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  502. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  503. const float value = argv[0]->f;
  504. plugin->setPanning(value, false, true);
  505. return 0;
  506. }
  507. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  508. {
  509. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  510. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  511. const int32_t index = argv[0]->i;
  512. const float value = argv[1]->f;
  513. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  514. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  515. return 0;
  516. }
  517. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS)
  518. {
  519. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  520. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  521. const int32_t index = argv[0]->i;
  522. const int32_t cc = argv[1]->i;
  523. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  524. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL, 0);
  525. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  526. return 0;
  527. }
  528. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  529. {
  530. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  531. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  532. const int32_t index = argv[0]->i;
  533. const int32_t channel = argv[1]->i;
  534. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  535. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  536. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  537. return 0;
  538. }
  539. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  540. {
  541. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  542. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  543. const int32_t index = argv[0]->i;
  544. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  545. plugin->setProgram(index, true, false, true);
  546. return 0;
  547. }
  548. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  549. {
  550. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  551. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  552. const int32_t index = argv[0]->i;
  553. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  554. plugin->setMidiProgram(index, true, false, true);
  555. return 0;
  556. }
  557. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  558. {
  559. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  560. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  561. const int32_t channel = argv[0]->i;
  562. const int32_t note = argv[1]->i;
  563. const int32_t velo = argv[2]->i;
  564. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  565. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  566. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  567. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  568. return 0;
  569. }
  570. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  571. {
  572. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  573. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  574. const int32_t channel = argv[0]->i;
  575. const int32_t note = argv[1]->i;
  576. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  577. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  578. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  579. return 0;
  580. }
  581. // -----------------------------------------------------------------------
  582. CARLA_BACKEND_END_NAMESPACE
  583. #endif // HAVE_LIBLO