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.

1955 lines
72KB

  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::UnityPlugIn:
  660. return shouldBuildUnityPlugin();
  661. case ProjectType::Target::AggregateTarget:
  662. case ProjectType::Target::SharedCodeTarget:
  663. return projectType.isAudioPlugin();
  664. case ProjectType::Target::unspecified:
  665. return false;
  666. default:
  667. break;
  668. }
  669. return true;
  670. }
  671. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  672. {
  673. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  674. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  675. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  676. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  677. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  678. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  679. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  680. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Unity")) return ProjectType::Target::UnityPlugIn;
  681. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  682. }
  683. const char* ProjectType::Target::getName() const noexcept
  684. {
  685. switch (type)
  686. {
  687. case GUIApp: return "App";
  688. case ConsoleApp: return "ConsoleApp";
  689. case StaticLibrary: return "Static Library";
  690. case DynamicLibrary: return "Dynamic Library";
  691. case VSTPlugIn: return "VST";
  692. case VST3PlugIn: return "VST3";
  693. case AudioUnitPlugIn: return "AU";
  694. case StandalonePlugIn: return "Standalone Plugin";
  695. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  696. case AAXPlugIn: return "AAX";
  697. case RTASPlugIn: return "RTAS";
  698. case UnityPlugIn: return "Unity Plugin";
  699. case SharedCodeTarget: return "Shared Code";
  700. case AggregateTarget: return "All";
  701. default: return "undefined";
  702. }
  703. }
  704. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  705. {
  706. switch (type)
  707. {
  708. case GUIApp: return executable;
  709. case ConsoleApp: return executable;
  710. case StaticLibrary: return staticLibrary;
  711. case DynamicLibrary: return sharedLibraryOrDLL;
  712. case VSTPlugIn: return pluginBundle;
  713. case VST3PlugIn: return pluginBundle;
  714. case AudioUnitPlugIn: return pluginBundle;
  715. case StandalonePlugIn: return executable;
  716. case AudioUnitv3PlugIn: return macOSAppex;
  717. case AAXPlugIn: return pluginBundle;
  718. case RTASPlugIn: return pluginBundle;
  719. case UnityPlugIn: return pluginBundle;
  720. case SharedCodeTarget: return staticLibrary;
  721. default:
  722. break;
  723. }
  724. return unknown;
  725. }
  726. //==============================================================================
  727. void Project::createPropertyEditors (PropertyListBuilder& props)
  728. {
  729. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  730. "The name of the project.");
  731. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  732. "The project's version number, This should be in the format major.minor.point[.point]");
  733. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  734. "Your company name, which will be added to the properties of the binary where possible");
  735. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  736. "Your company copyright, which will be added to the properties of the binary where possible");
  737. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  738. "Your company website, which will be added to the properties of the binary where possible");
  739. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  740. "Your company e-mail, which will be added to the properties of the binary where possible");
  741. {
  742. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  743. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  744. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  745. "license, or are using JUCE under the GPL v3 license.");
  746. StringPairArray description;
  747. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  748. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  749. if (ProjucerApplication::getApp().isPaidOrGPL())
  750. {
  751. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  752. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  753. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  754. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  755. }
  756. else
  757. {
  758. StringArray options;
  759. Array<var> vars;
  760. options.add (licenseRequiredTagline);
  761. vars.add (var());
  762. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  763. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  764. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  765. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  766. }
  767. }
  768. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  769. { "Dark", "Light" },
  770. { "Dark", "Light" }),
  771. "Choose the colour of the JUCE splash screen.");
  772. {
  773. StringArray projectTypeNames;
  774. Array<var> projectTypeCodes;
  775. auto types = ProjectType::getAllTypes();
  776. for (int i = 0; i < types.size(); ++i)
  777. {
  778. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  779. projectTypeCodes.add (types.getUnchecked(i)->getType());
  780. }
  781. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  782. "The project type for which settings should be shown.");
  783. }
  784. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  785. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  786. if (getProjectType().isAudioPlugin())
  787. createAudioPluginPropertyEditors (props);
  788. {
  789. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  790. StringArray maxSizeNames;
  791. Array<var> maxSizeCodes;
  792. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  793. {
  794. auto sizeInBytes = maxSizes[i] * 1024;
  795. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  796. maxSizeCodes.add (sizeInBytes);
  797. }
  798. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  799. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  800. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  801. }
  802. props.add (new ChoicePropertyComponent (includeBinaryDataInJuceHeaderValue, "Include BinaryData in JuceHeader"),
  803. "Include BinaryData.h in the JuceHeader.h file");
  804. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  805. "The namespace containing the binary assests.");
  806. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  807. { "C++11", "C++14", "C++17", "Use Latest" },
  808. { "11", "14", "17", "latest" }),
  809. "The standard of the C++ language that will be used for compilation.");
  810. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  811. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  812. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  813. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  814. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  815. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  816. }
  817. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  818. {
  819. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats",
  820. { "VST", "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Unity", "Enable IAA" },
  821. { Ids::buildVST.toString(), Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  822. Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::buildUnity.toString(),
  823. Ids::enableIAA.toString() }),
  824. "Plugin formats to build.");
  825. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  826. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  827. "Disable RTAS Bypass", "Disable AAX Bypass", "Disable RTAS Multi-Mono", "Disable AAX Multi-Mono" },
  828. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  829. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(), Ids::pluginRTASDisableBypass.toString(),
  830. Ids::pluginAAXDisableBypass.toString(), Ids::pluginRTASDisableMultiMono.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  831. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  832. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  833. "The name of your plugin (keep it short!)");
  834. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  835. "A short description of your plugin.");
  836. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  837. "The name of your company (cannot be blank).");
  838. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  839. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  840. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  841. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  842. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  843. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  844. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  845. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  846. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  847. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  848. "The value to use for the JucePlugin_AAXIdentifier setting");
  849. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  850. "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.");
  851. props.add (new MultiChoicePropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", getAllAUMainTypeStrings(), getAllAUMainTypeVars(), 1),
  852. "AU main type.");
  853. {
  854. Array<var> vstCategoryVars;
  855. for (auto s : getAllVSTCategoryStrings())
  856. vstCategoryVars.add (s);
  857. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  858. "VST category.");
  859. }
  860. {
  861. Array<var> vst3CategoryVars;
  862. for (auto s : getAllVST3CategoryStrings())
  863. vst3CategoryVars.add (s);
  864. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  865. "VST3 category.");
  866. }
  867. props.add (new MultiChoicePropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", getAllRTASCategoryStrings(), getAllRTASCategoryVars()),
  868. "RTAS category.");
  869. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  870. "AAX category.");
  871. }
  872. //==============================================================================
  873. static StringArray getVersionSegments (const Project& p)
  874. {
  875. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  876. segments.trim();
  877. segments.removeEmptyStrings();
  878. return segments;
  879. }
  880. int Project::getVersionAsHexInteger() const
  881. {
  882. auto segments = getVersionSegments (*this);
  883. auto value = (segments[0].getIntValue() << 16)
  884. + (segments[1].getIntValue() << 8)
  885. + segments[2].getIntValue();
  886. if (segments.size() >= 4)
  887. value = (value << 8) + segments[3].getIntValue();
  888. return value;
  889. }
  890. String Project::getVersionAsHex() const
  891. {
  892. return "0x" + String::toHexString (getVersionAsHexInteger());
  893. }
  894. File Project::getBinaryDataCppFile (int index) const
  895. {
  896. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  897. if (index > 0)
  898. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  899. .withFileExtension (cpp.getFileExtension());
  900. return cpp;
  901. }
  902. Project::Item Project::getMainGroup()
  903. {
  904. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  905. }
  906. PropertiesFile& Project::getStoredProperties() const
  907. {
  908. return getAppSettings().getProjectProperties (getProjectUIDString());
  909. }
  910. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  911. {
  912. if (item.isImageFile())
  913. {
  914. found.add (new Project::Item (item));
  915. }
  916. else if (item.isGroup())
  917. {
  918. for (int i = 0; i < item.getNumChildren(); ++i)
  919. findImages (item.getChild (i), found);
  920. }
  921. }
  922. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  923. {
  924. findImages (getMainGroup(), items);
  925. }
  926. //==============================================================================
  927. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  928. : project (p), state (s), belongsToModule (isModuleCode)
  929. {
  930. }
  931. Project::Item::Item (const Item& other)
  932. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  933. {
  934. }
  935. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  936. String Project::Item::getID() const { return state [Ids::ID]; }
  937. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  938. Drawable* Project::Item::loadAsImageFile() const
  939. {
  940. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  941. if (! mml.lockWasGained())
  942. return nullptr;
  943. return isValid() ? Drawable::createFromImageFile (getFile())
  944. : nullptr;
  945. }
  946. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  947. {
  948. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  949. group.setID (uid);
  950. group.initialiseMissingProperties();
  951. group.getNameValue() = name;
  952. return group;
  953. }
  954. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  955. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  956. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  957. bool Project::Item::isImageFile() const
  958. {
  959. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  960. || getFile().hasFileExtension ("svg"));
  961. }
  962. Project::Item Project::Item::findItemWithID (const String& targetId) const
  963. {
  964. if (state [Ids::ID] == targetId)
  965. return *this;
  966. if (isGroup())
  967. {
  968. for (auto i = getNumChildren(); --i >= 0;)
  969. {
  970. auto found = getChild(i).findItemWithID (targetId);
  971. if (found.isValid())
  972. return found;
  973. }
  974. }
  975. return Item (project, ValueTree(), false);
  976. }
  977. bool Project::Item::canContain (const Item& child) const
  978. {
  979. if (isFile())
  980. return false;
  981. if (isGroup())
  982. return child.isFile() || child.isGroup();
  983. jassertfalse;
  984. return false;
  985. }
  986. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  987. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  988. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  989. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  990. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  991. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  992. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  993. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  994. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  995. bool Project::Item::isModuleCode() const { return belongsToModule; }
  996. String Project::Item::getFilePath() const
  997. {
  998. if (isFile())
  999. return state [Ids::file].toString();
  1000. return {};
  1001. }
  1002. File Project::Item::getFile() const
  1003. {
  1004. if (isFile())
  1005. return project.resolveFilename (state [Ids::file].toString());
  1006. return {};
  1007. }
  1008. void Project::Item::setFile (const File& file)
  1009. {
  1010. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  1011. jassert (getFile() == file);
  1012. }
  1013. void Project::Item::setFile (const RelativePath& file)
  1014. {
  1015. jassert (isFile());
  1016. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  1017. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  1018. }
  1019. bool Project::Item::renameFile (const File& newFile)
  1020. {
  1021. auto oldFile = getFile();
  1022. if (oldFile.moveFileTo (newFile)
  1023. || (newFile.exists() && ! oldFile.exists()))
  1024. {
  1025. setFile (newFile);
  1026. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  1027. return true;
  1028. }
  1029. return false;
  1030. }
  1031. bool Project::Item::containsChildForFile (const RelativePath& file) const
  1032. {
  1033. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  1034. }
  1035. Project::Item Project::Item::findItemForFile (const File& file) const
  1036. {
  1037. if (getFile() == file)
  1038. return *this;
  1039. if (isGroup())
  1040. {
  1041. for (auto i = getNumChildren(); --i >= 0;)
  1042. {
  1043. auto found = getChild(i).findItemForFile (file);
  1044. if (found.isValid())
  1045. return found;
  1046. }
  1047. }
  1048. return Item (project, ValueTree(), false);
  1049. }
  1050. File Project::Item::determineGroupFolder() const
  1051. {
  1052. jassert (isGroup());
  1053. File f;
  1054. for (int i = 0; i < getNumChildren(); ++i)
  1055. {
  1056. f = getChild(i).getFile();
  1057. if (f.exists())
  1058. return f.getParentDirectory();
  1059. }
  1060. auto parent = getParent();
  1061. if (parent != *this)
  1062. {
  1063. f = parent.determineGroupFolder();
  1064. if (f.getChildFile (getName()).isDirectory())
  1065. f = f.getChildFile (getName());
  1066. }
  1067. else
  1068. {
  1069. f = project.getProjectFolder();
  1070. if (f.getChildFile ("Source").isDirectory())
  1071. f = f.getChildFile ("Source");
  1072. }
  1073. return f;
  1074. }
  1075. void Project::Item::initialiseMissingProperties()
  1076. {
  1077. if (! state.hasProperty (Ids::ID))
  1078. setID (createAlphaNumericUID());
  1079. if (isFile())
  1080. {
  1081. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1082. }
  1083. else if (isGroup())
  1084. {
  1085. for (auto i = getNumChildren(); --i >= 0;)
  1086. getChild(i).initialiseMissingProperties();
  1087. }
  1088. }
  1089. Value Project::Item::getNameValue()
  1090. {
  1091. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1092. }
  1093. String Project::Item::getName() const
  1094. {
  1095. return state [Ids::name];
  1096. }
  1097. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1098. {
  1099. state.addChild (newChild.state, insertIndex, getUndoManager());
  1100. }
  1101. void Project::Item::removeItemFromProject()
  1102. {
  1103. state.getParent().removeChild (state, getUndoManager());
  1104. }
  1105. Project::Item Project::Item::getParent() const
  1106. {
  1107. if (isMainGroup() || ! isGroup())
  1108. return *this;
  1109. return { project, state.getParent(), belongsToModule };
  1110. }
  1111. struct ItemSorter
  1112. {
  1113. static int compareElements (const ValueTree& first, const ValueTree& second)
  1114. {
  1115. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1116. }
  1117. };
  1118. struct ItemSorterWithGroupsAtStart
  1119. {
  1120. static int compareElements (const ValueTree& first, const ValueTree& second)
  1121. {
  1122. auto firstIsGroup = first.hasType (Ids::GROUP);
  1123. auto secondIsGroup = second.hasType (Ids::GROUP);
  1124. if (firstIsGroup == secondIsGroup)
  1125. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1126. return firstIsGroup ? -1 : 1;
  1127. }
  1128. };
  1129. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1130. {
  1131. if (keepGroupsAtStart)
  1132. {
  1133. ItemSorterWithGroupsAtStart sorter;
  1134. state.sort (sorter, undoManager, true);
  1135. }
  1136. else
  1137. {
  1138. ItemSorter sorter;
  1139. state.sort (sorter, undoManager, true);
  1140. }
  1141. }
  1142. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1143. {
  1144. if (state.getNumChildren() == 0)
  1145. return false;
  1146. if (state.getNumChildren() == 1)
  1147. return true;
  1148. auto stateCopy = state.createCopy();
  1149. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1150. return stateCopy.isEquivalentTo (state);
  1151. }
  1152. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1153. {
  1154. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1155. if (recursive)
  1156. for (auto i = getNumChildren(); --i >= 0;)
  1157. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1158. }
  1159. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1160. {
  1161. for (auto i = state.getNumChildren(); --i >= 0;)
  1162. {
  1163. auto child = state.getChild (i);
  1164. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1165. return { project, child, belongsToModule };
  1166. }
  1167. return addNewSubGroup (name, -1);
  1168. }
  1169. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1170. {
  1171. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1172. int n = 0;
  1173. while (project.getMainGroup().findItemWithID (newID).isValid())
  1174. newID = createGUID (newID + String (++n));
  1175. auto group = createGroup (project, name, newID, belongsToModule);
  1176. jassert (canContain (group));
  1177. addChild (group, insertIndex);
  1178. return group;
  1179. }
  1180. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1181. {
  1182. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1183. return false;
  1184. if (file.isDirectory())
  1185. {
  1186. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1187. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1188. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1189. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1190. }
  1191. else if (file.existsAsFile())
  1192. {
  1193. if (! project.getMainGroup().findItemForFile (file).isValid())
  1194. addFileUnchecked (file, insertIndex, shouldCompile);
  1195. }
  1196. else
  1197. {
  1198. jassertfalse;
  1199. }
  1200. return true;
  1201. }
  1202. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1203. {
  1204. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1205. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1206. if (! addFileAtIndex (file, 0, shouldCompile))
  1207. return false;
  1208. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1209. sortAlphabetically (wasSortedGroupsFirst, false);
  1210. return true;
  1211. }
  1212. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1213. {
  1214. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1215. item.initialiseMissingProperties();
  1216. item.getNameValue() = file.getFileName();
  1217. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1218. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1219. if (canContain (item))
  1220. {
  1221. item.setFile (file);
  1222. addChild (item, insertIndex);
  1223. }
  1224. }
  1225. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1226. {
  1227. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1228. item.initialiseMissingProperties();
  1229. item.getNameValue() = file.getFileName();
  1230. item.getShouldCompileValue() = shouldCompile;
  1231. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1232. if (canContain (item))
  1233. {
  1234. item.setFile (file);
  1235. addChild (item, insertIndex);
  1236. return true;
  1237. }
  1238. return false;
  1239. }
  1240. Icon Project::Item::getIcon (bool isOpen) const
  1241. {
  1242. auto& icons = getIcons();
  1243. if (isFile())
  1244. {
  1245. if (isImageFile())
  1246. return Icon (icons.imageDoc, Colours::transparentBlack);
  1247. return { icons.file, Colours::transparentBlack };
  1248. }
  1249. if (isMainGroup())
  1250. return { icons.juceLogo, Colours::orange };
  1251. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1252. }
  1253. bool Project::Item::isIconCrossedOut() const
  1254. {
  1255. return isFile()
  1256. && ! (shouldBeCompiled()
  1257. || shouldBeAddedToBinaryResources()
  1258. || getFile().hasFileExtension (headerFileExtensions));
  1259. }
  1260. //==============================================================================
  1261. ValueTree Project::getConfigNode()
  1262. {
  1263. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1264. }
  1265. ValueWithDefault Project::getConfigFlag (const String& name)
  1266. {
  1267. auto configNode = getConfigNode();
  1268. return { configNode, name, getUndoManagerFor (configNode) };
  1269. }
  1270. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1271. {
  1272. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1273. if (configValue == "default")
  1274. return defaultIsEnabled;
  1275. return configValue;
  1276. }
  1277. //==============================================================================
  1278. String Project::getAUMainTypeString() const noexcept
  1279. {
  1280. auto v = pluginAUMainTypeValue.get();
  1281. if (auto* arr = v.getArray())
  1282. return arr->getFirst().toString();
  1283. jassertfalse;
  1284. return {};
  1285. }
  1286. String Project::getVSTCategoryString() const noexcept
  1287. {
  1288. auto v = pluginVSTCategoryValue.get();
  1289. if (auto* arr = v.getArray())
  1290. return arr->getFirst().toString();
  1291. jassertfalse;
  1292. return {};
  1293. }
  1294. static String getVST3CategoryStringFromSelection (Array<var> selected) noexcept
  1295. {
  1296. StringArray categories;
  1297. for (auto& category : selected)
  1298. categories.add (category);
  1299. // "Fx" and "Instrument" should come first and if both are present prioritise "Fx"
  1300. if (categories.contains ("Instrument"))
  1301. categories.move (categories.indexOf ("Instrument"), 0);
  1302. if (categories.contains ("Fx"))
  1303. categories.move (categories.indexOf ("Fx"), 0);
  1304. return categories.joinIntoString ("|");
  1305. }
  1306. String Project::getVST3CategoryString() const noexcept
  1307. {
  1308. auto v = pluginVST3CategoryValue.get();
  1309. if (auto* arr = v.getArray())
  1310. return getVST3CategoryStringFromSelection (*arr);
  1311. jassertfalse;
  1312. return {};
  1313. }
  1314. int Project::getAAXCategory() const noexcept
  1315. {
  1316. int res = 0;
  1317. auto v = pluginAAXCategoryValue.get();
  1318. if (auto* arr = v.getArray())
  1319. {
  1320. for (auto c : *arr)
  1321. res |= static_cast<int> (c);
  1322. }
  1323. return res;
  1324. }
  1325. int Project::getRTASCategory() const noexcept
  1326. {
  1327. int res = 0;
  1328. auto v = pluginRTASCategoryValue.get();
  1329. if (auto* arr = v.getArray())
  1330. {
  1331. for (auto c : *arr)
  1332. res |= static_cast<int> (c);
  1333. }
  1334. return res;
  1335. }
  1336. String Project::getIAATypeCode()
  1337. {
  1338. String s;
  1339. if (pluginWantsMidiInput())
  1340. {
  1341. if (isPluginSynth())
  1342. s = "auri";
  1343. else
  1344. s = "aurm";
  1345. }
  1346. else
  1347. {
  1348. if (isPluginSynth())
  1349. s = "aurg";
  1350. else
  1351. s = "aurx";
  1352. }
  1353. return s;
  1354. }
  1355. String Project::getIAAPluginName()
  1356. {
  1357. auto s = getPluginManufacturerString();
  1358. s << ": ";
  1359. s << getPluginNameString();
  1360. return s;
  1361. }
  1362. //==============================================================================
  1363. bool Project::isAUPluginHost()
  1364. {
  1365. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1366. }
  1367. bool Project::isVSTPluginHost()
  1368. {
  1369. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1370. }
  1371. bool Project::isVST3PluginHost()
  1372. {
  1373. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1374. }
  1375. //==============================================================================
  1376. StringArray Project::getAllAUMainTypeStrings() noexcept
  1377. {
  1378. static StringArray auMainTypeStrings { "kAudioUnitType_Effect", "kAudioUnitType_FormatConverter", "kAudioUnitType_Generator", "kAudioUnitType_MIDIProcessor",
  1379. "kAudioUnitType_Mixer", "kAudioUnitType_MusicDevice", "kAudioUnitType_MusicEffect", "kAudioUnitType_OfflineEffect",
  1380. "kAudioUnitType_Output", "kAudioUnitType_Panner" };
  1381. return auMainTypeStrings;
  1382. }
  1383. Array<var> Project::getAllAUMainTypeVars() noexcept
  1384. {
  1385. static Array<var> auMainTypeVars { "'aufx'", "'aufc'", "'augn'", "'aumi'",
  1386. "'aumx'", "'aumu'", "'aumf'", "'auol'",
  1387. "'auou'", "'aupn'" };
  1388. return auMainTypeVars;
  1389. }
  1390. Array<var> Project::getDefaultAUMainTypes() const noexcept
  1391. {
  1392. if (isPluginMidiEffect()) return { "'aumi'" };
  1393. if (isPluginSynth()) return { "'aumu'" };
  1394. if (pluginWantsMidiInput()) return { "'aumf'" };
  1395. return { "'aufx'" };
  1396. }
  1397. StringArray Project::getAllVSTCategoryStrings() noexcept
  1398. {
  1399. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1400. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1401. "kPlugCategShell", "kPlugCategGenerator" };
  1402. return vstCategoryStrings;
  1403. }
  1404. Array<var> Project::getDefaultVSTCategories() const noexcept
  1405. {
  1406. if (isPluginSynth())
  1407. return { "kPlugCategSynth" };
  1408. return { "kPlugCategEffect" };
  1409. }
  1410. StringArray Project::getAllVST3CategoryStrings() noexcept
  1411. {
  1412. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Analyzer", "Delay", "Distortion", "Drum", "Dynamics", "EQ", "External", "Filter",
  1413. "Generator", "Mastering", "Modulation", "Mono", "Network", "NoOfflineProcess", "OnlyOfflineProcess", "OnlyRT",
  1414. "Pitch Shift", "Restoration", "Reverb", "Sampler", "Spatial", "Stereo", "Surround", "Synth", "Tools", "Up-Downmix" };
  1415. return vst3CategoryStrings;
  1416. }
  1417. Array<var> Project::getDefaultVST3Categories() const noexcept
  1418. {
  1419. if (isPluginSynth())
  1420. return { "Instrument", "Synth" };
  1421. return { "Fx" };
  1422. }
  1423. StringArray Project::getAllAAXCategoryStrings() noexcept
  1424. {
  1425. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1426. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1427. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1428. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1429. return aaxCategoryStrings;
  1430. }
  1431. Array<var> Project::getAllAAXCategoryVars() noexcept
  1432. {
  1433. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1434. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1435. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1436. 0x00000800, 0x00001000, 0x00002000 };
  1437. return aaxCategoryVars;
  1438. }
  1439. Array<var> Project::getDefaultAAXCategories() const noexcept
  1440. {
  1441. if (isPluginSynth())
  1442. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1443. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1444. }
  1445. StringArray Project::getAllRTASCategoryStrings() noexcept
  1446. {
  1447. static StringArray rtasCategoryStrings { "ePlugInCategory_None", "ePlugInCategory_EQ", "ePlugInCategory_Dynamics", "ePlugInCategory_PitchShift",
  1448. "ePlugInCategory_Reverb", "ePlugInCategory_Delay", "ePlugInCategory_Modulation", "ePlugInCategory_Harmonic",
  1449. "ePlugInCategory_NoiseReduction", "ePlugInCategory_Dither", "ePlugInCategory_SoundField", "ePlugInCategory_HWGenerators",
  1450. "ePlugInCategory_SWGenerators", "ePlugInCategory_WrappedPlugin", "ePlugInCategory_Effect" };
  1451. return rtasCategoryStrings;
  1452. }
  1453. Array<var> Project::getAllRTASCategoryVars() noexcept
  1454. {
  1455. static Array<var> rtasCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1456. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1457. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1458. 0x00000800, 0x00001000, 0x00002000 };
  1459. return rtasCategoryVars;
  1460. }
  1461. Array<var> Project::getDefaultRTASCategories() const noexcept
  1462. {
  1463. if (isPluginSynth())
  1464. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_SWGenerators")];
  1465. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_None")];
  1466. }
  1467. //==============================================================================
  1468. EnabledModuleList& Project::getModules()
  1469. {
  1470. if (enabledModulesList == nullptr)
  1471. enabledModulesList.reset (new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr)));
  1472. return *enabledModulesList;
  1473. }
  1474. //==============================================================================
  1475. ValueTree Project::getExporters()
  1476. {
  1477. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1478. }
  1479. int Project::getNumExporters()
  1480. {
  1481. return getExporters().getNumChildren();
  1482. }
  1483. ProjectExporter* Project::createExporter (int index)
  1484. {
  1485. jassert (index >= 0 && index < getNumExporters());
  1486. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1487. }
  1488. void Project::addNewExporter (const String& exporterName)
  1489. {
  1490. std::unique_ptr<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1491. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1492. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1493. auto exportersTree = getExporters();
  1494. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1495. }
  1496. void Project::createExporterForCurrentPlatform()
  1497. {
  1498. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1499. }
  1500. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1501. {
  1502. StringArray buildFolders;
  1503. auto exportersTree = getExporters();
  1504. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1505. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1506. {
  1507. auto exporterNode = exportersTree.getChild (i);
  1508. if (exporterNode.getType() == Identifier (type))
  1509. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1510. }
  1511. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1512. return {};
  1513. buildFolders.remove (buildFolders.indexOf (base));
  1514. int num = 1;
  1515. for (auto f : buildFolders)
  1516. {
  1517. if (! f.endsWith ("_" + String (num)))
  1518. break;
  1519. ++num;
  1520. }
  1521. return "_" + String (num);
  1522. }
  1523. //==============================================================================
  1524. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1525. {
  1526. if (! hasSentGUIBuilderAnalyticsEvent)
  1527. {
  1528. hasSentGUIBuilderAnalyticsEvent = true;
  1529. return true;
  1530. }
  1531. return false;
  1532. }
  1533. //==============================================================================
  1534. String Project::getFileTemplate (const String& templateName)
  1535. {
  1536. int dataSize;
  1537. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1538. return String::fromUTF8 (data, dataSize);
  1539. jassertfalse;
  1540. return {};
  1541. }
  1542. //==============================================================================
  1543. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1544. Project::ExporterIterator::~ExporterIterator() {}
  1545. bool Project::ExporterIterator::next()
  1546. {
  1547. if (++index >= project.getNumExporters())
  1548. return false;
  1549. exporter.reset (project.createExporter (index));
  1550. if (exporter == nullptr)
  1551. {
  1552. jassertfalse; // corrupted project file?
  1553. return next();
  1554. }
  1555. return true;
  1556. }