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.

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