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.

2114 lines
77KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../Application/jucer_Headers.h"
  20. #include "jucer_Project.h"
  21. #include "../ProjectSaving/jucer_ProjectSaver.h"
  22. #include "../Application/jucer_Application.h"
  23. #include "../LiveBuildEngine/jucer_CompileEngineSettings.h"
  24. namespace
  25. {
  26. String makeValid4CC (const String& seed)
  27. {
  28. auto s = CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx";
  29. return s.substring (0, 1).toUpperCase()
  30. + s.substring (1, 4).toLowerCase();
  31. }
  32. }
  33. //==============================================================================
  34. Project::Project (const File& f)
  35. : FileBasedDocument (projectFileExtension,
  36. String ("*") + projectFileExtension,
  37. "Choose a Jucer project to load",
  38. "Save Jucer project")
  39. {
  40. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  41. setFile (f);
  42. removeDefunctExporters();
  43. exporterPathsModuleList.reset (new AvailableModuleList());
  44. updateOldModulePaths();
  45. updateOldStyleConfigList();
  46. setCppVersionFromOldExporterSettings();
  47. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  48. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  49. initialiseProjectValues();
  50. initialiseMainGroup();
  51. initialiseAudioPluginValues();
  52. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  53. getEnabledModules().sortAlphabetically();
  54. projectRoot.addListener (this);
  55. compileEngineSettings.reset (new CompileEngineSettings (projectRoot));
  56. setChangedFlag (false);
  57. modificationTime = getFile().getLastModificationTime();
  58. }
  59. Project::~Project()
  60. {
  61. projectRoot.removeListener (this);
  62. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  63. }
  64. const char* Project::projectFileExtension = ".jucer";
  65. //==============================================================================
  66. void Project::setTitle (const String& newTitle)
  67. {
  68. projectNameValue = newTitle;
  69. updateTitleDependencies();
  70. }
  71. void Project::updateTitleDependencies()
  72. {
  73. auto projectName = getProjectNameString();
  74. getMainGroup().getNameValue() = projectName;
  75. pluginNameValue. setDefault (projectName);
  76. pluginDescriptionValue. setDefault (projectName);
  77. bundleIdentifierValue. setDefault (getDefaultBundleIdentifierString());
  78. pluginAUExportPrefixValue.setDefault (CodeHelpers::makeValidIdentifier (projectName, false, true, false) + "AU");
  79. pluginAAXIdentifierValue. setDefault (getDefaultAAXIdentifierString());
  80. }
  81. String Project::getDocumentTitle()
  82. {
  83. return getProjectNameString();
  84. }
  85. void Project::updateCompanyNameDependencies()
  86. {
  87. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  88. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  89. pluginManufacturerValue.setDefault (getDefaultPluginManufacturerString());
  90. }
  91. void Project::updateProjectSettings()
  92. {
  93. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  94. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  95. }
  96. bool Project::setCppVersionFromOldExporterSettings()
  97. {
  98. auto highestLanguageStandard = -1;
  99. for (Project::ExporterIterator exporter (*this); exporter.next();)
  100. {
  101. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  102. {
  103. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  104. {
  105. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  106. if (cppLanguageStandard != var())
  107. {
  108. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  109. if (versionNum > highestLanguageStandard)
  110. highestLanguageStandard = versionNum;
  111. }
  112. }
  113. }
  114. else
  115. {
  116. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  117. if (cppLanguageStandard != var())
  118. {
  119. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  120. {
  121. cppStandardValue = "latest";
  122. return true;
  123. }
  124. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  125. if (versionNum > highestLanguageStandard)
  126. highestLanguageStandard = versionNum;
  127. }
  128. }
  129. }
  130. if (highestLanguageStandard != -1 && highestLanguageStandard >= 11)
  131. {
  132. cppStandardValue = highestLanguageStandard;
  133. return true;
  134. }
  135. return false;
  136. }
  137. void Project::updateDeprecatedProjectSettingsInteractively()
  138. {
  139. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  140. for (Project::ExporterIterator exporter (*this); exporter.next();)
  141. exporter->updateDeprecatedProjectSettingsInteractively();
  142. }
  143. void Project::initialiseMainGroup()
  144. {
  145. // Create main file group if missing
  146. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  147. {
  148. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  149. projectRoot.addChild (mainGroup.state, 0, nullptr);
  150. }
  151. getMainGroup().initialiseMissingProperties();
  152. }
  153. void Project::initialiseProjectValues()
  154. {
  155. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  156. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  157. if (projectUIDValue.isUsingDefault())
  158. projectUIDValue = projectUIDValue.getDefault();
  159. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  160. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  161. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager());
  162. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  163. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), ProjectType_GUIApp::getTypeName());
  164. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  165. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  166. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), ! ProjucerApplication::getApp().isPaidOrGPL());
  167. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  168. reportAppUsageValue.referTo (projectRoot, Ids::reportAppUsage, getUndoManager());
  169. if (ProjucerApplication::getApp().isPaidOrGPL())
  170. {
  171. reportAppUsageValue.setDefault (ProjucerApplication::getApp().licenseController->getState().applicationUsageDataState
  172. == LicenseState::ApplicationUsageData::enabled);
  173. }
  174. else
  175. {
  176. reportAppUsageValue.setDefault (true);
  177. }
  178. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "14");
  179. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  180. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  181. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  182. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  183. // this is here for backwards compatibility with old projects using the incorrect id
  184. if (projectRoot.hasProperty ("includeBinaryInAppConfig"))
  185. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, "includeBinaryInAppConfig", getUndoManager(), true);
  186. else
  187. includeBinaryDataInJuceHeaderValue.referTo (projectRoot, Ids::includeBinaryInJuceHeader, getUndoManager(), true);
  188. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  189. }
  190. void Project::initialiseAudioPluginValues()
  191. {
  192. pluginFormatsValue.referTo (projectRoot, Ids::pluginFormats, getUndoManager(),
  193. Array<var> (Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildStandalone.toString()), ",");
  194. pluginCharacteristicsValue.referTo (projectRoot, Ids::pluginCharacteristicsValue, getUndoManager(), Array<var> (), ",");
  195. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  196. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  197. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), getDefaultPluginManufacturerString());
  198. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  199. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  200. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  201. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  202. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  203. CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  204. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager(), getDefaultAUMainTypes(), ",");
  205. pluginAUSandboxSafeValue.referTo (projectRoot, Ids::pluginAUIsSandboxSafe, getUndoManager(), false);
  206. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager(), getDefaultVSTCategories(), ",");
  207. pluginVST3CategoryValue.referTo (projectRoot, Ids::pluginVST3Category, getUndoManager(), getDefaultVST3Categories(), ",");
  208. pluginRTASCategoryValue.referTo (projectRoot, Ids::pluginRTASCategory, getUndoManager(), getDefaultRTASCategories(), ",");
  209. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), getDefaultAAXCategories(), ",");
  210. }
  211. void Project::updateOldStyleConfigList()
  212. {
  213. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  214. if (deprecatedConfigsList.isValid())
  215. {
  216. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  217. for (Project::ExporterIterator exporter (*this); exporter.next();)
  218. {
  219. if (exporter->getNumConfigurations() == 0)
  220. {
  221. auto newConfigs = deprecatedConfigsList.createCopy();
  222. if (! exporter->isXcode())
  223. {
  224. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  225. {
  226. auto config = newConfigs.getChild (j);
  227. config.removeProperty (Ids::osxSDK, nullptr);
  228. config.removeProperty (Ids::osxCompatibility, nullptr);
  229. config.removeProperty (Ids::osxArchitecture, nullptr);
  230. }
  231. }
  232. exporter->settings.addChild (newConfigs, 0, nullptr);
  233. }
  234. }
  235. }
  236. }
  237. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  238. {
  239. if (projectRoot.hasProperty (name))
  240. {
  241. for (Project::ExporterIterator exporter (*this); exporter.next();)
  242. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  243. projectRoot.removeProperty (name, nullptr);
  244. }
  245. }
  246. void Project::removeDefunctExporters()
  247. {
  248. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  249. StringPairArray oldExporters;
  250. oldExporters.set ("ANDROID", "Android Ant Exporter");
  251. oldExporters.set ("MSVC6", "MSVC6");
  252. oldExporters.set ("VS2010", "Visual Studio 2010");
  253. oldExporters.set ("VS2012", "Visual Studio 2012");
  254. for (auto& key : oldExporters.getAllKeys())
  255. {
  256. auto oldExporter = exporters.getChildWithName (key);
  257. if (oldExporter.isValid())
  258. {
  259. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  260. TRANS (oldExporters[key]),
  261. TRANS ("The " + oldExporters[key] + " Exporter is deprecated. The exporter will be removed from this project."));
  262. exporters.removeChild (oldExporter, nullptr);
  263. }
  264. }
  265. }
  266. void Project::updateOldModulePaths()
  267. {
  268. for (Project::ExporterIterator exporter (*this); exporter.next();)
  269. exporter->updateOldModulePaths();
  270. }
  271. Array<Identifier> Project::getLegacyPluginFormatIdentifiers() noexcept
  272. {
  273. static Array<Identifier> legacyPluginFormatIdentifiers { Ids::buildVST, Ids::buildVST3, Ids::buildAU, Ids::buildAUv3,
  274. Ids::buildRTAS, Ids::buildAAX, Ids::buildStandalone, Ids::enableIAA };
  275. return legacyPluginFormatIdentifiers;
  276. }
  277. Array<Identifier> Project::getLegacyPluginCharacteristicsIdentifiers() noexcept
  278. {
  279. static Array<Identifier> legacyPluginCharacteristicsIdentifiers { Ids::pluginIsSynth, Ids::pluginWantsMidiIn, Ids::pluginProducesMidiOut,
  280. Ids::pluginIsMidiEffectPlugin, Ids::pluginEditorRequiresKeys, Ids::pluginRTASDisableBypass,
  281. Ids::pluginRTASDisableMultiMono, Ids::pluginAAXDisableBypass, Ids::pluginAAXDisableMultiMono };
  282. return legacyPluginCharacteristicsIdentifiers;
  283. }
  284. void Project::coalescePluginFormatValues()
  285. {
  286. Array<var> formatsToBuild;
  287. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  288. {
  289. if (projectRoot.getProperty (formatIdentifier, false))
  290. formatsToBuild.add (formatIdentifier.toString());
  291. }
  292. if (formatsToBuild.size() > 0)
  293. {
  294. if (pluginFormatsValue.isUsingDefault())
  295. {
  296. pluginFormatsValue = formatsToBuild;
  297. }
  298. else
  299. {
  300. auto formatVar = pluginFormatsValue.get();
  301. if (auto* arr = formatVar.getArray())
  302. arr->addArray (formatsToBuild);
  303. }
  304. shouldWriteLegacyPluginFormatSettings = true;
  305. }
  306. }
  307. void Project::coalescePluginCharacteristicsValues()
  308. {
  309. Array<var> pluginCharacteristics;
  310. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  311. {
  312. if (projectRoot.getProperty (characteristicIdentifier, false))
  313. pluginCharacteristics.add (characteristicIdentifier.toString());
  314. }
  315. if (pluginCharacteristics.size() > 0)
  316. {
  317. pluginCharacteristicsValue = pluginCharacteristics;
  318. shouldWriteLegacyPluginCharacteristicsSettings = true;
  319. }
  320. }
  321. void Project::updatePluginCategories()
  322. {
  323. {
  324. auto aaxCategory = projectRoot.getProperty (Ids::pluginAAXCategory, {}).toString();
  325. if (getAllAAXCategoryVars().contains (aaxCategory))
  326. pluginAAXCategoryValue = aaxCategory;
  327. else if (getAllAAXCategoryStrings().contains (aaxCategory))
  328. pluginAAXCategoryValue = Array<var> (getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf (aaxCategory)]);
  329. }
  330. {
  331. auto rtasCategory = projectRoot.getProperty (Ids::pluginRTASCategory, {}).toString();
  332. if (getAllRTASCategoryVars().contains (rtasCategory))
  333. pluginRTASCategoryValue = rtasCategory;
  334. else if (getAllRTASCategoryStrings().contains (rtasCategory))
  335. pluginRTASCategoryValue = Array<var> (getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf (rtasCategory)]);
  336. }
  337. {
  338. auto vstCategory = projectRoot.getProperty (Ids::pluginVSTCategory, {}).toString();
  339. if (vstCategory.isNotEmpty() && getAllVSTCategoryStrings().contains (vstCategory))
  340. pluginVSTCategoryValue = Array<var> (vstCategory);
  341. else
  342. pluginVSTCategoryValue.resetToDefault();
  343. }
  344. {
  345. auto auMainType = projectRoot.getProperty (Ids::pluginAUMainType, {}).toString();
  346. if (auMainType.isNotEmpty())
  347. {
  348. if (getAllAUMainTypeVars().contains (auMainType))
  349. pluginAUMainTypeValue = Array<var> (auMainType);
  350. else if (getAllAUMainTypeVars().contains (auMainType.quoted ('\'')))
  351. pluginAUMainTypeValue = Array<var> (auMainType.quoted ('\''));
  352. else if (getAllAUMainTypeStrings().contains (auMainType))
  353. pluginAUMainTypeValue = Array<var> (getAllAUMainTypeVars()[getAllAUMainTypeStrings().indexOf (auMainType)]);
  354. }
  355. else
  356. {
  357. pluginAUMainTypeValue.resetToDefault();
  358. }
  359. }
  360. }
  361. void Project::writeLegacyPluginFormatSettings()
  362. {
  363. if (pluginFormatsValue.isUsingDefault())
  364. {
  365. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  366. projectRoot.removeProperty (formatIdentifier, nullptr);
  367. }
  368. else
  369. {
  370. auto formatVar = pluginFormatsValue.get();
  371. if (auto* arr = formatVar.getArray())
  372. {
  373. for (auto& formatIdentifier : getLegacyPluginFormatIdentifiers())
  374. projectRoot.setProperty (formatIdentifier, arr->contains (formatIdentifier.toString()), nullptr);
  375. }
  376. }
  377. }
  378. void Project::writeLegacyPluginCharacteristicsSettings()
  379. {
  380. if (pluginFormatsValue.isUsingDefault())
  381. {
  382. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  383. projectRoot.removeProperty (characteristicIdentifier, nullptr);
  384. }
  385. else
  386. {
  387. auto characteristicsVar = pluginCharacteristicsValue.get();
  388. if (auto* arr = characteristicsVar.getArray())
  389. {
  390. for (auto& characteristicIdentifier : getLegacyPluginCharacteristicsIdentifiers())
  391. projectRoot.setProperty (characteristicIdentifier, arr->contains (characteristicIdentifier.toString()), nullptr);
  392. }
  393. }
  394. }
  395. //==============================================================================
  396. static int getVersionElement (StringRef v, int index)
  397. {
  398. StringArray parts = StringArray::fromTokens (v, "., ", {});
  399. return parts [parts.size() - index - 1].getIntValue();
  400. }
  401. static int getJuceVersion (const String& v)
  402. {
  403. return getVersionElement (v, 2) * 100000
  404. + getVersionElement (v, 1) * 1000
  405. + getVersionElement (v, 0);
  406. }
  407. static int getBuiltJuceVersion()
  408. {
  409. return JUCE_MAJOR_VERSION * 100000
  410. + JUCE_MINOR_VERSION * 1000
  411. + JUCE_BUILDNUMBER;
  412. }
  413. static bool isModuleNewerThanProjucer (const ModuleDescription& module)
  414. {
  415. if (module.getID().startsWith ("juce_")
  416. && getJuceVersion (module.getVersion()) > getBuiltJuceVersion())
  417. return true;
  418. return false;
  419. }
  420. void Project::warnAboutOldProjucerVersion()
  421. {
  422. for (auto& juceModule : ProjucerApplication::getApp().getJUCEPathModuleList().getAllModules())
  423. {
  424. if (isModuleNewerThanProjucer ({ juceModule.second }))
  425. {
  426. // Projucer is out of date!
  427. if (ProjucerApplication::getApp().isRunningCommandLine)
  428. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  429. else
  430. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  431. "Projucer",
  432. "This version of the Projucer is out-of-date!"
  433. "\n\n"
  434. "Always make sure that you're running the very latest version, "
  435. "preferably compiled directly from the JUCE repository that you're working with!");
  436. return;
  437. }
  438. }
  439. }
  440. //==============================================================================
  441. static File lastDocumentOpened;
  442. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  443. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  444. static void registerRecentFile (const File& file)
  445. {
  446. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  447. getAppSettings().recentFiles.addFile (file);
  448. getAppSettings().flush();
  449. }
  450. static void forgetRecentFile (const File& file)
  451. {
  452. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  453. getAppSettings().recentFiles.removeFile (file);
  454. getAppSettings().flush();
  455. }
  456. //==============================================================================
  457. Result Project::loadDocument (const File& file)
  458. {
  459. auto xml = parseXML (file);
  460. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  461. return Result::fail ("Not a valid Jucer project!");
  462. auto newTree = ValueTree::fromXml (*xml);
  463. if (! newTree.hasType (Ids::JUCERPROJECT))
  464. return Result::fail ("The document contains errors and couldn't be parsed!");
  465. registerRecentFile (file);
  466. enabledModuleList.reset();
  467. projectRoot = newTree;
  468. initialiseProjectValues();
  469. initialiseMainGroup();
  470. initialiseAudioPluginValues();
  471. coalescePluginFormatValues();
  472. coalescePluginCharacteristicsValues();
  473. updatePluginCategories();
  474. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  475. removeDefunctExporters();
  476. updateOldModulePaths();
  477. setChangedFlag (false);
  478. if (! ProjucerApplication::getApp().isRunningCommandLine)
  479. warnAboutOldProjucerVersion();
  480. compileEngineSettings.reset (new CompileEngineSettings (projectRoot));
  481. exporterPathsModuleList.reset (new AvailableModuleList());
  482. rescanExporterPathModules (! ProjucerApplication::getApp().isRunningCommandLine);
  483. return Result::ok();
  484. }
  485. Result Project::saveDocument (const File& file)
  486. {
  487. return saveProject (file, false);
  488. }
  489. Result Project::saveProject (const File& file, bool isCommandLineApp)
  490. {
  491. if (isSaving)
  492. return Result::ok();
  493. if (isTemporaryProject())
  494. {
  495. askUserWhereToSaveProject();
  496. return Result::ok();
  497. }
  498. updateProjectSettings();
  499. if (! isCommandLineApp)
  500. {
  501. ProjucerApplication::getApp().openDocumentManager.saveAll();
  502. if (! isTemporaryProject())
  503. registerRecentFile (file);
  504. }
  505. const ScopedValueSetter<bool> vs (isSaving, true, false);
  506. ProjectSaver saver (*this, file);
  507. return saver.save (! isCommandLineApp, shouldWaitAfterSaving, specifiedExporterToSave);
  508. }
  509. Result Project::saveResourcesOnly (const File& file)
  510. {
  511. ProjectSaver saver (*this, file);
  512. return saver.saveResourcesOnly();
  513. }
  514. //==============================================================================
  515. void Project::setTemporaryDirectory (const File& dir) noexcept
  516. {
  517. tempDirectory = dir;
  518. // remove this file from the recent documents list as it is a temporary project
  519. forgetRecentFile (getFile());
  520. }
  521. void Project::askUserWhereToSaveProject()
  522. {
  523. FileChooser fc ("Save Project");
  524. fc.browseForDirectory();
  525. if (fc.getResult().exists())
  526. moveTemporaryDirectory (fc.getResult());
  527. }
  528. void Project::moveTemporaryDirectory (const File& newParentDirectory)
  529. {
  530. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  531. auto oldJucerFileName = getFile().getFileName();
  532. saveProjectRootToFile();
  533. tempDirectory.copyDirectoryTo (newDirectory);
  534. tempDirectory.deleteRecursively();
  535. tempDirectory = File();
  536. // reload project from new location
  537. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  538. {
  539. Component::SafePointer<MainWindow> safeWindow (window);
  540. MessageManager::callAsync ([safeWindow, newDirectory, oldJucerFileName]
  541. {
  542. if (safeWindow != nullptr)
  543. safeWindow.getComponent()->moveProject (newDirectory.getChildFile (oldJucerFileName));
  544. });
  545. }
  546. }
  547. bool Project::saveProjectRootToFile()
  548. {
  549. std::unique_ptr<XmlElement> xml (projectRoot.createXml());
  550. if (xml == nullptr)
  551. {
  552. jassertfalse;
  553. return false;
  554. }
  555. MemoryOutputStream mo;
  556. xml->writeToStream (mo, {});
  557. return FileHelpers::overwriteFileWithNewDataIfDifferent (getFile(), mo);
  558. }
  559. //==============================================================================
  560. static void sendProjectSettingAnalyticsEvent (StringRef label)
  561. {
  562. StringPairArray data;
  563. data.set ("label", label);
  564. Analytics::getInstance()->logEvent ("Project Setting", data, ProjucerAnalyticsEvent::projectEvent);
  565. }
  566. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  567. {
  568. if (tree.getRoot() == tree)
  569. {
  570. if (property == Ids::projectType)
  571. {
  572. sendChangeMessage();
  573. sendProjectSettingAnalyticsEvent ("Project Type = " + projectTypeValue.get().toString());
  574. }
  575. else if (property == Ids::name)
  576. {
  577. updateTitleDependencies();
  578. }
  579. else if (property == Ids::companyName)
  580. {
  581. updateCompanyNameDependencies();
  582. }
  583. else if (property == Ids::defines)
  584. {
  585. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  586. }
  587. else if (property == Ids::cppLanguageStandard)
  588. {
  589. sendProjectSettingAnalyticsEvent ("C++ Standard = " + cppStandardValue.get().toString());
  590. }
  591. else if (property == Ids::pluginFormats)
  592. {
  593. if (shouldWriteLegacyPluginFormatSettings)
  594. writeLegacyPluginFormatSettings();
  595. }
  596. else if (property == Ids::pluginCharacteristicsValue)
  597. {
  598. pluginAUMainTypeValue.setDefault (getDefaultAUMainTypes());
  599. pluginVSTCategoryValue.setDefault (getDefaultVSTCategories());
  600. pluginVST3CategoryValue.setDefault (getDefaultVST3Categories());
  601. pluginRTASCategoryValue.setDefault (getDefaultRTASCategories());
  602. pluginAAXCategoryValue.setDefault (getDefaultAAXCategories());
  603. if (shouldWriteLegacyPluginCharacteristicsSettings)
  604. writeLegacyPluginCharacteristicsSettings();
  605. }
  606. changed();
  607. }
  608. }
  609. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  610. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  611. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  612. void Project::valueTreeParentChanged (ValueTree&) {}
  613. //==============================================================================
  614. bool Project::hasProjectBeenModified()
  615. {
  616. auto oldModificationTime = modificationTime;
  617. modificationTime = getFile().getLastModificationTime();
  618. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  619. }
  620. //==============================================================================
  621. File Project::resolveFilename (String filename) const
  622. {
  623. if (filename.isEmpty())
  624. return {};
  625. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  626. #if ! JUCE_WINDOWS
  627. if (filename.startsWith ("~"))
  628. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  629. #endif
  630. if (FileHelpers::isAbsolutePath (filename))
  631. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  632. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  633. }
  634. String Project::getRelativePathForFile (const File& file) const
  635. {
  636. auto filename = file.getFullPathName();
  637. auto relativePathBase = getFile().getParentDirectory();
  638. auto p1 = relativePathBase.getFullPathName();
  639. auto p2 = file.getFullPathName();
  640. while (p1.startsWithChar (File::getSeparatorChar()))
  641. p1 = p1.substring (1);
  642. while (p2.startsWithChar (File::getSeparatorChar()))
  643. p2 = p2.substring (1);
  644. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  645. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  646. {
  647. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  648. }
  649. return filename;
  650. }
  651. //==============================================================================
  652. const ProjectType& Project::getProjectType() const
  653. {
  654. if (auto* type = ProjectType::findType (getProjectTypeString()))
  655. return *type;
  656. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  657. jassert (guiType != nullptr);
  658. return *guiType;
  659. }
  660. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  661. {
  662. auto& projectType = getProjectType();
  663. if (! projectType.supportsTargetType (targetType))
  664. return false;
  665. switch (targetType)
  666. {
  667. case ProjectType::Target::VSTPlugIn:
  668. return shouldBuildVST();
  669. case ProjectType::Target::VST3PlugIn:
  670. return shouldBuildVST3();
  671. case ProjectType::Target::AAXPlugIn:
  672. return shouldBuildAAX();
  673. case ProjectType::Target::RTASPlugIn:
  674. return shouldBuildRTAS();
  675. case ProjectType::Target::AudioUnitPlugIn:
  676. return shouldBuildAU();
  677. case ProjectType::Target::AudioUnitv3PlugIn:
  678. return shouldBuildAUv3();
  679. case ProjectType::Target::StandalonePlugIn:
  680. return shouldBuildStandalonePlugin();
  681. case ProjectType::Target::UnityPlugIn:
  682. return shouldBuildUnityPlugin();
  683. case ProjectType::Target::AggregateTarget:
  684. case ProjectType::Target::SharedCodeTarget:
  685. return projectType.isAudioPlugin();
  686. case ProjectType::Target::unspecified:
  687. return false;
  688. default:
  689. break;
  690. }
  691. return true;
  692. }
  693. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  694. {
  695. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  696. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  697. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  698. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  699. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  700. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  701. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  702. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Unity")) return ProjectType::Target::UnityPlugIn;
  703. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  704. }
  705. const char* ProjectType::Target::getName() const noexcept
  706. {
  707. switch (type)
  708. {
  709. case GUIApp: return "App";
  710. case ConsoleApp: return "ConsoleApp";
  711. case StaticLibrary: return "Static Library";
  712. case DynamicLibrary: return "Dynamic Library";
  713. case VSTPlugIn: return "VST";
  714. case VST3PlugIn: return "VST3";
  715. case AudioUnitPlugIn: return "AU";
  716. case StandalonePlugIn: return "Standalone Plugin";
  717. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  718. case AAXPlugIn: return "AAX";
  719. case RTASPlugIn: return "RTAS";
  720. case UnityPlugIn: return "Unity Plugin";
  721. case SharedCodeTarget: return "Shared Code";
  722. case AggregateTarget: return "All";
  723. default: return "undefined";
  724. }
  725. }
  726. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  727. {
  728. switch (type)
  729. {
  730. case GUIApp: return executable;
  731. case ConsoleApp: return executable;
  732. case StaticLibrary: return staticLibrary;
  733. case DynamicLibrary: return sharedLibraryOrDLL;
  734. case VSTPlugIn: return pluginBundle;
  735. case VST3PlugIn: return pluginBundle;
  736. case AudioUnitPlugIn: return pluginBundle;
  737. case StandalonePlugIn: return executable;
  738. case AudioUnitv3PlugIn: return macOSAppex;
  739. case AAXPlugIn: return pluginBundle;
  740. case RTASPlugIn: return pluginBundle;
  741. case UnityPlugIn: return pluginBundle;
  742. case SharedCodeTarget: return staticLibrary;
  743. default:
  744. break;
  745. }
  746. return unknown;
  747. }
  748. //==============================================================================
  749. void Project::createPropertyEditors (PropertyListBuilder& props)
  750. {
  751. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  752. "The name of the project.");
  753. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  754. "The project's version number. This should be in the format major.minor.point[.point] where you should omit the final "
  755. "(optional) [.point] if you are targeting AU and AUv3 plug-ins as they only support three number versions.");
  756. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  757. "Your company name, which will be added to the properties of the binary where possible");
  758. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  759. "Your company copyright, which will be added to the properties of the binary where possible");
  760. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  761. "Your company website, which will be added to the properties of the binary where possible");
  762. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  763. "Your company e-mail, which will be added to the properties of the binary where possible");
  764. {
  765. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  766. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  767. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  768. "license, or are using JUCE under the GPL v3 license.");
  769. StringPairArray description;
  770. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  771. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  772. if (ProjucerApplication::getApp().isPaidOrGPL())
  773. {
  774. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  775. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  776. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  777. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  778. }
  779. else
  780. {
  781. StringArray options;
  782. Array<var> vars;
  783. options.add (licenseRequiredTagline);
  784. vars.add (var());
  785. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  786. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  787. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  788. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  789. }
  790. }
  791. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  792. { "Dark", "Light" },
  793. { "Dark", "Light" }),
  794. "Choose the colour of the JUCE splash screen.");
  795. {
  796. StringArray projectTypeNames;
  797. Array<var> projectTypeCodes;
  798. auto types = ProjectType::getAllTypes();
  799. for (int i = 0; i < types.size(); ++i)
  800. {
  801. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  802. projectTypeCodes.add (types.getUnchecked(i)->getType());
  803. }
  804. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  805. "The project type for which settings should be shown.");
  806. }
  807. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  808. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  809. if (getProjectType().isAudioPlugin())
  810. createAudioPluginPropertyEditors (props);
  811. {
  812. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  813. StringArray maxSizeNames;
  814. Array<var> maxSizeCodes;
  815. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  816. {
  817. auto sizeInBytes = maxSizes[i] * 1024;
  818. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  819. maxSizeCodes.add (sizeInBytes);
  820. }
  821. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  822. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  823. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  824. }
  825. props.add (new ChoicePropertyComponent (includeBinaryDataInJuceHeaderValue, "Include BinaryData in JuceHeader"),
  826. "Include BinaryData.h in the JuceHeader.h file");
  827. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  828. "The namespace containing the binary assests.");
  829. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  830. { "C++11", "C++14", "C++17", "Use Latest" },
  831. { "11", "14", "17", "latest" }),
  832. "The standard of the C++ language that will be used for compilation.");
  833. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  834. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  835. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  836. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  837. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  838. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  839. }
  840. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  841. {
  842. props.add (new MultiChoicePropertyComponent (pluginFormatsValue, "Plugin Formats",
  843. { "VST3", "AU", "AUv3", "RTAS", "AAX", "Standalone", "Unity", "Enable IAA", "VST (Legacy)" },
  844. { Ids::buildVST3.toString(), Ids::buildAU.toString(), Ids::buildAUv3.toString(),
  845. Ids::buildRTAS.toString(), Ids::buildAAX.toString(), Ids::buildStandalone.toString(), Ids::buildUnity.toString(),
  846. Ids::enableIAA.toString(), Ids::buildVST.toString() }),
  847. "Plugin formats to build. If you have selected \"VST (Legacy)\" then you will need to ensure that you have a VST2 SDK "
  848. "in your header search paths. The VST2 SDK can be obtained from the vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK "
  849. "or JUCE version 5.3.2. You also need a VST2 license from Steinberg to distribute VST2 plug-ins.");
  850. props.add (new MultiChoicePropertyComponent (pluginCharacteristicsValue, "Plugin Characteristics",
  851. { "Plugin is a Synth", "Plugin MIDI Input", "Plugin MIDI Output", "MIDI Effect Plugin", "Plugin Editor Requires Keyboard Focus",
  852. "Disable RTAS Bypass", "Disable AAX Bypass", "Disable RTAS Multi-Mono", "Disable AAX Multi-Mono" },
  853. { Ids::pluginIsSynth.toString(), Ids::pluginWantsMidiIn.toString(), Ids::pluginProducesMidiOut.toString(),
  854. Ids::pluginIsMidiEffectPlugin.toString(), Ids::pluginEditorRequiresKeys.toString(), Ids::pluginRTASDisableBypass.toString(),
  855. Ids::pluginAAXDisableBypass.toString(), Ids::pluginRTASDisableMultiMono.toString(), Ids::pluginAAXDisableMultiMono.toString() }),
  856. "Some characteristics of your plugin such as whether it is a synth, produces MIDI messages, accepts MIDI messages etc.");
  857. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  858. "The name of your plugin (keep it short!)");
  859. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  860. "A short description of your plugin.");
  861. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  862. "The name of your company (cannot be blank).");
  863. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  864. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  865. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  866. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  867. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  868. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  869. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  870. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  871. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  872. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  873. "The value to use for the JucePlugin_AAXIdentifier setting");
  874. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  875. "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.");
  876. props.add (new MultiChoicePropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", getAllAUMainTypeStrings(), getAllAUMainTypeVars(), 1),
  877. "AU main type.");
  878. props.add (new ChoicePropertyComponent (pluginAUSandboxSafeValue, "Plugin AU is sandbox safe"),
  879. "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 "
  880. "the Music folder. Your plug-in must be able to deal with this. Newer versions of GarageBand require this to be enabled.");
  881. {
  882. Array<var> vst3CategoryVars;
  883. for (auto s : getAllVST3CategoryStrings())
  884. vst3CategoryVars.add (s);
  885. props.add (new MultiChoicePropertyComponent (pluginVST3CategoryValue, "Plugin VST3 Category", getAllVST3CategoryStrings(), vst3CategoryVars),
  886. "VST3 category. Most hosts require either \"Fx\" or \"Instrument\" to be selected in order for the plugin to be recognised. "
  887. "If neither of these are selected, the appropriate one will be automatically added based on the \"Plugin is a synth\" option.");
  888. }
  889. props.add (new MultiChoicePropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", getAllRTASCategoryStrings(), getAllRTASCategoryVars()),
  890. "RTAS category.");
  891. props.add (new MultiChoicePropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", getAllAAXCategoryStrings(), getAllAAXCategoryVars()),
  892. "AAX category.");
  893. {
  894. Array<var> vstCategoryVars;
  895. for (auto s : getAllVSTCategoryStrings())
  896. vstCategoryVars.add (s);
  897. props.add (new MultiChoicePropertyComponent (pluginVSTCategoryValue, "Plugin VST (Legacy) Category", getAllVSTCategoryStrings(), vstCategoryVars, 1),
  898. "VST category.");
  899. }
  900. }
  901. //==============================================================================
  902. static StringArray getVersionSegments (const Project& p)
  903. {
  904. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  905. segments.trim();
  906. segments.removeEmptyStrings();
  907. return segments;
  908. }
  909. int Project::getVersionAsHexInteger() const
  910. {
  911. auto segments = getVersionSegments (*this);
  912. auto value = (segments[0].getIntValue() << 16)
  913. + (segments[1].getIntValue() << 8)
  914. + segments[2].getIntValue();
  915. if (segments.size() > 3)
  916. value = (value << 8) + segments[3].getIntValue();
  917. return value;
  918. }
  919. String Project::getVersionAsHex() const
  920. {
  921. return "0x" + String::toHexString (getVersionAsHexInteger());
  922. }
  923. File Project::getBinaryDataCppFile (int index) const
  924. {
  925. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  926. if (index > 0)
  927. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  928. .withFileExtension (cpp.getFileExtension());
  929. return cpp;
  930. }
  931. Project::Item Project::getMainGroup()
  932. {
  933. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  934. }
  935. PropertiesFile& Project::getStoredProperties() const
  936. {
  937. return getAppSettings().getProjectProperties (getProjectUIDString());
  938. }
  939. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  940. {
  941. if (item.isImageFile())
  942. {
  943. found.add (new Project::Item (item));
  944. }
  945. else if (item.isGroup())
  946. {
  947. for (int i = 0; i < item.getNumChildren(); ++i)
  948. findImages (item.getChild (i), found);
  949. }
  950. }
  951. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  952. {
  953. findImages (getMainGroup(), items);
  954. }
  955. //==============================================================================
  956. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  957. : project (p), state (s), belongsToModule (isModuleCode)
  958. {
  959. }
  960. Project::Item::Item (const Item& other)
  961. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  962. {
  963. }
  964. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  965. String Project::Item::getID() const { return state [Ids::ID]; }
  966. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  967. Drawable* Project::Item::loadAsImageFile() const
  968. {
  969. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  970. if (! mml.lockWasGained())
  971. return nullptr;
  972. return isValid() ? Drawable::createFromImageFile (getFile())
  973. : nullptr;
  974. }
  975. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  976. {
  977. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  978. group.setID (uid);
  979. group.initialiseMissingProperties();
  980. group.getNameValue() = name;
  981. return group;
  982. }
  983. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  984. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  985. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  986. bool Project::Item::isImageFile() const
  987. {
  988. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  989. || getFile().hasFileExtension ("svg"));
  990. }
  991. Project::Item Project::Item::findItemWithID (const String& targetId) const
  992. {
  993. if (state [Ids::ID] == targetId)
  994. return *this;
  995. if (isGroup())
  996. {
  997. for (auto i = getNumChildren(); --i >= 0;)
  998. {
  999. auto found = getChild(i).findItemWithID (targetId);
  1000. if (found.isValid())
  1001. return found;
  1002. }
  1003. }
  1004. return Item (project, ValueTree(), false);
  1005. }
  1006. bool Project::Item::canContain (const Item& child) const
  1007. {
  1008. if (isFile())
  1009. return false;
  1010. if (isGroup())
  1011. return child.isFile() || child.isGroup();
  1012. jassertfalse;
  1013. return false;
  1014. }
  1015. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  1016. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  1017. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  1018. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  1019. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  1020. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  1021. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  1022. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  1023. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  1024. bool Project::Item::isModuleCode() const { return belongsToModule; }
  1025. String Project::Item::getFilePath() const
  1026. {
  1027. if (isFile())
  1028. return state [Ids::file].toString();
  1029. return {};
  1030. }
  1031. File Project::Item::getFile() const
  1032. {
  1033. if (isFile())
  1034. return project.resolveFilename (state [Ids::file].toString());
  1035. return {};
  1036. }
  1037. void Project::Item::setFile (const File& file)
  1038. {
  1039. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  1040. jassert (getFile() == file);
  1041. }
  1042. void Project::Item::setFile (const RelativePath& file)
  1043. {
  1044. jassert (isFile());
  1045. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  1046. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  1047. }
  1048. bool Project::Item::renameFile (const File& newFile)
  1049. {
  1050. auto oldFile = getFile();
  1051. if (oldFile.moveFileTo (newFile)
  1052. || (newFile.exists() && ! oldFile.exists()))
  1053. {
  1054. setFile (newFile);
  1055. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  1056. return true;
  1057. }
  1058. return false;
  1059. }
  1060. bool Project::Item::containsChildForFile (const RelativePath& file) const
  1061. {
  1062. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  1063. }
  1064. Project::Item Project::Item::findItemForFile (const File& file) const
  1065. {
  1066. if (getFile() == file)
  1067. return *this;
  1068. if (isGroup())
  1069. {
  1070. for (auto i = getNumChildren(); --i >= 0;)
  1071. {
  1072. auto found = getChild(i).findItemForFile (file);
  1073. if (found.isValid())
  1074. return found;
  1075. }
  1076. }
  1077. return Item (project, ValueTree(), false);
  1078. }
  1079. File Project::Item::determineGroupFolder() const
  1080. {
  1081. jassert (isGroup());
  1082. File f;
  1083. for (int i = 0; i < getNumChildren(); ++i)
  1084. {
  1085. f = getChild(i).getFile();
  1086. if (f.exists())
  1087. return f.getParentDirectory();
  1088. }
  1089. auto parent = getParent();
  1090. if (parent != *this)
  1091. {
  1092. f = parent.determineGroupFolder();
  1093. if (f.getChildFile (getName()).isDirectory())
  1094. f = f.getChildFile (getName());
  1095. }
  1096. else
  1097. {
  1098. f = project.getProjectFolder();
  1099. if (f.getChildFile ("Source").isDirectory())
  1100. f = f.getChildFile ("Source");
  1101. }
  1102. return f;
  1103. }
  1104. void Project::Item::initialiseMissingProperties()
  1105. {
  1106. if (! state.hasProperty (Ids::ID))
  1107. setID (createAlphaNumericUID());
  1108. if (isFile())
  1109. {
  1110. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  1111. }
  1112. else if (isGroup())
  1113. {
  1114. for (auto i = getNumChildren(); --i >= 0;)
  1115. getChild(i).initialiseMissingProperties();
  1116. }
  1117. }
  1118. Value Project::Item::getNameValue()
  1119. {
  1120. return state.getPropertyAsValue (Ids::name, getUndoManager());
  1121. }
  1122. String Project::Item::getName() const
  1123. {
  1124. return state [Ids::name];
  1125. }
  1126. void Project::Item::addChild (const Item& newChild, int insertIndex)
  1127. {
  1128. state.addChild (newChild.state, insertIndex, getUndoManager());
  1129. }
  1130. void Project::Item::removeItemFromProject()
  1131. {
  1132. state.getParent().removeChild (state, getUndoManager());
  1133. }
  1134. Project::Item Project::Item::getParent() const
  1135. {
  1136. if (isMainGroup() || ! isGroup())
  1137. return *this;
  1138. return { project, state.getParent(), belongsToModule };
  1139. }
  1140. struct ItemSorter
  1141. {
  1142. static int compareElements (const ValueTree& first, const ValueTree& second)
  1143. {
  1144. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1145. }
  1146. };
  1147. struct ItemSorterWithGroupsAtStart
  1148. {
  1149. static int compareElements (const ValueTree& first, const ValueTree& second)
  1150. {
  1151. auto firstIsGroup = first.hasType (Ids::GROUP);
  1152. auto secondIsGroup = second.hasType (Ids::GROUP);
  1153. if (firstIsGroup == secondIsGroup)
  1154. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  1155. return firstIsGroup ? -1 : 1;
  1156. }
  1157. };
  1158. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  1159. {
  1160. if (keepGroupsAtStart)
  1161. {
  1162. ItemSorterWithGroupsAtStart sorter;
  1163. state.sort (sorter, undoManager, true);
  1164. }
  1165. else
  1166. {
  1167. ItemSorter sorter;
  1168. state.sort (sorter, undoManager, true);
  1169. }
  1170. }
  1171. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  1172. {
  1173. if (state.getNumChildren() == 0)
  1174. return false;
  1175. if (state.getNumChildren() == 1)
  1176. return true;
  1177. auto stateCopy = state.createCopy();
  1178. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  1179. return stateCopy.isEquivalentTo (state);
  1180. }
  1181. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  1182. {
  1183. sortGroup (state, keepGroupsAtStart, getUndoManager());
  1184. if (recursive)
  1185. for (auto i = getNumChildren(); --i >= 0;)
  1186. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  1187. }
  1188. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  1189. {
  1190. for (auto i = state.getNumChildren(); --i >= 0;)
  1191. {
  1192. auto child = state.getChild (i);
  1193. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  1194. return { project, child, belongsToModule };
  1195. }
  1196. return addNewSubGroup (name, -1);
  1197. }
  1198. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1199. {
  1200. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1201. int n = 0;
  1202. while (project.getMainGroup().findItemWithID (newID).isValid())
  1203. newID = createGUID (newID + String (++n));
  1204. auto group = createGroup (project, name, newID, belongsToModule);
  1205. jassert (canContain (group));
  1206. addChild (group, insertIndex);
  1207. return group;
  1208. }
  1209. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1210. {
  1211. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1212. return false;
  1213. if (file.isDirectory())
  1214. {
  1215. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1216. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1217. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1218. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1219. }
  1220. else if (file.existsAsFile())
  1221. {
  1222. if (! project.getMainGroup().findItemForFile (file).isValid())
  1223. addFileUnchecked (file, insertIndex, shouldCompile);
  1224. }
  1225. else
  1226. {
  1227. jassertfalse;
  1228. }
  1229. return true;
  1230. }
  1231. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1232. {
  1233. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1234. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1235. if (! addFileAtIndex (file, 0, shouldCompile))
  1236. return false;
  1237. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1238. sortAlphabetically (wasSortedGroupsFirst, false);
  1239. return true;
  1240. }
  1241. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1242. {
  1243. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1244. item.initialiseMissingProperties();
  1245. item.getNameValue() = file.getFileName();
  1246. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1247. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1248. if (canContain (item))
  1249. {
  1250. item.setFile (file);
  1251. addChild (item, insertIndex);
  1252. }
  1253. }
  1254. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1255. {
  1256. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1257. item.initialiseMissingProperties();
  1258. item.getNameValue() = file.getFileName();
  1259. item.getShouldCompileValue() = shouldCompile;
  1260. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1261. if (canContain (item))
  1262. {
  1263. item.setFile (file);
  1264. addChild (item, insertIndex);
  1265. return true;
  1266. }
  1267. return false;
  1268. }
  1269. Icon Project::Item::getIcon (bool isOpen) const
  1270. {
  1271. auto& icons = getIcons();
  1272. if (isFile())
  1273. {
  1274. if (isImageFile())
  1275. return Icon (icons.imageDoc, Colours::transparentBlack);
  1276. return { icons.file, Colours::transparentBlack };
  1277. }
  1278. if (isMainGroup())
  1279. return { icons.juceLogo, Colours::orange };
  1280. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1281. }
  1282. bool Project::Item::isIconCrossedOut() const
  1283. {
  1284. return isFile()
  1285. && ! (shouldBeCompiled()
  1286. || shouldBeAddedToBinaryResources()
  1287. || getFile().hasFileExtension (headerFileExtensions));
  1288. }
  1289. bool Project::Item::needsSaving() const noexcept
  1290. {
  1291. auto& odm = ProjucerApplication::getApp().openDocumentManager;
  1292. if (odm.anyFilesNeedSaving())
  1293. {
  1294. for (int i = 0; i < odm.getNumOpenDocuments(); ++i)
  1295. {
  1296. auto* doc = odm.getOpenDocument (i);
  1297. if (doc->needsSaving() && doc->getFile() == getFile())
  1298. return true;
  1299. }
  1300. }
  1301. return false;
  1302. }
  1303. //==============================================================================
  1304. ValueTree Project::getConfigNode()
  1305. {
  1306. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1307. }
  1308. ValueWithDefault Project::getConfigFlag (const String& name)
  1309. {
  1310. auto configNode = getConfigNode();
  1311. return { configNode, name, getUndoManagerFor (configNode) };
  1312. }
  1313. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1314. {
  1315. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1316. if (configValue == "default")
  1317. return defaultIsEnabled;
  1318. return configValue;
  1319. }
  1320. //==============================================================================
  1321. static String getCompanyNameOrDefault (StringRef str)
  1322. {
  1323. if (str.isEmpty())
  1324. return "yourcompany";
  1325. return str;
  1326. }
  1327. String Project::getDefaultBundleIdentifierString() const
  1328. {
  1329. return "com." + getCompanyNameOrDefault (getCompanyNameString()) + "." + CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false);
  1330. }
  1331. String Project::getDefaultPluginManufacturerString() const
  1332. {
  1333. return getCompanyNameOrDefault (getCompanyNameString());
  1334. }
  1335. String Project::getAUMainTypeString() const noexcept
  1336. {
  1337. auto v = pluginAUMainTypeValue.get();
  1338. if (auto* arr = v.getArray())
  1339. return arr->getFirst().toString();
  1340. jassertfalse;
  1341. return {};
  1342. }
  1343. bool Project::isAUSandBoxSafe() const noexcept
  1344. {
  1345. return pluginAUSandboxSafeValue.get();
  1346. }
  1347. String Project::getVSTCategoryString() const noexcept
  1348. {
  1349. auto v = pluginVSTCategoryValue.get();
  1350. if (auto* arr = v.getArray())
  1351. return arr->getFirst().toString();
  1352. jassertfalse;
  1353. return {};
  1354. }
  1355. static String getVST3CategoryStringFromSelection (Array<var> selected, const Project& p) noexcept
  1356. {
  1357. StringArray categories;
  1358. for (auto& category : selected)
  1359. categories.add (category);
  1360. // One of these needs to be selected in order for the plug-in to be recognised in Cubase
  1361. if (! categories.contains ("Fx") && ! categories.contains ("Instrument"))
  1362. {
  1363. categories.insert (0, p.isPluginSynth() ? "Instrument"
  1364. : "Fx");
  1365. }
  1366. else
  1367. {
  1368. // "Fx" and "Instrument" should come first and if both are present prioritise "Fx"
  1369. if (categories.contains ("Instrument"))
  1370. categories.move (categories.indexOf ("Instrument"), 0);
  1371. if (categories.contains ("Fx"))
  1372. categories.move (categories.indexOf ("Fx"), 0);
  1373. }
  1374. return categories.joinIntoString ("|");
  1375. }
  1376. String Project::getVST3CategoryString() const noexcept
  1377. {
  1378. auto v = pluginVST3CategoryValue.get();
  1379. if (auto* arr = v.getArray())
  1380. return getVST3CategoryStringFromSelection (*arr, *this);
  1381. jassertfalse;
  1382. return {};
  1383. }
  1384. int Project::getAAXCategory() const noexcept
  1385. {
  1386. int res = 0;
  1387. auto v = pluginAAXCategoryValue.get();
  1388. if (auto* arr = v.getArray())
  1389. {
  1390. for (auto c : *arr)
  1391. res |= static_cast<int> (c);
  1392. }
  1393. return res;
  1394. }
  1395. int Project::getRTASCategory() const noexcept
  1396. {
  1397. int res = 0;
  1398. auto v = pluginRTASCategoryValue.get();
  1399. if (auto* arr = v.getArray())
  1400. {
  1401. for (auto c : *arr)
  1402. res |= static_cast<int> (c);
  1403. }
  1404. return res;
  1405. }
  1406. String Project::getIAATypeCode()
  1407. {
  1408. String s;
  1409. if (pluginWantsMidiInput())
  1410. {
  1411. if (isPluginSynth())
  1412. s = "auri";
  1413. else
  1414. s = "aurm";
  1415. }
  1416. else
  1417. {
  1418. if (isPluginSynth())
  1419. s = "aurg";
  1420. else
  1421. s = "aurx";
  1422. }
  1423. return s;
  1424. }
  1425. String Project::getIAAPluginName()
  1426. {
  1427. auto s = getPluginManufacturerString();
  1428. s << ": ";
  1429. s << getPluginNameString();
  1430. return s;
  1431. }
  1432. //==============================================================================
  1433. bool Project::isAUPluginHost()
  1434. {
  1435. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1436. }
  1437. bool Project::isVSTPluginHost()
  1438. {
  1439. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1440. }
  1441. bool Project::isVST3PluginHost()
  1442. {
  1443. return getEnabledModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1444. }
  1445. //==============================================================================
  1446. StringArray Project::getAllAUMainTypeStrings() noexcept
  1447. {
  1448. static StringArray auMainTypeStrings { "kAudioUnitType_Effect", "kAudioUnitType_FormatConverter", "kAudioUnitType_Generator", "kAudioUnitType_MIDIProcessor",
  1449. "kAudioUnitType_Mixer", "kAudioUnitType_MusicDevice", "kAudioUnitType_MusicEffect", "kAudioUnitType_OfflineEffect",
  1450. "kAudioUnitType_Output", "kAudioUnitType_Panner" };
  1451. return auMainTypeStrings;
  1452. }
  1453. Array<var> Project::getAllAUMainTypeVars() noexcept
  1454. {
  1455. static Array<var> auMainTypeVars { "'aufx'", "'aufc'", "'augn'", "'aumi'",
  1456. "'aumx'", "'aumu'", "'aumf'", "'auol'",
  1457. "'auou'", "'aupn'" };
  1458. return auMainTypeVars;
  1459. }
  1460. Array<var> Project::getDefaultAUMainTypes() const noexcept
  1461. {
  1462. if (isPluginMidiEffect()) return { "'aumi'" };
  1463. if (isPluginSynth()) return { "'aumu'" };
  1464. if (pluginWantsMidiInput()) return { "'aumf'" };
  1465. return { "'aufx'" };
  1466. }
  1467. StringArray Project::getAllVSTCategoryStrings() noexcept
  1468. {
  1469. static StringArray vstCategoryStrings { "kPlugCategUnknown", "kPlugCategEffect", "kPlugCategSynth", "kPlugCategAnalysis", "kPlugCategMastering",
  1470. "kPlugCategSpacializer", "kPlugCategRoomFx", "kPlugSurroundFx", "kPlugCategRestoration", "kPlugCategOfflineProcess",
  1471. "kPlugCategShell", "kPlugCategGenerator" };
  1472. return vstCategoryStrings;
  1473. }
  1474. Array<var> Project::getDefaultVSTCategories() const noexcept
  1475. {
  1476. if (isPluginSynth())
  1477. return { "kPlugCategSynth" };
  1478. return { "kPlugCategEffect" };
  1479. }
  1480. StringArray Project::getAllVST3CategoryStrings() noexcept
  1481. {
  1482. static StringArray vst3CategoryStrings { "Fx", "Instrument", "Analyzer", "Delay", "Distortion", "Drum", "Dynamics", "EQ", "External", "Filter",
  1483. "Generator", "Mastering", "Modulation", "Mono", "Network", "NoOfflineProcess", "OnlyOfflineProcess", "OnlyRT",
  1484. "Pitch Shift", "Restoration", "Reverb", "Sampler", "Spatial", "Stereo", "Surround", "Synth", "Tools", "Up-Downmix" };
  1485. return vst3CategoryStrings;
  1486. }
  1487. Array<var> Project::getDefaultVST3Categories() const noexcept
  1488. {
  1489. if (isPluginSynth())
  1490. return { "Instrument", "Synth" };
  1491. return { "Fx" };
  1492. }
  1493. StringArray Project::getAllAAXCategoryStrings() noexcept
  1494. {
  1495. static StringArray aaxCategoryStrings { "AAX_ePlugInCategory_None", "AAX_ePlugInCategory_EQ", "AAX_ePlugInCategory_Dynamics", "AAX_ePlugInCategory_PitchShift",
  1496. "AAX_ePlugInCategory_Reverb", "AAX_ePlugInCategory_Delay", "AAX_ePlugInCategory_Modulation", "AAX_ePlugInCategory_Harmonic",
  1497. "AAX_ePlugInCategory_NoiseReduction", "AAX_ePlugInCategory_Dither", "AAX_ePlugInCategory_SoundField", "AAX_ePlugInCategory_HWGenerators",
  1498. "AAX_ePlugInCategory_SWGenerators", "AAX_ePlugInCategory_WrappedPlugin", "AAX_EPlugInCategory_Effect" };
  1499. return aaxCategoryStrings;
  1500. }
  1501. Array<var> Project::getAllAAXCategoryVars() noexcept
  1502. {
  1503. static Array<var> aaxCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1504. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1505. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1506. 0x00000800, 0x00001000, 0x00002000 };
  1507. return aaxCategoryVars;
  1508. }
  1509. Array<var> Project::getDefaultAAXCategories() const noexcept
  1510. {
  1511. if (isPluginSynth())
  1512. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_SWGenerators")];
  1513. return getAllAAXCategoryVars()[getAllAAXCategoryStrings().indexOf ("AAX_ePlugInCategory_None")];
  1514. }
  1515. StringArray Project::getAllRTASCategoryStrings() noexcept
  1516. {
  1517. static StringArray rtasCategoryStrings { "ePlugInCategory_None", "ePlugInCategory_EQ", "ePlugInCategory_Dynamics", "ePlugInCategory_PitchShift",
  1518. "ePlugInCategory_Reverb", "ePlugInCategory_Delay", "ePlugInCategory_Modulation", "ePlugInCategory_Harmonic",
  1519. "ePlugInCategory_NoiseReduction", "ePlugInCategory_Dither", "ePlugInCategory_SoundField", "ePlugInCategory_HWGenerators",
  1520. "ePlugInCategory_SWGenerators", "ePlugInCategory_WrappedPlugin", "ePlugInCategory_Effect" };
  1521. return rtasCategoryStrings;
  1522. }
  1523. Array<var> Project::getAllRTASCategoryVars() noexcept
  1524. {
  1525. static Array<var> rtasCategoryVars { 0x00000000, 0x00000001, 0x00000002, 0x00000004,
  1526. 0x00000008, 0x00000010, 0x00000020, 0x00000040,
  1527. 0x00000080, 0x00000100, 0x00000200, 0x00000400,
  1528. 0x00000800, 0x00001000, 0x00002000 };
  1529. return rtasCategoryVars;
  1530. }
  1531. Array<var> Project::getDefaultRTASCategories() const noexcept
  1532. {
  1533. if (isPluginSynth())
  1534. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_SWGenerators")];
  1535. return getAllRTASCategoryVars()[getAllRTASCategoryStrings().indexOf ("ePlugInCategory_None")];
  1536. }
  1537. //==============================================================================
  1538. EnabledModuleList& Project::getEnabledModules()
  1539. {
  1540. if (enabledModuleList == nullptr)
  1541. enabledModuleList.reset (new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr)));
  1542. return *enabledModuleList;
  1543. }
  1544. static Array<File> getModulePathsFromCompatibleExporters (Project& project)
  1545. {
  1546. StringArray paths;
  1547. for (Project::ExporterIterator exporter (project); exporter.next();)
  1548. {
  1549. if (! exporter->mayCompileOnCurrentOS())
  1550. continue;
  1551. auto& modules = project.getEnabledModules();
  1552. auto n = modules.getNumModules();
  1553. for (int i = 0; i < n; ++i)
  1554. {
  1555. auto id = modules.getModuleID (i);
  1556. if (modules.shouldUseGlobalPath (id))
  1557. continue;
  1558. auto path = exporter->getPathForModuleString (id);
  1559. if (path.isNotEmpty())
  1560. paths.addIfNotAlreadyThere (path);
  1561. }
  1562. auto oldPath = exporter->getLegacyModulePath();
  1563. if (oldPath.isNotEmpty())
  1564. paths.addIfNotAlreadyThere (oldPath);
  1565. }
  1566. Array<File> files;
  1567. for (auto& path : paths)
  1568. {
  1569. auto f = project.resolveFilename (path);
  1570. if (f.isDirectory())
  1571. {
  1572. files.addIfNotAlreadyThere (f);
  1573. if (f.getChildFile ("modules").isDirectory())
  1574. files.addIfNotAlreadyThere (f.getChildFile ("modules"));
  1575. }
  1576. }
  1577. return files;
  1578. }
  1579. AvailableModuleList& Project::getExporterPathsModuleList()
  1580. {
  1581. return *exporterPathsModuleList;
  1582. }
  1583. void Project::rescanExporterPathModules (bool async)
  1584. {
  1585. if (async)
  1586. exporterPathsModuleList->scanPathsAsync (getModulePathsFromCompatibleExporters (*this));
  1587. else
  1588. exporterPathsModuleList->scanPaths (getModulePathsFromCompatibleExporters (*this));
  1589. }
  1590. ModuleIDAndFolder Project::getModuleWithID (const String& id)
  1591. {
  1592. if (! getEnabledModules().shouldUseGlobalPath (id))
  1593. {
  1594. const auto& mod = exporterPathsModuleList->getModuleWithID (id);
  1595. if (mod.second != File())
  1596. return mod;
  1597. }
  1598. const auto& list = (isJUCEModule (id) ? ProjucerApplication::getApp().getJUCEPathModuleList().getAllModules()
  1599. : ProjucerApplication::getApp().getUserPathsModuleList().getAllModules());
  1600. for (auto& m : list)
  1601. if (m.first == id)
  1602. return m;
  1603. return exporterPathsModuleList->getModuleWithID (id);
  1604. }
  1605. //==============================================================================
  1606. ValueTree Project::getExporters()
  1607. {
  1608. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1609. }
  1610. int Project::getNumExporters()
  1611. {
  1612. return getExporters().getNumChildren();
  1613. }
  1614. ProjectExporter* Project::createExporter (int index)
  1615. {
  1616. jassert (index >= 0 && index < getNumExporters());
  1617. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1618. }
  1619. void Project::addNewExporter (const String& exporterName)
  1620. {
  1621. std::unique_ptr<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1622. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1623. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1624. auto exportersTree = getExporters();
  1625. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1626. }
  1627. void Project::createExporterForCurrentPlatform()
  1628. {
  1629. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1630. }
  1631. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1632. {
  1633. StringArray buildFolders;
  1634. auto exportersTree = getExporters();
  1635. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1636. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1637. {
  1638. auto exporterNode = exportersTree.getChild (i);
  1639. if (exporterNode.getType() == Identifier (type))
  1640. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1641. }
  1642. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1643. return {};
  1644. buildFolders.remove (buildFolders.indexOf (base));
  1645. int num = 1;
  1646. for (auto f : buildFolders)
  1647. {
  1648. if (! f.endsWith ("_" + String (num)))
  1649. break;
  1650. ++num;
  1651. }
  1652. return "_" + String (num);
  1653. }
  1654. //==============================================================================
  1655. bool Project::shouldSendGUIBuilderAnalyticsEvent() noexcept
  1656. {
  1657. if (! hasSentGUIBuilderAnalyticsEvent)
  1658. {
  1659. hasSentGUIBuilderAnalyticsEvent = true;
  1660. return true;
  1661. }
  1662. return false;
  1663. }
  1664. //==============================================================================
  1665. String Project::getFileTemplate (const String& templateName)
  1666. {
  1667. int dataSize;
  1668. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1669. return String::fromUTF8 (data, dataSize);
  1670. jassertfalse;
  1671. return {};
  1672. }
  1673. //==============================================================================
  1674. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1675. Project::ExporterIterator::~ExporterIterator() {}
  1676. bool Project::ExporterIterator::next()
  1677. {
  1678. if (++index >= project.getNumExporters())
  1679. return false;
  1680. exporter.reset (project.createExporter (index));
  1681. if (exporter == nullptr)
  1682. {
  1683. jassertfalse; // corrupted project file?
  1684. return next();
  1685. }
  1686. return true;
  1687. }