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.

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