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.

2193 lines
80KB

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