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.

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