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.

2348 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::strncmp(label, "http://calf.sourceforge.net/plugins/", 36) == 0 ||
  354. std::strcmp(label, "http://factorial.hu/plugins/lv2/ir") == 0 ||
  355. std::strstr(label, "v1.sourceforge.net/lv2") != nullptr)
  356. {
  357. preferBridges = true;
  358. }
  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. else
  452. {
  453. setLastError("This Carla build cannot handle this binary");
  454. return false;
  455. }
  456. }
  457. else
  458. #endif // ! BUILD_BRIDGE
  459. {
  460. bool use16Outs;
  461. setLastError("Invalid or unsupported plugin type");
  462. switch (ptype)
  463. {
  464. case PLUGIN_NONE:
  465. break;
  466. case PLUGIN_INTERNAL:
  467. /*if (std::strcmp(label, "FluidSynth") == 0)
  468. {
  469. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  470. plugin = CarlaPlugin::newFluidSynth(initializer, use16Outs);
  471. }
  472. else if (std::strcmp(label, "LinuxSampler (GIG)") == 0)
  473. {
  474. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  475. plugin = CarlaPlugin::newLinuxSampler(initializer, "GIG", use16Outs);
  476. }
  477. else if (std::strcmp(label, "LinuxSampler (SF2)") == 0)
  478. {
  479. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  480. plugin = CarlaPlugin::newLinuxSampler(initializer, "SF2", use16Outs);
  481. }
  482. else if (std::strcmp(label, "LinuxSampler (SFZ)") == 0)
  483. {
  484. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  485. plugin = CarlaPlugin::newLinuxSampler(initializer, "SFZ", use16Outs);
  486. }*/
  487. plugin = CarlaPlugin::newNative(initializer);
  488. break;
  489. case PLUGIN_LADSPA:
  490. plugin = CarlaPlugin::newLADSPA(initializer, (const LADSPA_RDF_Descriptor*)extra);
  491. break;
  492. case PLUGIN_DSSI:
  493. if (CarlaString(filename).contains("dssi-vst", true))
  494. {
  495. const ScopedEngineEnvironmentLocker _seel(this);
  496. const ScopedEnvVar _sev("VST_PATH", pData->options.pathVST2);
  497. plugin = CarlaPlugin::newDSSI(initializer);
  498. }
  499. else
  500. {
  501. plugin = CarlaPlugin::newDSSI(initializer);
  502. }
  503. break;
  504. case PLUGIN_LV2:
  505. plugin = CarlaPlugin::newLV2(initializer);
  506. break;
  507. case PLUGIN_VST2:
  508. plugin = CarlaPlugin::newVST2(initializer);
  509. break;
  510. case PLUGIN_VST3:
  511. plugin = CarlaPlugin::newVST3(initializer);
  512. break;
  513. case PLUGIN_AU:
  514. plugin = CarlaPlugin::newAU(initializer);
  515. break;
  516. case PLUGIN_GIG:
  517. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  518. plugin = CarlaPlugin::newFileGIG(initializer, use16Outs);
  519. break;
  520. case PLUGIN_SF2:
  521. use16Outs = (extra != nullptr && std::strcmp((const char*)extra, "true") == 0);
  522. plugin = CarlaPlugin::newFileSF2(initializer, use16Outs);
  523. break;
  524. case PLUGIN_SFZ:
  525. plugin = CarlaPlugin::newFileSFZ(initializer);
  526. break;
  527. case PLUGIN_JACK:
  528. #ifndef BUILD_BRIDGE
  529. plugin = CarlaPlugin::newJackApp(initializer);
  530. #endif
  531. break;
  532. }
  533. }
  534. if (plugin == nullptr)
  535. return false;
  536. plugin->reload();
  537. bool canRun = true;
  538. /**/ if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK)
  539. {
  540. /**/ if (! plugin->canRunInRack())
  541. {
  542. setLastError("Carla's rack mode can only work with Mono or Stereo plugins, sorry!");
  543. canRun = false;
  544. }
  545. else if (plugin->getCVInCount() > 0 || plugin->getCVInCount() > 0)
  546. {
  547. setLastError("Carla's rack mode cannot work with plugins that have CV ports, sorry!");
  548. canRun = false;
  549. }
  550. }
  551. else if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  552. {
  553. /**/ if (plugin->getMidiInCount() > 1 || plugin->getMidiOutCount() > 1)
  554. {
  555. setLastError("Carla's patchbay mode cannot work with plugins that have multiple MIDI ports, sorry!");
  556. canRun = false;
  557. }
  558. else if (plugin->getCVInCount() > 0 || plugin->getCVInCount() > 0)
  559. {
  560. setLastError("CV ports in patchbay mode is still TODO");
  561. canRun = false;
  562. }
  563. }
  564. if (! canRun)
  565. {
  566. delete plugin;
  567. return false;
  568. }
  569. #if defined(HAVE_LIBLO) && ! defined(BUILD_BRIDGE)
  570. plugin->registerToOscClient();
  571. #endif
  572. EnginePluginData& pluginData(pData->plugins[id]);
  573. pluginData.plugin = plugin;
  574. pluginData.insPeak[0] = 0.0f;
  575. pluginData.insPeak[1] = 0.0f;
  576. pluginData.outsPeak[0] = 0.0f;
  577. pluginData.outsPeak[1] = 0.0f;
  578. #ifndef BUILD_BRIDGE
  579. if (oldPlugin != nullptr)
  580. {
  581. CARLA_SAFE_ASSERT(! pData->loadingProject);
  582. const ScopedThreadStopper sts(this);
  583. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  584. pData->graph.replacePlugin(oldPlugin, plugin);
  585. const bool wasActive = oldPlugin->getInternalParameterValue(PARAMETER_ACTIVE) >= 0.5f;
  586. const float oldDryWet = oldPlugin->getInternalParameterValue(PARAMETER_DRYWET);
  587. const float oldVolume = oldPlugin->getInternalParameterValue(PARAMETER_VOLUME);
  588. delete oldPlugin;
  589. if (plugin->getHints() & PLUGIN_CAN_DRYWET)
  590. plugin->setDryWet(oldDryWet, true, true);
  591. if (plugin->getHints() & PLUGIN_CAN_VOLUME)
  592. plugin->setVolume(oldVolume, true, true);
  593. plugin->setActive(wasActive, true, true);
  594. plugin->setEnabled(true);
  595. callback(ENGINE_CALLBACK_RELOAD_ALL, id, 0, 0, 0.0f, nullptr);
  596. }
  597. else if (! pData->loadingProject)
  598. #endif
  599. {
  600. plugin->setActive(true, true, false);
  601. plugin->setEnabled(true);
  602. ++pData->curPluginCount;
  603. callback(ENGINE_CALLBACK_PLUGIN_ADDED, id, 0, 0, 0.0f, plugin->getName());
  604. #ifndef BUILD_BRIDGE
  605. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  606. pData->graph.addPlugin(plugin);
  607. #endif
  608. }
  609. return true;
  610. }
  611. 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)
  612. {
  613. return addPlugin(BINARY_NATIVE, ptype, filename, name, label, uniqueId, extra, 0x0);
  614. }
  615. bool CarlaEngine::removePlugin(const uint id)
  616. {
  617. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  618. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  619. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  620. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  621. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  622. carla_debug("CarlaEngine::removePlugin(%i)", id);
  623. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  624. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to remove");
  625. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  626. const ScopedThreadStopper sts(this);
  627. #ifndef BUILD_BRIDGE
  628. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  629. pData->graph.removePlugin(plugin);
  630. const bool lockWait(isRunning() /*&& pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS*/);
  631. const ScopedActionLock sal(this, kEnginePostActionRemovePlugin, id, 0, lockWait);
  632. /*
  633. for (uint i=id; i < pData->curPluginCount; ++i)
  634. {
  635. CarlaPlugin* const plugin2(pData->plugins[i].plugin);
  636. CARLA_SAFE_ASSERT_BREAK(plugin2 != nullptr);
  637. plugin2->updateOscURL();
  638. }
  639. */
  640. # ifdef HAVE_LIBLO
  641. if (isOscControlRegistered())
  642. oscSend_control_remove_plugin(id);
  643. # endif
  644. #else
  645. pData->curPluginCount = 0;
  646. carla_zeroStructs(pData->plugins, 1);
  647. #endif
  648. delete plugin;
  649. callback(ENGINE_CALLBACK_PLUGIN_REMOVED, id, 0, 0, 0.0f, nullptr);
  650. return true;
  651. }
  652. bool CarlaEngine::removeAllPlugins()
  653. {
  654. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  655. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  656. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextPluginId == pData->maxPluginNumber, "Invalid engine internal data");
  657. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  658. carla_debug("CarlaEngine::removeAllPlugins()");
  659. if (pData->curPluginCount == 0)
  660. return true;
  661. const ScopedThreadStopper sts(this);
  662. const uint curPluginCount(pData->curPluginCount);
  663. #ifndef BUILD_BRIDGE
  664. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  665. pData->graph.removeAllPlugins();
  666. # ifdef HAVE_LIBLO
  667. if (isOscControlRegistered())
  668. {
  669. for (uint i=0; i < curPluginCount; ++i)
  670. oscSend_control_remove_plugin(curPluginCount-i-1);
  671. }
  672. # endif
  673. #endif
  674. const bool lockWait(isRunning());
  675. const ScopedActionLock sal(this, kEnginePostActionZeroCount, 0, 0, lockWait);
  676. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  677. for (uint i=0; i < curPluginCount; ++i)
  678. {
  679. EnginePluginData& pluginData(pData->plugins[i]);
  680. if (pluginData.plugin != nullptr)
  681. {
  682. delete pluginData.plugin;
  683. pluginData.plugin = nullptr;
  684. }
  685. pluginData.insPeak[0] = 0.0f;
  686. pluginData.insPeak[1] = 0.0f;
  687. pluginData.outsPeak[0] = 0.0f;
  688. pluginData.outsPeak[1] = 0.0f;
  689. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  690. }
  691. return true;
  692. }
  693. #ifndef BUILD_BRIDGE
  694. const char* CarlaEngine::renamePlugin(const uint id, const char* const newName)
  695. {
  696. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  697. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data");
  698. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data");
  699. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  700. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id");
  701. CARLA_SAFE_ASSERT_RETURN_ERRN(newName != nullptr && newName[0] != '\0', "Invalid plugin name");
  702. carla_debug("CarlaEngine::renamePlugin(%i, \"%s\")", id, newName);
  703. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  704. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin != nullptr, "Could not find plugin to rename");
  705. CARLA_SAFE_ASSERT_RETURN_ERRN(plugin->getId() == id, "Invalid engine internal data");
  706. const char* const uniqueName(getUniquePluginName(newName));
  707. CARLA_SAFE_ASSERT_RETURN_ERRN(uniqueName != nullptr, "Unable to get new unique plugin name");
  708. plugin->setName(uniqueName);
  709. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  710. pData->graph.renamePlugin(plugin, uniqueName);
  711. delete[] uniqueName;
  712. return plugin->getName();
  713. }
  714. bool CarlaEngine::clonePlugin(const uint id)
  715. {
  716. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  717. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  718. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  719. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  720. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  721. carla_debug("CarlaEngine::clonePlugin(%i)", id);
  722. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  723. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to clone");
  724. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  725. char label[STR_MAX+1];
  726. carla_zeroChars(label, STR_MAX+1);
  727. plugin->getLabel(label);
  728. const uint pluginCountBefore(pData->curPluginCount);
  729. if (! addPlugin(plugin->getBinaryType(), plugin->getType(),
  730. plugin->getFilename(), plugin->getName(), label, plugin->getUniqueId(),
  731. plugin->getExtraStuff(), plugin->getOptionsEnabled()))
  732. return false;
  733. CARLA_SAFE_ASSERT_RETURN_ERR(pluginCountBefore+1 == pData->curPluginCount, "No new plugin found");
  734. if (CarlaPlugin* const newPlugin = pData->plugins[pluginCountBefore].plugin)
  735. newPlugin->loadStateSave(plugin->getStateSave());
  736. return true;
  737. }
  738. bool CarlaEngine::replacePlugin(const uint id) noexcept
  739. {
  740. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  741. CARLA_SAFE_ASSERT_RETURN_ERR(pData->plugins != nullptr, "Invalid engine internal data");
  742. CARLA_SAFE_ASSERT_RETURN_ERR(pData->curPluginCount != 0, "Invalid engine internal data");
  743. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  744. carla_debug("CarlaEngine::replacePlugin(%i)", id);
  745. // might use this to reset
  746. if (id == pData->maxPluginNumber)
  747. {
  748. pData->nextPluginId = pData->maxPluginNumber;
  749. return true;
  750. }
  751. CARLA_SAFE_ASSERT_RETURN_ERR(id < pData->curPluginCount, "Invalid plugin Id");
  752. CarlaPlugin* const plugin(pData->plugins[id].plugin);
  753. CARLA_SAFE_ASSERT_RETURN_ERR(plugin != nullptr, "Could not find plugin to replace");
  754. CARLA_SAFE_ASSERT_RETURN_ERR(plugin->getId() == id, "Invalid engine internal data");
  755. pData->nextPluginId = id;
  756. return true;
  757. }
  758. bool CarlaEngine::switchPlugins(const uint idA, const uint idB) 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 >= 2, "Invalid engine internal data");
  763. CARLA_SAFE_ASSERT_RETURN_ERR(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  764. CARLA_SAFE_ASSERT_RETURN_ERR(idA != idB, "Invalid operation, cannot switch plugin with itself");
  765. CARLA_SAFE_ASSERT_RETURN_ERR(idA < pData->curPluginCount, "Invalid plugin Id");
  766. CARLA_SAFE_ASSERT_RETURN_ERR(idB < pData->curPluginCount, "Invalid plugin Id");
  767. carla_debug("CarlaEngine::switchPlugins(%i)", idA, idB);
  768. CarlaPlugin* const pluginA(pData->plugins[idA].plugin);
  769. CarlaPlugin* const pluginB(pData->plugins[idB].plugin);
  770. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch");
  771. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA != nullptr, "Could not find plugin to switch");
  772. CARLA_SAFE_ASSERT_RETURN_ERR(pluginA->getId() == idA, "Invalid engine internal data");
  773. CARLA_SAFE_ASSERT_RETURN_ERR(pluginB->getId() == idB, "Invalid engine internal data");
  774. const ScopedThreadStopper sts(this);
  775. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  776. pData->graph.replacePlugin(pluginA, pluginB);
  777. const bool lockWait(isRunning() /*&& pData->options.processMode != ENGINE_PROCESS_MODE_MULTIPLE_CLIENTS*/);
  778. const ScopedActionLock sal(this, kEnginePostActionSwitchPlugins, idA, idB, lockWait);
  779. // TODO
  780. /*
  781. pluginA->updateOscURL();
  782. pluginB->updateOscURL();
  783. if (isOscControlRegistered())
  784. oscSend_control_switch_plugins(idA, idB);
  785. */
  786. return true;
  787. }
  788. #endif
  789. CarlaPlugin* CarlaEngine::getPlugin(const uint id) const noexcept
  790. {
  791. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->plugins != nullptr, "Invalid engine internal data");
  792. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->curPluginCount != 0, "Invalid engine internal data");
  793. CARLA_SAFE_ASSERT_RETURN_ERRN(pData->nextAction.opcode == kEnginePostActionNull, "Invalid engine internal data");
  794. CARLA_SAFE_ASSERT_RETURN_ERRN(id < pData->curPluginCount, "Invalid plugin Id");
  795. return pData->plugins[id].plugin;
  796. }
  797. CarlaPlugin* CarlaEngine::getPluginUnchecked(const uint id) const noexcept
  798. {
  799. return pData->plugins[id].plugin;
  800. }
  801. const char* CarlaEngine::getUniquePluginName(const char* const name) const
  802. {
  803. CARLA_SAFE_ASSERT_RETURN(pData->nextAction.opcode == kEnginePostActionNull, nullptr);
  804. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  805. carla_debug("CarlaEngine::getUniquePluginName(\"%s\")", name);
  806. CarlaString sname;
  807. sname = name;
  808. if (sname.isEmpty())
  809. {
  810. sname = "(No name)";
  811. return sname.dup();
  812. }
  813. const std::size_t maxNameSize(carla_minConstrained<uint>(getMaxClientNameSize(), 0xff, 6U) - 6); // 6 = strlen(" (10)") + 1
  814. if (maxNameSize == 0 || ! isRunning())
  815. return sname.dup();
  816. sname.truncate(maxNameSize);
  817. sname.replace(':', '.'); // ':' is used in JACK1 to split client/port names
  818. for (uint i=0; i < pData->curPluginCount; ++i)
  819. {
  820. CARLA_SAFE_ASSERT_BREAK(pData->plugins[i].plugin != nullptr);
  821. // Check if unique name doesn't exist
  822. if (const char* const pluginName = pData->plugins[i].plugin->getName())
  823. {
  824. if (sname != pluginName)
  825. continue;
  826. }
  827. // Check if string has already been modified
  828. {
  829. const std::size_t len(sname.length());
  830. // 1 digit, ex: " (2)"
  831. if (sname[len-4] == ' ' && sname[len-3] == '(' && sname.isDigit(len-2) && sname[len-1] == ')')
  832. {
  833. const int number = sname[len-2] - '0';
  834. if (number == 9)
  835. {
  836. // next number is 10, 2 digits
  837. sname.truncate(len-4);
  838. sname += " (10)";
  839. //sname.replace(" (9)", " (10)");
  840. }
  841. else
  842. sname[len-2] = char('0' + number + 1);
  843. continue;
  844. }
  845. // 2 digits, ex: " (11)"
  846. if (sname[len-5] == ' ' && sname[len-4] == '(' && sname.isDigit(len-3) && sname.isDigit(len-2) && sname[len-1] == ')')
  847. {
  848. char n2 = sname[len-2];
  849. char n3 = sname[len-3];
  850. if (n2 == '9')
  851. {
  852. n2 = '0';
  853. n3 = static_cast<char>(n3 + 1);
  854. }
  855. else
  856. n2 = static_cast<char>(n2 + 1);
  857. sname[len-2] = n2;
  858. sname[len-3] = n3;
  859. continue;
  860. }
  861. }
  862. // Modify string if not
  863. sname += " (2)";
  864. }
  865. return sname.dup();
  866. }
  867. // -----------------------------------------------------------------------
  868. // Project management
  869. bool CarlaEngine::loadFile(const char* const filename)
  870. {
  871. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  872. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  873. carla_debug("CarlaEngine::loadFile(\"%s\")", filename);
  874. const String jfilename = String(CharPointer_UTF8(filename));
  875. File file(jfilename);
  876. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  877. CarlaString baseName(file.getFileNameWithoutExtension().toRawUTF8());
  878. CarlaString extension(file.getFileExtension().replace(".","").toLowerCase().toRawUTF8());
  879. const uint curPluginId(pData->nextPluginId < pData->curPluginCount ? pData->nextPluginId : pData->curPluginCount);
  880. // -------------------------------------------------------------------
  881. if (extension == "carxp" || extension == "carxs")
  882. return loadProject(filename);
  883. // -------------------------------------------------------------------
  884. if (extension == "gig")
  885. return addPlugin(PLUGIN_GIG, filename, baseName, baseName, 0, nullptr);
  886. if (extension == "sf2")
  887. return addPlugin(PLUGIN_SF2, filename, baseName, baseName, 0, nullptr);
  888. if (extension == "sfz")
  889. return addPlugin(PLUGIN_SFZ, filename, baseName, baseName, 0, nullptr);
  890. // -------------------------------------------------------------------
  891. if (extension == "aif" || extension == "aiff" || extension == "bwf" || extension == "flac" || extension == "ogg" || extension == "wav")
  892. {
  893. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "audiofile", 0, nullptr))
  894. {
  895. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  896. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  897. return true;
  898. }
  899. return false;
  900. }
  901. // -------------------------------------------------------------------
  902. if (extension == "mid" || extension == "midi")
  903. {
  904. if (addPlugin(PLUGIN_INTERNAL, nullptr, baseName, "midifile", 0, nullptr))
  905. {
  906. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  907. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "file", filename, true);
  908. return true;
  909. }
  910. return false;
  911. }
  912. // -------------------------------------------------------------------
  913. // ZynAddSubFX
  914. if (extension == "xmz" || extension == "xiz")
  915. {
  916. #ifdef HAVE_ZYN_DEPS
  917. CarlaString nicerName("Zyn - ");
  918. const std::size_t sep(baseName.find('-')+1);
  919. if (sep < baseName.length())
  920. nicerName += baseName.buffer()+sep;
  921. else
  922. nicerName += baseName;
  923. //nicerName
  924. if (addPlugin(PLUGIN_INTERNAL, nullptr, nicerName, "zynaddsubfx", 0, nullptr))
  925. {
  926. callback(ENGINE_CALLBACK_UI_STATE_CHANGED, curPluginId, 0, 0, 0.0f, nullptr);
  927. if (CarlaPlugin* const plugin = getPlugin(curPluginId))
  928. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
  929. return true;
  930. }
  931. return false;
  932. #else
  933. setLastError("This Carla build does not have ZynAddSubFX support");
  934. return false;
  935. #endif
  936. }
  937. // -------------------------------------------------------------------
  938. setLastError("Unknown file extension");
  939. return false;
  940. }
  941. bool CarlaEngine::loadProject(const char* const filename)
  942. {
  943. CARLA_SAFE_ASSERT_RETURN_ERR(pData->isIdling == 0, "An operation is still being processed, please wait for it to finish");
  944. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  945. carla_debug("CarlaEngine::loadProject(\"%s\")", filename);
  946. const String jfilename = String(CharPointer_UTF8(filename));
  947. File file(jfilename);
  948. CARLA_SAFE_ASSERT_RETURN_ERR(file.existsAsFile(), "Requested file does not exist or is not a readable file");
  949. XmlDocument xml(file);
  950. return loadProjectInternal(xml);
  951. }
  952. bool CarlaEngine::saveProject(const char* const filename)
  953. {
  954. CARLA_SAFE_ASSERT_RETURN_ERR(filename != nullptr && filename[0] != '\0', "Invalid filename");
  955. carla_debug("CarlaEngine::saveProject(\"%s\")", filename);
  956. MemoryOutputStream out;
  957. saveProjectInternal(out);
  958. const String jfilename = String(CharPointer_UTF8(filename));
  959. File file(jfilename);
  960. if (file.replaceWithData(out.getData(), out.getDataSize()))
  961. return true;
  962. setLastError("Failed to write file");
  963. return false;
  964. }
  965. // -----------------------------------------------------------------------
  966. // Information (base)
  967. uint CarlaEngine::getHints() const noexcept
  968. {
  969. return pData->hints;
  970. }
  971. uint32_t CarlaEngine::getBufferSize() const noexcept
  972. {
  973. return pData->bufferSize;
  974. }
  975. double CarlaEngine::getSampleRate() const noexcept
  976. {
  977. return pData->sampleRate;
  978. }
  979. const char* CarlaEngine::getName() const noexcept
  980. {
  981. return pData->name;
  982. }
  983. EngineProcessMode CarlaEngine::getProccessMode() const noexcept
  984. {
  985. return pData->options.processMode;
  986. }
  987. const EngineOptions& CarlaEngine::getOptions() const noexcept
  988. {
  989. return pData->options;
  990. }
  991. const EngineTimeInfo& CarlaEngine::getTimeInfo() const noexcept
  992. {
  993. return pData->timeInfo;
  994. }
  995. // -----------------------------------------------------------------------
  996. // Information (peaks)
  997. float CarlaEngine::getInputPeak(const uint pluginId, const bool isLeft) const noexcept
  998. {
  999. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1000. return pData->plugins[pluginId].insPeak[isLeft ? 0 : 1];
  1001. }
  1002. float CarlaEngine::getOutputPeak(const uint pluginId, const bool isLeft) const noexcept
  1003. {
  1004. CARLA_SAFE_ASSERT_RETURN(pluginId < pData->curPluginCount, 0.0f);
  1005. return pData->plugins[pluginId].outsPeak[isLeft ? 0 : 1];
  1006. }
  1007. // -----------------------------------------------------------------------
  1008. // Callback
  1009. void CarlaEngine::callback(const EngineCallbackOpcode action, const uint pluginId, const int value1, const int value2, const float value3, const char* const valueStr) noexcept
  1010. {
  1011. #ifdef DEBUG
  1012. if (action != ENGINE_CALLBACK_IDLE)
  1013. carla_debug("CarlaEngine::callback(%i:%s, %i, %i, %i, %f, \"%s\")", action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1014. #endif
  1015. #ifdef BUILD_BRIDGE
  1016. if (pData->isIdling)
  1017. #else
  1018. if (pData->isIdling && action != ENGINE_CALLBACK_PATCHBAY_CLIENT_DATA_CHANGED)
  1019. #endif
  1020. {
  1021. carla_stdout("callback while idling (%i:%s, %i, %i, %i, %f, \"%s\")", action, EngineCallbackOpcode2Str(action), pluginId, value1, value2, value3, valueStr);
  1022. }
  1023. if (pData->callback != nullptr)
  1024. {
  1025. if (action == ENGINE_CALLBACK_IDLE)
  1026. ++pData->isIdling;
  1027. try {
  1028. pData->callback(pData->callbackPtr, action, pluginId, value1, value2, value3, valueStr);
  1029. #if defined(CARLA_OS_LINUX) && defined(__arm__)
  1030. } catch (__cxxabiv1::__forced_unwind&) {
  1031. carla_stderr2("Caught forced unwind exception in callback");
  1032. throw;
  1033. #endif
  1034. } catch (...) {
  1035. carla_safe_exception("callback", __FILE__, __LINE__);
  1036. }
  1037. if (action == ENGINE_CALLBACK_IDLE)
  1038. --pData->isIdling;
  1039. }
  1040. }
  1041. void CarlaEngine::setCallback(const EngineCallbackFunc func, void* const ptr) noexcept
  1042. {
  1043. carla_debug("CarlaEngine::setCallback(%p, %p)", func, ptr);
  1044. pData->callback = func;
  1045. pData->callbackPtr = ptr;
  1046. }
  1047. // -----------------------------------------------------------------------
  1048. // File Callback
  1049. const char* CarlaEngine::runFileCallback(const FileCallbackOpcode action, const bool isDir, const char* const title, const char* const filter) noexcept
  1050. {
  1051. CARLA_SAFE_ASSERT_RETURN(title != nullptr && title[0] != '\0', nullptr);
  1052. CARLA_SAFE_ASSERT_RETURN(filter != nullptr, nullptr);
  1053. carla_debug("CarlaEngine::runFileCallback(%i:%s, %s, \"%s\", \"%s\")", action, FileCallbackOpcode2Str(action), bool2str(isDir), title, filter);
  1054. const char* ret = nullptr;
  1055. if (pData->fileCallback != nullptr)
  1056. {
  1057. try {
  1058. ret = pData->fileCallback(pData->fileCallbackPtr, action, isDir, title, filter);
  1059. } CARLA_SAFE_EXCEPTION("runFileCallback");
  1060. }
  1061. return ret;
  1062. }
  1063. void CarlaEngine::setFileCallback(const FileCallbackFunc func, void* const ptr) noexcept
  1064. {
  1065. carla_debug("CarlaEngine::setFileCallback(%p, %p)", func, ptr);
  1066. pData->fileCallback = func;
  1067. pData->fileCallbackPtr = ptr;
  1068. }
  1069. // -----------------------------------------------------------------------
  1070. // Transport
  1071. void CarlaEngine::transportPlay() noexcept
  1072. {
  1073. pData->timeInfo.playing = true;
  1074. pData->time.setNeedsReset();
  1075. }
  1076. void CarlaEngine::transportPause() noexcept
  1077. {
  1078. pData->timeInfo.playing = false;
  1079. pData->time.setNeedsReset();
  1080. }
  1081. void CarlaEngine::transportRelocate(const uint64_t frame) noexcept
  1082. {
  1083. pData->time.relocate(frame);
  1084. }
  1085. // -----------------------------------------------------------------------
  1086. // Error handling
  1087. const char* CarlaEngine::getLastError() const noexcept
  1088. {
  1089. return pData->lastError;
  1090. }
  1091. void CarlaEngine::setLastError(const char* const error) const noexcept
  1092. {
  1093. pData->lastError = error;
  1094. }
  1095. // -----------------------------------------------------------------------
  1096. // Misc
  1097. bool CarlaEngine::isAboutToClose() const noexcept
  1098. {
  1099. return pData->aboutToClose;
  1100. }
  1101. bool CarlaEngine::setAboutToClose() noexcept
  1102. {
  1103. carla_debug("CarlaEngine::setAboutToClose()");
  1104. pData->aboutToClose = true;
  1105. return (pData->isIdling == 0);
  1106. }
  1107. // -----------------------------------------------------------------------
  1108. // Global options
  1109. void CarlaEngine::setOption(const EngineOption option, const int value, const char* const valueStr) noexcept
  1110. {
  1111. carla_debug("CarlaEngine::setOption(%i:%s, %i, \"%s\")", option, EngineOption2Str(option), value, valueStr);
  1112. if (isRunning() && (option == ENGINE_OPTION_PROCESS_MODE || option == ENGINE_OPTION_AUDIO_NUM_PERIODS || option == ENGINE_OPTION_AUDIO_DEVICE))
  1113. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Cannot set this option while engine is running!", option, EngineOption2Str(option), value, valueStr);
  1114. // do not un-force stereo for rack mode
  1115. if (pData->options.processMode == ENGINE_PROCESS_MODE_CONTINUOUS_RACK && option == ENGINE_OPTION_FORCE_STEREO && value != 0)
  1116. return;
  1117. switch (option)
  1118. {
  1119. case ENGINE_OPTION_DEBUG:
  1120. break;
  1121. case ENGINE_OPTION_PROCESS_MODE:
  1122. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_PROCESS_MODE_SINGLE_CLIENT && value <= ENGINE_PROCESS_MODE_BRIDGE,);
  1123. pData->options.processMode = static_cast<EngineProcessMode>(value);
  1124. break;
  1125. case ENGINE_OPTION_TRANSPORT_MODE:
  1126. CARLA_SAFE_ASSERT_RETURN(value >= ENGINE_TRANSPORT_MODE_INTERNAL && value <= ENGINE_TRANSPORT_MODE_BRIDGE,);
  1127. CARLA_SAFE_ASSERT_RETURN(getType() == kEngineTypeJack || value != ENGINE_TRANSPORT_MODE_JACK,);
  1128. pData->options.transportMode = static_cast<EngineTransportMode>(value);
  1129. delete[] pData->options.transportExtra;
  1130. pData->options.transportExtra = (valueStr != nullptr) ? carla_strdup_safe(valueStr) : nullptr;
  1131. pData->time.setNeedsReset();
  1132. #if defined(HAVE_HYLIA) && !defined(BUILD_BRIDGE)
  1133. // enable link now if needed
  1134. {
  1135. const bool linkEnabled = pData->options.transportExtra != nullptr && std::strstr(pData->options.transportExtra, ":link:") != nullptr;
  1136. pData->time.enableLink(linkEnabled);
  1137. }
  1138. #endif
  1139. break;
  1140. case ENGINE_OPTION_FORCE_STEREO:
  1141. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1142. pData->options.forceStereo = (value != 0);
  1143. break;
  1144. case ENGINE_OPTION_PREFER_PLUGIN_BRIDGES:
  1145. #ifdef BUILD_BRIDGE
  1146. CARLA_SAFE_ASSERT_RETURN(value == 0,);
  1147. #else
  1148. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1149. #endif
  1150. pData->options.preferPluginBridges = (value != 0);
  1151. break;
  1152. case ENGINE_OPTION_PREFER_UI_BRIDGES:
  1153. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1154. pData->options.preferUiBridges = (value != 0);
  1155. break;
  1156. case ENGINE_OPTION_UIS_ALWAYS_ON_TOP:
  1157. CARLA_SAFE_ASSERT_RETURN(value == 0 || value == 1,);
  1158. pData->options.uisAlwaysOnTop = (value != 0);
  1159. break;
  1160. case ENGINE_OPTION_MAX_PARAMETERS:
  1161. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1162. pData->options.maxParameters = static_cast<uint>(value);
  1163. break;
  1164. case ENGINE_OPTION_UI_BRIDGES_TIMEOUT:
  1165. CARLA_SAFE_ASSERT_RETURN(value >= 0,);
  1166. pData->options.uiBridgesTimeout = static_cast<uint>(value);
  1167. break;
  1168. case ENGINE_OPTION_AUDIO_NUM_PERIODS:
  1169. CARLA_SAFE_ASSERT_RETURN(value >= 2 && value <= 3,);
  1170. pData->options.audioNumPeriods = static_cast<uint>(value);
  1171. break;
  1172. case ENGINE_OPTION_AUDIO_BUFFER_SIZE:
  1173. CARLA_SAFE_ASSERT_RETURN(value >= 8,);
  1174. pData->options.audioBufferSize = static_cast<uint>(value);
  1175. break;
  1176. case ENGINE_OPTION_AUDIO_SAMPLE_RATE:
  1177. CARLA_SAFE_ASSERT_RETURN(value >= 22050,);
  1178. pData->options.audioSampleRate = static_cast<uint>(value);
  1179. break;
  1180. case ENGINE_OPTION_AUDIO_DEVICE:
  1181. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr,);
  1182. if (pData->options.audioDevice != nullptr)
  1183. delete[] pData->options.audioDevice;
  1184. pData->options.audioDevice = carla_strdup_safe(valueStr);
  1185. break;
  1186. case ENGINE_OPTION_PLUGIN_PATH:
  1187. CARLA_SAFE_ASSERT_RETURN(value > PLUGIN_NONE,);
  1188. CARLA_SAFE_ASSERT_RETURN(value <= PLUGIN_SFZ,);
  1189. switch (value)
  1190. {
  1191. case PLUGIN_LADSPA:
  1192. if (pData->options.pathLADSPA != nullptr)
  1193. delete[] pData->options.pathLADSPA;
  1194. if (valueStr != nullptr)
  1195. pData->options.pathLADSPA = carla_strdup_safe(valueStr);
  1196. else
  1197. pData->options.pathLADSPA = nullptr;
  1198. break;
  1199. case PLUGIN_DSSI:
  1200. if (pData->options.pathDSSI != nullptr)
  1201. delete[] pData->options.pathDSSI;
  1202. if (valueStr != nullptr)
  1203. pData->options.pathDSSI = carla_strdup_safe(valueStr);
  1204. else
  1205. pData->options.pathDSSI = nullptr;
  1206. break;
  1207. case PLUGIN_LV2:
  1208. if (pData->options.pathLV2 != nullptr)
  1209. delete[] pData->options.pathLV2;
  1210. if (valueStr != nullptr)
  1211. pData->options.pathLV2 = carla_strdup_safe(valueStr);
  1212. else
  1213. pData->options.pathLV2 = nullptr;
  1214. break;
  1215. case PLUGIN_VST2:
  1216. if (pData->options.pathVST2 != nullptr)
  1217. delete[] pData->options.pathVST2;
  1218. if (valueStr != nullptr)
  1219. pData->options.pathVST2 = carla_strdup_safe(valueStr);
  1220. else
  1221. pData->options.pathVST2 = nullptr;
  1222. break;
  1223. case PLUGIN_VST3:
  1224. if (pData->options.pathVST3 != nullptr)
  1225. delete[] pData->options.pathVST3;
  1226. if (valueStr != nullptr)
  1227. pData->options.pathVST3 = carla_strdup_safe(valueStr);
  1228. else
  1229. pData->options.pathVST3 = nullptr;
  1230. break;
  1231. case PLUGIN_GIG:
  1232. if (pData->options.pathGIG != nullptr)
  1233. delete[] pData->options.pathGIG;
  1234. if (valueStr != nullptr)
  1235. pData->options.pathGIG = carla_strdup_safe(valueStr);
  1236. else
  1237. pData->options.pathGIG = nullptr;
  1238. break;
  1239. case PLUGIN_SF2:
  1240. if (pData->options.pathSF2 != nullptr)
  1241. delete[] pData->options.pathSF2;
  1242. if (valueStr != nullptr)
  1243. pData->options.pathSF2 = carla_strdup_safe(valueStr);
  1244. else
  1245. pData->options.pathSF2 = nullptr;
  1246. break;
  1247. case PLUGIN_SFZ:
  1248. if (pData->options.pathSFZ != nullptr)
  1249. delete[] pData->options.pathSFZ;
  1250. if (valueStr != nullptr)
  1251. pData->options.pathSFZ = carla_strdup_safe(valueStr);
  1252. else
  1253. pData->options.pathSFZ = nullptr;
  1254. break;
  1255. default:
  1256. return carla_stderr("CarlaEngine::setOption(%i:%s, %i, \"%s\") - Invalid plugin type", option, EngineOption2Str(option), value, valueStr);
  1257. break;
  1258. }
  1259. break;
  1260. case ENGINE_OPTION_PATH_BINARIES:
  1261. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1262. if (pData->options.binaryDir != nullptr)
  1263. delete[] pData->options.binaryDir;
  1264. pData->options.binaryDir = carla_strdup_safe(valueStr);
  1265. break;
  1266. case ENGINE_OPTION_PATH_RESOURCES:
  1267. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1268. if (pData->options.resourceDir != nullptr)
  1269. delete[] pData->options.resourceDir;
  1270. pData->options.resourceDir = carla_strdup_safe(valueStr);
  1271. break;
  1272. case ENGINE_OPTION_PREVENT_BAD_BEHAVIOUR:
  1273. CARLA_SAFE_ASSERT_RETURN(pData->options.binaryDir != nullptr && pData->options.binaryDir[0] != '\0',);
  1274. #ifdef CARLA_OS_LINUX
  1275. if (value != 0)
  1276. {
  1277. CarlaString interposerPath(CarlaString(pData->options.binaryDir) + "/libcarla_interposer-safe.so");
  1278. ::setenv("LD_PRELOAD", interposerPath.buffer(), 1);
  1279. }
  1280. else
  1281. {
  1282. ::unsetenv("LD_PRELOAD");
  1283. }
  1284. #endif
  1285. break;
  1286. case ENGINE_OPTION_FRONTEND_WIN_ID: {
  1287. CARLA_SAFE_ASSERT_RETURN(valueStr != nullptr && valueStr[0] != '\0',);
  1288. const long long winId(std::strtoll(valueStr, nullptr, 16));
  1289. CARLA_SAFE_ASSERT_RETURN(winId >= 0,);
  1290. pData->options.frontendWinId = static_cast<uintptr_t>(winId);
  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(juce::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 << " <VST3_PATH>" << xmlSafeString(options.pathVST3, true) << "</VST3_PATH>\n";
  1428. outSettings << " <GIG_PATH>" << xmlSafeString(options.pathGIG, true) << "</GIG_PATH>\n";
  1429. outSettings << " <SF2_PATH>" << xmlSafeString(options.pathSF2, true) << "</SF2_PATH>\n";
  1430. outSettings << " <SFZ_PATH>" << xmlSafeString(options.pathSFZ, true) << "</SFZ_PATH>\n";
  1431. }
  1432. outSettings << " </EngineSettings>\n";
  1433. outStream << outSettings;
  1434. char strBuf[STR_MAX+1];
  1435. for (uint i=0; i < pData->curPluginCount; ++i)
  1436. {
  1437. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1438. if (plugin != nullptr && plugin->isEnabled())
  1439. {
  1440. MemoryOutputStream outPlugin(4096), streamPlugin;
  1441. plugin->getStateSave(false).dumpToMemoryStream(streamPlugin);
  1442. outPlugin << "\n";
  1443. strBuf[0] = '\0';
  1444. plugin->getRealName(strBuf);
  1445. if (strBuf[0] != '\0')
  1446. outPlugin << " <!-- " << xmlSafeString(strBuf, true) << " -->\n";
  1447. outPlugin << " <Plugin>\n";
  1448. outPlugin << streamPlugin;
  1449. outPlugin << " </Plugin>\n";
  1450. outStream << outPlugin;
  1451. }
  1452. }
  1453. #ifndef BUILD_BRIDGE
  1454. // tell bridges we're done saving
  1455. for (uint i=0; i < pData->curPluginCount; ++i)
  1456. {
  1457. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1458. if (plugin != nullptr && plugin->isEnabled() && (plugin->getHints() & PLUGIN_IS_BRIDGE) != 0)
  1459. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "true", false);
  1460. }
  1461. // save internal connections
  1462. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1463. {
  1464. if (const char* const* const patchbayConns = getPatchbayConnections(false))
  1465. {
  1466. MemoryOutputStream outPatchbay(2048);
  1467. outPatchbay << "\n <Patchbay>\n";
  1468. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1469. {
  1470. const char* const connSource(patchbayConns[i]);
  1471. const char* const connTarget(patchbayConns[i+1]);
  1472. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1473. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1474. outPatchbay << " <Connection>\n";
  1475. outPatchbay << " <Source>" << xmlSafeString(connSource, true) << "</Source>\n";
  1476. outPatchbay << " <Target>" << xmlSafeString(connTarget, true) << "</Target>\n";
  1477. outPatchbay << " </Connection>\n";
  1478. }
  1479. outPatchbay << " </Patchbay>\n";
  1480. outStream << outPatchbay;
  1481. }
  1482. }
  1483. // if we're running inside some session-manager (and using JACK), let them handle the connections
  1484. bool saveExternalConnections;
  1485. /**/ if (isPlugin)
  1486. saveExternalConnections = false;
  1487. else if (std::strcmp(getCurrentDriverName(), "JACK") != 0)
  1488. saveExternalConnections = true;
  1489. else if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr)
  1490. saveExternalConnections = false;
  1491. else if (std::getenv("LADISH_APP_NAME") != nullptr)
  1492. saveExternalConnections = false;
  1493. else if (std::getenv("NSM_URL") != nullptr)
  1494. saveExternalConnections = false;
  1495. else
  1496. saveExternalConnections = true;
  1497. if (saveExternalConnections)
  1498. {
  1499. if (const char* const* const patchbayConns = getPatchbayConnections(true))
  1500. {
  1501. MemoryOutputStream outPatchbay(2048);
  1502. outPatchbay << "\n <ExternalPatchbay>\n";
  1503. for (int i=0; patchbayConns[i] != nullptr && patchbayConns[i+1] != nullptr; ++i, ++i )
  1504. {
  1505. const char* const connSource(patchbayConns[i]);
  1506. const char* const connTarget(patchbayConns[i+1]);
  1507. CARLA_SAFE_ASSERT_CONTINUE(connSource != nullptr && connSource[0] != '\0');
  1508. CARLA_SAFE_ASSERT_CONTINUE(connTarget != nullptr && connTarget[0] != '\0');
  1509. outPatchbay << " <Connection>\n";
  1510. outPatchbay << " <Source>" << xmlSafeString(connSource, true) << "</Source>\n";
  1511. outPatchbay << " <Target>" << xmlSafeString(connTarget, true) << "</Target>\n";
  1512. outPatchbay << " </Connection>\n";
  1513. }
  1514. outPatchbay << " </ExternalPatchbay>\n";
  1515. outStream << outPatchbay;
  1516. }
  1517. }
  1518. #endif
  1519. outStream << "</CARLA-PROJECT>\n";
  1520. }
  1521. static String findBinaryInCustomPath(const char* const searchPath, const char* const binary)
  1522. {
  1523. const StringArray searchPaths(StringArray::fromTokens(searchPath, CARLA_OS_SPLIT_STR, ""));
  1524. // try direct filename first
  1525. String jbinary(binary);
  1526. // adjust for current platform
  1527. #ifdef CARLA_OS_WIN
  1528. if (jbinary[0] == '/')
  1529. jbinary = "C:" + jbinary.replaceCharacter('/', '\\');
  1530. #else
  1531. if (jbinary[1] == ':' && (jbinary[2] == '\\' || jbinary[2] == '/'))
  1532. jbinary = jbinary.substring(2).replaceCharacter('\\', '/');
  1533. #endif
  1534. String filename = File(jbinary).getFileName();
  1535. int searchFlags = File::findFiles|File::ignoreHiddenFiles;
  1536. #ifdef CARLA_OS_MAC
  1537. if (filename.endsWithIgnoreCase(".vst") || filename.endsWithIgnoreCase(".vst3"))
  1538. searchFlags |= File::findDirectories;
  1539. #endif
  1540. Array<File> results;
  1541. for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it)
  1542. {
  1543. const File path(*it);
  1544. results.clear();
  1545. path.findChildFiles(results, searchFlags, true, filename);
  1546. if (results.size() > 0)
  1547. return results.getFirst().getFullPathName();
  1548. }
  1549. // try changing extension
  1550. #if defined(CARLA_OS_MAC)
  1551. if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".so"))
  1552. filename = File(jbinary).getFileNameWithoutExtension() + ".dylib";
  1553. #elif defined(CARLA_OS_WIN)
  1554. if (filename.endsWithIgnoreCase(".dylib") || filename.endsWithIgnoreCase(".so"))
  1555. filename = File(jbinary).getFileNameWithoutExtension() + ".dll";
  1556. #else
  1557. if (filename.endsWithIgnoreCase(".dll") || filename.endsWithIgnoreCase(".dylib"))
  1558. filename = File(jbinary).getFileNameWithoutExtension() + ".so";
  1559. #endif
  1560. else
  1561. return String();
  1562. for (const String *it=searchPaths.begin(), *end=searchPaths.end(); it != end; ++it)
  1563. {
  1564. const File path(*it);
  1565. results.clear();
  1566. path.findChildFiles(results, searchFlags, true, filename);
  1567. if (results.size() > 0)
  1568. return results.getFirst().getFullPathName();
  1569. }
  1570. return String();
  1571. }
  1572. bool CarlaEngine::loadProjectInternal(juce::XmlDocument& xmlDoc)
  1573. {
  1574. ScopedPointer<XmlElement> xmlElement(xmlDoc.getDocumentElement(true));
  1575. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to parse project file");
  1576. const String& xmlType(xmlElement->getTagName());
  1577. const bool isPreset(xmlType.equalsIgnoreCase("carla-preset"));
  1578. if (! (xmlType.equalsIgnoreCase("carla-project") || isPreset))
  1579. {
  1580. setLastError("Not a valid Carla project or preset file");
  1581. return false;
  1582. }
  1583. #ifndef BUILD_BRIDGE
  1584. const ScopedValueSetter<bool> _svs(pData->loadingProject, true, false);
  1585. #endif
  1586. // completely load file
  1587. xmlElement = xmlDoc.getDocumentElement(false);
  1588. CARLA_SAFE_ASSERT_RETURN_ERR(xmlElement != nullptr, "Failed to completely parse project file");
  1589. if (pData->aboutToClose)
  1590. return true;
  1591. const bool isPlugin(getType() == kEngineTypePlugin);
  1592. // engine settings
  1593. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1594. {
  1595. const String& tagName(elem->getTagName());
  1596. if (! tagName.equalsIgnoreCase("enginesettings"))
  1597. continue;
  1598. for (XmlElement* settElem = elem->getFirstChildElement(); settElem != nullptr; settElem = settElem->getNextElement())
  1599. {
  1600. const String& tag(settElem->getTagName());
  1601. const String text(settElem->getAllSubText().trim());
  1602. /** some settings might be incorrect or require extra work,
  1603. so we call setOption rather than modifying them direly */
  1604. int option = -1;
  1605. int value = 0;
  1606. const char* valueStr = nullptr;
  1607. /**/ if (tag.equalsIgnoreCase("forcestereo"))
  1608. {
  1609. option = ENGINE_OPTION_FORCE_STEREO;
  1610. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1611. }
  1612. else if (tag.equalsIgnoreCase("preferpluginbridges"))
  1613. {
  1614. option = ENGINE_OPTION_PREFER_PLUGIN_BRIDGES;
  1615. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1616. }
  1617. else if (tag.equalsIgnoreCase("preferuibridges"))
  1618. {
  1619. option = ENGINE_OPTION_PREFER_UI_BRIDGES;
  1620. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1621. }
  1622. else if (tag.equalsIgnoreCase("uisalwaysontop"))
  1623. {
  1624. option = ENGINE_OPTION_UIS_ALWAYS_ON_TOP;
  1625. value = text.equalsIgnoreCase("true") ? 1 : 0;
  1626. }
  1627. else if (tag.equalsIgnoreCase("maxparameters"))
  1628. {
  1629. option = ENGINE_OPTION_MAX_PARAMETERS;
  1630. value = text.getIntValue();
  1631. }
  1632. else if (tag.equalsIgnoreCase("uibridgestimeout"))
  1633. {
  1634. option = ENGINE_OPTION_UI_BRIDGES_TIMEOUT;
  1635. value = text.getIntValue();
  1636. }
  1637. else if (isPlugin)
  1638. {
  1639. /**/ if (tag.equalsIgnoreCase("LADSPA_PATH"))
  1640. {
  1641. option = ENGINE_OPTION_PLUGIN_PATH;
  1642. value = PLUGIN_LADSPA;
  1643. valueStr = text.toRawUTF8();
  1644. }
  1645. else if (tag.equalsIgnoreCase("DSSI_PATH"))
  1646. {
  1647. option = ENGINE_OPTION_PLUGIN_PATH;
  1648. value = PLUGIN_DSSI;
  1649. valueStr = text.toRawUTF8();
  1650. }
  1651. else if (tag.equalsIgnoreCase("LV2_PATH"))
  1652. {
  1653. option = ENGINE_OPTION_PLUGIN_PATH;
  1654. value = PLUGIN_LV2;
  1655. valueStr = text.toRawUTF8();
  1656. }
  1657. else if (tag.equalsIgnoreCase("VST2_PATH"))
  1658. {
  1659. option = ENGINE_OPTION_PLUGIN_PATH;
  1660. value = PLUGIN_VST2;
  1661. valueStr = text.toRawUTF8();
  1662. }
  1663. else if (tag.equalsIgnoreCase("VST3_PATH"))
  1664. {
  1665. option = ENGINE_OPTION_PLUGIN_PATH;
  1666. value = PLUGIN_VST3;
  1667. valueStr = text.toRawUTF8();
  1668. }
  1669. else if (tag.equalsIgnoreCase("GIG_PATH"))
  1670. {
  1671. option = ENGINE_OPTION_PLUGIN_PATH;
  1672. value = PLUGIN_GIG;
  1673. valueStr = text.toRawUTF8();
  1674. }
  1675. else if (tag.equalsIgnoreCase("SF2_PATH"))
  1676. {
  1677. option = ENGINE_OPTION_PLUGIN_PATH;
  1678. value = PLUGIN_SF2;
  1679. valueStr = text.toRawUTF8();
  1680. }
  1681. else if (tag.equalsIgnoreCase("SFZ_PATH"))
  1682. {
  1683. option = ENGINE_OPTION_PLUGIN_PATH;
  1684. value = PLUGIN_SFZ;
  1685. valueStr = text.toRawUTF8();
  1686. }
  1687. }
  1688. CARLA_SAFE_ASSERT_CONTINUE(option != -1);
  1689. setOption(static_cast<EngineOption>(option), value, valueStr);
  1690. }
  1691. break;
  1692. }
  1693. if (pData->aboutToClose)
  1694. return true;
  1695. // handle plugins first
  1696. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1697. {
  1698. const String& tagName(elem->getTagName());
  1699. if (isPreset || tagName.equalsIgnoreCase("plugin"))
  1700. {
  1701. CarlaStateSave stateSave;
  1702. stateSave.fillFromXmlElement(isPreset ? xmlElement.get() : elem);
  1703. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1704. if (pData->aboutToClose)
  1705. return true;
  1706. CARLA_SAFE_ASSERT_CONTINUE(stateSave.type != nullptr);
  1707. const void* extraStuff = nullptr;
  1708. static const char kTrue[] = "true";
  1709. const PluginType ptype(getPluginTypeFromString(stateSave.type));
  1710. switch (ptype)
  1711. {
  1712. case PLUGIN_GIG:
  1713. case PLUGIN_SF2:
  1714. if (CarlaString(stateSave.label).endsWith(" (16 outs)"))
  1715. extraStuff = kTrue;
  1716. // fall through
  1717. case PLUGIN_LADSPA:
  1718. case PLUGIN_DSSI:
  1719. case PLUGIN_VST2:
  1720. case PLUGIN_VST3:
  1721. case PLUGIN_SFZ:
  1722. if (stateSave.binary != nullptr && stateSave.binary[0] != '\0' &&
  1723. ! (File::isAbsolutePath(stateSave.binary) && File(stateSave.binary).exists()))
  1724. {
  1725. const char* searchPath;
  1726. switch (ptype)
  1727. {
  1728. case PLUGIN_LADSPA: searchPath = pData->options.pathLADSPA; break;
  1729. case PLUGIN_DSSI: searchPath = pData->options.pathDSSI; break;
  1730. case PLUGIN_VST2: searchPath = pData->options.pathVST2; break;
  1731. case PLUGIN_VST3: searchPath = pData->options.pathVST3; break;
  1732. case PLUGIN_GIG: searchPath = pData->options.pathGIG; break;
  1733. case PLUGIN_SF2: searchPath = pData->options.pathSF2; break;
  1734. case PLUGIN_SFZ: searchPath = pData->options.pathSFZ; break;
  1735. default: searchPath = nullptr; break;
  1736. }
  1737. if (searchPath != nullptr && searchPath[0] != '\0')
  1738. {
  1739. carla_stderr("Plugin binary '%s' doesn't exist on this filesystem, let's look for it...",
  1740. stateSave.binary);
  1741. String result = findBinaryInCustomPath(searchPath, stateSave.binary);
  1742. if (result.isEmpty())
  1743. {
  1744. switch (ptype)
  1745. {
  1746. case PLUGIN_LADSPA: searchPath = std::getenv("LADSPA_PATH"); break;
  1747. case PLUGIN_DSSI: searchPath = std::getenv("DSSI_PATH"); break;
  1748. case PLUGIN_VST2: searchPath = std::getenv("VST_PATH"); break;
  1749. case PLUGIN_VST3: searchPath = std::getenv("VST3_PATH"); break;
  1750. case PLUGIN_GIG: searchPath = std::getenv("GIG_PATH"); break;
  1751. case PLUGIN_SF2: searchPath = std::getenv("SF2_PATH"); break;
  1752. case PLUGIN_SFZ: searchPath = std::getenv("SFZ_PATH"); break;
  1753. default: searchPath = nullptr; break;
  1754. }
  1755. if (searchPath != nullptr && searchPath[0] != '\0')
  1756. result = findBinaryInCustomPath(searchPath, stateSave.binary);
  1757. }
  1758. if (result.isNotEmpty())
  1759. {
  1760. delete[] stateSave.binary;
  1761. stateSave.binary = carla_strdup(result.toRawUTF8());
  1762. carla_stderr("Found it! :)");
  1763. }
  1764. else
  1765. {
  1766. carla_stderr("Damn, we failed... :(");
  1767. }
  1768. }
  1769. }
  1770. break;
  1771. default:
  1772. break;
  1773. }
  1774. if (addPlugin(getBinaryTypeFromFile(stateSave.binary), ptype, stateSave.binary,
  1775. stateSave.name, stateSave.label, stateSave.uniqueId, extraStuff, stateSave.options))
  1776. {
  1777. const uint pluginId = pData->curPluginCount;
  1778. if (CarlaPlugin* const plugin = pData->plugins[pluginId].plugin)
  1779. {
  1780. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1781. if (pData->aboutToClose)
  1782. return true;
  1783. #ifndef BUILD_BRIDGE
  1784. // deactivate bridge client-side ping check, since some plugins block during load
  1785. if ((plugin->getHints() & PLUGIN_IS_BRIDGE) != 0 && ! isPreset)
  1786. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "false", false);
  1787. #endif
  1788. plugin->loadStateSave(stateSave);
  1789. /* NOTE: The following code is the same as the end of addPlugin().
  1790. * When project is loading we do not enable the plugin right away,
  1791. * as we want to load state first.
  1792. */
  1793. #ifdef BUILD_BRIDGE
  1794. plugin->setActive(true, true, false);
  1795. #endif
  1796. plugin->setEnabled(true);
  1797. ++pData->curPluginCount;
  1798. callback(ENGINE_CALLBACK_PLUGIN_ADDED, pluginId, 0, 0, 0.0f, plugin->getName());
  1799. #ifndef BUILD_BRIDGE
  1800. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1801. pData->graph.addPlugin(plugin);
  1802. #endif
  1803. }
  1804. else
  1805. {
  1806. carla_stderr2("Failed to get new plugin, state will not be restored correctly\n");
  1807. }
  1808. }
  1809. else
  1810. {
  1811. carla_stderr2("Failed to load a plugin, error was:\n%s", getLastError());
  1812. }
  1813. }
  1814. if (isPreset)
  1815. return true;
  1816. }
  1817. #ifndef BUILD_BRIDGE
  1818. // tell bridges we're done loading
  1819. for (uint i=0; i < pData->curPluginCount; ++i)
  1820. {
  1821. CarlaPlugin* const plugin(pData->plugins[i].plugin);
  1822. if (plugin != nullptr && plugin->isEnabled() && (plugin->getHints() & PLUGIN_IS_BRIDGE) != 0)
  1823. plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, "__CarlaPingOnOff__", "true", false);
  1824. }
  1825. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1826. if (pData->aboutToClose)
  1827. return true;
  1828. // handle connections (internal)
  1829. if (pData->options.processMode == ENGINE_PROCESS_MODE_PATCHBAY)
  1830. {
  1831. const bool isUsingExternal(pData->graph.isUsingExternal());
  1832. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1833. {
  1834. const String& tagName(elem->getTagName());
  1835. if (! tagName.equalsIgnoreCase("patchbay"))
  1836. continue;
  1837. CarlaString sourcePort, targetPort;
  1838. for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement())
  1839. {
  1840. const String& patchTag(patchElem->getTagName());
  1841. sourcePort.clear();
  1842. targetPort.clear();
  1843. if (! patchTag.equalsIgnoreCase("connection"))
  1844. continue;
  1845. for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement())
  1846. {
  1847. const String& tag(connElem->getTagName());
  1848. const String text(connElem->getAllSubText().trim());
  1849. /**/ if (tag.equalsIgnoreCase("source"))
  1850. sourcePort = xmlSafeString(text, false).toRawUTF8();
  1851. else if (tag.equalsIgnoreCase("target"))
  1852. targetPort = xmlSafeString(text, false).toRawUTF8();
  1853. }
  1854. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1855. restorePatchbayConnection(false, sourcePort, targetPort, !isUsingExternal);
  1856. }
  1857. break;
  1858. }
  1859. callback(ENGINE_CALLBACK_IDLE, 0, 0, 0, 0.0f, nullptr);
  1860. if (pData->aboutToClose)
  1861. return true;
  1862. }
  1863. // if we're running inside some session-manager (and using JACK), let them handle the external connections
  1864. bool loadExternalConnections;
  1865. /**/ if (isPlugin)
  1866. loadExternalConnections = false;
  1867. else if (std::strcmp(getCurrentDriverName(), "JACK") != 0)
  1868. loadExternalConnections = true;
  1869. else if (std::getenv("CARLA_DONT_MANAGE_CONNECTIONS") != nullptr)
  1870. loadExternalConnections = false;
  1871. else if (std::getenv("LADISH_APP_NAME") != nullptr)
  1872. loadExternalConnections = false;
  1873. else if (std::getenv("NSM_URL") != nullptr)
  1874. loadExternalConnections = false;
  1875. else
  1876. loadExternalConnections = true;
  1877. // handle connections (external)
  1878. if (loadExternalConnections)
  1879. {
  1880. const bool isUsingExternal(pData->graph.isUsingExternal());
  1881. for (XmlElement* elem = xmlElement->getFirstChildElement(); elem != nullptr; elem = elem->getNextElement())
  1882. {
  1883. const String& tagName(elem->getTagName());
  1884. if (! tagName.equalsIgnoreCase("externalpatchbay"))
  1885. continue;
  1886. CarlaString sourcePort, targetPort;
  1887. for (XmlElement* patchElem = elem->getFirstChildElement(); patchElem != nullptr; patchElem = patchElem->getNextElement())
  1888. {
  1889. const String& patchTag(patchElem->getTagName());
  1890. sourcePort.clear();
  1891. targetPort.clear();
  1892. if (! patchTag.equalsIgnoreCase("connection"))
  1893. continue;
  1894. for (XmlElement* connElem = patchElem->getFirstChildElement(); connElem != nullptr; connElem = connElem->getNextElement())
  1895. {
  1896. const String& tag(connElem->getTagName());
  1897. const String text(connElem->getAllSubText().trim());
  1898. /**/ if (tag.equalsIgnoreCase("source"))
  1899. sourcePort = xmlSafeString(text, false).toRawUTF8();
  1900. else if (tag.equalsIgnoreCase("target"))
  1901. targetPort = xmlSafeString(text, false).toRawUTF8();
  1902. }
  1903. if (sourcePort.isNotEmpty() && targetPort.isNotEmpty())
  1904. restorePatchbayConnection(true, sourcePort, targetPort, isUsingExternal);
  1905. }
  1906. break;
  1907. }
  1908. }
  1909. #endif
  1910. return true;
  1911. }
  1912. // -----------------------------------------------------------------------
  1913. CARLA_BACKEND_END_NAMESPACE