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.

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