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.

818 lines
26KB

  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 "CarlaBridge.hpp"
  23. #endif
  24. CARLA_BACKEND_START_NAMESPACE
  25. #ifndef BUILD_BRIDGE
  26. // -------------------------------------------------------------------
  27. // Bridge Helper, defined in plugin/CarlaBlugin.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, "set_peaks") == 0)
  284. return handleMsgBridgeSetPeaks(plugin, argc, argv, types);
  285. if (std::strcmp(method+7, "audio_count") == 0)
  286. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeAudioCount, argc, argv, types);
  287. if (std::strcmp(method+7, "midi_count") == 0)
  288. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiCount, argc, argv, types);
  289. if (std::strcmp(method+7, "parameter_count") == 0)
  290. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterCount, argc, argv, types);
  291. if (std::strcmp(method+7, "program_count") == 0)
  292. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeProgramCount, argc, argv, types);
  293. if (std::strcmp(method+7, "midi_program_count") == 0)
  294. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiProgramCount, argc, argv, types);
  295. if (std::strcmp(method+7, "plugin_info") == 0)
  296. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgePluginInfo, argc, argv, types);
  297. if (std::strcmp(method+7, "parameter_info") == 0)
  298. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterInfo, argc, argv, types);
  299. if (std::strcmp(method+7, "parameter_data") == 0)
  300. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterData, argc, argv, types);
  301. if (std::strcmp(method+7, "parameter_ranges") == 0)
  302. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeParameterRanges, argc, argv, types);
  303. if (std::strcmp(method+7, "program_info") == 0)
  304. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeProgramInfo, argc, argv, types);
  305. if (std::strcmp(method+7, "midi_program_info") == 0)
  306. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeMidiProgramInfo, argc, argv, types);
  307. if (std::strcmp(method+7, "configure") == 0)
  308. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeConfigure, argc, argv, types);
  309. if (std::strcmp(method+7, "set_parameter_value") == 0)
  310. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetParameterValue, argc, argv, types);
  311. if (std::strcmp(method+7, "set_default_value") == 0)
  312. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetDefaultValue, argc, argv, types);
  313. if (std::strcmp(method+7, "set_program") == 0)
  314. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetProgram, argc, argv, types);
  315. if (std::strcmp(method+7, "set_midi_program") == 0)
  316. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetMidiProgram, argc, argv, types);
  317. if (std::strcmp(method+7, "set_custom_data") == 0)
  318. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetCustomData, argc, argv, types);
  319. if (std::strcmp(method+7, "set_chunk_data") == 0)
  320. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeSetChunkData, argc, argv, types);
  321. if (std::strcmp(method+7, "update") == 0)
  322. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeUpdateNow, argc, argv, types);
  323. if (std::strcmp(method+7, "error") == 0)
  324. return CarlaPluginSetOscBridgeInfo(plugin, kPluginBridgeError, argc, argv, types);
  325. }
  326. #endif
  327. // Plugin-specific methods, FIXME
  328. #if 0 //def WANT_LV2
  329. if (std::strcmp(method, "lv2_atom_transfer") == 0)
  330. return handleMsgLv2AtomTransfer(plugin, argc, argv, types);
  331. if (std::strcmp(method, "lv2_event_transfer") == 0)
  332. return handleMsgLv2EventTransfer(plugin, argc, argv, types);
  333. #endif
  334. carla_stderr("CarlaEngineOsc::handleMessage() - unsupported OSC method '%s'", method);
  335. return 1;
  336. }
  337. // -----------------------------------------------------------------------
  338. #ifndef BUILD_BRIDGE
  339. int CarlaEngineOsc::handleMsgRegister(const bool isTCP, const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source)
  340. {
  341. carla_debug("CarlaEngineOsc::handleMsgRegister()");
  342. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  343. if (fControlData.path != nullptr)
  344. {
  345. carla_stderr("CarlaEngineOsc::handleMsgRegister() - OSC backend already registered to %s", fControlData.path);
  346. return 1;
  347. }
  348. const char* const url = &argv[0]->s;
  349. carla_debug("CarlaEngineOsc::handleMsgRegister() - OSC backend registered to %s", url);
  350. {
  351. const char* host = lo_address_get_hostname(source);
  352. const char* port = lo_address_get_port(source);
  353. fControlData.source = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  354. }
  355. {
  356. char* host = lo_url_get_hostname(url);
  357. char* port = lo_url_get_port(url);
  358. fControlData.path = carla_strdup_free(lo_url_get_path(url));
  359. fControlData.target = lo_address_new_with_proto(isTCP ? LO_TCP : LO_UDP, host, port);
  360. std::free(host);
  361. std::free(port);
  362. }
  363. for (unsigned short i=0; i < kEngine->currentPluginCount(); i++)
  364. {
  365. CarlaPlugin* const plugin = kEngine->getPluginUnchecked(i);
  366. if (plugin && plugin->enabled())
  367. plugin->registerToOscClient();
  368. }
  369. return 0;
  370. }
  371. int CarlaEngineOsc::handleMsgUnregister()
  372. {
  373. carla_debug("CarlaEngineOsc::handleMsgUnregister()");
  374. if (fControlData.path == nullptr)
  375. {
  376. carla_stderr("CarlaEngineOsc::handleMsgUnregister() - OSC backend is not registered yet");
  377. return 1;
  378. }
  379. fControlData.free();
  380. return 0;
  381. }
  382. #endif
  383. // -----------------------------------------------------------------------
  384. int CarlaEngineOsc::handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source)
  385. {
  386. carla_debug("CarlaEngineOsc::handleMsgUpdate()");
  387. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  388. const char* const url = (const char*)&argv[0]->s;
  389. plugin->updateOscData(source, url);
  390. return 0;
  391. }
  392. int CarlaEngineOsc::handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  393. {
  394. carla_debug("CarlaEngineOsc::handleMsgConfigure()");
  395. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ss");
  396. const char* const key = (const char*)&argv[0]->s;
  397. const char* const value = (const char*)&argv[1]->s;
  398. plugin->setCustomData(CUSTOM_DATA_STRING, key, value, false);
  399. return 0;
  400. }
  401. int CarlaEngineOsc::handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  402. {
  403. carla_debug("CarlaEngineOsc::handleMsgControl()");
  404. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  405. const int32_t rindex = argv[0]->i;
  406. const float value = argv[1]->f;
  407. plugin->setParameterValueByRIndex(rindex, value, false, true, true);
  408. return 0;
  409. }
  410. int CarlaEngineOsc::handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  411. {
  412. carla_debug("CarlaEngineOsc::handleMsgProgram()");
  413. if (argc == 2)
  414. {
  415. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  416. const int32_t bank = argv[0]->i;
  417. const int32_t program = argv[1]->i;
  418. CARLA_SAFE_ASSERT_INT(bank >= 0, bank);
  419. CARLA_SAFE_ASSERT_INT(program >= 0, program);
  420. if (bank < 0)
  421. return 1;
  422. if (program < 0)
  423. return 1;
  424. plugin->setMidiProgramById(static_cast<uint32_t>(bank), static_cast<uint32_t>(program), false, true, true);
  425. return 0;
  426. }
  427. else
  428. {
  429. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  430. const int32_t program = argv[0]->i;
  431. CARLA_SAFE_ASSERT_INT(program >= 0, program);
  432. if (program < 0)
  433. return 1;
  434. if (program < static_cast<int32_t>(plugin->programCount()))
  435. {
  436. plugin->setProgram(program, false, true, true);
  437. return 0;
  438. }
  439. carla_stderr("CarlaEngineOsc::handleMsgProgram() - programId '%i' out of bounds", program);
  440. return 1;
  441. }
  442. }
  443. int CarlaEngineOsc::handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  444. {
  445. carla_debug("CarlaEngineOsc::handleMsgMidi()");
  446. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "m");
  447. if (plugin->midiInCount() == 0)
  448. {
  449. carla_stderr("CarlaEngineOsc::handleMsgMidi() - recived midi when plugin has no midi inputs");
  450. return 1;
  451. }
  452. const uint8_t* const data = argv[0]->m;
  453. uint8_t status = data[1];
  454. uint8_t channel = status & 0x0F;
  455. // Fix bad note-off
  456. if (MIDI_IS_STATUS_NOTE_ON(status) && data[3] == 0)
  457. status -= 0x10;
  458. if (MIDI_IS_STATUS_NOTE_OFF(status))
  459. {
  460. const uint8_t note = data[2];
  461. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  462. if (note >= MAX_MIDI_NOTE)
  463. return 1;
  464. plugin->sendMidiSingleNote(channel, note, 0, false, true, true);
  465. }
  466. else if (MIDI_IS_STATUS_NOTE_ON(status))
  467. {
  468. const uint8_t note = data[2];
  469. const uint8_t velo = data[3];
  470. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  471. CARLA_SAFE_ASSERT_INT(velo < MAX_MIDI_VALUE, velo);
  472. if (note >= MAX_MIDI_NOTE)
  473. return 1;
  474. if (velo >= MAX_MIDI_VALUE)
  475. return 1;
  476. plugin->sendMidiSingleNote(channel, note, velo, false, true, true);
  477. }
  478. return 0;
  479. }
  480. int CarlaEngineOsc::handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1)
  481. {
  482. carla_debug("CarlaEngineOsc::handleMsgExiting()");
  483. // TODO - check for non-UIs (dssi-vst) and set to -1 instead
  484. kEngine->callback(CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0f, nullptr);
  485. plugin->freeOscData();
  486. return 0;
  487. }
  488. // -----------------------------------------------------------------------
  489. #ifndef BUILD_BRIDGE
  490. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  491. {
  492. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  493. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  494. const bool active = (argv[0]->i != 0);
  495. plugin->setActive(active, false, true);
  496. return 0;
  497. }
  498. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  499. {
  500. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  501. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  502. const float value = argv[0]->f;
  503. plugin->setDryWet(value, false, true);
  504. return 0;
  505. }
  506. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  507. {
  508. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  509. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  510. const float value = argv[0]->f;
  511. plugin->setVolume(value, false, true);
  512. return 0;
  513. }
  514. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  515. {
  516. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  517. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  518. const float value = argv[0]->f;
  519. plugin->setBalanceLeft(value, false, true);
  520. return 0;
  521. }
  522. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  523. {
  524. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  525. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  526. const float value = argv[0]->f;
  527. plugin->setBalanceRight(value, false, true);
  528. return 0;
  529. }
  530. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  531. {
  532. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  533. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  534. const float value = argv[0]->f;
  535. plugin->setPanning(value, false, true);
  536. return 0;
  537. }
  538. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  539. {
  540. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  541. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  542. const int32_t index = argv[0]->i;
  543. const float value = argv[1]->f;
  544. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  545. if (index < 0)
  546. return 1;
  547. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  548. return 0;
  549. }
  550. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  551. {
  552. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  553. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  554. const int32_t index = argv[0]->i;
  555. const int32_t cc = argv[1]->i;
  556. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  557. CARLA_SAFE_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc);
  558. if (index < 0)
  559. return 1;
  560. if (cc < -1 || cc > 0x5F)
  561. return 1;
  562. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  563. return 0;
  564. }
  565. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  566. {
  567. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  568. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  569. const int32_t index = argv[0]->i;
  570. const int32_t channel = argv[1]->i;
  571. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  572. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  573. if (index < 0)
  574. return 1;
  575. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  576. return 1;
  577. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  578. return 0;
  579. }
  580. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  581. {
  582. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  583. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  584. const int32_t index = argv[0]->i;
  585. plugin->setProgram(index, true, false, true);
  586. return 0;
  587. }
  588. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  589. {
  590. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  591. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  592. const int32_t index = argv[0]->i;
  593. plugin->setMidiProgram(index, true, false, true);
  594. return 0;
  595. }
  596. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  597. {
  598. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  599. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  600. const int32_t channel = argv[0]->i;
  601. const int32_t note = argv[1]->i;
  602. const int32_t velo = argv[2]->i;
  603. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  604. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  605. CARLA_SAFE_ASSERT_INT(velo >= 0 && velo < MAX_MIDI_VALUE, velo);
  606. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  607. return 1;
  608. if (note < 0 || note >= MAX_MIDI_NOTE)
  609. return 1;
  610. if (velo < 0 || velo >= MAX_MIDI_VALUE)
  611. return 1;
  612. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  613. return 0;
  614. }
  615. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  616. {
  617. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  618. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  619. const int32_t channel = argv[0]->i;
  620. const int32_t note = argv[1]->i;
  621. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  622. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  623. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  624. return 1;
  625. if (note < 0 || note >= MAX_MIDI_NOTE)
  626. return 1;
  627. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  628. return 0;
  629. }
  630. // FIXME - remove once IPC audio is implemented
  631. int CarlaEngineOsc::handleMsgBridgeSetPeaks(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  632. {
  633. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(4, "ffff");
  634. const float in1 = argv[0]->f;
  635. const float in2 = argv[1]->f;
  636. const float out1 = argv[2]->f;
  637. const float out2 = argv[3]->f;
  638. float const inPeaks[CarlaEngine::MAX_PEAKS] = { in1, in2 };
  639. float const outPeaks[CarlaEngine::MAX_PEAKS] = { out1, out2 };
  640. kEngine->setPeaks(plugin->id(), inPeaks, outPeaks);
  641. return 0;
  642. }
  643. #endif
  644. CARLA_BACKEND_END_NAMESPACE