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.

1891 lines
69KB

  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 "../Application/jucer_Headers.h"
  20. #include "jucer_Project.h"
  21. #include "../ProjectSaving/jucer_ProjectSaver.h"
  22. #include "../Application/jucer_Application.h"
  23. namespace
  24. {
  25. String makeValid4CC (const String& seed)
  26. {
  27. auto s = CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx";
  28. return s.substring (0, 1).toUpperCase()
  29. + s.substring (1, 4).toLowerCase();
  30. }
  31. }
  32. //==============================================================================
  33. Project::Project (const File& f)
  34. : FileBasedDocument (projectFileExtension,
  35. String ("*") + projectFileExtension,
  36. "Choose a Jucer project to load",
  37. "Save Jucer project")
  38. {
  39. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  40. setFile (f);
  41. removeDefunctExporters();
  42. updateOldModulePaths();
  43. updateOldStyleConfigList();
  44. setCppVersionFromOldExporterSettings();
  45. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  46. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  47. initialiseProjectValues();
  48. initialiseMainGroup();
  49. initialiseAudioPluginValues();
  50. coalescePluginFormatValues();
  51. coalescePluginCharacteristicsValues();
  52. updatePluginCategories();
  53. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  54. getModules().sortAlphabetically();
  55. projectRoot.addListener (this);
  56. setChangedFlag (false);
  57. modificationTime = getFile().getLastModificationTime();
  58. }
  59. Project::~Project()
  60. {
  61. projectRoot.removeListener (this);
  62. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  63. }
  64. const char* Project::projectFileExtension = ".jucer";
  65. //==============================================================================
  66. void Project::setTitle (const String& newTitle)
  67. {
  68. projectNameValue = newTitle;
  69. updateTitle();
  70. }
  71. void Project::updateTitle()
  72. {
  73. getMainGroup().getNameValue() = getProjectNameString();
  74. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  75. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  76. }
  77. String Project::getDocumentTitle()
  78. {
  79. return getProjectNameString();
  80. }
  81. void Project::updateProjectSettings()
  82. {
  83. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  84. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  85. }
  86. bool Project::setCppVersionFromOldExporterSettings()
  87. {
  88. auto highestLanguageStandard = -1;
  89. for (Project::ExporterIterator exporter (*this); exporter.next();)
  90. {
  91. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  92. {
  93. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  94. {
  95. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  96. if (cppLanguageStandard != var())
  97. {
  98. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  99. if (versionNum > highestLanguageStandard)
  100. highestLanguageStandard = versionNum;
  101. }
  102. }
  103. }
  104. else
  105. {
  106. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  107. if (cppLanguageStandard != var())
  108. {
  109. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  110. {
  111. cppStandardValue = "latest";
  112. return true;
  113. }
  114. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  115. if (versionNum > highestLanguageStandard)
  116. highestLanguageStandard = versionNum;
  117. }
  118. }
  119. }
  120. if (highestLanguageStandard != -1 && highestLanguageStandard >= 11)
  121. {
  122. cppStandardValue = highestLanguageStandard;
  123. return true;
  124. }
  125. return false;
  126. }
  127. void Project::updateDeprecatedProjectSettingsInteractively()
  128. {
  129. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  130. for (Project::ExporterIterator exporter (*this); exporter.next();)
  131. exporter->updateDeprecatedProjectSettingsInteractively();
  132. }
  133. void Project::initialiseMainGroup()
  134. {
  135. // Create main file group if missing
  136. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  137. {
  138. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  139. projectRoot.addChild (mainGroup.state, 0, 0);
  140. }
  141. getMainGroup().initialiseMissingProperties();
  142. }
  143. void Project::initialiseProjectValues()
  144. {
  145. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  146. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  147. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), ProjectType_GUIApp::getTypeName());
  148. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  149. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  150. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  151. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  152. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager());
  153. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  154. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), ! ProjucerApplication::getApp().isPaidOrGPL());
  155. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  156. reportAppUsageValue.referTo (projectRoot, Ids::reportAppUsage, getUndoManager());
  157. if (ProjucerApplication::getApp().isPaidOrGPL())
  158. {
  159. reportAppUsageValue.setDefault (ProjucerApplication::getApp().licenseController->getState().applicationUsageDataState
  160. == LicenseState::ApplicationUsageData::enabled);
  161. }
  162. else
  163. {
  164. reportAppUsageValue.setDefault (true);
  165. }
  166. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "14");
  167. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  168. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  169. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  170. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  171. includeBinaryDataInAppConfigValue.referTo (projectRoot, Ids::includeBinaryInAppConfig, getUndoManager(), true);
  172. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  173. }
  174. void Project::initialiseAudioPluginValues()
  175. {
  176. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(), Array<var> (Ids::buildVST.toString(), Ids::buildAU.toString()), ",");
  177. pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array<var> (), ",");
  178. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  179. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  180. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), "yourcompany");
  181. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  182. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  183. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  184. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  185. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  186. CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  187. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager());
  188. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager(), getDefaultVSTCategories(), ",");
  189. pluginVST3CategoryValue.referTo (projectRoot, Ids::pluginVST3Category, getUndoManager(), getDefaultVST3Categories(), ",");
  190. pluginRTASCategoryValue.referTo (projectRoot, Ids::pluginRTASCategory, getUndoManager(), getDefaultRTASCategories(), ",");
  191. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), getDefaultAAXCategories(), ",");
  192. }
  193. void Project::updateOldStyleConfigList()
  194. {
  195. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  196. if (deprecatedConfigsList.isValid())
  197. {
  198. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  199. for (Project::ExporterIterator exporter (*this); exporter.next();)
  200. {
  201. if (exporter->getNumConfigurations() == 0)
  202. {
  203. auto newConfigs = deprecatedConfigsList.createCopy();
  204. if (! exporter->isXcode())
  205. {
  206. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  207. {
  208. auto config = newConfigs.getChild (j);
  209. config.removeProperty (Ids::osxSDK, nullptr);
  210. config.removeProperty (Ids::osxCompatibility, nullptr);
  211. config.removeProperty (Ids::osxArchitecture, nullptr);
  212. }
  213. }
  214. exporter->settings.addChild (newConfigs, 0, nullptr);
  215. }
  216. }
  217. }
  218. }
  219. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  220. {
  221. if (projectRoot.hasProperty (name))
  222. {
  223. for (Project::ExporterIterator exporter (*this); exporter.next();)
  224. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  225. projectRoot.removeProperty (name, nullptr);
  226. }
  227. }
  228. void Project::removeDefunctExporters()
  229. {
  230. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  231. StringPairArray oldExporters;
  232. oldExporters.set ("ANDROID", "Android Ant Exporter");
  233. oldExporters.set ("MSVC6", "MSVC6");
  234. oldExporters.set ("VS2010", "Visual Studio 2010");
  235. oldExporters.set ("VS2012", "Visual Studio 2012");
  236. for (auto& key : oldExporters.getAllKeys())
  237. {
  238. auto oldExporter = exporters.getChildWithName (key);
  239. if (oldExporter.isValid())
  240. {
  241. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  242. TRANS (oldExporters[key]),
  243. TRANS ("The " + oldExporters[key] + " Exporter is deprecated. The exporter will be removed from this project."));
  244. exporters.removeChild (oldExporter, nullptr);
  245. }
  246. }
  247. }
  248. void Project::updateOldModulePaths()
  249. {
  250. for (Project::ExporterIterator exporter (*this); exporter.next();)
  251. exporter->updateOldModulePaths();
  252. }
  253. Array<Identifier> Project::getLegacyPluginFormatIdentifiers() noexcept
  254. {
  255. static Array<Identifier> legacyPluginFormatIdentifiers { Ids::buildVST, Ids::buildVST3, Ids::buildAU, Ids::buildAUv3,
  256. Ids::buildRTAS, Ids::buildAAX, Ids::buildStandalone, Ids::enableIAA };
  257. return legacyPluginFormatIdentifiers;
  258. }
  259. Array<Identifier> Project::getLegacyPluginCharacteristicsIdentifiers() noexcept
  260. {
  261. static Array<Identifier> legacyPluginCharacteristicsIdentifiers { Ids::pluginIsSynth, Ids::pluginWantsMidiIn, Ids::pluginProducesMidiOut,
  262. Ids::pluginIsMidiEffectPlugin, Ids::pluginEditorRequiresKeys, Ids::pluginRTASDisableBypass,
  263. Ids::pluginRTASDisableMultiMono, Ids::pluginAAXDisableBypass, Ids::pluginAAXDisableMultiMono };
  264. return legacyPluginCharacteristicsIdentifiers;
  265. }
  266. void Project::coalescePluginFormatValues()
  267. {
  268. Array<var> formatsToBuild;
  269. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  270. {
  271. if (projectRoot.getProperty (formatIdentifier, false))
  272. formatsToBuild.add (formatIdentifier.toString());
  273. }
  274. if (formatsToBuild.size() > 0)
  275. {
  276. pluginFormatsValue = formatsToBuild;
  277. shouldWriteLegacyPluginFormatSettings = true;
  278. }
  279. }
  280. void Project::coalescePluginCharacteristicsValues()
  281. {
  282. Array<var> pluginCharacteristics;
  283. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  284. {
  285. if (projectRoot.getProperty (characteristicIdentifier, false))
  286. pluginCharacteristics.add (characteristicIdentifier.toString());
  287. }
  288. if (pluginCharacteristics.size() > 0)
  289. {
  290. pluginCharacteristicsValue = pluginCharacteristics;
  291. shouldWriteLegacyPluginCharacteristicsSettings = true;
  292. }
  293. }
  294. void Project::updatePluginCategories()
  295. {
  296. {
  297. auto aaxCategory = projectRoot.getProperty (Ids::pluginAAXCategory, {}).toString();
  298. if (aaxCategory.isNotEmpty())
  299. pluginAAXCategoryValue = Array<var> (getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf (aaxCategory)]);
  300. }
  301. {
  302. auto rtasCategory = projectRoot.getProperty (Ids::pluginRTASCategory, {}).toString();
  303. if (rtasCategory.isNotEmpty())
  304. pluginRTASCategoryValue = Array<var> (getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf (rtasCategory)]);
  305. }
  306. {
  307. auto vstCategory = projectRoot.getProperty (Ids::pluginVSTCategory, {}).toString();
  308. if (vstCategory.isNotEmpty() && getAllVSTCategoryStrings().contains (vstCategory))
  309. pluginVSTCategoryValue = Array<var> (vstCategory);
  310. }
  311. }
  312. void Project::writeLegacyPluginFormatSettings()
  313. {
  314. if (pluginFormatsValue.isUsingDefault())
  315. {
  316. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  317. projectRoot.removeProperty (formatIdentifier, nullptr);
  318. }
  319. else
  320. {
  321. auto formatVar = pluginFormatsValue.get();
  322. if (auto* arr = formatVar.getArray())
  323. {
  324. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  325. projectRoot.setProperty (formatIdentifier, arr->contains (formatIdentifier.toString()), nullptr);
  326. }
  327. }
  328. }
  329. void Project::writeLegacyPluginCharacteristicsSettings()
  330. {
  331. if (pluginFormatsValue.isUsingDefault())
  332. {
  333. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  334. projectRoot.removeProperty (characteristicIdentifier, nullptr);
  335. }
  336. else
  337. {
  338. auto characteristicsVar = pluginCharacteristicsValue.get();
  339. if (auto* arr = characteristicsVar.getArray())
  340. {
  341. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  342. projectRoot.setProperty (characteristicIdentifier, arr->contains (characteristicIdentifier.toString()), nullptr);
  343. }
  344. }
  345. }
  346. //==============================================================================
  347. static int getVersionElement (StringRef v, int index)
  348. {
  349. StringArray parts = StringArray::fromTokens (v, "., ", {});
  350. return parts [parts.size() - index - 1].getIntValue();
  351. }
  352. static int getJuceVersion (const String& v)
  353. {
  354. return getVersionElement (v, 2) * 100000
  355. + getVersionElement (v, 1) * 1000
  356. + getVersionElement (v, 0);
  357. }
  358. static int getBuiltJuceVersion()
  359. {
  360. return JUCE_MAJOR_VERSION * 100000
  361. + JUCE_MINOR_VERSION * 1000
  362. + JUCE_BUILDNUMBER;
  363. }
  364. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  365. {
  366. for (auto i = modules.size(); --i >= 0;)
  367. {
  368. auto* m = modules.getUnchecked(i);
  369. if (m->getID().startsWith ("juce_")
  370. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  371. return true;
  372. }
  373. return false;
  374. }
  375. void Project::warnAboutOldProjucerVersion()
  376. {
  377. ModuleList available;
  378. available.scanGlobalJuceModulePath();
  379. if (! isAnyModuleNewerThanProjucer (available.modules))
  380. available.scanGlobalUserModulePath();
  381. if (! isAnyModuleNewerThanProjucer (available.modules))
  382. available.scanProjectExporterModulePaths (*this);
  383. if (! isAnyModuleNewerThanProjucer (available.modules))
  384. return;
  385. // Projucer is out of date!
  386. if (ProjucerApplication::getApp().isRunningCommandLine)
  387. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  388. else
  389. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  390. "Projucer",
  391. "This version of the Projucer is out-of-date!"
  392. "\n\n"
  393. "Always make sure that you're running the very latest version, "
  394. "preferably compiled directly from the JUCE repository that you're working with!");
  395. }
  396. //==============================================================================
  397. static File lastDocumentOpened;
  398. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  399. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  400. static void registerRecentFile (const File& file)
  401. {
  402. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  403. getAppSettings().recentFiles.addFile (file);
  404. getAppSettings().flush();
  405. }
  406. static void forgetRecentFile (const File& file)
  407. {
  408. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  409. getAppSettings().recentFiles.removeFile (file);
  410. getAppSettings().flush();
  411. }
  412. //==============================================================================
  413. Result Project::loadDocument (const File& file)
  414. {
  415. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  416. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  417. return Result::fail ("Not a valid Jucer project!");
  418. auto newTree = ValueTree::fromXml (*xml);
  419. if (! newTree.hasType (Ids::JUCERPROJECT))
  420. return Result::fail ("The document contains errors and couldn't be parsed!");
  421. registerRecentFile (file);
  422. enabledModulesList.reset();
  423. projectRoot = newTree;
  424. initialiseProjectValues();
  425. initialiseMainGroup();
  426. initialiseAudioPluginValues();
  427. coalescePluginFormatValues();
  428. coalescePluginCharacteristicsValues();
  429. updatePluginCategories();
  430. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  431. removeDefunctExporters();
  432. updateOldModulePaths();
  433. setChangedFlag (false);
  434. if (! ProjucerApplication::getApp().isRunningCommandLine)
  435. warnAboutOldProjucerVersion();
  436. return Result::ok();
  437. }
  438. Result Project::saveDocument (const File& file)
  439. {
  440. return saveProject (file, false);
  441. }
  442. Result Project::saveProject (const File& file, bool isCommandLineApp)
  443. {
  444. if (isSaving)
  445. return Result::ok();
  446. if (isTemporaryProject())
  447. {
  448. askUserWhereToSaveProject();
  449. return Result::ok();
  450. }
  451. updateProjectSettings();
  452. if (! isCommandLineApp && ! isTemporaryProject())
  453. registerRecentFile (file);
  454. const ScopedValueSetter<bool> vs (isSaving, true, false);
  455. ProjectSaver saver (*this, file);
  456. return saver.save (! isCommandLineApp, shouldWaitAfterSaving, specifiedExporterToSave);
  457. }
  458. Result Project::saveResourcesOnly (const File& file)
  459. {
  460. ProjectSaver saver (*this, file);
  461. return saver.saveResourcesOnly();
  462. }
  463. //==============================================================================
  464. void Project::setTemporaryDirectory (const File& dir) noexcept
  465. {
  466. tempDirectory = dir;
  467. // remove this file from the recent documents list as it is a temporary project
  468. forgetRecentFile (getFile());
  469. }
  470. void Project::askUserWhereToSaveProject()
  471. {
  472. FileChooser fc ("Save Project");
  473. fc.browseForDirectory();
  474. if (fc.getResult().exists())
  475. moveTemporaryDirectory (fc.getResult());
  476. }
  477. void Project::moveTemporaryDirectory (const File& newParentDirectory)
  478. {
  479. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  480. auto oldJucerFileName = getFile().getFileName();
  481. saveProjectRootToFile();
  482. tempDirectory.copyDirectoryTo (newDirectory);
  483. tempDirectory.deleteRecursively();
  484. tempDirectory = File();
  485. // reload project from new location
  486. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  487. {
  488. Component::SafePointer<MainWindow> safeWindow (window);
  489. MessageManager::callAsync ([safeWindow, newDirectory, oldJucerFileName]
  490. {
  491. if (safeWindow != nullptr)
  492. safeWindow.getComponent()->moveProject (newDirectory.getChildFile (oldJucerFileName));
  493. });
  494. }
  495. }
  496. bool Project::saveProjectRootToFile()
  497. {
  498. ScopedPointer<XmlElement> xml (projectRoot.createXml());
  499. if (xml == nullptr)
  500. {
  501. jassertfalse;
  502. return false;
  503. }
  504. MemoryOutputStream mo;
  505. xml->writeToStream (mo, {});
  506. return FileHelpers::overwriteFileWithNewDataIfDifferent (getFile(), mo);
  507. }
  508. //==============================================================================
  509. static void sendProjectSettingAnalyticsEvent (StringRef label)
  510. {
  511. StringPairArray data;
  512. data.set ("label", label);
  513. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  514. }
  515. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  516. {
  517. if (tree.getRoot() == tree)
  518. {
  519. if (property == Ids::projectType)
  520. {
  521. sendChangeMessage();
  522. sendProjectSettingAnalyticsEvent ("Project Type = " + projectTypeValue.get().toString());
  523. }
  524. else if (property == Ids::name)
  525. {
  526. updateTitle();
  527. }
  528. else if (property == Ids::defines)
  529. {
  530. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  531. }
  532. else if (property == Ids::cppLanguageStandard)
  533. {
  534. sendProjectSettingAnalyticsEvent ("C++ Standard = " + cppStandardValue.get().toString());
  535. }
  536. else if (property == Ids::pluginFormats)
  537. {
  538. if (shouldWriteLegacyPluginFormatSettings)
  539. writeLegacyPluginFormatSettings();
  540. }
  541. else if (property == Ids::pluginCharacteristicsValue)
  542. {
  543. pluginVSTCategoryValue.setDefault (getDefaultVSTCategories());
  544. pluginVST3CategoryValue.setDefault (getDefaultVST3Categories());
  545. pluginRTASCategoryValue.setDefault (getDefaultRTASCategories());
  546. pluginAAXCategoryValue.setDefault (getDefaultAAXCategories());
  547. if (shouldWriteLegacyPluginCharacteristicsSettings)
  548. writeLegacyPluginCharacteristicsSettings();
  549. }
  550. changed();
  551. }
  552. }
  553. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  554. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  555. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  556. void Project::valueTreeParentChanged (ValueTree&) {}
  557. //==============================================================================
  558. bool Project::hasProjectBeenModified()
  559. {
  560. auto oldModificationTime = modificationTime;
  561. modificationTime = getFile().getLastModificationTime();
  562. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  563. }
  564. //==============================================================================
  565. File Project::resolveFilename (String filename) const
  566. {
  567. if (filename.isEmpty())
  568. return {};
  569. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  570. #if ! JUCE_WINDOWS
  571. if (filename.startsWith ("~"))
  572. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  573. #endif
  574. if (FileHelpers::isAbsolutePath (filename))
  575. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  576. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  577. }
  578. String Project::getRelativePathForFile (const File& file) const
  579. {
  580. auto filename = file.getFullPathName();
  581. auto relativePathBase = getFile().getParentDirectory();
  582. auto p1 = relativePathBase.getFullPathName();
  583. auto p2 = file.getFullPathName();
  584. while (p1.startsWithChar (File::getSeparatorChar()))
  585. p1 = p1.substring (1);
  586. while (p2.startsWithChar (File::getSeparatorChar()))
  587. p2 = p2.substring (1);
  588. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  589. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  590. {
  591. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  592. }
  593. return filename;
  594. }
  595. //==============================================================================
  596. const ProjectType& Project::getProjectType() const
  597. {
  598. if (auto* type = ProjectType::findType (getProjectTypeString()))
  599. return *type;
  600. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  601. jassert (guiType != nullptr);
  602. return *guiType;
  603. }
  604. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  605. {
  606. auto& projectType = getProjectType();
  607. if (! projectType.supportsTargetType (targetType))
  608. return false;
  609. switch (targetType)
  610. {
  611. case ProjectType::Target::VSTPlugIn:
  612. return shouldBuildVST();
  613. case ProjectType::Target::VST3PlugIn:
  614. return shouldBuildVST3();
  615. case ProjectType::Target::AAXPlugIn:
  616. return shouldBuildAAX();
  617. case ProjectType::Target::RTASPlugIn:
  618. return shouldBuildRTAS();
  619. case ProjectType::Target::AudioUnitPlugIn:
  620. return shouldBuildAU();
  621. case ProjectType::Target::AudioUnitv3PlugIn:
  622. return shouldBuildAUv3();
  623. case ProjectType::Target::StandalonePlugIn:
  624. return shouldBuildStandalonePlugin();
  625. case ProjectType::Target::AggregateTarget:
  626. case ProjectType::Target::SharedCodeTarget:
  627. return projectType.isAudioPlugin();
  628. case ProjectType::Target::unspecified:
  629. return false;
  630. default:
  631. break;
  632. }
  633. return true;
  634. }
  635. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  636. {
  637. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  638. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  639. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  640. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  641. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  642. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  643. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  644. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  645. }
  646. const char* ProjectType::Target::getName() const noexcept
  647. {
  648. switch (type)
  649. {
  650. case GUIApp: return "App";
  651. case ConsoleApp: return "ConsoleApp";
  652. case StaticLibrary: return "Static Library";
  653. case DynamicLibrary: return "Dynamic Library";
  654. case VSTPlugIn: return "VST";
  655. case VST3PlugIn: return "VST3";
  656. case AudioUnitPlugIn: return "AU";
  657. case StandalonePlugIn: return "Standalone Plugin";
  658. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  659. case AAXPlugIn: return "AAX";
  660. case RTASPlugIn: return "RTAS";
  661. case SharedCodeTarget: return "Shared Code";
  662. case AggregateTarget: return "All";
  663. default: return "undefined";
  664. }
  665. }
  666. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  667. {
  668. switch (type)
  669. {
  670. case GUIApp: return executable;
  671. case ConsoleApp: return executable;
  672. case StaticLibrary: return staticLibrary;
  673. case DynamicLibrary: return sharedLibraryOrDLL;
  674. case VSTPlugIn: return pluginBundle;
  675. case VST3PlugIn: return pluginBundle;
  676. case AudioUnitPlugIn: return pluginBundle;
  677. case StandalonePlugIn: return executable;
  678. case AudioUnitv3PlugIn: return macOSAppex;
  679. case AAXPlugIn: return pluginBundle;
  680. case RTASPlugIn: return pluginBundle;
  681. case SharedCodeTarget: return staticLibrary;
  682. default:
  683. break;
  684. }
  685. return unknown;
  686. }
  687. //==============================================================================
  688. void Project::createPropertyEditors (PropertyListBuilder& props)
  689. {
  690. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  691. "The name of the project.");
  692. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  693. "The project's version number, This should be in the format major.minor.point[.point]");
  694. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  695. "Your company name, which will be added to the properties of the binary where possible");
  696. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  697. "Your company copyright, which will be added to the properties of the binary where possible");
  698. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  699. "Your company website, which will be added to the properties of the binary where possible");
  700. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  701. "Your company e-mail, which will be added to the properties of the binary where possible");
  702. {
  703. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  704. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  705. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  706. "license, or are using JUCE under the GPL v3 license.");
  707. StringPairArray description;
  708. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  709. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  710. if (ProjucerApplication::getApp().isPaidOrGPL())
  711. {
  712. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  713. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  714. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  715. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  716. }
  717. else
  718. {
  719. StringArray options;
  720. Array<var> vars;
  721. options.add (licenseRequiredTagline);
  722. vars.add (var());
  723. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  724. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  725. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  726. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  727. }
  728. }
  729. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  730. { "Dark", "Light" },
  731. { "Dark", "Light" }),
  732. "Choose the colour of the JUCE splash screen.");
  733. {
  734. StringArray projectTypeNames;
  735. Array<var> projectTypeCodes;
  736. auto types = ProjectType::getAllTypes();
  737. for (int i = 0; i < types.size(); ++i)
  738. {
  739. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  740. projectTypeCodes.add (types.getUnchecked(i)->getType());
  741. }
  742. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  743. "The project type for which settings should be shown.");
  744. }
  745. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  746. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  747. if (getProjectType().isAudioPlugin())
  748. createAudioPluginPropertyEditors (props);
  749. {
  750. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  751. StringArray maxSizeNames;
  752. Array<var> maxSizeCodes;
  753. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  754. {
  755. auto sizeInBytes = maxSizes[i] * 1024;
  756. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  757. maxSizeCodes.add (sizeInBytes);
  758. }
  759. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  760. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  761. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  762. }
  763. props.add (new ChoicePropertyComponent (includeBinaryDataInAppConfigValue, "Include BinaryData in AppConfig"),
  764. "Include BinaryData.h in the AppConfig.h file");
  765. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  766. "The namespace containing the binary assests.");
  767. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  768. { "C++11", "C++14", "C++17", "Use Latest" },
  769. { "11", "14", "17", "latest" }),
  770. "The standard of the C++ language that will be used for compilation.");
  771. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  772. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  773. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  774. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  775. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  776. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  777. }
  778. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  779. {
  780. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats",
  781. { "VST", "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Enable IAA" },
  782. { Ids::buildVST.toString(), Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  783. Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::enableIAA.toString() }),
  784. "Plugin formats to build.");
  785. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  786. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  787. "Disable RTAS Bypass", "Disable AAX Bypass", "Disable RTAS Multi-Mono", "Disable AAX Multi-Mono" },
  788. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  789. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(), Ids::pluginRTASDisableBypass.toString(),
  790. Ids::pluginAAXDisableBypass.toString(), Ids::pluginRTASDisableMultiMono.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  791. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  792. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  793. "The name of your plugin (keep it short!)");
  794. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  795. "A short description of your plugin.");
  796. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  797. "The name of your company (cannot be blank).");
  798. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  799. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  800. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  801. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  802. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  803. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  804. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  805. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  806. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  807. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  808. "The value to use for the JucePlugin_AAXIdentifier setting");
  809. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  810. "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.");
  811. props.add (new TextPropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", 128, false),
  812. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  813. {
  814. Array<var> vstCategoryVars;
  815. for (auto s : getAllVSTCategoryStrings())
  816. vstCategoryVars.add (s);
  817. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  818. "VST category");
  819. }
  820. {
  821. Array<var> vst3CategoryVars;
  822. for (auto s : getAllVST3CategoryStrings())
  823. vst3CategoryVars.add (s);
  824. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  825. "VST3 category");
  826. }
  827. props.add (new MultiChoicePropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", getAllRTASCategoryStrings(), getAllRTASCategoryVars()),
  828. "RTAS category");
  829. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  830. "AAX category");
  831. }
  832. //==============================================================================
  833. static StringArray getVersionSegments (const Project& p)
  834. {
  835. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  836. segments.trim();
  837. segments.removeEmptyStrings();
  838. return segments;
  839. }
  840. int Project::getVersionAsHexInteger() const
  841. {
  842. auto segments = getVersionSegments (*this);
  843. auto value = (segments[0].getIntValue() << 16)
  844. + (segments[1].getIntValue() << 8)
  845. + segments[2].getIntValue();
  846. if (segments.size() >= 4)
  847. value = (value << 8) + segments[3].getIntValue();
  848. return value;
  849. }
  850. String Project::getVersionAsHex() const
  851. {
  852. return "0x" + String::toHexString (getVersionAsHexInteger());
  853. }
  854. File Project::getBinaryDataCppFile (int index) const
  855. {
  856. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  857. if (index > 0)
  858. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  859. .withFileExtension (cpp.getFileExtension());
  860. return cpp;
  861. }
  862. Project::Item Project::getMainGroup()
  863. {
  864. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  865. }
  866. PropertiesFile& Project::getStoredProperties() const
  867. {
  868. return getAppSettings().getProjectProperties (getProjectUIDString());
  869. }
  870. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  871. {
  872. if (item.isImageFile())
  873. {
  874. found.add (new Project::Item (item));
  875. }
  876. else if (item.isGroup())
  877. {
  878. for (int i = 0; i < item.getNumChildren(); ++i)
  879. findImages (item.getChild (i), found);
  880. }
  881. }
  882. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  883. {
  884. findImages (getMainGroup(), items);
  885. }
  886. //==============================================================================
  887. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  888. : project (p), state (s), belongsToModule (isModuleCode)
  889. {
  890. }
  891. Project::Item::Item (const Item& other)
  892. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  893. {
  894. }
  895. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  896. String Project::Item::getID() const { return state [Ids::ID]; }
  897. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  898. Drawable* Project::Item::loadAsImageFile() const
  899. {
  900. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  901. if (! mml.lockWasGained())
  902. return nullptr;
  903. return isValid() ? Drawable::createFromImageFile (getFile())
  904. : nullptr;
  905. }
  906. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  907. {
  908. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  909. group.setID (uid);
  910. group.initialiseMissingProperties();
  911. group.getNameValue() = name;
  912. return group;
  913. }
  914. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  915. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  916. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  917. bool Project::Item::isImageFile() const
  918. {
  919. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  920. || getFile().hasFileExtension ("svg"));
  921. }
  922. Project::Item Project::Item::findItemWithID (const String& targetId) const
  923. {
  924. if (state [Ids::ID] == targetId)
  925. return *this;
  926. if (isGroup())
  927. {
  928. for (auto i = getNumChildren(); --i >= 0;)
  929. {
  930. auto found = getChild(i).findItemWithID (targetId);
  931. if (found.isValid())
  932. return found;
  933. }
  934. }
  935. return Item (project, ValueTree(), false);
  936. }
  937. bool Project::Item::canContain (const Item& child) const
  938. {
  939. if (isFile())
  940. return false;
  941. if (isGroup())
  942. return child.isFile() || child.isGroup();
  943. jassertfalse;
  944. return false;
  945. }
  946. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  947. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  948. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  949. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  950. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  951. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  952. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  953. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  954. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  955. bool Project::Item::isModuleCode() const { return belongsToModule; }
  956. String Project::Item::getFilePath() const
  957. {
  958. if (isFile())
  959. return state [Ids::file].toString();
  960. return {};
  961. }
  962. File Project::Item::getFile() const
  963. {
  964. if (isFile())
  965. return project.resolveFilename (state [Ids::file].toString());
  966. return {};
  967. }
  968. void Project::Item::setFile (const File& file)
  969. {
  970. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  971. jassert (getFile() == file);
  972. }
  973. void Project::Item::setFile (const RelativePath& file)
  974. {
  975. jassert (isFile());
  976. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  977. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  978. }
  979. bool Project::Item::renameFile (const File& newFile)
  980. {
  981. auto oldFile = getFile();
  982. if (oldFile.moveFileTo (newFile)
  983. || (newFile.exists() && ! oldFile.exists()))
  984. {
  985. setFile (newFile);
  986. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  987. return true;
  988. }
  989. return false;
  990. }
  991. bool Project::Item::containsChildForFile (const RelativePath& file) const
  992. {
  993. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  994. }
  995. Project::Item Project::Item::findItemForFile (const File& file) const
  996. {
  997. if (getFile() == file)
  998. return *this;
  999. if (isGroup())
  1000. {
  1001. for (auto i = getNumChildren(); --i >= 0;)
  1002. {
  1003. auto found = getChild(i).findItemForFile (file);
  1004. if (found.isValid())
  1005. return found;
  1006. }
  1007. }
  1008. return Item (project, ValueTree(), false);
  1009. }
  1010. File Project::Item::determineGroupFolder() const
  1011. {
  1012. jassert (isGroup());
  1013. File f;
  1014. for (int i = 0; i < getNumChildren(); ++i)
  1015. {
  1016. f = getChild(i).getFile();
  1017. if (f.exists())
  1018. return f.getParentDirectory();
  1019. }
  1020. auto parent = getParent();
  1021. if (parent != *this)
  1022. {
  1023. f = parent.determineGroupFolder();
  1024. if (f.getChildFile (getName()).isDirectory())
  1025. f = f.getChildFile (getName());
  1026. }
  1027. else
  1028. {
  1029. f = project.getProjectFolder();
  1030. if (f.getChildFile ("Source").isDirectory())
  1031. f = f.getChildFile ("Source");
  1032. }
  1033. return f;
  1034. }
  1035. void Project::Item::initialiseMissingProperties()
  1036. {
  1037. if (! state.hasProperty (Ids::ID))
  1038. setID (createAlphaNumericUID());
  1039. if (isFile())
  1040. {
  1041. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1042. }
  1043. else if (isGroup())
  1044. {
  1045. for (auto i = getNumChildren(); --i >= 0;)
  1046. getChild(i).initialiseMissingProperties();
  1047. }
  1048. }
  1049. Value Project::Item::getNameValue()
  1050. {
  1051. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1052. }
  1053. String Project::Item::getName() const
  1054. {
  1055. return state [Ids::name];
  1056. }
  1057. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1058. {
  1059. state.addChild (newChild.state, insertIndex, getUndoManager());
  1060. }
  1061. void Project::Item::removeItemFromProject()
  1062. {
  1063. state.getParent().removeChild (state, getUndoManager());
  1064. }
  1065. Project::Item Project::Item::getParent() const
  1066. {
  1067. if (isMainGroup() || ! isGroup())
  1068. return *this;
  1069. return { project, state.getParent(), belongsToModule };
  1070. }
  1071. struct ItemSorter
  1072. {
  1073. static int compareElements (const ValueTree& first, const ValueTree& second)
  1074. {
  1075. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1076. }
  1077. };
  1078. struct ItemSorterWithGroupsAtStart
  1079. {
  1080. static int compareElements (const ValueTree& first, const ValueTree& second)
  1081. {
  1082. auto firstIsGroup = first.hasType (Ids::GROUP);
  1083. auto secondIsGroup = second.hasType (Ids::GROUP);
  1084. if (firstIsGroup == secondIsGroup)
  1085. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1086. return firstIsGroup ? -1 : 1;
  1087. }
  1088. };
  1089. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1090. {
  1091. if (keepGroupsAtStart)
  1092. {
  1093. ItemSorterWithGroupsAtStart sorter;
  1094. state.sort (sorter, undoManager, true);
  1095. }
  1096. else
  1097. {
  1098. ItemSorter sorter;
  1099. state.sort (sorter, undoManager, true);
  1100. }
  1101. }
  1102. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1103. {
  1104. if (state.getNumChildren() == 0)
  1105. return false;
  1106. if (state.getNumChildren() == 1)
  1107. return true;
  1108. auto stateCopy = state.createCopy();
  1109. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1110. return stateCopy.isEquivalentTo (state);
  1111. }
  1112. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1113. {
  1114. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1115. if (recursive)
  1116. for (auto i = getNumChildren(); --i >= 0;)
  1117. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1118. }
  1119. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1120. {
  1121. for (auto i = state.getNumChildren(); --i >= 0;)
  1122. {
  1123. auto child = state.getChild (i);
  1124. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1125. return { project, child, belongsToModule };
  1126. }
  1127. return addNewSubGroup (name, -1);
  1128. }
  1129. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1130. {
  1131. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1132. int n = 0;
  1133. while (project.getMainGroup().findItemWithID (newID).isValid())
  1134. newID = createGUID (newID + String (++n));
  1135. auto group = createGroup (project, name, newID, belongsToModule);
  1136. jassert (canContain (group));
  1137. addChild (group, insertIndex);
  1138. return group;
  1139. }
  1140. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1141. {
  1142. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1143. return false;
  1144. if (file.isDirectory())
  1145. {
  1146. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1147. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1148. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1149. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1150. }
  1151. else if (file.existsAsFile())
  1152. {
  1153. if (! project.getMainGroup().findItemForFile (file).isValid())
  1154. addFileUnchecked (file, insertIndex, shouldCompile);
  1155. }
  1156. else
  1157. {
  1158. jassertfalse;
  1159. }
  1160. return true;
  1161. }
  1162. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1163. {
  1164. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1165. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1166. if (! addFileAtIndex (file, 0, shouldCompile))
  1167. return false;
  1168. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1169. sortAlphabetically (wasSortedGroupsFirst, false);
  1170. return true;
  1171. }
  1172. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1173. {
  1174. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1175. item.initialiseMissingProperties();
  1176. item.getNameValue() = file.getFileName();
  1177. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1178. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1179. if (canContain (item))
  1180. {
  1181. item.setFile (file);
  1182. addChild (item, insertIndex);
  1183. }
  1184. }
  1185. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1186. {
  1187. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1188. item.initialiseMissingProperties();
  1189. item.getNameValue() = file.getFileName();
  1190. item.getShouldCompileValue() = shouldCompile;
  1191. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1192. if (canContain (item))
  1193. {
  1194. item.setFile (file);
  1195. addChild (item, insertIndex);
  1196. return true;
  1197. }
  1198. return false;
  1199. }
  1200. Icon Project::Item::getIcon (bool isOpen) const
  1201. {
  1202. auto& icons = getIcons();
  1203. if (isFile())
  1204. {
  1205. if (isImageFile())
  1206. return Icon (icons.imageDoc, Colours::transparentBlack);
  1207. return { icons.file, Colours::transparentBlack };
  1208. }
  1209. if (isMainGroup())
  1210. return { icons.juceLogo, Colours::orange };
  1211. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1212. }
  1213. bool Project::Item::isIconCrossedOut() const
  1214. {
  1215. return isFile()
  1216. && ! (shouldBeCompiled()
  1217. || shouldBeAddedToBinaryResources()
  1218. || getFile().hasFileExtension (headerFileExtensions));
  1219. }
  1220. //==============================================================================
  1221. ValueTree Project::getConfigNode()
  1222. {
  1223. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1224. }
  1225. ValueWithDefault Project::getConfigFlag (const String& name)
  1226. {
  1227. auto configNode = getConfigNode();
  1228. return { configNode, name, getUndoManagerFor (configNode) };
  1229. }
  1230. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1231. {
  1232. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1233. if (configValue == "default")
  1234. return defaultIsEnabled;
  1235. return configValue;
  1236. }
  1237. //==============================================================================
  1238. String Project::getVSTCategoryString() const noexcept
  1239. {
  1240. auto v = pluginVSTCategoryValue.get();
  1241. if (auto* arr = v.getArray())
  1242. return arr->getFirst().toString();
  1243. return {};
  1244. }
  1245. static String getVST3CategoryStringFromSelection (Array<var> selected) noexcept
  1246. {
  1247. StringArray categories;
  1248. for (auto& category : selected)
  1249. categories.add (category);
  1250. return categories.joinIntoString ("|");
  1251. }
  1252. String Project::getVST3CategoryString() const noexcept
  1253. {
  1254. auto v = pluginVST3CategoryValue.get();
  1255. if (auto* arr = v.getArray())
  1256. return getVST3CategoryStringFromSelection (*arr);
  1257. return {};
  1258. }
  1259. int Project::getAAXCategory() const noexcept
  1260. {
  1261. int res = 0;
  1262. auto v = pluginAAXCategoryValue.get();
  1263. if (auto* arr = v.getArray())
  1264. {
  1265. for (auto c : *arr)
  1266. res |= static_cast<int> (c);
  1267. }
  1268. return res;
  1269. }
  1270. int Project::getRTASCategory() const noexcept
  1271. {
  1272. int res = 0;
  1273. auto v = pluginRTASCategoryValue.get();
  1274. if (auto* arr = v.getArray())
  1275. {
  1276. for (auto c : *arr)
  1277. res |= static_cast<int> (c);
  1278. }
  1279. return res;
  1280. }
  1281. String Project::getAUMainTypeString()
  1282. {
  1283. auto s = getPluginAUMainTypeString();
  1284. if (s.isEmpty())
  1285. {
  1286. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  1287. // Use aumi instead.
  1288. if (isPluginMidiEffect()) s = "'aumi'";
  1289. else if (isPluginSynth()) s = "kAudioUnitType_MusicDevice";
  1290. else if (pluginWantsMidiInput()) s = "kAudioUnitType_MusicEffect";
  1291. else s = "kAudioUnitType_Effect";
  1292. }
  1293. return s;
  1294. }
  1295. String Project::getAUMainTypeCode()
  1296. {
  1297. auto s = getPluginAUMainTypeString();
  1298. if (s.isEmpty())
  1299. {
  1300. if (isPluginMidiEffect()) s = "aumi";
  1301. else if (isPluginSynth()) s = "aumu";
  1302. else if (pluginWantsMidiInput()) s = "aumf";
  1303. else s = "aufx";
  1304. }
  1305. return s;
  1306. }
  1307. String Project::getIAATypeCode()
  1308. {
  1309. String s;
  1310. if (pluginWantsMidiInput())
  1311. {
  1312. if (isPluginSynth())
  1313. s = "auri";
  1314. else
  1315. s = "aurm";
  1316. }
  1317. else
  1318. {
  1319. if (isPluginSynth())
  1320. s = "aurg";
  1321. else
  1322. s = "aurx";
  1323. }
  1324. return s;
  1325. }
  1326. String Project::getIAAPluginName()
  1327. {
  1328. auto s = getPluginManufacturerString();
  1329. s << ": ";
  1330. s << getPluginNameString();
  1331. return s;
  1332. }
  1333. //==============================================================================
  1334. bool Project::isAUPluginHost()
  1335. {
  1336. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1337. }
  1338. bool Project::isVSTPluginHost()
  1339. {
  1340. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1341. }
  1342. bool Project::isVST3PluginHost()
  1343. {
  1344. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1345. }
  1346. //==============================================================================
  1347. StringArray Project::getAllVSTCategoryStrings() noexcept
  1348. {
  1349. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1350. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1351. "kPlugCategShell", "kPlugCategGenerator" };
  1352. return vstCategoryStrings;
  1353. }
  1354. Array<var> Project::getDefaultVSTCategories() const noexcept
  1355. {
  1356. if (isPluginSynth())
  1357. return { "kPlugCategSynth" };
  1358. return { "kPlugCategEffect" };
  1359. }
  1360. StringArray Project::getAllVST3CategoryStrings() noexcept
  1361. {
  1362. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Spatial", "Analyzer", "Delay", "Distortion", "EQ", "Filter", "Generator", "Mastering",
  1363. "Modulation", "Pitch Shift", "Restoration", "Reverb", "Surround", "Tools", "Network", "Drum", "Sampler",
  1364. "Synth", "External", "OnlyRT", "OnlyOfflineProcess", "NoOfflineProcess", "Up-Downmix" };
  1365. return vst3CategoryStrings;
  1366. }
  1367. Array<var> Project::getDefaultVST3Categories() const noexcept
  1368. {
  1369. if (isPluginSynth())
  1370. return { "Instrument", "Synth" };
  1371. return { "Fx" };
  1372. }
  1373. StringArray Project::getAllAAXCategoryStrings() noexcept
  1374. {
  1375. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1376. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1377. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1378. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1379. return aaxCategoryStrings;
  1380. }
  1381. Array<var> Project::getAllAAXCategoryVars() noexcept
  1382. {
  1383. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1384. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1385. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1386. 0x00000800, 0x00001000, 0x00002000 };
  1387. return aaxCategoryVars;
  1388. }
  1389. Array<var> Project::getDefaultAAXCategories() const noexcept
  1390. {
  1391. if (isPluginSynth())
  1392. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1393. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1394. }
  1395. StringArray Project::getAllRTASCategoryStrings() noexcept
  1396. {
  1397. static StringArray rtasCategoryStrings { "ePlugInCategory_None", "ePlugInCategory_EQ", "ePlugInCategory_Dynamics", "ePlugInCategory_PitchShift",
  1398. "ePlugInCategory_Reverb", "ePlugInCategory_Delay", "ePlugInCategory_Modulation", "ePlugInCategory_Harmonic",
  1399. "ePlugInCategory_NoiseReduction", "ePlugInCategory_Dither", "ePlugInCategory_SoundField", "ePlugInCategory_HWGenerators",
  1400. "ePlugInCategory_SWGenerators", "ePlugInCategory_WrappedPlugin", "ePlugInCategory_Effect" };
  1401. return rtasCategoryStrings;
  1402. }
  1403. Array<var> Project::getAllRTASCategoryVars() noexcept
  1404. {
  1405. static Array<var> rtasCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1406. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1407. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1408. 0x00000800, 0x00001000, 0x00002000 };
  1409. return rtasCategoryVars;
  1410. }
  1411. Array<var> Project::getDefaultRTASCategories() const noexcept
  1412. {
  1413. if (isPluginSynth())
  1414. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_SWGenerators")];
  1415. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_None")];
  1416. }
  1417. //==============================================================================
  1418. EnabledModuleList& Project::getModules()
  1419. {
  1420. if (enabledModulesList == nullptr)
  1421. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  1422. return *enabledModulesList;
  1423. }
  1424. //==============================================================================
  1425. ValueTree Project::getExporters()
  1426. {
  1427. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1428. }
  1429. int Project::getNumExporters()
  1430. {
  1431. return getExporters().getNumChildren();
  1432. }
  1433. ProjectExporter* Project::createExporter (int index)
  1434. {
  1435. jassert (index >= 0 && index < getNumExporters());
  1436. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1437. }
  1438. void Project::addNewExporter (const String& exporterName)
  1439. {
  1440. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1441. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1442. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1443. auto exportersTree = getExporters();
  1444. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1445. }
  1446. void Project::createExporterForCurrentPlatform()
  1447. {
  1448. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1449. }
  1450. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1451. {
  1452. StringArray buildFolders;
  1453. auto exportersTree = getExporters();
  1454. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1455. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1456. {
  1457. auto exporterNode = exportersTree.getChild (i);
  1458. if (exporterNode.getType() == Identifier (type))
  1459. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1460. }
  1461. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1462. return {};
  1463. buildFolders.remove (buildFolders.indexOf (base));
  1464. int num = 1;
  1465. for (auto f : buildFolders)
  1466. {
  1467. if (! f.endsWith ("_" + String (num)))
  1468. break;
  1469. ++num;
  1470. }
  1471. return "_" + String (num);
  1472. }
  1473. //==============================================================================
  1474. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1475. {
  1476. if (! hasSentGUIBuilderAnalyticsEvent)
  1477. {
  1478. hasSentGUIBuilderAnalyticsEvent = true;
  1479. return true;
  1480. }
  1481. return false;
  1482. }
  1483. //==============================================================================
  1484. String Project::getFileTemplate (const String& templateName)
  1485. {
  1486. int dataSize;
  1487. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1488. return String::fromUTF8 (data, dataSize);
  1489. jassertfalse;
  1490. return {};
  1491. }
  1492. //==============================================================================
  1493. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1494. Project::ExporterIterator::~ExporterIterator() {}
  1495. bool Project::ExporterIterator::next()
  1496. {
  1497. if (++index >= project.getNumExporters())
  1498. return false;
  1499. exporter = project.createExporter (index);
  1500. if (exporter == nullptr)
  1501. {
  1502. jassertfalse; // corrupted project file?
  1503. return next();
  1504. }
  1505. return true;
  1506. }