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.

1622 lines
60KB

  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. tempDirectory.copyDirectoryTo (newDirectory);
  393. tempDirectory.deleteRecursively();
  394. tempDirectory = File();
  395. // reload project from new location
  396. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  397. window->moveProject (newDirectory.getChildFile (oldJucerFileName));
  398. }
  399. //==============================================================================
  400. static void sendProjectSettingAnalyticsEvent (StringRef label)
  401. {
  402. StringPairArray data;
  403. data.set ("label", label);
  404. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  405. }
  406. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  407. {
  408. if (tree.getRoot() == tree)
  409. {
  410. if (property == Ids::projectType)
  411. {
  412. sendChangeMessage();
  413. sendProjectSettingAnalyticsEvent ("Project Type = " + projectTypeValue.get().toString());
  414. }
  415. else if (property == Ids::name)
  416. {
  417. setTitle (projectRoot [Ids::name]);
  418. }
  419. else if (property == Ids::defines)
  420. {
  421. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  422. }
  423. else if (property == Ids::cppLanguageStandard)
  424. {
  425. sendProjectSettingAnalyticsEvent ("C++ Standard = " + cppStandardValue.get().toString());
  426. }
  427. changed();
  428. }
  429. }
  430. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  431. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  432. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  433. void Project::valueTreeParentChanged (ValueTree&) {}
  434. //==============================================================================
  435. bool Project::hasProjectBeenModified()
  436. {
  437. auto oldModificationTime = modificationTime;
  438. modificationTime = getFile().getLastModificationTime();
  439. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  440. }
  441. //==============================================================================
  442. File Project::resolveFilename (String filename) const
  443. {
  444. if (filename.isEmpty())
  445. return {};
  446. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  447. #if ! JUCE_WINDOWS
  448. if (filename.startsWith ("~"))
  449. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  450. #endif
  451. if (FileHelpers::isAbsolutePath (filename))
  452. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  453. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  454. }
  455. String Project::getRelativePathForFile (const File& file) const
  456. {
  457. auto filename = file.getFullPathName();
  458. auto relativePathBase = getFile().getParentDirectory();
  459. auto p1 = relativePathBase.getFullPathName();
  460. auto p2 = file.getFullPathName();
  461. while (p1.startsWithChar (File::getSeparatorChar()))
  462. p1 = p1.substring (1);
  463. while (p2.startsWithChar (File::getSeparatorChar()))
  464. p2 = p2.substring (1);
  465. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  466. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  467. {
  468. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  469. }
  470. return filename;
  471. }
  472. //==============================================================================
  473. const ProjectType& Project::getProjectType() const
  474. {
  475. if (auto* type = ProjectType::findType (getProjectTypeString()))
  476. return *type;
  477. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  478. jassert (guiType != nullptr);
  479. return *guiType;
  480. }
  481. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  482. {
  483. auto& projectType = getProjectType();
  484. if (! projectType.supportsTargetType (targetType))
  485. return false;
  486. switch (targetType)
  487. {
  488. case ProjectType::Target::VSTPlugIn:
  489. return shouldBuildVST();
  490. case ProjectType::Target::VST3PlugIn:
  491. return shouldBuildVST3();
  492. case ProjectType::Target::AAXPlugIn:
  493. return shouldBuildAAX();
  494. case ProjectType::Target::RTASPlugIn:
  495. return shouldBuildRTAS();
  496. case ProjectType::Target::AudioUnitPlugIn:
  497. return shouldBuildAU();
  498. case ProjectType::Target::AudioUnitv3PlugIn:
  499. return shouldBuildAUv3();
  500. case ProjectType::Target::StandalonePlugIn:
  501. return shouldBuildStandalonePlugin();
  502. case ProjectType::Target::AggregateTarget:
  503. case ProjectType::Target::SharedCodeTarget:
  504. return projectType.isAudioPlugin();
  505. case ProjectType::Target::unspecified:
  506. return false;
  507. default:
  508. break;
  509. }
  510. return true;
  511. }
  512. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  513. {
  514. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  515. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  516. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  517. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  518. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  519. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  520. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  521. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  522. }
  523. const char* ProjectType::Target::getName() const noexcept
  524. {
  525. switch (type)
  526. {
  527. case GUIApp: return "App";
  528. case ConsoleApp: return "ConsoleApp";
  529. case StaticLibrary: return "Static Library";
  530. case DynamicLibrary: return "Dynamic Library";
  531. case VSTPlugIn: return "VST";
  532. case VST3PlugIn: return "VST3";
  533. case AudioUnitPlugIn: return "AU";
  534. case StandalonePlugIn: return "Standalone Plugin";
  535. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  536. case AAXPlugIn: return "AAX";
  537. case RTASPlugIn: return "RTAS";
  538. case SharedCodeTarget: return "Shared Code";
  539. case AggregateTarget: return "All";
  540. default: return "undefined";
  541. }
  542. }
  543. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  544. {
  545. switch (type)
  546. {
  547. case GUIApp: return executable;
  548. case ConsoleApp: return executable;
  549. case StaticLibrary: return staticLibrary;
  550. case DynamicLibrary: return sharedLibraryOrDLL;
  551. case VSTPlugIn: return pluginBundle;
  552. case VST3PlugIn: return pluginBundle;
  553. case AudioUnitPlugIn: return pluginBundle;
  554. case StandalonePlugIn: return executable;
  555. case AudioUnitv3PlugIn: return macOSAppex;
  556. case AAXPlugIn: return pluginBundle;
  557. case RTASPlugIn: return pluginBundle;
  558. case SharedCodeTarget: return staticLibrary;
  559. default:
  560. break;
  561. }
  562. return unknown;
  563. }
  564. //==============================================================================
  565. void Project::createPropertyEditors (PropertyListBuilder& props)
  566. {
  567. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  568. "The name of the project.");
  569. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  570. "The project's version number, This should be in the format major.minor.point[.point]");
  571. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  572. "Your company name, which will be added to the properties of the binary where possible");
  573. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  574. "Your company copyright, which will be added to the properties of the binary where possible");
  575. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  576. "Your company website, which will be added to the properties of the binary where possible");
  577. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  578. "Your company e-mail, which will be added to the properties of the binary where possible");
  579. {
  580. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  581. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  582. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  583. "license, or are using JUCE under the GPL v3 license.");
  584. StringPairArray description;
  585. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  586. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  587. if (ProjucerApplication::getApp().isPaidOrGPL())
  588. {
  589. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  590. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  591. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  592. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  593. }
  594. else
  595. {
  596. StringArray options;
  597. Array<var> vars;
  598. options.add (licenseRequiredTagline);
  599. vars.add (var());
  600. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  601. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  602. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  603. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  604. }
  605. }
  606. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  607. { "Dark", "Light" },
  608. { "Dark", "Light" }),
  609. "Choose the colour of the JUCE splash screen.");
  610. {
  611. StringArray projectTypeNames;
  612. Array<var> projectTypeCodes;
  613. auto types = ProjectType::getAllTypes();
  614. for (int i = 0; i < types.size(); ++i)
  615. {
  616. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  617. projectTypeCodes.add (types.getUnchecked(i)->getType());
  618. }
  619. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  620. "The project type for which settings should be shown.");
  621. }
  622. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  623. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  624. if (getProjectType().isAudioPlugin())
  625. createAudioPluginPropertyEditors (props);
  626. {
  627. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  628. StringArray maxSizeNames;
  629. Array<var> maxSizeCodes;
  630. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  631. {
  632. auto sizeInBytes = maxSizes[i] * 1024;
  633. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  634. maxSizeCodes.add (sizeInBytes);
  635. }
  636. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  637. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  638. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  639. }
  640. props.add (new ChoicePropertyComponent (includeBinaryDataInAppConfigValue, "Include BinaryData in AppConfig"),
  641. "Include BinaryData.h in the AppConfig.h file");
  642. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  643. "The namespace containing the binary assests.");
  644. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  645. { "C++11", "C++14", "C++17", "Use Latest" },
  646. { "11", "14", "17", "latest" }),
  647. "The standard of the C++ language that will be used for compilation.");
  648. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  649. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  650. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  651. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  652. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  653. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  654. }
  655. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  656. {
  657. props.add (new ChoicePropertyComponent (buildVSTValue, "Build VST"),
  658. "Whether the project should produce a VST plugin.");
  659. props.add (new ChoicePropertyComponent (buildVST3Value, "Build VST3"),
  660. "Whether the project should produce a VST3 plugin.");
  661. props.add (new ChoicePropertyComponent (buildAUValue, "Build AudioUnit"),
  662. "Whether the project should produce an AudioUnit plugin.");
  663. props.add (new ChoicePropertyComponent (buildAUv3Value, "Build AudioUnit v3"),
  664. "Whether the project should produce an AudioUnit version 3 plugin.");
  665. props.add (new ChoicePropertyComponent (buildRTASValue, "Build RTAS"),
  666. "Whether the project should produce an RTAS plugin.");
  667. props.add (new ChoicePropertyComponent (buildAAXValue, "Build AAX"),
  668. "Whether the project should produce an AAX plugin.");
  669. props.add (new ChoicePropertyComponent (buildStandaloneValue, "Build Standalone Plug-In"),
  670. "Whether the project should produce a standalone version of your plugin.");
  671. props.add (new ChoicePropertyComponent (enableIAAValue, "Enable Inter-App Audio"),
  672. "Whether a standalone plug-in should be an Inter-App Audio app. You should also enable the audio "
  673. "background capability in the iOS exporter.");
  674. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  675. "The name of your plugin (keep it short!)");
  676. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  677. "A short description of your plugin.");
  678. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  679. "The name of your company (cannot be blank).");
  680. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  681. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  682. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  683. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  684. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  685. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  686. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  687. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  688. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  689. props.add (new ChoicePropertyComponent (pluginIsSynthValue, "Plugin is a Synth"),
  690. "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.");
  691. props.add (new ChoicePropertyComponent (pluginWantsMidiInputValue, "Plugin Midi Input"),
  692. "Enable this if you want your plugin to accept midi messages.");
  693. props.add (new ChoicePropertyComponent (pluginProducesMidiOutValue, "Plugin Midi Output"),
  694. "Enable this if your plugin is going to produce midi messages.");
  695. props.add (new ChoicePropertyComponent (pluginIsMidiEffectPluginValue, "Midi Effect Plugin"),
  696. "Enable this if your plugin only processes midi and no audio.");
  697. props.add (new ChoicePropertyComponent (pluginEditorNeedsKeyFocusValue, "Plugin Editor Requires Keyboard Focus"),
  698. "Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  699. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  700. "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.");
  701. props.add (new TextPropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", 128, false),
  702. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  703. props.add (new TextPropertyComponent (pluginVSTCategoryValue, "VST Category", 128, false),
  704. "In a VST, this is the value that is set as JucePlugin_VSTCategory. Leave it blank unless you want to use a custom value.");
  705. props.add (new TextPropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", 128, false),
  706. "(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, "
  707. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  708. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  709. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  710. props.add (new TextPropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", 128, false),
  711. "This is one of the categories from the AAX_EPlugInCategory enum");
  712. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  713. "The value to use for the JucePlugin_AAXIdentifier setting");
  714. }
  715. //==============================================================================
  716. static StringArray getVersionSegments (const Project& p)
  717. {
  718. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  719. segments.trim();
  720. segments.removeEmptyStrings();
  721. return segments;
  722. }
  723. int Project::getVersionAsHexInteger() const
  724. {
  725. auto segments = getVersionSegments (*this);
  726. auto value = (segments[0].getIntValue() << 16)
  727. + (segments[1].getIntValue() << 8)
  728. + segments[2].getIntValue();
  729. if (segments.size() >= 4)
  730. value = (value << 8) + segments[3].getIntValue();
  731. return value;
  732. }
  733. String Project::getVersionAsHex() const
  734. {
  735. return "0x" + String::toHexString (getVersionAsHexInteger());
  736. }
  737. File Project::getBinaryDataCppFile (int index) const
  738. {
  739. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  740. if (index > 0)
  741. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  742. .withFileExtension (cpp.getFileExtension());
  743. return cpp;
  744. }
  745. Project::Item Project::getMainGroup()
  746. {
  747. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  748. }
  749. PropertiesFile& Project::getStoredProperties() const
  750. {
  751. return getAppSettings().getProjectProperties (getProjectUIDString());
  752. }
  753. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  754. {
  755. if (item.isImageFile())
  756. {
  757. found.add (new Project::Item (item));
  758. }
  759. else if (item.isGroup())
  760. {
  761. for (int i = 0; i < item.getNumChildren(); ++i)
  762. findImages (item.getChild (i), found);
  763. }
  764. }
  765. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  766. {
  767. findImages (getMainGroup(), items);
  768. }
  769. //==============================================================================
  770. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  771. : project (p), state (s), belongsToModule (isModuleCode)
  772. {
  773. }
  774. Project::Item::Item (const Item& other)
  775. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  776. {
  777. }
  778. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  779. String Project::Item::getID() const { return state [Ids::ID]; }
  780. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  781. Drawable* Project::Item::loadAsImageFile() const
  782. {
  783. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  784. if (! mml.lockWasGained())
  785. return nullptr;
  786. return isValid() ? Drawable::createFromImageFile (getFile())
  787. : nullptr;
  788. }
  789. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  790. {
  791. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  792. group.setID (uid);
  793. group.initialiseMissingProperties();
  794. group.getNameValue() = name;
  795. return group;
  796. }
  797. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  798. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  799. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  800. bool Project::Item::isImageFile() const
  801. {
  802. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  803. || getFile().hasFileExtension ("svg"));
  804. }
  805. Project::Item Project::Item::findItemWithID (const String& targetId) const
  806. {
  807. if (state [Ids::ID] == targetId)
  808. return *this;
  809. if (isGroup())
  810. {
  811. for (auto i = getNumChildren(); --i >= 0;)
  812. {
  813. auto found = getChild(i).findItemWithID (targetId);
  814. if (found.isValid())
  815. return found;
  816. }
  817. }
  818. return Item (project, ValueTree(), false);
  819. }
  820. bool Project::Item::canContain (const Item& child) const
  821. {
  822. if (isFile())
  823. return false;
  824. if (isGroup())
  825. return child.isFile() || child.isGroup();
  826. jassertfalse;
  827. return false;
  828. }
  829. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  830. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  831. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  832. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  833. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  834. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  835. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  836. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  837. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  838. bool Project::Item::isModuleCode() const { return belongsToModule; }
  839. String Project::Item::getFilePath() const
  840. {
  841. if (isFile())
  842. return state [Ids::file].toString();
  843. return {};
  844. }
  845. File Project::Item::getFile() const
  846. {
  847. if (isFile())
  848. return project.resolveFilename (state [Ids::file].toString());
  849. return {};
  850. }
  851. void Project::Item::setFile (const File& file)
  852. {
  853. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  854. jassert (getFile() == file);
  855. }
  856. void Project::Item::setFile (const RelativePath& file)
  857. {
  858. jassert (isFile());
  859. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  860. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  861. }
  862. bool Project::Item::renameFile (const File& newFile)
  863. {
  864. auto oldFile = getFile();
  865. if (oldFile.moveFileTo (newFile)
  866. || (newFile.exists() && ! oldFile.exists()))
  867. {
  868. setFile (newFile);
  869. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  870. return true;
  871. }
  872. return false;
  873. }
  874. bool Project::Item::containsChildForFile (const RelativePath& file) const
  875. {
  876. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  877. }
  878. Project::Item Project::Item::findItemForFile (const File& file) const
  879. {
  880. if (getFile() == file)
  881. return *this;
  882. if (isGroup())
  883. {
  884. for (auto i = getNumChildren(); --i >= 0;)
  885. {
  886. auto found = getChild(i).findItemForFile (file);
  887. if (found.isValid())
  888. return found;
  889. }
  890. }
  891. return Item (project, ValueTree(), false);
  892. }
  893. File Project::Item::determineGroupFolder() const
  894. {
  895. jassert (isGroup());
  896. File f;
  897. for (int i = 0; i < getNumChildren(); ++i)
  898. {
  899. f = getChild(i).getFile();
  900. if (f.exists())
  901. return f.getParentDirectory();
  902. }
  903. auto parent = getParent();
  904. if (parent != *this)
  905. {
  906. f = parent.determineGroupFolder();
  907. if (f.getChildFile (getName()).isDirectory())
  908. f = f.getChildFile (getName());
  909. }
  910. else
  911. {
  912. f = project.getProjectFolder();
  913. if (f.getChildFile ("Source").isDirectory())
  914. f = f.getChildFile ("Source");
  915. }
  916. return f;
  917. }
  918. void Project::Item::initialiseMissingProperties()
  919. {
  920. if (! state.hasProperty (Ids::ID))
  921. setID (createAlphaNumericUID());
  922. if (isFile())
  923. {
  924. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  925. }
  926. else if (isGroup())
  927. {
  928. for (auto i = getNumChildren(); --i >= 0;)
  929. getChild(i).initialiseMissingProperties();
  930. }
  931. }
  932. Value Project::Item::getNameValue()
  933. {
  934. return state.getPropertyAsValue (Ids::name, getUndoManager());
  935. }
  936. String Project::Item::getName() const
  937. {
  938. return state [Ids::name];
  939. }
  940. void Project::Item::addChild (const Item& newChild, int insertIndex)
  941. {
  942. state.addChild (newChild.state, insertIndex, getUndoManager());
  943. }
  944. void Project::Item::removeItemFromProject()
  945. {
  946. state.getParent().removeChild (state, getUndoManager());
  947. }
  948. Project::Item Project::Item::getParent() const
  949. {
  950. if (isMainGroup() || ! isGroup())
  951. return *this;
  952. return { project, state.getParent(), belongsToModule };
  953. }
  954. struct ItemSorter
  955. {
  956. static int compareElements (const ValueTree& first, const ValueTree& second)
  957. {
  958. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  959. }
  960. };
  961. struct ItemSorterWithGroupsAtStart
  962. {
  963. static int compareElements (const ValueTree& first, const ValueTree& second)
  964. {
  965. auto firstIsGroup = first.hasType (Ids::GROUP);
  966. auto secondIsGroup = second.hasType (Ids::GROUP);
  967. if (firstIsGroup == secondIsGroup)
  968. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  969. return firstIsGroup ? -1 : 1;
  970. }
  971. };
  972. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  973. {
  974. if (keepGroupsAtStart)
  975. {
  976. ItemSorterWithGroupsAtStart sorter;
  977. state.sort (sorter, undoManager, true);
  978. }
  979. else
  980. {
  981. ItemSorter sorter;
  982. state.sort (sorter, undoManager, true);
  983. }
  984. }
  985. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  986. {
  987. if (state.getNumChildren() == 0)
  988. return false;
  989. if (state.getNumChildren() == 1)
  990. return true;
  991. auto stateCopy = state.createCopy();
  992. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  993. return stateCopy.isEquivalentTo (state);
  994. }
  995. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  996. {
  997. sortGroup (state, keepGroupsAtStart, getUndoManager());
  998. if (recursive)
  999. for (auto i = getNumChildren(); --i >= 0;)
  1000. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1001. }
  1002. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1003. {
  1004. for (auto i = state.getNumChildren(); --i >= 0;)
  1005. {
  1006. auto child = state.getChild (i);
  1007. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1008. return { project, child, belongsToModule };
  1009. }
  1010. return addNewSubGroup (name, -1);
  1011. }
  1012. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1013. {
  1014. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1015. int n = 0;
  1016. while (project.getMainGroup().findItemWithID (newID).isValid())
  1017. newID = createGUID (newID + String (++n));
  1018. auto group = createGroup (project, name, newID, belongsToModule);
  1019. jassert (canContain (group));
  1020. addChild (group, insertIndex);
  1021. return group;
  1022. }
  1023. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1024. {
  1025. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1026. return false;
  1027. if (file.isDirectory())
  1028. {
  1029. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1030. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1031. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1032. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1033. }
  1034. else if (file.existsAsFile())
  1035. {
  1036. if (! project.getMainGroup().findItemForFile (file).isValid())
  1037. addFileUnchecked (file, insertIndex, shouldCompile);
  1038. }
  1039. else
  1040. {
  1041. jassertfalse;
  1042. }
  1043. return true;
  1044. }
  1045. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1046. {
  1047. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1048. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1049. if (! addFileAtIndex (file, 0, shouldCompile))
  1050. return false;
  1051. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1052. sortAlphabetically (wasSortedGroupsFirst, false);
  1053. return true;
  1054. }
  1055. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1056. {
  1057. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1058. item.initialiseMissingProperties();
  1059. item.getNameValue() = file.getFileName();
  1060. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1061. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1062. if (canContain (item))
  1063. {
  1064. item.setFile (file);
  1065. addChild (item, insertIndex);
  1066. }
  1067. }
  1068. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1069. {
  1070. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1071. item.initialiseMissingProperties();
  1072. item.getNameValue() = file.getFileName();
  1073. item.getShouldCompileValue() = shouldCompile;
  1074. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1075. if (canContain (item))
  1076. {
  1077. item.setFile (file);
  1078. addChild (item, insertIndex);
  1079. return true;
  1080. }
  1081. return false;
  1082. }
  1083. Icon Project::Item::getIcon (bool isOpen) const
  1084. {
  1085. auto& icons = getIcons();
  1086. if (isFile())
  1087. {
  1088. if (isImageFile())
  1089. return Icon (icons.imageDoc, Colours::transparentBlack);
  1090. return { icons.file, Colours::transparentBlack };
  1091. }
  1092. if (isMainGroup())
  1093. return { icons.juceLogo, Colours::orange };
  1094. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1095. }
  1096. bool Project::Item::isIconCrossedOut() const
  1097. {
  1098. return isFile()
  1099. && ! (shouldBeCompiled()
  1100. || shouldBeAddedToBinaryResources()
  1101. || getFile().hasFileExtension (headerFileExtensions));
  1102. }
  1103. //==============================================================================
  1104. ValueTree Project::getConfigNode()
  1105. {
  1106. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1107. }
  1108. ValueWithDefault Project::getConfigFlag (const String& name)
  1109. {
  1110. auto configNode = getConfigNode();
  1111. return { configNode, name, getUndoManagerFor (configNode) };
  1112. }
  1113. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1114. {
  1115. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1116. if (configValue == "default")
  1117. return defaultIsEnabled;
  1118. return configValue;
  1119. }
  1120. //==============================================================================
  1121. String Project::getPluginRTASCategoryCode()
  1122. {
  1123. if (static_cast<bool> (isPluginSynth()))
  1124. return "ePlugInCategory_SWGenerators";
  1125. auto s = getPluginRTASCategoryString();
  1126. if (s.isEmpty())
  1127. s = "ePlugInCategory_None";
  1128. return s;
  1129. }
  1130. String Project::getAUMainTypeString()
  1131. {
  1132. auto s = getPluginAUMainTypeString();
  1133. if (s.isEmpty())
  1134. {
  1135. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  1136. // Use aumi instead.
  1137. if (isPluginMidiEffect()) s = "'aumi'";
  1138. else if (isPluginSynth()) s = "kAudioUnitType_MusicDevice";
  1139. else if (pluginWantsMidiInput()) s = "kAudioUnitType_MusicEffect";
  1140. else s = "kAudioUnitType_Effect";
  1141. }
  1142. return s;
  1143. }
  1144. String Project::getAUMainTypeCode()
  1145. {
  1146. auto s = getPluginAUMainTypeString();
  1147. if (s.isEmpty())
  1148. {
  1149. if (isPluginMidiEffect()) s = "aumi";
  1150. else if (isPluginSynth()) s = "aumu";
  1151. else if (pluginWantsMidiInput()) s = "aumf";
  1152. else s = "aufx";
  1153. }
  1154. return s;
  1155. }
  1156. String Project::getIAATypeCode()
  1157. {
  1158. String s;
  1159. if (pluginWantsMidiInput())
  1160. {
  1161. if (isPluginSynth())
  1162. s = "auri";
  1163. else
  1164. s = "aurm";
  1165. }
  1166. else
  1167. {
  1168. if (isPluginSynth())
  1169. s = "aurg";
  1170. else
  1171. s = "aurx";
  1172. }
  1173. return s;
  1174. }
  1175. String Project::getIAAPluginName()
  1176. {
  1177. auto s = getPluginManufacturerString();
  1178. s << ": ";
  1179. s << getPluginNameString();
  1180. return s;
  1181. }
  1182. String Project::getPluginVSTCategoryString()
  1183. {
  1184. auto s = pluginVSTCategoryValue.get().toString().trim();
  1185. if (s.isEmpty())
  1186. s = isPluginSynth() ? "kPlugCategSynth" : "kPlugCategEffect";
  1187. return s;
  1188. }
  1189. bool Project::isAUPluginHost()
  1190. {
  1191. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1192. }
  1193. bool Project::isVSTPluginHost()
  1194. {
  1195. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1196. }
  1197. bool Project::isVST3PluginHost()
  1198. {
  1199. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1200. }
  1201. //==============================================================================
  1202. EnabledModuleList& Project::getModules()
  1203. {
  1204. if (enabledModulesList == nullptr)
  1205. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  1206. return *enabledModulesList;
  1207. }
  1208. //==============================================================================
  1209. ValueTree Project::getExporters()
  1210. {
  1211. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1212. }
  1213. int Project::getNumExporters()
  1214. {
  1215. return getExporters().getNumChildren();
  1216. }
  1217. ProjectExporter* Project::createExporter (int index)
  1218. {
  1219. jassert (index >= 0 && index < getNumExporters());
  1220. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1221. }
  1222. void Project::addNewExporter (const String& exporterName)
  1223. {
  1224. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1225. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1226. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1227. auto exportersTree = getExporters();
  1228. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1229. }
  1230. void Project::createExporterForCurrentPlatform()
  1231. {
  1232. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1233. }
  1234. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1235. {
  1236. StringArray buildFolders;
  1237. auto exportersTree = getExporters();
  1238. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1239. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1240. {
  1241. auto exporterNode = exportersTree.getChild (i);
  1242. if (exporterNode.getType() == Identifier (type))
  1243. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1244. }
  1245. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1246. return {};
  1247. buildFolders.remove (buildFolders.indexOf (base));
  1248. int num = 1;
  1249. for (auto f : buildFolders)
  1250. {
  1251. if (! f.endsWith ("_" + String (num)))
  1252. break;
  1253. ++num;
  1254. }
  1255. return "_" + String (num);
  1256. }
  1257. //==============================================================================
  1258. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1259. {
  1260. if (! hasSentGUIBuilderAnalyticsEvent)
  1261. {
  1262. hasSentGUIBuilderAnalyticsEvent = true;
  1263. return true;
  1264. }
  1265. return false;
  1266. }
  1267. //==============================================================================
  1268. String Project::getFileTemplate (const String& templateName)
  1269. {
  1270. int dataSize;
  1271. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1272. return String::fromUTF8 (data, dataSize);
  1273. jassertfalse;
  1274. return {};
  1275. }
  1276. //==============================================================================
  1277. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1278. Project::ExporterIterator::~ExporterIterator() {}
  1279. bool Project::ExporterIterator::next()
  1280. {
  1281. if (++index >= project.getNumExporters())
  1282. return false;
  1283. exporter = project.createExporter (index);
  1284. if (exporter == nullptr)
  1285. {
  1286. jassertfalse; // corrupted project file?
  1287. return next();
  1288. }
  1289. return true;
  1290. }