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.

2070 lines
76KB

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