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.

2131 lines
78KB

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