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.

657 lines
21KB

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