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.

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