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.

652 lines
21KB

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