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.

2077 lines
76KB

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