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.

816 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_forth") == 0)
  159. return handleMsgSetForth(plugin, argc, argv, types);
  160. if (std::strcmp(method, "set_ctrl_channel") == 0)
  161. return 0; //handleMsgSetControlChannel(plugin, argc, argv, types); // TODO
  162. if (std::strcmp(method, "set_parameter_value") == 0)
  163. return handleMsgSetParameterValue(plugin, argc, argv, types);
  164. if (std::strcmp(method, "set_parameter_mapped_control_index") == 0)
  165. return handleMsgSetParameterMappedControlIndex(plugin, argc, argv, types);
  166. if (std::strcmp(method, "set_parameter_mapped_range") == 0)
  167. return handleMsgSetParameterMappedRange(plugin, argc, argv, types);
  168. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  169. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  170. if (std::strcmp(method, "set_program") == 0)
  171. return handleMsgSetProgram(plugin, argc, argv, types);
  172. if (std::strcmp(method, "set_midi_program") == 0)
  173. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  174. if (std::strcmp(method, "set_custom_data") == 0)
  175. return 0; //handleMsgSetCustomData(plugin, argc, argv, types); // TODO
  176. if (std::strcmp(method, "set_chunk") == 0)
  177. return 0; //handleMsgSetChunk(plugin, argc, argv, types); // TODO
  178. if (std::strcmp(method, "note_on") == 0)
  179. return handleMsgNoteOn(plugin, argc, argv, types);
  180. if (std::strcmp(method, "note_off") == 0)
  181. return handleMsgNoteOff(plugin, argc, argv, types);
  182. // Send all other methods to plugins, TODO
  183. plugin->handleOscMessage(method, argc, argv, types, msg);
  184. return 0;
  185. }
  186. // -----------------------------------------------------------------------
  187. int CarlaEngineOsc::handleMsgRegister(const bool isTCP,
  188. const int argc, const lo_arg* const* const argv, const char* const types,
  189. const lo_address source)
  190. {
  191. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  192. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  193. const char* const url = &argv[0]->s;
  194. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  195. if (oscData.owner != nullptr)
  196. {
  197. carla_stderr("OSC backend already registered to %s", oscData.owner);
  198. char* const path = lo_url_get_path(url);
  199. const size_t pathlen = std::strlen(path);
  200. CARLA_SAFE_ASSERT_RETURN(pathlen < 32, 0);
  201. char targetPath[pathlen+12];
  202. std::strcpy(targetPath, path);
  203. std::strcat(targetPath, "/exit-error");
  204. lo_send_from(source, isTCP ? fServerTCP : fServerUDP, LO_TT_IMMEDIATE,
  205. targetPath, "s", "OSC already registered to another client");
  206. free(path);
  207. }
  208. else
  209. {
  210. const char* const host = lo_address_get_hostname(source);
  211. /* */ char* const port = lo_url_get_port(url); // NOTE: lo_address_get_port is buggy against TCP
  212. const lo_address target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  213. oscData.owner = carla_strdup_safe(host);
  214. oscData.path = carla_strdup_free(lo_url_get_path(url));
  215. oscData.target = target;
  216. char* const targeturl = lo_address_get_url(target);
  217. carla_stdout("OSC %s backend registered to %s, path: %s, target: %s (host: %s, port: %s)",
  218. isTCP ? "TCP" : "UDP", url, oscData.path, targeturl, host, port);
  219. free(targeturl);
  220. free(port);
  221. if (isTCP)
  222. {
  223. const EngineOptions& opts(fEngine->getOptions());
  224. fEngine->callback(false, true,
  225. ENGINE_CALLBACK_ENGINE_STARTED,
  226. fEngine->getCurrentPluginCount(),
  227. opts.processMode,
  228. opts.transportMode,
  229. static_cast<int>(fEngine->getBufferSize()),
  230. static_cast<float>(fEngine->getSampleRate()),
  231. fEngine->getCurrentDriverName());
  232. for (uint i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  233. {
  234. const CarlaPluginPtr plugin = fEngine->getPluginUnchecked(i);
  235. CARLA_SAFE_ASSERT_CONTINUE(plugin != nullptr);
  236. fEngine->callback(false, true, ENGINE_CALLBACK_PLUGIN_ADDED, i, plugin->getType(),
  237. 0, 0, 0.0f,
  238. plugin->getName());
  239. }
  240. fEngine->patchbayRefresh(false, true, fEngine->pData->graph.isUsingExternalOSC());
  241. }
  242. }
  243. return 0;
  244. }
  245. int CarlaEngineOsc::handleMsgUnregister(const bool isTCP,
  246. const int argc, const lo_arg* const* const argv, const char* const types,
  247. const lo_address source)
  248. {
  249. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  250. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  251. CarlaOscData& oscData(isTCP ? fControlDataTCP : fControlDataUDP);
  252. if (oscData.owner == nullptr)
  253. {
  254. carla_stderr("OSC backend is not registered yet, unregister failed");
  255. return 0;
  256. }
  257. const char* const url = &argv[0]->s;
  258. const char* const host = lo_address_get_hostname(source);
  259. const char* const path = lo_url_get_path(url);
  260. if (std::strcmp(oscData.owner, host) != 0)
  261. {
  262. carla_stderr("OSC backend unregister failed, current owner host %s does not match requested %s",
  263. oscData.owner, host);
  264. return 0;
  265. }
  266. if (std::strcmp(oscData.path, path) != 0)
  267. {
  268. carla_stderr("OSC backend unregister failed, current owner path %s does not match requested %s",
  269. oscData.path, path);
  270. return 0;
  271. }
  272. carla_stdout("OSC client %s unregistered", url);
  273. oscData.clear();
  274. return 0;
  275. }
  276. int CarlaEngineOsc::handleMsgControl(const char* const method,
  277. const int argc, const lo_arg* const* const argv, const char* const types)
  278. {
  279. carla_debug("CarlaEngineOsc::handleMsgControl()");
  280. CARLA_SAFE_ASSERT_RETURN(method != nullptr && method[0] != '\0', 0);
  281. CARLA_SAFE_ASSERT_RETURN(types != nullptr, 0);
  282. CARLA_SAFE_ASSERT_RETURN(types[0] == 'i', 0);
  283. if (fControlDataTCP.owner == nullptr)
  284. {
  285. carla_stderr("OSC backend is not registered yet, control failed");
  286. return 0;
  287. }
  288. const int32_t messageId = argv[0]->i;
  289. bool ok;
  290. #define CARLA_SAFE_ASSERT_RETURN_OSC_ERR(cond) \
  291. if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); sendResponse(messageId, #cond); return 0; }
  292. /**/ if (std::strcmp(method, "clear_engine_xruns") == 0)
  293. {
  294. ok = true;
  295. fEngine->clearXruns();
  296. }
  297. else if (std::strcmp(method, "cancel_engine_action") == 0)
  298. {
  299. ok = true;
  300. fEngine->setActionCanceled(true);
  301. }
  302. else if (std::strcmp(method, "patchbay_connect") == 0)
  303. {
  304. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 6);
  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. const bool external = argv[1]->i != 0;
  311. const int32_t groupA = argv[2]->i;
  312. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupA >= 0);
  313. const int32_t portA = argv[3]->i;
  314. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portA >= 0);
  315. const int32_t groupB = argv[4]->i;
  316. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupB >= 0);
  317. const int32_t portB = argv[5]->i;
  318. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(portB >= 0);
  319. ok = fEngine->patchbayConnect(external,
  320. static_cast<uint32_t>(groupA),
  321. static_cast<uint32_t>(portA),
  322. static_cast<uint32_t>(groupB),
  323. static_cast<uint32_t>(portB));
  324. }
  325. else if (std::strcmp(method, "patchbay_disconnect") == 0)
  326. {
  327. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  328. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  329. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  330. const bool external = argv[1]->i != 0;
  331. const int32_t connectionId = argv[2]->i;
  332. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(connectionId >= 0);
  333. ok = fEngine->patchbayDisconnect(external, static_cast<uint32_t>(connectionId));
  334. }
  335. else if (std::strcmp(method, "patchbay_set_group_pos") == 0)
  336. {
  337. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 7);
  338. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  339. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  340. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 'i');
  341. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 'i');
  342. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 'i');
  343. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[6] == 'i');
  344. const bool external = argv[1]->i != 0;
  345. const int32_t groupId = argv[2]->i;
  346. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(groupId >= 0);
  347. ok = fEngine->patchbaySetGroupPos(true, false,
  348. external, static_cast<uint32_t>(groupId),
  349. argv[3]->i, argv[4]->i, argv[5]->i, argv[6]->i);
  350. }
  351. else if (std::strcmp(method, "patchbay_refresh") == 0)
  352. {
  353. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  354. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  355. const bool external = argv[1]->i != 0;
  356. ok = fEngine->patchbayRefresh(false, true, external);
  357. }
  358. else if (std::strcmp(method, "transport_play") == 0)
  359. {
  360. ok = true;
  361. fEngine->transportPlay();
  362. }
  363. else if (std::strcmp(method, "transport_pause") == 0)
  364. {
  365. ok = true;
  366. fEngine->transportPause();
  367. }
  368. else if (std::strcmp(method, "transport_bpm") == 0)
  369. {
  370. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  371. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'f');
  372. const double bpm = argv[1]->f;
  373. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(bpm >= 0.0);
  374. ok = true;
  375. fEngine->transportBPM(bpm);
  376. }
  377. else if (std::strcmp(method, "transport_relocate") == 0)
  378. {
  379. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  380. uint64_t frame;
  381. /**/ if (types[1] == 'i')
  382. {
  383. const int32_t i = argv[1]->i;
  384. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(i >= 0);
  385. frame = static_cast<uint64_t>(i);
  386. }
  387. else if (types[1] == 'h')
  388. {
  389. const int64_t h = argv[1]->h;
  390. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(h >= 0);
  391. frame = static_cast<uint64_t>(h);
  392. }
  393. else
  394. {
  395. carla_stderr2("Wrong OSC type used for '%s'", method);
  396. sendResponse(messageId, "Wrong OSC type");
  397. return 0;
  398. }
  399. ok = true;
  400. fEngine->transportRelocate(frame);
  401. }
  402. else if (std::strcmp(method, "add_plugin") == 0)
  403. {
  404. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 8);
  405. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  406. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  407. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[3] == 's');
  408. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[4] == 's');
  409. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[5] == 's');
  410. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[7] == 'i');
  411. int32_t btype = argv[1]->i;
  412. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(btype >= 0);
  413. const int32_t ptype = argv[2]->i;
  414. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(ptype >= 0);
  415. // Force binary type to be native in some cases
  416. switch (ptype)
  417. {
  418. case PLUGIN_INTERNAL:
  419. case PLUGIN_LV2:
  420. case PLUGIN_SF2:
  421. case PLUGIN_SFZ:
  422. case PLUGIN_JACK:
  423. btype = BINARY_NATIVE;
  424. break;
  425. }
  426. const char* filename = &argv[3]->s;
  427. if (filename != nullptr && std::strcmp(filename, "(null)") == 0)
  428. filename = nullptr;
  429. const char* name = &argv[4]->s;
  430. if (name != nullptr && std::strcmp(name, "(null)") == 0)
  431. name = nullptr;
  432. const char* const label = &argv[5]->s;
  433. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(label != nullptr && label[0] != '\0');
  434. int64_t uniqueId;
  435. /**/ if (types[6] == 'i')
  436. {
  437. uniqueId = argv[6]->i;
  438. }
  439. else if (types[6] == 'h')
  440. {
  441. uniqueId = argv[6]->h;
  442. }
  443. else
  444. {
  445. carla_stderr2("Wrong OSC type used for '%s' uniqueId", method);
  446. sendResponse(messageId, "Wrong OSC type");
  447. return 0;
  448. }
  449. const int32_t options = argv[7]->i;
  450. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(options >= 0);
  451. ok = fEngine->addPlugin(static_cast<BinaryType>(btype),
  452. static_cast<PluginType>(ptype),
  453. filename, name, label, uniqueId, nullptr, static_cast<uint32_t>(options));
  454. }
  455. else if (std::strcmp(method, "remove_plugin") == 0)
  456. {
  457. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  458. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  459. const int32_t id = argv[1]->i;
  460. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  461. ok = fEngine->removePlugin(static_cast<uint32_t>(id));
  462. }
  463. else if (std::strcmp(method, "remove_all_plugins") == 0)
  464. {
  465. ok = fEngine->removeAllPlugins();
  466. }
  467. else if (std::strcmp(method, "rename_plugin") == 0)
  468. {
  469. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  470. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  471. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 's');
  472. const int32_t id = argv[1]->i;
  473. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  474. const char* const newName = &argv[2]->s;
  475. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(newName != nullptr && newName[0] != '\0');
  476. ok = fEngine->renamePlugin(static_cast<uint32_t>(id), newName);
  477. }
  478. else if (std::strcmp(method, "clone_plugin") == 0)
  479. {
  480. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  481. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  482. const int32_t id = argv[1]->i;
  483. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  484. ok = fEngine->clonePlugin(static_cast<uint32_t>(id));
  485. }
  486. else if (std::strcmp(method, "replace_plugin") == 0)
  487. {
  488. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 2);
  489. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  490. const int32_t id = argv[1]->i;
  491. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(id >= 0);
  492. ok = fEngine->replacePlugin(static_cast<uint32_t>(id));
  493. }
  494. else if (std::strcmp(method, "switch_plugins") == 0)
  495. {
  496. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(argc == 3);
  497. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[1] == 'i');
  498. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(types[2] == 'i');
  499. const int32_t idA = argv[1]->i;
  500. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idA >= 0);
  501. const int32_t idB = argv[2]->i;
  502. CARLA_SAFE_ASSERT_RETURN_OSC_ERR(idB >= 0);
  503. ok = fEngine->switchPlugins(static_cast<uint32_t>(idA), static_cast<uint32_t>(idB));
  504. }
  505. else
  506. {
  507. carla_stderr2("Unhandled OSC control for '%s'", method);
  508. sendResponse(messageId, "Unhandled OSC control method");
  509. return 0;
  510. }
  511. #undef CARLA_SAFE_ASSERT_RETURN_OSC_ERR
  512. sendResponse(messageId, ok ? "" : fEngine->getLastError());
  513. return 0;
  514. }
  515. // -----------------------------------------------------------------------
  516. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS)
  517. {
  518. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  519. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  520. const bool active = (argv[0]->i != 0);
  521. plugin->setActive(active, false, true);
  522. return 0;
  523. }
  524. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS)
  525. {
  526. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  527. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  528. const float value = argv[0]->f;
  529. plugin->setDryWet(value, false, true);
  530. return 0;
  531. }
  532. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS)
  533. {
  534. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  535. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  536. const float value = argv[0]->f;
  537. plugin->setVolume(value, false, true);
  538. return 0;
  539. }
  540. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS)
  541. {
  542. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  543. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  544. const float value = argv[0]->f;
  545. plugin->setBalanceLeft(value, false, true);
  546. return 0;
  547. }
  548. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS)
  549. {
  550. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  551. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  552. const float value = argv[0]->f;
  553. plugin->setBalanceRight(value, false, true);
  554. return 0;
  555. }
  556. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS)
  557. {
  558. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  559. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  560. const float value = argv[0]->f;
  561. plugin->setPanning(value, false, true);
  562. return 0;
  563. }
  564. int CarlaEngineOsc::handleMsgSetForth(CARLA_ENGINE_OSC_HANDLE_ARGS)
  565. {
  566. carla_debug("CarlaEngineOsc::handleMsgSetForth()");
  567. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  568. const float value = argv[0]->f;
  569. plugin->setForth(value, false, true);
  570. return 0;
  571. }
  572. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS)
  573. {
  574. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  575. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  576. const int32_t index = argv[0]->i;
  577. const float value = argv[1]->f;
  578. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  579. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  580. return 0;
  581. }
  582. int CarlaEngineOsc::handleMsgSetParameterMappedControlIndex(CARLA_ENGINE_OSC_HANDLE_ARGS)
  583. {
  584. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedIndex()");
  585. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  586. const int32_t index = argv[0]->i;
  587. const int32_t ctrl = argv[1]->i;
  588. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  589. CARLA_SAFE_ASSERT_RETURN(ctrl >= CONTROL_INDEX_NONE && ctrl <= CONTROL_INDEX_MAX_ALLOWED, 0);
  590. plugin->setParameterMappedControlIndex(static_cast<uint32_t>(index), static_cast<int16_t>(ctrl), false, true, true);
  591. return 0;
  592. }
  593. int CarlaEngineOsc::handleMsgSetParameterMappedRange(CARLA_ENGINE_OSC_HANDLE_ARGS)
  594. {
  595. carla_debug("CarlaEngineOsc::handleMsgSetParameterMappedRange()");
  596. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "iff");
  597. const int32_t index = argv[0]->i;
  598. const float minimum = argv[1]->f;
  599. const float maximum = argv[2]->f;
  600. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  601. plugin->setParameterMappedRange(static_cast<uint32_t>(index), minimum, maximum, false, true);
  602. return 0;
  603. }
  604. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS)
  605. {
  606. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  607. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  608. const int32_t index = argv[0]->i;
  609. const int32_t channel = argv[1]->i;
  610. CARLA_SAFE_ASSERT_RETURN(index >= 0, 0);
  611. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  612. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  613. return 0;
  614. }
  615. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  616. {
  617. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  618. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  619. const int32_t index = argv[0]->i;
  620. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  621. plugin->setProgram(index, true, false, true);
  622. return 0;
  623. }
  624. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS)
  625. {
  626. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  627. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  628. const int32_t index = argv[0]->i;
  629. CARLA_SAFE_ASSERT_RETURN(index >= -1, 0);
  630. plugin->setMidiProgram(index, true, false, true);
  631. return 0;
  632. }
  633. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS)
  634. {
  635. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  636. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  637. const int32_t channel = argv[0]->i;
  638. const int32_t note = argv[1]->i;
  639. const int32_t velo = argv[2]->i;
  640. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  641. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  642. CARLA_SAFE_ASSERT_RETURN(velo >= 0 && velo < MAX_MIDI_VALUE, 0);
  643. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  644. return 0;
  645. }
  646. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS)
  647. {
  648. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  649. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  650. const int32_t channel = argv[0]->i;
  651. const int32_t note = argv[1]->i;
  652. CARLA_SAFE_ASSERT_RETURN(channel >= 0 && channel < MAX_MIDI_CHANNELS, 0);
  653. CARLA_SAFE_ASSERT_RETURN(note >= 0 && note < MAX_MIDI_NOTE, 0);
  654. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  655. return 0;
  656. }
  657. // -----------------------------------------------------------------------
  658. CARLA_BACKEND_END_NAMESPACE
  659. #endif // HAVE_LIBLO