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.

2066 lines
76KB

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