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 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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,
  26. const int argc, const lo_arg* const* const argv, const char* const types,
  27. const lo_message msg)
  28. {
  29. CARLA_SAFE_ASSERT_RETURN(fName.isNotEmpty(), 1);
  30. CARLA_SAFE_ASSERT_RETURN(path != nullptr && path[0] != '\0', 1);
  31. CARLA_SAFE_ASSERT_RETURN(path[0] == '/', 1);
  32. #ifdef DEBUG
  33. if (std::strncmp(path, "/bridge_pong", 12) != 0) {
  34. carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)",
  35. bool2str(isTCP), path, argc, argv, types, msg);
  36. }
  37. #endif
  38. if (isTCP)
  39. {
  40. CARLA_SAFE_ASSERT_RETURN(fServerPathTCP.isNotEmpty(), 1);
  41. CARLA_SAFE_ASSERT_RETURN(fServerTCP != nullptr, 1);
  42. }
  43. else
  44. {
  45. CARLA_SAFE_ASSERT_RETURN(fServerPathUDP.isNotEmpty(), 1);
  46. CARLA_SAFE_ASSERT_RETURN(fServerUDP != nullptr, 1);
  47. }
  48. const lo_address source = lo_message_get_source(msg);
  49. // Initial path check
  50. if (std::strcmp(path, "/register") == 0)
  51. return handleMsgRegister(isTCP, argc, argv, types, source);
  52. if (std::strcmp(path, "/unregister") == 0)
  53. return handleMsgUnregister(isTCP, argc, argv, types);
  54. if (std::strncmp(path, "/ctrl/", 6) == 0)
  55. {
  56. CARLA_SAFE_ASSERT_RETURN(isTCP, 1);
  57. return handleMsgControl(path + 6, argc, argv, types);
  58. }
  59. // Check if message is for this client
  60. std::size_t bytesAfterName;
  61. if (fControlDataTCP.owner != nullptr && std::strcmp(lo_address_get_hostname(source), fControlDataTCP.owner) == 0)
  62. {
  63. if (const char* const slash = std::strchr(path+1, '/'))
  64. {
  65. bytesAfterName = static_cast<std::size_t>(slash - path);
  66. }
  67. else
  68. {
  69. carla_stderr("CarlaEngineOsc::handleMessage() - message '%s' is invalid", path);
  70. return 1;
  71. }
  72. }
  73. else
  74. {
  75. bytesAfterName = fName.length();
  76. if (std::strlen(path) <= bytesAfterName || std::strncmp(path+1, fName, bytesAfterName) != 0)
  77. {
  78. carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'",
  79. path, fName.buffer());
  80. return 1;
  81. }
  82. ++bytesAfterName;
  83. }
  84. // Get plugin id from path, "/carla/23/method" -> 23
  85. uint pluginId = 0;
  86. std::size_t offset;
  87. if (! std::isdigit(path[bytesAfterName+1]))
  88. {
  89. carla_stderr("CarlaEngineOsc::handleMessage() - invalid message '%s'", path);
  90. return 1;
  91. }
  92. if (std::isdigit(path[bytesAfterName+2]))
  93. {
  94. if (std::isdigit(path[bytesAfterName+4]))
  95. {
  96. carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")",
  97. path+bytesAfterName);
  98. return 1;
  99. }
  100. else if (std::isdigit(path[bytesAfterName+3]))
  101. {
  102. // 3 digits, /xyz/method
  103. offset = 5;
  104. pluginId += uint(path[bytesAfterName+1]-'0')*100;
  105. pluginId += uint(path[bytesAfterName+2]-'0')*10;
  106. pluginId += uint(path[bytesAfterName+3]-'0');
  107. }
  108. else
  109. {
  110. // 2 digits, /xy/method
  111. offset = 4;
  112. pluginId += uint(path[bytesAfterName+1]-'0')*10;
  113. pluginId += uint(path[bytesAfterName+2]-'0');
  114. }
  115. }
  116. else
  117. {
  118. // single digit, /x/method
  119. offset = 3;
  120. pluginId += uint(path[bytesAfterName+1]-'0');
  121. }
  122. if (pluginId > fEngine->getCurrentPluginCount())
  123. {
  124. carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId);
  125. return 0;
  126. }
  127. // Get plugin
  128. const CarlaPluginPtr plugin = fEngine->getPluginUnchecked(pluginId);
  129. if (plugin == nullptr || plugin->getId() != pluginId)
  130. {
  131. carla_stderr("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed (path: '%s')", pluginId, path);
  132. return 0;
  133. }
  134. // Get method from path, "/Carla/i/method" -> "method"
  135. char method[48];
  136. std::strncpy(method, path + (bytesAfterName + offset), 47);
  137. method[47] = '\0';
  138. if (method[0] == '\0')
  139. {
  140. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message without method", bool2str(isTCP), path);
  141. return 0;
  142. }
  143. // Internal methods
  144. if (std::strcmp(method, "set_option") == 0)
  145. return 0; //handleMsgSetOption(plugin, argc, argv, types); // TODO
  146. if (std::strcmp(method, "set_active") == 0)
  147. return handleMsgSetActive(plugin, argc, argv, types);
  148. if (std::strcmp(method, "set_drywet") == 0)
  149. return handleMsgSetDryWet(plugin, argc, argv, types);
  150. if (std::strcmp(method, "set_volume") == 0)
  151. return handleMsgSetVolume(plugin, argc, argv, types);
  152. if (std::strcmp(method, "set_balance_left") == 0)
  153. return handleMsgSetBalanceLeft(plugin, argc, argv, types);
  154. if (std::strcmp(method, "set_balance_right") == 0)
  155. return handleMsgSetBalanceRight(plugin, argc, argv, types);
  156. if (std::strcmp(method, "set_panning") == 0)
  157. return handleMsgSetPanning(plugin, argc, argv, types);
  158. if (std::strcmp(method, "set_ctrl_channel") == 0)
  159. return 0; //handleMsgSetControlChannel(plugin, argc, argv, types); // TODO
  160. if (std::strcmp(method, "set_parameter_value") == 0)
  161. return handleMsgSetParameterValue(plugin, argc, argv, types);
  162. if (std::strcmp(method, "set_parameter_mapped_control_index") == 0)
  163. return handleMsgSetParameterMappedControlIndex(plugin, argc, argv, types);
  164. if (std::strcmp(method, "set_parameter_mapped_range") == 0)
  165. return handleMsgSetParameterMappedRange(plugin, argc, argv, types);
  166. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  167. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  168. if (std::strcmp(method, "set_program") == 0)
  169. return handleMsgSetProgram(plugin, argc, argv, types);
  170. if (std::strcmp(method, "set_midi_program") == 0)
  171. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  172. if (std::strcmp(method, "set_custom_data") == 0)
  173. return 0; //handleMsgSetCustomData(plugin, argc, argv, types); // TODO
  174. if (std::strcmp(method, "set_chunk") == 0)
  175. return 0; //handleMsgSetChunk(plugin, argc, argv, types); // TODO
  176. if (std::strcmp(method, "note_on") == 0)
  177. return handleMsgNoteOn(plugin, argc, argv, types);
  178. if (std::strcmp(method, "note_off") == 0)
  179. return handleMsgNoteOff(plugin, argc, argv, types);
  180. // Send all other methods to plugins, TODO
  181. plugin->handleOscMessage(method, argc, argv, types, msg);
  182. return 0;
  183. }
  184. // -----------------------------------------------------------------------
  185. int CarlaEngineOsc::handleMsgRegister(const bool isTCP,
  186. const int argc, const lo_arg* const* const argv, const char* const types,
  187. const lo_address source)
  188. {
  189. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  190. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  191. const char* const url = &argv[0]->s;
  192. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  193. if (oscData.owner != nullptr)
  194. {
  195. carla_stderr("OSC backend already registered to %s", oscData.owner);
  196. char* const path = lo_url_get_path(url);
  197. const size_t pathlen = std::strlen(path);
  198. CARLA_SAFE_ASSERT_RETURN(pathlen < 32, 0);
  199. char targetPath[pathlen+12];
  200. std::strcpy(targetPath, path);
  201. std::strcat(targetPath, "/exit-error");
  202. lo_send_from(source, isTCP ? fServerTCP : fServerUDP, LO_TT_IMMEDIATE,
  203. targetPath, "s", "OSC already registered to another client");
  204. free(path);
  205. }
  206. else
  207. {
  208. const char* const host = lo_address_get_hostname(source);
  209. /* */ char* const port = lo_url_get_port(url); // NOTE: lo_address_get_port is buggy against TCP
  210. const lo_address target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  211. oscData.owner = carla_strdup_safe(host);
  212. oscData.path = carla_strdup_free(lo_url_get_path(url));
  213. oscData.target = target;
  214. char* const targeturl = lo_address_get_url(target);
  215. carla_stdout("OSC %s backend registered to %s, path: %s, target: %s (host: %s, port: %s)",
  216. isTCP ? "TCP" : "UDP", url, oscData.path, targeturl, host, port);
  217. free(targeturl);
  218. free(port);
  219. if (isTCP)
  220. {
  221. const EngineOptions& opts(fEngine->getOptions());
  222. fEngine->callback(false, true,
  223. ENGINE_CALLBACK_ENGINE_STARTED,
  224. fEngine->getCurrentPluginCount(),
  225. opts.processMode,
  226. opts.transportMode,
  227. static_cast<int>(fEngine->getBufferSize()),
  228. static_cast<float>(fEngine->getSampleRate()),
  229. fEngine->getCurrentDriverName());
  230. for (uint i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  231. {
  232. const CarlaPluginPtr plugin = fEngine->getPluginUnchecked(i);
  233. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
  234. fEngine->callback(false, true, ENGINE_CALLBACK_PLUGIN_ADDED, i, 0, 0, 0, 0.0f, plugin->getName());
  235. }
  236. fEngine->patchbayRefresh(false, true, fEngine->pData->graph.isUsingExternalOSC());
  237. }
  238. }
  239. return 0;
  240. }
  241. int CarlaEngineOsc::handleMsgUnregister(const bool isTCP,
  242. const int argc, const lo_arg* const* const argv, const char* const types)
  243. {
  244. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  245. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  246. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  247. if (oscData.owner == nullptr)
  248. {
  249. carla_stderr("OSC backend is not registered yet, unregister failed");
  250. return 0;
  251. }
  252. const char* const url = &argv[0]->s;
  253. if (std::strcmp(oscData.owner, url) == 0)
  254. {
  255. carla_stdout("OSC client %s unregistered", url);
  256. oscData.clear();
  257. return 0;
  258. }
  259. carla_stderr("OSC backend unregister failed, current owner %s does not match requested %s", oscData.owner, url);
  260. return 0;
  261. }
  262. int CarlaEngineOsc::handleMsgControl(const char* const method,
  263. const int argc, const lo_arg* const* const argv, const char* const types)
  264. {
  265. carla_debug("CarlaEngineOsc::handleMsgControl()");
  266. CARLA_SAFE_ASSERT_RETURN(method != nullptr && method[0] != '\0', 0);
  267. CARLA_SAFE_ASSERT_RETURN(types != nullptr, 0);
  268. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  269. if (fControlDataTCP.owner == nullptr)
  270. {
  271. carla_stderr("OSC backend is not registered yet, control failed");
  272. return 0;
  273. }
  274. const int32_t messageId = argv[0]->i;
  275. bool ok;
  276. #define CARLA_SAFE_ASSERT_RETURN_OSC_ERR(cond) \
  277. if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); sendResponse(messageId, #cond); return 0; }
  278. /**/ if (std::strcmp(method, "clear_engine_xruns") == 0)
  279. {
  280. ok = true;
  281. fEngine->clearXruns();
  282. }
  283. else if (std::strcmp(method, "cancel_engine_action") == 0)
  284. {
  285. ok = true;
  286. fEngine->setActionCanceled(true);
  287. }
  288. else if (std::strcmp(method, "patchbay_connect") == 0)
  289. {
  290. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 6);
  291. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  292. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  293. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  294. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  295. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  296. const bool external = argv[1]->i != 0;
  297. const int32_t groupA = argv[2]->i;
  298. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupA >= 0);
  299. const int32_t portA = argv[3]->i;
  300. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portA >= 0);
  301. const int32_t groupB = argv[4]->i;
  302. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupB >= 0);
  303. const int32_t portB = argv[5]->i;
  304. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portB >= 0);
  305. ok = fEngine->patchbayConnect(external,
  306. static_cast<uint32_t>(groupA),
  307. static_cast<uint32_t>(portA),
  308. static_cast<uint32_t>(groupB),
  309. static_cast<uint32_t>(portB));
  310. }
  311. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  312. {
  313. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  314. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  315. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  316. const bool external = argv[1]->i != 0;
  317. const int32_t connectionId = argv[2]->i;
  318. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(connectionId >= 0);
  319. ok = fEngine->patchbayDisconnect(external, static_cast<uint32_t>(connectionId));
  320. }
  321. else if (std::strcmp(method, "patchbay_set_group_pos") == 0)
  322. {
  323. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 7);
  324. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  325. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  326. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  327. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  328. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  329. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[6] == 'i');
  330. const bool external = argv[1]->i != 0;
  331. const int32_t groupId = argv[2]->i;
  332. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupId >= 0);
  333. ok = fEngine->patchbaySetGroupPos(true, false,
  334. external, static_cast<uint32_t>(groupId),
  335. argv[3]->i, argv[4]->i, argv[5]->i, argv[6]->i);
  336. }
  337. else if (std::strcmp(method, "patchbay_refresh") == 0)
  338. {
  339. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  340. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  341. const bool external = argv[1]->i != 0;
  342. ok = fEngine->patchbayRefresh(false, true, external);
  343. }
  344. else if (std::strcmp(method, "transport_play") == 0)
  345. {
  346. ok = true;
  347. fEngine->transportPlay();
  348. }
  349. else if (std::strcmp(method, "transport_pause") == 0)
  350. {
  351. ok = true;
  352. fEngine->transportPause();
  353. }
  354. else if (std::strcmp(method, "transport_bpm") == 0)
  355. {
  356. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  357. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f');
  358. const double bpm = argv[1]->f;
  359. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0);
  360. ok = true;
  361. fEngine->transportBPM(bpm);
  362. }
  363. else if (std::strcmp(method, "transport_relocate") == 0)
  364. {
  365. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  366. uint64_t frame;
  367. /**/ if (types[1] == 'i')
  368. {
  369. const int32_t i = argv[1]->i;
  370. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0);
  371. frame = static_cast<uint64_t>(i);
  372. }
  373. else if (types[1] == 'h')
  374. {
  375. const int64_t h = argv[1]->h;
  376. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0);
  377. frame = static_cast<uint64_t>(h);
  378. }
  379. else
  380. {
  381. carla_stderr2("Wrong OSC type used for '%s'", method);
  382. sendResponse(messageId, "Wrong OSC type");
  383. return 0;
  384. }
  385. ok = true;
  386. fEngine->transportRelocate(frame);
  387. }
  388. else if (std::strcmp(method, "add_plugin") == 0)
  389. {
  390. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8);
  391. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  392. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  393. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's');
  394. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's');
  395. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's');
  396. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i');
  397. int32_t btype = argv[1]->i;
  398. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0);
  399. const int32_t ptype = argv[2]->i;
  400. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0);
  401. // Force binary type to be native in some cases
  402. switch (ptype)
  403. {
  404. case PLUGIN_INTERNAL:
  405. case PLUGIN_LV2:
  406. case PLUGIN_SF2:
  407. case PLUGIN_SFZ:
  408. case PLUGIN_JACK:
  409. btype = BINARY_NATIVE;
  410. break;
  411. }
  412. const char* filename = &argv[3]->s;
  413. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  414. filename = nullptr;
  415. const char* name = &argv[4]->s;
  416. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  417. name = nullptr;
  418. const char* const label = &argv[5]->s;
  419. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0');
  420. int64_t uniqueId;
  421. /**/ if (types[6] == 'i')
  422. {
  423. uniqueId = argv[6]->i;
  424. }
  425. else if (types[6] == 'h')
  426. {
  427. uniqueId = argv[6]->h;
  428. }
  429. else
  430. {
  431. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  432. sendResponse(messageId, "Wrong OSC type");
  433. return 0;
  434. }
  435. const int32_t options = argv[7]->i;
  436. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0);
  437. ok = fEngine->addPlugin(static_cast<BinaryType>(btype),
  438. static_cast<PluginType>(ptype),
  439. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  440. }
  441. else if (std::strcmp(method, "remove_plugin") == 0)
  442. {
  443. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  444. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  445. const int32_t id = argv[1]->i;
  446. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  447. ok = fEngine->removePlugin(static_cast<uint32_t>(id));
  448. }
  449. else if (std::strcmp(method, "remove_all_plugins") == 0)
  450. {
  451. ok = fEngine->removeAllPlugins();
  452. }
  453. else if (std::strcmp(method, "rename_plugin") == 0)
  454. {
  455. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  456. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  457. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's');
  458. const int32_t id = argv[1]->i;
  459. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  460. const char* const newName = &argv[2]->s;
  461. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0');
  462. ok = fEngine->renamePlugin(static_cast<uint32_t>(id), newName);
  463. }
  464. else if (std::strcmp(method, "clone_plugin") == 0)
  465. {
  466. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  467. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  468. const int32_t id = argv[1]->i;
  469. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  470. ok = fEngine->clonePlugin(static_cast<uint32_t>(id));
  471. }
  472. else if (std::strcmp(method, "replace_plugin") == 0)
  473. {
  474. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  475. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  476. const int32_t id = argv[1]->i;
  477. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  478. ok = fEngine->replacePlugin(static_cast<uint32_t>(id));
  479. }
  480. else if (std::strcmp(method, "switch_plugins") == 0)
  481. {
  482. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  483. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  484. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  485. const int32_t idA = argv[1]->i;
  486. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0);
  487. const int32_t idB = argv[2]->i;
  488. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0);
  489. ok = fEngine->switchPlugins(static_cast<uint32_t>(idA), static_cast<uint32_t>(idB));
  490. }
  491. else
  492. {
  493. carla_stderr2("Unhandled OSC control for '%s'", method);
  494. sendResponse(messageId, "Unhandled OSC control method");
  495. return 0;
  496. }
  497. #undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR
  498. sendResponse(messageId, ok ? "" : fEngine->getLastError());
  499. return 0;
  500. }
  501. // -----------------------------------------------------------------------
  502. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  503. {
  504. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  505. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  506. const bool active = (argv[0]->i != 0);
  507. plugin->setActive(active, false, true);
  508. return 0;
  509. }
  510. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  511. {
  512. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  513. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  514. const float value = argv[0]->f;
  515. plugin->setDryWet(value, false, true);
  516. return 0;
  517. }
  518. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  519. {
  520. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  521. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  522. const float value = argv[0]->f;
  523. plugin->setVolume(value, false, true);
  524. return 0;
  525. }
  526. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  527. {
  528. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  529. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  530. const float value = argv[0]->f;
  531. plugin->setBalanceLeft(value, false, true);
  532. return 0;
  533. }
  534. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  535. {
  536. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  537. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  538. const float value = argv[0]->f;
  539. plugin->setBalanceRight(value, false, true);
  540. return 0;
  541. }
  542. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  543. {
  544. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  545. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  546. const float value = argv[0]->f;
  547. plugin->setPanning(value, false, true);
  548. return 0;
  549. }
  550. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  551. {
  552. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  553. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  554. const int32_t index = argv[0]->i;
  555. const float value = argv[1]->f;
  556. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  557. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  558. return 0;
  559. }
  560. int CarlaEngineOsc::handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS)
  561. {
  562. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedIndex()");
  563. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  564. const int32_t index = argv[0]->i;
  565. const int32_t ctrl = argv[1]->i;
  566. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  567. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, 0);
  568. plugin->setParameterMappedControlIndex(static_cast<uint32_t>(index), static_cast<int16_t>(ctrl), false, true, true);
  569. return 0;
  570. }
  571. int CarlaEngineOsc::handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS)
  572. {
  573. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedRange()");
  574. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "iff");
  575. const int32_t index = argv[0]->i;
  576. const float minimum = argv[1]->f;
  577. const float maximum = argv[2]->f;
  578. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  579. plugin->setParameterMappedRange(static_cast<uint32_t>(index), minimum, maximum, false, true);
  580. return 0;
  581. }
  582. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  583. {
  584. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  585. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  586. const int32_t index = argv[0]->i;
  587. const int32_t channel = argv[1]->i;
  588. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  589. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  590. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  591. return 0;
  592. }
  593. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  594. {
  595. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  596. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  597. const int32_t index = argv[0]->i;
  598. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  599. plugin->setProgram(index, true, false, true);
  600. return 0;
  601. }
  602. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  603. {
  604. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  605. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  606. const int32_t index = argv[0]->i;
  607. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  608. plugin->setMidiProgram(index, true, false, true);
  609. return 0;
  610. }
  611. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  612. {
  613. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  614. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  615. const int32_t channel = argv[0]->i;
  616. const int32_t note = argv[1]->i;
  617. const int32_t velo = argv[2]->i;
  618. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  619. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  620. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  621. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  622. return 0;
  623. }
  624. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  625. {
  626. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  627. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  628. const int32_t channel = argv[0]->i;
  629. const int32_t note = argv[1]->i;
  630. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  631. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  632. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  633. return 0;
  634. }
  635. // -----------------------------------------------------------------------
  636. CARLA_BACKEND_END_NAMESPACE
  637. #endif // HAVE_LIBLO