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.

2216 lines
86KB

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