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.

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