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.

2106 lines
77KB

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