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.

2239 lines
83KB

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