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.

1510 lines
54KB

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