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.

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