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.

2129 lines
78KB

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