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.

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