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.

2359 lines
81KB

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