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.

688 lines
21KB

  1. /*
  2. * Carla Engine OSC
  3. * Copyright (C) 2011-2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #include "carla_engine.hpp"
  18. #include "carla_engine_osc.hpp"
  19. #include "carla_plugin.hpp"
  20. #include "carla_midi.h"
  21. #include <QtCore/QString>
  22. CARLA_BACKEND_START_NAMESPACE
  23. // -----------------------------------------------------------------------
  24. CarlaEngineOsc::CarlaEngineOsc(CarlaEngine* const engine_)
  25. : engine(engine_)
  26. {
  27. qDebug("CarlaEngineOsc::CarlaEngineOsc(%p)", engine);
  28. CARLA_ASSERT(engine);
  29. m_name = nullptr;
  30. m_nameSize = 0;
  31. m_serverTCP = nullptr;
  32. m_serverUDP = nullptr;
  33. }
  34. CarlaEngineOsc::~CarlaEngineOsc()
  35. {
  36. qDebug("CarlaEngineOsc::~CarlaEngineOsc()");
  37. CARLA_ASSERT(! m_name);
  38. CARLA_ASSERT(! m_serverTCP);
  39. CARLA_ASSERT(! m_serverUDP);
  40. }
  41. // -----------------------------------------------------------------------
  42. void CarlaEngineOsc::init(const char* const name)
  43. {
  44. qDebug("CarlaEngineOsc::init(\"%s\")", name);
  45. CARLA_ASSERT(! m_name);
  46. CARLA_ASSERT(! m_serverTCP);
  47. CARLA_ASSERT(! m_serverUDP);
  48. CARLA_ASSERT(m_nameSize == 0);
  49. CARLA_ASSERT(m_serverPathTCP.isEmpty());
  50. CARLA_ASSERT(m_serverPathUDP.isEmpty());
  51. CARLA_ASSERT(name);
  52. m_name = strdup(name ? name : "");
  53. m_nameSize = strlen(m_name);
  54. m_serverTCP = lo_server_new_with_proto(nullptr, LO_TCP, osc_error_handlerTCP);
  55. m_serverUDP = lo_server_new_with_proto(nullptr, LO_UDP, osc_error_handlerUDP);
  56. if (m_serverTCP)
  57. {
  58. if (char* const serverPathTCP = lo_server_get_url(m_serverTCP))
  59. {
  60. m_serverPathTCP = serverPathTCP;
  61. m_serverPathTCP += m_name;
  62. free(serverPathTCP);
  63. }
  64. lo_server_add_method(m_serverTCP, nullptr, nullptr, osc_message_handler, this);
  65. }
  66. if (m_serverUDP)
  67. {
  68. if (char* const serverPathUDP = lo_server_get_url(m_serverUDP))
  69. {
  70. m_serverPathUDP = serverPathUDP;
  71. m_serverPathUDP += m_name;
  72. free(serverPathUDP);
  73. }
  74. lo_server_add_method(m_serverUDP, nullptr, nullptr, osc_message_handler, this);
  75. }
  76. }
  77. void CarlaEngineOsc::idle()
  78. {
  79. if (m_serverTCP)
  80. {
  81. while (lo_server_recv_noblock(m_serverTCP, 0) != 0) {}
  82. }
  83. if (m_serverUDP)
  84. {
  85. while (lo_server_recv_noblock(m_serverUDP, 0) != 0) {}
  86. }
  87. }
  88. void CarlaEngineOsc::close()
  89. {
  90. qDebug("CarlaEngineOsc::close()");
  91. CARLA_ASSERT(m_name);
  92. CARLA_ASSERT(m_serverTCP);
  93. CARLA_ASSERT(m_serverUDP);
  94. CARLA_ASSERT(m_serverPathTCP.isNotEmpty());
  95. CARLA_ASSERT(m_serverPathUDP.isNotEmpty());
  96. m_nameSize = 0;
  97. if (m_name)
  98. {
  99. free(m_name);
  100. m_name = nullptr;
  101. }
  102. if (m_serverTCP)
  103. {
  104. lo_server_del_method(m_serverTCP, nullptr, nullptr);
  105. lo_server_free(m_serverTCP);
  106. m_serverTCP = nullptr;
  107. }
  108. if (m_serverUDP)
  109. {
  110. lo_server_del_method(m_serverUDP, nullptr, nullptr);
  111. lo_server_free(m_serverUDP);
  112. m_serverUDP = nullptr;
  113. }
  114. m_serverPathTCP.clear();
  115. m_serverPathUDP.clear();
  116. #ifndef BUILD_BRIDGE
  117. m_controlData.free();
  118. #endif
  119. }
  120. // -----------------------------------------------------------------------
  121. int CarlaEngineOsc::handleMessage(const char* const path, const int argc, const lo_arg* const* const argv, const char* const types, const lo_message msg)
  122. {
  123. #if DEBUG
  124. if (! QString(path).endsWith("peak"))
  125. qDebug("CarlaEngineOsc::handleMessage(%s, %i, %p, %s, %p)", path, argc, argv, types, msg);
  126. #endif
  127. CARLA_ASSERT(m_name);
  128. CARLA_ASSERT(m_serverTCP || m_serverUDP);
  129. CARLA_ASSERT(m_serverPathTCP.isNotEmpty() || m_serverPathUDP.isNotEmpty());
  130. CARLA_ASSERT(path);
  131. if (! path)
  132. {
  133. qCritical("CarlaEngineOsc::handleMessage() - got invalid path");
  134. return 1;
  135. }
  136. if (! m_name)
  137. {
  138. qCritical("CarlaEngineOsc::handleMessage(\"%s\", ...) - received message but client is offline", path);
  139. return 1;
  140. }
  141. #ifndef BUILD_BRIDGE
  142. // Initial path check
  143. if (strcmp(path, "/register") == 0)
  144. {
  145. const lo_address source = lo_message_get_source(msg);
  146. return handleMsgRegister(argc, argv, types, source);
  147. }
  148. if (strcmp(path, "/unregister") == 0)
  149. {
  150. return handleMsgUnregister();
  151. }
  152. #endif
  153. // Check if message is for this client
  154. if (strlen(path) <= m_nameSize || strncmp(path+1, m_name, m_nameSize) != 0)
  155. {
  156. qWarning("CarlaEngineOsc::handleMessage() - message not for this client -> '%s' != '/%s/'", path, m_name);
  157. return 1;
  158. }
  159. // Get plugin id from message
  160. int pluginId = 0;
  161. if (std::isdigit(path[m_nameSize+2]))
  162. pluginId += path[m_nameSize+2]-'0';
  163. if (std::isdigit(path[m_nameSize+3]))
  164. pluginId += (path[m_nameSize+3]-'0')*10;
  165. if (pluginId < 0 || pluginId > engine->maxPluginNumber())
  166. {
  167. qCritical("CarlaEngineOsc::handleMessage() - failed to get plugin, wrong id '%i'", pluginId);
  168. return 1;
  169. }
  170. // Get plugin
  171. CarlaPlugin* const plugin = engine->getPluginUnchecked(pluginId);
  172. if (plugin == nullptr || plugin->id() != pluginId)
  173. {
  174. qWarning("CarlaEngineOsc::handleMessage() - invalid plugin id '%i', probably has been removed", pluginId);
  175. return 1;
  176. }
  177. // Get method from path, "/Carla/i/method"
  178. const int offset = (pluginId >= 10) ? 5 : 4;
  179. char method[32] = { 0 };
  180. strncpy(method, path + (m_nameSize + offset), 31);
  181. if (method[0] == '\0')
  182. {
  183. qWarning("CarlaEngineOsc::handleMessage(\"%s\", ...) - received message without method", path);
  184. return 1;
  185. }
  186. // Common OSC methods (DSSI and internal UIs)
  187. if (strcmp(method, "update") == 0)
  188. {
  189. const lo_address source = lo_message_get_source(msg);
  190. return handleMsgUpdate(plugin, argc, argv, types, source);
  191. }
  192. if (strcmp(method, "configure") == 0)
  193. return handleMsgConfigure(plugin, argc, argv, types);
  194. if (strcmp(method, "control") == 0)
  195. return handleMsgControl(plugin, argc, argv, types);
  196. if (strcmp(method, "program") == 0)
  197. return handleMsgProgram(plugin, argc, argv, types);
  198. if (strcmp(method, "midi") == 0)
  199. return handleMsgMidi(plugin, argc, argv, types);
  200. if (strcmp(method, "exiting") == 0)
  201. return handleMsgExiting(plugin);
  202. #ifndef BUILD_BRIDGE
  203. // Internal methods
  204. if (strcmp(method, "set_active") == 0)
  205. return handleMsgSetActive(plugin, argc, argv, types);
  206. if (strcmp(method, "set_drywet") == 0)
  207. return handleMsgSetDryWet(plugin, argc, argv, types);
  208. if (strcmp(method, "set_volume") == 0)
  209. return handleMsgSetVolume(plugin, argc, argv, types);
  210. if (strcmp(method, "set_balance_left") == 0)
  211. return handleMsgSetBalanceLeft(plugin, argc, argv, types);
  212. if (strcmp(method, "set_balance_right") == 0)
  213. return handleMsgSetBalanceRight(plugin, argc, argv, types);
  214. if (strcmp(method, "set_parameter_value") == 0)
  215. return handleMsgSetParameterValue(plugin, argc, argv, types);
  216. if (strcmp(method, "set_parameter_midi_cc") == 0)
  217. return handleMsgSetParameterMidiCC(plugin, argc, argv, types);
  218. if (strcmp(method, "set_parameter_midi_channel") == 0)
  219. return handleMsgSetParameterMidiChannel(plugin, argc, argv, types);
  220. if (strcmp(method, "set_program") == 0)
  221. return handleMsgSetProgram(plugin, argc, argv, types);
  222. if (strcmp(method, "set_midi_program") == 0)
  223. return handleMsgSetMidiProgram(plugin, argc, argv, types);
  224. if (strcmp(method, "note_on") == 0)
  225. return handleMsgNoteOn(plugin, argc, argv, types);
  226. if (strcmp(method, "note_off") == 0)
  227. return handleMsgNoteOff(plugin, argc, argv, types);
  228. // Plugin Bridges
  229. if ((plugin->hints() & PLUGIN_IS_BRIDGE) > 0 && strlen(method) > 11 && strncmp(method, "bridge_", 7) == 0)
  230. {
  231. if (strcmp(method+7, "set_inpeak") == 0)
  232. return handleMsgBridgeSetInPeak(plugin, argc, argv, types);
  233. if (strcmp(method+7, "set_outpeak") == 0)
  234. return handleMsgBridgeSetOutPeak(plugin, argc, argv, types);
  235. if (strcmp(method+7, "audio_count") == 0)
  236. return plugin->setOscBridgeInfo(PluginBridgeAudioCount, argc, argv, types);
  237. if (strcmp(method+7, "midi_count") == 0)
  238. return plugin->setOscBridgeInfo(PluginBridgeMidiCount, argc, argv, types);
  239. if (strcmp(method+7, "parameter_count") == 0)
  240. return plugin->setOscBridgeInfo(PluginBridgeParameterCount, argc, argv, types);
  241. if (strcmp(method+7, "program_count") == 0)
  242. return plugin->setOscBridgeInfo(PluginBridgeProgramCount, argc, argv, types);
  243. if (strcmp(method+7, "midi_program_count") == 0)
  244. return plugin->setOscBridgeInfo(PluginBridgeMidiProgramCount, argc, argv, types);
  245. if (strcmp(method+7, "plugin_info") == 0)
  246. return plugin->setOscBridgeInfo(PluginBridgePluginInfo, argc, argv, types);
  247. if (strcmp(method+7, "parameter_info") == 0)
  248. return plugin->setOscBridgeInfo(PluginBridgeParameterInfo, argc, argv, types);
  249. if (strcmp(method+7, "parameter_data") == 0)
  250. return plugin->setOscBridgeInfo(PluginBridgeParameterData, argc, argv, types);
  251. if (strcmp(method+7, "parameter_ranges") == 0)
  252. return plugin->setOscBridgeInfo(PluginBridgeParameterRanges, argc, argv, types);
  253. if (strcmp(method+7, "program_info") == 0)
  254. return plugin->setOscBridgeInfo(PluginBridgeProgramInfo, argc, argv, types);
  255. if (strcmp(method+7, "midi_program_info") == 0)
  256. return plugin->setOscBridgeInfo(PluginBridgeMidiProgramInfo, argc, argv, types);
  257. if (strcmp(method+7, "configure") == 0)
  258. return plugin->setOscBridgeInfo(PluginBridgeConfigure, argc, argv, types);
  259. if (strcmp(method+7, "set_parameter_value") == 0)
  260. return plugin->setOscBridgeInfo(PluginBridgeSetParameterValue, argc, argv, types);
  261. if (strcmp(method+7, "set_default_value") == 0)
  262. return plugin->setOscBridgeInfo(PluginBridgeSetDefaultValue, argc, argv, types);
  263. if (strcmp(method+7, "set_program") == 0)
  264. return plugin->setOscBridgeInfo(PluginBridgeSetProgram, argc, argv, types);
  265. if (strcmp(method+7, "set_midi_program") == 0)
  266. return plugin->setOscBridgeInfo(PluginBridgeSetMidiProgram, argc, argv, types);
  267. if (strcmp(method+7, "set_custom_data") == 0)
  268. return plugin->setOscBridgeInfo(PluginBridgeSetCustomData, argc, argv, types);
  269. if (strcmp(method+7, "set_chunk_data") == 0)
  270. return plugin->setOscBridgeInfo(PluginBridgeSetChunkData, argc, argv, types);
  271. if (strcmp(method+7, "update") == 0)
  272. return plugin->setOscBridgeInfo(PluginBridgeUpdateNow, argc, argv, types);
  273. if (strcmp(method+7, "error") == 0)
  274. return plugin->setOscBridgeInfo(PluginBridgeError, argc, argv, types);
  275. }
  276. #endif
  277. // Plugin-specific methods
  278. #ifdef WANT_LV2
  279. if (strcmp(method, "lv2_atom_transfer") == 0)
  280. return handleMsgLv2AtomTransfer(plugin, argc, argv, types);
  281. if (strcmp(method, "lv2_event_transfer") == 0)
  282. return handleMsgLv2EventTransfer(plugin, argc, argv, types);
  283. #endif
  284. qWarning("CarlaEngineOsc::handleMessage() - unsupported OSC method '%s'", method);
  285. return 1;
  286. }
  287. // -----------------------------------------------------------------------
  288. #ifndef BUILD_BRIDGE
  289. int CarlaEngineOsc::handleMsgRegister(const int argc, const lo_arg* const* const argv, const char* const types, const lo_address source)
  290. {
  291. qDebug("CarlaEngineOsc::handleMsgRegister()");
  292. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  293. if (m_controlData.path)
  294. {
  295. qWarning("CarlaEngineOsc::handleMsgRegister() - OSC backend already registered to %s", m_controlData.path);
  296. return 1;
  297. }
  298. const char* const url = (const char*)&argv[0]->s;
  299. const char* host;
  300. const char* port;
  301. qDebug("CarlaEngineOsc::handleMsgRegister() - OSC backend registered to %s", url);
  302. host = lo_address_get_hostname(source);
  303. port = lo_address_get_port(source);
  304. m_controlData.source = lo_address_new_with_proto(LO_TCP, host, port);
  305. host = lo_url_get_hostname(url);
  306. port = lo_url_get_port(url);
  307. m_controlData.path = lo_url_get_path(url);
  308. m_controlData.target = lo_address_new_with_proto(LO_TCP, host, port);
  309. free((void*)host);
  310. free((void*)port);
  311. for (unsigned short i=0; i < engine->maxPluginNumber(); i++)
  312. {
  313. CarlaPlugin* const plugin = engine->getPluginUnchecked(i);
  314. if (plugin && plugin->enabled())
  315. plugin->registerToOscClient();
  316. }
  317. return 0;
  318. }
  319. int CarlaEngineOsc::handleMsgUnregister()
  320. {
  321. qDebug("CarlaEngineOsc::handleMsgUnregister()");
  322. if (! m_controlData.path)
  323. {
  324. qWarning("CarlaEngineOsc::handleMsgUnregister() - OSC backend is not registered yet");
  325. return 1;
  326. }
  327. m_controlData.free();
  328. return 0;
  329. }
  330. #endif
  331. // -----------------------------------------------------------------------
  332. int CarlaEngineOsc::handleMsgUpdate(CARLA_ENGINE_OSC_HANDLE_ARGS2, const lo_address source)
  333. {
  334. qDebug("CarlaEngineOsc::handleMsgUpdate()");
  335. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "s");
  336. const char* const url = (const char*)&argv[0]->s;
  337. plugin->updateOscData(source, url);
  338. return 0;
  339. }
  340. int CarlaEngineOsc::handleMsgConfigure(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  341. {
  342. qDebug("CarlaEngineOsc::handleMsgConfigure()");
  343. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ss");
  344. const char* const key = (const char*)&argv[0]->s;
  345. const char* const value = (const char*)&argv[1]->s;
  346. #ifdef DEBUG
  347. qDebug("CarlaEngineOsc::handleMsgConfigure(\"%s\", \"%s\")", key, value);
  348. #endif
  349. plugin->setCustomData(CUSTOM_DATA_STRING, key, value, false);
  350. return 0;
  351. }
  352. int CarlaEngineOsc::handleMsgControl(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  353. {
  354. qDebug("CarlaEngineOsc::handleMsgControl()");
  355. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  356. const int rindex = argv[0]->i;
  357. const float value = argv[1]->f;
  358. plugin->setParameterValueByRIndex(rindex, value, false, true, true);
  359. return 0;
  360. }
  361. int CarlaEngineOsc::handleMsgProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  362. {
  363. qDebug("CarlaEngineOsc::handleMsgProgram()");
  364. if (argc == 2)
  365. {
  366. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  367. const uint32_t bank_id = argv[0]->i;
  368. const uint32_t program_id = argv[1]->i;
  369. plugin->setMidiProgramById(bank_id, program_id, false, true, true, true);
  370. return 0;
  371. }
  372. else
  373. {
  374. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  375. const uint32_t program_id = argv[0]->i;
  376. if (program_id < plugin->programCount())
  377. {
  378. plugin->setProgram(program_id, false, true, true, true);
  379. return 0;
  380. }
  381. qCritical("CarlaEngineOsc::handleMsgProgram() - program_id '%i' out of bounds", program_id);
  382. }
  383. return 1;
  384. }
  385. int CarlaEngineOsc::handleMsgMidi(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  386. {
  387. qDebug("CarlaEngineOsc::handleMsgMidi()");
  388. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "m");
  389. if (plugin->midiInCount() > 0)
  390. {
  391. const uint8_t* const data = argv[0]->m;
  392. uint8_t status = data[1];
  393. uint8_t channel = status & 0x0F;
  394. // Fix bad note-off
  395. if (MIDI_IS_STATUS_NOTE_ON(status) && data[3] == 0)
  396. status -= 0x10;
  397. if (MIDI_IS_STATUS_NOTE_OFF(status))
  398. {
  399. uint8_t note = data[2];
  400. plugin->sendMidiSingleNote(channel, note, 0, false, true, true);
  401. }
  402. else if (MIDI_IS_STATUS_NOTE_ON(status))
  403. {
  404. uint8_t note = data[2];
  405. uint8_t velo = data[3];
  406. plugin->sendMidiSingleNote(channel, note, velo, false, true, true);
  407. }
  408. return 0;
  409. }
  410. qWarning("CarlaEngineOsc::handleMsgMidi() - recived midi when plugin has no midi inputs");
  411. return 1;
  412. }
  413. int CarlaEngineOsc::handleMsgExiting(CARLA_ENGINE_OSC_HANDLE_ARGS1)
  414. {
  415. qDebug("CarlaEngineOsc::handleMsgExiting()");
  416. // TODO - check for non-UIs (dssi-vst) and set to -1 instead
  417. engine->callback(CALLBACK_SHOW_GUI, plugin->id(), 0, 0, 0.0, nullptr);
  418. plugin->freeOscData();
  419. return 0;
  420. }
  421. // -----------------------------------------------------------------------
  422. #ifndef BUILD_BRIDGE
  423. int CarlaEngineOsc::handleMsgSetActive(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  424. {
  425. qDebug("CarlaEngineOsc::handleMsgSetActive()");
  426. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  427. const bool active = (bool)argv[0]->i;
  428. plugin->setActive(active, false, true);
  429. return 0;
  430. }
  431. int CarlaEngineOsc::handleMsgSetDryWet(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  432. {
  433. qDebug("CarlaEngineOsc::handleMsgSetDryWet()");
  434. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  435. const float value = argv[0]->f;
  436. plugin->setDryWet(value, false, true);
  437. return 0;
  438. }
  439. int CarlaEngineOsc::handleMsgSetVolume(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  440. {
  441. qDebug("CarlaEngineOsc::handleMsgSetVolume()");
  442. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  443. const float value = argv[0]->f;
  444. plugin->setVolume(value, false, true);
  445. return 0;
  446. }
  447. int CarlaEngineOsc::handleMsgSetBalanceLeft(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  448. {
  449. qDebug("CarlaEngineOsc::handleMsgSetBalanceLeft()");
  450. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  451. const float value = argv[0]->f;
  452. plugin->setBalanceLeft(value, false, true);
  453. return 0;
  454. }
  455. int CarlaEngineOsc::handleMsgSetBalanceRight(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  456. {
  457. qDebug("CarlaEngineOsc::handleMsgSetBalanceRight()");
  458. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "f");
  459. const float value = argv[0]->f;
  460. plugin->setBalanceRight(value, false, true);
  461. return 0;
  462. }
  463. int CarlaEngineOsc::handleMsgSetParameterValue(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  464. {
  465. qDebug("CarlaEngineOsc::handleMsgSetParameterValue()");
  466. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "if");
  467. const int32_t index = argv[0]->i;
  468. const float value = argv[1]->f;
  469. plugin->setParameterValue(index, value, true, false, true);
  470. return 0;
  471. }
  472. int CarlaEngineOsc::handleMsgSetParameterMidiCC(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  473. {
  474. qDebug("CarlaEngineOsc::handleMsgSetParameterMidiCC()");
  475. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  476. const int32_t index = argv[0]->i;
  477. const int32_t cc = argv[1]->i;
  478. plugin->setParameterMidiCC(index, cc, false, true);
  479. return 0;
  480. }
  481. int CarlaEngineOsc::handleMsgSetParameterMidiChannel(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  482. {
  483. qDebug("CarlaEngineOsc::handleMsgSetParameterMidiChannel()");
  484. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  485. const int32_t index = argv[0]->i;
  486. const int32_t channel = argv[1]->i;
  487. plugin->setParameterMidiChannel(index, channel, false, true);
  488. return 0;
  489. }
  490. int CarlaEngineOsc::handleMsgSetProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  491. {
  492. qDebug("CarlaEngineOsc::handleMsgSetProgram()");
  493. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  494. const int32_t index = argv[0]->i;
  495. plugin->setProgram(index, true, false, true, true);
  496. // parameters might have changed, send all param values back
  497. if (m_controlData.target && index >= 0)
  498. {
  499. for (uint32_t i=0; i < plugin->parameterCount(); i++)
  500. engine->osc_send_control_set_parameter_value(plugin->id(), i, plugin->getParameterValue(i));
  501. }
  502. return 0;
  503. }
  504. int CarlaEngineOsc::handleMsgSetMidiProgram(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  505. {
  506. qDebug("CarlaEngineOsc::handleMsgSetMidiProgram()");
  507. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(1, "i");
  508. const int32_t index = argv[0]->i;
  509. plugin->setMidiProgram(index, true, false, true, true);
  510. // parameters might have changed, send all param values back
  511. if (m_controlData.target && index >= 0)
  512. {
  513. for (uint32_t i=0; i < plugin->parameterCount(); i++)
  514. engine->osc_send_control_set_parameter_value(plugin->id(), i, plugin->getParameterValue(i));
  515. }
  516. return 0;
  517. }
  518. int CarlaEngineOsc::handleMsgNoteOn(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  519. {
  520. qDebug("CarlaEngineOsc::handleMsgNoteOn()");
  521. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(3, "iii");
  522. const int32_t channel = argv[0]->i;
  523. const int32_t note = argv[1]->i;
  524. const int32_t velo = argv[2]->i;
  525. plugin->sendMidiSingleNote(channel, note, velo, true, false, true);
  526. return 0;
  527. }
  528. int CarlaEngineOsc::handleMsgNoteOff(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  529. {
  530. qDebug("CarlaEngineOsc::handleMsgNoteOff()");
  531. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "ii");
  532. const int32_t channel = argv[0]->i;
  533. const int32_t note = argv[1]->i;
  534. plugin->sendMidiSingleNote(channel, note, 0, true, false, true);
  535. return 0;
  536. }
  537. int CarlaEngineOsc::handleMsgBridgeSetInPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  538. {
  539. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "id");
  540. const int32_t index = argv[0]->i;
  541. const double value = argv[1]->d;
  542. engine->setInputPeak(plugin->id(), index-1, value);
  543. return 0;
  544. }
  545. int CarlaEngineOsc::handleMsgBridgeSetOutPeak(CARLA_ENGINE_OSC_HANDLE_ARGS2)
  546. {
  547. CARLA_ENGINE_OSC_CHECK_OSC_TYPES(2, "id");
  548. const int32_t index = argv[0]->i;
  549. const double value = argv[1]->d;
  550. engine->setOutputPeak(plugin->id(), index-1, value);
  551. return 0;
  552. }
  553. #endif
  554. CARLA_BACKEND_END_NAMESPACE