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.

2228 lines
82KB

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