The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

1942 lines
71KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../Application/jucer_Headers.h"
  20. #include "jucer_Project.h"
  21. #include "../ProjectSaving/jucer_ProjectSaver.h"
  22. #include "../Application/jucer_Application.h"
  23. #include "../LiveBuildEngine/jucer_CompileEngineSettings.h"
  24. namespace
  25. {
  26. String makeValid4CC (const String& seed)
  27. {
  28. auto s = CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx";
  29. return s.substring (0, 1).toUpperCase()
  30. + s.substring (1, 4).toLowerCase();
  31. }
  32. }
  33. //==============================================================================
  34. Project::Project (const File& f)
  35. : FileBasedDocument (projectFileExtension,
  36. String ("*") + projectFileExtension,
  37. "Choose a Jucer project to load",
  38. "Save Jucer project")
  39. {
  40. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  41. setFile (f);
  42. removeDefunctExporters();
  43. updateOldModulePaths();
  44. updateOldStyleConfigList();
  45. setCppVersionFromOldExporterSettings();
  46. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  47. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  48. initialiseProjectValues();
  49. initialiseMainGroup();
  50. initialiseAudioPluginValues();
  51. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  52. getModules().sortAlphabetically();
  53. projectRoot.addListener (this);
  54. compileEngineSettings.reset (new CompileEngineSettings (projectRoot));
  55. setChangedFlag (false);
  56. modificationTime = getFile().getLastModificationTime();
  57. }
  58. Project::~Project()
  59. {
  60. projectRoot.removeListener (this);
  61. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  62. }
  63. const char* Project::projectFileExtension = ".jucer";
  64. //==============================================================================
  65. void Project::setTitle (const String& newTitle)
  66. {
  67. projectNameValue = newTitle;
  68. updateTitle();
  69. }
  70. void Project::updateTitle()
  71. {
  72. auto projectName = getProjectNameString();
  73. getMainGroup().getNameValue() = projectName;
  74. pluginNameValue.setDefault (projectName);
  75. pluginDescriptionValue.setDefault (projectName);
  76. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  77. pluginAUExportPrefixValue.setDefault (CodeHelpers::makeValidIdentifier (projectName, false, true, false) + "AU");
  78. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  79. }
  80. String Project::getDocumentTitle()
  81. {
  82. return getProjectNameString();
  83. }
  84. void Project::updateProjectSettings()
  85. {
  86. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  87. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  88. }
  89. bool Project::setCppVersionFromOldExporterSettings()
  90. {
  91. auto highestLanguageStandard = -1;
  92. for (Project::ExporterIterator exporter (*this); exporter.next();)
  93. {
  94. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  95. {
  96. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  97. {
  98. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  99. if (cppLanguageStandard != var())
  100. {
  101. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  102. if (versionNum > highestLanguageStandard)
  103. highestLanguageStandard = versionNum;
  104. }
  105. }
  106. }
  107. else
  108. {
  109. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  110. if (cppLanguageStandard != var())
  111. {
  112. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  113. {
  114. cppStandardValue = "latest";
  115. return true;
  116. }
  117. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  118. if (versionNum > highestLanguageStandard)
  119. highestLanguageStandard = versionNum;
  120. }
  121. }
  122. }
  123. if (highestLanguageStandard != -1 && highestLanguageStandard >= 11)
  124. {
  125. cppStandardValue = highestLanguageStandard;
  126. return true;
  127. }
  128. return false;
  129. }
  130. void Project::updateDeprecatedProjectSettingsInteractively()
  131. {
  132. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  133. for (Project::ExporterIterator exporter (*this); exporter.next();)
  134. exporter->updateDeprecatedProjectSettingsInteractively();
  135. }
  136. void Project::initialiseMainGroup()
  137. {
  138. // Create main file group if missing
  139. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  140. {
  141. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  142. projectRoot.addChild (mainGroup.state, 0, 0);
  143. }
  144. getMainGroup().initialiseMissingProperties();
  145. }
  146. void Project::initialiseProjectValues()
  147. {
  148. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  149. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  150. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), ProjectType_GUIApp::getTypeName());
  151. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  152. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  153. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  154. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  155. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager());
  156. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  157. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), ! ProjucerApplication::getApp().isPaidOrGPL());
  158. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  159. reportAppUsageValue.referTo (projectRoot, Ids::reportAppUsage, getUndoManager());
  160. if (ProjucerApplication::getApp().isPaidOrGPL())
  161. {
  162. reportAppUsageValue.setDefault (ProjucerApplication::getApp().licenseController->getState().applicationUsageDataState
  163. == LicenseState::ApplicationUsageData::enabled);
  164. }
  165. else
  166. {
  167. reportAppUsageValue.setDefault (true);
  168. }
  169. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "14");
  170. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  171. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  172. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  173. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  174. // this is here for backwards compatibility with old projects using the incorrect id
  175. if (projectRoot.hasProperty ("includeBinaryInAppConfig"))
  176. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, "includeBinaryInAppConfig", getUndoManager(), true);
  177. else
  178. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, Ids::includeBinaryInJuceHeader, getUndoManager(), true);
  179. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  180. }
  181. void Project::initialiseAudioPluginValues()
  182. {
  183. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(),
  184. Array<var> (Ids::buildVST.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()), ",");
  185. pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array<var> (), ",");
  186. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  187. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  188. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), "yourcompany");
  189. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  190. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  191. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  192. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  193. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  194. CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  195. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager(), getDefaultAUMainTypes(), ",");
  196. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager(), getDefaultVSTCategories(), ",");
  197. pluginVST3CategoryValue.referTo (projectRoot, Ids::pluginVST3Category, getUndoManager(), getDefaultVST3Categories(), ",");
  198. pluginRTASCategoryValue.referTo (projectRoot, Ids::pluginRTASCategory, getUndoManager(), getDefaultRTASCategories(), ",");
  199. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), getDefaultAAXCategories(), ",");
  200. }
  201. void Project::updateOldStyleConfigList()
  202. {
  203. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  204. if (deprecatedConfigsList.isValid())
  205. {
  206. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  207. for (Project::ExporterIterator exporter (*this); exporter.next();)
  208. {
  209. if (exporter->getNumConfigurations() == 0)
  210. {
  211. auto newConfigs = deprecatedConfigsList.createCopy();
  212. if (! exporter->isXcode())
  213. {
  214. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  215. {
  216. auto config = newConfigs.getChild (j);
  217. config.removeProperty (Ids::osxSDK, nullptr);
  218. config.removeProperty (Ids::osxCompatibility, nullptr);
  219. config.removeProperty (Ids::osxArchitecture, nullptr);
  220. }
  221. }
  222. exporter->settings.addChild (newConfigs, 0, nullptr);
  223. }
  224. }
  225. }
  226. }
  227. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  228. {
  229. if (projectRoot.hasProperty (name))
  230. {
  231. for (Project::ExporterIterator exporter (*this); exporter.next();)
  232. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  233. projectRoot.removeProperty (name, nullptr);
  234. }
  235. }
  236. void Project::removeDefunctExporters()
  237. {
  238. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  239. StringPairArray oldExporters;
  240. oldExporters.set ("ANDROID", "Android Ant Exporter");
  241. oldExporters.set ("MSVC6", "MSVC6");
  242. oldExporters.set ("VS2010", "Visual Studio 2010");
  243. oldExporters.set ("VS2012", "Visual Studio 2012");
  244. for (auto& key : oldExporters.getAllKeys())
  245. {
  246. auto oldExporter = exporters.getChildWithName (key);
  247. if (oldExporter.isValid())
  248. {
  249. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  250. TRANS (oldExporters[key]),
  251. TRANS ("The " + oldExporters[key] + " Exporter is deprecated. The exporter will be removed from this project."));
  252. exporters.removeChild (oldExporter, nullptr);
  253. }
  254. }
  255. }
  256. void Project::updateOldModulePaths()
  257. {
  258. for (Project::ExporterIterator exporter (*this); exporter.next();)
  259. exporter->updateOldModulePaths();
  260. }
  261. Array<Identifier> Project::getLegacyPluginFormatIdentifiers() noexcept
  262. {
  263. static Array<Identifier> legacyPluginFormatIdentifiers { Ids::buildVST, Ids::buildVST3, Ids::buildAU, Ids::buildAUv3,
  264. Ids::buildRTAS, Ids::buildAAX, Ids::buildStandalone, Ids::enableIAA };
  265. return legacyPluginFormatIdentifiers;
  266. }
  267. Array<Identifier> Project::getLegacyPluginCharacteristicsIdentifiers() noexcept
  268. {
  269. static Array<Identifier> legacyPluginCharacteristicsIdentifiers { Ids::pluginIsSynth, Ids::pluginWantsMidiIn, Ids::pluginProducesMidiOut,
  270. Ids::pluginIsMidiEffectPlugin, Ids::pluginEditorRequiresKeys, Ids::pluginRTASDisableBypass,
  271. Ids::pluginRTASDisableMultiMono, Ids::pluginAAXDisableBypass, Ids::pluginAAXDisableMultiMono };
  272. return legacyPluginCharacteristicsIdentifiers;
  273. }
  274. void Project::coalescePluginFormatValues()
  275. {
  276. Array<var> formatsToBuild;
  277. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  278. {
  279. if (projectRoot.getProperty (formatIdentifier, false))
  280. formatsToBuild.add (formatIdentifier.toString());
  281. }
  282. if (formatsToBuild.size() > 0)
  283. {
  284. pluginFormatsValue = formatsToBuild;
  285. shouldWriteLegacyPluginFormatSettings = true;
  286. }
  287. }
  288. void Project::coalescePluginCharacteristicsValues()
  289. {
  290. Array<var> pluginCharacteristics;
  291. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  292. {
  293. if (projectRoot.getProperty (characteristicIdentifier, false))
  294. pluginCharacteristics.add (characteristicIdentifier.toString());
  295. }
  296. if (pluginCharacteristics.size() > 0)
  297. {
  298. pluginCharacteristicsValue = pluginCharacteristics;
  299. shouldWriteLegacyPluginCharacteristicsSettings = true;
  300. }
  301. }
  302. void Project::updatePluginCategories()
  303. {
  304. {
  305. auto aaxCategory = projectRoot.getProperty (Ids::pluginAAXCategory, {}).toString();
  306. if (getAllAAXCategoryVars().contains (aaxCategory))
  307. pluginAAXCategoryValue = aaxCategory;
  308. else if (getAllAAXCategoryStrings().contains (aaxCategory))
  309. pluginAAXCategoryValue = Array<var> (getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf (aaxCategory)]);
  310. else
  311. pluginAAXCategoryValue.resetToDefault();
  312. }
  313. {
  314. auto rtasCategory = projectRoot.getProperty (Ids::pluginRTASCategory, {}).toString();
  315. if (getAllRTASCategoryVars().contains (rtasCategory))
  316. pluginRTASCategoryValue = rtasCategory;
  317. else if (getAllRTASCategoryStrings().contains (rtasCategory))
  318. pluginRTASCategoryValue = Array<var> (getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf (rtasCategory)]);
  319. else
  320. pluginRTASCategoryValue.resetToDefault();
  321. }
  322. {
  323. auto vstCategory = projectRoot.getProperty (Ids::pluginVSTCategory, {}).toString();
  324. if (vstCategory.isNotEmpty() && getAllVSTCategoryStrings().contains (vstCategory))
  325. pluginVSTCategoryValue = Array<var> (vstCategory);
  326. else
  327. pluginVSTCategoryValue.resetToDefault();
  328. }
  329. {
  330. auto auMainType = projectRoot.getProperty (Ids::pluginAUMainType, {}).toString();
  331. if (auMainType.isNotEmpty())
  332. {
  333. if (getAllAUMainTypeVars().contains (auMainType))
  334. pluginAUMainTypeValue = Array<var> (auMainType);
  335. else if (getAllAUMainTypeVars().contains (auMainType.quoted ('\'')))
  336. pluginAUMainTypeValue = Array<var> (auMainType.quoted ('\''));
  337. else if (getAllAUMainTypeStrings().contains (auMainType))
  338. pluginAUMainTypeValue = Array<var> (getAllAUMainTypeVars()[getAllAUMainTypeStrings().indexOf (auMainType)]);
  339. }
  340. else
  341. {
  342. pluginAUMainTypeValue.resetToDefault();
  343. }
  344. }
  345. }
  346. void Project::writeLegacyPluginFormatSettings()
  347. {
  348. if (pluginFormatsValue.isUsingDefault())
  349. {
  350. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  351. projectRoot.removeProperty (formatIdentifier, nullptr);
  352. }
  353. else
  354. {
  355. auto formatVar = pluginFormatsValue.get();
  356. if (auto* arr = formatVar.getArray())
  357. {
  358. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  359. projectRoot.setProperty (formatIdentifier, arr->contains (formatIdentifier.toString()), nullptr);
  360. }
  361. }
  362. }
  363. void Project::writeLegacyPluginCharacteristicsSettings()
  364. {
  365. if (pluginFormatsValue.isUsingDefault())
  366. {
  367. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  368. projectRoot.removeProperty (characteristicIdentifier, nullptr);
  369. }
  370. else
  371. {
  372. auto characteristicsVar = pluginCharacteristicsValue.get();
  373. if (auto* arr = characteristicsVar.getArray())
  374. {
  375. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  376. projectRoot.setProperty (characteristicIdentifier, arr->contains (characteristicIdentifier.toString()), nullptr);
  377. }
  378. }
  379. }
  380. //==============================================================================
  381. static int getVersionElement (StringRef v, int index)
  382. {
  383. StringArray parts = StringArray::fromTokens (v, "., ", {});
  384. return parts [parts.size() - index - 1].getIntValue();
  385. }
  386. static int getJuceVersion (const String& v)
  387. {
  388. return getVersionElement (v, 2) * 100000
  389. + getVersionElement (v, 1) * 1000
  390. + getVersionElement (v, 0);
  391. }
  392. static int getBuiltJuceVersion()
  393. {
  394. return JUCE_MAJOR_VERSION * 100000
  395. + JUCE_MINOR_VERSION * 1000
  396. + JUCE_BUILDNUMBER;
  397. }
  398. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  399. {
  400. for (auto i = modules.size(); --i >= 0;)
  401. {
  402. auto* m = modules.getUnchecked(i);
  403. if (m->getID().startsWith ("juce_")
  404. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  405. return true;
  406. }
  407. return false;
  408. }
  409. void Project::warnAboutOldProjucerVersion()
  410. {
  411. ModuleList available;
  412. available.scanGlobalJuceModulePath();
  413. if (! isAnyModuleNewerThanProjucer (available.modules))
  414. available.scanGlobalUserModulePath();
  415. if (! isAnyModuleNewerThanProjucer (available.modules))
  416. available.scanProjectExporterModulePaths (*this);
  417. if (! isAnyModuleNewerThanProjucer (available.modules))
  418. return;
  419. // Projucer is out of date!
  420. if (ProjucerApplication::getApp().isRunningCommandLine)
  421. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  422. else
  423. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  424. "Projucer",
  425. "This version of the Projucer is out-of-date!"
  426. "\n\n"
  427. "Always make sure that you're running the very latest version, "
  428. "preferably compiled directly from the JUCE repository that you're working with!");
  429. }
  430. //==============================================================================
  431. static File lastDocumentOpened;
  432. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  433. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  434. static void registerRecentFile (const File& file)
  435. {
  436. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  437. getAppSettings().recentFiles.addFile (file);
  438. getAppSettings().flush();
  439. }
  440. static void forgetRecentFile (const File& file)
  441. {
  442. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  443. getAppSettings().recentFiles.removeFile (file);
  444. getAppSettings().flush();
  445. }
  446. //==============================================================================
  447. Result Project::loadDocument (const File& file)
  448. {
  449. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  450. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  451. return Result::fail ("Not a valid Jucer project!");
  452. auto newTree = ValueTree::fromXml (*xml);
  453. if (! newTree.hasType (Ids::JUCERPROJECT))
  454. return Result::fail ("The document contains errors and couldn't be parsed!");
  455. registerRecentFile (file);
  456. enabledModulesList.reset();
  457. projectRoot = newTree;
  458. initialiseProjectValues();
  459. initialiseMainGroup();
  460. initialiseAudioPluginValues();
  461. coalescePluginFormatValues();
  462. coalescePluginCharacteristicsValues();
  463. updatePluginCategories();
  464. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  465. removeDefunctExporters();
  466. updateOldModulePaths();
  467. setChangedFlag (false);
  468. if (! ProjucerApplication::getApp().isRunningCommandLine)
  469. warnAboutOldProjucerVersion();
  470. compileEngineSettings.reset (new CompileEngineSettings (projectRoot));
  471. return Result::ok();
  472. }
  473. Result Project::saveDocument (const File& file)
  474. {
  475. return saveProject (file, false);
  476. }
  477. Result Project::saveProject (const File& file, bool isCommandLineApp)
  478. {
  479. if (isSaving)
  480. return Result::ok();
  481. if (isTemporaryProject())
  482. {
  483. askUserWhereToSaveProject();
  484. return Result::ok();
  485. }
  486. updateProjectSettings();
  487. if (! isCommandLineApp && ! isTemporaryProject())
  488. registerRecentFile (file);
  489. const ScopedValueSetter<bool> vs (isSaving, true, false);
  490. ProjectSaver saver (*this, file);
  491. return saver.save (! isCommandLineApp, shouldWaitAfterSaving, specifiedExporterToSave);
  492. }
  493. Result Project::saveResourcesOnly (const File& file)
  494. {
  495. ProjectSaver saver (*this, file);
  496. return saver.saveResourcesOnly();
  497. }
  498. //==============================================================================
  499. void Project::setTemporaryDirectory (const File& dir) noexcept
  500. {
  501. tempDirectory = dir;
  502. // remove this file from the recent documents list as it is a temporary project
  503. forgetRecentFile (getFile());
  504. }
  505. void Project::askUserWhereToSaveProject()
  506. {
  507. FileChooser fc ("Save Project");
  508. fc.browseForDirectory();
  509. if (fc.getResult().exists())
  510. moveTemporaryDirectory (fc.getResult());
  511. }
  512. void Project::moveTemporaryDirectory (const File& newParentDirectory)
  513. {
  514. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  515. auto oldJucerFileName = getFile().getFileName();
  516. saveProjectRootToFile();
  517. tempDirectory.copyDirectoryTo (newDirectory);
  518. tempDirectory.deleteRecursively();
  519. tempDirectory = File();
  520. // reload project from new location
  521. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  522. {
  523. Component::SafePointer<MainWindow> safeWindow (window);
  524. MessageManager::callAsync ([safeWindow, newDirectory, oldJucerFileName]
  525. {
  526. if (safeWindow != nullptr)
  527. safeWindow.getComponent()->moveProject (newDirectory.getChildFile (oldJucerFileName));
  528. });
  529. }
  530. }
  531. bool Project::saveProjectRootToFile()
  532. {
  533. ScopedPointer<XmlElement> xml (projectRoot.createXml());
  534. if (xml == nullptr)
  535. {
  536. jassertfalse;
  537. return false;
  538. }
  539. MemoryOutputStream mo;
  540. xml->writeToStream (mo, {});
  541. return FileHelpers::overwriteFileWithNewDataIfDifferent (getFile(), mo);
  542. }
  543. //==============================================================================
  544. static void sendProjectSettingAnalyticsEvent (StringRef label)
  545. {
  546. StringPairArray data;
  547. data.set ("label", label);
  548. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  549. }
  550. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  551. {
  552. if (tree.getRoot() == tree)
  553. {
  554. if (property == Ids::projectType)
  555. {
  556. sendChangeMessage();
  557. sendProjectSettingAnalyticsEvent ("Project Type = " + projectTypeValue.get().toString());
  558. }
  559. else if (property == Ids::name)
  560. {
  561. updateTitle();
  562. }
  563. else if (property == Ids::defines)
  564. {
  565. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  566. }
  567. else if (property == Ids::cppLanguageStandard)
  568. {
  569. sendProjectSettingAnalyticsEvent ("C++ Standard = " + cppStandardValue.get().toString());
  570. }
  571. else if (property == Ids::pluginFormats)
  572. {
  573. if (shouldWriteLegacyPluginFormatSettings)
  574. writeLegacyPluginFormatSettings();
  575. }
  576. else if (property == Ids::pluginCharacteristicsValue)
  577. {
  578. pluginAUMainTypeValue.setDefault (getDefaultAUMainTypes());
  579. pluginVSTCategoryValue.setDefault (getDefaultVSTCategories());
  580. pluginVST3CategoryValue.setDefault (getDefaultVST3Categories());
  581. pluginRTASCategoryValue.setDefault (getDefaultRTASCategories());
  582. pluginAAXCategoryValue.setDefault (getDefaultAAXCategories());
  583. if (shouldWriteLegacyPluginCharacteristicsSettings)
  584. writeLegacyPluginCharacteristicsSettings();
  585. }
  586. changed();
  587. }
  588. }
  589. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  590. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  591. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  592. void Project::valueTreeParentChanged (ValueTree&) {}
  593. //==============================================================================
  594. bool Project::hasProjectBeenModified()
  595. {
  596. auto oldModificationTime = modificationTime;
  597. modificationTime = getFile().getLastModificationTime();
  598. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  599. }
  600. //==============================================================================
  601. File Project::resolveFilename (String filename) const
  602. {
  603. if (filename.isEmpty())
  604. return {};
  605. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  606. #if ! JUCE_WINDOWS
  607. if (filename.startsWith ("~"))
  608. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  609. #endif
  610. if (FileHelpers::isAbsolutePath (filename))
  611. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  612. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  613. }
  614. String Project::getRelativePathForFile (const File& file) const
  615. {
  616. auto filename = file.getFullPathName();
  617. auto relativePathBase = getFile().getParentDirectory();
  618. auto p1 = relativePathBase.getFullPathName();
  619. auto p2 = file.getFullPathName();
  620. while (p1.startsWithChar (File::getSeparatorChar()))
  621. p1 = p1.substring (1);
  622. while (p2.startsWithChar (File::getSeparatorChar()))
  623. p2 = p2.substring (1);
  624. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  625. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  626. {
  627. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  628. }
  629. return filename;
  630. }
  631. //==============================================================================
  632. const ProjectType& Project::getProjectType() const
  633. {
  634. if (auto* type = ProjectType::findType (getProjectTypeString()))
  635. return *type;
  636. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  637. jassert (guiType != nullptr);
  638. return *guiType;
  639. }
  640. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  641. {
  642. auto& projectType = getProjectType();
  643. if (! projectType.supportsTargetType (targetType))
  644. return false;
  645. switch (targetType)
  646. {
  647. case ProjectType::Target::VSTPlugIn:
  648. return shouldBuildVST();
  649. case ProjectType::Target::VST3PlugIn:
  650. return shouldBuildVST3();
  651. case ProjectType::Target::AAXPlugIn:
  652. return shouldBuildAAX();
  653. case ProjectType::Target::RTASPlugIn:
  654. return shouldBuildRTAS();
  655. case ProjectType::Target::AudioUnitPlugIn:
  656. return shouldBuildAU();
  657. case ProjectType::Target::AudioUnitv3PlugIn:
  658. return shouldBuildAUv3();
  659. case ProjectType::Target::StandalonePlugIn:
  660. return shouldBuildStandalonePlugin();
  661. case ProjectType::Target::AggregateTarget:
  662. case ProjectType::Target::SharedCodeTarget:
  663. return projectType.isAudioPlugin();
  664. case ProjectType::Target::unspecified:
  665. return false;
  666. default:
  667. break;
  668. }
  669. return true;
  670. }
  671. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  672. {
  673. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  674. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  675. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  676. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  677. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  678. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  679. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  680. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  681. }
  682. const char* ProjectType::Target::getName() const noexcept
  683. {
  684. switch (type)
  685. {
  686. case GUIApp: return "App";
  687. case ConsoleApp: return "ConsoleApp";
  688. case StaticLibrary: return "Static Library";
  689. case DynamicLibrary: return "Dynamic Library";
  690. case VSTPlugIn: return "VST";
  691. case VST3PlugIn: return "VST3";
  692. case AudioUnitPlugIn: return "AU";
  693. case StandalonePlugIn: return "Standalone Plugin";
  694. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  695. case AAXPlugIn: return "AAX";
  696. case RTASPlugIn: return "RTAS";
  697. case SharedCodeTarget: return "Shared Code";
  698. case AggregateTarget: return "All";
  699. default: return "undefined";
  700. }
  701. }
  702. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  703. {
  704. switch (type)
  705. {
  706. case GUIApp: return executable;
  707. case ConsoleApp: return executable;
  708. case StaticLibrary: return staticLibrary;
  709. case DynamicLibrary: return sharedLibraryOrDLL;
  710. case VSTPlugIn: return pluginBundle;
  711. case VST3PlugIn: return pluginBundle;
  712. case AudioUnitPlugIn: return pluginBundle;
  713. case StandalonePlugIn: return executable;
  714. case AudioUnitv3PlugIn: return macOSAppex;
  715. case AAXPlugIn: return pluginBundle;
  716. case RTASPlugIn: return pluginBundle;
  717. case SharedCodeTarget: return staticLibrary;
  718. default:
  719. break;
  720. }
  721. return unknown;
  722. }
  723. //==============================================================================
  724. void Project::createPropertyEditors (PropertyListBuilder& props)
  725. {
  726. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  727. "The name of the project.");
  728. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  729. "The project's version number, This should be in the format major.minor.point[.point]");
  730. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  731. "Your company name, which will be added to the properties of the binary where possible");
  732. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  733. "Your company copyright, which will be added to the properties of the binary where possible");
  734. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  735. "Your company website, which will be added to the properties of the binary where possible");
  736. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  737. "Your company e-mail, which will be added to the properties of the binary where possible");
  738. {
  739. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  740. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  741. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  742. "license, or are using JUCE under the GPL v3 license.");
  743. StringPairArray description;
  744. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  745. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  746. if (ProjucerApplication::getApp().isPaidOrGPL())
  747. {
  748. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  749. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  750. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  751. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  752. }
  753. else
  754. {
  755. StringArray options;
  756. Array<var> vars;
  757. options.add (licenseRequiredTagline);
  758. vars.add (var());
  759. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  760. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  761. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  762. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  763. }
  764. }
  765. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  766. { "Dark", "Light" },
  767. { "Dark", "Light" }),
  768. "Choose the colour of the JUCE splash screen.");
  769. {
  770. StringArray projectTypeNames;
  771. Array<var> projectTypeCodes;
  772. auto types = ProjectType::getAllTypes();
  773. for (int i = 0; i < types.size(); ++i)
  774. {
  775. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  776. projectTypeCodes.add (types.getUnchecked(i)->getType());
  777. }
  778. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  779. "The project type for which settings should be shown.");
  780. }
  781. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  782. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  783. if (getProjectType().isAudioPlugin())
  784. createAudioPluginPropertyEditors (props);
  785. {
  786. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  787. StringArray maxSizeNames;
  788. Array<var> maxSizeCodes;
  789. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  790. {
  791. auto sizeInBytes = maxSizes[i] * 1024;
  792. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  793. maxSizeCodes.add (sizeInBytes);
  794. }
  795. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  796. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  797. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  798. }
  799. props.add (new ChoicePropertyComponent (includeBinaryDataInJuceHeaderValue, "Include BinaryData in JuceHeader"),
  800. "Include BinaryData.h in the JuceHeader.h file");
  801. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  802. "The namespace containing the binary assests.");
  803. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  804. { "C++11", "C++14", "C++17", "Use Latest" },
  805. { "11", "14", "17", "latest" }),
  806. "The standard of the C++ language that will be used for compilation.");
  807. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  808. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  809. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  810. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  811. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  812. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  813. }
  814. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  815. {
  816. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats",
  817. { "VST", "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Enable IAA" },
  818. { Ids::buildVST.toString(), Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  819. Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::enableIAA.toString() }),
  820. "Plugin formats to build.");
  821. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  822. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  823. "Disable RTAS Bypass", "Disable AAX Bypass", "Disable RTAS Multi-Mono", "Disable AAX Multi-Mono" },
  824. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  825. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(), Ids::pluginRTASDisableBypass.toString(),
  826. Ids::pluginAAXDisableBypass.toString(), Ids::pluginRTASDisableMultiMono.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  827. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  828. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  829. "The name of your plugin (keep it short!)");
  830. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  831. "A short description of your plugin.");
  832. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  833. "The name of your company (cannot be blank).");
  834. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  835. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  836. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  837. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  838. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  839. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  840. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  841. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  842. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  843. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  844. "The value to use for the JucePlugin_AAXIdentifier setting");
  845. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  846. "A prefix for the names of exported entry-point functions that the component exposes - typically this will be a version of your plugin's name that can be used as part of a C++ token.");
  847. props.add (new MultiChoicePropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", getAllAUMainTypeStrings(), getAllAUMainTypeVars(), 1),
  848. "AU main type.");
  849. {
  850. Array<var> vstCategoryVars;
  851. for (auto s : getAllVSTCategoryStrings())
  852. vstCategoryVars.add (s);
  853. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  854. "VST category.");
  855. }
  856. {
  857. Array<var> vst3CategoryVars;
  858. for (auto s : getAllVST3CategoryStrings())
  859. vst3CategoryVars.add (s);
  860. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  861. "VST3 category.");
  862. }
  863. props.add (new MultiChoicePropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", getAllRTASCategoryStrings(), getAllRTASCategoryVars()),
  864. "RTAS category.");
  865. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  866. "AAX category.");
  867. }
  868. //==============================================================================
  869. static StringArray getVersionSegments (const Project& p)
  870. {
  871. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  872. segments.trim();
  873. segments.removeEmptyStrings();
  874. return segments;
  875. }
  876. int Project::getVersionAsHexInteger() const
  877. {
  878. auto segments = getVersionSegments (*this);
  879. auto value = (segments[0].getIntValue() << 16)
  880. + (segments[1].getIntValue() << 8)
  881. + segments[2].getIntValue();
  882. if (segments.size() >= 4)
  883. value = (value << 8) + segments[3].getIntValue();
  884. return value;
  885. }
  886. String Project::getVersionAsHex() const
  887. {
  888. return "0x" + String::toHexString (getVersionAsHexInteger());
  889. }
  890. File Project::getBinaryDataCppFile (int index) const
  891. {
  892. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  893. if (index > 0)
  894. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  895. .withFileExtension (cpp.getFileExtension());
  896. return cpp;
  897. }
  898. Project::Item Project::getMainGroup()
  899. {
  900. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  901. }
  902. PropertiesFile& Project::getStoredProperties() const
  903. {
  904. return getAppSettings().getProjectProperties (getProjectUIDString());
  905. }
  906. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  907. {
  908. if (item.isImageFile())
  909. {
  910. found.add (new Project::Item (item));
  911. }
  912. else if (item.isGroup())
  913. {
  914. for (int i = 0; i < item.getNumChildren(); ++i)
  915. findImages (item.getChild (i), found);
  916. }
  917. }
  918. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  919. {
  920. findImages (getMainGroup(), items);
  921. }
  922. //==============================================================================
  923. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  924. : project (p), state (s), belongsToModule (isModuleCode)
  925. {
  926. }
  927. Project::Item::Item (const Item& other)
  928. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  929. {
  930. }
  931. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  932. String Project::Item::getID() const { return state [Ids::ID]; }
  933. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  934. Drawable* Project::Item::loadAsImageFile() const
  935. {
  936. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  937. if (! mml.lockWasGained())
  938. return nullptr;
  939. return isValid() ? Drawable::createFromImageFile (getFile())
  940. : nullptr;
  941. }
  942. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  943. {
  944. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  945. group.setID (uid);
  946. group.initialiseMissingProperties();
  947. group.getNameValue() = name;
  948. return group;
  949. }
  950. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  951. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  952. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  953. bool Project::Item::isImageFile() const
  954. {
  955. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  956. || getFile().hasFileExtension ("svg"));
  957. }
  958. Project::Item Project::Item::findItemWithID (const String& targetId) const
  959. {
  960. if (state [Ids::ID] == targetId)
  961. return *this;
  962. if (isGroup())
  963. {
  964. for (auto i = getNumChildren(); --i >= 0;)
  965. {
  966. auto found = getChild(i).findItemWithID (targetId);
  967. if (found.isValid())
  968. return found;
  969. }
  970. }
  971. return Item (project, ValueTree(), false);
  972. }
  973. bool Project::Item::canContain (const Item& child) const
  974. {
  975. if (isFile())
  976. return false;
  977. if (isGroup())
  978. return child.isFile() || child.isGroup();
  979. jassertfalse;
  980. return false;
  981. }
  982. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  983. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  984. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  985. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  986. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  987. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  988. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  989. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  990. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  991. bool Project::Item::isModuleCode() const { return belongsToModule; }
  992. String Project::Item::getFilePath() const
  993. {
  994. if (isFile())
  995. return state [Ids::file].toString();
  996. return {};
  997. }
  998. File Project::Item::getFile() const
  999. {
  1000. if (isFile())
  1001. return project.resolveFilename (state [Ids::file].toString());
  1002. return {};
  1003. }
  1004. void Project::Item::setFile (const File& file)
  1005. {
  1006. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  1007. jassert (getFile() == file);
  1008. }
  1009. void Project::Item::setFile (const RelativePath& file)
  1010. {
  1011. jassert (isFile());
  1012. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  1013. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  1014. }
  1015. bool Project::Item::renameFile (const File& newFile)
  1016. {
  1017. auto oldFile = getFile();
  1018. if (oldFile.moveFileTo (newFile)
  1019. || (newFile.exists() && ! oldFile.exists()))
  1020. {
  1021. setFile (newFile);
  1022. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  1023. return true;
  1024. }
  1025. return false;
  1026. }
  1027. bool Project::Item::containsChildForFile (const RelativePath& file) const
  1028. {
  1029. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  1030. }
  1031. Project::Item Project::Item::findItemForFile (const File& file) const
  1032. {
  1033. if (getFile() == file)
  1034. return *this;
  1035. if (isGroup())
  1036. {
  1037. for (auto i = getNumChildren(); --i >= 0;)
  1038. {
  1039. auto found = getChild(i).findItemForFile (file);
  1040. if (found.isValid())
  1041. return found;
  1042. }
  1043. }
  1044. return Item (project, ValueTree(), false);
  1045. }
  1046. File Project::Item::determineGroupFolder() const
  1047. {
  1048. jassert (isGroup());
  1049. File f;
  1050. for (int i = 0; i < getNumChildren(); ++i)
  1051. {
  1052. f = getChild(i).getFile();
  1053. if (f.exists())
  1054. return f.getParentDirectory();
  1055. }
  1056. auto parent = getParent();
  1057. if (parent != *this)
  1058. {
  1059. f = parent.determineGroupFolder();
  1060. if (f.getChildFile (getName()).isDirectory())
  1061. f = f.getChildFile (getName());
  1062. }
  1063. else
  1064. {
  1065. f = project.getProjectFolder();
  1066. if (f.getChildFile ("Source").isDirectory())
  1067. f = f.getChildFile ("Source");
  1068. }
  1069. return f;
  1070. }
  1071. void Project::Item::initialiseMissingProperties()
  1072. {
  1073. if (! state.hasProperty (Ids::ID))
  1074. setID (createAlphaNumericUID());
  1075. if (isFile())
  1076. {
  1077. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1078. }
  1079. else if (isGroup())
  1080. {
  1081. for (auto i = getNumChildren(); --i >= 0;)
  1082. getChild(i).initialiseMissingProperties();
  1083. }
  1084. }
  1085. Value Project::Item::getNameValue()
  1086. {
  1087. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1088. }
  1089. String Project::Item::getName() const
  1090. {
  1091. return state [Ids::name];
  1092. }
  1093. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1094. {
  1095. state.addChild (newChild.state, insertIndex, getUndoManager());
  1096. }
  1097. void Project::Item::removeItemFromProject()
  1098. {
  1099. state.getParent().removeChild (state, getUndoManager());
  1100. }
  1101. Project::Item Project::Item::getParent() const
  1102. {
  1103. if (isMainGroup() || ! isGroup())
  1104. return *this;
  1105. return { project, state.getParent(), belongsToModule };
  1106. }
  1107. struct ItemSorter
  1108. {
  1109. static int compareElements (const ValueTree& first, const ValueTree& second)
  1110. {
  1111. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1112. }
  1113. };
  1114. struct ItemSorterWithGroupsAtStart
  1115. {
  1116. static int compareElements (const ValueTree& first, const ValueTree& second)
  1117. {
  1118. auto firstIsGroup = first.hasType (Ids::GROUP);
  1119. auto secondIsGroup = second.hasType (Ids::GROUP);
  1120. if (firstIsGroup == secondIsGroup)
  1121. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1122. return firstIsGroup ? -1 : 1;
  1123. }
  1124. };
  1125. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1126. {
  1127. if (keepGroupsAtStart)
  1128. {
  1129. ItemSorterWithGroupsAtStart sorter;
  1130. state.sort (sorter, undoManager, true);
  1131. }
  1132. else
  1133. {
  1134. ItemSorter sorter;
  1135. state.sort (sorter, undoManager, true);
  1136. }
  1137. }
  1138. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1139. {
  1140. if (state.getNumChildren() == 0)
  1141. return false;
  1142. if (state.getNumChildren() == 1)
  1143. return true;
  1144. auto stateCopy = state.createCopy();
  1145. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1146. return stateCopy.isEquivalentTo (state);
  1147. }
  1148. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1149. {
  1150. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1151. if (recursive)
  1152. for (auto i = getNumChildren(); --i >= 0;)
  1153. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1154. }
  1155. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1156. {
  1157. for (auto i = state.getNumChildren(); --i >= 0;)
  1158. {
  1159. auto child = state.getChild (i);
  1160. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1161. return { project, child, belongsToModule };
  1162. }
  1163. return addNewSubGroup (name, -1);
  1164. }
  1165. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1166. {
  1167. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1168. int n = 0;
  1169. while (project.getMainGroup().findItemWithID (newID).isValid())
  1170. newID = createGUID (newID + String (++n));
  1171. auto group = createGroup (project, name, newID, belongsToModule);
  1172. jassert (canContain (group));
  1173. addChild (group, insertIndex);
  1174. return group;
  1175. }
  1176. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1177. {
  1178. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1179. return false;
  1180. if (file.isDirectory())
  1181. {
  1182. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1183. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1184. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1185. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1186. }
  1187. else if (file.existsAsFile())
  1188. {
  1189. if (! project.getMainGroup().findItemForFile (file).isValid())
  1190. addFileUnchecked (file, insertIndex, shouldCompile);
  1191. }
  1192. else
  1193. {
  1194. jassertfalse;
  1195. }
  1196. return true;
  1197. }
  1198. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1199. {
  1200. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1201. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1202. if (! addFileAtIndex (file, 0, shouldCompile))
  1203. return false;
  1204. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1205. sortAlphabetically (wasSortedGroupsFirst, false);
  1206. return true;
  1207. }
  1208. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1209. {
  1210. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1211. item.initialiseMissingProperties();
  1212. item.getNameValue() = file.getFileName();
  1213. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1214. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1215. if (canContain (item))
  1216. {
  1217. item.setFile (file);
  1218. addChild (item, insertIndex);
  1219. }
  1220. }
  1221. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1222. {
  1223. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1224. item.initialiseMissingProperties();
  1225. item.getNameValue() = file.getFileName();
  1226. item.getShouldCompileValue() = shouldCompile;
  1227. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1228. if (canContain (item))
  1229. {
  1230. item.setFile (file);
  1231. addChild (item, insertIndex);
  1232. return true;
  1233. }
  1234. return false;
  1235. }
  1236. Icon Project::Item::getIcon (bool isOpen) const
  1237. {
  1238. auto& icons = getIcons();
  1239. if (isFile())
  1240. {
  1241. if (isImageFile())
  1242. return Icon (icons.imageDoc, Colours::transparentBlack);
  1243. return { icons.file, Colours::transparentBlack };
  1244. }
  1245. if (isMainGroup())
  1246. return { icons.juceLogo, Colours::orange };
  1247. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1248. }
  1249. bool Project::Item::isIconCrossedOut() const
  1250. {
  1251. return isFile()
  1252. && ! (shouldBeCompiled()
  1253. || shouldBeAddedToBinaryResources()
  1254. || getFile().hasFileExtension (headerFileExtensions));
  1255. }
  1256. //==============================================================================
  1257. ValueTree Project::getConfigNode()
  1258. {
  1259. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1260. }
  1261. ValueWithDefault Project::getConfigFlag (const String& name)
  1262. {
  1263. auto configNode = getConfigNode();
  1264. return { configNode, name, getUndoManagerFor (configNode) };
  1265. }
  1266. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1267. {
  1268. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1269. if (configValue == "default")
  1270. return defaultIsEnabled;
  1271. return configValue;
  1272. }
  1273. //==============================================================================
  1274. String Project::getAUMainTypeString() const noexcept
  1275. {
  1276. auto v = pluginAUMainTypeValue.get();
  1277. if (auto* arr = v.getArray())
  1278. return arr->getFirst().toString();
  1279. jassertfalse;
  1280. return {};
  1281. }
  1282. String Project::getVSTCategoryString() const noexcept
  1283. {
  1284. auto v = pluginVSTCategoryValue.get();
  1285. if (auto* arr = v.getArray())
  1286. return arr->getFirst().toString();
  1287. jassertfalse;
  1288. return {};
  1289. }
  1290. static String getVST3CategoryStringFromSelection (Array<var> selected) noexcept
  1291. {
  1292. StringArray categories;
  1293. for (auto& category : selected)
  1294. categories.add (category);
  1295. return categories.joinIntoString ("|");
  1296. }
  1297. String Project::getVST3CategoryString() const noexcept
  1298. {
  1299. auto v = pluginVST3CategoryValue.get();
  1300. if (auto* arr = v.getArray())
  1301. return getVST3CategoryStringFromSelection (*arr);
  1302. jassertfalse;
  1303. return {};
  1304. }
  1305. int Project::getAAXCategory() const noexcept
  1306. {
  1307. int res = 0;
  1308. auto v = pluginAAXCategoryValue.get();
  1309. if (auto* arr = v.getArray())
  1310. {
  1311. for (auto c : *arr)
  1312. res |= static_cast<int> (c);
  1313. }
  1314. return res;
  1315. }
  1316. int Project::getRTASCategory() const noexcept
  1317. {
  1318. int res = 0;
  1319. auto v = pluginRTASCategoryValue.get();
  1320. if (auto* arr = v.getArray())
  1321. {
  1322. for (auto c : *arr)
  1323. res |= static_cast<int> (c);
  1324. }
  1325. return res;
  1326. }
  1327. String Project::getIAATypeCode()
  1328. {
  1329. String s;
  1330. if (pluginWantsMidiInput())
  1331. {
  1332. if (isPluginSynth())
  1333. s = "auri";
  1334. else
  1335. s = "aurm";
  1336. }
  1337. else
  1338. {
  1339. if (isPluginSynth())
  1340. s = "aurg";
  1341. else
  1342. s = "aurx";
  1343. }
  1344. return s;
  1345. }
  1346. String Project::getIAAPluginName()
  1347. {
  1348. auto s = getPluginManufacturerString();
  1349. s << ": ";
  1350. s << getPluginNameString();
  1351. return s;
  1352. }
  1353. //==============================================================================
  1354. bool Project::isAUPluginHost()
  1355. {
  1356. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1357. }
  1358. bool Project::isVSTPluginHost()
  1359. {
  1360. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1361. }
  1362. bool Project::isVST3PluginHost()
  1363. {
  1364. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1365. }
  1366. //==============================================================================
  1367. StringArray Project::getAllAUMainTypeStrings() noexcept
  1368. {
  1369. static StringArray auMainTypeStrings { "kAudioUnitType_Effect", "kAudioUnitType_FormatConverter", "kAudioUnitType_Generator", "kAudioUnitType_MIDIProcessor",
  1370. "kAudioUnitType_Mixer", "kAudioUnitType_MusicDevice", "kAudioUnitType_MusicEffect", "kAudioUnitType_OfflineEffect",
  1371. "kAudioUnitType_Output", "kAudioUnitType_Panner" };
  1372. return auMainTypeStrings;
  1373. }
  1374. Array<var> Project::getAllAUMainTypeVars() noexcept
  1375. {
  1376. static Array<var> auMainTypeVars { "'aufx'", "'aufc'", "'augn'", "'aumi'",
  1377. "'aumx'", "'aumu'", "'aumf'", "'auol'",
  1378. "'auou'", "'aupn'" };
  1379. return auMainTypeVars;
  1380. }
  1381. Array<var> Project::getDefaultAUMainTypes() const noexcept
  1382. {
  1383. if (isPluginMidiEffect()) return { "'aumi'" };
  1384. if (isPluginSynth()) return { "'aumu'" };
  1385. if (pluginWantsMidiInput()) return { "'aumf'" };
  1386. return { "'aufx'" };
  1387. }
  1388. StringArray Project::getAllVSTCategoryStrings() noexcept
  1389. {
  1390. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1391. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1392. "kPlugCategShell", "kPlugCategGenerator" };
  1393. return vstCategoryStrings;
  1394. }
  1395. Array<var> Project::getDefaultVSTCategories() const noexcept
  1396. {
  1397. if (isPluginSynth())
  1398. return { "kPlugCategSynth" };
  1399. return { "kPlugCategEffect" };
  1400. }
  1401. StringArray Project::getAllVST3CategoryStrings() noexcept
  1402. {
  1403. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Spatial", "Analyzer", "Delay", "Distortion", "EQ", "Filter", "Generator", "Mastering",
  1404. "Modulation", "Pitch Shift", "Restoration", "Reverb", "Surround", "Tools", "Network", "Drum", "Sampler",
  1405. "Synth", "External", "OnlyRT", "OnlyOfflineProcess", "NoOfflineProcess", "Up-Downmix" };
  1406. return vst3CategoryStrings;
  1407. }
  1408. Array<var> Project::getDefaultVST3Categories() const noexcept
  1409. {
  1410. if (isPluginSynth())
  1411. return { "Instrument", "Synth" };
  1412. return { "Fx" };
  1413. }
  1414. StringArray Project::getAllAAXCategoryStrings() noexcept
  1415. {
  1416. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1417. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1418. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1419. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1420. return aaxCategoryStrings;
  1421. }
  1422. Array<var> Project::getAllAAXCategoryVars() noexcept
  1423. {
  1424. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1425. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1426. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1427. 0x00000800, 0x00001000, 0x00002000 };
  1428. return aaxCategoryVars;
  1429. }
  1430. Array<var> Project::getDefaultAAXCategories() const noexcept
  1431. {
  1432. if (isPluginSynth())
  1433. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1434. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1435. }
  1436. StringArray Project::getAllRTASCategoryStrings() noexcept
  1437. {
  1438. static StringArray rtasCategoryStrings { "ePlugInCategory_None", "ePlugInCategory_EQ", "ePlugInCategory_Dynamics", "ePlugInCategory_PitchShift",
  1439. "ePlugInCategory_Reverb", "ePlugInCategory_Delay", "ePlugInCategory_Modulation", "ePlugInCategory_Harmonic",
  1440. "ePlugInCategory_NoiseReduction", "ePlugInCategory_Dither", "ePlugInCategory_SoundField", "ePlugInCategory_HWGenerators",
  1441. "ePlugInCategory_SWGenerators", "ePlugInCategory_WrappedPlugin", "ePlugInCategory_Effect" };
  1442. return rtasCategoryStrings;
  1443. }
  1444. Array<var> Project::getAllRTASCategoryVars() noexcept
  1445. {
  1446. static Array<var> rtasCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1447. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1448. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1449. 0x00000800, 0x00001000, 0x00002000 };
  1450. return rtasCategoryVars;
  1451. }
  1452. Array<var> Project::getDefaultRTASCategories() const noexcept
  1453. {
  1454. if (isPluginSynth())
  1455. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_SWGenerators")];
  1456. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_None")];
  1457. }
  1458. //==============================================================================
  1459. EnabledModuleList& Project::getModules()
  1460. {
  1461. if (enabledModulesList == nullptr)
  1462. enabledModulesList.reset (new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr)));
  1463. return *enabledModulesList;
  1464. }
  1465. //==============================================================================
  1466. ValueTree Project::getExporters()
  1467. {
  1468. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1469. }
  1470. int Project::getNumExporters()
  1471. {
  1472. return getExporters().getNumChildren();
  1473. }
  1474. ProjectExporter* Project::createExporter (int index)
  1475. {
  1476. jassert (index >= 0 && index < getNumExporters());
  1477. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1478. }
  1479. void Project::addNewExporter (const String& exporterName)
  1480. {
  1481. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1482. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1483. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1484. auto exportersTree = getExporters();
  1485. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1486. }
  1487. void Project::createExporterForCurrentPlatform()
  1488. {
  1489. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1490. }
  1491. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1492. {
  1493. StringArray buildFolders;
  1494. auto exportersTree = getExporters();
  1495. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1496. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1497. {
  1498. auto exporterNode = exportersTree.getChild (i);
  1499. if (exporterNode.getType() == Identifier (type))
  1500. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1501. }
  1502. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1503. return {};
  1504. buildFolders.remove (buildFolders.indexOf (base));
  1505. int num = 1;
  1506. for (auto f : buildFolders)
  1507. {
  1508. if (! f.endsWith ("_" + String (num)))
  1509. break;
  1510. ++num;
  1511. }
  1512. return "_" + String (num);
  1513. }
  1514. //==============================================================================
  1515. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1516. {
  1517. if (! hasSentGUIBuilderAnalyticsEvent)
  1518. {
  1519. hasSentGUIBuilderAnalyticsEvent = true;
  1520. return true;
  1521. }
  1522. return false;
  1523. }
  1524. //==============================================================================
  1525. String Project::getFileTemplate (const String& templateName)
  1526. {
  1527. int dataSize;
  1528. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1529. return String::fromUTF8 (data, dataSize);
  1530. jassertfalse;
  1531. return {};
  1532. }
  1533. //==============================================================================
  1534. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1535. Project::ExporterIterator::~ExporterIterator() {}
  1536. bool Project::ExporterIterator::next()
  1537. {
  1538. if (++index >= project.getNumExporters())
  1539. return false;
  1540. exporter.reset (project.createExporter (index));
  1541. if (exporter == nullptr)
  1542. {
  1543. jassertfalse; // corrupted project file?
  1544. return next();
  1545. }
  1546. return true;
  1547. }