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.

2235 lines
67KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 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. double abs_d(const double& value)
  21. {
  22. return (value < 0.0) ? -value : value;
  23. }
  24. // -----------------------------------------------------------------------
  25. unsigned short CarlaEngine::m_maxPluginNumber = 0;
  26. CarlaEngine::CarlaEngine()
  27. : m_checkThread(this),
  28. #ifndef BUILD_BRIDGE
  29. m_osc(this),
  30. #endif
  31. m_oscData(nullptr),
  32. m_callback(nullptr),
  33. #ifdef Q_COMPILER_INITIALIZER_LISTS
  34. m_callbackPtr(nullptr),
  35. m_carlaPlugins{nullptr},
  36. m_uniqueNames{nullptr},
  37. m_insPeak{0.0},
  38. m_outsPeak{0.0}
  39. #else
  40. m_callbackPtr(nullptr)
  41. #endif
  42. {
  43. qDebug("CarlaEngine::CarlaEngine()");
  44. type = CarlaEngineTypeNull;
  45. name = nullptr;
  46. bufferSize = 0;
  47. sampleRate = 0.0;
  48. m_maxPluginNumber = 0;
  49. #ifndef Q_COMPILER_INITIALIZER_LISTS
  50. for (unsigned short i=0; i < MAX_PLUGINS; i++)
  51. {
  52. m_carlaPlugins[i] = nullptr;
  53. m_uniqueNames[i] = nullptr;
  54. }
  55. for (unsigned short i=0; i < MAX_PLUGINS * MAX_PEAKS; i++)
  56. {
  57. m_insPeak[i] = 0.0;
  58. m_outsPeak[i] = 0.0;
  59. }
  60. #endif
  61. }
  62. CarlaEngine::~CarlaEngine()
  63. {
  64. qDebug("CarlaEngine::~CarlaEngine()");
  65. if (name)
  66. free((void*)name);
  67. }
  68. // -----------------------------------------------------------------------
  69. // Static values
  70. int CarlaEngine::maxClientNameSize()
  71. {
  72. #ifdef CARLA_ENGINE_JACK
  73. # ifndef BUILD_BRIDGE
  74. if (processMode != PROCESS_MODE_CONTINUOUS_RACK)
  75. # endif
  76. return jackbridge_client_name_size();
  77. #endif
  78. return STR_MAX/2;
  79. }
  80. int CarlaEngine::maxPortNameSize()
  81. {
  82. #ifdef CARLA_ENGINE_JACK
  83. # ifndef BUILD_BRIDGE
  84. if (processMode != PROCESS_MODE_CONTINUOUS_RACK)
  85. # endif
  86. return jackbridge_port_name_size();
  87. #endif
  88. return STR_MAX;
  89. }
  90. unsigned short CarlaEngine::maxPluginNumber()
  91. {
  92. return m_maxPluginNumber;
  93. }
  94. const char* CarlaEngine::getFixedClientName(const char* const clientName)
  95. {
  96. char* fixedName = strdup(clientName);
  97. for (size_t i=0; i < strlen(fixedName); i++)
  98. {
  99. if (! (std::isalpha(fixedName[i]) || std::isdigit(fixedName[i])))
  100. fixedName[i] = '_';
  101. }
  102. return fixedName;
  103. }
  104. unsigned int CarlaEngine::getDriverCount()
  105. {
  106. unsigned int count = 0;
  107. #ifdef CARLA_ENGINE_JACK
  108. count += 1;
  109. #endif
  110. #ifdef CARLA_ENGINE_RTAUDIO
  111. std::vector<RtAudio::Api> apis;
  112. RtAudio::getCompiledApi(apis);
  113. count += apis.size();
  114. #endif
  115. return count;
  116. }
  117. const char* CarlaEngine::getDriverName(unsigned int index)
  118. {
  119. #ifdef CARLA_ENGINE_JACK
  120. if (index == 0)
  121. return "JACK";
  122. else
  123. index -= 1;
  124. #endif
  125. #ifdef CARLA_ENGINE_RTAUDIO
  126. std::vector<RtAudio::Api> apis;
  127. RtAudio::getCompiledApi(apis);
  128. if (index < apis.size())
  129. {
  130. RtAudio::Api api = apis[index];
  131. switch (api)
  132. {
  133. case RtAudio::UNSPECIFIED:
  134. return "Unspecified";
  135. case RtAudio::LINUX_ALSA:
  136. return "ALSA";
  137. case RtAudio::LINUX_PULSE:
  138. return "PulseAudio";
  139. case RtAudio::LINUX_OSS:
  140. return "OSS";
  141. case RtAudio::UNIX_JACK:
  142. return "JACK (RtAudio)";
  143. case RtAudio::MACOSX_CORE:
  144. return "CoreAudio";
  145. case RtAudio::WINDOWS_ASIO:
  146. return "ASIO";
  147. case RtAudio::WINDOWS_DS:
  148. return "DirectSound";
  149. case RtAudio::RTAUDIO_DUMMY:
  150. return "Dummy";
  151. }
  152. }
  153. #endif
  154. qWarning("CarlaEngine::getDriverName(%i) - invalid index", index);
  155. return nullptr;
  156. }
  157. CarlaEngine* CarlaEngine::newDriverByName(const char* driverName)
  158. {
  159. #ifdef CARLA_ENGINE_JACK
  160. if (strcmp(driverName, "JACK") == 0)
  161. return newJack();
  162. #else
  163. if (false)
  164. pass();
  165. #endif
  166. #ifdef CARLA_ENGINE_RTAUDIO
  167. #ifdef __LINUX_ALSA__
  168. else if (strcmp(driverName, "ALSA") == 0)
  169. return newRtAudio(RtAudio::LINUX_ALSA);
  170. #endif
  171. #ifdef __LINUX_PULSE__
  172. else if (strcmp(driverName, "PulseAudio") == 0)
  173. return newRtAudio(RtAudio::LINUX_PULSE);
  174. #endif
  175. #ifdef __LINUX_OSS__
  176. else if (strcmp(driverName, "OSS") == 0)
  177. return newRtAudio(RtAudio::LINUX_OSS);
  178. #endif
  179. #ifdef __UNIX_JACK__
  180. else if (strcmp(driverName, "JACK (RtAudio)") == 0)
  181. return newRtAudio(RtAudio::UNIX_JACK);
  182. #endif
  183. #ifdef __MACOSX_CORE__
  184. else if (strcmp(driverName, "CoreAudio") == 0)
  185. return newRtAudio(RtAudio::MACOSX_CORE);
  186. #endif
  187. #ifdef __WINDOWS_ASIO__
  188. else if (strcmp(driverName, "ASIO") == 0)
  189. return newRtAudio(RtAudio::WINDOWS_ASIO);
  190. #endif
  191. #ifdef __WINDOWS_DS__
  192. else if (strcmp(driverName, "DirectSound") == 0)
  193. return newRtAudio(RtAudio::WINDOWS_DS);
  194. #endif
  195. #ifdef __RTAUDIO_DUMMY__
  196. else if (strcmp(driverName, "Dummy") == 0)
  197. return newRtAudio(RtAudio::RTAUDIO_DUMMY);
  198. #endif
  199. #endif
  200. return nullptr;
  201. }
  202. // -----------------------------------------------------------------------
  203. // Global options
  204. #ifndef BUILD_BRIDGE
  205. ProcessModeType CarlaEngine::processMode = PROCESS_MODE_MULTIPLE_CLIENTS;
  206. void CarlaEngine::setOption(const OptionsType option, const int value, const char* const valueStr)
  207. {
  208. qDebug("CarlaEngine::setOption(%s, %i, \"%s\")", OptionsType2str(option), value, valueStr);
  209. switch (option)
  210. {
  211. case OPTION_PROCESS_NAME:
  212. carla_setprocname(valueStr);
  213. break;
  214. case OPTION_PROCESS_MODE:
  215. if (value < PROCESS_MODE_SINGLE_CLIENT || value > PROCESS_MODE_CONTINUOUS_RACK)
  216. return qCritical("CarlaEngine::setOption(%s, %i, \"%s\") - invalid value", OptionsType2str(option), value, valueStr);
  217. processMode = (ProcessModeType)value;
  218. break;
  219. case OPTION_PROCESS_HIGH_PRECISION:
  220. options.processHighPrecision = value;
  221. break;
  222. case OPTION_MAX_PARAMETERS:
  223. options.maxParameters = (value > 0) ? value : MAX_PARAMETERS;
  224. break;
  225. case OPTION_PREFERRED_BUFFER_SIZE:
  226. options.preferredBufferSize = value;
  227. break;
  228. case OPTION_PREFERRED_SAMPLE_RATE:
  229. options.preferredSampleRate = value;
  230. break;
  231. case OPTION_FORCE_STEREO:
  232. options.forceStereo = value;
  233. break;
  234. case OPTION_USE_DSSI_VST_CHUNKS:
  235. options.useDssiVstChunks = value;
  236. break;
  237. case OPTION_PREFER_PLUGIN_BRIDGES:
  238. options.preferPluginBridges = value;
  239. break;
  240. case OPTION_PREFER_UI_BRIDGES:
  241. options.preferUiBridges = value;
  242. break;
  243. case OPTION_OSC_UI_TIMEOUT:
  244. options.oscUiTimeout = value/100;
  245. break;
  246. case OPTION_PATH_LADSPA:
  247. carla_setenv("LADSPA_PATH", valueStr);
  248. break;
  249. case OPTION_PATH_DSSI:
  250. carla_setenv("DSSI_PATH", valueStr);
  251. break;
  252. case OPTION_PATH_LV2:
  253. carla_setenv("LV2_PATH", valueStr);
  254. break;
  255. case OPTION_PATH_VST:
  256. carla_setenv("VST_PATH", valueStr);
  257. break;
  258. case OPTION_PATH_GIG:
  259. carla_setenv("GIG_PATH", valueStr);
  260. break;
  261. case OPTION_PATH_SF2:
  262. carla_setenv("SF2_PATH", valueStr);
  263. break;
  264. case OPTION_PATH_SFZ:
  265. carla_setenv("SFZ_PATH", valueStr);
  266. break;
  267. case OPTION_PATH_BRIDGE_POSIX32:
  268. options.bridge_posix32 = strdup(valueStr);
  269. break;
  270. case OPTION_PATH_BRIDGE_POSIX64:
  271. options.bridge_posix64 = strdup(valueStr);
  272. break;
  273. case OPTION_PATH_BRIDGE_WIN32:
  274. options.bridge_win32 = strdup(valueStr);
  275. break;
  276. case OPTION_PATH_BRIDGE_WIN64:
  277. options.bridge_win64 = strdup(valueStr);
  278. break;
  279. case OPTION_PATH_BRIDGE_LV2_GTK2:
  280. options.bridge_lv2gtk2 = strdup(valueStr);
  281. break;
  282. case OPTION_PATH_BRIDGE_LV2_GTK3:
  283. options.bridge_lv2gtk3 = strdup(valueStr);
  284. break;
  285. case OPTION_PATH_BRIDGE_LV2_QT4:
  286. options.bridge_lv2qt4 = strdup(valueStr);
  287. break;
  288. case OPTION_PATH_BRIDGE_LV2_X11:
  289. options.bridge_lv2x11 = strdup(valueStr);
  290. break;
  291. case OPTION_PATH_BRIDGE_VST_HWND:
  292. options.bridge_vsthwnd = strdup(valueStr);
  293. break;
  294. case OPTION_PATH_BRIDGE_VST_X11:
  295. options.bridge_vstx11 = strdup(valueStr);
  296. break;
  297. }
  298. }
  299. void CarlaEngine::resetOptions()
  300. {
  301. qDebug("CarlaEngine::resetOptions()");
  302. if (options.bridge_posix32)
  303. free((void*)options.bridge_posix32);
  304. if (options.bridge_posix64)
  305. free((void*)options.bridge_posix64);
  306. if (options.bridge_win32)
  307. free((void*)options.bridge_win32);
  308. if (options.bridge_win64)
  309. free((void*)options.bridge_win64);
  310. if (options.bridge_lv2gtk2)
  311. free((void*)options.bridge_lv2gtk2);
  312. if (options.bridge_lv2gtk3)
  313. free((void*)options.bridge_lv2gtk3);
  314. if (options.bridge_lv2qt4)
  315. free((void*)options.bridge_lv2qt4);
  316. if (options.bridge_lv2x11)
  317. free((void*)options.bridge_lv2x11);
  318. if (options.bridge_vsthwnd)
  319. free((void*)options.bridge_vsthwnd);
  320. if (options.bridge_vstx11)
  321. free((void*)options.bridge_vstx11);
  322. processMode = PROCESS_MODE_MULTIPLE_CLIENTS;
  323. options.processHighPrecision = false;
  324. options.maxParameters = MAX_PARAMETERS;
  325. options.preferredBufferSize = 512;
  326. options.preferredSampleRate = 44100;
  327. options.forceStereo = false;
  328. options.useDssiVstChunks = false;
  329. options.preferPluginBridges = false;
  330. options.preferUiBridges = true;
  331. options.oscUiTimeout = 4000/100;
  332. options.bridge_posix32 = nullptr;
  333. options.bridge_posix64 = nullptr;
  334. options.bridge_win32 = nullptr;
  335. options.bridge_win64 = nullptr;
  336. options.bridge_lv2gtk2 = nullptr;
  337. options.bridge_lv2gtk3 = nullptr;
  338. options.bridge_lv2qt4 = nullptr;
  339. options.bridge_lv2x11 = nullptr;
  340. options.bridge_vsthwnd = nullptr;
  341. options.bridge_vstx11 = nullptr;
  342. }
  343. #endif
  344. // -----------------------------------------------------------------------
  345. // Virtual, per-engine type calls
  346. bool CarlaEngine::init(const char* const clientName)
  347. {
  348. qDebug("CarlaEngine::init(\"%s\")", clientName);
  349. #ifndef BUILD_BRIDGE
  350. m_osc.init(clientName);
  351. m_oscData = m_osc.getControlData();
  352. if (strcmp(clientName, "Carla"))
  353. carla_setprocname(clientName);
  354. #endif
  355. return true;
  356. }
  357. bool CarlaEngine::close()
  358. {
  359. qDebug("CarlaEngine::close()");
  360. m_checkThread.stopNow();
  361. #ifndef BUILD_BRIDGE
  362. osc_send_control_exit();
  363. m_osc.close();
  364. #endif
  365. m_oscData = nullptr;
  366. m_maxPluginNumber = 0;
  367. return true;
  368. }
  369. // -----------------------------------------------------------------------
  370. // plugin management
  371. short CarlaEngine::getNewPluginId() const
  372. {
  373. qDebug("CarlaEngine::getNewPluginId()");
  374. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  375. {
  376. if (! m_carlaPlugins[i])
  377. return i;
  378. }
  379. return -1;
  380. }
  381. CarlaPlugin* CarlaEngine::getPlugin(const unsigned short id) const
  382. {
  383. qDebug("CarlaEngine::getPlugin(%i/%i)", id, m_maxPluginNumber);
  384. CARLA_ASSERT(m_maxPluginNumber != 0);
  385. CARLA_ASSERT(id < m_maxPluginNumber);
  386. if (id < m_maxPluginNumber)
  387. return m_carlaPlugins[id];
  388. return nullptr;
  389. }
  390. CarlaPlugin* CarlaEngine::getPluginUnchecked(const unsigned short id) const
  391. {
  392. CARLA_ASSERT(m_maxPluginNumber != 0);
  393. CARLA_ASSERT(id < m_maxPluginNumber);
  394. return m_carlaPlugins[id];
  395. }
  396. const char* CarlaEngine::getUniquePluginName(const char* const name)
  397. {
  398. qDebug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  399. CARLA_ASSERT(name);
  400. QString qname(name);
  401. if (qname.isEmpty())
  402. qname = "(No name)";
  403. qname.truncate(maxClientNameSize()-5-1); // 5 = strlen(" (10)")
  404. qname.replace(":", "."); // ":" is used in JACK1 to split client/port names
  405. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  406. {
  407. // Check if unique name already exists
  408. if (m_uniqueNames[i] && qname == m_uniqueNames[i])
  409. {
  410. // Check if string has already been modified
  411. uint len = qname.size();
  412. // 1 digit, ex: " (2)"
  413. if (qname.at(len-4) == QChar(' ') && qname.at(len-3) == QChar('(') && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  414. {
  415. int number = qname.at(len-2).toAscii()-'0';
  416. if (number == 9)
  417. // next number is 10, 2 digits
  418. qname.replace(" (9)", " (10)");
  419. else
  420. qname[len-2] = QChar('0'+number+1);
  421. continue;
  422. }
  423. // 2 digits, ex: " (11)"
  424. if (qname.at(len-5) == QChar(' ') && qname.at(len-4) == QChar('(') && qname.at(len-3).isDigit() && qname.at(len-2).isDigit() && qname.at(len-1) == QChar(')'))
  425. {
  426. QChar n2 = qname.at(len-2);
  427. QChar n3 = qname.at(len-3);
  428. if (n2 == QChar('9'))
  429. {
  430. n2 = QChar('0');
  431. n3 = QChar(n3.toAscii()+1);
  432. }
  433. else
  434. n2 = QChar(n2.toAscii()+1);
  435. qname[len-2] = n2;
  436. qname[len-3] = n3;
  437. continue;
  438. }
  439. // Modify string if not
  440. qname += " (2)";
  441. }
  442. }
  443. return strdup(qname.toUtf8().constData());
  444. }
  445. short CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  446. {
  447. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, extra);
  448. }
  449. short CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype, const char* const filename, const char* const name, const char* const label, void* const extra)
  450. {
  451. qDebug("CarlaEngine::addPlugin(%s, %s, \"%s\", \"%s\", \"%s\", %p)", BinaryType2str(btype), PluginType2str(ptype), filename, name, label, extra);
  452. CARLA_ASSERT(btype != BINARY_NONE);
  453. CARLA_ASSERT(ptype != PLUGIN_NONE);
  454. CARLA_ASSERT(filename);
  455. CARLA_ASSERT(label);
  456. if (m_maxPluginNumber == 0)
  457. {
  458. #ifdef BUILD_BRIDGE
  459. m_maxPluginNumber = MAX_PLUGINS;
  460. #else
  461. m_maxPluginNumber = (processMode == PROCESS_MODE_CONTINUOUS_RACK) ? 16 : MAX_PLUGINS;
  462. #endif
  463. }
  464. CarlaPlugin::initializer init = {
  465. this,
  466. filename,
  467. name,
  468. label
  469. };
  470. CarlaPlugin* plugin = nullptr;
  471. #ifndef BUILD_BRIDGE
  472. if (btype != BINARY_NATIVE || (options.preferPluginBridges && getBinaryBidgePath(btype) && type == CarlaEngineTypeJack))
  473. {
  474. # ifdef CARLA_ENGINE_JACK
  475. if (processMode != CarlaBackend::PROCESS_MODE_MULTIPLE_CLIENTS)
  476. {
  477. setLastError("Can only use bridged plugins in JACK Multi-Client mode");
  478. return -1;
  479. }
  480. # endif
  481. if (type != CarlaEngineTypeJack)
  482. {
  483. setLastError("Can only use bridged plugins with JACK backend");
  484. return -1;
  485. }
  486. plugin = CarlaPlugin::newBridge(init, btype, ptype);
  487. }
  488. else
  489. #endif
  490. {
  491. switch (ptype)
  492. {
  493. case PLUGIN_NONE:
  494. break;
  495. #ifndef BUILD_BRIDGE
  496. case PLUGIN_INTERNAL:
  497. plugin = CarlaPlugin::newNative(init);
  498. break;
  499. #endif
  500. case PLUGIN_LADSPA:
  501. plugin = CarlaPlugin::newLADSPA(init, extra);
  502. break;
  503. case PLUGIN_DSSI:
  504. plugin = CarlaPlugin::newDSSI(init, extra);
  505. break;
  506. case PLUGIN_LV2:
  507. plugin = CarlaPlugin::newLV2(init);
  508. break;
  509. case PLUGIN_VST:
  510. plugin = CarlaPlugin::newVST(init);
  511. break;
  512. #ifndef BUILD_BRIDGE
  513. case PLUGIN_GIG:
  514. plugin = CarlaPlugin::newGIG(init);
  515. break;
  516. case PLUGIN_SF2:
  517. plugin = CarlaPlugin::newSF2(init);
  518. break;
  519. case PLUGIN_SFZ:
  520. plugin = CarlaPlugin::newSFZ(init);
  521. break;
  522. #else
  523. default:
  524. break;
  525. #endif
  526. }
  527. }
  528. if (! plugin)
  529. return -1;
  530. const short id = plugin->id();
  531. m_carlaPlugins[id] = plugin;
  532. m_uniqueNames[id] = plugin->name();
  533. if (! m_checkThread.isRunning())
  534. m_checkThread.startNow();
  535. return id;
  536. }
  537. bool CarlaEngine::removePlugin(const unsigned short id)
  538. {
  539. qDebug("CarlaEngine::removePlugin(%i)", id);
  540. CARLA_ASSERT(m_maxPluginNumber != 0);
  541. CARLA_ASSERT(id < m_maxPluginNumber);
  542. CarlaPlugin* const plugin = m_carlaPlugins[id];
  543. if (plugin /*&& plugin->id() == id*/)
  544. {
  545. CARLA_ASSERT(plugin->id() == id);
  546. m_checkThread.stopNow();
  547. processLock();
  548. plugin->setEnabled(false);
  549. m_carlaPlugins[id] = nullptr;
  550. m_uniqueNames[id] = nullptr;
  551. processUnlock();
  552. delete plugin;
  553. #ifndef BUILD_BRIDGE
  554. osc_send_control_remove_plugin(id);
  555. if (processMode == PROCESS_MODE_CONTINUOUS_RACK)
  556. {
  557. // TODO - handle OSC server comm
  558. for (unsigned short i=id; i < m_maxPluginNumber-1; i++)
  559. {
  560. m_carlaPlugins[i] = m_carlaPlugins[i+1];
  561. m_uniqueNames[i] = m_uniqueNames[i+1];
  562. if (m_carlaPlugins[i])
  563. m_carlaPlugins[i]->setId(i);
  564. }
  565. }
  566. #endif
  567. if (isRunning())
  568. {
  569. // only re-start check thread if there are still plugins left
  570. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  571. {
  572. if (m_carlaPlugins[i])
  573. {
  574. m_checkThread.startNow();
  575. break;
  576. }
  577. }
  578. }
  579. return true;
  580. }
  581. qCritical("CarlaEngine::removePlugin(%i) - could not find plugin", id);
  582. setLastError("Could not find plugin to remove");
  583. return false;
  584. }
  585. void CarlaEngine::removeAllPlugins()
  586. {
  587. qDebug("CarlaEngine::removeAllPlugins()");
  588. m_checkThread.stopNow();
  589. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  590. {
  591. CarlaPlugin* const plugin = m_carlaPlugins[i];
  592. if (plugin)
  593. {
  594. processLock();
  595. plugin->setEnabled(false);
  596. processUnlock();
  597. delete plugin;
  598. m_carlaPlugins[i] = nullptr;
  599. m_uniqueNames[i] = nullptr;
  600. }
  601. }
  602. m_maxPluginNumber = 0;
  603. }
  604. void CarlaEngine::idlePluginGuis()
  605. {
  606. CARLA_ASSERT(m_maxPluginNumber != 0);
  607. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  608. {
  609. CarlaPlugin* const plugin = m_carlaPlugins[i];
  610. if (plugin && plugin->enabled())
  611. plugin->idleGui();
  612. }
  613. }
  614. #ifndef BUILD_BRIDGE
  615. void CarlaEngine::processRack(float* inBuf[2], float* outBuf[2], uint32_t frames)
  616. {
  617. // initialize outputs (zero)
  618. carla_zeroF(outBuf[0], frames);
  619. carla_zeroF(outBuf[1], frames);
  620. memset(rackControlEventsOut, 0, sizeof(CarlaEngineControlEvent)*MAX_ENGINE_CONTROL_EVENTS);
  621. memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  622. bool processed = false;
  623. // process plugins
  624. for (unsigned short i=0, max=maxPluginNumber(); i < max; i++)
  625. {
  626. CarlaPlugin* const plugin = getPluginUnchecked(i);
  627. if (plugin && plugin->enabled())
  628. {
  629. if (processed)
  630. {
  631. // initialize inputs (from previous outputs)
  632. memcpy(inBuf[0], outBuf[0], sizeof(float)*frames);
  633. memcpy(inBuf[1], outBuf[1], sizeof(float)*frames);
  634. memcpy(rackMidiEventsIn, rackMidiEventsOut, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  635. // initialize outputs (zero)
  636. carla_zeroF(outBuf[0], frames);
  637. carla_zeroF(outBuf[1], frames);
  638. memset(rackMidiEventsOut, 0, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  639. }
  640. // process
  641. plugin->engineProcessLock();
  642. plugin->initBuffers();
  643. if (options.processHighPrecision)
  644. {
  645. float* inBuf2[2];
  646. float* outBuf2[2];
  647. for (uint32_t j=0; j < frames; j += 8)
  648. {
  649. inBuf2[0] = inBuf[0] + j;
  650. inBuf2[1] = inBuf[1] + j;
  651. outBuf2[0] = outBuf[0] + j;
  652. outBuf2[1] = outBuf[1] + j;
  653. plugin->process(inBuf2, outBuf2, 8, j);
  654. }
  655. }
  656. else
  657. plugin->process(inBuf, outBuf, frames);
  658. plugin->engineProcessUnlock();
  659. // if plugin has no audio inputs, add previous buffers
  660. if (plugin->audioInCount() == 0)
  661. {
  662. for (uint32_t j=0; j < frames; j++)
  663. {
  664. outBuf[0][j] += inBuf[0][j];
  665. outBuf[1][j] += inBuf[1][j];
  666. }
  667. }
  668. // if plugin has no midi output, add previous midi input
  669. if (plugin->midiOutCount() == 0)
  670. {
  671. memcpy(rackMidiEventsOut, rackMidiEventsIn, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  672. }
  673. // set peaks
  674. {
  675. double inPeak1 = 0.0;
  676. double inPeak2 = 0.0;
  677. double outPeak1 = 0.0;
  678. double outPeak2 = 0.0;
  679. for (uint32_t k=0; k < frames; k++)
  680. {
  681. if (abs_d(inBuf[0][k]) > inPeak1)
  682. inPeak1 = abs_d(inBuf[0][k]);
  683. if (abs_d(inBuf[1][k]) > inPeak2)
  684. inPeak2 = abs_d(inBuf[1][k]);
  685. if (abs_d(outBuf[0][k]) > outPeak1)
  686. outPeak1 = abs_d(outBuf[0][k]);
  687. if (abs_d(outBuf[1][k]) > outPeak2)
  688. outPeak2 = abs_d(outBuf[1][k]);
  689. }
  690. m_insPeak[i*MAX_PEAKS + 0] = inPeak1;
  691. m_insPeak[i*MAX_PEAKS + 1] = inPeak2;
  692. m_outsPeak[i*MAX_PEAKS + 0] = outPeak1;
  693. m_outsPeak[i*MAX_PEAKS + 1] = outPeak2;
  694. }
  695. processed = true;
  696. }
  697. }
  698. // if no plugins in the rack, copy inputs over outputs
  699. if (! processed)
  700. {
  701. memcpy(outBuf[0], inBuf[0], sizeof(float)*frames);
  702. memcpy(outBuf[1], inBuf[1], sizeof(float)*frames);
  703. memcpy(rackMidiEventsOut, rackMidiEventsIn, sizeof(CarlaEngineMidiEvent)*MAX_ENGINE_MIDI_EVENTS);
  704. }
  705. }
  706. #endif
  707. // -----------------------------------------------------------------------
  708. // Information (base)
  709. CarlaEngineType CarlaEngine::getType() const
  710. {
  711. return type;
  712. }
  713. const char* CarlaEngine::getName() const
  714. {
  715. CARLA_ASSERT(name);
  716. return name;
  717. }
  718. double CarlaEngine::getSampleRate() const
  719. {
  720. //CARLA_ASSERT(sampleRate != 0.0);
  721. return sampleRate;
  722. }
  723. uint32_t CarlaEngine::getBufferSize() const
  724. {
  725. //CARLA_ASSERT(bufferSize != 0);
  726. return bufferSize;
  727. }
  728. const CarlaTimeInfo* CarlaEngine::getTimeInfo() const
  729. {
  730. return &timeInfo;
  731. }
  732. // -----------------------------------------------------------------------
  733. // Information (audio peaks)
  734. double CarlaEngine::getInputPeak(const unsigned short pluginId, const unsigned short id) const
  735. {
  736. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  737. CARLA_ASSERT(id < MAX_PEAKS);
  738. return m_insPeak[pluginId*MAX_PEAKS + id];
  739. }
  740. double CarlaEngine::getOutputPeak(const unsigned short pluginId, const unsigned short id) const
  741. {
  742. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  743. CARLA_ASSERT(id < MAX_PEAKS);
  744. return m_outsPeak[pluginId*MAX_PEAKS + id];
  745. }
  746. void CarlaEngine::setInputPeak(const unsigned short pluginId, const unsigned short id, double value)
  747. {
  748. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  749. CARLA_ASSERT(id < MAX_PEAKS);
  750. m_insPeak[pluginId*MAX_PEAKS + id] = value;
  751. }
  752. void CarlaEngine::setOutputPeak(const unsigned short pluginId, const unsigned short id, double value)
  753. {
  754. CARLA_ASSERT(pluginId < m_maxPluginNumber);
  755. CARLA_ASSERT(id < MAX_PEAKS);
  756. m_outsPeak[pluginId*MAX_PEAKS + id] = value;
  757. }
  758. // -----------------------------------------------------------------------
  759. // Callback
  760. void CarlaEngine::callback(const CallbackType action, const unsigned short pluginId, const int value1, const int value2, const double value3)
  761. {
  762. qDebug("CarlaEngine::callback(%s, %i, %i, %i, %f)", CallbackType2str(action), pluginId, value1, value2, value3);
  763. if (m_callback)
  764. m_callback(m_callbackPtr, action, pluginId, value1, value2, value3);
  765. }
  766. void CarlaEngine::setCallback(const CallbackFunc func, void* const ptr)
  767. {
  768. qDebug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  769. CARLA_ASSERT(func);
  770. m_callback = func;
  771. m_callbackPtr = ptr;
  772. }
  773. // -----------------------------------------------------------------------
  774. // Mutex locks
  775. void CarlaEngine::processLock()
  776. {
  777. m_procLock.lock();
  778. }
  779. void CarlaEngine::processUnlock()
  780. {
  781. m_procLock.unlock();
  782. }
  783. void CarlaEngine::midiLock()
  784. {
  785. m_midiLock.lock();
  786. }
  787. void CarlaEngine::midiUnlock()
  788. {
  789. m_midiLock.unlock();
  790. }
  791. // -----------------------------------------------------------------------
  792. // OSC Stuff
  793. bool CarlaEngine::isOscControlRegisted() const
  794. {
  795. #ifndef BUILD_BRIDGE
  796. return m_osc.isControlRegistered();
  797. #else
  798. return bool(m_oscData);
  799. #endif
  800. }
  801. #ifndef BUILD_BRIDGE
  802. void CarlaEngine::oscWaitEvents()
  803. {
  804. m_osc.waitForEvents();
  805. }
  806. const char* CarlaEngine::getOscServerPathTCP() const
  807. {
  808. return m_osc.getServerPathTCP();
  809. }
  810. const char* CarlaEngine::getOscServerPathUDP() const
  811. {
  812. return m_osc.getServerPathUDP();
  813. }
  814. #else
  815. void CarlaEngine::setOscBridgeData(const CarlaOscData* const oscData)
  816. {
  817. m_oscData = oscData;
  818. }
  819. #endif
  820. // -----------------------------------------------------------------------
  821. // protected calls
  822. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  823. {
  824. qDebug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  825. bufferSize = newBufferSize;
  826. for (unsigned short i=0; i < m_maxPluginNumber; i++)
  827. {
  828. if (m_carlaPlugins[i] && m_carlaPlugins[i]->enabled())
  829. m_carlaPlugins[i]->bufferSizeChanged(newBufferSize);
  830. }
  831. }
  832. void CarlaEngine::startCheckThread()
  833. {
  834. if (! m_checkThread.isRunning())
  835. m_checkThread.startNow();
  836. }
  837. // -------------------------------------------------------------------------------------------------------------------
  838. // Carla Engine Client
  839. CarlaEngineClient::CarlaEngineClient(const CarlaEngineClientNativeHandle& handle_)
  840. : handle(handle_)
  841. {
  842. qDebug("CarlaEngineClient::CarlaEngineClient()");
  843. CARLA_ASSERT(handle.type != CarlaEngineTypeNull);
  844. m_active = false;
  845. m_latency = 0;
  846. }
  847. CarlaEngineClient::~CarlaEngineClient()
  848. {
  849. qDebug("CarlaEngineClient::~CarlaEngineClient()");
  850. CARLA_ASSERT(! m_active);
  851. #ifndef BUILD_BRIDGE
  852. if (CarlaEngine::processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  853. #endif
  854. {
  855. #ifdef CARLA_ENGINE_JACK
  856. if (handle.jackClient)
  857. jackbridge_client_close(handle.jackClient);
  858. #endif
  859. }
  860. }
  861. void CarlaEngineClient::activate()
  862. {
  863. qDebug("CarlaEngineClient::activate()");
  864. CARLA_ASSERT(! m_active);
  865. #ifndef BUILD_BRIDGE
  866. if (CarlaEngine::processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  867. #endif
  868. {
  869. if (! m_active)
  870. {
  871. #ifdef CARLA_ENGINE_JACK
  872. if (handle.jackClient)
  873. jackbridge_activate(handle.jackClient);
  874. #endif
  875. }
  876. }
  877. m_active = true;
  878. }
  879. void CarlaEngineClient::deactivate()
  880. {
  881. qDebug("CarlaEngineClient::deactivate()");
  882. CARLA_ASSERT(m_active);
  883. #ifndef BUILD_BRIDGE
  884. if (CarlaEngine::processMode == PROCESS_MODE_MULTIPLE_CLIENTS)
  885. #endif
  886. {
  887. if (m_active)
  888. {
  889. #ifdef CARLA_ENGINE_JACK
  890. if (handle.jackClient)
  891. jackbridge_deactivate(handle.jackClient);
  892. #endif
  893. }
  894. }
  895. m_active = false;
  896. }
  897. bool CarlaEngineClient::isActive() const
  898. {
  899. qDebug("CarlaEngineClient::isActive()");
  900. return m_active;
  901. }
  902. bool CarlaEngineClient::isOk() const
  903. {
  904. qDebug("CarlaEngineClient::isOk()");
  905. #ifndef BUILD_BRIDGE
  906. if (CarlaEngine::processMode != PROCESS_MODE_CONTINUOUS_RACK)
  907. #endif
  908. {
  909. #ifdef CARLA_ENGINE_JACK
  910. if (handle.type == CarlaEngineTypeJack)
  911. return bool(handle.jackClient);
  912. #endif
  913. }
  914. return true;
  915. }
  916. uint32_t CarlaEngineClient::getLatency() const
  917. {
  918. return m_latency;
  919. }
  920. void CarlaEngineClient::setLatency(const uint32_t samples)
  921. {
  922. m_latency = samples;
  923. #ifndef BUILD_BRIDGE
  924. if (CarlaEngine::processMode != PROCESS_MODE_CONTINUOUS_RACK)
  925. #endif
  926. {
  927. #ifdef CARLA_ENGINE_JACK
  928. if (handle.type == CarlaEngineTypeJack)
  929. jackbridge_recompute_total_latencies(handle.jackClient);
  930. #endif
  931. }
  932. }
  933. const CarlaEngineBasePort* CarlaEngineClient::addPort(const CarlaEnginePortType portType, const char* const name, const bool isInput)
  934. {
  935. qDebug("CarlaEngineClient::addPort(%i, \"%s\", %s)", portType, name, bool2str(isInput));
  936. CarlaEnginePortNativeHandle portHandle;
  937. #ifdef CARLA_ENGINE_JACK
  938. portHandle.jackClient = handle.jackClient;
  939. #endif
  940. #ifndef BUILD_BRIDGE
  941. if (CarlaEngine::processMode != PROCESS_MODE_CONTINUOUS_RACK)
  942. #endif
  943. {
  944. #ifdef CARLA_ENGINE_JACK
  945. if (handle.type == CarlaEngineTypeJack)
  946. {
  947. switch (portType)
  948. {
  949. case CarlaEnginePortTypeAudio:
  950. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_AUDIO_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  951. break;
  952. case CarlaEnginePortTypeControl:
  953. case CarlaEnginePortTypeMIDI:
  954. portHandle.jackPort = jackbridge_port_register(handle.jackClient, name, JACK_DEFAULT_MIDI_TYPE, isInput ? JackPortIsInput : JackPortIsOutput, 0);
  955. break;
  956. }
  957. }
  958. #endif
  959. }
  960. switch (portType)
  961. {
  962. case CarlaEnginePortTypeAudio:
  963. return new CarlaEngineAudioPort(portHandle, isInput);
  964. case CarlaEnginePortTypeControl:
  965. return new CarlaEngineControlPort(portHandle, isInput);
  966. case CarlaEnginePortTypeMIDI:
  967. return new CarlaEngineMidiPort(portHandle, isInput);
  968. }
  969. qCritical("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  970. return nullptr;
  971. }
  972. // -------------------------------------------------------------------------------------------------------------------
  973. // Carla Engine Port (Base class)
  974. CarlaEngineBasePort::CarlaEngineBasePort(const CarlaEnginePortNativeHandle& handle_, const bool isInput_)
  975. : isInput(isInput_),
  976. handle(handle_)
  977. {
  978. qDebug("CarlaEngineBasePort::CarlaEngineBasePort(%s)", bool2str(isInput_));
  979. buffer = nullptr;
  980. }
  981. CarlaEngineBasePort::~CarlaEngineBasePort()
  982. {
  983. qDebug("CarlaEngineBasePort::~CarlaEngineBasePort()");
  984. #ifndef BUILD_BRIDGE
  985. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  986. return;
  987. #endif
  988. #ifdef CARLA_ENGINE_JACK
  989. if (handle.jackClient && handle.jackPort)
  990. jackbridge_port_unregister(handle.jackClient, handle.jackPort);
  991. #endif
  992. }
  993. // -------------------------------------------------------------------------------------------------------------------
  994. // Carla Engine Port (Audio)
  995. CarlaEngineAudioPort::CarlaEngineAudioPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  996. : CarlaEngineBasePort(handle, isInput)
  997. {
  998. qDebug("CarlaEngineAudioPort::CarlaEngineAudioPort(%s)", bool2str(isInput));
  999. }
  1000. void CarlaEngineAudioPort::initBuffer(CarlaEngine* const /*engine*/)
  1001. {
  1002. }
  1003. #ifdef CARLA_ENGINE_JACK
  1004. float* CarlaEngineAudioPort::getJackAudioBuffer(uint32_t nframes)
  1005. {
  1006. # ifndef BUILD_BRIDGE
  1007. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1008. return nullptr;
  1009. # endif
  1010. CARLA_ASSERT(handle.jackPort);
  1011. return (float*)jackbridge_port_get_buffer(handle.jackPort, nframes);
  1012. }
  1013. #endif
  1014. // -------------------------------------------------------------------------------------------------------------------
  1015. // Carla Engine Port (Control)
  1016. CarlaEngineControlPort::CarlaEngineControlPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  1017. : CarlaEngineBasePort(handle, isInput)
  1018. {
  1019. qDebug("CarlaEngineControlPort::CarlaEngineControlPort(%s)", bool2str(isInput));
  1020. }
  1021. void CarlaEngineControlPort::initBuffer(CarlaEngine* const engine)
  1022. {
  1023. CARLA_ASSERT(engine);
  1024. #ifndef BUILD_BRIDGE
  1025. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1026. {
  1027. buffer = isInput ? engine->rackControlEventsIn : engine->rackControlEventsOut;
  1028. return;
  1029. }
  1030. #endif
  1031. #ifdef CARLA_ENGINE_JACK
  1032. if (handle.jackPort)
  1033. {
  1034. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  1035. if (! isInput)
  1036. jackbridge_midi_clear_buffer(buffer);
  1037. }
  1038. #endif
  1039. }
  1040. uint32_t CarlaEngineControlPort::getEventCount()
  1041. {
  1042. if (! isInput)
  1043. return 0;
  1044. CARLA_ASSERT(buffer);
  1045. #ifndef BUILD_BRIDGE
  1046. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1047. {
  1048. uint32_t count = 0;
  1049. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  1050. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  1051. {
  1052. if (events[i].type != CarlaEngineEventNull)
  1053. count++;
  1054. else
  1055. break;
  1056. }
  1057. return count;
  1058. }
  1059. #endif
  1060. #ifdef CARLA_ENGINE_JACK
  1061. if (handle.jackPort)
  1062. return jackbridge_midi_get_event_count(buffer);
  1063. #endif
  1064. return 0;
  1065. }
  1066. const CarlaEngineControlEvent* CarlaEngineControlPort::getEvent(uint32_t index)
  1067. {
  1068. if (! isInput)
  1069. return nullptr;
  1070. CARLA_ASSERT(buffer);
  1071. #ifndef BUILD_BRIDGE
  1072. CARLA_ASSERT(index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS);
  1073. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1074. {
  1075. const CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  1076. if (index < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS)
  1077. return &events[index];
  1078. return nullptr;
  1079. }
  1080. #endif
  1081. #ifdef CARLA_ENGINE_JACK
  1082. if (handle.jackPort)
  1083. {
  1084. static jackbridge_midi_event_t jackEvent;
  1085. static CarlaEngineControlEvent carlaEvent;
  1086. if (jackbridge_midi_event_get(&jackEvent, buffer, index) != 0)
  1087. return nullptr;
  1088. memset(&carlaEvent, 0, sizeof(CarlaEngineControlEvent));
  1089. uint8_t midiStatus = jackEvent.buffer[0];
  1090. uint8_t midiChannel = midiStatus & 0x0F;
  1091. carlaEvent.time = jackEvent.time;
  1092. carlaEvent.channel = midiChannel;
  1093. if (MIDI_IS_STATUS_CONTROL_CHANGE(midiStatus))
  1094. {
  1095. uint8_t midiControl = jackEvent.buffer[1];
  1096. if (MIDI_IS_CONTROL_BANK_SELECT(midiControl))
  1097. {
  1098. uint8_t midiBank = jackEvent.buffer[2];
  1099. carlaEvent.type = CarlaEngineEventMidiBankChange;
  1100. carlaEvent.value = midiBank;
  1101. }
  1102. else if (midiControl == MIDI_CONTROL_ALL_SOUND_OFF)
  1103. {
  1104. carlaEvent.type = CarlaEngineEventAllSoundOff;
  1105. }
  1106. else if (midiControl == MIDI_CONTROL_ALL_NOTES_OFF)
  1107. {
  1108. carlaEvent.type = CarlaEngineEventAllNotesOff;
  1109. }
  1110. else
  1111. {
  1112. uint8_t midiValue = jackEvent.buffer[2];
  1113. carlaEvent.type = CarlaEngineEventControlChange;
  1114. carlaEvent.controller = midiControl;
  1115. carlaEvent.value = double(midiValue)/127;
  1116. }
  1117. return &carlaEvent;
  1118. }
  1119. else if (MIDI_IS_STATUS_PROGRAM_CHANGE(midiStatus))
  1120. {
  1121. uint8_t midiProgram = jackEvent.buffer[1];
  1122. carlaEvent.type = CarlaEngineEventMidiProgramChange;
  1123. carlaEvent.value = midiProgram;
  1124. return &carlaEvent;
  1125. }
  1126. }
  1127. #endif
  1128. return nullptr;
  1129. }
  1130. void CarlaEngineControlPort::writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value)
  1131. {
  1132. if (isInput)
  1133. return;
  1134. CARLA_ASSERT(buffer);
  1135. CARLA_ASSERT(type != CarlaEngineEventNull);
  1136. #ifndef BUILD_BRIDGE
  1137. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1138. {
  1139. CarlaEngineControlEvent* const events = (CarlaEngineControlEvent*)buffer;
  1140. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_CONTROL_EVENTS; i++)
  1141. {
  1142. if (events[i].type == CarlaEngineEventNull)
  1143. {
  1144. events[i].type = type;
  1145. events[i].time = time;
  1146. events[i].value = value;
  1147. events[i].channel = channel;
  1148. events[i].controller = controller;
  1149. break;
  1150. }
  1151. }
  1152. return;
  1153. }
  1154. #endif
  1155. #ifdef CARLA_ENGINE_JACK
  1156. if (handle.jackPort)
  1157. {
  1158. if (type == CarlaEngineEventControlChange && MIDI_IS_CONTROL_BANK_SELECT(controller))
  1159. type = CarlaEngineEventMidiBankChange;
  1160. uint8_t data[4] = { 0 };
  1161. switch (type)
  1162. {
  1163. case CarlaEngineEventNull:
  1164. break;
  1165. case CarlaEngineEventControlChange:
  1166. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1167. data[1] = controller;
  1168. data[2] = value * 127;
  1169. jackbridge_midi_event_write(buffer, time, data, 3);
  1170. break;
  1171. case CarlaEngineEventMidiBankChange:
  1172. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1173. data[1] = MIDI_CONTROL_BANK_SELECT;
  1174. data[2] = value;
  1175. jackbridge_midi_event_write(buffer, time, data, 3);
  1176. break;
  1177. case CarlaEngineEventMidiProgramChange:
  1178. data[0] = MIDI_STATUS_PROGRAM_CHANGE + channel;
  1179. data[1] = value;
  1180. jackbridge_midi_event_write(buffer, time, data, 2);
  1181. break;
  1182. case CarlaEngineEventAllSoundOff:
  1183. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1184. data[1] = MIDI_CONTROL_ALL_SOUND_OFF;
  1185. jackbridge_midi_event_write(buffer, time, data, 2);
  1186. break;
  1187. case CarlaEngineEventAllNotesOff:
  1188. data[0] = MIDI_STATUS_CONTROL_CHANGE + channel;
  1189. data[1] = MIDI_CONTROL_ALL_NOTES_OFF;
  1190. jackbridge_midi_event_write(buffer, time, data, 2);
  1191. break;
  1192. }
  1193. }
  1194. #endif
  1195. }
  1196. // -------------------------------------------------------------------------------------------------------------------
  1197. // Carla Engine Port (MIDI)
  1198. CarlaEngineMidiPort::CarlaEngineMidiPort(const CarlaEnginePortNativeHandle& handle, const bool isInput)
  1199. : CarlaEngineBasePort(handle, isInput)
  1200. {
  1201. qDebug("CarlaEngineMidiPort::CarlaEngineMidiPort(%s)", bool2str(isInput));
  1202. }
  1203. void CarlaEngineMidiPort::initBuffer(CarlaEngine* const engine)
  1204. {
  1205. CARLA_ASSERT(engine);
  1206. #ifndef BUILD_BRIDGE
  1207. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1208. {
  1209. buffer = isInput ? engine->rackMidiEventsIn : engine->rackMidiEventsOut;
  1210. return;
  1211. }
  1212. #endif
  1213. #ifdef CARLA_ENGINE_JACK
  1214. if (handle.jackPort)
  1215. {
  1216. buffer = jackbridge_port_get_buffer(handle.jackPort, engine->getBufferSize());
  1217. if (! isInput)
  1218. jackbridge_midi_clear_buffer(buffer);
  1219. }
  1220. #endif
  1221. }
  1222. uint32_t CarlaEngineMidiPort::getEventCount()
  1223. {
  1224. if (! isInput)
  1225. return 0;
  1226. CARLA_ASSERT(buffer);
  1227. #ifndef BUILD_BRIDGE
  1228. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1229. {
  1230. uint32_t count = 0;
  1231. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1232. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  1233. {
  1234. if (events[i].size > 0)
  1235. count++;
  1236. else
  1237. break;
  1238. }
  1239. return count;
  1240. }
  1241. #endif
  1242. #ifdef CARLA_ENGINE_JACK
  1243. if (handle.jackPort)
  1244. return jackbridge_midi_get_event_count(buffer);
  1245. #endif
  1246. return 0;
  1247. }
  1248. const CarlaEngineMidiEvent* CarlaEngineMidiPort::getEvent(uint32_t index)
  1249. {
  1250. if (! isInput)
  1251. return nullptr;
  1252. CARLA_ASSERT(buffer);
  1253. #ifndef BUILD_BRIDGE
  1254. CARLA_ASSERT(index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS);
  1255. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1256. {
  1257. const CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1258. if (index < CarlaEngine::MAX_ENGINE_MIDI_EVENTS)
  1259. return &events[index];
  1260. return nullptr;
  1261. }
  1262. #endif
  1263. #ifdef CARLA_ENGINE_JACK
  1264. if (handle.jackPort)
  1265. {
  1266. static jackbridge_midi_event_t jackEvent;
  1267. static CarlaEngineMidiEvent carlaEvent;
  1268. if (jackbridge_midi_event_get(&jackEvent, buffer, index) == 0 && jackEvent.size <= 4)
  1269. {
  1270. carlaEvent.time = jackEvent.time;
  1271. carlaEvent.size = jackEvent.size;
  1272. memcpy(carlaEvent.data, jackEvent.buffer, jackEvent.size);
  1273. return &carlaEvent;
  1274. }
  1275. }
  1276. #endif
  1277. return nullptr;
  1278. }
  1279. void CarlaEngineMidiPort::writeEvent(uint32_t time, const uint8_t* data, uint8_t size)
  1280. {
  1281. if (isInput)
  1282. return;
  1283. CARLA_ASSERT(buffer);
  1284. CARLA_ASSERT(data);
  1285. CARLA_ASSERT(size > 0);
  1286. #ifndef BUILD_BRIDGE
  1287. if (CarlaEngine::processMode == PROCESS_MODE_CONTINUOUS_RACK)
  1288. {
  1289. if (size > 4)
  1290. return;
  1291. CarlaEngineMidiEvent* const events = (CarlaEngineMidiEvent*)buffer;
  1292. for (unsigned short i=0; i < CarlaEngine::MAX_ENGINE_MIDI_EVENTS; i++)
  1293. {
  1294. if (events[i].size == 0)
  1295. {
  1296. events[i].time = time;
  1297. events[i].size = size;
  1298. memcpy(events[i].data, data, size);
  1299. break;
  1300. }
  1301. }
  1302. return;
  1303. }
  1304. #endif
  1305. #ifdef CARLA_ENGINE_JACK
  1306. if (handle.jackPort)
  1307. jackbridge_midi_event_write(buffer, time, data, size);
  1308. #endif
  1309. }
  1310. // -------------------------------------------------------------------------------------------------------------------
  1311. // Carla Engine OSC stuff
  1312. #ifndef BUILD_BRIDGE
  1313. void CarlaEngine::osc_send_control_add_plugin_start(const int32_t pluginId, const char* const pluginName)
  1314. {
  1315. qDebug("CarlaEngine::osc_send_control_add_plugin_start(%i, \"%s\")", pluginId, pluginName);
  1316. CARLA_ASSERT(m_oscData);
  1317. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1318. CARLA_ASSERT(pluginName);
  1319. if (m_oscData && m_oscData->target)
  1320. {
  1321. char target_path[strlen(m_oscData->path)+18];
  1322. strcpy(target_path, m_oscData->path);
  1323. strcat(target_path, "/add_plugin_start");
  1324. lo_send(m_oscData->target, target_path, "is", pluginId, pluginName);
  1325. }
  1326. }
  1327. void CarlaEngine::osc_send_control_add_plugin_end(const int32_t pluginId)
  1328. {
  1329. qDebug("CarlaEngine::osc_send_control_add_plugin_end(%i)", pluginId);
  1330. CARLA_ASSERT(m_oscData);
  1331. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1332. if (m_oscData && m_oscData->target)
  1333. {
  1334. char target_path[strlen(m_oscData->path)+16];
  1335. strcpy(target_path, m_oscData->path);
  1336. strcat(target_path, "/add_plugin_end");
  1337. lo_send(m_oscData->target, target_path, "i", pluginId);
  1338. }
  1339. }
  1340. void CarlaEngine::osc_send_control_remove_plugin(const int32_t pluginId)
  1341. {
  1342. qDebug("CarlaEngine::osc_send_control_remove_plugin(%i)", pluginId);
  1343. CARLA_ASSERT(m_oscData);
  1344. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1345. if (m_oscData && m_oscData->target)
  1346. {
  1347. char target_path[strlen(m_oscData->path)+15];
  1348. strcpy(target_path, m_oscData->path);
  1349. strcat(target_path, "/remove_plugin");
  1350. lo_send(m_oscData->target, target_path, "i", pluginId);
  1351. }
  1352. }
  1353. void CarlaEngine::osc_send_control_set_plugin_data(const int32_t pluginId, const int32_t type, const int32_t category, const int32_t hints, const char* const realName, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1354. {
  1355. qDebug("CarlaEngine::osc_send_control_set_plugin_data(%i, %i, %i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1356. CARLA_ASSERT(m_oscData);
  1357. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1358. CARLA_ASSERT(type != PLUGIN_NONE);
  1359. if (m_oscData && m_oscData->target)
  1360. {
  1361. char target_path[strlen(m_oscData->path)+17];
  1362. strcpy(target_path, m_oscData->path);
  1363. strcat(target_path, "/set_plugin_data");
  1364. lo_send(m_oscData->target, target_path, "iiiissssh", pluginId, type, category, hints, realName, label, maker, copyright, uniqueId);
  1365. }
  1366. }
  1367. void CarlaEngine::osc_send_control_set_plugin_ports(const int32_t pluginId, const int32_t audioIns, const int32_t audioOuts, const int32_t midiIns, const int32_t midiOuts, const int32_t cIns, const int32_t cOuts, const int32_t cTotals)
  1368. {
  1369. qDebug("CarlaEngine::osc_send_control_set_plugin_ports(%i, %i, %i, %i, %i, %i, %i, %i)", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1370. CARLA_ASSERT(m_oscData);
  1371. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1372. if (m_oscData && m_oscData->target)
  1373. {
  1374. char target_path[strlen(m_oscData->path)+18];
  1375. strcpy(target_path, m_oscData->path);
  1376. strcat(target_path, "/set_plugin_ports");
  1377. lo_send(m_oscData->target, target_path, "iiiiiiii", pluginId, audioIns, audioOuts, midiIns, midiOuts, cIns, cOuts, cTotals);
  1378. }
  1379. }
  1380. void CarlaEngine::osc_send_control_set_parameter_data(const int32_t pluginId, const int32_t index, const int32_t type, const int32_t hints, const char* const name, const char* const label, const double current)
  1381. {
  1382. qDebug("CarlaEngine::osc_send_control_set_parameter_data(%i, %i, %i, %i, \"%s\", \"%s\", %g)", pluginId, index, type, hints, name, label, current);
  1383. CARLA_ASSERT(m_oscData);
  1384. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1385. CARLA_ASSERT(index >= 0);
  1386. CARLA_ASSERT(type != PARAMETER_UNKNOWN);
  1387. if (m_oscData && m_oscData->target)
  1388. {
  1389. char target_path[strlen(m_oscData->path)+20];
  1390. strcpy(target_path, m_oscData->path);
  1391. strcat(target_path, "/set_parameter_data");
  1392. lo_send(m_oscData->target, target_path, "iiiissd", pluginId, index, type, hints, name, label, current);
  1393. }
  1394. }
  1395. void CarlaEngine::osc_send_control_set_parameter_ranges(const int32_t pluginId, const int32_t index, const double min, const double max, const double def, const double step, const double stepSmall, const double stepLarge)
  1396. {
  1397. qDebug("CarlaEngine::osc_send_control_set_parameter_ranges(%i, %i, %g, %g, %g, %g, %g, %g)", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1398. CARLA_ASSERT(m_oscData);
  1399. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1400. CARLA_ASSERT(index >= 0);
  1401. CARLA_ASSERT(min < max);
  1402. if (m_oscData && m_oscData->target)
  1403. {
  1404. char target_path[strlen(m_oscData->path)+22];
  1405. strcpy(target_path, m_oscData->path);
  1406. strcat(target_path, "/set_parameter_ranges");
  1407. lo_send(m_oscData->target, target_path, "iidddddd", pluginId, index, min, max, def, step, stepSmall, stepLarge);
  1408. }
  1409. }
  1410. void CarlaEngine::osc_send_control_set_parameter_midi_cc(const int32_t pluginId, const int32_t index, const int32_t cc)
  1411. {
  1412. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_cc(%i, %i, %i)", pluginId, index, cc);
  1413. CARLA_ASSERT(m_oscData);
  1414. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1415. CARLA_ASSERT(index >= 0);
  1416. if (m_oscData && m_oscData->target)
  1417. {
  1418. char target_path[strlen(m_oscData->path)+23];
  1419. strcpy(target_path, m_oscData->path);
  1420. strcat(target_path, "/set_parameter_midi_cc");
  1421. lo_send(m_oscData->target, target_path, "iii", pluginId, index, cc);
  1422. }
  1423. }
  1424. void CarlaEngine::osc_send_control_set_parameter_midi_channel(const int32_t pluginId, const int32_t index, const int32_t channel)
  1425. {
  1426. qDebug("CarlaEngine::osc_send_control_set_parameter_midi_channel(%i, %i, %i)", pluginId, index, channel);
  1427. CARLA_ASSERT(m_oscData);
  1428. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1429. CARLA_ASSERT(index >= 0);
  1430. CARLA_ASSERT(channel >= 0 && channel < 16);
  1431. if (m_oscData && m_oscData->target)
  1432. {
  1433. char target_path[strlen(m_oscData->path)+28];
  1434. strcpy(target_path, m_oscData->path);
  1435. strcat(target_path, "/set_parameter_midi_channel");
  1436. lo_send(m_oscData->target, target_path, "iii", pluginId, index, channel);
  1437. }
  1438. }
  1439. void CarlaEngine::osc_send_control_set_parameter_value(const int32_t pluginId, const int32_t index, const double value)
  1440. {
  1441. #if DEBUG
  1442. if (index < -1)
  1443. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %s, %g)", pluginId, InternalParametersIndex2str((InternalParametersIndex)index), value);
  1444. else
  1445. qDebug("CarlaEngine::osc_send_control_set_parameter_value(%i, %i, %g)", pluginId, index, value);
  1446. #endif
  1447. CARLA_ASSERT(m_oscData);
  1448. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1449. if (m_oscData && m_oscData->target)
  1450. {
  1451. char target_path[strlen(m_oscData->path)+21];
  1452. strcpy(target_path, m_oscData->path);
  1453. strcat(target_path, "/set_parameter_value");
  1454. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1455. }
  1456. }
  1457. void CarlaEngine::osc_send_control_set_default_value(const int32_t pluginId, const int32_t index, const double value)
  1458. {
  1459. qDebug("CarlaEngine::osc_send_control_set_default_value(%i, %i, %g)", pluginId, index, value);
  1460. CARLA_ASSERT(m_oscData);
  1461. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1462. CARLA_ASSERT(index >= 0);
  1463. if (m_oscData && m_oscData->target)
  1464. {
  1465. char target_path[strlen(m_oscData->path)+19];
  1466. strcpy(target_path, m_oscData->path);
  1467. strcat(target_path, "/set_default_value");
  1468. lo_send(m_oscData->target, target_path, "iid", pluginId, index, value);
  1469. }
  1470. }
  1471. void CarlaEngine::osc_send_control_set_program(const int32_t pluginId, const int32_t index)
  1472. {
  1473. qDebug("CarlaEngine::osc_send_control_set_program(%i, %i)", pluginId, index);
  1474. CARLA_ASSERT(m_oscData);
  1475. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1476. if (m_oscData && m_oscData->target)
  1477. {
  1478. char target_path[strlen(m_oscData->path)+13];
  1479. strcpy(target_path, m_oscData->path);
  1480. strcat(target_path, "/set_program");
  1481. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1482. }
  1483. }
  1484. void CarlaEngine::osc_send_control_set_program_count(const int32_t pluginId, const int32_t count)
  1485. {
  1486. qDebug("CarlaEngine::osc_send_control_set_program_count(%i, %i)", pluginId, count);
  1487. CARLA_ASSERT(m_oscData);
  1488. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1489. CARLA_ASSERT(count >= 0);
  1490. if (m_oscData && m_oscData->target)
  1491. {
  1492. char target_path[strlen(m_oscData->path)+19];
  1493. strcpy(target_path, m_oscData->path);
  1494. strcat(target_path, "/set_program_count");
  1495. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1496. }
  1497. }
  1498. void CarlaEngine::osc_send_control_set_program_name(const int32_t pluginId, const int32_t index, const char* const name)
  1499. {
  1500. qDebug("CarlaEngine::osc_send_control_set_program_name(%i, %i, \"%s\")", pluginId, index, name);
  1501. CARLA_ASSERT(m_oscData);
  1502. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1503. CARLA_ASSERT(index >= 0);
  1504. CARLA_ASSERT(name);
  1505. if (m_oscData && m_oscData->target)
  1506. {
  1507. char target_path[strlen(m_oscData->path)+18];
  1508. strcpy(target_path, m_oscData->path);
  1509. strcat(target_path, "/set_program_name");
  1510. lo_send(m_oscData->target, target_path, "iis", pluginId, index, name);
  1511. }
  1512. }
  1513. void CarlaEngine::osc_send_control_set_midi_program(const int32_t pluginId, const int32_t index)
  1514. {
  1515. qDebug("CarlaEngine::osc_send_control_set_midi_program(%i, %i)", pluginId, index);
  1516. CARLA_ASSERT(m_oscData);
  1517. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1518. if (m_oscData && m_oscData->target)
  1519. {
  1520. char target_path[strlen(m_oscData->path)+18];
  1521. strcpy(target_path, m_oscData->path);
  1522. strcat(target_path, "/set_midi_program");
  1523. lo_send(m_oscData->target, target_path, "ii", pluginId, index);
  1524. }
  1525. }
  1526. void CarlaEngine::osc_send_control_set_midi_program_count(const int32_t pluginId, const int32_t count)
  1527. {
  1528. qDebug("CarlaEngine::osc_send_control_set_midi_program_count(%i, %i)", pluginId, count);
  1529. CARLA_ASSERT(m_oscData);
  1530. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1531. CARLA_ASSERT(count >= 0);
  1532. if (m_oscData && m_oscData->target)
  1533. {
  1534. char target_path[strlen(m_oscData->path)+24];
  1535. strcpy(target_path, m_oscData->path);
  1536. strcat(target_path, "/set_midi_program_count");
  1537. lo_send(m_oscData->target, target_path, "ii", pluginId, count);
  1538. }
  1539. }
  1540. void CarlaEngine::osc_send_control_set_midi_program_data(const int32_t pluginId, const int32_t index, const int32_t bank, const int32_t program, const char* const name)
  1541. {
  1542. qDebug("CarlaEngine::osc_send_control_set_midi_program_data(%i, %i, %i, %i, \"%s\")", pluginId, index, bank, program, name);
  1543. CARLA_ASSERT(m_oscData);
  1544. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1545. CARLA_ASSERT(index >= 0);
  1546. CARLA_ASSERT(bank >= 0);
  1547. CARLA_ASSERT(program >= 0);
  1548. CARLA_ASSERT(name);
  1549. if (m_oscData && m_oscData->target)
  1550. {
  1551. char target_path[strlen(m_oscData->path)+23];
  1552. strcpy(target_path, m_oscData->path);
  1553. strcat(target_path, "/set_midi_program_data");
  1554. lo_send(m_oscData->target, target_path, "iiiis", pluginId, index, bank, program, name);
  1555. }
  1556. }
  1557. void CarlaEngine::osc_send_control_note_on(const int32_t pluginId, const int32_t channel, const int32_t note, const int32_t velo)
  1558. {
  1559. qDebug("CarlaEngine::osc_send_control_note_on(%i, %i, %i, %i)", pluginId, channel, note, velo);
  1560. CARLA_ASSERT(m_oscData);
  1561. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1562. CARLA_ASSERT(channel >= 0 && channel < 16);
  1563. CARLA_ASSERT(note >= 0 && note < 128);
  1564. CARLA_ASSERT(velo > 0 && velo < 128);
  1565. if (m_oscData && m_oscData->target)
  1566. {
  1567. char target_path[strlen(m_oscData->path)+9];
  1568. strcpy(target_path, m_oscData->path);
  1569. strcat(target_path, "/note_on");
  1570. lo_send(m_oscData->target, target_path, "iiii", pluginId, channel, note, velo);
  1571. }
  1572. }
  1573. void CarlaEngine::osc_send_control_note_off(const int32_t pluginId, const int32_t channel, const int32_t note)
  1574. {
  1575. qDebug("CarlaEngine::osc_send_control_note_off(%i, %i, %i)", pluginId, channel, note);
  1576. CARLA_ASSERT(m_oscData);
  1577. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1578. CARLA_ASSERT(channel >= 0 && channel < 16);
  1579. CARLA_ASSERT(note >= 0 && note < 128);
  1580. if (m_oscData && m_oscData->target)
  1581. {
  1582. char target_path[strlen(m_oscData->path)+10];
  1583. strcpy(target_path, m_oscData->path);
  1584. strcat(target_path, "/note_off");
  1585. lo_send(m_oscData->target, target_path, "iii", pluginId, channel, note);
  1586. }
  1587. }
  1588. void CarlaEngine::osc_send_control_set_input_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1589. {
  1590. //qDebug("CarlaEngine::osc_send_control_set_input_peak_value(%i, %i, %g)", pluginId, portId, value);
  1591. CARLA_ASSERT(m_oscData);
  1592. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1593. CARLA_ASSERT(portId == 1 || portId == 2);
  1594. if (m_oscData && m_oscData->target)
  1595. {
  1596. char target_path[strlen(m_oscData->path)+22];
  1597. strcpy(target_path, m_oscData->path);
  1598. strcat(target_path, "/set_input_peak_value");
  1599. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1600. }
  1601. }
  1602. void CarlaEngine::osc_send_control_set_output_peak_value(const int32_t pluginId, const int32_t portId, const double value)
  1603. {
  1604. //qDebug("CarlaEngine::osc_send_control_set_output_peak_value(%i, %i, %g)", pluginId, portId, value);
  1605. CARLA_ASSERT(m_oscData);
  1606. CARLA_ASSERT(pluginId >= 0 && pluginId < m_maxPluginNumber);
  1607. CARLA_ASSERT(portId == 1 || portId == 2);
  1608. if (m_oscData && m_oscData->target)
  1609. {
  1610. char target_path[strlen(m_oscData->path)+23];
  1611. strcpy(target_path, m_oscData->path);
  1612. strcat(target_path, "/set_output_peak_value");
  1613. lo_send(m_oscData->target, target_path, "iid", pluginId, portId, value);
  1614. }
  1615. }
  1616. void CarlaEngine::osc_send_control_exit()
  1617. {
  1618. qDebug("CarlaEngine::osc_send_control_exit()");
  1619. CARLA_ASSERT(m_oscData);
  1620. if (m_oscData && m_oscData->target)
  1621. {
  1622. char target_path[strlen(m_oscData->path)+6];
  1623. strcpy(target_path, m_oscData->path);
  1624. strcat(target_path, "/exit");
  1625. lo_send(m_oscData->target, target_path, "");
  1626. }
  1627. }
  1628. #else
  1629. void CarlaEngine::osc_send_bridge_audio_count(const int32_t ins, const int32_t outs, const int32_t total)
  1630. {
  1631. qDebug("CarlaEngine::osc_send_bridge_audio_count(%i, %i, %i)", ins, outs, total);
  1632. CARLA_ASSERT(m_oscData);
  1633. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1634. if (m_oscData && m_oscData->target)
  1635. {
  1636. char target_path[strlen(m_oscData->path)+20];
  1637. strcpy(target_path, m_oscData->path);
  1638. strcat(target_path, "/bridge_audio_count");
  1639. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1640. }
  1641. }
  1642. void CarlaEngine::osc_send_bridge_midi_count(const int32_t ins, const int32_t outs, const int32_t total)
  1643. {
  1644. qDebug("CarlaEngine::osc_send_bridge_midi_count(%i, %i, %i)", ins, outs, total);
  1645. CARLA_ASSERT(m_oscData);
  1646. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1647. if (m_oscData && m_oscData->target)
  1648. {
  1649. char target_path[strlen(m_oscData->path)+19];
  1650. strcpy(target_path, m_oscData->path);
  1651. strcat(target_path, "/bridge_midi_count");
  1652. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1653. }
  1654. }
  1655. void CarlaEngine::osc_send_bridge_parameter_count(const int32_t ins, const int32_t outs, const int32_t total)
  1656. {
  1657. qDebug("CarlaEngine::osc_send_bridge_parameter_count(%i, %i, %i)", ins, outs, total);
  1658. CARLA_ASSERT(m_oscData);
  1659. CARLA_ASSERT(total >= 0 && total >= ins + outs);
  1660. if (m_oscData && m_oscData->target)
  1661. {
  1662. char target_path[strlen(m_oscData->path)+24];
  1663. strcpy(target_path, m_oscData->path);
  1664. strcat(target_path, "/bridge_parameter_count");
  1665. lo_send(m_oscData->target, target_path, "iii", ins, outs, total);
  1666. }
  1667. }
  1668. void CarlaEngine::osc_send_bridge_program_count(const int32_t count)
  1669. {
  1670. qDebug("CarlaEngine::osc_send_bridge_program_count(%i)", count);
  1671. CARLA_ASSERT(m_oscData);
  1672. CARLA_ASSERT(count >= 0);
  1673. if (m_oscData && m_oscData->target)
  1674. {
  1675. char target_path[strlen(m_oscData->path)+22];
  1676. strcpy(target_path, m_oscData->path);
  1677. strcat(target_path, "/bridge_program_count");
  1678. lo_send(m_oscData->target, target_path, "i", count);
  1679. }
  1680. }
  1681. void CarlaEngine::osc_send_bridge_midi_program_count(const int32_t count)
  1682. {
  1683. qDebug("CarlaEngine::osc_send_bridge_midi_program_count(%i)", count);
  1684. CARLA_ASSERT(m_oscData);
  1685. CARLA_ASSERT(count >= 0);
  1686. if (m_oscData && m_oscData->target)
  1687. {
  1688. char target_path[strlen(m_oscData->path)+27];
  1689. strcpy(target_path, m_oscData->path);
  1690. strcat(target_path, "/bridge_midi_program_count");
  1691. lo_send(m_oscData->target, target_path, "i", count);
  1692. }
  1693. }
  1694. void CarlaEngine::osc_send_bridge_plugin_info(const int32_t category, const int32_t hints, const char* const name, const char* const label, const char* const maker, const char* const copyright, const int64_t uniqueId)
  1695. {
  1696. qDebug("CarlaEngine::osc_send_bridge_plugin_info(%i, %i, \"%s\", \"%s\", \"%s\", \"%s\", " P_INT64 ")", category, hints, name, label, maker, copyright, uniqueId);
  1697. CARLA_ASSERT(m_oscData);
  1698. CARLA_ASSERT(name);
  1699. CARLA_ASSERT(label);
  1700. CARLA_ASSERT(maker);
  1701. CARLA_ASSERT(copyright);
  1702. if (m_oscData && m_oscData->target)
  1703. {
  1704. char target_path[strlen(m_oscData->path)+20];
  1705. strcpy(target_path, m_oscData->path);
  1706. strcat(target_path, "/bridge_plugin_info");
  1707. lo_send(m_oscData->target, target_path, "iissssh", category, hints, name, label, maker, copyright, uniqueId);
  1708. }
  1709. }
  1710. void CarlaEngine::osc_send_bridge_parameter_info(const int32_t index, const char* const name, const char* const unit)
  1711. {
  1712. qDebug("CarlaEngine::osc_send_bridge_parameter_info(%i, \"%s\", \"%s\")", index, name, unit);
  1713. CARLA_ASSERT(m_oscData);
  1714. CARLA_ASSERT(name);
  1715. CARLA_ASSERT(unit);
  1716. if (m_oscData && m_oscData->target)
  1717. {
  1718. char target_path[strlen(m_oscData->path)+23];
  1719. strcpy(target_path, m_oscData->path);
  1720. strcat(target_path, "/bridge_parameter_info");
  1721. lo_send(m_oscData->target, target_path, "iss", index, name, unit);
  1722. }
  1723. }
  1724. void CarlaEngine::osc_send_bridge_parameter_data(const int32_t index, const int32_t type, const int32_t rindex, const int32_t hints, const int32_t midiChannel, const int32_t midiCC)
  1725. {
  1726. qDebug("CarlaEngine::osc_send_bridge_parameter_data(%i, %i, %i, %i, %i, %i)", index, type, rindex, hints, midiChannel, midiCC);
  1727. CARLA_ASSERT(m_oscData);
  1728. if (m_oscData && m_oscData->target)
  1729. {
  1730. char target_path[strlen(m_oscData->path)+23];
  1731. strcpy(target_path, m_oscData->path);
  1732. strcat(target_path, "/bridge_parameter_data");
  1733. lo_send(m_oscData->target, target_path, "iiiiii", index, type, rindex, hints, midiChannel, midiCC);
  1734. }
  1735. }
  1736. void CarlaEngine::osc_send_bridge_parameter_ranges(const int32_t index, const double def, const double min, const double max, const double step, const double stepSmall, const double stepLarge)
  1737. {
  1738. qDebug("CarlaEngine::osc_send_bridge_parameter_ranges(%i, %g, %g, %g, %g, %g, %g)", index, def, min, max, step, stepSmall, stepLarge);
  1739. CARLA_ASSERT(m_oscData);
  1740. if (m_oscData && m_oscData->target)
  1741. {
  1742. char target_path[strlen(m_oscData->path)+25];
  1743. strcpy(target_path, m_oscData->path);
  1744. strcat(target_path, "/bridge_parameter_ranges");
  1745. lo_send(m_oscData->target, target_path, "idddddd", index, def, min, max, step, stepSmall, stepLarge);
  1746. }
  1747. }
  1748. void CarlaEngine::osc_send_bridge_program_info(const int32_t index, const char* const name)
  1749. {
  1750. qDebug("CarlaEngine::osc_send_bridge_program_info(%i, \"%s\")", index, name);
  1751. CARLA_ASSERT(m_oscData);
  1752. if (m_oscData && m_oscData->target)
  1753. {
  1754. char target_path[strlen(m_oscData->path)+21];
  1755. strcpy(target_path, m_oscData->path);
  1756. strcat(target_path, "/bridge_program_info");
  1757. lo_send(m_oscData->target, target_path, "is", index, name);
  1758. }
  1759. }
  1760. void CarlaEngine::osc_send_bridge_midi_program_info(const int32_t index, const int32_t bank, const int32_t program, const char* const label)
  1761. {
  1762. qDebug("CarlaEngine::osc_send_bridge_midi_program_info(%i, %i, %i, \"%s\")", index, bank, program, label);
  1763. CARLA_ASSERT(m_oscData);
  1764. if (m_oscData && m_oscData->target)
  1765. {
  1766. char target_path[strlen(m_oscData->path)+26];
  1767. strcpy(target_path, m_oscData->path);
  1768. strcat(target_path, "/bridge_midi_program_info");
  1769. lo_send(m_oscData->target, target_path, "iiis", index, bank, program, label);
  1770. }
  1771. }
  1772. void CarlaEngine::osc_send_bridge_configure(const char* const key, const char* const value)
  1773. {
  1774. qDebug("CarlaEngine::osc_send_bridge_configure(\"%s\", \"%s\")", key, value);
  1775. CARLA_ASSERT(m_oscData);
  1776. CARLA_ASSERT(key);
  1777. CARLA_ASSERT(value);
  1778. if (m_oscData && m_oscData->target)
  1779. {
  1780. char target_path[strlen(m_oscData->path)+18];
  1781. strcpy(target_path, m_oscData->path);
  1782. strcat(target_path, "/bridge_configure");
  1783. lo_send(m_oscData->target, target_path, "ss", key, value);
  1784. }
  1785. }
  1786. void CarlaEngine::osc_send_bridge_set_parameter_value(const int32_t index, const double value)
  1787. {
  1788. qDebug("CarlaEngine::osc_send_bridge_set_parameter_value(%i, %g)", index, value);
  1789. CARLA_ASSERT(m_oscData);
  1790. if (m_oscData && m_oscData->target)
  1791. {
  1792. char target_path[strlen(m_oscData->path)+28];
  1793. strcpy(target_path, m_oscData->path);
  1794. strcat(target_path, "/bridge_set_parameter_value");
  1795. lo_send(m_oscData->target, target_path, "id", index, value);
  1796. }
  1797. }
  1798. void CarlaEngine::osc_send_bridge_set_default_value(const int32_t index, const double value)
  1799. {
  1800. qDebug("CarlaEngine::osc_send_bridge_set_default_value(%i, %g)", index, value);
  1801. CARLA_ASSERT(m_oscData);
  1802. if (m_oscData && m_oscData->target)
  1803. {
  1804. char target_path[strlen(m_oscData->path)+26];
  1805. strcpy(target_path, m_oscData->path);
  1806. strcat(target_path, "/bridge_set_default_value");
  1807. lo_send(m_oscData->target, target_path, "id", index, value);
  1808. }
  1809. }
  1810. void CarlaEngine::osc_send_bridge_set_program(const int32_t index)
  1811. {
  1812. qDebug("CarlaEngine::osc_send_bridge_set_program(%i)", index);
  1813. CARLA_ASSERT(m_oscData);
  1814. if (m_oscData && m_oscData->target)
  1815. {
  1816. char target_path[strlen(m_oscData->path)+20];
  1817. strcpy(target_path, m_oscData->path);
  1818. strcat(target_path, "/bridge_set_program");
  1819. lo_send(m_oscData->target, target_path, "i", index);
  1820. }
  1821. }
  1822. void CarlaEngine::osc_send_bridge_set_midi_program(const int32_t index)
  1823. {
  1824. qDebug("CarlaEngine::osc_send_bridge_set_midi_program(%i)", index);
  1825. CARLA_ASSERT(m_oscData);
  1826. if (m_oscData && m_oscData->target)
  1827. {
  1828. char target_path[strlen(m_oscData->path)+25];
  1829. strcpy(target_path, m_oscData->path);
  1830. strcat(target_path, "/bridge_set_midi_program");
  1831. lo_send(m_oscData->target, target_path, "i", index);
  1832. }
  1833. }
  1834. void CarlaEngine::osc_send_bridge_set_custom_data(const char* const stype, const char* const key, const char* const value)
  1835. {
  1836. qDebug("CarlaEngine::osc_send_bridge_set_custom_data(\"%s\", \"%s\", \"%s\")", stype, key, value);
  1837. CARLA_ASSERT(m_oscData);
  1838. if (m_oscData && m_oscData->target)
  1839. {
  1840. char target_path[strlen(m_oscData->path)+24];
  1841. strcpy(target_path, m_oscData->path);
  1842. strcat(target_path, "/bridge_set_custom_data");
  1843. lo_send(m_oscData->target, target_path, "sss", stype, key, value);
  1844. }
  1845. }
  1846. void CarlaEngine::osc_send_bridge_set_chunk_data(const char* const chunkFile)
  1847. {
  1848. qDebug("CarlaEngine::osc_send_bridge_set_chunk_data(\"%s\")", chunkFile);
  1849. CARLA_ASSERT(m_oscData);
  1850. if (m_oscData && m_oscData->target)
  1851. {
  1852. char target_path[strlen(m_oscData->path)+23];
  1853. strcpy(target_path, m_oscData->path);
  1854. strcat(target_path, "/bridge_set_chunk_data");
  1855. lo_send(m_oscData->target, target_path, "s", chunkFile);
  1856. }
  1857. }
  1858. void CarlaEngine::osc_send_bridge_set_inpeak(const int32_t portId, const double value)
  1859. {
  1860. CARLA_ASSERT(m_oscData);
  1861. CARLA_ASSERT(portId == 1 || portId == 2);
  1862. if (m_oscData && m_oscData->target)
  1863. {
  1864. char target_path[strlen(m_oscData->path)+28];
  1865. strcpy(target_path, m_oscData->path);
  1866. strcat(target_path, "/bridge_set_inpeak");
  1867. lo_send(m_oscData->target, target_path, "id", portId, value);
  1868. }
  1869. }
  1870. void CarlaEngine::osc_send_bridge_set_outpeak(const int32_t portId, const double value)
  1871. {
  1872. CARLA_ASSERT(m_oscData);
  1873. CARLA_ASSERT(portId == 1 || portId == 2);
  1874. if (m_oscData && m_oscData->target)
  1875. {
  1876. char target_path[strlen(m_oscData->path)+29];
  1877. strcpy(target_path, m_oscData->path);
  1878. strcat(target_path, "/bridge_set_outpeak");
  1879. lo_send(m_oscData->target, target_path, "id", portId, value);
  1880. }
  1881. }
  1882. #endif
  1883. CARLA_BACKEND_END_NAMESPACE