Audio plugin host https://kx.studio/carla
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.

2367 lines
82KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2017 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 doc/GPL.txt file.
  16. */
  17. /* TODO:
  18. * - complete processRack(): carefully add to input, sorted events
  19. * - implement processPatchbay()
  20. * - implement oscSend_control_switch_plugins()
  21. * - something about the peaks?
  22. */
  23. #include "CarlaEngineInternal.hpp"
  24. #include "CarlaPlugin.hpp"
  25. #include "CarlaBackendUtils.hpp"
  26. #include "CarlaBinaryUtils.hpp"
  27. #include "CarlaEngineUtils.hpp"
  28. #include "CarlaMathUtils.hpp"
  29. #include "CarlaPipeUtils.hpp"
  30. #include "CarlaStateUtils.hpp"
  31. #include "CarlaMIDI.h"
  32. #include "jackbridge/JackBridge.hpp"
  33. #include "water/files/File.h"
  34. #include "water/streams/MemoryOutputStream.h"
  35. #include "water/xml/XmlDocument.h"
  36. #include "water/xml/XmlElement.h"
  37. using water::Array;
  38. using water::CharPointer_UTF8;
  39. using water::File;
  40. using water::MemoryOutputStream;
  41. using water::String;
  42. using water::StringArray;
  43. using water::XmlDocument;
  44. using water::XmlElement;
  45. CARLA_BACKEND_START_NAMESPACE
  46. // -----------------------------------------------------------------------
  47. // Carla Engine
  48. CarlaEngine::CarlaEngine()
  49. : pData(new ProtectedData(this))
  50. {
  51. carla_debug("CarlaEngine::CarlaEngine()");
  52. }
  53. CarlaEngine::~CarlaEngine()
  54. {
  55. carla_debug("CarlaEngine::~CarlaEngine()");
  56. delete pData;
  57. }
  58. // -----------------------------------------------------------------------
  59. // Static calls
  60. uint CarlaEngine::getDriverCount()
  61. {
  62. carla_debug("CarlaEngine::getDriverCount()");
  63. uint count = 0;
  64. if (jackbridge_is_ok())
  65. count += 1;
  66. #ifndef BUILD_BRIDGE
  67. count += getRtAudioApiCount();
  68. #endif
  69. return count;
  70. }
  71. const char* CarlaEngine::getDriverName(const uint index2)
  72. {
  73. carla_debug("CarlaEngine::getDriverName(%i)", index2);
  74. uint index(index2);
  75. if (jackbridge_is_ok() && index-- == 0)
  76. return "JACK";
  77. #ifndef BUILD_BRIDGE
  78. if (const uint count = getRtAudioApiCount())
  79. {
  80. if (index < count)
  81. return getRtAudioApiName(index);
  82. index -= count;
  83. }
  84. #endif
  85. carla_stderr("CarlaEngine::getDriverName(%i) - invalid index", index2);
  86. return nullptr;
  87. }
  88. const char* const* CarlaEngine::getDriverDeviceNames(const uint index2)
  89. {
  90. carla_debug("CarlaEngine::getDriverDeviceNames(%i)", index2);
  91. uint index(index2);
  92. if (jackbridge_is_ok() && index-- == 0)
  93. {
  94. static const char* ret[3] = { "Auto-Connect OFF", "Auto-Connect ON", nullptr };
  95. return ret;
  96. }
  97. #ifndef BUILD_BRIDGE
  98. if (const uint count = getRtAudioApiCount())
  99. {
  100. if (index < count)
  101. return getRtAudioApiDeviceNames(index);
  102. index -= count;
  103. }
  104. #endif
  105. carla_stderr("CarlaEngine::getDriverDeviceNames(%i) - invalid index", index2);
  106. return nullptr;
  107. }
  108. const EngineDriverDeviceInfo* CarlaEngine::getDriverDeviceInfo(const uint index2, const char* const deviceName)
  109. {
  110. carla_debug("CarlaEngine::getDriverDeviceInfo(%i, \"%s\")", index2, deviceName);
  111. uint index(index2);
  112. if (jackbridge_is_ok() && index-- == 0)
  113. {
  114. static uint32_t bufSizes[11] = { 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 0 };
  115. static EngineDriverDeviceInfo devInfo;
  116. devInfo.hints = ENGINE_DRIVER_DEVICE_VARIABLE_BUFFER_SIZE;
  117. devInfo.bufferSizes = bufSizes;
  118. devInfo.sampleRates = nullptr;
  119. return &devInfo;
  120. }
  121. #ifndef BUILD_BRIDGE
  122. if (const uint count = getRtAudioApiCount())
  123. {
  124. if (index < count)
  125. return getRtAudioDeviceInfo(index, deviceName);
  126. index -= count;
  127. }
  128. #endif
  129. carla_stderr("CarlaEngine::getDriverDeviceNames(%i, \"%s\") - invalid index", index2, deviceName);
  130. return nullptr;
  131. }
  132. CarlaEngine* CarlaEngine::newDriverByName(const char* const driverName)
  133. {
  134. CARLA_SAFE_ASSERT_RETURN(driverName != nullptr && driverName[0] != '\0', nullptr);
  135. carla_debug("CarlaEngine::newDriverByName(\"%s\")", driverName);
  136. if (std::strcmp(driverName, "JACK") == 0)
  137. return newJack();
  138. #ifndef BUILD_BRIDGE
  139. // -------------------------------------------------------------------
  140. // common
  141. if (std::strcmp(driverName, "Dummy") == 0)
  142. return newRtAudio(AUDIO_API_NULL);
  143. if (std::strncmp(driverName, "JACK ", 5) == 0)
  144. return newRtAudio(AUDIO_API_JACK);
  145. if (std::strcmp(driverName, "OSS") == 0)
  146. return newRtAudio(AUDIO_API_OSS);
  147. // -------------------------------------------------------------------
  148. // linux
  149. if (std::strcmp(driverName, "ALSA") == 0)
  150. return newRtAudio(AUDIO_API_ALSA);
  151. if (std::strcmp(driverName, "PulseAudio") == 0)
  152. return newRtAudio(AUDIO_API_PULSEAUDIO);
  153. // -------------------------------------------------------------------
  154. // macos
  155. if (std::strcmp(driverName, "CoreAudio") == 0)
  156. return newRtAudio(AUDIO_API_COREAUDIO);
  157. // -------------------------------------------------------------------
  158. // windows
  159. if (std::strcmp(driverName, "ASIO") == 0)
  160. return newRtAudio(AUDIO_API_ASIO);
  161. if (std::strcmp(driverName, "DirectSound") == 0)
  162. return newRtAudio(AUDIO_API_DIRECTSOUND);
  163. if (std::strcmp(driverName, "WASAPI") == 0)
  164. return newRtAudio(AUDIO_API_WASAPI);
  165. #endif
  166. carla_stderr("CarlaEngine::newDriverByName(\"%s\") - invalid driver name", driverName);
  167. return nullptr;
  168. }
  169. // -----------------------------------------------------------------------
  170. // Constant values
  171. uint CarlaEngine::getMaxClientNameSize() const noexcept
  172. {
  173. return STR_MAX/2;
  174. }
  175. uint CarlaEngine::getMaxPortNameSize() const noexcept
  176. {
  177. return STR_MAX;
  178. }
  179. uint CarlaEngine::getCurrentPluginCount() const noexcept
  180. {
  181. return pData->curPluginCount;
  182. }
  183. uint CarlaEngine::getMaxPluginNumber() const noexcept
  184. {
  185. return pData->maxPluginNumber;
  186. }
  187. // -----------------------------------------------------------------------
  188. // Virtual, per-engine type calls
  189. bool CarlaEngine::close()
  190. {
  191. carla_debug("CarlaEngine::close()");
  192. if (pData->curPluginCount != 0)
  193. {
  194. pData->aboutToClose = true;
  195. removeAllPlugins();
  196. }
  197. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  198. if (pData->osc.isControlRegistered())
  199. oscSend_control_exit();
  200. #endif
  201. pData->close();
  202. callback(ENGINE_CALLBACK_ENGINE_STOPPED, 0, 0, 0, 0.0f, nullptr);
  203. return true;
  204. }
  205. bool CarlaEngine::usesConstantBufferSize() const noexcept
  206. {
  207. return true;
  208. }
  209. void CarlaEngine::idle() noexcept
  210. {
  211. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull,); // FIXME REMOVE
  212. CARLA_SAFE_ASSERT_RETURN(pData->nextPluginId == pData->maxPluginNumber,);
  213. CARLA_SAFE_ASSERT_RETURN(getType() != kEngineTypePlugin,);
  214. for (uint i=0; i < pData->curPluginCount; ++i)
  215. {
  216. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  217. if (plugin != nullptr && plugin->isEnabled())
  218. {
  219. const uint hints(plugin->getHints());
  220. if ((hints & PLUGIN_HAS_CUSTOM_UI) != 0 && (hints & PLUGIN_NEEDS_UI_MAIN_THREAD) != 0)
  221. {
  222. try {
  223. plugin->uiIdle();
  224. } CARLA_SAFE_EXCEPTION_CONTINUE("Plugin uiIdle");
  225. }
  226. }
  227. }
  228. #ifdef HAVE_LIBLO
  229. pData->osc.idle();
  230. #endif
  231. }
  232. CarlaEngineClient* CarlaEngine::addClient(CarlaPlugin* const)
  233. {
  234. return new CarlaEngineClient(*this);
  235. }
  236. // -----------------------------------------------------------------------
  237. // Plugin management
  238. bool CarlaEngine::addPlugin(const BinaryType btype, const PluginType ptype,
  239. const char* const filename, const char* const name, const char* const label, const int64_t uniqueId,
  240. const void* const extra, const uint options)
  241. {
  242. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  243. #ifndef BUILD_BRIDGE
  244. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  245. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId <= pData->maxPluginNumber, "Invalid engine internal data");
  246. #endif
  247. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  248. CARLA_SAFE_ASSERT_RETURN_ERR(btype != BINARY_NONE, "Invalid plugin binary mode");
  249. CARLA_SAFE_ASSERT_RETURN_ERR(ptype != PLUGIN_NONE, "Invalid plugin type");
  250. CARLA_SAFE_ASSERT_RETURN_ERR((filename != nullptr && filename[0] != '\0') || (label != nullptr && label[0] != '\0'), "Invalid plugin filename and label");
  251. carla_debug("CarlaEngine::addPlugin(%i:%s, %i:%s, \"%s\", \"%s\", \"%s\", " P_INT64 ", %p, %u)", btype, BinaryType2Str(btype), ptype, PluginType2Str(ptype), filename, name, label, uniqueId, extra, options);
  252. uint id;
  253. #ifndef BUILD_BRIDGE
  254. CarlaPlugin* oldPlugin = nullptr;
  255. if (pData->nextPluginId < pData->curPluginCount)
  256. {
  257. id = pData->nextPluginId;
  258. pData->nextPluginId = pData->maxPluginNumber;
  259. oldPlugin = pData->plugins[id].plugin;
  260. CARLA_SAFE_ASSERT_RETURN_ERR(oldPlugin != nullptr, "Invalid replace plugin Id");
  261. }
  262. else
  263. #endif
  264. {
  265. id = pData->curPluginCount;
  266. if (id == pData->maxPluginNumber)
  267. {
  268. setLastError("Maximum number of plugins reached");
  269. return false;
  270. }
  271. #ifndef BUILD_BRIDGE
  272. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins[id].plugin == nullptr, "Invalid engine internal data");
  273. #endif
  274. }
  275. CarlaPlugin::Initializer initializer = {
  276. this,
  277. id,
  278. filename,
  279. name,
  280. label,
  281. uniqueId,
  282. options
  283. };
  284. CarlaPlugin* plugin = nullptr;
  285. CarlaString bridgeBinary(pData->options.binaryDir);
  286. if (bridgeBinary.isNotEmpty())
  287. {
  288. if (btype == BINARY_NATIVE)
  289. {
  290. #ifdef CARLA_OS_WIN
  291. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-native.exe";
  292. #else
  293. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-native";
  294. #endif
  295. }
  296. else
  297. {
  298. switch (btype)
  299. {
  300. case BINARY_POSIX32:
  301. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-posix32";
  302. break;
  303. case BINARY_POSIX64:
  304. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-posix64";
  305. break;
  306. case BINARY_WIN32:
  307. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-win32.exe";
  308. break;
  309. case BINARY_WIN64:
  310. bridgeBinary += CARLA_OS_SEP_STR "carla-bridge-win64.exe";
  311. break;
  312. default:
  313. bridgeBinary.clear();
  314. break;
  315. }
  316. }
  317. if (! File(bridgeBinary.buffer()).existsAsFile())
  318. bridgeBinary.clear();
  319. }
  320. // Prefer bridges for some specific plugins
  321. bool preferBridges = pData->options.preferPluginBridges;
  322. #ifndef BUILD_BRIDGE
  323. if (! preferBridges)
  324. {
  325. if (ptype == PLUGIN_LV2 && label != nullptr)
  326. {
  327. if (std::strncmp(label, "http://calf.sourceforge.net/plugins/", 36) == 0 ||
  328. std::strcmp(label, "http://factorial.hu/plugins/lv2/ir") == 0 ||
  329. std::strstr(label, "v1.sourceforge.net/lv2") != nullptr)
  330. {
  331. preferBridges = true;
  332. }
  333. }
  334. # if 0
  335. else if (ptype == PLUGIN_VST2)
  336. {
  337. /*
  338. char uniqueIdChars[5] = {
  339. static_cast<char>((uniqueId & 0xFF000000) >> 24),
  340. static_cast<char>((uniqueId & 0x00FF0000) >> 16),
  341. static_cast<char>((uniqueId & 0x0000FF00) >> 8),
  342. static_cast<char>((uniqueId & 0x000000FF) >> 1),
  343. 0
  344. };
  345. */
  346. /**/ if (uniqueId == 1633895765 && std::strstr(filename, "/ACE.") != nullptr)
  347. preferBridges = true;
  348. else if (uniqueId == 1433421876 && std::strstr(filename, "/Bazille.") != nullptr)
  349. preferBridges = true;
  350. else if (uniqueId == 1147754081 && std::strstr(filename, "/Diva.") != nullptr)
  351. preferBridges = true;
  352. else if (uniqueId == 1095583057 && std::strstr(filename, "/Filterscape.") != nullptr)
  353. preferBridges = true;
  354. else if (uniqueId == 1179866689 && std::strstr(filename, "/Filterscape.") != nullptr)
  355. preferBridges = true;
  356. else if (uniqueId == 1179865398 && std::strstr(filename, "/Filterscape.") != nullptr)
  357. preferBridges = true;
  358. else if (uniqueId == 1749636677 && std::strstr(filename, "/Hive.") != nullptr)
  359. preferBridges = true;
  360. else if (uniqueId == 1296452914 && std::strstr(filename, "/MFM2.") != nullptr)
  361. preferBridges = true;
  362. else if (uniqueId == 1349477487 && std::strstr(filename, "/Podolski.") != nullptr)
  363. preferBridges = true;
  364. else if (uniqueId == 1886548821 && std::strstr(filename, "/Presswerk.") != nullptr)
  365. preferBridges = true;
  366. else if (uniqueId == 1969770582 && std::strstr(filename, "/Protoverb.") != nullptr)
  367. preferBridges = true;
  368. else if (uniqueId == 1969771348 && std::strstr(filename, "/Satin.") != nullptr)
  369. preferBridges = true;
  370. else if (uniqueId == 1667388281 && std::strstr(filename, "/TripleCheese.") != nullptr)
  371. preferBridges = true;
  372. else if (uniqueId == 1952017974 && std::strstr(filename, "/TyrellN6.") != nullptr)
  373. preferBridges = true;
  374. else if (uniqueId == 1432568113 && std::strstr(filename, "/Uhbik.") != nullptr)
  375. preferBridges = true;
  376. else if (uniqueId == 1432568881 && std::strstr(filename, "/Uhbik.") != nullptr)
  377. preferBridges = true;
  378. else if (uniqueId == 1432572209 && std::strstr(filename, "/Uhbik.") != nullptr)
  379. preferBridges = true;
  380. else if (uniqueId == 1432569393 && std::strstr(filename, "/Uhbik.") != nullptr)
  381. preferBridges = true;
  382. else if (uniqueId == 1432569649 && std::strstr(filename, "/Uhbik.") != nullptr)
  383. preferBridges = true;
  384. else if (uniqueId == 1432571953 && std::strstr(filename, "/Uhbik.") != nullptr)
  385. preferBridges = true;
  386. else if (uniqueId == 1382232375 && std::strstr(filename, "/Uhbik.") != nullptr)
  387. preferBridges = true;
  388. else if (uniqueId == 1432572721 && std::strstr(filename, "/Uhbik.") != nullptr)
  389. preferBridges = true;
  390. else if (uniqueId == 1432572977 && std::strstr(filename, "/Uhbik.") != nullptr)
  391. preferBridges = true;
  392. else if (uniqueId == 1397572658 && std::strstr(filename, "/Zebra2.") != nullptr)
  393. preferBridges = true;
  394. else if (uniqueId == 1397572659 && std::strstr(filename, "/Zebra2.") != nullptr)
  395. preferBridges = true;
  396. else if (uniqueId == 1919243824 && std::strstr(filename, "/Zebra2.") != nullptr)
  397. preferBridges = true;
  398. else if (uniqueId == 1397578034 && std::strstr(filename, "/Zebra2.") != nullptr)
  399. preferBridges = true;
  400. else if (uniqueId == 1397573722 && std::strstr(filename, "/ZebraHZ.") != nullptr)
  401. preferBridges = true;
  402. }
  403. # endif
  404. // FIXME: linuxsampler inside carla-rack/patchbay plugin has some issues (only last kit makes noise)
  405. else if (getType() == kEngineTypePlugin && (ptype == PLUGIN_GIG || ptype == PLUGIN_SFZ))
  406. {
  407. // if we're not loading a project consider all is ok
  408. if (! pData->loadingProject)
  409. pData->firstLinuxSamplerInstance = true;
  410. // loading a project, revert first status if set
  411. else if (pData->firstLinuxSamplerInstance)
  412. pData->firstLinuxSamplerInstance = false;
  413. // now check if bridge is needed
  414. if (! pData->firstLinuxSamplerInstance)
  415. preferBridges = true;
  416. }
  417. }
  418. #endif // ! BUILD_BRIDGE
  419. if (ptype != PLUGIN_INTERNAL && (btype != BINARY_NATIVE || (preferBridges && bridgeBinary.isNotEmpty())))
  420. {
  421. if (bridgeBinary.isNotEmpty())
  422. {
  423. plugin = CarlaPlugin::newBridge(initializer, btype, ptype, bridgeBinary);
  424. }
  425. else
  426. {
  427. setLastError("This Carla build cannot handle this binary");
  428. return false;
  429. }
  430. }
  431. else
  432. {
  433. bool use16Outs;
  434. setLastError("Invalid or unsupported plugin type");
  435. switch (ptype)
  436. {
  437. case PLUGIN_NONE:
  438. break;
  439. case PLUGIN_INTERNAL:
  440. /*if (std::strcmp(label, "FluidSynth") == 0)
  441. {
  442. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  443. plugin = CarlaPlugin::newFluidSynth(initializer, use16Outs);
  444. }
  445. else if (std::strcmp(label, "LinuxSampler (GIG)") == 0)
  446. {
  447. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  448. plugin = CarlaPlugin::newLinuxSampler(initializer, "GIG", use16Outs);
  449. }
  450. else if (std::strcmp(label, "LinuxSampler (SF2)") == 0)
  451. {
  452. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  453. plugin = CarlaPlugin::newLinuxSampler(initializer, "SF2", use16Outs);
  454. }
  455. else if (std::strcmp(label, "LinuxSampler (SFZ)") == 0)
  456. {
  457. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  458. plugin = CarlaPlugin::newLinuxSampler(initializer, "SFZ", use16Outs);
  459. }*/
  460. plugin = CarlaPlugin::newNative(initializer);
  461. break;
  462. case PLUGIN_LADSPA:
  463. plugin = CarlaPlugin::newLADSPA(initializer, (const LADSPA_RDF_Descriptor*)extra);
  464. break;
  465. case PLUGIN_DSSI:
  466. plugin = CarlaPlugin::newDSSI(initializer);
  467. break;
  468. case PLUGIN_LV2:
  469. plugin = CarlaPlugin::newLV2(initializer);
  470. break;
  471. case PLUGIN_VST2:
  472. plugin = CarlaPlugin::newVST2(initializer);
  473. break;
  474. case PLUGIN_GIG:
  475. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  476. plugin = CarlaPlugin::newFileGIG(initializer, use16Outs);
  477. break;
  478. case PLUGIN_SF2:
  479. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  480. plugin = CarlaPlugin::newFileSF2(initializer, use16Outs);
  481. break;
  482. case PLUGIN_SFZ:
  483. plugin = CarlaPlugin::newFileSFZ(initializer);
  484. break;
  485. case PLUGIN_JACK:
  486. plugin = CarlaPlugin::newJackApp(initializer);
  487. break;
  488. }
  489. }
  490. if (plugin == nullptr)
  491. return false;
  492. plugin->reload();
  493. #ifndef BUILD_BRIDGE
  494. bool canRun = true;
  495. /**/ if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
  496. {
  497. /**/ if (! plugin->canRunInRack())
  498. {
  499. setLastError("Carla's rack mode can only work with Mono or Stereo plugins, sorry!");
  500. canRun = false;
  501. }
  502. else if (plugin->getCVInCount() > 0 || plugin->getCVInCount() > 0)
  503. {
  504. setLastError("Carla's rack mode cannot work with plugins that have CV ports, sorry!");
  505. canRun = false;
  506. }
  507. }
  508. else if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  509. {
  510. /**/ if (plugin->getMidiInCount() > 1 || plugin->getMidiOutCount() > 1)
  511. {
  512. setLastError("Carla's patchbay mode cannot work with plugins that have multiple MIDI ports, sorry!");
  513. canRun = false;
  514. }
  515. else if (plugin->getCVInCount() > 0 || plugin->getCVInCount() > 0)
  516. {
  517. setLastError("CV ports in patchbay mode is still TODO");
  518. canRun = false;
  519. }
  520. }
  521. if (! canRun)
  522. {
  523. delete plugin;
  524. return false;
  525. }
  526. # ifdef HAVE_LIBLO
  527. plugin->registerToOscClient();
  528. # endif
  529. #endif
  530. EnginePluginData& pluginData(pData->plugins[id]);
  531. pluginData.plugin = plugin;
  532. pluginData.insPeak[0] = 0.0f;
  533. pluginData.insPeak[1] = 0.0f;
  534. pluginData.outsPeak[0] = 0.0f;
  535. pluginData.outsPeak[1] = 0.0f;
  536. #ifndef BUILD_BRIDGE
  537. if (oldPlugin != nullptr)
  538. {
  539. CARLA_SAFE_ASSERT(! pData->loadingProject);
  540. const ScopedThreadStopper sts(this);
  541. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  542. pData->graph.replacePlugin(oldPlugin, plugin);
  543. const bool wasActive = oldPlugin->getInternalParameterValue(PARAMETER_ACTIVE) >= 0.5f;
  544. const float oldDryWet = oldPlugin->getInternalParameterValue(PARAMETER_DRYWET);
  545. const float oldVolume = oldPlugin->getInternalParameterValue(PARAMETER_VOLUME);
  546. delete oldPlugin;
  547. if (plugin->getHints() & PLUGIN_CAN_DRYWET)
  548. plugin->setDryWet(oldDryWet, true, true);
  549. if (plugin->getHints() & PLUGIN_CAN_VOLUME)
  550. plugin->setVolume(oldVolume, true, true);
  551. plugin->setActive(wasActive, true, true);
  552. plugin->setEnabled(true);
  553. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, nullptr);
  554. }
  555. else if (! pData->loadingProject)
  556. #endif
  557. {
  558. plugin->setActive(true, true, false);
  559. plugin->setEnabled(true);
  560. ++pData->curPluginCount;
  561. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  562. #ifndef BUILD_BRIDGE
  563. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  564. pData->graph.addPlugin(plugin);
  565. #endif
  566. }
  567. return true;
  568. }
  569. bool CarlaEngine::addPlugin(const PluginType ptype, const char* const filename, const char* const name, const char* const label, const int64_t uniqueId, const void* const extra)
  570. {
  571. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, uniqueId, extra, 0x0);
  572. }
  573. bool CarlaEngine::removePlugin(const uint id)
  574. {
  575. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  576. #ifndef BUILD_BRIDGE
  577. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  578. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  579. #endif
  580. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  581. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  582. carla_debug("CarlaEngine::removePlugin(%i)", id);
  583. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  584. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  585. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  586. const ScopedThreadStopper sts(this);
  587. #ifndef BUILD_BRIDGE
  588. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  589. pData->graph.removePlugin(plugin);
  590. const bool lockWait(isRunning() /*&& pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS*/);
  591. const ScopedActionLock sal(this, kEnginePostActionRemovePlugin, id, 0, lockWait);
  592. /*
  593. for (uint i=id; i < pData->curPluginCount; ++i)
  594. {
  595. CarlaPlugin* const plugin2(pData->plugins[i].plugin);
  596. CARLA_SAFE_ASSERT_BREAK(plugin2 != nullptr);
  597. plugin2->updateOscURL();
  598. }
  599. */
  600. # ifdef HAVE_LIBLO
  601. if (isOscControlRegistered())
  602. oscSend_control_remove_plugin(id);
  603. # endif
  604. #else
  605. pData->curPluginCount = 0;
  606. carla_zeroStructs(pData->plugins, 1);
  607. #endif
  608. delete plugin;
  609. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  610. return true;
  611. }
  612. bool CarlaEngine::removeAllPlugins()
  613. {
  614. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  615. #ifndef BUILD_BRIDGE
  616. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  617. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data");
  618. #endif
  619. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  620. carla_debug("CarlaEngine::removeAllPlugins()");
  621. if (pData->curPluginCount == 0)
  622. return true;
  623. const ScopedThreadStopper sts(this);
  624. const uint curPluginCount(pData->curPluginCount);
  625. #ifndef BUILD_BRIDGE
  626. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  627. pData->graph.removeAllPlugins();
  628. # ifdef HAVE_LIBLO
  629. if (isOscControlRegistered())
  630. {
  631. for (uint i=0; i < curPluginCount; ++i)
  632. oscSend_control_remove_plugin(curPluginCount-i-1);
  633. }
  634. # endif
  635. #endif
  636. const bool lockWait(isRunning());
  637. const ScopedActionLock sal(this, kEnginePostActionZeroCount, 0, 0, lockWait);
  638. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  639. for (uint i=0; i < curPluginCount; ++i)
  640. {
  641. EnginePluginData& pluginData(pData->plugins[i]);
  642. if (pluginData.plugin != nullptr)
  643. {
  644. delete pluginData.plugin;
  645. pluginData.plugin = nullptr;
  646. }
  647. pluginData.insPeak[0] = 0.0f;
  648. pluginData.insPeak[1] = 0.0f;
  649. pluginData.outsPeak[0] = 0.0f;
  650. pluginData.outsPeak[1] = 0.0f;
  651. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  652. }
  653. return true;
  654. }
  655. #ifndef BUILD_BRIDGE
  656. const char* CarlaEngine::renamePlugin(const uint id, const char* const newName)
  657. {
  658. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  659. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data");
  660. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data");
  661. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  662. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id");
  663. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  664. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  665. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  666. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  667. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data");
  668. const char* const uniqueName(getUniquePluginName(newName));
  669. CARLA_SAFE_ASSERT_RETURN_ERRN(uniqueName != nullptr, "Unable to get new unique plugin name");
  670. plugin->setName(uniqueName);
  671. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  672. pData->graph.renamePlugin(plugin, uniqueName);
  673. delete[] uniqueName;
  674. return plugin->getName();
  675. }
  676. bool CarlaEngine::clonePlugin(const uint id)
  677. {
  678. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  679. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  680. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  681. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  682. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  683. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  684. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  685. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  686. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  687. char label[STR_MAX+1];
  688. carla_zeroChars(label, STR_MAX+1);
  689. plugin->getLabel(label);
  690. const uint pluginCountBefore(pData->curPluginCount);
  691. if (! addPlugin(plugin->getBinaryType(), plugin->getType(),
  692. plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(),
  693. plugin->getExtraStuff(), plugin->getOptionsEnabled()))
  694. return false;
  695. CARLA_SAFE_ASSERT_RETURN_ERR(pluginCountBefore+1 == pData->curPluginCount, "No new plugin found");
  696. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  697. newPlugin->loadStateSave(plugin->getStateSave());
  698. return true;
  699. }
  700. bool CarlaEngine::replacePlugin(const uint id) noexcept
  701. {
  702. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  703. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  704. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  705. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  706. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  707. // might use this to reset
  708. if (id == pData->maxPluginNumber)
  709. {
  710. pData->nextPluginId = pData->maxPluginNumber;
  711. return true;
  712. }
  713. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  714. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  715. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  716. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  717. pData->nextPluginId = id;
  718. return true;
  719. }
  720. bool CarlaEngine::switchPlugins(const uint idA, const uint idB) noexcept
  721. {
  722. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  723. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  724. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount >= 2, "Invalid engine internal data");
  725. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  726. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  727. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id");
  728. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id");
  729. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  730. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  731. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  732. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch");
  733. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch");
  734. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data");
  735. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data");
  736. const ScopedThreadStopper sts(this);
  737. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  738. pData->graph.replacePlugin(pluginA, pluginB);
  739. const bool lockWait(isRunning() /*&& pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS*/);
  740. const ScopedActionLock sal(this, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  741. // TODO
  742. /*
  743. pluginA->updateOscURL();
  744. pluginB->updateOscURL();
  745. if (isOscControlRegistered())
  746. oscSend_control_switch_plugins(idA, idB);
  747. */
  748. return true;
  749. }
  750. #endif
  751. CarlaPlugin* CarlaEngine::getPlugin(const uint id) const noexcept
  752. {
  753. #ifndef BUILD_BRIDGE
  754. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data");
  755. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data");
  756. #endif
  757. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  758. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id");
  759. return pData->plugins[id].plugin;
  760. }
  761. CarlaPlugin* CarlaEngine::getPluginUnchecked(const uint id) const noexcept
  762. {
  763. return pData->plugins[id].plugin;
  764. }
  765. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  766. {
  767. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  768. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  769. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  770. CarlaString sname;
  771. sname = name;
  772. if (sname.isEmpty())
  773. {
  774. sname = "(No name)";
  775. return sname.dup();
  776. }
  777. const std::size_t maxNameSize(carla_minConstrained<uint>(getMaxClientNameSize(), 0xff, 6U) - 6); // 6 = strlen(" (10)") + 1
  778. if (maxNameSize == 0 || ! isRunning())
  779. return sname.dup();
  780. sname.truncate(maxNameSize);
  781. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  782. for (uint i=0; i < pData->curPluginCount; ++i)
  783. {
  784. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  785. // Check if unique name doesn't exist
  786. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  787. {
  788. if (sname != pluginName)
  789. continue;
  790. }
  791. // Check if string has already been modified
  792. {
  793. const std::size_t len(sname.length());
  794. // 1 digit, ex: " (2)"
  795. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  796. {
  797. const int number = sname[len-2] - '0';
  798. if (number == 9)
  799. {
  800. // next number is 10, 2 digits
  801. sname.truncate(len-4);
  802. sname += " (10)";
  803. //sname.replace(" (9)", " (10)");
  804. }
  805. else
  806. sname[len-2] = char('0' + number + 1);
  807. continue;
  808. }
  809. // 2 digits, ex: " (11)"
  810. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  811. {
  812. char n2 = sname[len-2];
  813. char n3 = sname[len-3];
  814. if (n2 == '9')
  815. {
  816. n2 = '0';
  817. n3 = static_cast<char>(n3 + 1);
  818. }
  819. else
  820. n2 = static_cast<char>(n2 + 1);
  821. sname[len-2] = n2;
  822. sname[len-3] = n3;
  823. continue;
  824. }
  825. }
  826. // Modify string if not
  827. sname += " (2)";
  828. }
  829. return sname.dup();
  830. }
  831. // -----------------------------------------------------------------------
  832. // Project management
  833. bool CarlaEngine::loadFile(const char* const filename)
  834. {
  835. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  836. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  837. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  838. const String jfilename = String(CharPointer_UTF8(filename));
  839. File file(jfilename);
  840. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  841. CarlaString baseName(file.getFileNameWithoutExtension().toRawUTF8());
  842. CarlaString extension(file.getFileExtension().replace(".","").toLowerCase().toRawUTF8());
  843. const uint curPluginId(pData->nextPluginId < pData->curPluginCount ? pData->nextPluginId : pData->curPluginCount);
  844. // -------------------------------------------------------------------
  845. if (extension == "carxp" || extension == "carxs")
  846. return loadProject(filename);
  847. // -------------------------------------------------------------------
  848. if (extension == "gig")
  849. return addPlugin(PLUGIN_GIG, filename, baseName, baseName, 0, nullptr);
  850. if (extension == "sf2")
  851. return addPlugin(PLUGIN_SF2, filename, baseName, baseName, 0, nullptr);
  852. if (extension == "sfz")
  853. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName, 0, nullptr);
  854. // -------------------------------------------------------------------
  855. if (extension == "aif" || extension == "aiff" || extension == "bwf" || extension == "flac" || extension == "ogg" || extension == "wav")
  856. {
  857. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  858. {
  859. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  860. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  861. return true;
  862. }
  863. return false;
  864. }
  865. // -------------------------------------------------------------------
  866. if (extension == "mid" || extension == "midi")
  867. {
  868. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile", 0, nullptr))
  869. {
  870. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  871. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  872. return true;
  873. }
  874. return false;
  875. }
  876. // -------------------------------------------------------------------
  877. // ZynAddSubFX
  878. if (extension == "xmz" || extension == "xiz")
  879. {
  880. #ifdef HAVE_ZYN_DEPS
  881. CarlaString nicerName("Zyn - ");
  882. const std::size_t sep(baseName.find('-')+1);
  883. if (sep < baseName.length())
  884. nicerName += baseName.buffer()+sep;
  885. else
  886. nicerName += baseName;
  887. //nicerName
  888. if (addPlugin(PLUGIN_INTERNAL, nullptr, nicerName, "zynaddsubfx", 0, nullptr))
  889. {
  890. callback(ENGINE_CALLBACK_UI_STATE_CHANGED, curPluginId, 0, 0, 0.0f, nullptr);
  891. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  892. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  893. return true;
  894. }
  895. return false;
  896. #else
  897. setLastError("This Carla build does not have ZynAddSubFX support");
  898. return false;
  899. #endif
  900. }
  901. // -------------------------------------------------------------------
  902. // Direct plugin binaries
  903. #ifdef CARLA_OS_MAC
  904. if (extension == "vst")
  905. return addPlugin(PLUGIN_VST2, filename, nullptr, nullptr, 0, nullptr);
  906. #else
  907. if (extension == "dll" || extension == "so")
  908. return addPlugin(getBinaryTypeFromFile(filename), PLUGIN_VST2, filename, nullptr, nullptr, 0, nullptr, 0x0);
  909. #endif
  910. // -------------------------------------------------------------------
  911. setLastError("Unknown file extension");
  912. return false;
  913. }
  914. bool CarlaEngine::loadProject(const char* const filename)
  915. {
  916. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  917. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  918. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  919. const String jfilename = String(CharPointer_UTF8(filename));
  920. File file(jfilename);
  921. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  922. XmlDocument xml(file);
  923. return loadProjectInternal(xml);
  924. }
  925. bool CarlaEngine::saveProject(const char* const filename)
  926. {
  927. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  928. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  929. MemoryOutputStream out;
  930. saveProjectInternal(out);
  931. const String jfilename = String(CharPointer_UTF8(filename));
  932. File file(jfilename);
  933. if (file.replaceWithData(out.getData(), out.getDataSize()))
  934. return true;
  935. setLastError("Failed to write file");
  936. return false;
  937. }
  938. // -----------------------------------------------------------------------
  939. // Information (base)
  940. uint CarlaEngine::getHints() const noexcept
  941. {
  942. return pData->hints;
  943. }
  944. uint32_t CarlaEngine::getBufferSize() const noexcept
  945. {
  946. return pData->bufferSize;
  947. }
  948. double CarlaEngine::getSampleRate() const noexcept
  949. {
  950. return pData->sampleRate;
  951. }
  952. const char* CarlaEngine::getName() const noexcept
  953. {
  954. return pData->name;
  955. }
  956. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  957. {
  958. return pData->options.processMode;
  959. }
  960. const EngineOptions& CarlaEngine::getOptions() const noexcept
  961. {
  962. return pData->options;
  963. }
  964. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  965. {
  966. return pData->timeInfo;
  967. }
  968. // -----------------------------------------------------------------------
  969. // Information (peaks)
  970. float CarlaEngine::getInputPeak(const uint pluginId, const bool isLeft) const noexcept
  971. {
  972. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  973. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  974. }
  975. float CarlaEngine::getOutputPeak(const uint pluginId, const bool isLeft) const noexcept
  976. {
  977. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  978. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  979. }
  980. // -----------------------------------------------------------------------
  981. // Callback
  982. void CarlaEngine::callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  983. {
  984. #ifdef DEBUG
  985. if (action != ENGINE_CALLBACK_IDLE)
  986. carla_debug("CarlaEngine::callback(%i:%s, %i, %i, %i, %f, \"%s\")", action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  987. #endif
  988. #ifdef BUILD_BRIDGE
  989. if (pData->isIdling)
  990. #else
  991. if (pData->isIdling && action != ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED)
  992. #endif
  993. {
  994. carla_stdout("callback while idling (%i:%s, %i, %i, %i, %f, \"%s\")", action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  995. }
  996. if (pData->callback != nullptr)
  997. {
  998. if (action == ENGINE_CALLBACK_IDLE)
  999. ++pData->isIdling;
  1000. try {
  1001. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1002. #if defined(CARLA_OS_LINUX) && defined(__arm__)
  1003. } catch (__cxxabiv1::__forced_unwind&) {
  1004. carla_stderr2("Caught forced unwind exception in callback");
  1005. throw;
  1006. #endif
  1007. } catch (...) {
  1008. carla_safe_exception("callback", __FILE__, __LINE__);
  1009. }
  1010. if (action == ENGINE_CALLBACK_IDLE)
  1011. --pData->isIdling;
  1012. }
  1013. }
  1014. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1015. {
  1016. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1017. pData->callback = func;
  1018. pData->callbackPtr = ptr;
  1019. }
  1020. // -----------------------------------------------------------------------
  1021. // File Callback
  1022. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1023. {
  1024. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1025. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1026. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1027. const char* ret = nullptr;
  1028. if (pData->fileCallback != nullptr)
  1029. {
  1030. try {
  1031. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1032. } CARLA_SAFE_EXCEPTION("runFileCallback");
  1033. }
  1034. return ret;
  1035. }
  1036. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1037. {
  1038. carla_debug("CarlaEngine::setFileCallback(%p, %p)", func, ptr);
  1039. pData->fileCallback = func;
  1040. pData->fileCallbackPtr = ptr;
  1041. }
  1042. // -----------------------------------------------------------------------
  1043. // Transport
  1044. void CarlaEngine::transportPlay() noexcept
  1045. {
  1046. pData->timeInfo.playing = true;
  1047. pData->time.setNeedsReset();
  1048. }
  1049. void CarlaEngine::transportPause() noexcept
  1050. {
  1051. pData->timeInfo.playing = false;
  1052. pData->time.setNeedsReset();
  1053. }
  1054. void CarlaEngine::transportBPM(const double bpm) noexcept
  1055. {
  1056. try {
  1057. pData->time.setBPM(bpm);
  1058. } CARLA_SAFE_EXCEPTION("CarlaEngine::transportBPM");
  1059. }
  1060. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1061. {
  1062. pData->time.relocate(frame);
  1063. }
  1064. // -----------------------------------------------------------------------
  1065. // Error handling
  1066. const char* CarlaEngine::getLastError() const noexcept
  1067. {
  1068. return pData->lastError;
  1069. }
  1070. void CarlaEngine::setLastError(const char* const error) const noexcept
  1071. {
  1072. pData->lastError = error;
  1073. }
  1074. // -----------------------------------------------------------------------
  1075. // Misc
  1076. bool CarlaEngine::isAboutToClose() const noexcept
  1077. {
  1078. return pData->aboutToClose;
  1079. }
  1080. bool CarlaEngine::setAboutToClose() noexcept
  1081. {
  1082. carla_debug("CarlaEngine::setAboutToClose()");
  1083. pData->aboutToClose = true;
  1084. return (pData->isIdling == 0);
  1085. }
  1086. // -----------------------------------------------------------------------
  1087. // Global options
  1088. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr) noexcept
  1089. {
  1090. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1091. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1092. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1093. // do not un-force stereo for rack mode
  1094. if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && option == ENGINE_OPTION_FORCE_STEREO && value != 0)
  1095. return;
  1096. switch (option)
  1097. {
  1098. case ENGINE_OPTION_DEBUG:
  1099. break;
  1100. case ENGINE_OPTION_PROCESS_MODE:
  1101. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1102. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1103. break;
  1104. case ENGINE_OPTION_TRANSPORT_MODE:
  1105. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1106. CARLA_SAFE_ASSERT_RETURN(getType() == kEngineTypeJack || value != ENGINE_TRANSPORT_MODE_JACK,);
  1107. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1108. delete[] pData->options.transportExtra;
  1109. pData->options.transportExtra = (valueStr != nullptr) ? carla_strdup_safe(valueStr) : nullptr;
  1110. pData->time.setNeedsReset();
  1111. #if defined(HAVE_HYLIA) && !defined(BUILD_BRIDGE)
  1112. // enable link now if needed
  1113. {
  1114. const bool linkEnabled = pData->options.transportExtra != nullptr && std::strstr(pData->options.transportExtra, ":link:") != nullptr;
  1115. pData->time.enableLink(linkEnabled);
  1116. }
  1117. #endif
  1118. break;
  1119. case ENGINE_OPTION_FORCE_STEREO:
  1120. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1121. pData->options.forceStereo = (value != 0);
  1122. break;
  1123. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1124. #ifdef BUILD_BRIDGE
  1125. CARLA_SAFE_ASSERT_RETURN(value == 0,);
  1126. #else
  1127. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1128. #endif
  1129. pData->options.preferPluginBridges = (value != 0);
  1130. break;
  1131. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1132. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1133. pData->options.preferUiBridges = (value != 0);
  1134. break;
  1135. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1136. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1137. pData->options.uisAlwaysOnTop = (value != 0);
  1138. break;
  1139. case ENGINE_OPTION_MAX_PARAMETERS:
  1140. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1141. pData->options.maxParameters = static_cast<uint>(value);
  1142. break;
  1143. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1144. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1145. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1146. break;
  1147. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1148. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1149. pData->options.audioNumPeriods = static_cast<uint>(value);
  1150. break;
  1151. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1152. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1153. pData->options.audioBufferSize = static_cast<uint>(value);
  1154. break;
  1155. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1156. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1157. pData->options.audioSampleRate = static_cast<uint>(value);
  1158. break;
  1159. case ENGINE_OPTION_AUDIO_DEVICE:
  1160. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1161. if (pData->options.audioDevice != nullptr)
  1162. delete[] pData->options.audioDevice;
  1163. pData->options.audioDevice = carla_strdup_safe(valueStr);
  1164. break;
  1165. case ENGINE_OPTION_PLUGIN_PATH:
  1166. CARLA_SAFE_ASSERT_RETURN(value > PLUGIN_NONE,);
  1167. CARLA_SAFE_ASSERT_RETURN(value <= PLUGIN_SFZ,);
  1168. switch (value)
  1169. {
  1170. case PLUGIN_LADSPA:
  1171. if (pData->options.pathLADSPA != nullptr)
  1172. delete[] pData->options.pathLADSPA;
  1173. if (valueStr != nullptr)
  1174. pData->options.pathLADSPA = carla_strdup_safe(valueStr);
  1175. else
  1176. pData->options.pathLADSPA = nullptr;
  1177. break;
  1178. case PLUGIN_DSSI:
  1179. if (pData->options.pathDSSI != nullptr)
  1180. delete[] pData->options.pathDSSI;
  1181. if (valueStr != nullptr)
  1182. pData->options.pathDSSI = carla_strdup_safe(valueStr);
  1183. else
  1184. pData->options.pathDSSI = nullptr;
  1185. break;
  1186. case PLUGIN_LV2:
  1187. if (pData->options.pathLV2 != nullptr)
  1188. delete[] pData->options.pathLV2;
  1189. if (valueStr != nullptr)
  1190. pData->options.pathLV2 = carla_strdup_safe(valueStr);
  1191. else
  1192. pData->options.pathLV2 = nullptr;
  1193. break;
  1194. case PLUGIN_VST2:
  1195. if (pData->options.pathVST2 != nullptr)
  1196. delete[] pData->options.pathVST2;
  1197. if (valueStr != nullptr)
  1198. pData->options.pathVST2 = carla_strdup_safe(valueStr);
  1199. else
  1200. pData->options.pathVST2 = nullptr;
  1201. break;
  1202. case PLUGIN_GIG:
  1203. if (pData->options.pathGIG != nullptr)
  1204. delete[] pData->options.pathGIG;
  1205. if (valueStr != nullptr)
  1206. pData->options.pathGIG = carla_strdup_safe(valueStr);
  1207. else
  1208. pData->options.pathGIG = nullptr;
  1209. break;
  1210. case PLUGIN_SF2:
  1211. if (pData->options.pathSF2 != nullptr)
  1212. delete[] pData->options.pathSF2;
  1213. if (valueStr != nullptr)
  1214. pData->options.pathSF2 = carla_strdup_safe(valueStr);
  1215. else
  1216. pData->options.pathSF2 = nullptr;
  1217. break;
  1218. case PLUGIN_SFZ:
  1219. if (pData->options.pathSFZ != nullptr)
  1220. delete[] pData->options.pathSFZ;
  1221. if (valueStr != nullptr)
  1222. pData->options.pathSFZ = carla_strdup_safe(valueStr);
  1223. else
  1224. pData->options.pathSFZ = nullptr;
  1225. break;
  1226. default:
  1227. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Invalid plugin type", option, EngineOption2Str(option), value, valueStr);
  1228. break;
  1229. }
  1230. break;
  1231. case ENGINE_OPTION_PATH_BINARIES:
  1232. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1233. if (pData->options.binaryDir != nullptr)
  1234. delete[] pData->options.binaryDir;
  1235. pData->options.binaryDir = carla_strdup_safe(valueStr);
  1236. break;
  1237. case ENGINE_OPTION_PATH_RESOURCES:
  1238. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1239. if (pData->options.resourceDir != nullptr)
  1240. delete[] pData->options.resourceDir;
  1241. pData->options.resourceDir = carla_strdup_safe(valueStr);
  1242. break;
  1243. case ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR: {
  1244. CARLA_SAFE_ASSERT_RETURN(pData->options.binaryDir != nullptr && pData->options.binaryDir[0] != '\0',);
  1245. #ifdef CARLA_OS_LINUX
  1246. const ScopedEngineEnvironmentLocker _seel(this);
  1247. if (value != 0)
  1248. {
  1249. CarlaString interposerPath(CarlaString(pData->options.binaryDir) + "/libcarla_interposer-safe.so");
  1250. ::setenv("LD_PRELOAD", interposerPath.buffer(), 1);
  1251. }
  1252. else
  1253. {
  1254. ::unsetenv("LD_PRELOAD");
  1255. }
  1256. #endif
  1257. } break;
  1258. case ENGINE_OPTION_FRONTEND_WIN_ID: {
  1259. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1260. const long long winId(std::strtoll(valueStr, nullptr, 16));
  1261. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1262. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  1263. } break;
  1264. case ENGINE_OPTION_WINE_EXECUTABLE:
  1265. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1266. if (pData->options.wine.executable != nullptr)
  1267. delete[] pData->options.wine.executable;
  1268. pData->options.wine.executable = carla_strdup_safe(valueStr);
  1269. break;
  1270. case ENGINE_OPTION_WINE_AUTO_PREFIX:
  1271. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1272. pData->options.wine.autoPrefix = (value != 0);
  1273. break;
  1274. case ENGINE_OPTION_WINE_FALLBACK_PREFIX:
  1275. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1276. if (pData->options.wine.fallbackPrefix != nullptr)
  1277. delete[] pData->options.wine.fallbackPrefix;
  1278. pData->options.wine.fallbackPrefix = carla_strdup_safe(valueStr);
  1279. break;
  1280. case ENGINE_OPTION_WINE_RT_PRIO_ENABLED:
  1281. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1282. pData->options.wine.rtPrio = (value != 0);
  1283. break;
  1284. case ENGINE_OPTION_WINE_BASE_RT_PRIO:
  1285. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 89,);
  1286. pData->options.wine.baseRtPrio = value;
  1287. break;
  1288. case ENGINE_OPTION_WINE_SERVER_RT_PRIO:
  1289. CARLA_SAFE_ASSERT_RETURN(value >= 1 && value <= 99,);
  1290. pData->options.wine.serverRtPrio = value;
  1291. break;
  1292. case ENGINE_OPTION_DEBUG_CONSOLE_OUTPUT:
  1293. break;
  1294. }
  1295. }
  1296. #ifdef HAVE_LIBLO
  1297. // -----------------------------------------------------------------------
  1298. // OSC Stuff
  1299. # ifndef BUILD_BRIDGE
  1300. bool CarlaEngine::isOscControlRegistered() const noexcept
  1301. {
  1302. return pData->osc.isControlRegistered();
  1303. }
  1304. # endif
  1305. void CarlaEngine::idleOsc() const noexcept
  1306. {
  1307. pData->osc.idle();
  1308. }
  1309. const char* CarlaEngine::getOscServerPathTCP() const noexcept
  1310. {
  1311. return pData->osc.getServerPathTCP();
  1312. }
  1313. const char* CarlaEngine::getOscServerPathUDP() const noexcept
  1314. {
  1315. return pData->osc.getServerPathUDP();
  1316. }
  1317. #endif
  1318. // -----------------------------------------------------------------------
  1319. // Helper functions
  1320. EngineEvent* CarlaEngine::getInternalEventBuffer(const bool isInput) const noexcept
  1321. {
  1322. return isInput ? pData->events.in : pData->events.out;
  1323. }
  1324. // -----------------------------------------------------------------------
  1325. // Internal stuff
  1326. void CarlaEngine::bufferSizeChanged(const uint32_t newBufferSize)
  1327. {
  1328. carla_debug("CarlaEngine::bufferSizeChanged(%i)", newBufferSize);
  1329. #ifndef BUILD_BRIDGE
  1330. if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK ||
  1331. pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1332. {
  1333. pData->graph.setBufferSize(newBufferSize);
  1334. }
  1335. #endif
  1336. pData->time.updateAudioValues(newBufferSize, pData->sampleRate);
  1337. for (uint i=0; i < pData->curPluginCount; ++i)
  1338. {
  1339. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1340. if (plugin != nullptr && plugin->isEnabled())
  1341. plugin->bufferSizeChanged(newBufferSize);
  1342. }
  1343. callback(ENGINE_CALLBACK_BUFFER_SIZE_CHANGED, 0, static_cast<int>(newBufferSize), 0, 0.0f, nullptr);
  1344. }
  1345. void CarlaEngine::sampleRateChanged(const double newSampleRate)
  1346. {
  1347. carla_debug("CarlaEngine::sampleRateChanged(%g)", newSampleRate);
  1348. #ifndef BUILD_BRIDGE
  1349. if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK ||
  1350. pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1351. {
  1352. pData->graph.setSampleRate(newSampleRate);
  1353. }
  1354. #endif
  1355. pData->time.updateAudioValues(pData->bufferSize, newSampleRate);
  1356. for (uint i=0; i < pData->curPluginCount; ++i)
  1357. {
  1358. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1359. if (plugin != nullptr && plugin->isEnabled())
  1360. plugin->sampleRateChanged(newSampleRate);
  1361. }
  1362. callback(ENGINE_CALLBACK_SAMPLE_RATE_CHANGED, 0, 0, 0, static_cast<float>(newSampleRate), nullptr);
  1363. }
  1364. void CarlaEngine::offlineModeChanged(const bool isOfflineNow)
  1365. {
  1366. carla_debug("CarlaEngine::offlineModeChanged(%s)", bool2str(isOfflineNow));
  1367. #ifndef BUILD_BRIDGE
  1368. if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK ||
  1369. pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1370. {
  1371. pData->graph.setOffline(isOfflineNow);
  1372. }
  1373. #endif
  1374. for (uint i=0; i < pData->curPluginCount; ++i)
  1375. {
  1376. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1377. if (plugin != nullptr && plugin->isEnabled())
  1378. plugin->offlineModeChanged(isOfflineNow);
  1379. }
  1380. }
  1381. void CarlaEngine::setPluginPeaks(const uint pluginId, float const inPeaks[2], float const outPeaks[2]) noexcept
  1382. {
  1383. EnginePluginData& pluginData(pData->plugins[pluginId]);
  1384. pluginData.insPeak[0] = inPeaks[0];
  1385. pluginData.insPeak[1] = inPeaks[1];
  1386. pluginData.outsPeak[0] = outPeaks[0];
  1387. pluginData.outsPeak[1] = outPeaks[1];
  1388. }
  1389. void CarlaEngine::saveProjectInternal(water::MemoryOutputStream& outStream) const
  1390. {
  1391. // send initial prepareForSave first, giving time for bridges to act
  1392. for (uint i=0; i < pData->curPluginCount; ++i)
  1393. {
  1394. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1395. if (plugin != nullptr && plugin->isEnabled())
  1396. {
  1397. #ifndef BUILD_BRIDGE
  1398. // deactivate bridge client-side ping check, since some plugins block during save
  1399. if (plugin->getHints() & PLUGIN_IS_BRIDGE)
  1400. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "false", false);
  1401. #endif
  1402. plugin->prepareForSave();
  1403. }
  1404. }
  1405. outStream << "<?xml version='1.0' encoding='UTF-8'?>\n";
  1406. outStream << "<!DOCTYPE CARLA-PROJECT>\n";
  1407. outStream << "<CARLA-PROJECT VERSION='2.0'>\n";
  1408. const bool isPlugin(getType() == kEngineTypePlugin);
  1409. const EngineOptions& options(pData->options);
  1410. MemoryOutputStream outSettings(1024);
  1411. // save appropriate engine settings
  1412. outSettings << " <EngineSettings>\n";
  1413. //processMode
  1414. //transportMode
  1415. outSettings << " <ForceStereo>" << bool2str(options.forceStereo) << "</ForceStereo>\n";
  1416. outSettings << " <PreferPluginBridges>" << bool2str(options.preferPluginBridges) << "</PreferPluginBridges>\n";
  1417. outSettings << " <PreferUiBridges>" << bool2str(options.preferUiBridges) << "</PreferUiBridges>\n";
  1418. outSettings << " <UIsAlwaysOnTop>" << bool2str(options.uisAlwaysOnTop) << "</UIsAlwaysOnTop>\n";
  1419. outSettings << " <MaxParameters>" << String(options.maxParameters) << "</MaxParameters>\n";
  1420. outSettings << " <UIBridgesTimeout>" << String(options.uiBridgesTimeout) << "</UIBridgesTimeout>\n";
  1421. if (isPlugin)
  1422. {
  1423. outSettings << " <LADSPA_PATH>" << xmlSafeString(options.pathLADSPA, true) << "</LADSPA_PATH>\n";
  1424. outSettings << " <DSSI_PATH>" << xmlSafeString(options.pathDSSI, true) << "</DSSI_PATH>\n";
  1425. outSettings << " <LV2_PATH>" << xmlSafeString(options.pathLV2, true) << "</LV2_PATH>\n";
  1426. outSettings << " <VST2_PATH>" << xmlSafeString(options.pathVST2, true) << "</VST2_PATH>\n";
  1427. outSettings << " <GIG_PATH>" << xmlSafeString(options.pathGIG, true) << "</GIG_PATH>\n";
  1428. outSettings << " <SF2_PATH>" << xmlSafeString(options.pathSF2, true) << "</SF2_PATH>\n";
  1429. outSettings << " <SFZ_PATH>" << xmlSafeString(options.pathSFZ, true) << "</SFZ_PATH>\n";
  1430. }
  1431. outSettings << " </EngineSettings>\n";
  1432. outStream << outSettings;
  1433. char strBuf[STR_MAX+1];
  1434. for (uint i=0; i < pData->curPluginCount; ++i)
  1435. {
  1436. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1437. if (plugin != nullptr && plugin->isEnabled())
  1438. {
  1439. MemoryOutputStream outPlugin(4096), streamPlugin;
  1440. plugin->getStateSave(false).dumpToMemoryStream(streamPlugin);
  1441. outPlugin << "\n";
  1442. strBuf[0] = '\0';
  1443. plugin->getRealName(strBuf);
  1444. if (strBuf[0] != '\0')
  1445. outPlugin << " <!-- " << xmlSafeString(strBuf, true) << " -->\n";
  1446. outPlugin << " <Plugin>\n";
  1447. outPlugin << streamPlugin;
  1448. outPlugin << " </Plugin>\n";
  1449. outStream << outPlugin;
  1450. }
  1451. }
  1452. #ifndef BUILD_BRIDGE
  1453. // tell bridges we're done saving
  1454. for (uint i=0; i < pData->curPluginCount; ++i)
  1455. {
  1456. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1457. if (plugin != nullptr && plugin->isEnabled() && (plugin->getHints() & PLUGIN_IS_BRIDGE) != 0)
  1458. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "true", false);
  1459. }
  1460. // save internal connections
  1461. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1462. {
  1463. if (const char* const* const patchbayConns = getPatchbayConnections(false))
  1464. {
  1465. MemoryOutputStream outPatchbay(2048);
  1466. outPatchbay << "\n <Patchbay>\n";
  1467. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1468. {
  1469. const char* const connSource(patchbayConns[i]);
  1470. const char* const connTarget(patchbayConns[i+1]);
  1471. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1472. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1473. outPatchbay << " <Connection>\n";
  1474. outPatchbay << " <Source>" << xmlSafeString(connSource, true) << "</Source>\n";
  1475. outPatchbay << " <Target>" << xmlSafeString(connTarget, true) << "</Target>\n";
  1476. outPatchbay << " </Connection>\n";
  1477. }
  1478. outPatchbay << " </Patchbay>\n";
  1479. outStream << outPatchbay;
  1480. }
  1481. }
  1482. // if we're running inside some session-manager (and using JACK), let them handle the connections
  1483. bool saveExternalConnections;
  1484. /**/ if (isPlugin)
  1485. saveExternalConnections = false;
  1486. else if (std::strcmp(getCurrentDriverName(), "JACK") != 0)
  1487. saveExternalConnections = true;
  1488. else if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr)
  1489. saveExternalConnections = false;
  1490. else if (std::getenv("LADISH_APP_NAME") != nullptr)
  1491. saveExternalConnections = false;
  1492. else if (std::getenv("NSM_URL") != nullptr)
  1493. saveExternalConnections = false;
  1494. else
  1495. saveExternalConnections = true;
  1496. if (saveExternalConnections)
  1497. {
  1498. if (const char* const* const patchbayConns = getPatchbayConnections(true))
  1499. {
  1500. MemoryOutputStream outPatchbay(2048);
  1501. outPatchbay << "\n <ExternalPatchbay>\n";
  1502. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1503. {
  1504. const char* const connSource(patchbayConns[i]);
  1505. const char* const connTarget(patchbayConns[i+1]);
  1506. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1507. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1508. outPatchbay << " <Connection>\n";
  1509. outPatchbay << " <Source>" << xmlSafeString(connSource, true) << "</Source>\n";
  1510. outPatchbay << " <Target>" << xmlSafeString(connTarget, true) << "</Target>\n";
  1511. outPatchbay << " </Connection>\n";
  1512. }
  1513. outPatchbay << " </ExternalPatchbay>\n";
  1514. outStream << outPatchbay;
  1515. }
  1516. }
  1517. #endif
  1518. outStream << "</CARLA-PROJECT>\n";
  1519. }
  1520. static String findBinaryInCustomPath(const char* const searchPath, const char* const binary)
  1521. {
  1522. const StringArray searchPaths(StringArray::fromTokens(searchPath, CARLA_OS_SPLIT_STR, ""));
  1523. // try direct filename first
  1524. String jbinary(binary);
  1525. // adjust for current platform
  1526. #ifdef CARLA_OS_WIN
  1527. if (jbinary[0] == '/')
  1528. jbinary = "C:" + jbinary.replaceCharacter('/', '\\');
  1529. #else
  1530. if (jbinary[1] == ':' && (jbinary[2] == '\\' || jbinary[2] == '/'))
  1531. jbinary = jbinary.substring(2).replaceCharacter('\\', '/');
  1532. #endif
  1533. String filename = File(jbinary).getFileName();
  1534. int searchFlags = File::findFiles|File::ignoreHiddenFiles;
  1535. #ifdef CARLA_OS_MAC
  1536. if (filename.endsWithIgnoreCase(".vst"))
  1537. searchFlags |= File::findDirectories;
  1538. #endif
  1539. Array<File> results;
  1540. for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it)
  1541. {
  1542. const File path(*it);
  1543. results.clear();
  1544. path.findChildFiles(results, searchFlags, true, filename);
  1545. if (results.size() > 0)
  1546. return results.getFirst().getFullPathName();
  1547. }
  1548. // try changing extension
  1549. #if defined(CARLA_OS_MAC)
  1550. if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".so"))
  1551. filename = File(jbinary).getFileNameWithoutExtension() + ".dylib";
  1552. #elif defined(CARLA_OS_WIN)
  1553. if (filename.endsWithIgnoreCase(".dylib") || filename.endsWithIgnoreCase(".so"))
  1554. filename = File(jbinary).getFileNameWithoutExtension() + ".dll";
  1555. #else
  1556. if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".dylib"))
  1557. filename = File(jbinary).getFileNameWithoutExtension() + ".so";
  1558. #endif
  1559. else
  1560. return String();
  1561. for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it)
  1562. {
  1563. const File path(*it);
  1564. results.clear();
  1565. path.findChildFiles(results, searchFlags, true, filename);
  1566. if (results.size() > 0)
  1567. return results.getFirst().getFullPathName();
  1568. }
  1569. return String();
  1570. }
  1571. bool CarlaEngine::loadProjectInternal(water::XmlDocument& xmlDoc)
  1572. {
  1573. ScopedPointer<XmlElement> xmlElement(xmlDoc.getDocumentElement(true));
  1574. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to parse project file");
  1575. const String& xmlType(xmlElement->getTagName());
  1576. const bool isPreset(xmlType.equalsIgnoreCase("carla-preset"));
  1577. if (! (xmlType.equalsIgnoreCase("carla-project") || isPreset))
  1578. {
  1579. setLastError("Not a valid Carla project or preset file");
  1580. return false;
  1581. }
  1582. #ifndef BUILD_BRIDGE
  1583. const ScopedValueSetter<bool> _svs(pData->loadingProject, true, false);
  1584. #endif
  1585. // completely load file
  1586. xmlElement = xmlDoc.getDocumentElement(false);
  1587. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to completely parse project file");
  1588. if (pData->aboutToClose)
  1589. return true;
  1590. const bool isPlugin(getType() == kEngineTypePlugin);
  1591. // engine settings
  1592. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1593. {
  1594. const String& tagName(elem->getTagName());
  1595. if (! tagName.equalsIgnoreCase("enginesettings"))
  1596. continue;
  1597. for (XmlElement* settElem = elem->getFirstChildElement(); settElem != nullptr; settElem = settElem->getNextElement())
  1598. {
  1599. const String& tag(settElem->getTagName());
  1600. const String text(settElem->getAllSubText().trim());
  1601. /** some settings might be incorrect or require extra work,
  1602. so we call setOption rather than modifying them direly */
  1603. int option = -1;
  1604. int value = 0;
  1605. const char* valueStr = nullptr;
  1606. /**/ if (tag.equalsIgnoreCase("forcestereo"))
  1607. {
  1608. option = ENGINE_OPTION_FORCE_STEREO;
  1609. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1610. }
  1611. else if (tag.equalsIgnoreCase("preferpluginbridges"))
  1612. {
  1613. option = ENGINE_OPTION_PREFER_PLUGIN_BRIDGES;
  1614. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1615. }
  1616. else if (tag.equalsIgnoreCase("preferuibridges"))
  1617. {
  1618. option = ENGINE_OPTION_PREFER_UI_BRIDGES;
  1619. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1620. }
  1621. else if (tag.equalsIgnoreCase("uisalwaysontop"))
  1622. {
  1623. option = ENGINE_OPTION_UIS_ALWAYS_ON_TOP;
  1624. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1625. }
  1626. else if (tag.equalsIgnoreCase("maxparameters"))
  1627. {
  1628. option = ENGINE_OPTION_MAX_PARAMETERS;
  1629. value = text.getIntValue();
  1630. }
  1631. else if (tag.equalsIgnoreCase("uibridgestimeout"))
  1632. {
  1633. option = ENGINE_OPTION_UI_BRIDGES_TIMEOUT;
  1634. value = text.getIntValue();
  1635. }
  1636. else if (isPlugin)
  1637. {
  1638. /**/ if (tag.equalsIgnoreCase("LADSPA_PATH"))
  1639. {
  1640. option = ENGINE_OPTION_PLUGIN_PATH;
  1641. value = PLUGIN_LADSPA;
  1642. valueStr = text.toRawUTF8();
  1643. }
  1644. else if (tag.equalsIgnoreCase("DSSI_PATH"))
  1645. {
  1646. option = ENGINE_OPTION_PLUGIN_PATH;
  1647. value = PLUGIN_DSSI;
  1648. valueStr = text.toRawUTF8();
  1649. }
  1650. else if (tag.equalsIgnoreCase("LV2_PATH"))
  1651. {
  1652. option = ENGINE_OPTION_PLUGIN_PATH;
  1653. value = PLUGIN_LV2;
  1654. valueStr = text.toRawUTF8();
  1655. }
  1656. else if (tag.equalsIgnoreCase("VST2_PATH"))
  1657. {
  1658. option = ENGINE_OPTION_PLUGIN_PATH;
  1659. value = PLUGIN_VST2;
  1660. valueStr = text.toRawUTF8();
  1661. }
  1662. else if (tag.equalsIgnoreCase("GIG_PATH"))
  1663. {
  1664. option = ENGINE_OPTION_PLUGIN_PATH;
  1665. value = PLUGIN_GIG;
  1666. valueStr = text.toRawUTF8();
  1667. }
  1668. else if (tag.equalsIgnoreCase("SF2_PATH"))
  1669. {
  1670. option = ENGINE_OPTION_PLUGIN_PATH;
  1671. value = PLUGIN_SF2;
  1672. valueStr = text.toRawUTF8();
  1673. }
  1674. else if (tag.equalsIgnoreCase("SFZ_PATH"))
  1675. {
  1676. option = ENGINE_OPTION_PLUGIN_PATH;
  1677. value = PLUGIN_SFZ;
  1678. valueStr = text.toRawUTF8();
  1679. }
  1680. }
  1681. CARLA_SAFE_ASSERT_CONTINUE(option != -1);
  1682. setOption(static_cast<EngineOption>(option), value, valueStr);
  1683. }
  1684. break;
  1685. }
  1686. if (pData->aboutToClose)
  1687. return true;
  1688. // handle plugins first
  1689. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1690. {
  1691. const String& tagName(elem->getTagName());
  1692. if (isPreset || tagName.equalsIgnoreCase("plugin"))
  1693. {
  1694. CarlaStateSave stateSave;
  1695. stateSave.fillFromXmlElement(isPreset ? xmlElement.get() : elem);
  1696. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1697. if (pData->aboutToClose)
  1698. return true;
  1699. CARLA_SAFE_ASSERT_CONTINUE(stateSave.type != nullptr);
  1700. const void* extraStuff = nullptr;
  1701. static const char kTrue[] = "true";
  1702. const PluginType ptype(getPluginTypeFromString(stateSave.type));
  1703. switch (ptype)
  1704. {
  1705. case PLUGIN_GIG:
  1706. case PLUGIN_SF2:
  1707. if (CarlaString(stateSave.label).endsWith(" (16 outs)"))
  1708. extraStuff = kTrue;
  1709. // fall through
  1710. case PLUGIN_LADSPA:
  1711. case PLUGIN_DSSI:
  1712. case PLUGIN_VST2:
  1713. case PLUGIN_SFZ:
  1714. if (stateSave.binary != nullptr && stateSave.binary[0] != '\0' &&
  1715. ! (File::isAbsolutePath(stateSave.binary) && File(stateSave.binary).exists()))
  1716. {
  1717. const char* searchPath;
  1718. switch (ptype)
  1719. {
  1720. case PLUGIN_LADSPA: searchPath = pData->options.pathLADSPA; break;
  1721. case PLUGIN_DSSI: searchPath = pData->options.pathDSSI; break;
  1722. case PLUGIN_VST2: searchPath = pData->options.pathVST2; break;
  1723. case PLUGIN_GIG: searchPath = pData->options.pathGIG; break;
  1724. case PLUGIN_SF2: searchPath = pData->options.pathSF2; break;
  1725. case PLUGIN_SFZ: searchPath = pData->options.pathSFZ; break;
  1726. default: searchPath = nullptr; break;
  1727. }
  1728. if (searchPath != nullptr && searchPath[0] != '\0')
  1729. {
  1730. carla_stderr("Plugin binary '%s' doesn't exist on this filesystem, let's look for it...",
  1731. stateSave.binary);
  1732. String result = findBinaryInCustomPath(searchPath, stateSave.binary);
  1733. if (result.isEmpty())
  1734. {
  1735. switch (ptype)
  1736. {
  1737. case PLUGIN_LADSPA: searchPath = std::getenv("LADSPA_PATH"); break;
  1738. case PLUGIN_DSSI: searchPath = std::getenv("DSSI_PATH"); break;
  1739. case PLUGIN_VST2: searchPath = std::getenv("VST_PATH"); break;
  1740. case PLUGIN_GIG: searchPath = std::getenv("GIG_PATH"); break;
  1741. case PLUGIN_SF2: searchPath = std::getenv("SF2_PATH"); break;
  1742. case PLUGIN_SFZ: searchPath = std::getenv("SFZ_PATH"); break;
  1743. default: searchPath = nullptr; break;
  1744. }
  1745. if (searchPath != nullptr && searchPath[0] != '\0')
  1746. result = findBinaryInCustomPath(searchPath, stateSave.binary);
  1747. }
  1748. if (result.isNotEmpty())
  1749. {
  1750. delete[] stateSave.binary;
  1751. stateSave.binary = carla_strdup(result.toRawUTF8());
  1752. carla_stderr("Found it! :)");
  1753. }
  1754. else
  1755. {
  1756. carla_stderr("Damn, we failed... :(");
  1757. }
  1758. }
  1759. }
  1760. break;
  1761. default:
  1762. break;
  1763. }
  1764. if (addPlugin(getBinaryTypeFromFile(stateSave.binary), ptype, stateSave.binary,
  1765. stateSave.name, stateSave.label, stateSave.uniqueId, extraStuff, stateSave.options))
  1766. {
  1767. #ifndef BUILD_BRIDGE
  1768. const uint pluginId = pData->curPluginCount;
  1769. #else
  1770. const uint pluginId = 0;
  1771. #endif
  1772. if (CarlaPlugin* const plugin = pData->plugins[pluginId].plugin)
  1773. {
  1774. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1775. if (pData->aboutToClose)
  1776. return true;
  1777. // deactivate bridge client-side ping check, since some plugins block during load
  1778. if ((plugin->getHints() & PLUGIN_IS_BRIDGE) != 0 && ! isPreset)
  1779. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "false", false);
  1780. plugin->loadStateSave(stateSave);
  1781. /* NOTE: The following code is the same as the end of addPlugin().
  1782. * When project is loading we do not enable the plugin right away,
  1783. * as we want to load state first.
  1784. */
  1785. #ifdef BUILD_BRIDGE
  1786. plugin->setActive(true, true, false);
  1787. #else
  1788. ++pData->curPluginCount;
  1789. #endif
  1790. plugin->setEnabled(true);
  1791. callback(ENGINE_CALLBACK_PLUGIN_ADDED, pluginId, 0, 0, 0.0f, plugin->getName());
  1792. #ifndef BUILD_BRIDGE
  1793. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1794. pData->graph.addPlugin(plugin);
  1795. #endif
  1796. }
  1797. else
  1798. {
  1799. carla_stderr2("Failed to get new plugin, state will not be restored correctly\n");
  1800. }
  1801. }
  1802. else
  1803. {
  1804. carla_stderr2("Failed to load a plugin, error was:\n%s", getLastError());
  1805. }
  1806. }
  1807. if (isPreset)
  1808. return true;
  1809. }
  1810. #ifndef BUILD_BRIDGE
  1811. // tell bridges we're done loading
  1812. for (uint i=0; i < pData->curPluginCount; ++i)
  1813. {
  1814. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1815. if (plugin != nullptr && plugin->isEnabled() && (plugin->getHints() & PLUGIN_IS_BRIDGE) != 0)
  1816. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "true", false);
  1817. }
  1818. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1819. if (pData->aboutToClose)
  1820. return true;
  1821. // handle connections (internal)
  1822. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1823. {
  1824. const bool isUsingExternal(pData->graph.isUsingExternal());
  1825. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1826. {
  1827. const String& tagName(elem->getTagName());
  1828. // only load internal patchbay connections
  1829. if (! tagName.equalsIgnoreCase("patchbay"))
  1830. continue;
  1831. CarlaString sourcePort, targetPort;
  1832. for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement())
  1833. {
  1834. const String& patchTag(patchElem->getTagName());
  1835. sourcePort.clear();
  1836. targetPort.clear();
  1837. if (! patchTag.equalsIgnoreCase("connection"))
  1838. continue;
  1839. for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement())
  1840. {
  1841. const String& tag(connElem->getTagName());
  1842. const String text(connElem->getAllSubText().trim());
  1843. /**/ if (tag.equalsIgnoreCase("source"))
  1844. sourcePort = xmlSafeString(text, false).toRawUTF8();
  1845. else if (tag.equalsIgnoreCase("target"))
  1846. targetPort = xmlSafeString(text, false).toRawUTF8();
  1847. }
  1848. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1849. restorePatchbayConnection(false, sourcePort, targetPort, !isUsingExternal);
  1850. }
  1851. break;
  1852. }
  1853. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1854. if (pData->aboutToClose)
  1855. return true;
  1856. }
  1857. // if we're running inside some session-manager (and using JACK), let them handle the external connections
  1858. bool loadExternalConnections;
  1859. /**/ if (isPlugin)
  1860. loadExternalConnections = false;
  1861. else if (std::strcmp(getCurrentDriverName(), "JACK") != 0)
  1862. loadExternalConnections = true;
  1863. else if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr)
  1864. loadExternalConnections = false;
  1865. else if (std::getenv("LADISH_APP_NAME") != nullptr)
  1866. loadExternalConnections = false;
  1867. else if (std::getenv("NSM_URL") != nullptr)
  1868. loadExternalConnections = false;
  1869. else
  1870. loadExternalConnections = true;
  1871. // handle connections
  1872. if (loadExternalConnections)
  1873. {
  1874. const bool isUsingExternal(pData->graph.isUsingExternal());
  1875. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1876. {
  1877. const String& tagName(elem->getTagName());
  1878. // check if we want to load patchbay-mode connections into an external (multi-client) graph
  1879. if (tagName.equalsIgnoreCase("patchbay"))
  1880. {
  1881. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1882. continue;
  1883. }
  1884. // or load external patchbay connections
  1885. else if (! tagName.equalsIgnoreCase("externalpatchbay"))
  1886. {
  1887. continue;
  1888. }
  1889. CarlaString sourcePort, targetPort;
  1890. for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement())
  1891. {
  1892. const String& patchTag(patchElem->getTagName());
  1893. sourcePort.clear();
  1894. targetPort.clear();
  1895. if (! patchTag.equalsIgnoreCase("connection"))
  1896. continue;
  1897. for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement())
  1898. {
  1899. const String& tag(connElem->getTagName());
  1900. const String text(connElem->getAllSubText().trim());
  1901. /**/ if (tag.equalsIgnoreCase("source"))
  1902. sourcePort = xmlSafeString(text, false).toRawUTF8();
  1903. else if (tag.equalsIgnoreCase("target"))
  1904. targetPort = xmlSafeString(text, false).toRawUTF8();
  1905. }
  1906. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1907. restorePatchbayConnection(true, sourcePort, targetPort, isUsingExternal);
  1908. }
  1909. break;
  1910. }
  1911. }
  1912. #endif
  1913. callback(ENGINE_CALLBACK_PROJECT_LOAD_FINISHED, 0, 0, 0, 0.0f, nullptr);
  1914. return true;
  1915. }
  1916. // -----------------------------------------------------------------------
  1917. CARLA_BACKEND_END_NAMESPACE