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.

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