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