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.

2850 lines
107KB

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