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.

814 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. CARLA_BACKEND_START_NAMESPACE
  22. #ifndef BUILD_BRIDGE
  23. // -------------------------------------------------------------------
  24. // Bridge Helper, defined in plugin/CarlaBlugin.cpp
  25. extern int CarlaPluginSetOscBridgeInfo(CarlaPlugin* const plugin, const PluginBridgeInfoType type,
  26. const int argc, const lo_arg* const* const argv, const char* const types);
  27. #endif
  28. // -----------------------------------------------------------------------
  29. CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine)
  30. : kEngine(engine),
  31. fServerTCP(nullptr),
  32. fServerUDP(nullptr)
  33. {
  34. carla_debug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine);
  35. CARLA_ASSERT(engine != nullptr);
  36. }
  37. CarlaEngineOsc::~CarlaEngineOsc()
  38. {
  39. carla_debug("CarlaEngineOsc::~CarlaEngineOsc()");
  40. CARLA_ASSERT(fName.isEmpty());
  41. CARLA_ASSERT(fServerPathTCP.isEmpty());
  42. CARLA_ASSERT(fServerPathUDP.isEmpty());
  43. CARLA_ASSERT(fServerTCP == nullptr);
  44. CARLA_ASSERT(fServerUDP == nullptr);
  45. }
  46. // -----------------------------------------------------------------------
  47. void CarlaEngineOsc::init(const char* const name)
  48. {
  49. carla_debug("CarlaEngineOsc::init(\"%s\")", name);
  50. CARLA_ASSERT(fName.isEmpty());
  51. CARLA_ASSERT(fServerPathTCP.isEmpty());
  52. CARLA_ASSERT(fServerPathUDP.isEmpty());
  53. CARLA_ASSERT(fServerTCP == nullptr);
  54. CARLA_ASSERT(fServerUDP == nullptr);
  55. CARLA_ASSERT(name != nullptr);
  56. fName = name;
  57. fName.toBasic();
  58. fServerTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handler_TCP);
  59. if (fServerTCP != nullptr)
  60. {
  61. if (char* const tmpServerPathTCP = lo_server_get_url(fServerTCP))
  62. {
  63. fServerPathTCP = tmpServerPathTCP;
  64. fServerPathTCP += fName;
  65. std::free(tmpServerPathTCP);
  66. }
  67. lo_server_add_method(fServerTCP, nullptr, nullptr, osc_message_handler_TCP, this);
  68. }
  69. fServerUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handler_UDP);
  70. if (fServerUDP != nullptr)
  71. {
  72. if (char* const tmpServerPathUDP = lo_server_get_url(fServerUDP))
  73. {
  74. fServerPathUDP = tmpServerPathUDP;
  75. fServerPathUDP += fName;
  76. std::free(tmpServerPathUDP);
  77. }
  78. lo_server_add_method(fServerUDP, nullptr, nullptr, osc_message_handler_UDP, this);
  79. }
  80. CARLA_ASSERT(fName.isNotEmpty());
  81. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  82. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  83. CARLA_ASSERT(fServerTCP != nullptr);
  84. CARLA_ASSERT(fServerUDP != nullptr);
  85. }
  86. void CarlaEngineOsc::idle()
  87. {
  88. if (fServerTCP != nullptr)
  89. {
  90. while (lo_server_recv_noblock(fServerTCP, 0) != 0) {}
  91. }
  92. if (fServerUDP != nullptr)
  93. {
  94. while (lo_server_recv_noblock(fServerUDP, 0) != 0) {}
  95. }
  96. }
  97. void CarlaEngineOsc::close()
  98. {
  99. carla_debug("CarlaEngineOsc::close()");
  100. CARLA_ASSERT(fName.isNotEmpty());
  101. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  102. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  103. CARLA_ASSERT(fServerTCP != nullptr);
  104. CARLA_ASSERT(fServerUDP != nullptr);
  105. fName.clear();
  106. if (fServerTCP != nullptr)
  107. {
  108. lo_server_del_method(fServerTCP, nullptr, nullptr);
  109. lo_server_free(fServerTCP);
  110. fServerTCP = nullptr;
  111. }
  112. if (fServerUDP != nullptr)
  113. {
  114. lo_server_del_method(fServerUDP, nullptr, nullptr);
  115. lo_server_free(fServerUDP);
  116. fServerUDP = nullptr;
  117. }
  118. fServerPathTCP.clear();
  119. fServerPathUDP.clear();
  120. #ifndef BUILD_BRIDGE
  121. fControlData.free();
  122. #endif
  123. CARLA_ASSERT(fName.isEmpty());
  124. CARLA_ASSERT(fServerPathTCP.isEmpty());
  125. CARLA_ASSERT(fServerPathUDP.isEmpty());
  126. CARLA_ASSERT(fServerTCP == nullptr);
  127. CARLA_ASSERT(fServerUDP == nullptr);
  128. }
  129. // -----------------------------------------------------------------------
  130. bool isDigit(const char c)
  131. {
  132. return (c >= '0' && c <= '9');
  133. }
  134. 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)
  135. {
  136. carla_debug("CarlaEngineOsc::handleMessage(%s, \"%s\", %i, %p, \"%s\", %p)", bool2str(isTCP), path, argc, argv, types, msg);
  137. CARLA_ASSERT(fName.isNotEmpty());
  138. CARLA_ASSERT(fServerPathTCP.isNotEmpty());
  139. CARLA_ASSERT(fServerPathUDP.isNotEmpty());
  140. CARLA_ASSERT(fServerTCP != nullptr);
  141. CARLA_ASSERT(fServerUDP != nullptr);
  142. CARLA_ASSERT(path != nullptr);
  143. if (path == nullptr)
  144. {
  145. carla_stderr("CarlaEngineOsc::handleMessage() - got invalid path");
  146. return 1;
  147. }
  148. if (fName.isEmpty())
  149. {
  150. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message but client is offline", bool2str(isTCP), path);
  151. return 1;
  152. }
  153. #ifndef BUILD_BRIDGE
  154. // Initial path check
  155. if (std::strcmp(path, "/register") == 0)
  156. {
  157. const lo_address source = lo_message_get_source(msg);
  158. return handleMsgRegister(isTCP, argc, argv, types, source);
  159. }
  160. if (std::strcmp(path, "/unregister") == 0)
  161. {
  162. return handleMsgUnregister();
  163. }
  164. #endif
  165. const size_t nameSize = fName.length();
  166. // Check if message is for this client
  167. if (std::strlen(path) <= nameSize || std::strncmp(path+1, (const char*)fName, nameSize) != 0)
  168. {
  169. carla_stderr("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, (const char*)fName);
  170. return 1;
  171. }
  172. // Get plugin id from message
  173. // eg, /carla/23/method
  174. unsigned int pluginId = 0;
  175. size_t offset;
  176. if (isDigit(path[nameSize+2]))
  177. {
  178. if (isDigit(path[nameSize+3]))
  179. {
  180. if (isDigit(path[nameSize+5]))
  181. {
  182. carla_stderr2("CarlaEngineOsc::handleMessage() - invalid plugin id, over 999? (value: \"%s\")", path+nameSize);
  183. return 1;
  184. }
  185. else if (isDigit(path[nameSize+4]))
  186. {
  187. // 3 digits, /xyz/method
  188. offset = 6;
  189. pluginId += (path[nameSize+2]-'0')*100;
  190. pluginId += (path[nameSize+3]-'0')*10;
  191. pluginId += (path[nameSize+4]-'0');
  192. }
  193. else
  194. {
  195. // 2 digits, /xy/method
  196. offset = 5;
  197. pluginId += (path[nameSize+2]-'0')*10;
  198. pluginId += (path[nameSize+3]-'0');
  199. }
  200. }
  201. else
  202. {
  203. // single digit, /x/method
  204. offset = 4;
  205. pluginId += path[nameSize+2]-'0';
  206. }
  207. }
  208. else
  209. {
  210. carla_stderr("CarlaEngineOsc::handleMessage() - invalid message '%s'", path);
  211. return 1;
  212. }
  213. if (pluginId > kEngine->currentPluginCount())
  214. {
  215. carla_stderr("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId);
  216. return 1;
  217. }
  218. // Get plugin
  219. CarlaPlugin* const plugin = kEngine->getPluginUnchecked(pluginId);
  220. if (plugin == nullptr || plugin->id() != pluginId)
  221. {
  222. carla_stderr("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed", pluginId);
  223. return 1;
  224. }
  225. // Get method from path, "/Carla/i/method" -> "method"
  226. char method[32] = { 0 };
  227. std::strncpy(method, path + (nameSize + offset), 31);
  228. if (method[0] == '\0')
  229. {
  230. carla_stderr("CarlaEngineOsc::handleMessage(%s, \"%s\", ...) - received message without method", bool2str(isTCP), path);
  231. return 1;
  232. }
  233. // Common OSC methods (DSSI and bridge UIs)
  234. if (std::strcmp(method, "update") == 0)
  235. {
  236. const lo_address source = lo_message_get_source(msg);
  237. return handleMsgUpdate(plugin, argc, argv, types, source);
  238. }
  239. if (std::strcmp(method, "configure") == 0)
  240. return handleMsgConfigure(plugin, argc, argv, types);
  241. if (std::strcmp(method, "control") == 0)
  242. return handleMsgControl(plugin, argc, argv, types);
  243. if (std::strcmp(method, "program") == 0)
  244. return handleMsgProgram(plugin, argc, argv, types);
  245. if (std::strcmp(method, "midi") == 0)
  246. return handleMsgMidi(plugin, argc, argv, types);
  247. if (std::strcmp(method, "exiting") == 0)
  248. return handleMsgExiting(plugin);
  249. #ifndef BUILD_BRIDGE
  250. // Internal methods
  251. if (std::strcmp(method, "set_active") == 0)
  252. return handleMsgSetActive(plugin, argc, argv, types);
  253. if (std::strcmp(method, "set_drywet") == 0)
  254. return handleMsgSetDryWet(plugin, argc, argv, types);
  255. if (std::strcmp(method, "set_volume") == 0)
  256. return handleMsgSetVolume(plugin, argc, argv, types);
  257. if (std::strcmp(method, "set_balance_left") == 0)
  258. return handleMsgSetBalanceLeft(plugin, argc, argv, types);
  259. if (std::strcmp(method, "set_balance_right") == 0)
  260. return handleMsgSetBalanceRight(plugin, argc, argv, types);
  261. if (std::strcmp(method, "set_panning") == 0)
  262. return handleMsgSetPanning(plugin, argc, argv, types);
  263. if (std::strcmp(method, "set_parameter_value") == 0)
  264. return handleMsgSetParameterValue(plugin, argc, argv, types);
  265. if (std::strcmp(method, "set_parameter_midi_cc") == 0)
  266. return handleMsgSetParameterMidiCC(plugin, argc, argv, types);
  267. if (std::strcmp(method, "set_parameter_midi_channel") == 0)
  268. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  269. if (std::strcmp(method, "set_program") == 0)
  270. return handleMsgSetProgram(plugin, argc, argv, types);
  271. if (std::strcmp(method, "set_midi_program") == 0)
  272. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  273. if (std::strcmp(method, "note_on") == 0)
  274. return handleMsgNoteOn(plugin, argc, argv, types);
  275. if (std::strcmp(method, "note_off") == 0)
  276. return handleMsgNoteOff(plugin, argc, argv, types);
  277. // Plugin Bridges
  278. if ((plugin->hints() & PLUGIN_IS_BRIDGE) > 0 && std::strlen(method) > 11 && std::strncmp(method, "bridge_", 7) == 0)
  279. {
  280. if (std::strcmp(method+7, "set_peaks") == 0)
  281. return handleMsgBridgeSetPeaks(plugin, argc, argv, types);
  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, FIXME
  325. #if 0 //def WANT_LV2
  326. if (std::strcmp(method, "lv2_atom_transfer") == 0)
  327. return handleMsgLv2AtomTransfer(plugin, argc, argv, types);
  328. if (std::strcmp(method, "lv2_event_transfer") == 0)
  329. return handleMsgLv2EventTransfer(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 short i=0; i < kEngine->currentPluginCount(); i++)
  361. {
  362. CarlaPlugin* const plugin = kEngine->getPluginUnchecked(i);
  363. if (plugin && plugin->enabled())
  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_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->setParameterValueByRIndex(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->programCount()))
  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. if (plugin->midiInCount() == 0)
  445. {
  446. carla_stderr("CarlaEngineOsc::handleMsgMidi() - recived midi when plugin has no midi inputs");
  447. return 1;
  448. }
  449. const uint8_t* const data = argv[0]->m;
  450. uint8_t status = data[1];
  451. uint8_t channel = status & 0x0F;
  452. // Fix bad note-off
  453. if (MIDI_IS_STATUS_NOTE_ON(status) && data[3] == 0)
  454. status -= 0x10;
  455. if (MIDI_IS_STATUS_NOTE_OFF(status))
  456. {
  457. const uint8_t note = data[2];
  458. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  459. if (note >= MAX_MIDI_NOTE)
  460. return 1;
  461. plugin->sendMidiSingleNote(channel, note, 0, false, true, true);
  462. }
  463. else if (MIDI_IS_STATUS_NOTE_ON(status))
  464. {
  465. const uint8_t note = data[2];
  466. const uint8_t velo = data[3];
  467. CARLA_SAFE_ASSERT_INT(note < MAX_MIDI_NOTE, note);
  468. CARLA_SAFE_ASSERT_INT(velo < MAX_MIDI_VALUE, velo);
  469. if (note >= MAX_MIDI_NOTE)
  470. return 1;
  471. if (velo >= MAX_MIDI_VALUE)
  472. return 1;
  473. plugin->sendMidiSingleNote(channel, note, velo, false, true, true);
  474. }
  475. return 0;
  476. }
  477. int CarlaEngineOsc::handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1)
  478. {
  479. carla_debug("CarlaEngineOsc::handleMsgExiting()");
  480. // TODO - check for non-UIs (dssi-vst) and set to -1 instead
  481. kEngine->callback(CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0f, nullptr);
  482. plugin->freeOscData();
  483. return 0;
  484. }
  485. // -----------------------------------------------------------------------
  486. #ifndef BUILD_BRIDGE
  487. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  488. {
  489. carla_debug("CarlaEngineOsc::handleMsgSetActive()");
  490. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  491. const bool active = (argv[0]->i != 0);
  492. plugin->setActive(active, false, true);
  493. return 0;
  494. }
  495. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  496. {
  497. carla_debug("CarlaEngineOsc::handleMsgSetDryWet()");
  498. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  499. const float value = argv[0]->f;
  500. plugin->setDryWet(value, false, true);
  501. return 0;
  502. }
  503. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  504. {
  505. carla_debug("CarlaEngineOsc::handleMsgSetVolume()");
  506. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  507. const float value = argv[0]->f;
  508. plugin->setVolume(value, false, true);
  509. return 0;
  510. }
  511. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  512. {
  513. carla_debug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  514. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  515. const float value = argv[0]->f;
  516. plugin->setBalanceLeft(value, false, true);
  517. return 0;
  518. }
  519. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  520. {
  521. carla_debug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  522. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  523. const float value = argv[0]->f;
  524. plugin->setBalanceRight(value, false, true);
  525. return 0;
  526. }
  527. int CarlaEngineOsc::handleMsgSetPanning(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  528. {
  529. carla_debug("CarlaEngineOsc::handleMsgSetPanning()");
  530. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  531. const float value = argv[0]->f;
  532. plugin->setPanning(value, false, true);
  533. return 0;
  534. }
  535. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  536. {
  537. carla_debug("CarlaEngineOsc::handleMsgSetParameterValue()");
  538. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  539. const int32_t index = argv[0]->i;
  540. const float value = argv[1]->f;
  541. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  542. if (index < 0)
  543. return 1;
  544. plugin->setParameterValue(static_cast<uint32_t>(index), value, true, false, true);
  545. return 0;
  546. }
  547. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  548. {
  549. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  550. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  551. const int32_t index = argv[0]->i;
  552. const int32_t cc = argv[1]->i;
  553. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  554. CARLA_SAFE_ASSERT_INT(cc >= -1 && cc <= 0x5F, cc);
  555. if (index < 0)
  556. return 1;
  557. if (cc < -1 || cc > 0x5F)
  558. return 1;
  559. plugin->setParameterMidiCC(static_cast<uint32_t>(index), static_cast<int16_t>(cc), false, true);
  560. return 0;
  561. }
  562. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  563. {
  564. carla_debug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  565. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  566. const int32_t index = argv[0]->i;
  567. const int32_t channel = argv[1]->i;
  568. CARLA_SAFE_ASSERT_INT(index >= 0, index);
  569. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  570. if (index < 0)
  571. return 1;
  572. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  573. return 1;
  574. plugin->setParameterMidiChannel(static_cast<uint32_t>(index), static_cast<uint8_t>(channel), false, true);
  575. return 0;
  576. }
  577. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  578. {
  579. carla_debug("CarlaEngineOsc::handleMsgSetProgram()");
  580. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  581. const int32_t index = argv[0]->i;
  582. plugin->setProgram(index, true, false, true);
  583. return 0;
  584. }
  585. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  586. {
  587. carla_debug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  588. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  589. const int32_t index = argv[0]->i;
  590. plugin->setMidiProgram(index, true, false, true);
  591. return 0;
  592. }
  593. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  594. {
  595. carla_debug("CarlaEngineOsc::handleMsgNoteOn()");
  596. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  597. const int32_t channel = argv[0]->i;
  598. const int32_t note = argv[1]->i;
  599. const int32_t velo = argv[2]->i;
  600. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  601. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  602. CARLA_SAFE_ASSERT_INT(velo >= 0 && velo < MAX_MIDI_VALUE, velo);
  603. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  604. return 1;
  605. if (note < 0 || note >= MAX_MIDI_NOTE)
  606. return 1;
  607. if (velo < 0 || velo >= MAX_MIDI_VALUE)
  608. return 1;
  609. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), static_cast<uint8_t>(velo), true, false, true);
  610. return 0;
  611. }
  612. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  613. {
  614. carla_debug("CarlaEngineOsc::handleMsgNoteOff()");
  615. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  616. const int32_t channel = argv[0]->i;
  617. const int32_t note = argv[1]->i;
  618. CARLA_SAFE_ASSERT_INT(channel >= 0 && channel < MAX_MIDI_CHANNELS, channel);
  619. CARLA_SAFE_ASSERT_INT(note >= 0 && note < MAX_MIDI_NOTE, note);
  620. if (channel < 0 || channel >= MAX_MIDI_CHANNELS)
  621. return 1;
  622. if (note < 0 || note >= MAX_MIDI_NOTE)
  623. return 1;
  624. plugin->sendMidiSingleNote(static_cast<uint8_t>(channel), static_cast<uint8_t>(note), 0, true, false, true);
  625. return 0;
  626. }
  627. // FIXME - remove once IPC audio is implemented
  628. int CarlaEngineOsc::handleMsgBridgeSetPeaks(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  629. {
  630. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(4, "ffff");
  631. const float in1 = argv[0]->f;
  632. const float in2 = argv[1]->f;
  633. const float out1 = argv[2]->f;
  634. const float out2 = argv[3]->f;
  635. float const inPeaks[CarlaEngine::MAX_PEAKS] = { in1, in2 };
  636. float const outPeaks[CarlaEngine::MAX_PEAKS] = { out1, out2 };
  637. kEngine->setPeaks(plugin->id(), inPeaks, outPeaks);
  638. return 0;
  639. }
  640. #endif
  641. CARLA_BACKEND_END_NAMESPACE