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.

1570 lines
57KB

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