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.

633 lines
20KB

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