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.

762 lines
25KB

  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. const CarlaPluginPtr 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. const CarlaPluginPtr 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_set_group_pos") == 0)
  297. {
  298. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 7);
  299. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  300. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  301. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  302. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  303. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  304. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[6] == 'i');
  305. const bool external = argv[1]->i != 0;
  306. const int32_t groupId = argv[2]->i;
  307. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupId >= 0);
  308. ok = fEngine->patchbaySetGroupPos(true, false,
  309. external, static_cast<uint32_t>(groupId),
  310. argv[3]->i, argv[4]->i, argv[5]->i, argv[6]->i);
  311. }
  312. else if (std::strcmp(method, "patchbay_refresh") == 0)
  313. {
  314. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  315. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  316. const bool external = argv[1]->i != 0;
  317. ok = fEngine->patchbayRefresh(false, true, external);
  318. }
  319. else if (std::strcmp(method, "transport_play") == 0)
  320. {
  321. ok = true;
  322. fEngine->transportPlay();
  323. }
  324. else if (std::strcmp(method, "transport_pause") == 0)
  325. {
  326. ok = true;
  327. fEngine->transportPause();
  328. }
  329. else if (std::strcmp(method, "transport_bpm") == 0)
  330. {
  331. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  332. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f');
  333. const double bpm = argv[1]->f;
  334. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0);
  335. ok = true;
  336. fEngine->transportBPM(bpm);
  337. }
  338. else if (std::strcmp(method, "transport_relocate") == 0)
  339. {
  340. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  341. uint64_t frame;
  342. /**/ if (types[1] == 'i')
  343. {
  344. const int32_t i = argv[1]->i;
  345. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0);
  346. frame = static_cast<uint64_t>(i);
  347. }
  348. else if (types[1] == 'h')
  349. {
  350. const int64_t h = argv[1]->h;
  351. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0);
  352. frame = static_cast<uint64_t>(h);
  353. }
  354. else
  355. {
  356. carla_stderr2("Wrong OSC type used for '%s'", method);
  357. sendResponse(messageId, "Wrong OSC type");
  358. return 0;
  359. }
  360. ok = true;
  361. fEngine->transportRelocate(frame);
  362. }
  363. else if (std::strcmp(method, "add_plugin") == 0)
  364. {
  365. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8);
  366. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  367. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  368. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's');
  369. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's');
  370. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's');
  371. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i');
  372. int32_t btype = argv[1]->i;
  373. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0);
  374. const int32_t ptype = argv[2]->i;
  375. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0);
  376. // Force binary type to be native in some cases
  377. switch (ptype)
  378. {
  379. case PLUGIN_INTERNAL:
  380. case PLUGIN_LV2:
  381. case PLUGIN_SF2:
  382. case PLUGIN_SFZ:
  383. case PLUGIN_JACK:
  384. btype = BINARY_NATIVE;
  385. break;
  386. }
  387. const char* filename = &argv[3]->s;
  388. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  389. filename = nullptr;
  390. const char* name = &argv[4]->s;
  391. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  392. name = nullptr;
  393. const char* const label = &argv[5]->s;
  394. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0');
  395. int64_t uniqueId;
  396. /**/ if (types[6] == 'i')
  397. {
  398. uniqueId = argv[6]->i;
  399. }
  400. else if (types[6] == 'h')
  401. {
  402. uniqueId = argv[6]->h;
  403. }
  404. else
  405. {
  406. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  407. sendResponse(messageId, "Wrong OSC type");
  408. return 0;
  409. }
  410. const int32_t options = argv[7]->i;
  411. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0);
  412. ok = fEngine->addPlugin(static_cast<BinaryType>(btype),
  413. static_cast<PluginType>(ptype),
  414. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  415. }
  416. else if (std::strcmp(method, "remove_plugin") == 0)
  417. {
  418. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  419. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  420. const int32_t id = argv[1]->i;
  421. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  422. ok = fEngine->removePlugin(static_cast<uint32_t>(id));
  423. }
  424. else if (std::strcmp(method, "remove_all_plugins") == 0)
  425. {
  426. ok = fEngine->removeAllPlugins();
  427. }
  428. else if (std::strcmp(method, "rename_plugin") == 0)
  429. {
  430. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  431. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  432. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's');
  433. const int32_t id = argv[1]->i;
  434. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  435. const char* const newName = &argv[2]->s;
  436. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0');
  437. ok = fEngine->renamePlugin(static_cast<uint32_t>(id), newName);
  438. }
  439. else if (std::strcmp(method, "clone_plugin") == 0)
  440. {
  441. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  442. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  443. const int32_t id = argv[1]->i;
  444. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  445. ok = fEngine->clonePlugin(static_cast<uint32_t>(id));
  446. }
  447. else if (std::strcmp(method, "replace_plugin") == 0)
  448. {
  449. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  450. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  451. const int32_t id = argv[1]->i;
  452. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  453. ok = fEngine->replacePlugin(static_cast<uint32_t>(id));
  454. }
  455. else if (std::strcmp(method, "switch_plugins") == 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] == 'i');
  460. const int32_t idA = argv[1]->i;
  461. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0);
  462. const int32_t idB = argv[2]->i;
  463. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0);
  464. ok = fEngine->switchPlugins(static_cast<uint32_t>(idA), static_cast<uint32_t>(idB));
  465. }
  466. else
  467. {
  468. carla_stderr2("Unhandled OSC control for '%s'", method);
  469. sendResponse(messageId, "Unhandled OSC control method");
  470. return 0;
  471. }
  472. #undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR
  473. sendResponse(messageId, ok ? "" : fEngine->getLastError());
  474. return 0;
  475. }
  476. // -----------------------------------------------------------------------
  477. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  478. {
  479. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  480. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  481. const bool active = (argv[0]->i != 0);
  482. plugin->setActive(active, false, true);
  483. return 0;
  484. }
  485. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  486. {
  487. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  488. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  489. const float value = argv[0]->f;
  490. plugin->setDryWet(value, false, true);
  491. return 0;
  492. }
  493. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  494. {
  495. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  496. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  497. const float value = argv[0]->f;
  498. plugin->setVolume(value, false, true);
  499. return 0;
  500. }
  501. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  502. {
  503. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  504. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  505. const float value = argv[0]->f;
  506. plugin->setBalanceLeft(value, false, true);
  507. return 0;
  508. }
  509. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  510. {
  511. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  512. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  513. const float value = argv[0]->f;
  514. plugin->setBalanceRight(value, false, true);
  515. return 0;
  516. }
  517. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  518. {
  519. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  520. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  521. const float value = argv[0]->f;
  522. plugin->setPanning(value, false, true);
  523. return 0;
  524. }
  525. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  526. {
  527. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  528. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  529. const int32_t index = argv[0]->i;
  530. const float value = argv[1]->f;
  531. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  532. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  533. return 0;
  534. }
  535. int CarlaEngineOsc::handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS)
  536. {
  537. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedIndex()");
  538. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  539. const int32_t index = argv[0]->i;
  540. const int32_t ctrl = argv[1]->i;
  541. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  542. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, 0);
  543. plugin->setParameterMappedControlIndex(static_cast<uint32_t>(index), static_cast<int16_t>(ctrl), false, true);
  544. return 0;
  545. }
  546. int CarlaEngineOsc::handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS)
  547. {
  548. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedRange()");
  549. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "iff");
  550. const int32_t index = argv[0]->i;
  551. const float minimum = argv[1]->f;
  552. const float maximum = argv[2]->f;
  553. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  554. plugin->setParameterMappedRange(static_cast<uint32_t>(index), minimum, maximum, false, true);
  555. return 0;
  556. }
  557. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  558. {
  559. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  560. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  561. const int32_t index = argv[0]->i;
  562. const int32_t channel = argv[1]->i;
  563. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  564. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  565. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  566. return 0;
  567. }
  568. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  569. {
  570. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  571. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  572. const int32_t index = argv[0]->i;
  573. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  574. plugin->setProgram(index, true, false, true);
  575. return 0;
  576. }
  577. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  578. {
  579. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  580. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  581. const int32_t index = argv[0]->i;
  582. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  583. plugin->setMidiProgram(index, true, false, true);
  584. return 0;
  585. }
  586. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  587. {
  588. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  589. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  590. const int32_t channel = argv[0]->i;
  591. const int32_t note = argv[1]->i;
  592. const int32_t velo = argv[2]->i;
  593. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  594. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  595. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  596. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  597. return 0;
  598. }
  599. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  600. {
  601. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  602. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  603. const int32_t channel = argv[0]->i;
  604. const int32_t note = argv[1]->i;
  605. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  606. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  607. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  608. return 0;
  609. }
  610. // -----------------------------------------------------------------------
  611. CARLA_BACKEND_END_NAMESPACE
  612. #endif // HAVE_LIBLO