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.

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