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

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