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.

2244 lines
67KB

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