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.

803 lines
27KB

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