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.

807 lines
25KB

  1. /*
  2. * Carla Engine OSC
  3. * Copyright (C) 2012-2013 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. #include "CarlaEngine.hpp"
  19. #include "CarlaPlugin.hpp"
  20. #ifndef BUILD_BRIDGE
  21. # include "CarlaBridgeUtils.hpp"
  22. #endif
  23. CARLA_BACKEND_START_NAMESPACE
  24. #ifndef BUILD_BRIDGE
  25. // -------------------------------------------------------------------
  26. // Bridge Helper, defined in CarlaPlugin.cpp
  27. extern int CarlaPluginSetOscBridgeInfo(CarlaPlugin* const plugin, const PluginBridgeInfoType type,
  28. const int argc, const lo_arg* const* const argv, const char* const types);
  29. #endif
  30. // -----------------------------------------------------------------------
  31. CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine)
  32. : fEngine(engine),
  33. fServerTCP(nullptr),
  34. fServerUDP(nullptr)
  35. {
  36. carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine);
  37. CARLA_ASSERT(engine != nullptr);
  38. }
  39. CarlaEngineOsc::~CarlaEngineOsc()
  40. {
  41. carla_debug("CarlaEngineOsc::~CarlaEngineOsc()");
  42. CARLA_ASSERT(fName.isEmpty());
  43. CARLA_ASSERT(fServerPathTCP.isEmpty());
  44. CARLA_ASSERT(fServerPathUDP.isEmpty());
  45. CARLA_ASSERT(fServerTCP == nullptr);
  46. CARLA_ASSERT(fServerUDP == nullptr);
  47. }
  48. // -----------------------------------------------------------------------
  49. void CarlaEngineOsc::init(const char* const name)
  50. {
  51. carla_debug("CarlaEngineOsc::init(\"%s\")", name);
  52. CARLA_ASSERT(fName.isEmpty());
  53. CARLA_ASSERT(fServerPathTCP.isEmpty());
  54. CARLA_ASSERT(fServerPathUDP.isEmpty());
  55. CARLA_ASSERT(fServerTCP == nullptr);
  56. CARLA_ASSERT(fServerUDP == nullptr);
  57. CARLA_ASSERT(name != nullptr);
  58. fName = name;
  59. fName.toBasic();
  60. fServerTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP);
  61. if (fServerTCP != nullptr)
  62. {
  63. if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP))
  64. {
  65. fServerPathTCP = tmpServerPathTCP;
  66. fServerPathTCP += fName;
  67. std::free(tmpServerPathTCP);
  68. }
  69. lo_server_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this);
  70. }
  71. fServerUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP);
  72. if (fServerUDP != nullptr)
  73. {
  74. if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP))
  75. {
  76. fServerPathUDP = tmpServerPathUDP;
  77. fServerPathUDP += fName;
  78. std::free(tmpServerPathUDP);
  79. }
  80. lo_server_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this);
  81. }
  82. CARLA_ASSERT(fName.isNotEmpty());
  83. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  84. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  85. CARLA_ASSERT(fServerTCP != nullptr);
  86. CARLA_ASSERT(fServerUDP != nullptr);
  87. }
  88. void CarlaEngineOsc::idle()
  89. {
  90. if (fServerTCP != nullptr)
  91. {
  92. while (lo_server_recv_noblock(fServerTCP, 0) != 0) {}
  93. }
  94. if (fServerUDP != nullptr)
  95. {
  96. while (lo_server_recv_noblock(fServerUDP, 0) != 0) {}
  97. }
  98. }
  99. void CarlaEngineOsc::close()
  100. {
  101. carla_debug("CarlaEngineOsc::close()");
  102. CARLA_ASSERT(fName.isNotEmpty());
  103. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  104. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  105. CARLA_ASSERT(fServerTCP != nullptr);
  106. CARLA_ASSERT(fServerUDP != nullptr);
  107. fName.clear();
  108. if (fServerTCP != nullptr)
  109. {
  110. lo_server_del_method(fServerTCP, nullptr, nullptr);
  111. lo_server_free(fServerTCP);
  112. fServerTCP = nullptr;
  113. }
  114. if (fServerUDP != nullptr)
  115. {
  116. lo_server_del_method(fServerUDP, nullptr, nullptr);
  117. lo_server_free(fServerUDP);
  118. fServerUDP = nullptr;
  119. }
  120. fServerPathTCP.clear();
  121. fServerPathUDP.clear();
  122. #ifndef BUILD_BRIDGE
  123. fControlData.free();
  124. #endif
  125. CARLA_ASSERT(fName.isEmpty());
  126. CARLA_ASSERT(fServerPathTCP.isEmpty());
  127. CARLA_ASSERT(fServerPathUDP.isEmpty());
  128. CARLA_ASSERT(fServerTCP == nullptr);
  129. CARLA_ASSERT(fServerUDP == nullptr);
  130. }
  131. // -----------------------------------------------------------------------
  132. bool isDigit(const char c)
  133. {
  134. return (c >= '0' && c <= '9');
  135. }
  136. 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)
  137. {
  138. CARLA_ASSERT(fName.isNotEmpty());
  139. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  140. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  141. CARLA_ASSERT(fServerTCP != nullptr);
  142. CARLA_ASSERT(fServerUDP != nullptr);
  143. CARLA_ASSERT(path != nullptr);
  144. carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg);
  145. if (path == nullptr)
  146. {
  147. carla_stderr("CarlaEngineOsc::handleMessage() - got invalid path");
  148. return 1;
  149. }
  150. if (fName.isEmpty())
  151. {
  152. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message but client is offline", bool2str(isTCP), path);
  153. return 1;
  154. }
  155. #ifndef BUILD_BRIDGE
  156. // Initial path check
  157. if (std::strcmp(path, "/register") == 0)
  158. {
  159. const lo_address source = lo_message_get_source(msg);
  160. return handleMsgRegister(isTCP, argc, argv, types, source);
  161. }
  162. if (std::strcmp(path, "/unregister") == 0)
  163. {
  164. return handleMsgUnregister();
  165. }
  166. #endif
  167. const size_t nameSize = fName.length();
  168. // Check if message is for this client
  169. if (std::strlen(path) <= nameSize || std::strncmp(path+1, (const char*)fName, nameSize) != 0)
  170. {
  171. carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, (const char*)fName);
  172. return 1;
  173. }
  174. // Get plugin id from message
  175. // eg, /carla/23/method
  176. unsigned int pluginId = 0;
  177. size_t offset;
  178. if (isDigit(path[nameSize+2]))
  179. {
  180. if (isDigit(path[nameSize+3]))
  181. {
  182. if (isDigit(path[nameSize+5]))
  183. {
  184. carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", path+nameSize+1);
  185. return 1;
  186. }
  187. else if (isDigit(path[nameSize+4]))
  188. {
  189. // 3 digits, /xyz/method
  190. offset = 6;
  191. pluginId += (path[nameSize+2]-'0')*100;
  192. pluginId += (path[nameSize+3]-'0')*10;
  193. pluginId += (path[nameSize+4]-'0');
  194. }
  195. else
  196. {
  197. // 2 digits, /xy/method
  198. offset = 5;
  199. pluginId += (path[nameSize+2]-'0')*10;
  200. pluginId += (path[nameSize+3]-'0');
  201. }
  202. }
  203. else
  204. {
  205. // single digit, /x/method
  206. offset = 4;
  207. pluginId += path[nameSize+2]-'0';
  208. }
  209. }
  210. else
  211. {
  212. carla_stderr("CarlaEngineOsc::handleMessage() - invalid message '%s'", path);
  213. return 1;
  214. }
  215. if (pluginId > fEngine->getCurrentPluginCount())
  216. {
  217. carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId);
  218. return 1;
  219. }
  220. // Get plugin
  221. CarlaPlugin* const plugin = fEngine->getPluginUnchecked(pluginId);
  222. if (plugin == nullptr || plugin->getId() != pluginId)
  223. {
  224. carla_stderr("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed", pluginId);
  225. return 1;
  226. }
  227. // Get method from path, "/Carla/i/method" -> "method"
  228. char method[32] = { 0 };
  229. std::strncpy(method, path + (nameSize + offset), 31);
  230. if (method[0] == '\0')
  231. {
  232. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message without method", bool2str(isTCP), path);
  233. return 1;
  234. }
  235. // Common OSC methods (DSSI and bridge UIs)
  236. if (std::strcmp(method, "update") == 0)
  237. {
  238. const lo_address source = lo_message_get_source(msg);
  239. return handleMsgUpdate(plugin, argc, argv, types, source);
  240. }
  241. if (std::strcmp(method, "configure") == 0)
  242. return handleMsgConfigure(plugin, argc, argv, types);
  243. if (std::strcmp(method, "control") == 0)
  244. return handleMsgControl(plugin, argc, argv, types);
  245. if (std::strcmp(method, "program") == 0)
  246. return handleMsgProgram(plugin, argc, argv, types);
  247. if (std::strcmp(method, "midi") == 0)
  248. return handleMsgMidi(plugin, argc, argv, types);
  249. if (std::strcmp(method, "exiting") == 0)
  250. return handleMsgExiting(plugin);
  251. #ifndef BUILD_BRIDGE
  252. // Internal methods
  253. if (std::strcmp(method, "set_active") == 0)
  254. return handleMsgSetActive(plugin, argc, argv, types);
  255. if (std::strcmp(method, "set_drywet") == 0)
  256. return handleMsgSetDryWet(plugin, argc, argv, types);
  257. if (std::strcmp(method, "set_volume") == 0)
  258. return handleMsgSetVolume(plugin, argc, argv, types);
  259. if (std::strcmp(method, "set_balance_left") == 0)
  260. return handleMsgSetBalanceLeft(plugin, argc, argv, types);
  261. if (std::strcmp(method, "set_balance_right") == 0)
  262. return handleMsgSetBalanceRight(plugin, argc, argv, types);
  263. if (std::strcmp(method, "set_panning") == 0)
  264. return handleMsgSetPanning(plugin, argc, argv, types);
  265. if (std::strcmp(method, "set_parameter_value") == 0)
  266. return handleMsgSetParameterValue(plugin, argc, argv, types);
  267. if (std::strcmp(method, "set_parameter_midi_cc") == 0)
  268. return handleMsgSetParameterMidiCC(plugin, argc, argv, types);
  269. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  270. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  271. if (std::strcmp(method, "set_program") == 0)
  272. return handleMsgSetProgram(plugin, argc, argv, types);
  273. if (std::strcmp(method, "set_midi_program") == 0)
  274. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  275. if (std::strcmp(method, "note_on") == 0)
  276. return handleMsgNoteOn(plugin, argc, argv, types);
  277. if (std::strcmp(method, "note_off") == 0)
  278. return handleMsgNoteOff(plugin, argc, argv, types);
  279. // Plugin Bridges
  280. if ((plugin->getHints() & PLUGIN_IS_BRIDGE) > 0 && std::strlen(method) > 11 && std::strncmp(method, "bridge_", 7) == 0)
  281. {
  282. if (std::strcmp(method+7, "audio_count") == 0)
  283. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeAudioCount, argc, argv, types);
  284. if (std::strcmp(method+7, "midi_count") == 0)
  285. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiCount, argc, argv, types);
  286. if (std::strcmp(method+7, "parameter_count") == 0)
  287. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterCount, argc, argv, types);
  288. if (std::strcmp(method+7, "program_count") == 0)
  289. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeProgramCount, argc, argv, types);
  290. if (std::strcmp(method+7, "midi_program_count") == 0)
  291. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiProgramCount, argc, argv, types);
  292. if (std::strcmp(method+7, "plugin_info") == 0)
  293. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgePluginInfo, argc, argv, types);
  294. if (std::strcmp(method+7, "parameter_info") == 0)
  295. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterInfo, argc, argv, types);
  296. if (std::strcmp(method+7, "parameter_data") == 0)
  297. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterData, argc, argv, types);
  298. if (std::strcmp(method+7, "parameter_ranges") == 0)
  299. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterRanges, argc, argv, types);
  300. if (std::strcmp(method+7, "program_info") == 0)
  301. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeProgramInfo, argc, argv, types);
  302. if (std::strcmp(method+7, "midi_program_info") == 0)
  303. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiProgramInfo, argc, argv, types);
  304. if (std::strcmp(method+7, "configure") == 0)
  305. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeConfigure, argc, argv, types);
  306. if (std::strcmp(method+7, "set_parameter_value") == 0)
  307. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetParameterValue, argc, argv, types);
  308. if (std::strcmp(method+7, "set_default_value") == 0)
  309. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetDefaultValue, argc, argv, types);
  310. if (std::strcmp(method+7, "set_program") == 0)
  311. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetProgram, argc, argv, types);
  312. if (std::strcmp(method+7, "set_midi_program") == 0)
  313. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetMidiProgram, argc, argv, types);
  314. if (std::strcmp(method+7, "set_custom_data") == 0)
  315. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetCustomData, argc, argv, types);
  316. if (std::strcmp(method+7, "set_chunk_data") == 0)
  317. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetChunkData, argc, argv, types);
  318. if (std::strcmp(method+7, "update") == 0)
  319. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeUpdateNow, argc, argv, types);
  320. if (std::strcmp(method+7, "error") == 0)
  321. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeError, argc, argv, types);
  322. }
  323. #endif
  324. // Plugin-specific methods
  325. #ifdef WANT_LV2
  326. if (std::strcmp(method, "lv2_atom_transfer") == 0)
  327. return handleMsgLv2AtomTransfer(plugin, argc, argv, types);
  328. if (std::strcmp(method, "lv2_urid_map") == 0)
  329. return handleMsgLv2UridMap(plugin, argc, argv, types);
  330. #endif
  331. carla_stderr("CarlaEngineOsc::handleMessage() - unsupported OSC method '%s'", method);
  332. return 1;
  333. }
  334. // -----------------------------------------------------------------------
  335. #ifndef BUILD_BRIDGE
  336. int CarlaEngineOsc::handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source)
  337. {
  338. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  339. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  340. if (fControlData.path != nullptr)
  341. {
  342. carla_stderr("CarlaEngineOsc::handleMsgRegister() - OSC backend already registered to %s", fControlData.path);
  343. return 1;
  344. }
  345. const char* const url = &argv[0]->s;
  346. carla_debug("CarlaEngineOsc::handleMsgRegister() - OSC backend registered to %s", url);
  347. {
  348. const char* host = lo_address_get_hostname(source);
  349. const char* port = lo_address_get_port(source);
  350. fControlData.source = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  351. }
  352. {
  353. char* host = lo_url_get_hostname(url);
  354. char* port = lo_url_get_port(url);
  355. fControlData.path = carla_strdup_free(lo_url_get_path(url));
  356. fControlData.target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  357. std::free(host);
  358. std::free(port);
  359. }
  360. for (unsigned int i=0, count=fEngine->getCurrentPluginCount(); i < count; ++i)
  361. {
  362. CarlaPlugin* const plugin(fEngine->getPluginUnchecked(i));
  363. if (plugin != nullptr && plugin->isEnabled())
  364. plugin->registerToOscClient();
  365. }
  366. return 0;
  367. }
  368. int CarlaEngineOsc::handleMsgUnregister()
  369. {
  370. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  371. if (fControlData.path == nullptr)
  372. {
  373. carla_stderr("CarlaEngineOsc::handleMsgUnregister() - OSC backend is not registered yet");
  374. return 1;
  375. }
  376. fControlData.free();
  377. return 0;
  378. }
  379. #endif
  380. // -----------------------------------------------------------------------
  381. int CarlaEngineOsc::handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source)
  382. {
  383. carla_debug("CarlaEngineOsc::handleMsgUpdate()");
  384. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  385. const char* const url = (const char*)&argv[0]->s;
  386. plugin->updateOscData(source, url);
  387. return 0;
  388. }
  389. int CarlaEngineOsc::handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  390. {
  391. carla_debug("CarlaEngineOsc::handleMsgConfigure()");
  392. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ss");
  393. const char* const key = (const char*)&argv[0]->s;
  394. const char* const value = (const char*)&argv[1]->s;
  395. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, key, value, false);
  396. return 0;
  397. }
  398. int CarlaEngineOsc::handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  399. {
  400. carla_debug("CarlaEngineOsc::handleMsgControl()");
  401. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  402. const int32_t rindex = argv[0]->i;
  403. const float value = argv[1]->f;
  404. plugin->setParameterValueByRealIndex(rindex, value, false, true, true);
  405. return 0;
  406. }
  407. int CarlaEngineOsc::handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  408. {
  409. carla_debug("CarlaEngineOsc::handleMsgProgram()");
  410. if (argc == 2)
  411. {
  412. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  413. const int32_t bank = argv[0]->i;
  414. const int32_t program = argv[1]->i;
  415. CARLA_SAFE_ASSERT_INT(bank >= 0, bank);
  416. CARLA_SAFE_ASSERT_INT(program >= 0, program);
  417. if (bank < 0)
  418. return 1;
  419. if (program < 0)
  420. return 1;
  421. plugin->setMidiProgramById(static_cast<uint32_t>(bank), static_cast<uint32_t>(program), false, true, true);
  422. return 0;
  423. }
  424. else
  425. {
  426. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  427. const int32_t program = argv[0]->i;
  428. CARLA_SAFE_ASSERT_INT(program >= 0, program);
  429. if (program < 0)
  430. return 1;
  431. if (program < static_cast<int32_t>(plugin->getProgramCount()))
  432. {
  433. plugin->setProgram(program, false, true, true);
  434. return 0;
  435. }
  436. carla_stderr("CarlaEngineOsc::handleMsgProgram() - programId '%i' out of bounds", program);
  437. return 1;
  438. }
  439. }
  440. int CarlaEngineOsc::handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  441. {
  442. carla_debug("CarlaEngineOsc::handleMsgMidi()");
  443. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "m");
  444. #ifdef BUILD_BRIDGE
  445. CARLA_ASSERT(false); // this should never happen
  446. return 1;
  447. // unused
  448. (void)plugin;
  449. (void)argv;
  450. #else
  451. if (plugin->getMidiInCount() == 0)
  452. {
  453. carla_stderr("CarlaEngineOsc::handleMsgMidi() - recived midi when plugin has no midi inputs");
  454. return 1;
  455. }
  456. const uint8_t* const data = argv[0]->m;
  457. uint8_t status = data[1];
  458. uint8_t channel = status & 0x0F;
  459. // Fix bad note-off
  460. if (MIDI_IS_STATUS_NOTE_ON(status) && data[3] == 0)
  461. status = static_cast<uint8_t>(status - 0x10);
  462. if (MIDI_IS_STATUS_NOTE_OFF(status))
  463. {
  464. const uint8_t note = data[2];
  465. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  466. if (note >= MAX_MIDI_NOTE)
  467. return 1;
  468. plugin->sendMidiSingleNote(channel, note, 0, false, true, true);
  469. }
  470. else if (MIDI_IS_STATUS_NOTE_ON(status))
  471. {
  472. const uint8_t note = data[2];
  473. const uint8_t velo = data[3];
  474. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  475. CARLA_SAFE_ASSERT_INT(velo < MAX_MIDI_VALUE, velo);
  476. if (note >= MAX_MIDI_NOTE)
  477. return 1;
  478. if (velo >= MAX_MIDI_VALUE)
  479. return 1;
  480. plugin->sendMidiSingleNote(channel, note, velo, false, true, true);
  481. }
  482. return 0;
  483. #endif
  484. }
  485. int CarlaEngineOsc::handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1)
  486. {
  487. carla_debug("CarlaEngineOsc::handleMsgExiting()");
  488. // TODO - check for non-UIs (dssi-vst) and set to -1 instead
  489. fEngine->callback(ENGINE_CALLBACK_UI_STATE_CHANGED, plugin->getId(), 0, 0, 0.0f, nullptr);
  490. // TODO
  491. //plugin->freeOscData();
  492. return 0;
  493. }
  494. // -----------------------------------------------------------------------
  495. #ifndef BUILD_BRIDGE
  496. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  497. {
  498. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  499. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  500. const bool active = (argv[0]->i != 0);
  501. plugin->setActive(active, false, true);
  502. return 0;
  503. }
  504. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  505. {
  506. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  507. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  508. const float value = argv[0]->f;
  509. plugin->setDryWet(value, false, true);
  510. return 0;
  511. }
  512. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  513. {
  514. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  515. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  516. const float value = argv[0]->f;
  517. plugin->setVolume(value, false, true);
  518. return 0;
  519. }
  520. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  521. {
  522. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  523. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  524. const float value = argv[0]->f;
  525. plugin->setBalanceLeft(value, false, true);
  526. return 0;
  527. }
  528. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  529. {
  530. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  531. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  532. const float value = argv[0]->f;
  533. plugin->setBalanceRight(value, false, true);
  534. return 0;
  535. }
  536. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  537. {
  538. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  539. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  540. const float value = argv[0]->f;
  541. plugin->setPanning(value, false, true);
  542. return 0;
  543. }
  544. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  545. {
  546. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  547. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  548. const int32_t index = argv[0]->i;
  549. const float value = argv[1]->f;
  550. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  551. if (index < 0)
  552. return 1;
  553. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  554. return 0;
  555. }
  556. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  557. {
  558. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  559. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  560. const int32_t index = argv[0]->i;
  561. const int32_t cc = argv[1]->i;
  562. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  563. CARLA_SAFE_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc);
  564. if (index < 0)
  565. return 1;
  566. if (cc < -1 || cc > 0x5F)
  567. return 1;
  568. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  569. return 0;
  570. }
  571. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  572. {
  573. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  574. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  575. const int32_t index = argv[0]->i;
  576. const int32_t channel = argv[1]->i;
  577. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  578. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  579. if (index < 0)
  580. return 1;
  581. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  582. return 1;
  583. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  584. return 0;
  585. }
  586. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  587. {
  588. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  589. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  590. const int32_t index = argv[0]->i;
  591. plugin->setProgram(index, true, false, true);
  592. return 0;
  593. }
  594. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  595. {
  596. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  597. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  598. const int32_t index = argv[0]->i;
  599. plugin->setMidiProgram(index, true, false, true);
  600. return 0;
  601. }
  602. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  603. {
  604. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  605. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  606. const int32_t channel = argv[0]->i;
  607. const int32_t note = argv[1]->i;
  608. const int32_t velo = argv[2]->i;
  609. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  610. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  611. CARLA_SAFE_ASSERT_INT(velo >= 0 && velo < MAX_MIDI_VALUE, velo);
  612. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  613. return 1;
  614. if (note < 0 || note >= MAX_MIDI_NOTE)
  615. return 1;
  616. if (velo < 0 || velo >= MAX_MIDI_VALUE)
  617. return 1;
  618. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  619. return 0;
  620. }
  621. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  622. {
  623. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  624. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  625. const int32_t channel = argv[0]->i;
  626. const int32_t note = argv[1]->i;
  627. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  628. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  629. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  630. return 1;
  631. if (note < 0 || note >= MAX_MIDI_NOTE)
  632. return 1;
  633. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  634. return 0;
  635. }
  636. #endif
  637. CARLA_BACKEND_END_NAMESPACE