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.

768 lines
26KB

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