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