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.

720 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, 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. fEngine->patchbayRefresh(false, true, fEngine->pData->graph.isUsingExternal());
  208. #if 0
  209. void CarlaPlugin::registerToOscClient() noexcept
  210. {
  211. // Programs
  212. if (const uint32_t count = std::min<uint32_t>(pData->prog.count, 50U))
  213. {
  214. pData->engine->oscSend_control_set_program_count(pData->id, count);
  215. for (uint32_t i=0; i < count; ++i)
  216. pData->engine->oscSend_control_set_program_name(pData->id, i, pData->prog.names[i]);
  217. // pData->engine->oscSend_control_set_current_program(pData->id, pData->prog.current);
  218. }
  219. // MIDI Programs
  220. if (const uint32_t count = std::min<uint32_t>(pData->midiprog.count, 50U))
  221. {
  222. pData->engine->oscSend_control_set_midi_program_count(pData->id, count);
  223. for (uint32_t i=0; i < count; ++i)
  224. {
  225. const MidiProgramData& mpData(pData->midiprog.data[i]);
  226. pData->engine->oscSend_control_set_midi_program_data(pData->id, i, mpData.bank, mpData.program, mpData.name);
  227. }
  228. // pData->engine->oscSend_control_set_current_midi_program(pData->id, pData->midiprog.current);
  229. }
  230. }
  231. #endif
  232. }
  233. }
  234. lo_address_free(addr);
  235. return 0;
  236. }
  237. int CarlaEngineOsc::handleMsgUnregister(const bool isTCP,
  238. const int argc, const lo_arg* const* const argv, const char* const types)
  239. {
  240. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  241. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  242. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  243. if (oscData.owner == nullptr)
  244. {
  245. carla_stderr("OSC backend is not registered yet, unregister failed");
  246. return 0;
  247. }
  248. const char* const url = &argv[0]->s;
  249. if (std::strcmp(oscData.owner, url) == 0)
  250. {
  251. carla_stdout("OSC client %s unregistered", url);
  252. oscData.clear();
  253. return 0;
  254. }
  255. carla_stderr("OSC backend unregister failed, current owner %s does not match requested %s", oscData.owner, url);
  256. return 0;
  257. }
  258. int CarlaEngineOsc::handleMsgControl(const char* const method,
  259. const int argc, const lo_arg* const* const argv, const char* const types)
  260. {
  261. carla_debug("CarlaEngineOsc::handleMsgControl()");
  262. CARLA_SAFE_ASSERT_RETURN(method != nullptr && method[0] != '\0', 0);
  263. CARLA_SAFE_ASSERT_RETURN(types != nullptr, 0);
  264. if (fControlDataTCP.owner == nullptr)
  265. {
  266. carla_stderr("OSC backend is not registered yet, control failed");
  267. return 0;
  268. }
  269. /**/ if (std::strcmp(method, "clear_engine_xruns") == 0)
  270. {
  271. fEngine->clearXruns();
  272. }
  273. else if (std::strcmp(method, "cancel_engine_action") == 0)
  274. {
  275. fEngine->setActionCanceled(true);
  276. }
  277. else if (std::strcmp(method, "patchbay_connect") == 0)
  278. {
  279. CARLA_SAFE_ASSERT_INT_RETURN(argc == 4, argc, 0);
  280. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  281. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  282. CARLA_SAFE_ASSERT_RETURN(types[2] == 'i', 0);
  283. CARLA_SAFE_ASSERT_RETURN(types[3] == 'i', 0);
  284. const int32_t i0 = argv[0]->i;
  285. CARLA_SAFE_ASSERT_RETURN(i0 >= 0, 0);
  286. const int32_t i1 = argv[1]->i;
  287. CARLA_SAFE_ASSERT_RETURN(i1 >= 0, 0);
  288. const int32_t i2 = argv[2]->i;
  289. CARLA_SAFE_ASSERT_RETURN(i2 >= 0, 0);
  290. const int32_t i3 = argv[3]->i;
  291. CARLA_SAFE_ASSERT_RETURN(i3 >= 0, 0);
  292. fEngine->patchbayConnect(static_cast<uint32_t>(i0),
  293. static_cast<uint32_t>(i1),
  294. static_cast<uint32_t>(i2),
  295. static_cast<uint32_t>(i3));
  296. }
  297. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  298. {
  299. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  300. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  301. const int32_t i = argv[0]->i;
  302. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  303. fEngine->patchbayDisconnect(static_cast<uint32_t>(i));
  304. }
  305. else if (std::strcmp(method, "patchbay_refresh") == 0)
  306. {
  307. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  308. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  309. const int32_t i = argv[0]->i;
  310. fEngine->patchbayRefresh(false, true, i != 0);
  311. }
  312. else if (std::strcmp(method, "transport_play") == 0)
  313. {
  314. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  315. fEngine->transportPlay();
  316. }
  317. else if (std::strcmp(method, "transport_pause") == 0)
  318. {
  319. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  320. fEngine->transportPause();
  321. }
  322. else if (std::strcmp(method, "transport_bpm") == 0)
  323. {
  324. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  325. CARLA_SAFE_ASSERT_RETURN(types[0] == 'f', 0);
  326. const double f = argv[0]->f;
  327. CARLA_SAFE_ASSERT_RETURN(f >= 0.0, 0);
  328. fEngine->transportBPM(f);
  329. }
  330. else if (std::strcmp(method, "transport_relocate") == 0)
  331. {
  332. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  333. uint64_t frame;
  334. /**/ if (types[0] == 'i')
  335. {
  336. const int32_t i = argv[0]->i;
  337. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  338. frame = static_cast<uint64_t>(i);
  339. }
  340. else if (types[0] == 'h')
  341. {
  342. const int64_t h = argv[0]->h;
  343. CARLA_SAFE_ASSERT_RETURN(h >= 0, 0);
  344. frame = static_cast<uint64_t>(h);
  345. }
  346. else
  347. {
  348. carla_stderr2("Wrong OSC type used for '%s'", method);
  349. return 0;
  350. }
  351. fEngine->transportRelocate(frame);
  352. }
  353. else if (std::strcmp(method, "add_plugin") == 0)
  354. {
  355. CARLA_SAFE_ASSERT_INT_RETURN(argc == 7, argc, 0);
  356. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  357. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  358. CARLA_SAFE_ASSERT_RETURN(types[2] == 's', 0);
  359. CARLA_SAFE_ASSERT_RETURN(types[3] == 's', 0);
  360. CARLA_SAFE_ASSERT_RETURN(types[4] == 's', 0);
  361. CARLA_SAFE_ASSERT_RETURN(types[6] == 'i', 0);
  362. const int32_t btype = argv[0]->i;
  363. CARLA_SAFE_ASSERT_RETURN(btype >= 0, 0);
  364. const int32_t ptype = argv[1]->i;
  365. CARLA_SAFE_ASSERT_RETURN(ptype >= 0, 0);
  366. const char* filename = &argv[2]->s;
  367. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  368. filename = nullptr;
  369. const char* name = &argv[3]->s;
  370. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  371. name = nullptr;
  372. const char* const label = &argv[4]->s;
  373. CARLA_SAFE_ASSERT_RETURN(label != nullptr && label[0] != '\0', 0);
  374. int64_t uniqueId;
  375. /**/ if (types[5] == 'i')
  376. {
  377. uniqueId = argv[5]->i;
  378. }
  379. else if (types[5] == 'h')
  380. {
  381. uniqueId = argv[5]->h;
  382. }
  383. else
  384. {
  385. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  386. return 0;
  387. }
  388. const int32_t options = argv[6]->i;
  389. CARLA_SAFE_ASSERT_RETURN(options >= 0, 0);
  390. fEngine->addPlugin(static_cast<BinaryType>(btype),
  391. static_cast<PluginType>(ptype),
  392. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  393. }
  394. else if (std::strcmp(method, "remove_plugin") == 0)
  395. {
  396. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  397. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  398. const int32_t i = argv[0]->i;
  399. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  400. fEngine->removePlugin(static_cast<uint32_t>(i));
  401. }
  402. else if (std::strcmp(method, "remove_all_plugins") == 0)
  403. {
  404. CARLA_SAFE_ASSERT_INT_RETURN(argc == 0, argc, 0);
  405. fEngine->removeAllPlugins();
  406. }
  407. else if (std::strcmp(method, "rename_plugin") == 0)
  408. {
  409. CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0);
  410. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  411. CARLA_SAFE_ASSERT_RETURN(types[1] == 's', 0);
  412. const int32_t i = argv[0]->i;
  413. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  414. const char* const s = &argv[0]->s;
  415. CARLA_SAFE_ASSERT_RETURN(s != nullptr && s[0] != '\0', 0);
  416. fEngine->renamePlugin(static_cast<uint32_t>(i), s);
  417. }
  418. else if (std::strcmp(method, "clone_plugin") == 0)
  419. {
  420. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  421. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  422. const int32_t i = argv[0]->i;
  423. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  424. fEngine->clonePlugin(static_cast<uint32_t>(i));
  425. }
  426. else if (std::strcmp(method, "replace_plugin") == 0)
  427. {
  428. CARLA_SAFE_ASSERT_INT_RETURN(argc == 1, argc, 0);
  429. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  430. const int32_t i = argv[0]->i;
  431. CARLA_SAFE_ASSERT_RETURN(i >= 0, 0);
  432. fEngine->replacePlugin(static_cast<uint32_t>(i));
  433. }
  434. else if (std::strcmp(method, "switch_plugins") == 0)
  435. {
  436. CARLA_SAFE_ASSERT_INT_RETURN(argc == 2, argc, 0);
  437. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  438. CARLA_SAFE_ASSERT_RETURN(types[1] == 'i', 0);
  439. const int32_t i0 = argv[0]->i;
  440. CARLA_SAFE_ASSERT_RETURN(i0 >= 0, 0);
  441. const int32_t i1 = argv[0]->i;
  442. CARLA_SAFE_ASSERT_RETURN(i1 >= 0, 0);
  443. fEngine->switchPlugins(static_cast<uint32_t>(i0), static_cast<uint32_t>(i1));
  444. }
  445. else
  446. {
  447. carla_stderr2("Unhandled OSC control for '%s'", method);
  448. }
  449. return 0;
  450. }
  451. // -----------------------------------------------------------------------
  452. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  453. {
  454. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  455. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  456. const bool active = (argv[0]->i != 0);
  457. plugin->setActive(active, false, true);
  458. return 0;
  459. }
  460. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  461. {
  462. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  463. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  464. const float value = argv[0]->f;
  465. plugin->setDryWet(value, false, true);
  466. return 0;
  467. }
  468. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  469. {
  470. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  471. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  472. const float value = argv[0]->f;
  473. plugin->setVolume(value, false, true);
  474. return 0;
  475. }
  476. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  477. {
  478. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  479. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  480. const float value = argv[0]->f;
  481. plugin->setBalanceLeft(value, false, true);
  482. return 0;
  483. }
  484. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  485. {
  486. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  487. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  488. const float value = argv[0]->f;
  489. plugin->setBalanceRight(value, false, true);
  490. return 0;
  491. }
  492. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  493. {
  494. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  495. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  496. const float value = argv[0]->f;
  497. plugin->setPanning(value, false, true);
  498. return 0;
  499. }
  500. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  501. {
  502. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  503. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  504. const int32_t index = argv[0]->i;
  505. const float value = argv[1]->f;
  506. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  507. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  508. return 0;
  509. }
  510. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS)
  511. {
  512. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  513. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  514. const int32_t index = argv[0]->i;
  515. const int32_t cc = argv[1]->i;
  516. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  517. CARLA_SAFE_ASSERT_RETURN(cc >= -1 && cc < MAX_MIDI_CONTROL, 0);
  518. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  519. return 0;
  520. }
  521. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  522. {
  523. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  524. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  525. const int32_t index = argv[0]->i;
  526. const int32_t channel = argv[1]->i;
  527. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  528. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  529. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  530. return 0;
  531. }
  532. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  533. {
  534. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  535. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  536. const int32_t index = argv[0]->i;
  537. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  538. plugin->setProgram(index, true, false, true);
  539. return 0;
  540. }
  541. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  542. {
  543. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  544. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  545. const int32_t index = argv[0]->i;
  546. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  547. plugin->setMidiProgram(index, true, false, true);
  548. return 0;
  549. }
  550. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  551. {
  552. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  553. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  554. const int32_t channel = argv[0]->i;
  555. const int32_t note = argv[1]->i;
  556. const int32_t velo = argv[2]->i;
  557. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  558. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  559. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  560. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  561. return 0;
  562. }
  563. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  564. {
  565. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  566. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  567. const int32_t channel = argv[0]->i;
  568. const int32_t note = argv[1]->i;
  569. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  570. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  571. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  572. return 0;
  573. }
  574. // -----------------------------------------------------------------------
  575. CARLA_BACKEND_END_NAMESPACE
  576. #endif // HAVE_LIBLO