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.

1459 lines
53KB

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