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.

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