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.

1995 lines
74KB

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