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.

2592 lines
98KB

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