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.

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