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.

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