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.

1941 lines
71KB

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