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.

1523 lines
55KB

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