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.

2283 lines
68KB

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