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.

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