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.

CarlaEngineOscHandlers.cpp 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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_mapped_control_index") == 0)
  143. return handleMsgSetParameterMappedControlIndex(plugin, argc, argv, types);
  144. if (std::strcmp(method, "set_parameter_mapped_range") == 0)
  145. return handleMsgSetParameterMappedRange(plugin, argc, argv, types);
  146. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  147. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  148. if (std::strcmp(method, "set_program") == 0)
  149. return handleMsgSetProgram(plugin, argc, argv, types);
  150. if (std::strcmp(method, "set_midi_program") == 0)
  151. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  152. if (std::strcmp(method, "set_custom_data") == 0)
  153. return 0; //handleMsgSetCustomData(plugin, argc, argv, types); // TODO
  154. if (std::strcmp(method, "set_chunk") == 0)
  155. return 0; //handleMsgSetChunk(plugin, argc, argv, types); // TODO
  156. if (std::strcmp(method, "note_on") == 0)
  157. return handleMsgNoteOn(plugin, argc, argv, types);
  158. if (std::strcmp(method, "note_off") == 0)
  159. return handleMsgNoteOff(plugin, argc, argv, types);
  160. // Send all other methods to plugins, TODO
  161. plugin->handleOscMessage(method, argc, argv, types, msg);
  162. return 0;
  163. }
  164. // -----------------------------------------------------------------------
  165. int CarlaEngineOsc::handleMsgRegister(const bool isTCP,
  166. const int argc, const lo_arg* const* const argv, const char* const types)
  167. {
  168. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  169. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  170. const char* const url = &argv[0]->s;
  171. const lo_address addr = lo_address_new_from_url(url);
  172. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  173. if (oscData.owner != nullptr)
  174. {
  175. carla_stderr("OSC backend already registered to %s", oscData.owner);
  176. char* const path = lo_url_get_path(url);
  177. char targetPath[std::strlen(path)+18];
  178. std::strcpy(targetPath, path);
  179. std::strcat(targetPath, "/exit-error");
  180. lo_send_from(addr, isTCP ? fServerTCP : fServerUDP, LO_TT_IMMEDIATE,
  181. targetPath, "s", "OSC already registered to another client");
  182. free(path);
  183. }
  184. else
  185. {
  186. carla_stdout("OSC backend registered to %s", url);
  187. const char* const host = lo_address_get_hostname(addr);
  188. const char* const port = lo_address_get_port(addr);
  189. const lo_address target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  190. oscData.owner = carla_strdup_safe(url);
  191. oscData.path = carla_strdup_free(lo_url_get_path(url));
  192. oscData.target = target;
  193. if (isTCP)
  194. {
  195. const EngineOptions& opts(fEngine->getOptions());
  196. fEngine->callback(false, true,
  197. ENGINE_CALLBACK_ENGINE_STARTED,
  198. fEngine->getCurrentPluginCount(),
  199. opts.processMode,
  200. opts.transportMode,
  201. static_cast<int>(fEngine->getBufferSize()),
  202. static_cast<float>(fEngine->getSampleRate()),
  203. fEngine->getCurrentDriverName());
  204. for (uint i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  205. {
  206. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  207. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
  208. fEngine->callback(false, true, ENGINE_CALLBACK_PLUGIN_ADDED, i, 0, 0, 0, 0.0f, plugin->getName());
  209. }
  210. fEngine->patchbayRefresh(false, true, fEngine->pData->graph.isUsingExternalOSC());
  211. }
  212. }
  213. lo_address_free(addr);
  214. return 0;
  215. }
  216. int CarlaEngineOsc::handleMsgUnregister(const bool isTCP,
  217. const int argc, const lo_arg* const* const argv, const char* const types)
  218. {
  219. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  220. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  221. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  222. if (oscData.owner == nullptr)
  223. {
  224. carla_stderr("OSC backend is not registered yet, unregister failed");
  225. return 0;
  226. }
  227. const char* const url = &argv[0]->s;
  228. if (std::strcmp(oscData.owner, url) == 0)
  229. {
  230. carla_stdout("OSC client %s unregistered", url);
  231. oscData.clear();
  232. return 0;
  233. }
  234. carla_stderr("OSC backend unregister failed, current owner %s does not match requested %s", oscData.owner, url);
  235. return 0;
  236. }
  237. int CarlaEngineOsc::handleMsgControl(const char* const method,
  238. const int argc, const lo_arg* const* const argv, const char* const types)
  239. {
  240. carla_debug("CarlaEngineOsc::handleMsgControl()");
  241. CARLA_SAFE_ASSERT_RETURN(method != nullptr && method[0] != '\0', 0);
  242. CARLA_SAFE_ASSERT_RETURN(types != nullptr, 0);
  243. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  244. if (fControlDataTCP.owner == nullptr)
  245. {
  246. carla_stderr("OSC backend is not registered yet, control failed");
  247. return 0;
  248. }
  249. const int32_t messageId = argv[0]->i;
  250. bool ok;
  251. #define CARLA_SAFE_ASSERT_RETURN_OSC_ERR(cond) \
  252. if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); sendResponse(messageId, #cond); return 0; }
  253. /**/ if (std::strcmp(method, "clear_engine_xruns") == 0)
  254. {
  255. ok = true;
  256. fEngine->clearXruns();
  257. }
  258. else if (std::strcmp(method, "cancel_engine_action") == 0)
  259. {
  260. ok = true;
  261. fEngine->setActionCanceled(true);
  262. }
  263. else if (std::strcmp(method, "patchbay_connect") == 0)
  264. {
  265. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 6);
  266. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  267. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  268. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  269. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  270. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  271. const bool external = argv[1]->i != 0;
  272. const int32_t groupA = argv[2]->i;
  273. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupA >= 0);
  274. const int32_t portA = argv[3]->i;
  275. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portA >= 0);
  276. const int32_t groupB = argv[4]->i;
  277. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupB >= 0);
  278. const int32_t portB = argv[5]->i;
  279. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portB >= 0);
  280. ok = fEngine->patchbayConnect(external,
  281. static_cast<uint32_t>(groupA),
  282. static_cast<uint32_t>(portA),
  283. static_cast<uint32_t>(groupB),
  284. static_cast<uint32_t>(portB));
  285. }
  286. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  287. {
  288. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  289. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  290. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  291. const bool external = argv[1]->i != 0;
  292. const int32_t connectionId = argv[2]->i;
  293. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(connectionId >= 0);
  294. ok = fEngine->patchbayDisconnect(external, static_cast<uint32_t>(connectionId));
  295. }
  296. else if (std::strcmp(method, "patchbay_refresh") == 0)
  297. {
  298. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  299. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  300. const bool external = argv[1]->i != 0;
  301. ok = fEngine->patchbayRefresh(false, true, external);
  302. }
  303. else if (std::strcmp(method, "transport_play") == 0)
  304. {
  305. ok = true;
  306. fEngine->transportPlay();
  307. }
  308. else if (std::strcmp(method, "transport_pause") == 0)
  309. {
  310. ok = true;
  311. fEngine->transportPause();
  312. }
  313. else if (std::strcmp(method, "transport_bpm") == 0)
  314. {
  315. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  316. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f');
  317. const double bpm = argv[1]->f;
  318. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0);
  319. ok = true;
  320. fEngine->transportBPM(bpm);
  321. }
  322. else if (std::strcmp(method, "transport_relocate") == 0)
  323. {
  324. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  325. uint64_t frame;
  326. /**/ if (types[1] == 'i')
  327. {
  328. const int32_t i = argv[1]->i;
  329. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0);
  330. frame = static_cast<uint64_t>(i);
  331. }
  332. else if (types[1] == 'h')
  333. {
  334. const int64_t h = argv[1]->h;
  335. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0);
  336. frame = static_cast<uint64_t>(h);
  337. }
  338. else
  339. {
  340. carla_stderr2("Wrong OSC type used for '%s'", method);
  341. sendResponse(messageId, "Wrong OSC type");
  342. return 0;
  343. }
  344. ok = true;
  345. fEngine->transportRelocate(frame);
  346. }
  347. else if (std::strcmp(method, "add_plugin") == 0)
  348. {
  349. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8);
  350. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  351. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  352. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's');
  353. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's');
  354. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's');
  355. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i');
  356. int32_t btype = argv[1]->i;
  357. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0);
  358. const int32_t ptype = argv[2]->i;
  359. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0);
  360. // Force binary type to be native in some cases
  361. switch (ptype)
  362. {
  363. case PLUGIN_INTERNAL:
  364. case PLUGIN_LV2:
  365. case PLUGIN_SF2:
  366. case PLUGIN_SFZ:
  367. case PLUGIN_JACK:
  368. btype = BINARY_NATIVE;
  369. break;
  370. }
  371. const char* filename = &argv[3]->s;
  372. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  373. filename = nullptr;
  374. const char* name = &argv[4]->s;
  375. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  376. name = nullptr;
  377. const char* const label = &argv[5]->s;
  378. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0');
  379. int64_t uniqueId;
  380. /**/ if (types[6] == 'i')
  381. {
  382. uniqueId = argv[6]->i;
  383. }
  384. else if (types[6] == 'h')
  385. {
  386. uniqueId = argv[6]->h;
  387. }
  388. else
  389. {
  390. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  391. sendResponse(messageId, "Wrong OSC type");
  392. return 0;
  393. }
  394. const int32_t options = argv[7]->i;
  395. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0);
  396. ok = fEngine->addPlugin(static_cast<BinaryType>(btype),
  397. static_cast<PluginType>(ptype),
  398. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  399. }
  400. else if (std::strcmp(method, "remove_plugin") == 0)
  401. {
  402. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  403. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  404. const int32_t id = argv[1]->i;
  405. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  406. ok = fEngine->removePlugin(static_cast<uint32_t>(id));
  407. }
  408. else if (std::strcmp(method, "remove_all_plugins") == 0)
  409. {
  410. ok = fEngine->removeAllPlugins();
  411. }
  412. else if (std::strcmp(method, "rename_plugin") == 0)
  413. {
  414. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  415. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  416. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's');
  417. const int32_t id = argv[1]->i;
  418. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  419. const char* const newName = &argv[2]->s;
  420. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0');
  421. ok = fEngine->renamePlugin(static_cast<uint32_t>(id), newName);
  422. }
  423. else if (std::strcmp(method, "clone_plugin") == 0)
  424. {
  425. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  426. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  427. const int32_t id = argv[1]->i;
  428. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  429. ok = fEngine->clonePlugin(static_cast<uint32_t>(id));
  430. }
  431. else if (std::strcmp(method, "replace_plugin") == 0)
  432. {
  433. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  434. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  435. const int32_t id = argv[1]->i;
  436. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  437. ok = fEngine->replacePlugin(static_cast<uint32_t>(id));
  438. }
  439. else if (std::strcmp(method, "switch_plugins") == 0)
  440. {
  441. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  442. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  443. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  444. const int32_t idA = argv[1]->i;
  445. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0);
  446. const int32_t idB = argv[2]->i;
  447. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0);
  448. ok = fEngine->switchPlugins(static_cast<uint32_t>(idA), static_cast<uint32_t>(idB));
  449. }
  450. else
  451. {
  452. carla_stderr2("Unhandled OSC control for '%s'", method);
  453. sendResponse(messageId, "Unhandled OSC control method");
  454. return 0;
  455. }
  456. #undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR
  457. sendResponse(messageId, ok ? "" : fEngine->getLastError());
  458. return 0;
  459. }
  460. // -----------------------------------------------------------------------
  461. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  462. {
  463. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  464. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  465. const bool active = (argv[0]->i != 0);
  466. plugin->setActive(active, false, true);
  467. return 0;
  468. }
  469. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  470. {
  471. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  472. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  473. const float value = argv[0]->f;
  474. plugin->setDryWet(value, false, true);
  475. return 0;
  476. }
  477. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  478. {
  479. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  480. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  481. const float value = argv[0]->f;
  482. plugin->setVolume(value, false, true);
  483. return 0;
  484. }
  485. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  486. {
  487. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  488. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  489. const float value = argv[0]->f;
  490. plugin->setBalanceLeft(value, false, true);
  491. return 0;
  492. }
  493. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  494. {
  495. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  496. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  497. const float value = argv[0]->f;
  498. plugin->setBalanceRight(value, false, true);
  499. return 0;
  500. }
  501. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  502. {
  503. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  504. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  505. const float value = argv[0]->f;
  506. plugin->setPanning(value, false, true);
  507. return 0;
  508. }
  509. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  510. {
  511. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  512. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  513. const int32_t index = argv[0]->i;
  514. const float value = argv[1]->f;
  515. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  516. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  517. return 0;
  518. }
  519. int CarlaEngineOsc::handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS)
  520. {
  521. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedIndex()");
  522. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  523. const int32_t index = argv[0]->i;
  524. const int32_t ctrl = argv[1]->i;
  525. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  526. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, 0);
  527. plugin->setParameterMappedControlIndex(static_cast<uint32_t>(index), static_cast<int16_t>(ctrl), false, true);
  528. return 0;
  529. }
  530. int CarlaEngineOsc::handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS)
  531. {
  532. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedRange()");
  533. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "iff");
  534. const int32_t index = argv[0]->i;
  535. const float minimum = argv[1]->f;
  536. const float maximum = argv[2]->f;
  537. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  538. plugin->setParameterMappedRange(static_cast<uint32_t>(index), minimum, maximum, false, true);
  539. return 0;
  540. }
  541. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  542. {
  543. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  544. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  545. const int32_t index = argv[0]->i;
  546. const int32_t channel = argv[1]->i;
  547. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  548. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  549. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  550. return 0;
  551. }
  552. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  553. {
  554. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  555. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  556. const int32_t index = argv[0]->i;
  557. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  558. plugin->setProgram(index, true, false, true);
  559. return 0;
  560. }
  561. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  562. {
  563. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  564. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  565. const int32_t index = argv[0]->i;
  566. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  567. plugin->setMidiProgram(index, true, false, true);
  568. return 0;
  569. }
  570. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  571. {
  572. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  573. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  574. const int32_t channel = argv[0]->i;
  575. const int32_t note = argv[1]->i;
  576. const int32_t velo = argv[2]->i;
  577. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  578. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  579. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  580. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  581. return 0;
  582. }
  583. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  584. {
  585. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  586. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  587. const int32_t channel = argv[0]->i;
  588. const int32_t note = argv[1]->i;
  589. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  590. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  591. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  592. return 0;
  593. }
  594. // -----------------------------------------------------------------------
  595. CARLA_BACKEND_END_NAMESPACE
  596. #endif // HAVE_LIBLO