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.

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