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.

2870 lines
108KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. #include "../Application/jucer_Headers.h"
  19. #include "jucer_Project.h"
  20. #include "../ProjectSaving/jucer_ProjectSaver.h"
  21. #include "../Application/jucer_Application.h"
  22. //==============================================================================
  23. Project::ProjectFileModificationPoller::ProjectFileModificationPoller (Project& p)
  24. : project (p)
  25. {
  26. startTimer (250);
  27. }
  28. void Project::ProjectFileModificationPoller::reset()
  29. {
  30. project.removeProjectMessage (ProjectMessages::Ids::jucerFileModified);
  31. pending = false;
  32. startTimer (250);
  33. }
  34. void Project::ProjectFileModificationPoller::timerCallback()
  35. {
  36. if (project.updateCachedFileState() && ! pending)
  37. {
  38. project.addProjectMessage (ProjectMessages::Ids::jucerFileModified,
  39. { { "Save current state", [this] { resaveProject(); } },
  40. { "Re-load from disk", [this] { reloadProjectFromDisk(); } },
  41. { "Ignore", [this] { reset(); } } });
  42. stopTimer();
  43. pending = true;
  44. }
  45. }
  46. void Project::ProjectFileModificationPoller::reloadProjectFromDisk()
  47. {
  48. auto oldTemporaryDirectory = project.getTemporaryDirectory();
  49. auto projectFile = project.getFile();
  50. MessageManager::callAsync ([oldTemporaryDirectory, projectFile]
  51. {
  52. if (auto* mw = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (projectFile))
  53. {
  54. Component::SafePointer<MainWindow> parent { mw };
  55. mw->closeCurrentProject (OpenDocumentManager::SaveIfNeeded::no, [parent, oldTemporaryDirectory, projectFile] (bool)
  56. {
  57. if (parent == nullptr)
  58. return;
  59. parent->openFile (projectFile, [parent, oldTemporaryDirectory] (bool openedSuccessfully)
  60. {
  61. if (parent == nullptr)
  62. return;
  63. if (openedSuccessfully && oldTemporaryDirectory != File())
  64. if (auto* newProject = parent->getProject())
  65. newProject->setTemporaryDirectory (oldTemporaryDirectory);
  66. });
  67. });
  68. }
  69. });
  70. }
  71. void Project::ProjectFileModificationPoller::resaveProject()
  72. {
  73. reset();
  74. project.saveProject (Async::yes, nullptr, nullptr);
  75. }
  76. //==============================================================================
  77. Project::Project (const File& f)
  78. : FileBasedDocument (projectFileExtension,
  79. String ("*") + projectFileExtension,
  80. "Choose a Jucer project to load",
  81. "Save Jucer project")
  82. {
  83. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  84. setFile (f);
  85. createEnabledModulesList();
  86. initialiseProjectValues();
  87. initialiseMainGroup();
  88. initialiseAudioPluginValues();
  89. setChangedFlag (false);
  90. updateCachedFileState();
  91. auto& app = ProjucerApplication::getApp();
  92. if (! app.isRunningCommandLine)
  93. app.getLicenseController().addListener (this);
  94. app.getJUCEPathModulesList().addListener (this);
  95. app.getUserPathsModulesList().addListener (this);
  96. updateJUCEPathWarning();
  97. getGlobalProperties().addChangeListener (this);
  98. if (! app.isRunningCommandLine && app.isAutomaticVersionCheckingEnabled())
  99. LatestVersionCheckerAndUpdater::getInstance()->checkForNewVersion (true);
  100. }
  101. Project::~Project()
  102. {
  103. projectRoot.removeListener (this);
  104. getGlobalProperties().removeChangeListener (this);
  105. auto& app = ProjucerApplication::getApp();
  106. app.openDocumentManager.closeAllDocumentsUsingProjectWithoutSaving (*this);
  107. if (! app.isRunningCommandLine)
  108. app.getLicenseController().removeListener (this);
  109. app.getJUCEPathModulesList().removeListener (this);
  110. app.getUserPathsModulesList().removeListener (this);
  111. }
  112. const char* Project::projectFileExtension = ".jucer";
  113. //==============================================================================
  114. void Project::setTitle (const String& newTitle)
  115. {
  116. projectNameValue = newTitle;
  117. updateTitleDependencies();
  118. }
  119. void Project::updateTitleDependencies()
  120. {
  121. auto projectName = getProjectNameString();
  122. getMainGroup().getNameValue() = projectName;
  123. pluginNameValue. setDefault (projectName);
  124. pluginDescriptionValue. setDefault (projectName);
  125. bundleIdentifierValue. setDefault (getDefaultBundleIdentifierString());
  126. pluginAUExportPrefixValue.setDefault (build_tools::makeValidIdentifier (projectName, false, true, false) + "AU");
  127. pluginAAXIdentifierValue. setDefault (getDefaultAAXIdentifierString());
  128. pluginLV2URIValue. setDefault (getDefaultLV2URI());
  129. pluginARAFactoryIDValue. setDefault (getDefaultARAFactoryIDString());
  130. pluginARAArchiveIDValue. setDefault (getDefaultARADocumentArchiveID());
  131. pluginARACompatibleArchiveIDsValue.setDefault (getDefaultARACompatibleArchiveIDs());
  132. }
  133. String Project::getDocumentTitle()
  134. {
  135. return getProjectNameString();
  136. }
  137. void Project::updateCompanyNameDependencies()
  138. {
  139. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  140. companyWebsiteValue.setDefault (getDefaultCompanyWebsiteString());
  141. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  142. pluginARAFactoryIDValue.setDefault (getDefaultARAFactoryIDString());
  143. pluginARAArchiveIDValue.setDefault (getDefaultARADocumentArchiveID());
  144. pluginManufacturerValue.setDefault (getDefaultPluginManufacturerString());
  145. updateLicenseWarning();
  146. }
  147. void Project::updateWebsiteDependencies()
  148. {
  149. pluginLV2URIValue.setDefault (getDefaultLV2URI());
  150. }
  151. void Project::updateProjectSettings()
  152. {
  153. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  154. }
  155. bool Project::setCppVersionFromOldExporterSettings()
  156. {
  157. auto highestLanguageStandard = -1;
  158. for (ExporterIterator exporter (*this); exporter.next();)
  159. {
  160. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  161. {
  162. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  163. {
  164. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  165. if (cppLanguageStandard != var())
  166. {
  167. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  168. if (versionNum > highestLanguageStandard)
  169. highestLanguageStandard = versionNum;
  170. }
  171. }
  172. }
  173. else
  174. {
  175. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  176. if (cppLanguageStandard != var())
  177. {
  178. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  179. {
  180. cppStandardValue = Project::getCppStandardVars().getLast();
  181. return true;
  182. }
  183. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  184. if (versionNum > highestLanguageStandard)
  185. highestLanguageStandard = versionNum;
  186. }
  187. }
  188. }
  189. if (highestLanguageStandard >= 17)
  190. {
  191. cppStandardValue = highestLanguageStandard;
  192. return true;
  193. }
  194. return false;
  195. }
  196. void Project::updateDeprecatedProjectSettings()
  197. {
  198. for (const auto& version : { "11", "14" })
  199. {
  200. if (cppStandardValue.get().toString() == version)
  201. {
  202. cppStandardValue.resetToDefault();
  203. break;
  204. }
  205. }
  206. for (ExporterIterator exporter (*this); exporter.next();)
  207. exporter->updateDeprecatedSettings();
  208. }
  209. void Project::updateDeprecatedProjectSettingsInteractively()
  210. {
  211. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  212. for (ExporterIterator exporter (*this); exporter.next();)
  213. exporter->updateDeprecatedSettingsInteractively();
  214. }
  215. void Project::initialiseMainGroup()
  216. {
  217. // Create main file group if missing
  218. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  219. {
  220. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  221. projectRoot.addChild (mainGroup.state, 0, nullptr);
  222. }
  223. getMainGroup().initialiseMissingProperties();
  224. }
  225. void Project::initialiseProjectValues()
  226. {
  227. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  228. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  229. if (projectUIDValue.isUsingDefault())
  230. projectUIDValue = projectUIDValue.getDefault();
  231. projectLineFeedValue.referTo (projectRoot, Ids::projectLineFeed, getUndoManager(), "\r\n");
  232. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  233. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  234. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager(), getDefaultCompanyWebsiteString());
  235. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  236. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), build_tools::ProjectType_GUIApp::getTypeName());
  237. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  238. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  239. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), false);
  240. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  241. useAppConfigValue.referTo (projectRoot, Ids::useAppConfig, getUndoManager(), true);
  242. addUsingNamespaceToJuceHeader.referTo (projectRoot, Ids::addUsingNamespaceToJuceHeader, getUndoManager(), true);
  243. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "17");
  244. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  245. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  246. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  247. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  248. // this is here for backwards compatibility with old projects using the incorrect id
  249. if (projectRoot.hasProperty ("includeBinaryInAppConfig"))
  250. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, "includeBinaryInAppConfig", getUndoManager(), true);
  251. else
  252. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, Ids::includeBinaryInJuceHeader, getUndoManager(), true);
  253. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  254. compilerFlagSchemesValue.referTo (projectRoot, Ids::compilerFlagSchemes, getUndoManager(), Array<var>(), ",");
  255. postExportShellCommandPosixValue.referTo (projectRoot, Ids::postExportShellCommandPosix, getUndoManager());
  256. postExportShellCommandWinValue.referTo (projectRoot, Ids::postExportShellCommandWin, getUndoManager());
  257. }
  258. void Project::initialiseAudioPluginValues()
  259. {
  260. auto makeValid4CC = [] (const String& seed)
  261. {
  262. auto s = build_tools::makeValidIdentifier (seed, false, true, false) + "xxxx";
  263. return s.substring (0, 1).toUpperCase()
  264. + s.substring (1, 4).toLowerCase();
  265. };
  266. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(),
  267. Array<var> (Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()), ",");
  268. pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array<var>(), ",");
  269. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  270. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  271. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), getDefaultPluginManufacturerString());
  272. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  273. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  274. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  275. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  276. pluginARAFactoryIDValue.referTo (projectRoot, Ids::araFactoryID, getUndoManager(), getDefaultARAFactoryIDString());
  277. pluginARAArchiveIDValue.referTo (projectRoot, Ids::araDocumentArchiveID, getUndoManager(), getDefaultARADocumentArchiveID());
  278. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  279. build_tools::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  280. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager(), getDefaultAUMainTypes(), ",");
  281. pluginAUSandboxSafeValue.referTo (projectRoot, Ids::pluginAUIsSandboxSafe, getUndoManager(), false);
  282. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager(), getDefaultVSTCategories(), ",");
  283. pluginVST3CategoryValue.referTo (projectRoot, Ids::pluginVST3Category, getUndoManager(), getDefaultVST3Categories(), ",");
  284. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), getDefaultAAXCategories(), ",");
  285. pluginEnableARA.referTo (projectRoot, Ids::enableARA, getUndoManager(), shouldEnableARA(), ",");
  286. pluginARAAnalyzableContentValue.referTo (projectRoot, Ids::pluginARAAnalyzableContent, getUndoManager(), getDefaultARAContentTypes(), ",");
  287. pluginARATransformFlagsValue.referTo (projectRoot, Ids::pluginARATransformFlags, getUndoManager(), getDefaultARATransformationFlags(), ",");
  288. pluginARACompatibleArchiveIDsValue.referTo (projectRoot, Ids::araCompatibleArchiveIDs, getUndoManager(), getDefaultARACompatibleArchiveIDs());
  289. pluginVSTNumMidiInputsValue.referTo (projectRoot, Ids::pluginVSTNumMidiInputs, getUndoManager(), 16);
  290. pluginVSTNumMidiOutputsValue.referTo (projectRoot, Ids::pluginVSTNumMidiOutputs, getUndoManager(), 16);
  291. pluginLV2URIValue.referTo (projectRoot, Ids::lv2Uri, getUndoManager(), getDefaultLV2URI());
  292. }
  293. void Project::updateOldStyleConfigList()
  294. {
  295. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  296. if (deprecatedConfigsList.isValid())
  297. {
  298. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  299. for (ExporterIterator exporter (*this); exporter.next();)
  300. {
  301. if (exporter->getNumConfigurations() == 0)
  302. {
  303. auto newConfigs = deprecatedConfigsList.createCopy();
  304. if (! exporter->isXcode())
  305. {
  306. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  307. {
  308. auto config = newConfigs.getChild (j);
  309. config.removeProperty (Ids::osxSDK, nullptr);
  310. config.removeProperty (Ids::osxCompatibility, nullptr);
  311. config.removeProperty (Ids::osxArchitecture, nullptr);
  312. }
  313. }
  314. exporter->settings.addChild (newConfigs, 0, nullptr);
  315. }
  316. }
  317. }
  318. }
  319. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  320. {
  321. if (projectRoot.hasProperty (name))
  322. {
  323. for (ExporterIterator exporter (*this); exporter.next();)
  324. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  325. projectRoot.removeProperty (name, nullptr);
  326. }
  327. }
  328. void Project::removeDefunctExporters()
  329. {
  330. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  331. StringPairArray oldExporters;
  332. oldExporters.set ("ANDROID", "Android Ant Exporter");
  333. oldExporters.set ("MSVC6", "MSVC6");
  334. oldExporters.set ("VS2010", "Visual Studio 2010");
  335. oldExporters.set ("VS2012", "Visual Studio 2012");
  336. oldExporters.set ("VS2013", "Visual Studio 2013");
  337. oldExporters.set ("VS2015", "Visual Studio 2015");
  338. oldExporters.set ("CLION", "CLion");
  339. std::vector<String> removedExporterKeys;
  340. for (auto& key : oldExporters.getAllKeys())
  341. {
  342. auto oldExporter = exporters.getChildWithName (key);
  343. if (oldExporter.isValid())
  344. {
  345. removedExporterKeys.push_back (key);
  346. exporters.removeChild (oldExporter, nullptr);
  347. }
  348. }
  349. if (! removedExporterKeys.empty())
  350. {
  351. if (ProjucerApplication::getApp().isRunningCommandLine)
  352. {
  353. for (const auto& key : removedExporterKeys)
  354. std::cout << "WARNING! The " + oldExporters[key]
  355. + " Exporter is deprecated. The exporter will be removed from this project."
  356. << std::endl;
  357. }
  358. else
  359. {
  360. const String warningTitle { TRANS ("Unsupported exporters") };
  361. String warningMessage;
  362. warningMessage << TRANS ("The following exporters are no longer supported") << "\n\n";
  363. for (const auto& key : removedExporterKeys)
  364. warningMessage << " - " + oldExporters[key] + "\n";
  365. warningMessage << "\n"
  366. << TRANS ("These exporters have been removed from the project. If you save the project they will be also erased from the .jucer file.");
  367. auto options = MessageBoxOptions::makeOptionsOk (MessageBoxIconType::WarningIcon, warningTitle, warningMessage);
  368. messageBox = AlertWindow::showScopedAsync (options, nullptr);
  369. }
  370. }
  371. }
  372. void Project::updateOldModulePaths()
  373. {
  374. for (ExporterIterator exporter (*this); exporter.next();)
  375. exporter->updateOldModulePaths();
  376. }
  377. Array<Identifier> Project::getLegacyPluginFormatIdentifiers() noexcept
  378. {
  379. static Array<Identifier> legacyPluginFormatIdentifiers { Ids::buildVST, Ids::buildVST3, Ids::buildAU, Ids::buildAUv3,
  380. Ids::buildAAX, Ids::buildStandalone, Ids::enableIAA };
  381. return legacyPluginFormatIdentifiers;
  382. }
  383. Array<Identifier> Project::getLegacyPluginCharacteristicsIdentifiers() noexcept
  384. {
  385. static Array<Identifier> legacyPluginCharacteristicsIdentifiers { Ids::pluginIsSynth, Ids::pluginWantsMidiIn, Ids::pluginProducesMidiOut,
  386. Ids::pluginIsMidiEffectPlugin, Ids::pluginEditorRequiresKeys,
  387. Ids::pluginAAXDisableBypass, Ids::pluginAAXDisableMultiMono };
  388. return legacyPluginCharacteristicsIdentifiers;
  389. }
  390. void Project::coalescePluginFormatValues()
  391. {
  392. Array<var> formatsToBuild;
  393. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  394. {
  395. if (projectRoot.getProperty (formatIdentifier, false))
  396. formatsToBuild.add (formatIdentifier.toString());
  397. }
  398. if (formatsToBuild.size() > 0)
  399. {
  400. if (pluginFormatsValue.isUsingDefault())
  401. {
  402. pluginFormatsValue = formatsToBuild;
  403. }
  404. else
  405. {
  406. auto formatVar = pluginFormatsValue.get();
  407. if (auto* arr = formatVar.getArray())
  408. arr->addArray (formatsToBuild);
  409. }
  410. shouldWriteLegacyPluginFormatSettings = true;
  411. }
  412. }
  413. void Project::coalescePluginCharacteristicsValues()
  414. {
  415. Array<var> pluginCharacteristics;
  416. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  417. {
  418. if (projectRoot.getProperty (characteristicIdentifier, false))
  419. pluginCharacteristics.add (characteristicIdentifier.toString());
  420. }
  421. if (pluginCharacteristics.size() > 0)
  422. {
  423. pluginCharacteristicsValue = pluginCharacteristics;
  424. shouldWriteLegacyPluginCharacteristicsSettings = true;
  425. }
  426. }
  427. void Project::updatePluginCategories()
  428. {
  429. {
  430. auto aaxCategory = projectRoot.getProperty (Ids::pluginAAXCategory, {}).toString();
  431. if (getAllAAXCategoryVars().contains (aaxCategory))
  432. pluginAAXCategoryValue = aaxCategory;
  433. else if (getAllAAXCategoryStrings().contains (aaxCategory))
  434. pluginAAXCategoryValue = Array<var> (getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf (aaxCategory)]);
  435. }
  436. {
  437. auto vstCategory = projectRoot.getProperty (Ids::pluginVSTCategory, {}).toString();
  438. if (vstCategory.isNotEmpty() && getAllVSTCategoryStrings().contains (vstCategory))
  439. pluginVSTCategoryValue = Array<var> (vstCategory);
  440. else
  441. pluginVSTCategoryValue.resetToDefault();
  442. }
  443. {
  444. auto auMainType = projectRoot.getProperty (Ids::pluginAUMainType, {}).toString();
  445. if (auMainType.isNotEmpty())
  446. {
  447. if (getAllAUMainTypeVars().contains (auMainType))
  448. pluginAUMainTypeValue = Array<var> (auMainType);
  449. else if (getAllAUMainTypeVars().contains (auMainType.quoted ('\'')))
  450. pluginAUMainTypeValue = Array<var> (auMainType.quoted ('\''));
  451. else if (getAllAUMainTypeStrings().contains (auMainType))
  452. pluginAUMainTypeValue = Array<var> (getAllAUMainTypeVars()[getAllAUMainTypeStrings().indexOf (auMainType)]);
  453. }
  454. else
  455. {
  456. pluginAUMainTypeValue.resetToDefault();
  457. }
  458. }
  459. }
  460. void Project::writeLegacyPluginFormatSettings()
  461. {
  462. if (pluginFormatsValue.isUsingDefault())
  463. {
  464. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  465. projectRoot.removeProperty (formatIdentifier, nullptr);
  466. }
  467. else
  468. {
  469. auto formatVar = pluginFormatsValue.get();
  470. if (auto* arr = formatVar.getArray())
  471. {
  472. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  473. projectRoot.setProperty (formatIdentifier, arr->contains (formatIdentifier.toString()), nullptr);
  474. }
  475. }
  476. }
  477. void Project::writeLegacyPluginCharacteristicsSettings()
  478. {
  479. if (pluginFormatsValue.isUsingDefault())
  480. {
  481. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  482. projectRoot.removeProperty (characteristicIdentifier, nullptr);
  483. }
  484. else
  485. {
  486. auto characteristicsVar = pluginCharacteristicsValue.get();
  487. if (auto* arr = characteristicsVar.getArray())
  488. {
  489. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  490. projectRoot.setProperty (characteristicIdentifier, arr->contains (characteristicIdentifier.toString()), nullptr);
  491. }
  492. }
  493. }
  494. //==============================================================================
  495. static int getVersionElement (StringRef v, int index)
  496. {
  497. StringArray parts = StringArray::fromTokens (v, "., ", {});
  498. return parts [parts.size() - index - 1].getIntValue();
  499. }
  500. static int getJuceVersion (const String& v)
  501. {
  502. return getVersionElement (v, 2) * 100000
  503. + getVersionElement (v, 1) * 1000
  504. + getVersionElement (v, 0);
  505. }
  506. static constexpr int getBuiltJuceVersion()
  507. {
  508. return JUCE_MAJOR_VERSION * 100000
  509. + JUCE_MINOR_VERSION * 1000
  510. + JUCE_BUILDNUMBER;
  511. }
  512. //==============================================================================
  513. static File& lastDocumentOpenedSingleton()
  514. {
  515. static File lastDocumentOpened;
  516. return lastDocumentOpened;
  517. }
  518. File Project::getLastDocumentOpened() { return lastDocumentOpenedSingleton(); }
  519. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpenedSingleton() = file; }
  520. static void registerRecentFile (const File& file)
  521. {
  522. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  523. getAppSettings().recentFiles.addFile (file);
  524. getAppSettings().flush();
  525. }
  526. static void forgetRecentFile (const File& file)
  527. {
  528. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  529. getAppSettings().recentFiles.removeFile (file);
  530. getAppSettings().flush();
  531. }
  532. //==============================================================================
  533. Result Project::loadDocument (const File& file)
  534. {
  535. auto xml = parseXMLIfTagMatches (file, Ids::JUCERPROJECT.toString());
  536. if (xml == nullptr)
  537. return Result::fail ("Not a valid Jucer project!");
  538. auto newTree = ValueTree::fromXml (*xml);
  539. if (! newTree.hasType (Ids::JUCERPROJECT))
  540. return Result::fail ("The document contains errors and couldn't be parsed!");
  541. registerRecentFile (file);
  542. enabledModulesList.reset();
  543. projectRoot = newTree;
  544. projectRoot.addListener (this);
  545. createEnabledModulesList();
  546. initialiseProjectValues();
  547. initialiseMainGroup();
  548. initialiseAudioPluginValues();
  549. coalescePluginFormatValues();
  550. coalescePluginCharacteristicsValues();
  551. updatePluginCategories();
  552. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  553. removeDefunctExporters();
  554. updateOldModulePaths();
  555. updateOldStyleConfigList();
  556. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  557. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  558. getEnabledModules().sortAlphabetically();
  559. rescanExporterPathModules (! ProjucerApplication::getApp().isRunningCommandLine);
  560. exporterPathsModulesList.addListener (this);
  561. if (cppStandardValue.isUsingDefault())
  562. setCppVersionFromOldExporterSettings();
  563. updateDeprecatedProjectSettings();
  564. setChangedFlag (false);
  565. updateLicenseWarning();
  566. return Result::ok();
  567. }
  568. Result Project::saveDocument ([[maybe_unused]] const File& file)
  569. {
  570. jassert (file == getFile());
  571. auto sharedResult = Result::ok();
  572. saveProject (Async::no, nullptr, [&sharedResult] (Result actualResult)
  573. {
  574. sharedResult = actualResult;
  575. });
  576. return sharedResult;
  577. }
  578. void Project::saveDocumentAsync ([[maybe_unused]] const File& file,
  579. std::function<void (Result)> afterSave)
  580. {
  581. jassert (file == getFile());
  582. saveProject (Async::yes, nullptr, std::move (afterSave));
  583. }
  584. void Project::saveProject (Async async,
  585. ProjectExporter* exporterToSave,
  586. std::function<void (Result)> onCompletion)
  587. {
  588. if (isSaveAndExportDisabled())
  589. {
  590. onCompletion (Result::fail ("Save and export is disabled."));
  591. return;
  592. }
  593. if (isTemporaryProject())
  594. {
  595. // Don't try to save a temporary project directly. Instead, check whether the
  596. // project is temporary before saving it, and call saveAndMoveTemporaryProject
  597. // in that case.
  598. onCompletion (Result::fail ("Cannot save temporary project."));
  599. return;
  600. }
  601. if (saver != nullptr)
  602. {
  603. onCompletion (Result::ok());
  604. return;
  605. }
  606. updateProjectSettings();
  607. if (! ProjucerApplication::getApp().isRunningCommandLine)
  608. {
  609. ProjucerApplication::getApp().openDocumentManager.saveAllSyncWithoutAsking();
  610. if (! isTemporaryProject())
  611. registerRecentFile (getFile());
  612. }
  613. saver = std::make_unique<ProjectSaver> (*this);
  614. saver->save (async, exporterToSave, [ref = WeakReference<Project> { this }, onCompletion] (Result result)
  615. {
  616. if (ref == nullptr)
  617. return;
  618. ref->saver = nullptr;
  619. NullCheckedInvocation::invoke (onCompletion, result);
  620. });
  621. }
  622. void Project::openProjectInIDE (ProjectExporter& exporterToOpen)
  623. {
  624. for (ExporterIterator exporter (*this); exporter.next();)
  625. {
  626. if (exporter->canLaunchProject() && exporter->getUniqueName() == exporterToOpen.getUniqueName())
  627. {
  628. if (isTemporaryProject())
  629. {
  630. saveAndMoveTemporaryProject (true);
  631. return;
  632. }
  633. exporter->launchProject();
  634. return;
  635. }
  636. }
  637. }
  638. Result Project::saveResourcesOnly()
  639. {
  640. saver = std::make_unique<ProjectSaver> (*this);
  641. return saver->saveResourcesOnly();
  642. }
  643. bool Project::hasIncompatibleLicenseTypeAndSplashScreenSetting() const
  644. {
  645. auto companyName = companyNameValue.get().toString();
  646. auto isJUCEProject = (companyName == "Raw Material Software Limited"
  647. || companyName == "JUCE"
  648. || companyName == "ROLI Ltd.");
  649. return ! ProjucerApplication::getApp().isRunningCommandLine && ! isJUCEProject && ! shouldDisplaySplashScreen()
  650. && ! ProjucerApplication::getApp().getLicenseController().getCurrentState().canUnlockFullFeatures();
  651. }
  652. bool Project::isFileModificationCheckPending() const
  653. {
  654. return fileModificationPoller.isCheckPending();
  655. }
  656. bool Project::isSaveAndExportDisabled() const
  657. {
  658. return ! ProjucerApplication::getApp().isRunningCommandLine
  659. && (hasIncompatibleLicenseTypeAndSplashScreenSetting() || isFileModificationCheckPending());
  660. }
  661. void Project::updateLicenseWarning()
  662. {
  663. if (hasIncompatibleLicenseTypeAndSplashScreenSetting())
  664. {
  665. ProjectMessages::MessageAction action;
  666. auto currentLicenseState = ProjucerApplication::getApp().getLicenseController().getCurrentState();
  667. if (currentLicenseState.isSignedIn() && (! currentLicenseState.canUnlockFullFeatures() || currentLicenseState.isOldLicense()))
  668. action = { "Upgrade", [] { URL ("https://juce.com/get-juce").launchInDefaultBrowser(); } };
  669. else
  670. action = { "Sign in", [this] { ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile())->showLoginFormOverlay(); } };
  671. addProjectMessage (ProjectMessages::Ids::incompatibleLicense,
  672. { std::move (action), { "Enable splash screen", [this] { displaySplashScreenValue = true; } } });
  673. }
  674. else
  675. {
  676. removeProjectMessage (ProjectMessages::Ids::incompatibleLicense);
  677. }
  678. }
  679. void Project::updateJUCEPathWarning()
  680. {
  681. if (ProjucerApplication::getApp().shouldPromptUserAboutIncorrectJUCEPath()
  682. && ProjucerApplication::getApp().settings->isJUCEPathIncorrect())
  683. {
  684. auto dontAskAgain = [this]
  685. {
  686. ProjucerApplication::getApp().setShouldPromptUserAboutIncorrectJUCEPath (false);
  687. removeProjectMessage (ProjectMessages::Ids::jucePath);
  688. };
  689. addProjectMessage (ProjectMessages::Ids::jucePath,
  690. { { "Set path", [] { ProjucerApplication::getApp().showPathsWindow (true); } },
  691. { "Ignore", [this] { removeProjectMessage (ProjectMessages::Ids::jucePath); } },
  692. { "Don't ask again", std::move (dontAskAgain) } });
  693. }
  694. else
  695. {
  696. removeProjectMessage (ProjectMessages::Ids::jucePath);
  697. }
  698. }
  699. void Project::updateCodeWarning (Identifier identifier, String value)
  700. {
  701. if (value.length() != 4 || value.toStdString().size() != 4)
  702. addProjectMessage (identifier, {});
  703. else
  704. removeProjectMessage (identifier);
  705. }
  706. void Project::updateModuleWarnings()
  707. {
  708. auto& modules = getEnabledModules();
  709. bool cppStandard = false, missingDependencies = false, oldProjucer = false, moduleNotFound = false;
  710. for (auto moduleID : modules.getAllModules())
  711. {
  712. if (! cppStandard && modules.doesModuleHaveHigherCppStandardThanProject (moduleID))
  713. cppStandard = true;
  714. if (! missingDependencies && ! modules.getExtraDependenciesNeeded (moduleID).isEmpty())
  715. missingDependencies = true;
  716. auto info = modules.getModuleInfo (moduleID);
  717. if (! oldProjucer && (isJUCEModule (moduleID) && getJuceVersion (info.getVersion()) > getBuiltJuceVersion()))
  718. oldProjucer = true;
  719. if (! moduleNotFound && ! info.isValid())
  720. moduleNotFound = true;
  721. }
  722. updateCppStandardWarning (cppStandard);
  723. updateMissingModuleDependenciesWarning (missingDependencies);
  724. updateOldProjucerWarning (oldProjucer);
  725. updateModuleNotFoundWarning (moduleNotFound);
  726. }
  727. void Project::updateExporterWarnings()
  728. {
  729. const Identifier deprecatedExporters[] = { "CODEBLOCKS_WINDOWS", "CODEBLOCKS_LINUX" };
  730. for (const auto exporter : getExporters())
  731. {
  732. for (const auto& name : deprecatedExporters)
  733. {
  734. if (exporter.getType() == name)
  735. {
  736. addProjectMessage (ProjectMessages::Ids::deprecatedExporter, {});
  737. return;
  738. }
  739. }
  740. }
  741. removeProjectMessage (ProjectMessages::Ids::deprecatedExporter);
  742. }
  743. void Project::updateCppStandardWarning (bool showWarning)
  744. {
  745. if (showWarning)
  746. {
  747. auto removeModules = [this]
  748. {
  749. auto& modules = getEnabledModules();
  750. for (auto& module : modules.getModulesWithHigherCppStandardThanProject())
  751. modules.removeModule (module);
  752. };
  753. auto updateCppStandard = [this]
  754. {
  755. cppStandardValue = getEnabledModules().getHighestModuleCppStandard();
  756. };
  757. addProjectMessage (ProjectMessages::Ids::cppStandard,
  758. { { "Update project C++ standard" , std::move (updateCppStandard) },
  759. { "Remove module(s)", std::move (removeModules) } });
  760. }
  761. else
  762. {
  763. removeProjectMessage (ProjectMessages::Ids::cppStandard);
  764. }
  765. }
  766. void Project::updateMissingModuleDependenciesWarning (bool showWarning)
  767. {
  768. if (showWarning)
  769. {
  770. auto removeModules = [this]
  771. {
  772. auto& modules = getEnabledModules();
  773. for (auto& mod : modules.getModulesWithMissingDependencies())
  774. modules.removeModule (mod);
  775. };
  776. auto addMissingDependencies = [this]
  777. {
  778. auto& modules = getEnabledModules();
  779. for (auto& mod : modules.getModulesWithMissingDependencies())
  780. modules.tryToFixMissingDependencies (mod);
  781. };
  782. addProjectMessage (ProjectMessages::Ids::missingModuleDependencies,
  783. { { "Add missing dependencies", std::move (addMissingDependencies) },
  784. { "Remove module(s)", std::move (removeModules) } });
  785. }
  786. else
  787. {
  788. removeProjectMessage (ProjectMessages::Ids::missingModuleDependencies);
  789. }
  790. }
  791. void Project::updateOldProjucerWarning (bool showWarning)
  792. {
  793. if (showWarning)
  794. addProjectMessage (ProjectMessages::Ids::oldProjucer, {});
  795. else
  796. removeProjectMessage (ProjectMessages::Ids::oldProjucer);
  797. }
  798. void Project::updateModuleNotFoundWarning (bool showWarning)
  799. {
  800. if (showWarning)
  801. addProjectMessage (ProjectMessages::Ids::moduleNotFound, {});
  802. else
  803. removeProjectMessage (ProjectMessages::Ids::moduleNotFound);
  804. }
  805. void Project::licenseStateChanged()
  806. {
  807. updateLicenseWarning();
  808. }
  809. void Project::changeListenerCallback (ChangeBroadcaster*)
  810. {
  811. updateJUCEPathWarning();
  812. }
  813. void Project::availableModulesChanged (AvailableModulesList* listThatHasChanged)
  814. {
  815. if (listThatHasChanged == &ProjucerApplication::getApp().getJUCEPathModulesList())
  816. updateJUCEPathWarning();
  817. updateModuleWarnings();
  818. }
  819. void Project::addProjectMessage (const Identifier& messageToAdd,
  820. std::vector<ProjectMessages::MessageAction>&& actions)
  821. {
  822. removeProjectMessage (messageToAdd);
  823. messageActions[messageToAdd] = std::move (actions);
  824. ValueTree child (messageToAdd);
  825. child.setProperty (ProjectMessages::Ids::isVisible, true, nullptr);
  826. projectMessages.getChildWithName (ProjectMessages::getTypeForMessage (messageToAdd)).addChild (child, -1, nullptr);
  827. }
  828. void Project::removeProjectMessage (const Identifier& messageToRemove)
  829. {
  830. auto subTree = projectMessages.getChildWithName (ProjectMessages::getTypeForMessage (messageToRemove));
  831. auto child = subTree.getChildWithName (messageToRemove);
  832. if (child.isValid())
  833. subTree.removeChild (child, nullptr);
  834. messageActions.erase (messageToRemove);
  835. }
  836. std::vector<ProjectMessages::MessageAction> Project::getMessageActions (const Identifier& message)
  837. {
  838. auto iter = messageActions.find (message);
  839. if (iter != messageActions.end())
  840. return iter->second;
  841. jassertfalse;
  842. return {};
  843. }
  844. //==============================================================================
  845. void Project::setTemporaryDirectory (const File& dir) noexcept
  846. {
  847. tempDirectory = dir;
  848. // remove this file from the recent documents list as it is a temporary project
  849. forgetRecentFile (getFile());
  850. }
  851. void Project::saveAndMoveTemporaryProject (bool openInIDE)
  852. {
  853. chooser = std::make_unique<FileChooser> ("Save Project");
  854. auto flags = FileBrowserComponent::openMode | FileBrowserComponent::canSelectDirectories;
  855. chooser->launchAsync (flags, [this, openInIDE] (const FileChooser& fc)
  856. {
  857. auto newParentDirectory = fc.getResult();
  858. if (! newParentDirectory.exists())
  859. return;
  860. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  861. auto oldJucerFileName = getFile().getFileName();
  862. saver = std::make_unique<ProjectSaver> (*this);
  863. saver->save (Async::yes, nullptr, [this, newDirectory, oldJucerFileName, openInIDE] (Result)
  864. {
  865. tempDirectory.copyDirectoryTo (newDirectory);
  866. tempDirectory.deleteRecursively();
  867. tempDirectory = File();
  868. // reload project from new location
  869. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  870. {
  871. MessageManager::callAsync ([newDirectory, oldJucerFileName, openInIDE,
  872. safeWindow = Component::SafePointer<MainWindow> { window }]() mutable
  873. {
  874. if (safeWindow != nullptr)
  875. safeWindow->moveProject (newDirectory.getChildFile (oldJucerFileName),
  876. openInIDE ? MainWindow::OpenInIDE::yes
  877. : MainWindow::OpenInIDE::no);
  878. });
  879. }
  880. });
  881. });
  882. }
  883. //==============================================================================
  884. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  885. {
  886. if (tree.getRoot() == tree)
  887. {
  888. if (property == Ids::name)
  889. {
  890. updateTitleDependencies();
  891. }
  892. else if (property == Ids::companyName)
  893. {
  894. updateCompanyNameDependencies();
  895. }
  896. else if (property == Ids::companyWebsite)
  897. {
  898. updateWebsiteDependencies();
  899. }
  900. else if (property == Ids::defines)
  901. {
  902. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  903. }
  904. else if (property == Ids::pluginFormats)
  905. {
  906. if (shouldWriteLegacyPluginFormatSettings)
  907. writeLegacyPluginFormatSettings();
  908. }
  909. else if (property == Ids::pluginCharacteristicsValue)
  910. {
  911. pluginAUMainTypeValue.setDefault (getDefaultAUMainTypes());
  912. pluginVSTCategoryValue.setDefault (getDefaultVSTCategories());
  913. pluginVST3CategoryValue.setDefault (getDefaultVST3Categories());
  914. pluginAAXCategoryValue.setDefault (getDefaultAAXCategories());
  915. pluginEnableARA.setDefault (getDefaultEnableARA());
  916. pluginARAAnalyzableContentValue.setDefault (getDefaultARAContentTypes());
  917. pluginARATransformFlagsValue.setDefault (getDefaultARATransformationFlags());
  918. if (shouldWriteLegacyPluginCharacteristicsSettings)
  919. writeLegacyPluginCharacteristicsSettings();
  920. }
  921. else if (property == Ids::displaySplashScreen)
  922. {
  923. updateLicenseWarning();
  924. }
  925. else if (property == Ids::cppLanguageStandard)
  926. {
  927. updateModuleWarnings();
  928. }
  929. else if (property == Ids::pluginCode)
  930. {
  931. updateCodeWarning (ProjectMessages::Ids::pluginCodeInvalid, pluginCodeValue.get());
  932. }
  933. else if (property == Ids::pluginManufacturerCode)
  934. {
  935. updateCodeWarning (ProjectMessages::Ids::manufacturerCodeInvalid, pluginManufacturerCodeValue.get());
  936. }
  937. }
  938. changed();
  939. }
  940. void Project::valueTreeChildAddedOrRemoved (ValueTree& parent, ValueTree& child)
  941. {
  942. if (child.getType() == Ids::MODULE)
  943. updateModuleWarnings();
  944. else if (parent.getType() == Ids::EXPORTFORMATS)
  945. updateExporterWarnings();
  946. changed();
  947. }
  948. void Project::valueTreeChildAdded (ValueTree& parent, ValueTree& child)
  949. {
  950. valueTreeChildAddedOrRemoved (parent, child);
  951. }
  952. void Project::valueTreeChildRemoved (ValueTree& parent, ValueTree& child, int)
  953. {
  954. valueTreeChildAddedOrRemoved (parent, child);
  955. }
  956. void Project::valueTreeChildOrderChanged (ValueTree&, int, int)
  957. {
  958. changed();
  959. }
  960. //==============================================================================
  961. String Project::serialiseProjectXml (std::unique_ptr<XmlElement> xml) const
  962. {
  963. if (xml == nullptr)
  964. return {};
  965. XmlElement::TextFormat format;
  966. format.newLineChars = getProjectLineFeed().toRawUTF8();
  967. return xml->toString (format);
  968. }
  969. bool Project::updateCachedFileState()
  970. {
  971. auto lastModificationTime = getFile().getLastModificationTime();
  972. if (lastModificationTime <= cachedFileState.first)
  973. return false;
  974. cachedFileState.first = lastModificationTime;
  975. auto serialisedFileContent = serialiseProjectXml (XmlDocument (getFile()).getDocumentElement());
  976. if (serialisedFileContent == cachedFileState.second)
  977. return false;
  978. cachedFileState.second = serialisedFileContent;
  979. return true;
  980. }
  981. //==============================================================================
  982. File Project::resolveFilename (String filename) const
  983. {
  984. if (filename.isEmpty())
  985. return {};
  986. filename = build_tools::replacePreprocessorDefs (getPreprocessorDefs(), filename);
  987. #if ! JUCE_WINDOWS
  988. if (filename.startsWith ("~"))
  989. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  990. #endif
  991. if (build_tools::isAbsolutePath (filename))
  992. return File::createFileWithoutCheckingPath (build_tools::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  993. return getFile().getSiblingFile (build_tools::currentOSStylePath (filename));
  994. }
  995. String Project::getRelativePathForFile (const File& file) const
  996. {
  997. auto filename = file.getFullPathName();
  998. auto relativePathBase = getFile().getParentDirectory();
  999. auto p1 = relativePathBase.getFullPathName();
  1000. auto p2 = file.getFullPathName();
  1001. while (p1.startsWithChar (File::getSeparatorChar()))
  1002. p1 = p1.substring (1);
  1003. while (p2.startsWithChar (File::getSeparatorChar()))
  1004. p2 = p2.substring (1);
  1005. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  1006. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  1007. {
  1008. filename = build_tools::getRelativePathFrom (file, relativePathBase);
  1009. }
  1010. return filename;
  1011. }
  1012. //==============================================================================
  1013. const build_tools::ProjectType& Project::getProjectType() const
  1014. {
  1015. if (auto* type = build_tools::ProjectType::findType (getProjectTypeString()))
  1016. return *type;
  1017. auto* guiType = build_tools::ProjectType::findType (build_tools::ProjectType_GUIApp::getTypeName());
  1018. jassert (guiType != nullptr);
  1019. // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
  1020. return *guiType;
  1021. }
  1022. bool Project::shouldBuildTargetType (build_tools::ProjectType::Target::Type targetType) const noexcept
  1023. {
  1024. auto& projectType = getProjectType();
  1025. if (! projectType.supportsTargetType (targetType))
  1026. return false;
  1027. using Target = build_tools::ProjectType::Target;
  1028. switch (targetType)
  1029. {
  1030. case Target::VSTPlugIn:
  1031. return shouldBuildVST();
  1032. case Target::VST3PlugIn:
  1033. return shouldBuildVST3();
  1034. case Target::VST3Helper:
  1035. return shouldBuildVST3();
  1036. case Target::AAXPlugIn:
  1037. return shouldBuildAAX();
  1038. case Target::AudioUnitPlugIn:
  1039. return shouldBuildAU();
  1040. case Target::AudioUnitv3PlugIn:
  1041. return shouldBuildAUv3();
  1042. case Target::StandalonePlugIn:
  1043. return shouldBuildStandalonePlugin();
  1044. case Target::UnityPlugIn:
  1045. return shouldBuildUnityPlugin();
  1046. case Target::LV2PlugIn:
  1047. case Target::LV2Helper:
  1048. return shouldBuildLV2();
  1049. case Target::AggregateTarget:
  1050. case Target::SharedCodeTarget:
  1051. return projectType.isAudioPlugin();
  1052. case Target::unspecified:
  1053. return false;
  1054. case Target::GUIApp:
  1055. case Target::ConsoleApp:
  1056. case Target::StaticLibrary:
  1057. case Target::DynamicLibrary:
  1058. default:
  1059. break;
  1060. }
  1061. return true;
  1062. }
  1063. build_tools::ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  1064. {
  1065. auto path = file.getFullPathName();
  1066. String pluginClientModuleName = "juce_audio_plugin_client";
  1067. auto isInPluginClientSubdir = [&path, &pluginClientModuleName] (StringRef subDir)
  1068. {
  1069. return path.contains (pluginClientModuleName
  1070. + File::getSeparatorString()
  1071. + subDir
  1072. + File::getSeparatorString());
  1073. };
  1074. auto isPluginClientSource = [&path, &pluginClientModuleName] (StringRef suffix)
  1075. {
  1076. auto prefix = pluginClientModuleName + "_" + suffix;
  1077. return path.contains (prefix + ".") || path.contains (prefix + "_");
  1078. };
  1079. using Target = build_tools::ProjectType::Target::Type;
  1080. struct FormatInfo
  1081. {
  1082. const char* source;
  1083. const char* subdir;
  1084. Target target;
  1085. };
  1086. const FormatInfo formatInfo[] { { "AU", "AU", Target::AudioUnitPlugIn },
  1087. { "AUv3", "AU", Target::AudioUnitv3PlugIn },
  1088. { "AAX", "AAX", Target::AAXPlugIn },
  1089. { "VST2", "VST", Target::VSTPlugIn },
  1090. { "VST3", "VST3", Target::VST3PlugIn },
  1091. { "Standalone", "Standalone", Target::StandalonePlugIn },
  1092. { "Unity", "Unity", Target::UnityPlugIn },
  1093. { "LV2", "LV2", Target::LV2PlugIn } };
  1094. for (const auto& info : formatInfo)
  1095. if (isPluginClientSource (info.source) || isInPluginClientSubdir (info.subdir))
  1096. return info.target;
  1097. return (returnSharedTargetIfNoValidSuffix ? build_tools::ProjectType::Target::SharedCodeTarget
  1098. : build_tools::ProjectType::Target::unspecified);
  1099. }
  1100. //==============================================================================
  1101. void Project::createPropertyEditors (PropertyListBuilder& props)
  1102. {
  1103. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  1104. "The name of the project.");
  1105. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  1106. "The project's version number. This should be in the format major.minor.point[.point] where you should omit the final "
  1107. "(optional) [.point] if you are targeting AU and AUv3 plug-ins as they only support three number versions.");
  1108. props.add (new ChoicePropertyComponent (projectLineFeedValue, "Project Line Feed", { "\\r\\n", "\\n", }, { "\r\n", "\n" }),
  1109. "Use this to set the line feed which will be used when creating new source files for this project "
  1110. "(this won't affect any existing files).");
  1111. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  1112. "Your company name, which will be added to the properties of the binary where possible");
  1113. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  1114. "Your company copyright, which will be added to the properties of the binary where possible");
  1115. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  1116. "Your company website, which will be added to the properties of the binary where possible");
  1117. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  1118. "Your company e-mail, which will be added to the properties of the binary where possible");
  1119. props.add (new ChoicePropertyComponent (useAppConfigValue, "Use Global AppConfig Header"),
  1120. "If enabled, the Projucer will generate module wrapper stubs which include AppConfig.h "
  1121. "and will include AppConfig.h in the JuceHeader.h. If disabled, all the settings that would "
  1122. "previously have been specified in the AppConfig.h will be injected via the build system instead, "
  1123. "which may simplify the includes in the project.");
  1124. props.add (new ChoicePropertyComponent (addUsingNamespaceToJuceHeader, "Add \"using namespace juce\" to JuceHeader.h"),
  1125. "If enabled, the JuceHeader.h will include a \"using namespace juce\" statement. If disabled, "
  1126. "no such statement will be included. This setting used to be enabled by default, but it "
  1127. "is recommended to leave it disabled for new projects.");
  1128. props.add (new ChoicePropertyComponent (displaySplashScreenValue, "Display the JUCE Splash Screen (required for closed source applications without an Indie or Pro JUCE license)"),
  1129. "This option controls the display of the standard JUCE splash screen. "
  1130. "In accordance with the terms of the JUCE 7 End-Use License Agreement (www.juce.com/juce-7-licence), "
  1131. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  1132. "license, or are using JUCE under the GPL v3 license.");
  1133. props.add (new ChoicePropertyComponentWithEnablement (splashScreenColourValue, displaySplashScreenValue, "Splash Screen Colour",
  1134. { "Dark", "Light" }, { "Dark", "Light" }),
  1135. "Choose the colour of the JUCE splash screen.");
  1136. {
  1137. StringArray projectTypeNames;
  1138. Array<var> projectTypeCodes;
  1139. auto types = build_tools::ProjectType::getAllTypes();
  1140. for (int i = 0; i < types.size(); ++i)
  1141. {
  1142. projectTypeNames.add (types.getUnchecked (i)->getDescription());
  1143. projectTypeCodes.add (types.getUnchecked (i)->getType());
  1144. }
  1145. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  1146. "The project type for which settings should be shown.");
  1147. }
  1148. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  1149. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  1150. if (isAudioPluginProject())
  1151. createAudioPluginPropertyEditors (props);
  1152. {
  1153. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  1154. StringArray maxSizeNames;
  1155. Array<var> maxSizeCodes;
  1156. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  1157. {
  1158. auto sizeInBytes = maxSizes[i] * 1024;
  1159. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  1160. maxSizeCodes.add (sizeInBytes);
  1161. }
  1162. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  1163. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  1164. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  1165. }
  1166. props.add (new ChoicePropertyComponent (includeBinaryDataInJuceHeaderValue, "Include BinaryData in JuceHeader"),
  1167. "Include BinaryData.h in the JuceHeader.h file");
  1168. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  1169. "The namespace containing the binary assets.");
  1170. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  1171. getCppStandardStrings(),
  1172. getCppStandardVars()),
  1173. "The standard of the C++ language that will be used for compilation.");
  1174. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  1175. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  1176. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  1177. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  1178. props.add (new TextPropertyComponent (postExportShellCommandPosixValue, "Post-Export Shell Command (macOS, Linux)", 1024, false),
  1179. "A command that will be executed by the system shell after saving this project on macOS or Linux. "
  1180. "The string \"%%1%%\" will be substituted with the absolute path to the project root folder.");
  1181. props.add (new TextPropertyComponent (postExportShellCommandWinValue, "Post-Export Shell Command (Windows)", 1024, false),
  1182. "A command that will be executed by the system shell after saving this project on Windows. "
  1183. "The string \"%%1%%\" will be substituted with the absolute path to the project root folder.");
  1184. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  1185. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  1186. }
  1187. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  1188. {
  1189. {
  1190. StringArray pluginFormatChoices { "VST3", "AU", "AUv3", "AAX", "Standalone", "LV2", "Unity", "Enable IAA", "VST (Legacy)" };
  1191. Array<var> pluginFormatChoiceValues { Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  1192. Ids::buildAAX.toString(), Ids::buildStandalone.toString(),
  1193. Ids::buildLV2.toString(), Ids::buildUnity.toString(), Ids::enableIAA.toString(), Ids::buildVST.toString() };
  1194. if (! getProjectType().isARAAudioPlugin())
  1195. {
  1196. pluginFormatChoices.add ("Enable ARA");
  1197. pluginFormatChoiceValues.add (Ids::enableARA.toString());
  1198. }
  1199. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats", pluginFormatChoices, pluginFormatChoiceValues),
  1200. "Plugin formats to build. If you have selected \"VST (Legacy)\" then you will need to ensure that you have a VST2 SDK "
  1201. "in your header search paths. The VST2 SDK can be obtained from the vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK "
  1202. "or JUCE version 5.3.2. You also need a VST2 license from Steinberg to distribute VST2 plug-ins. If you enable ARA you "
  1203. "will have to obtain the ARA SDK by recursively cloning https://github.com/Celemony/ARA_SDK and checking out the tag "
  1204. "releases/2.1.0.");
  1205. }
  1206. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  1207. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  1208. "Disable AAX Bypass", "Disable AAX Multi-Mono" },
  1209. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  1210. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(),
  1211. Ids::pluginAAXDisableBypass.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  1212. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  1213. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  1214. "The name of your plugin (keep it short!)");
  1215. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  1216. "A short description of your plugin.");
  1217. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  1218. "The name of your company (cannot be blank).");
  1219. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  1220. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!"
  1221. " GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case.");
  1222. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  1223. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain exactly one upper-case letter!"
  1224. " GarageBand 10.3 requires the first letter to be upper-case, and the remaining letters to be lower-case.");
  1225. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  1226. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  1227. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  1228. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  1229. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  1230. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  1231. "The value to use for the JucePlugin_AAXIdentifier setting");
  1232. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  1233. "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.");
  1234. props.add (new MultiChoicePropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", getAllAUMainTypeStrings(), getAllAUMainTypeVars(), 1),
  1235. "AU main type.");
  1236. props.add (new ChoicePropertyComponent (pluginAUSandboxSafeValue, "Plugin AU is sandbox safe"),
  1237. "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 "
  1238. "the Music folder. Your plug-in must be able to deal with this. Newer versions of GarageBand require this to be enabled.");
  1239. {
  1240. Array<var> varChoices;
  1241. StringArray stringChoices;
  1242. for (int i = 1; i <= 16; ++i)
  1243. {
  1244. varChoices.add (i);
  1245. stringChoices.add (String (i));
  1246. }
  1247. props.add (new ChoicePropertyComponentWithEnablement (pluginVSTNumMidiInputsValue, pluginCharacteristicsValue, Ids::pluginWantsMidiIn,
  1248. "Plugin VST Num MIDI Inputs", stringChoices, varChoices),
  1249. "For VST and VST3 plug-ins that accept MIDI, this allows you to configure the number of inputs.");
  1250. props.add (new ChoicePropertyComponentWithEnablement (pluginVSTNumMidiOutputsValue, pluginCharacteristicsValue, Ids::pluginProducesMidiOut,
  1251. "Plugin VST Num MIDI Outputs", stringChoices, varChoices),
  1252. "For VST and VST3 plug-ins that produce MIDI, this allows you to configure the number of outputs.");
  1253. }
  1254. {
  1255. Array<var> vst3CategoryVars;
  1256. for (auto s : getAllVST3CategoryStrings())
  1257. vst3CategoryVars.add (s);
  1258. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  1259. "VST3 category. Most hosts require either \"Fx\" or \"Instrument\" to be selected in order for the plugin to be recognised. "
  1260. "If neither of these are selected, the appropriate one will be automatically added based on the \"Plugin is a synth\" option.");
  1261. }
  1262. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  1263. "AAX category.");
  1264. {
  1265. Array<var> vstCategoryVars;
  1266. for (auto s : getAllVSTCategoryStrings())
  1267. vstCategoryVars.add (s);
  1268. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST (Legacy) Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  1269. "VST category.");
  1270. }
  1271. props.add (new TextPropertyComponent (pluginLV2URIValue, "LV2 URI", 128, false),
  1272. "This acts as a unique identifier for this plugin. "
  1273. "If you make any incompatible changes to your plugin (remove parameters, reorder parameters, change preset format etc.) "
  1274. "you MUST change this value. LV2 hosts will assume that any plugins with the same URI are interchangeable.");
  1275. if (shouldEnableARA())
  1276. {
  1277. props.add (new MultiChoicePropertyComponent (pluginARAAnalyzableContentValue, "Plugin ARA Analyzeable Content Types", getAllARAContentTypeStrings(), getAllARAContentTypeVars()),
  1278. "ARA Analyzeable Content Types.");
  1279. props.add (new MultiChoicePropertyComponent (pluginARATransformFlagsValue, "Plugin ARA Transformation Flags", getAllARATransformationFlagStrings(), getAllARATransformationFlagVars()),
  1280. "ARA Transformation Flags.");
  1281. props.add (new TextPropertyComponent (pluginARAFactoryIDValue, "Plugin ARA Factory ID", 256, false),
  1282. "ARA Factory ID.");
  1283. props.add (new TextPropertyComponent (pluginARAArchiveIDValue, "Plugin ARA Document Archive ID", 256, false),
  1284. "ARA Document Archive ID.");
  1285. props.add (new TextPropertyComponent (pluginARACompatibleArchiveIDsValue, "Plugin ARA Compatible Document Archive IDs", 1024, true),
  1286. "List of compatible ARA Document Archive IDs - one per line");
  1287. }
  1288. }
  1289. //==============================================================================
  1290. File Project::getBinaryDataCppFile (int index) const
  1291. {
  1292. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  1293. if (index > 0)
  1294. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  1295. .withFileExtension (cpp.getFileExtension());
  1296. return cpp;
  1297. }
  1298. Project::Item Project::getMainGroup()
  1299. {
  1300. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  1301. }
  1302. PropertiesFile& Project::getStoredProperties() const
  1303. {
  1304. return getAppSettings().getProjectProperties (getProjectUIDString());
  1305. }
  1306. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  1307. {
  1308. if (item.isImageFile())
  1309. {
  1310. found.add (new Project::Item (item));
  1311. }
  1312. else if (item.isGroup())
  1313. {
  1314. for (int i = 0; i < item.getNumChildren(); ++i)
  1315. findImages (item.getChild (i), found);
  1316. }
  1317. }
  1318. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  1319. {
  1320. findImages (getMainGroup(), items);
  1321. }
  1322. //==============================================================================
  1323. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  1324. : project (p), state (s), belongsToModule (isModuleCode)
  1325. {
  1326. }
  1327. Project::Item::Item (const Item& other)
  1328. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  1329. {
  1330. }
  1331. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  1332. String Project::Item::getID() const { return state [Ids::ID]; }
  1333. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  1334. std::unique_ptr<Drawable> Project::Item::loadAsImageFile() const
  1335. {
  1336. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  1337. if (! mml.lockWasGained())
  1338. return nullptr;
  1339. if (isValid())
  1340. return Drawable::createFromImageFile (getFile());
  1341. return {};
  1342. }
  1343. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  1344. {
  1345. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  1346. group.setID (uid);
  1347. group.initialiseMissingProperties();
  1348. group.getNameValue() = name;
  1349. return group;
  1350. }
  1351. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  1352. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  1353. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  1354. bool Project::Item::isImageFile() const
  1355. {
  1356. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  1357. || getFile().hasFileExtension ("svg"));
  1358. }
  1359. bool Project::Item::isSourceFile() const
  1360. {
  1361. return isFile() && getFile().hasFileExtension (sourceFileExtensions);
  1362. }
  1363. Project::Item Project::Item::findItemWithID (const String& targetId) const
  1364. {
  1365. if (state [Ids::ID] == targetId)
  1366. return *this;
  1367. if (isGroup())
  1368. {
  1369. for (auto i = getNumChildren(); --i >= 0;)
  1370. {
  1371. auto found = getChild (i).findItemWithID (targetId);
  1372. if (found.isValid())
  1373. return found;
  1374. }
  1375. }
  1376. return Item (project, ValueTree(), false);
  1377. }
  1378. bool Project::Item::canContain (const Item& child) const
  1379. {
  1380. if (isFile())
  1381. return false;
  1382. if (isGroup())
  1383. return child.isFile() || child.isGroup();
  1384. jassertfalse;
  1385. return false;
  1386. }
  1387. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  1388. bool Project::Item::shouldBeAddedToTargetExporter (const ProjectExporter& exporter) const
  1389. {
  1390. if (shouldBeAddedToXcodeResources())
  1391. return exporter.isXcode() || shouldBeCompiled();
  1392. return true;
  1393. }
  1394. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  1395. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  1396. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  1397. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  1398. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  1399. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  1400. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  1401. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  1402. bool Project::Item::isModuleCode() const { return belongsToModule; }
  1403. Value Project::Item::getShouldSkipPCHValue() { return state.getPropertyAsValue (Ids::skipPCH, getUndoManager()); }
  1404. bool Project::Item::shouldSkipPCH() const { return isModuleCode() || state [Ids::skipPCH]; }
  1405. Value Project::Item::getCompilerFlagSchemeValue() { return state.getPropertyAsValue (Ids::compilerFlagScheme, getUndoManager()); }
  1406. String Project::Item::getCompilerFlagSchemeString() const { return state[Ids::compilerFlagScheme]; }
  1407. void Project::Item::setCompilerFlagScheme (const String& scheme)
  1408. {
  1409. state.getPropertyAsValue (Ids::compilerFlagScheme, getUndoManager()).setValue (scheme);
  1410. }
  1411. void Project::Item::clearCurrentCompilerFlagScheme()
  1412. {
  1413. state.removeProperty (Ids::compilerFlagScheme, getUndoManager());
  1414. }
  1415. String Project::Item::getFilePath() const
  1416. {
  1417. if (isFile())
  1418. return state [Ids::file].toString();
  1419. return {};
  1420. }
  1421. File Project::Item::getFile() const
  1422. {
  1423. if (isFile())
  1424. return project.resolveFilename (state [Ids::file].toString());
  1425. return {};
  1426. }
  1427. void Project::Item::setFile (const File& file)
  1428. {
  1429. setFile (build_tools::RelativePath (project.getRelativePathForFile (file), build_tools::RelativePath::projectFolder));
  1430. jassert (getFile() == file);
  1431. }
  1432. void Project::Item::setFile (const build_tools::RelativePath& file)
  1433. {
  1434. jassert (isFile());
  1435. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  1436. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  1437. }
  1438. bool Project::Item::renameFile (const File& newFile)
  1439. {
  1440. auto oldFile = getFile();
  1441. if (oldFile.moveFileTo (newFile)
  1442. || (newFile.exists() && ! oldFile.exists()))
  1443. {
  1444. setFile (newFile);
  1445. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  1446. return true;
  1447. }
  1448. return false;
  1449. }
  1450. bool Project::Item::containsChildForFile (const build_tools::RelativePath& file) const
  1451. {
  1452. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  1453. }
  1454. Project::Item Project::Item::findItemForFile (const File& file) const
  1455. {
  1456. if (getFile() == file)
  1457. return *this;
  1458. if (isGroup())
  1459. {
  1460. for (auto i = getNumChildren(); --i >= 0;)
  1461. {
  1462. auto found = getChild (i).findItemForFile (file);
  1463. if (found.isValid())
  1464. return found;
  1465. }
  1466. }
  1467. return Item (project, ValueTree(), false);
  1468. }
  1469. File Project::Item::determineGroupFolder() const
  1470. {
  1471. jassert (isGroup());
  1472. File f;
  1473. for (int i = 0; i < getNumChildren(); ++i)
  1474. {
  1475. f = getChild (i).getFile();
  1476. if (f.exists())
  1477. return f.getParentDirectory();
  1478. }
  1479. auto parent = getParent();
  1480. if (parent != *this)
  1481. {
  1482. f = parent.determineGroupFolder();
  1483. if (f.getChildFile (getName()).isDirectory())
  1484. f = f.getChildFile (getName());
  1485. }
  1486. else
  1487. {
  1488. f = project.getProjectFolder();
  1489. if (f.getChildFile ("Source").isDirectory())
  1490. f = f.getChildFile ("Source");
  1491. }
  1492. return f;
  1493. }
  1494. void Project::Item::initialiseMissingProperties()
  1495. {
  1496. if (! state.hasProperty (Ids::ID))
  1497. setID (createAlphaNumericUID());
  1498. if (isFile())
  1499. {
  1500. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1501. }
  1502. else if (isGroup())
  1503. {
  1504. for (auto i = getNumChildren(); --i >= 0;)
  1505. getChild (i).initialiseMissingProperties();
  1506. }
  1507. }
  1508. Value Project::Item::getNameValue()
  1509. {
  1510. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1511. }
  1512. String Project::Item::getName() const
  1513. {
  1514. return state [Ids::name];
  1515. }
  1516. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1517. {
  1518. state.addChild (newChild.state, insertIndex, getUndoManager());
  1519. }
  1520. void Project::Item::removeItemFromProject()
  1521. {
  1522. state.getParent().removeChild (state, getUndoManager());
  1523. }
  1524. Project::Item Project::Item::getParent() const
  1525. {
  1526. if (isMainGroup() || ! isGroup())
  1527. return *this;
  1528. return { project, state.getParent(), belongsToModule };
  1529. }
  1530. struct ItemSorter
  1531. {
  1532. static int compareElements (const ValueTree& first, const ValueTree& second)
  1533. {
  1534. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1535. }
  1536. };
  1537. struct ItemSorterWithGroupsAtStart
  1538. {
  1539. static int compareElements (const ValueTree& first, const ValueTree& second)
  1540. {
  1541. auto firstIsGroup = first.hasType (Ids::GROUP);
  1542. auto secondIsGroup = second.hasType (Ids::GROUP);
  1543. if (firstIsGroup == secondIsGroup)
  1544. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1545. return firstIsGroup ? -1 : 1;
  1546. }
  1547. };
  1548. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1549. {
  1550. if (keepGroupsAtStart)
  1551. {
  1552. ItemSorterWithGroupsAtStart sorter;
  1553. state.sort (sorter, undoManager, true);
  1554. }
  1555. else
  1556. {
  1557. ItemSorter sorter;
  1558. state.sort (sorter, undoManager, true);
  1559. }
  1560. }
  1561. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1562. {
  1563. if (state.getNumChildren() == 0)
  1564. return false;
  1565. if (state.getNumChildren() == 1)
  1566. return true;
  1567. auto stateCopy = state.createCopy();
  1568. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1569. return stateCopy.isEquivalentTo (state);
  1570. }
  1571. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1572. {
  1573. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1574. if (recursive)
  1575. for (auto i = getNumChildren(); --i >= 0;)
  1576. getChild (i).sortAlphabetically (keepGroupsAtStart, true);
  1577. }
  1578. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1579. {
  1580. for (auto i = state.getNumChildren(); --i >= 0;)
  1581. {
  1582. auto child = state.getChild (i);
  1583. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1584. return { project, child, belongsToModule };
  1585. }
  1586. return addNewSubGroup (name, -1);
  1587. }
  1588. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1589. {
  1590. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1591. int n = 0;
  1592. while (project.getMainGroup().findItemWithID (newID).isValid())
  1593. newID = createGUID (newID + String (++n));
  1594. auto group = createGroup (project, name, newID, belongsToModule);
  1595. jassert (canContain (group));
  1596. addChild (group, insertIndex);
  1597. return group;
  1598. }
  1599. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1600. {
  1601. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1602. return false;
  1603. if (file.isDirectory())
  1604. {
  1605. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1606. for (const auto& iter : RangedDirectoryIterator (file, false, "*", File::findFilesAndDirectories))
  1607. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1608. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1609. }
  1610. else if (file.existsAsFile())
  1611. {
  1612. if (! project.getMainGroup().findItemForFile (file).isValid())
  1613. addFileUnchecked (file, insertIndex, shouldCompile);
  1614. }
  1615. else
  1616. {
  1617. jassertfalse;
  1618. }
  1619. return true;
  1620. }
  1621. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1622. {
  1623. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1624. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1625. if (! addFileAtIndex (file, 0, shouldCompile))
  1626. return false;
  1627. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1628. sortAlphabetically (wasSortedGroupsFirst, false);
  1629. return true;
  1630. }
  1631. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1632. {
  1633. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1634. item.initialiseMissingProperties();
  1635. item.getNameValue() = file.getFileName();
  1636. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1637. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1638. if (canContain (item))
  1639. {
  1640. item.setFile (file);
  1641. addChild (item, insertIndex);
  1642. }
  1643. }
  1644. bool Project::Item::addRelativeFile (const build_tools::RelativePath& file, int insertIndex, bool shouldCompile)
  1645. {
  1646. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1647. item.initialiseMissingProperties();
  1648. item.getNameValue() = file.getFileName();
  1649. item.getShouldCompileValue() = shouldCompile;
  1650. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1651. if (canContain (item))
  1652. {
  1653. item.setFile (file);
  1654. addChild (item, insertIndex);
  1655. return true;
  1656. }
  1657. return false;
  1658. }
  1659. Icon Project::Item::getIcon (bool isOpen) const
  1660. {
  1661. auto& icons = getIcons();
  1662. if (isFile())
  1663. {
  1664. if (isImageFile())
  1665. return Icon (icons.imageDoc, Colours::transparentBlack);
  1666. return { icons.file, Colours::transparentBlack };
  1667. }
  1668. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1669. }
  1670. bool Project::Item::isIconCrossedOut() const
  1671. {
  1672. return isFile()
  1673. && ! (shouldBeCompiled()
  1674. || shouldBeAddedToBinaryResources()
  1675. || getFile().hasFileExtension (headerFileExtensions));
  1676. }
  1677. bool Project::Item::needsSaving() const noexcept
  1678. {
  1679. auto& odm = ProjucerApplication::getApp().openDocumentManager;
  1680. if (odm.anyFilesNeedSaving())
  1681. {
  1682. for (int i = 0; i < odm.getNumOpenDocuments(); ++i)
  1683. {
  1684. auto* doc = odm.getOpenDocument (i);
  1685. if (doc->needsSaving() && doc->getFile() == getFile())
  1686. return true;
  1687. }
  1688. }
  1689. return false;
  1690. }
  1691. //==============================================================================
  1692. ValueTree Project::getConfigNode()
  1693. {
  1694. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1695. }
  1696. ValueTreePropertyWithDefault Project::getConfigFlag (const String& name)
  1697. {
  1698. auto configNode = getConfigNode();
  1699. return { configNode, name, getUndoManagerFor (configNode) };
  1700. }
  1701. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1702. {
  1703. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1704. if (configValue == "default")
  1705. return defaultIsEnabled;
  1706. return configValue;
  1707. }
  1708. //==============================================================================
  1709. StringArray Project::getCompilerFlagSchemes() const
  1710. {
  1711. if (compilerFlagSchemesValue.isUsingDefault())
  1712. return {};
  1713. StringArray schemes;
  1714. auto schemesVar = compilerFlagSchemesValue.get();
  1715. if (auto* arr = schemesVar.getArray())
  1716. schemes.addArray (arr->begin(), arr->end());
  1717. return schemes;
  1718. }
  1719. void Project::addCompilerFlagScheme (const String& schemeToAdd)
  1720. {
  1721. auto schemesVar = compilerFlagSchemesValue.get();
  1722. if (auto* arr = schemesVar.getArray())
  1723. {
  1724. arr->addIfNotAlreadyThere (schemeToAdd);
  1725. compilerFlagSchemesValue.setValue ({ *arr }, getUndoManager());
  1726. }
  1727. }
  1728. void Project::removeCompilerFlagScheme (const String& schemeToRemove)
  1729. {
  1730. auto schemesVar = compilerFlagSchemesValue.get();
  1731. if (auto* arr = schemesVar.getArray())
  1732. {
  1733. for (int i = 0; i < arr->size(); ++i)
  1734. {
  1735. if (arr->getUnchecked (i).toString() == schemeToRemove)
  1736. {
  1737. arr->remove (i);
  1738. if (arr->isEmpty())
  1739. compilerFlagSchemesValue.resetToDefault();
  1740. else
  1741. compilerFlagSchemesValue.setValue ({ *arr }, getUndoManager());
  1742. return;
  1743. }
  1744. }
  1745. }
  1746. }
  1747. //==============================================================================
  1748. static String getCompanyNameOrDefault (StringRef str)
  1749. {
  1750. if (str.isEmpty())
  1751. return "yourcompany";
  1752. return str;
  1753. }
  1754. String Project::getDefaultBundleIdentifierString() const
  1755. {
  1756. return "com." + build_tools::makeValidIdentifier (getCompanyNameOrDefault (getCompanyNameString()), false, true, false)
  1757. + "." + build_tools::makeValidIdentifier (getProjectNameString(), false, true, false);
  1758. }
  1759. String Project::getDefaultCompanyWebsiteString() const
  1760. {
  1761. return "www." + build_tools::makeValidIdentifier (getCompanyNameOrDefault (getCompanyNameString()), false, true, false) + ".com";
  1762. }
  1763. String Project::getDefaultPluginManufacturerString() const
  1764. {
  1765. return getCompanyNameOrDefault (getCompanyNameString());
  1766. }
  1767. String Project::getDefaultARAFactoryIDString() const
  1768. {
  1769. return getDefaultBundleIdentifierString() + ".factory";
  1770. }
  1771. String Project::getDefaultARADocumentArchiveID() const
  1772. {
  1773. return getDefaultBundleIdentifierString() + ".aradocumentarchive." + getVersionString();
  1774. }
  1775. String Project::getDefaultARACompatibleArchiveIDs() const
  1776. {
  1777. return String();
  1778. }
  1779. String Project::getAUMainTypeString() const noexcept
  1780. {
  1781. auto v = pluginAUMainTypeValue.get();
  1782. if (auto* arr = v.getArray())
  1783. return arr->getFirst().toString();
  1784. jassertfalse;
  1785. return {};
  1786. }
  1787. bool Project::isAUSandBoxSafe() const noexcept
  1788. {
  1789. return pluginAUSandboxSafeValue.get();
  1790. }
  1791. String Project::getVSTCategoryString() const noexcept
  1792. {
  1793. auto v = pluginVSTCategoryValue.get();
  1794. if (auto* arr = v.getArray())
  1795. return arr->getFirst().toString();
  1796. jassertfalse;
  1797. return {};
  1798. }
  1799. static String getVST3CategoryStringFromSelection (Array<var> selected, const Project& p) noexcept
  1800. {
  1801. StringArray categories;
  1802. for (auto& category : selected)
  1803. categories.add (category);
  1804. // One of these needs to be selected in order for the plug-in to be recognised in Cubase
  1805. if (! categories.contains ("Fx") && ! categories.contains ("Instrument"))
  1806. {
  1807. categories.insert (0, p.isPluginSynth() ? "Instrument"
  1808. : "Fx");
  1809. }
  1810. else
  1811. {
  1812. // "Fx" and "Instrument" should come first and if both are present prioritise "Fx"
  1813. if (categories.contains ("Instrument"))
  1814. categories.move (categories.indexOf ("Instrument"), 0);
  1815. if (categories.contains ("Fx"))
  1816. categories.move (categories.indexOf ("Fx"), 0);
  1817. }
  1818. return categories.joinIntoString ("|");
  1819. }
  1820. String Project::getVST3CategoryString() const noexcept
  1821. {
  1822. auto v = pluginVST3CategoryValue.get();
  1823. if (auto* arr = v.getArray())
  1824. return getVST3CategoryStringFromSelection (*arr, *this);
  1825. jassertfalse;
  1826. return {};
  1827. }
  1828. int Project::getAAXCategory() const noexcept
  1829. {
  1830. int res = 0;
  1831. auto v = pluginAAXCategoryValue.get();
  1832. if (auto* arr = v.getArray())
  1833. {
  1834. for (auto c : *arr)
  1835. res |= static_cast<int> (c);
  1836. }
  1837. return res;
  1838. }
  1839. String Project::getIAATypeCode() const
  1840. {
  1841. String s;
  1842. if (pluginWantsMidiInput())
  1843. {
  1844. if (isPluginSynth())
  1845. s = "auri";
  1846. else
  1847. s = "aurm";
  1848. }
  1849. else
  1850. {
  1851. if (isPluginSynth())
  1852. s = "aurg";
  1853. else
  1854. s = "aurx";
  1855. }
  1856. return s;
  1857. }
  1858. String Project::getIAAPluginName() const
  1859. {
  1860. auto s = getPluginManufacturerString();
  1861. s << ": ";
  1862. s << getPluginNameString();
  1863. return s;
  1864. }
  1865. int Project::getARAContentTypes() const noexcept
  1866. {
  1867. int res = 0;
  1868. if (auto* arr = pluginARAAnalyzableContentValue.get().getArray())
  1869. {
  1870. for (auto c : *arr)
  1871. res |= (int) c;
  1872. }
  1873. return res;
  1874. }
  1875. int Project::getARATransformationFlags() const noexcept
  1876. {
  1877. int res = 0;
  1878. if (auto* arr = pluginARATransformFlagsValue.get().getArray())
  1879. {
  1880. for (auto c : *arr)
  1881. res |= (int) c;
  1882. }
  1883. return res;
  1884. }
  1885. //==============================================================================
  1886. bool Project::isAUPluginHost() const
  1887. {
  1888. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU", false);
  1889. }
  1890. bool Project::isVSTPluginHost() const
  1891. {
  1892. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST", false);
  1893. }
  1894. bool Project::isVST3PluginHost() const
  1895. {
  1896. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3", false);
  1897. }
  1898. bool Project::isLV2PluginHost() const
  1899. {
  1900. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_LV2", false);
  1901. }
  1902. bool Project::isARAPluginHost() const
  1903. {
  1904. return (isVST3PluginHost() || isAUPluginHost()) && isConfigFlagEnabled ("JUCE_PLUGINHOST_ARA", false);
  1905. }
  1906. void Project::disableStandaloneForARAPlugIn()
  1907. {
  1908. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(), Array<var> (Ids::buildVST3.toString(), Ids::buildAU.toString()), ",");
  1909. }
  1910. //==============================================================================
  1911. StringArray Project::getAllAUMainTypeStrings() noexcept
  1912. {
  1913. static StringArray auMainTypeStrings { "kAudioUnitType_Effect", "kAudioUnitType_FormatConverter", "kAudioUnitType_Generator", "kAudioUnitType_MIDIProcessor",
  1914. "kAudioUnitType_Mixer", "kAudioUnitType_MusicDevice", "kAudioUnitType_MusicEffect", "kAudioUnitType_OfflineEffect",
  1915. "kAudioUnitType_Output", "kAudioUnitType_Panner" };
  1916. return auMainTypeStrings;
  1917. }
  1918. Array<var> Project::getAllAUMainTypeVars() noexcept
  1919. {
  1920. static Array<var> auMainTypeVars { "'aufx'", "'aufc'", "'augn'", "'aumi'",
  1921. "'aumx'", "'aumu'", "'aumf'", "'auol'",
  1922. "'auou'", "'aupn'" };
  1923. return auMainTypeVars;
  1924. }
  1925. Array<var> Project::getDefaultAUMainTypes() const noexcept
  1926. {
  1927. if (isPluginMidiEffect()) return { "'aumi'" };
  1928. if (isPluginSynth()) return { "'aumu'" };
  1929. if (pluginWantsMidiInput()) return { "'aumf'" };
  1930. return { "'aufx'" };
  1931. }
  1932. StringArray Project::getAllVSTCategoryStrings() noexcept
  1933. {
  1934. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1935. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1936. "kPlugCategShell", "kPlugCategGenerator" };
  1937. return vstCategoryStrings;
  1938. }
  1939. Array<var> Project::getDefaultVSTCategories() const noexcept
  1940. {
  1941. if (isPluginSynth())
  1942. return { "kPlugCategSynth" };
  1943. return { "kPlugCategEffect" };
  1944. }
  1945. StringArray Project::getAllVST3CategoryStrings() noexcept
  1946. {
  1947. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Analyzer", "Delay", "Distortion", "Drum", "Dynamics", "EQ", "External", "Filter",
  1948. "Generator", "Mastering", "Modulation", "Mono", "Network", "NoOfflineProcess", "OnlyOfflineProcess", "OnlyRT",
  1949. "Pitch Shift", "Restoration", "Reverb", "Sampler", "Spatial", "Stereo", "Surround", "Synth", "Tools", "Up-Downmix" };
  1950. return vst3CategoryStrings;
  1951. }
  1952. Array<var> Project::getDefaultVST3Categories() const noexcept
  1953. {
  1954. if (isPluginSynth())
  1955. return { "Instrument", "Synth" };
  1956. return { "Fx" };
  1957. }
  1958. StringArray Project::getAllAAXCategoryStrings() noexcept
  1959. {
  1960. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1961. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1962. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1963. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1964. return aaxCategoryStrings;
  1965. }
  1966. Array<var> Project::getAllAAXCategoryVars() noexcept
  1967. {
  1968. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1969. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1970. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1971. 0x00000800, 0x00001000, 0x00002000 };
  1972. return aaxCategoryVars;
  1973. }
  1974. Array<var> Project::getDefaultAAXCategories() const noexcept
  1975. {
  1976. if (isPluginSynth())
  1977. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1978. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1979. }
  1980. bool Project::getDefaultEnableARA() const noexcept
  1981. {
  1982. return false;
  1983. }
  1984. StringArray Project::getAllARAContentTypeStrings() noexcept
  1985. {
  1986. static StringArray araContentTypes { "Notes",
  1987. "Tempo Entries",
  1988. "Bar Signatures",
  1989. "Static Tuning",
  1990. "Dynamic Tuning Offsets",
  1991. "Key Signatures",
  1992. "Sheet Chords" };
  1993. return araContentTypes;
  1994. }
  1995. Array<var> Project::getAllARAContentTypeVars() noexcept
  1996. {
  1997. static Array<var> araContentVars {
  1998. /*kARAContentTypeNotes =*/ 1 << 0,
  1999. /*kARAContentTypeTempoEntries =*/ 1 << 1,
  2000. /*kARAContentTypeBarSignatures =*/ 1 << 2,
  2001. /*kARAContentTypeStaticTuning =*/ 1 << 3,
  2002. /*kARAContentTypeDynamicTuningOffsets =*/ 1 << 4,
  2003. /*kARAContentTypeKeySignatures =*/ 1 << 5,
  2004. /*kARAContentTypeSheetChords =*/ 1 << 6,
  2005. };
  2006. return araContentVars;
  2007. }
  2008. Array<var> Project::getDefaultARAContentTypes() const noexcept
  2009. {
  2010. return {};
  2011. }
  2012. StringArray Project::getAllARATransformationFlagStrings() noexcept
  2013. {
  2014. static StringArray araTransformationFlags { "Time Stretch",
  2015. "Time Stretch (reflecting tempo)",
  2016. "Content Based Fades At Tail",
  2017. "Content Based Fades At Head" };
  2018. return araTransformationFlags;
  2019. }
  2020. Array<var> Project::getAllARATransformationFlagVars() noexcept
  2021. {
  2022. static Array<var> araContentVars {
  2023. /*kARAPlaybackTransformationTimestretch =*/ 1 << 0,
  2024. /*kARAPlaybackTransformationTimestretchReflectingTempo =*/ 1 << 1,
  2025. /*kARAPlaybackTransformationContentBasedFadesAtTail =*/ 1 << 2,
  2026. /*kARAPlaybackTransformationContentBasedFadesAtHead =*/ 1 << 3
  2027. };
  2028. return araContentVars;
  2029. }
  2030. Array<var> Project::getDefaultARATransformationFlags() const noexcept
  2031. {
  2032. return {};
  2033. }
  2034. //==============================================================================
  2035. template <typename This>
  2036. auto& Project::getEnabledModulesImpl (This& t)
  2037. {
  2038. // This won't work until you've loaded a project!
  2039. jassert (t.enabledModulesList != nullptr);
  2040. return *t.enabledModulesList;
  2041. }
  2042. EnabledModulesList& Project::getEnabledModules() { return getEnabledModulesImpl (*this); }
  2043. const EnabledModulesList& Project::getEnabledModules() const { return getEnabledModulesImpl (*this); }
  2044. void Project::createEnabledModulesList()
  2045. {
  2046. enabledModulesList = std::make_unique<EnabledModulesList> (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  2047. }
  2048. static StringArray getModulePathsFromExporters (Project& project, bool onlyThisOS)
  2049. {
  2050. StringArray paths;
  2051. for (Project::ExporterIterator exporter (project); exporter.next();)
  2052. {
  2053. if (onlyThisOS && ! exporter->mayCompileOnCurrentOS())
  2054. continue;
  2055. auto& modules = project.getEnabledModules();
  2056. auto n = modules.getNumModules();
  2057. for (int i = 0; i < n; ++i)
  2058. {
  2059. auto id = modules.getModuleID (i);
  2060. if (modules.shouldUseGlobalPath (id))
  2061. continue;
  2062. auto path = exporter->getPathForModuleString (id);
  2063. if (path.isNotEmpty())
  2064. paths.addIfNotAlreadyThere (path);
  2065. }
  2066. auto oldPath = exporter->getLegacyModulePath();
  2067. if (oldPath.isNotEmpty())
  2068. paths.addIfNotAlreadyThere (oldPath);
  2069. }
  2070. return paths;
  2071. }
  2072. static Array<File> getExporterModulePathsToScan (Project& project)
  2073. {
  2074. auto exporterPaths = getModulePathsFromExporters (project, true);
  2075. if (exporterPaths.isEmpty())
  2076. exporterPaths = getModulePathsFromExporters (project, false);
  2077. Array<File> files;
  2078. for (auto& path : exporterPaths)
  2079. {
  2080. auto f = project.resolveFilename (path);
  2081. if (f.isDirectory())
  2082. {
  2083. files.addIfNotAlreadyThere (f);
  2084. if (f.getChildFile ("modules").isDirectory())
  2085. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  2086. }
  2087. }
  2088. return files;
  2089. }
  2090. void Project::rescanExporterPathModules (bool async)
  2091. {
  2092. if (async)
  2093. exporterPathsModulesList.scanPathsAsync (getExporterModulePathsToScan (*this));
  2094. else
  2095. exporterPathsModulesList.scanPaths (getExporterModulePathsToScan (*this));
  2096. }
  2097. AvailableModulesList::ModuleIDAndFolder Project::getModuleWithID (const String& id)
  2098. {
  2099. if (! getEnabledModules().shouldUseGlobalPath (id))
  2100. {
  2101. const auto& mod = exporterPathsModulesList.getModuleWithID (id);
  2102. if (mod.second != File())
  2103. return mod;
  2104. }
  2105. const auto& list = (isJUCEModule (id) ? ProjucerApplication::getApp().getJUCEPathModulesList().getAllModules()
  2106. : ProjucerApplication::getApp().getUserPathsModulesList().getAllModules());
  2107. for (auto& m : list)
  2108. if (m.first == id)
  2109. return m;
  2110. return exporterPathsModulesList.getModuleWithID (id);
  2111. }
  2112. //==============================================================================
  2113. ValueTree Project::getExporters()
  2114. {
  2115. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  2116. }
  2117. int Project::getNumExporters()
  2118. {
  2119. return getExporters().getNumChildren();
  2120. }
  2121. std::unique_ptr<ProjectExporter> Project::createExporter (int index)
  2122. {
  2123. jassert (index >= 0 && index < getNumExporters());
  2124. return ProjectExporter::createExporterFromSettings (*this, getExporters().getChild (index));
  2125. }
  2126. void Project::addNewExporter (const Identifier& exporterIdentifier)
  2127. {
  2128. std::unique_ptr<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterIdentifier));
  2129. exp->getTargetLocationValue() = exp->getTargetLocationString()
  2130. + getUniqueTargetFolderSuffixForExporter (exporterIdentifier, exp->getTargetLocationString());
  2131. auto exportersTree = getExporters();
  2132. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  2133. }
  2134. void Project::createExporterForCurrentPlatform()
  2135. {
  2136. addNewExporter (ProjectExporter::getCurrentPlatformExporterTypeInfo().identifier);
  2137. }
  2138. String Project::getUniqueTargetFolderSuffixForExporter (const Identifier& exporterIdentifier, const String& base)
  2139. {
  2140. StringArray buildFolders;
  2141. auto exportersTree = getExporters();
  2142. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  2143. {
  2144. auto exporterNode = exportersTree.getChild (i);
  2145. if (exporterNode.getType() == exporterIdentifier)
  2146. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  2147. }
  2148. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  2149. return {};
  2150. buildFolders.remove (buildFolders.indexOf (base));
  2151. int num = 1;
  2152. for (auto f : buildFolders)
  2153. {
  2154. if (! f.endsWith ("_" + String (num)))
  2155. break;
  2156. ++num;
  2157. }
  2158. return "_" + String (num);
  2159. }
  2160. //==============================================================================
  2161. StringPairArray Project::getAppConfigDefs()
  2162. {
  2163. StringPairArray result;
  2164. result.set ("JUCE_DISPLAY_SPLASH_SCREEN", shouldDisplaySplashScreen() ? "1" : "0");
  2165. result.set ("JUCE_USE_DARK_SPLASH_SCREEN", getSplashScreenColourString() == "Dark" ? "1" : "0");
  2166. result.set ("JUCE_PROJUCER_VERSION", "0x" + String::toHexString (ProjectInfo::versionNumber));
  2167. OwnedArray<LibraryModule> modules;
  2168. getEnabledModules().createRequiredModules (modules);
  2169. for (auto& m : modules)
  2170. result.set ("JUCE_MODULE_AVAILABLE_" + m->getID(), "1");
  2171. result.set ("JUCE_GLOBAL_MODULE_SETTINGS_INCLUDED", "1");
  2172. for (auto& m : modules)
  2173. {
  2174. OwnedArray<Project::ConfigFlag> flags;
  2175. m->getConfigFlags (*this, flags);
  2176. for (auto* flag : flags)
  2177. if (! flag->value.isUsingDefault())
  2178. result.set (flag->symbol, flag->value.get() ? "1" : "0");
  2179. }
  2180. result.addArray (getAudioPluginFlags());
  2181. const auto& type = getProjectType();
  2182. const auto isStandaloneApplication = (! type.isAudioPlugin() && ! type.isDynamicLibrary());
  2183. const auto standaloneValue = [&]
  2184. {
  2185. if (result.containsKey ("JucePlugin_Name") && result.containsKey ("JucePlugin_Build_Standalone"))
  2186. return "JucePlugin_Build_Standalone";
  2187. return isStandaloneApplication ? "1" : "0";
  2188. }();
  2189. result.set ("JUCE_STANDALONE_APPLICATION", standaloneValue);
  2190. return result;
  2191. }
  2192. StringPairArray Project::getAudioPluginFlags() const
  2193. {
  2194. if (! isAudioPluginProject())
  2195. return {};
  2196. const auto boolToString = [] (bool b) { return b ? "1" : "0"; };
  2197. const auto toStringLiteral = [] (const String& v)
  2198. {
  2199. return CppTokeniserFunctions::addEscapeChars (v).quoted();
  2200. };
  2201. const auto countMaxPluginChannels = [] (const String& configString, bool isInput)
  2202. {
  2203. auto configs = StringArray::fromTokens (configString, ", {}", {});
  2204. configs.trim();
  2205. configs.removeEmptyStrings();
  2206. jassert ((configs.size() & 1) == 0); // looks like a syntax error in the configs?
  2207. int maxVal = 0;
  2208. for (int i = (isInput ? 0 : 1); i < configs.size(); i += 2)
  2209. maxVal = jmax (maxVal, configs[i].getIntValue());
  2210. return maxVal;
  2211. };
  2212. const auto toCharLiteral = [] (const String& v)
  2213. {
  2214. auto fourCharCode = v.substring (0, 4);
  2215. uint32 hexRepresentation = 0;
  2216. for (int i = 0; i < 4; ++i)
  2217. {
  2218. const auto character = (unsigned int) (i < fourCharCode.length() ? fourCharCode[i] : 0);
  2219. hexRepresentation = (hexRepresentation << 8u) | (character & 0xffu);
  2220. }
  2221. return "0x" + String::toHexString (static_cast<int> (hexRepresentation));
  2222. };
  2223. StringPairArray flags;
  2224. flags.set ("JucePlugin_Build_VST", boolToString (shouldBuildVST()));
  2225. flags.set ("JucePlugin_Build_VST3", boolToString (shouldBuildVST3()));
  2226. flags.set ("JucePlugin_Build_AU", boolToString (shouldBuildAU()));
  2227. flags.set ("JucePlugin_Build_AUv3", boolToString (shouldBuildAUv3()));
  2228. flags.set ("JucePlugin_Build_AAX", boolToString (shouldBuildAAX()));
  2229. flags.set ("JucePlugin_Build_Standalone", boolToString (shouldBuildStandalonePlugin()));
  2230. flags.set ("JucePlugin_Build_Unity", boolToString (shouldBuildUnityPlugin()));
  2231. flags.set ("JucePlugin_Build_LV2", boolToString (shouldBuildLV2()));
  2232. flags.set ("JucePlugin_Enable_IAA", boolToString (shouldEnableIAA()));
  2233. flags.set ("JucePlugin_Enable_ARA", boolToString (shouldEnableARA()));
  2234. flags.set ("JucePlugin_Name", toStringLiteral (getPluginNameString()));
  2235. flags.set ("JucePlugin_Desc", toStringLiteral (getPluginDescriptionString()));
  2236. flags.set ("JucePlugin_Manufacturer", toStringLiteral (getPluginManufacturerString()));
  2237. flags.set ("JucePlugin_ManufacturerWebsite", toStringLiteral (getCompanyWebsiteString()));
  2238. flags.set ("JucePlugin_ManufacturerEmail", toStringLiteral (getCompanyEmailString()));
  2239. flags.set ("JucePlugin_ManufacturerCode", toCharLiteral (getPluginManufacturerCodeString()));
  2240. flags.set ("JucePlugin_PluginCode", toCharLiteral (getPluginCodeString()));
  2241. flags.set ("JucePlugin_IsSynth", boolToString (isPluginSynth()));
  2242. flags.set ("JucePlugin_WantsMidiInput", boolToString (pluginWantsMidiInput()));
  2243. flags.set ("JucePlugin_ProducesMidiOutput", boolToString (pluginProducesMidiOutput()));
  2244. flags.set ("JucePlugin_IsMidiEffect", boolToString (isPluginMidiEffect()));
  2245. flags.set ("JucePlugin_EditorRequiresKeyboardFocus", boolToString (pluginEditorNeedsKeyFocus()));
  2246. flags.set ("JucePlugin_Version", getVersionString());
  2247. flags.set ("JucePlugin_VersionCode", getVersionAsHex());
  2248. flags.set ("JucePlugin_VersionString", toStringLiteral (getVersionString()));
  2249. flags.set ("JucePlugin_VSTUniqueID", "JucePlugin_PluginCode");
  2250. flags.set ("JucePlugin_VSTCategory", getVSTCategoryString());
  2251. flags.set ("JucePlugin_Vst3Category", toStringLiteral (getVST3CategoryString()));
  2252. flags.set ("JucePlugin_AUMainType", getAUMainTypeString());
  2253. flags.set ("JucePlugin_AUSubType", "JucePlugin_PluginCode");
  2254. flags.set ("JucePlugin_AUExportPrefix", getPluginAUExportPrefixString());
  2255. flags.set ("JucePlugin_AUExportPrefixQuoted", toStringLiteral (getPluginAUExportPrefixString()));
  2256. flags.set ("JucePlugin_AUManufacturerCode", "JucePlugin_ManufacturerCode");
  2257. flags.set ("JucePlugin_CFBundleIdentifier", getBundleIdentifierString());
  2258. flags.set ("JucePlugin_AAXIdentifier", getAAXIdentifierString());
  2259. flags.set ("JucePlugin_AAXManufacturerCode", "JucePlugin_ManufacturerCode");
  2260. flags.set ("JucePlugin_AAXProductId", "JucePlugin_PluginCode");
  2261. flags.set ("JucePlugin_AAXCategory", String (getAAXCategory()));
  2262. flags.set ("JucePlugin_AAXDisableBypass", boolToString (isPluginAAXBypassDisabled()));
  2263. flags.set ("JucePlugin_AAXDisableMultiMono", boolToString (isPluginAAXMultiMonoDisabled()));
  2264. flags.set ("JucePlugin_IAAType", toCharLiteral (getIAATypeCode()));
  2265. flags.set ("JucePlugin_IAASubType", "JucePlugin_PluginCode");
  2266. flags.set ("JucePlugin_IAAName", toStringLiteral (getIAAPluginName()));
  2267. flags.set ("JucePlugin_VSTNumMidiInputs", getVSTNumMIDIInputsString());
  2268. flags.set ("JucePlugin_VSTNumMidiOutputs", getVSTNumMIDIOutputsString());
  2269. flags.set ("JucePlugin_ARAContentTypes", String (getARAContentTypes()));
  2270. flags.set ("JucePlugin_ARATransformationFlags", String (getARATransformationFlags()));
  2271. flags.set ("JucePlugin_ARAFactoryID", toStringLiteral (getARAFactoryIDString()));
  2272. flags.set ("JucePlugin_ARADocumentArchiveID", toStringLiteral (getARADocumentArchiveIDString()));
  2273. flags.set ("JucePlugin_ARACompatibleArchiveIDs", toStringLiteral (getARACompatibleArchiveIDStrings()));
  2274. {
  2275. String plugInChannelConfig = getPluginChannelConfigsString();
  2276. if (plugInChannelConfig.isNotEmpty())
  2277. {
  2278. flags.set ("JucePlugin_MaxNumInputChannels", String (countMaxPluginChannels (plugInChannelConfig, true)));
  2279. flags.set ("JucePlugin_MaxNumOutputChannels", String (countMaxPluginChannels (plugInChannelConfig, false)));
  2280. flags.set ("JucePlugin_PreferredChannelConfigurations", plugInChannelConfig);
  2281. }
  2282. }
  2283. return flags;
  2284. }
  2285. //==============================================================================
  2286. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  2287. bool Project::ExporterIterator::next()
  2288. {
  2289. if (++index >= project.getNumExporters())
  2290. return false;
  2291. exporter = project.createExporter (index);
  2292. if (exporter == nullptr)
  2293. {
  2294. jassertfalse; // corrupted project file?
  2295. return next();
  2296. }
  2297. return true;
  2298. }