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.

1648 lines
61KB

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