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.

2670 lines
101KB

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