Collection of tools useful for audio production
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.

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