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.

1596 lines
59KB

  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. namespace
  24. {
  25. String makeValid4CC (const String& seed)
  26. {
  27. auto s = CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx";
  28. return s.substring (0, 1).toUpperCase()
  29. + s.substring (1, 4).toLowerCase();
  30. }
  31. }
  32. //==============================================================================
  33. Project::Project (const File& f)
  34. : FileBasedDocument (projectFileExtension,
  35. String ("*") + projectFileExtension,
  36. "Choose a Jucer project to load",
  37. "Save Jucer project")
  38. {
  39. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  40. setFile (f);
  41. removeDefunctExporters();
  42. updateOldModulePaths();
  43. updateOldStyleConfigList();
  44. setCppVersionFromOldExporterSettings();
  45. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  46. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  47. initialiseProjectValues();
  48. initialiseMainGroup();
  49. initialiseAudioPluginValues();
  50. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  51. getModules().sortAlphabetically();
  52. projectRoot.addListener (this);
  53. setChangedFlag (false);
  54. modificationTime = getFile().getLastModificationTime();
  55. }
  56. Project::~Project()
  57. {
  58. projectRoot.removeListener (this);
  59. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  60. }
  61. const char* Project::projectFileExtension = ".jucer";
  62. //==============================================================================
  63. void Project::setTitle (const String& newTitle)
  64. {
  65. projectRoot.setProperty (Ids::name, newTitle, getUndoManager());
  66. getMainGroup().getNameValue() = newTitle;
  67. bundleIdentifierValue.setDefault (getDefaultBundleIdentifierString());
  68. pluginAAXIdentifierValue.setDefault (getDefaultAAXIdentifierString());
  69. }
  70. String Project::getDocumentTitle()
  71. {
  72. return getProjectNameString();
  73. }
  74. void Project::updateProjectSettings()
  75. {
  76. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  77. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  78. }
  79. bool Project::setCppVersionFromOldExporterSettings()
  80. {
  81. auto highestLanguageStandard = -1;
  82. for (Project::ExporterIterator exporter (*this); exporter.next();)
  83. {
  84. if (exporter->isXcode()) // cpp version was per-build configuration for xcode exporters
  85. {
  86. for (ProjectExporter::ConfigIterator config (*exporter); config.next();)
  87. {
  88. auto cppLanguageStandard = config->getValue (Ids::cppLanguageStandard).getValue();
  89. if (cppLanguageStandard != var())
  90. {
  91. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  92. if (versionNum > highestLanguageStandard)
  93. highestLanguageStandard = versionNum;
  94. }
  95. }
  96. }
  97. else
  98. {
  99. auto cppLanguageStandard = exporter->getSetting (Ids::cppLanguageStandard).getValue();
  100. if (cppLanguageStandard != var())
  101. {
  102. if (cppLanguageStandard.toString().containsIgnoreCase ("latest"))
  103. {
  104. cppStandardValue = "latest";
  105. return true;
  106. }
  107. auto versionNum = cppLanguageStandard.toString().getLastCharacters (2).getIntValue();
  108. if (versionNum > highestLanguageStandard)
  109. highestLanguageStandard = versionNum;
  110. }
  111. }
  112. }
  113. if (highestLanguageStandard != -1 && highestLanguageStandard >= 11)
  114. {
  115. cppStandardValue = highestLanguageStandard;
  116. return true;
  117. }
  118. return false;
  119. }
  120. void Project::updateDeprecatedProjectSettingsInteractively()
  121. {
  122. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  123. for (Project::ExporterIterator exporter (*this); exporter.next();)
  124. exporter->updateDeprecatedProjectSettingsInteractively();
  125. }
  126. void Project::initialiseMainGroup()
  127. {
  128. // Create main file group if missing
  129. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  130. {
  131. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  132. projectRoot.addChild (mainGroup.state, 0, 0);
  133. }
  134. getMainGroup().initialiseMissingProperties();
  135. }
  136. void Project::initialiseProjectValues()
  137. {
  138. projectNameValue.referTo (projectRoot, Ids::name, getUndoManager(), "JUCE Project");
  139. projectUIDValue.referTo (projectRoot, Ids::ID, getUndoManager(), createAlphaNumericUID());
  140. projectTypeValue.referTo (projectRoot, Ids::projectType, getUndoManager(), ProjectType_GUIApp::getTypeName());
  141. versionValue.referTo (projectRoot, Ids::version, getUndoManager(), "1.0.0");
  142. bundleIdentifierValue.referTo (projectRoot, Ids::bundleIdentifier, getUndoManager(), getDefaultBundleIdentifierString());
  143. companyNameValue.referTo (projectRoot, Ids::companyName, getUndoManager());
  144. companyCopyrightValue.referTo (projectRoot, Ids::companyCopyright, getUndoManager());
  145. companyWebsiteValue.referTo (projectRoot, Ids::companyWebsite, getUndoManager());
  146. companyEmailValue.referTo (projectRoot, Ids::companyEmail, getUndoManager());
  147. displaySplashScreenValue.referTo (projectRoot, Ids::displaySplashScreen, getUndoManager(), ! ProjucerApplication::getApp().isPaidOrGPL());
  148. splashScreenColourValue.referTo (projectRoot, Ids::splashScreenColour, getUndoManager(), "Dark");
  149. reportAppUsageValue.referTo (projectRoot, Ids::reportAppUsage, getUndoManager());
  150. if (ProjucerApplication::getApp().isPaidOrGPL())
  151. {
  152. reportAppUsageValue.setDefault (ProjucerApplication::getApp().licenseController->getState().applicationUsageDataState
  153. == LicenseState::ApplicationUsageData::enabled);
  154. }
  155. else
  156. {
  157. reportAppUsageValue.setDefault (true);
  158. }
  159. cppStandardValue.referTo (projectRoot, Ids::cppLanguageStandard, getUndoManager(), "14");
  160. headerSearchPathsValue.referTo (projectRoot, Ids::headerPath, getUndoManager());
  161. preprocessorDefsValue.referTo (projectRoot, Ids::defines, getUndoManager());
  162. userNotesValue.referTo (projectRoot, Ids::userNotes, getUndoManager());
  163. maxBinaryFileSizeValue.referTo (projectRoot, Ids::maxBinaryFileSize, getUndoManager(), 10240 * 1024);
  164. includeBinaryDataInAppConfigValue.referTo (projectRoot, Ids::includeBinaryInAppConfig, getUndoManager(), true);
  165. binaryDataNamespaceValue.referTo (projectRoot, Ids::binaryDataNamespace, getUndoManager(), "BinaryData");
  166. }
  167. void Project::initialiseAudioPluginValues()
  168. {
  169. buildVSTValue.referTo (projectRoot, Ids::buildVST, getUndoManager(), true);
  170. buildVST3Value.referTo (projectRoot, Ids::buildVST3, getUndoManager(), false);
  171. buildAUValue.referTo (projectRoot, Ids::buildAU, getUndoManager(), true);
  172. buildAUv3Value.referTo (projectRoot, Ids::buildAUv3, getUndoManager(), false);
  173. buildRTASValue.referTo (projectRoot, Ids::buildRTAS, getUndoManager(), false);
  174. buildAAXValue.referTo (projectRoot, Ids::buildAAX, getUndoManager(), false);
  175. buildStandaloneValue.referTo (projectRoot, Ids::buildStandalone, getUndoManager(), false);
  176. enableIAAValue.referTo (projectRoot, Ids::enableIAA, getUndoManager(), false);
  177. pluginNameValue.referTo (projectRoot, Ids::pluginName, getUndoManager(), getProjectNameString());
  178. pluginDescriptionValue.referTo (projectRoot, Ids::pluginDesc, getUndoManager(), getProjectNameString());
  179. pluginManufacturerValue.referTo (projectRoot, Ids::pluginManufacturer, getUndoManager(), "yourcompany");
  180. pluginManufacturerCodeValue.referTo (projectRoot, Ids::pluginManufacturerCode, getUndoManager(), "Manu");
  181. pluginCodeValue.referTo (projectRoot, Ids::pluginCode, getUndoManager(), makeValid4CC (getProjectUIDString() + getProjectUIDString()));
  182. pluginChannelConfigsValue.referTo (projectRoot, Ids::pluginChannelConfigs, getUndoManager());
  183. pluginIsSynthValue.referTo (projectRoot, Ids::pluginIsSynth, getUndoManager(), false);
  184. pluginWantsMidiInputValue.referTo (projectRoot, Ids::pluginWantsMidiIn, getUndoManager(), false);
  185. pluginProducesMidiOutValue.referTo (projectRoot, Ids::pluginProducesMidiOut, getUndoManager(), false);
  186. pluginIsMidiEffectPluginValue.referTo (projectRoot, Ids::pluginIsMidiEffectPlugin, getUndoManager(), false);
  187. pluginEditorNeedsKeyFocusValue.referTo (projectRoot, Ids::pluginEditorRequiresKeys, getUndoManager(), false);
  188. pluginVSTCategoryValue.referTo (projectRoot, Ids::pluginVSTCategory, getUndoManager());
  189. pluginAUExportPrefixValue.referTo (projectRoot, Ids::pluginAUExportPrefix, getUndoManager(),
  190. CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false) + "AU");
  191. pluginAUMainTypeValue.referTo (projectRoot, Ids::pluginAUMainType, getUndoManager());
  192. pluginRTASCategoryValue.referTo (projectRoot, Ids::pluginRTASCategory, getUndoManager());
  193. pluginRTASBypassDisabledValue.referTo (projectRoot, Ids::pluginRTASDisableBypass, getUndoManager());
  194. pluginRTASMultiMonoDisabledValue.referTo (projectRoot, Ids::pluginRTASDisableMultiMono, getUndoManager());
  195. pluginAAXIdentifierValue.referTo (projectRoot, Ids::aaxIdentifier, getUndoManager(), getDefaultAAXIdentifierString());
  196. pluginAAXCategoryValue.referTo (projectRoot, Ids::pluginAAXCategory, getUndoManager(), "AAX_ePlugInCategory_Dynamics");
  197. pluginAAXBypassDisabledValue.referTo (projectRoot, Ids::pluginAAXDisableBypass, getUndoManager());
  198. pluginAAXMultiMonoDisabledValue.referTo (projectRoot, Ids::pluginAAXDisableMultiMono, getUndoManager());
  199. }
  200. void Project::updateOldStyleConfigList()
  201. {
  202. auto deprecatedConfigsList = projectRoot.getChildWithName (Ids::CONFIGURATIONS);
  203. if (deprecatedConfigsList.isValid())
  204. {
  205. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  206. for (Project::ExporterIterator exporter (*this); exporter.next();)
  207. {
  208. if (exporter->getNumConfigurations() == 0)
  209. {
  210. auto newConfigs = deprecatedConfigsList.createCopy();
  211. if (! exporter->isXcode())
  212. {
  213. for (auto j = newConfigs.getNumChildren(); --j >= 0;)
  214. {
  215. auto config = newConfigs.getChild (j);
  216. config.removeProperty (Ids::osxSDK, nullptr);
  217. config.removeProperty (Ids::osxCompatibility, nullptr);
  218. config.removeProperty (Ids::osxArchitecture, nullptr);
  219. }
  220. }
  221. exporter->settings.addChild (newConfigs, 0, nullptr);
  222. }
  223. }
  224. }
  225. }
  226. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  227. {
  228. if (projectRoot.hasProperty (name))
  229. {
  230. for (Project::ExporterIterator exporter (*this); exporter.next();)
  231. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  232. projectRoot.removeProperty (name, nullptr);
  233. }
  234. }
  235. void Project::removeDefunctExporters()
  236. {
  237. auto exporters = projectRoot.getChildWithName (Ids::EXPORTFORMATS);
  238. StringPairArray oldExporters;
  239. oldExporters.set ("ANDROID", "Android Ant Exporter");
  240. oldExporters.set ("MSVC6", "MSVC6");
  241. oldExporters.set ("VS2010", "Visual Studio 2010");
  242. oldExporters.set ("VS2012", "Visual Studio 2012");
  243. for (auto& key : oldExporters.getAllKeys())
  244. {
  245. auto oldExporter = exporters.getChildWithName (key);
  246. if (oldExporter.isValid())
  247. {
  248. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  249. TRANS (oldExporters[key]),
  250. TRANS ("The " + oldExporters[key] + " Exporter is deprecated. The exporter will be removed from this project."));
  251. exporters.removeChild (oldExporter, nullptr);
  252. }
  253. }
  254. }
  255. void Project::updateOldModulePaths()
  256. {
  257. for (Project::ExporterIterator exporter (*this); exporter.next();)
  258. exporter->updateOldModulePaths();
  259. }
  260. //==============================================================================
  261. static int getVersionElement (StringRef v, int index)
  262. {
  263. StringArray parts = StringArray::fromTokens (v, "., ", {});
  264. return parts [parts.size() - index - 1].getIntValue();
  265. }
  266. static int getJuceVersion (const String& v)
  267. {
  268. return getVersionElement (v, 2) * 100000
  269. + getVersionElement (v, 1) * 1000
  270. + getVersionElement (v, 0);
  271. }
  272. static int getBuiltJuceVersion()
  273. {
  274. return JUCE_MAJOR_VERSION * 100000
  275. + JUCE_MINOR_VERSION * 1000
  276. + JUCE_BUILDNUMBER;
  277. }
  278. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  279. {
  280. for (auto i = modules.size(); --i >= 0;)
  281. {
  282. auto* m = modules.getUnchecked(i);
  283. if (m->getID().startsWith ("juce_")
  284. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  285. return true;
  286. }
  287. return false;
  288. }
  289. void Project::warnAboutOldProjucerVersion()
  290. {
  291. ModuleList available;
  292. available.scanGlobalJuceModulePath();
  293. if (! isAnyModuleNewerThanProjucer (available.modules))
  294. available.scanGlobalUserModulePath();
  295. if (! isAnyModuleNewerThanProjucer (available.modules))
  296. available.scanProjectExporterModulePaths (*this);
  297. if (! isAnyModuleNewerThanProjucer (available.modules))
  298. return;
  299. // Projucer is out of date!
  300. if (ProjucerApplication::getApp().isRunningCommandLine)
  301. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  302. else
  303. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  304. "Projucer",
  305. "This version of the Projucer is out-of-date!"
  306. "\n\n"
  307. "Always make sure that you're running the very latest version, "
  308. "preferably compiled directly from the JUCE repository that you're working with!");
  309. }
  310. //==============================================================================
  311. static File lastDocumentOpened;
  312. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  313. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  314. static void registerRecentFile (const File& file)
  315. {
  316. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  317. getAppSettings().recentFiles.addFile (file);
  318. getAppSettings().flush();
  319. }
  320. static void forgetRecentFile (const File& file)
  321. {
  322. RecentlyOpenedFilesList::forgetRecentFileNatively (file);
  323. getAppSettings().recentFiles.removeFile (file);
  324. getAppSettings().flush();
  325. }
  326. //==============================================================================
  327. Result Project::loadDocument (const File& file)
  328. {
  329. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  330. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  331. return Result::fail ("Not a valid Jucer project!");
  332. auto newTree = ValueTree::fromXml (*xml);
  333. if (! newTree.hasType (Ids::JUCERPROJECT))
  334. return Result::fail ("The document contains errors and couldn't be parsed!");
  335. registerRecentFile (file);
  336. enabledModulesList.reset();
  337. projectRoot = newTree;
  338. initialiseProjectValues();
  339. initialiseMainGroup();
  340. initialiseAudioPluginValues();
  341. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  342. removeDefunctExporters();
  343. updateOldModulePaths();
  344. setChangedFlag (false);
  345. if (! ProjucerApplication::getApp().isRunningCommandLine)
  346. warnAboutOldProjucerVersion();
  347. return Result::ok();
  348. }
  349. Result Project::saveDocument (const File& file)
  350. {
  351. return saveProject (file, false);
  352. }
  353. Result Project::saveProject (const File& file, bool isCommandLineApp)
  354. {
  355. if (isSaving)
  356. return Result::ok();
  357. if (isTemporaryProject())
  358. {
  359. askUserWhereToSaveProject();
  360. return Result::ok();
  361. }
  362. updateProjectSettings();
  363. if (! isCommandLineApp && ! isTemporaryProject())
  364. registerRecentFile (file);
  365. const ScopedValueSetter<bool> vs (isSaving, true, false);
  366. ProjectSaver saver (*this, file);
  367. return saver.save (! isCommandLineApp, shouldWaitAfterSaving, specifiedExporterToSave);
  368. }
  369. Result Project::saveResourcesOnly (const File& file)
  370. {
  371. ProjectSaver saver (*this, file);
  372. return saver.saveResourcesOnly();
  373. }
  374. //==============================================================================
  375. void Project::setTemporaryDirectory (const File& dir) noexcept
  376. {
  377. tempDirectory = dir;
  378. // remove this file from the recent documents list as it is a temporary project
  379. forgetRecentFile (getFile());
  380. }
  381. void Project::askUserWhereToSaveProject()
  382. {
  383. FileChooser fc ("Save Project");
  384. fc.browseForDirectory();
  385. if (fc.getResult().exists())
  386. moveTemporaryDirectory (fc.getResult());
  387. }
  388. void Project::moveTemporaryDirectory (const File& newParentDirectory)
  389. {
  390. auto newDirectory = newParentDirectory.getChildFile (tempDirectory.getFileName());
  391. auto oldJucerFileName = getFile().getFileName();
  392. tempDirectory.copyDirectoryTo (newDirectory);
  393. tempDirectory.deleteRecursively();
  394. tempDirectory = File();
  395. // reload project from new location
  396. if (auto* window = ProjucerApplication::getApp().mainWindowList.getMainWindowForFile (getFile()))
  397. window->moveProject (newDirectory.getChildFile (oldJucerFileName));
  398. }
  399. //==============================================================================
  400. void Project::valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  401. {
  402. if (tree.getRoot() == tree)
  403. {
  404. if (property == Ids::projectType)
  405. {
  406. sendChangeMessage();
  407. }
  408. else if (property == Ids::name)
  409. {
  410. setTitle (projectRoot [Ids::name]);
  411. }
  412. else if (property == Ids::defines)
  413. {
  414. parsedPreprocessorDefs = parsePreprocessorDefs (preprocessorDefsValue.get());
  415. }
  416. changed();
  417. }
  418. }
  419. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  420. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  421. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  422. void Project::valueTreeParentChanged (ValueTree&) {}
  423. //==============================================================================
  424. bool Project::hasProjectBeenModified()
  425. {
  426. auto oldModificationTime = modificationTime;
  427. modificationTime = getFile().getLastModificationTime();
  428. return (modificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  429. }
  430. //==============================================================================
  431. File Project::resolveFilename (String filename) const
  432. {
  433. if (filename.isEmpty())
  434. return {};
  435. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  436. #if ! JUCE_WINDOWS
  437. if (filename.startsWith ("~"))
  438. return File::getSpecialLocation (File::userHomeDirectory).getChildFile (filename.trimCharactersAtStart ("~/"));
  439. #endif
  440. if (FileHelpers::isAbsolutePath (filename))
  441. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  442. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  443. }
  444. String Project::getRelativePathForFile (const File& file) const
  445. {
  446. auto filename = file.getFullPathName();
  447. auto relativePathBase = getFile().getParentDirectory();
  448. auto p1 = relativePathBase.getFullPathName();
  449. auto p2 = file.getFullPathName();
  450. while (p1.startsWithChar (File::getSeparatorChar()))
  451. p1 = p1.substring (1);
  452. while (p2.startsWithChar (File::getSeparatorChar()))
  453. p2 = p2.substring (1);
  454. if (p1.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)
  455. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::getSeparatorString(), true, false)))
  456. {
  457. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  458. }
  459. return filename;
  460. }
  461. //==============================================================================
  462. const ProjectType& Project::getProjectType() const
  463. {
  464. if (auto* type = ProjectType::findType (getProjectTypeString()))
  465. return *type;
  466. auto* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  467. jassert (guiType != nullptr);
  468. return *guiType;
  469. }
  470. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  471. {
  472. auto& projectType = getProjectType();
  473. if (! projectType.supportsTargetType (targetType))
  474. return false;
  475. switch (targetType)
  476. {
  477. case ProjectType::Target::VSTPlugIn:
  478. return shouldBuildVST();
  479. case ProjectType::Target::VST3PlugIn:
  480. return shouldBuildVST3();
  481. case ProjectType::Target::AAXPlugIn:
  482. return shouldBuildAAX();
  483. case ProjectType::Target::RTASPlugIn:
  484. return shouldBuildRTAS();
  485. case ProjectType::Target::AudioUnitPlugIn:
  486. return shouldBuildAU();
  487. case ProjectType::Target::AudioUnitv3PlugIn:
  488. return shouldBuildAUv3();
  489. case ProjectType::Target::StandalonePlugIn:
  490. return shouldBuildStandalonePlugin();
  491. case ProjectType::Target::AggregateTarget:
  492. case ProjectType::Target::SharedCodeTarget:
  493. return projectType.isAudioPlugin();
  494. case ProjectType::Target::unspecified:
  495. return false;
  496. default:
  497. break;
  498. }
  499. return true;
  500. }
  501. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  502. {
  503. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  504. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  505. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  506. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  507. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  508. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  509. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  510. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  511. }
  512. const char* ProjectType::Target::getName() const noexcept
  513. {
  514. switch (type)
  515. {
  516. case GUIApp: return "App";
  517. case ConsoleApp: return "ConsoleApp";
  518. case StaticLibrary: return "Static Library";
  519. case DynamicLibrary: return "Dynamic Library";
  520. case VSTPlugIn: return "VST";
  521. case VST3PlugIn: return "VST3";
  522. case AudioUnitPlugIn: return "AU";
  523. case StandalonePlugIn: return "Standalone Plugin";
  524. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  525. case AAXPlugIn: return "AAX";
  526. case RTASPlugIn: return "RTAS";
  527. case SharedCodeTarget: return "Shared Code";
  528. case AggregateTarget: return "All";
  529. default: return "undefined";
  530. }
  531. }
  532. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  533. {
  534. switch (type)
  535. {
  536. case GUIApp: return executable;
  537. case ConsoleApp: return executable;
  538. case StaticLibrary: return staticLibrary;
  539. case DynamicLibrary: return sharedLibraryOrDLL;
  540. case VSTPlugIn: return pluginBundle;
  541. case VST3PlugIn: return pluginBundle;
  542. case AudioUnitPlugIn: return pluginBundle;
  543. case StandalonePlugIn: return executable;
  544. case AudioUnitv3PlugIn: return macOSAppex;
  545. case AAXPlugIn: return pluginBundle;
  546. case RTASPlugIn: return pluginBundle;
  547. case SharedCodeTarget: return staticLibrary;
  548. default:
  549. break;
  550. }
  551. return unknown;
  552. }
  553. //==============================================================================
  554. void Project::createPropertyEditors (PropertyListBuilder& props)
  555. {
  556. props.add (new TextPropertyComponent (projectNameValue, "Project Name", 256, false),
  557. "The name of the project.");
  558. props.add (new TextPropertyComponent (versionValue, "Project Version", 16, false),
  559. "The project's version number, This should be in the format major.minor.point[.point]");
  560. props.add (new TextPropertyComponent (companyNameValue, "Company Name", 256, false),
  561. "Your company name, which will be added to the properties of the binary where possible");
  562. props.add (new TextPropertyComponent (companyCopyrightValue, "Company Copyright", 256, false),
  563. "Your company copyright, which will be added to the properties of the binary where possible");
  564. props.add (new TextPropertyComponent (companyWebsiteValue, "Company Website", 256, false),
  565. "Your company website, which will be added to the properties of the binary where possible");
  566. props.add (new TextPropertyComponent (companyEmailValue, "Company E-mail", 256, false),
  567. "Your company e-mail, which will be added to the properties of the binary where possible");
  568. {
  569. String licenseRequiredTagline ("Required for closed source applications without an Indie or Pro JUCE license");
  570. String licenseRequiredInfo ("In accordance with the terms of the JUCE 5 End-Use License Agreement (www.juce.com/juce-5-licence), "
  571. "this option can only be disabled for closed source applications if you have a JUCE Indie or Pro "
  572. "license, or are using JUCE under the GPL v3 license.");
  573. StringPairArray description;
  574. description.set ("Report JUCE app usage", "This option controls the collection of usage data from users of this JUCE application.");
  575. description.set ("Display the JUCE splash screen", "This option controls the display of the standard JUCE splash screen.");
  576. if (ProjucerApplication::getApp().isPaidOrGPL())
  577. {
  578. props.add (new ChoicePropertyComponent (reportAppUsageValue, String ("Report JUCE App Usage") + " (" + licenseRequiredTagline + ")"),
  579. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  580. props.add (new ChoicePropertyComponent (displaySplashScreenValue, String ("Display the JUCE Splash Screen") + " (" + licenseRequiredTagline + ")"),
  581. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  582. }
  583. else
  584. {
  585. StringArray options;
  586. Array<var> vars;
  587. options.add (licenseRequiredTagline);
  588. vars.add (var());
  589. props.add (new ChoicePropertyComponent (Value(), "Report JUCE App Usage", options, vars),
  590. description["Report JUCE app usage"] + " " + licenseRequiredInfo);
  591. props.add (new ChoicePropertyComponent (Value(), "Display the JUCE Splash Screen", options, vars),
  592. description["Display the JUCE splash screen"] + " " + licenseRequiredInfo);
  593. }
  594. }
  595. props.add (new ChoicePropertyComponent (splashScreenColourValue, "Splash Screen Colour",
  596. { "Dark", "Light" },
  597. { "Dark", "Light" }),
  598. "Choose the colour of the JUCE splash screen.");
  599. {
  600. StringArray projectTypeNames;
  601. Array<var> projectTypeCodes;
  602. auto types = ProjectType::getAllTypes();
  603. for (int i = 0; i < types.size(); ++i)
  604. {
  605. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  606. projectTypeCodes.add (types.getUnchecked(i)->getType());
  607. }
  608. props.add (new ChoicePropertyComponent (projectTypeValue, "Project Type", projectTypeNames, projectTypeCodes),
  609. "The project type for which settings should be shown.");
  610. }
  611. props.add (new TextPropertyComponent (bundleIdentifierValue, "Bundle Identifier", 256, false),
  612. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  613. if (getProjectType().isAudioPlugin())
  614. createAudioPluginPropertyEditors (props);
  615. {
  616. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  617. StringArray maxSizeNames;
  618. Array<var> maxSizeCodes;
  619. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  620. {
  621. auto sizeInBytes = maxSizes[i] * 1024;
  622. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  623. maxSizeCodes.add (sizeInBytes);
  624. }
  625. props.add (new ChoicePropertyComponent (maxBinaryFileSizeValue, "BinaryData.cpp Size Limit", maxSizeNames, maxSizeCodes),
  626. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  627. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  628. }
  629. props.add (new ChoicePropertyComponent (includeBinaryDataInAppConfigValue, "Include BinaryData in AppConfig"),
  630. "Include BinaryData.h in the AppConfig.h file");
  631. props.add (new TextPropertyComponent (binaryDataNamespaceValue, "BinaryData Namespace", 256, false),
  632. "The namespace containing the binary assests.");
  633. props.add (new ChoicePropertyComponent (cppStandardValue, "C++ Language Standard",
  634. { "C++11", "C++14", "C++17", "Use Latest" },
  635. { "11", "14", "17", "latest" }),
  636. "The standard of the C++ language that will be used for compilation.");
  637. props.add (new TextPropertyComponent (preprocessorDefsValue, "Preprocessor Definitions", 32768, true),
  638. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  639. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  640. props.addSearchPathProperty (headerSearchPathsValue, "Header Search Paths", "Global header search paths.");
  641. props.add (new TextPropertyComponent (userNotesValue, "Notes", 32768, true),
  642. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  643. }
  644. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  645. {
  646. props.add (new ChoicePropertyComponent (buildVSTValue, "Build VST"),
  647. "Whether the project should produce a VST plugin.");
  648. props.add (new ChoicePropertyComponent (buildVST3Value, "Build VST3"),
  649. "Whether the project should produce a VST3 plugin.");
  650. props.add (new ChoicePropertyComponent (buildAUValue, "Build AudioUnit"),
  651. "Whether the project should produce an AudioUnit plugin.");
  652. props.add (new ChoicePropertyComponent (buildAUv3Value, "Build AudioUnit v3"),
  653. "Whether the project should produce an AudioUnit version 3 plugin.");
  654. props.add (new ChoicePropertyComponent (buildRTASValue, "Build RTAS"),
  655. "Whether the project should produce an RTAS plugin.");
  656. props.add (new ChoicePropertyComponent (buildAAXValue, "Build AAX"),
  657. "Whether the project should produce an AAX plugin.");
  658. props.add (new ChoicePropertyComponent (buildStandaloneValue, "Build Standalone Plug-In"),
  659. "Whether the project should produce a standalone version of your plugin.");
  660. props.add (new ChoicePropertyComponent (enableIAAValue, "Enable Inter-App Audio"),
  661. "Whether a standalone plug-in should be an Inter-App Audio app. You should also enable the audio "
  662. "background capability in the iOS exporter.");
  663. props.add (new TextPropertyComponent (pluginNameValue, "Plugin Name", 128, false),
  664. "The name of your plugin (keep it short!)");
  665. props.add (new TextPropertyComponent (pluginDescriptionValue, "Plugin Description", 256, false),
  666. "A short description of your plugin.");
  667. props.add (new TextPropertyComponent (pluginManufacturerValue, "Plugin Manufacturer", 256, false),
  668. "The name of your company (cannot be blank).");
  669. props.add (new TextPropertyComponent (pluginManufacturerCodeValue, "Plugin Manufacturer Code", 4, false),
  670. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  671. props.add (new TextPropertyComponent (pluginCodeValue, "Plugin Code", 4, false),
  672. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  673. props.add (new TextPropertyComponent (pluginChannelConfigsValue, "Plugin Channel Configurations", 1024, false),
  674. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  675. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  676. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  677. "this field empty and override the isBusesLayoutSupported callback in your AudioProcessor.");
  678. props.add (new ChoicePropertyComponent (pluginIsSynthValue, "Plugin is a Synth"),
  679. "Enable this if you want your plugin to be treated as a synth or generator. It doesn't make much difference to the plugin itself, but some hosts treat synths differently to other plugins.");
  680. props.add (new ChoicePropertyComponent (pluginWantsMidiInputValue, "Plugin Midi Input"),
  681. "Enable this if you want your plugin to accept midi messages.");
  682. props.add (new ChoicePropertyComponent (pluginProducesMidiOutValue, "Plugin Midi Output"),
  683. "Enable this if your plugin is going to produce midi messages.");
  684. props.add (new ChoicePropertyComponent (pluginIsMidiEffectPluginValue, "Midi Effect Plugin"),
  685. "Enable this if your plugin only processes midi and no audio.");
  686. props.add (new ChoicePropertyComponent (pluginEditorNeedsKeyFocusValue, "Plugin Editor Requires Keyboard Focus"),
  687. "Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  688. props.add (new TextPropertyComponent (pluginAUExportPrefixValue, "Plugin AU Export Prefix", 128, false),
  689. "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.");
  690. props.add (new TextPropertyComponent (pluginAUMainTypeValue, "Plugin AU Main Type", 128, false),
  691. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  692. props.add (new TextPropertyComponent (pluginVSTCategoryValue, "VST Category", 128, false),
  693. "In a VST, this is the value that is set as JucePlugin_VSTCategory. Leave it blank unless you want to use a custom value.");
  694. props.add (new TextPropertyComponent (pluginRTASCategoryValue, "Plugin RTAS Category", 128, false),
  695. "(Leave this blank if your plugin is a synth). This is one of the RTAS categories from FicPluginEnums.h, such as: ePlugInCategory_None, ePlugInCategory_EQ, ePlugInCategory_Dynamics, "
  696. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  697. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  698. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  699. props.add (new TextPropertyComponent (pluginAAXCategoryValue, "Plugin AAX Category", 128, false),
  700. "This is one of the categories from the AAX_EPlugInCategory enum");
  701. props.add (new TextPropertyComponent (pluginAAXIdentifierValue, "Plugin AAX Identifier", 256, false),
  702. "The value to use for the JucePlugin_AAXIdentifier setting");
  703. }
  704. //==============================================================================
  705. static StringArray getVersionSegments (const Project& p)
  706. {
  707. auto segments = StringArray::fromTokens (p.getVersionString(), ",.", "");
  708. segments.trim();
  709. segments.removeEmptyStrings();
  710. return segments;
  711. }
  712. int Project::getVersionAsHexInteger() const
  713. {
  714. auto segments = getVersionSegments (*this);
  715. auto value = (segments[0].getIntValue() << 16)
  716. + (segments[1].getIntValue() << 8)
  717. + segments[2].getIntValue();
  718. if (segments.size() >= 4)
  719. value = (value << 8) + segments[3].getIntValue();
  720. return value;
  721. }
  722. String Project::getVersionAsHex() const
  723. {
  724. return "0x" + String::toHexString (getVersionAsHexInteger());
  725. }
  726. File Project::getBinaryDataCppFile (int index) const
  727. {
  728. auto cpp = getGeneratedCodeFolder().getChildFile ("BinaryData.cpp");
  729. if (index > 0)
  730. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  731. .withFileExtension (cpp.getFileExtension());
  732. return cpp;
  733. }
  734. Project::Item Project::getMainGroup()
  735. {
  736. return { *this, projectRoot.getChildWithName (Ids::MAINGROUP), false };
  737. }
  738. PropertiesFile& Project::getStoredProperties() const
  739. {
  740. return getAppSettings().getProjectProperties (getProjectUIDString());
  741. }
  742. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  743. {
  744. if (item.isImageFile())
  745. {
  746. found.add (new Project::Item (item));
  747. }
  748. else if (item.isGroup())
  749. {
  750. for (int i = 0; i < item.getNumChildren(); ++i)
  751. findImages (item.getChild (i), found);
  752. }
  753. }
  754. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  755. {
  756. findImages (getMainGroup(), items);
  757. }
  758. //==============================================================================
  759. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  760. : project (p), state (s), belongsToModule (isModuleCode)
  761. {
  762. }
  763. Project::Item::Item (const Item& other)
  764. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  765. {
  766. }
  767. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  768. String Project::Item::getID() const { return state [Ids::ID]; }
  769. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  770. Drawable* Project::Item::loadAsImageFile() const
  771. {
  772. const MessageManagerLock mml (ThreadPoolJob::getCurrentThreadPoolJob());
  773. if (! mml.lockWasGained())
  774. return nullptr;
  775. return isValid() ? Drawable::createFromImageFile (getFile())
  776. : nullptr;
  777. }
  778. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  779. {
  780. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  781. group.setID (uid);
  782. group.initialiseMissingProperties();
  783. group.getNameValue() = name;
  784. return group;
  785. }
  786. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  787. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  788. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  789. bool Project::Item::isImageFile() const
  790. {
  791. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  792. || getFile().hasFileExtension ("svg"));
  793. }
  794. Project::Item Project::Item::findItemWithID (const String& targetId) const
  795. {
  796. if (state [Ids::ID] == targetId)
  797. return *this;
  798. if (isGroup())
  799. {
  800. for (auto i = getNumChildren(); --i >= 0;)
  801. {
  802. auto found = getChild(i).findItemWithID (targetId);
  803. if (found.isValid())
  804. return found;
  805. }
  806. }
  807. return Item (project, ValueTree(), false);
  808. }
  809. bool Project::Item::canContain (const Item& child) const
  810. {
  811. if (isFile())
  812. return false;
  813. if (isGroup())
  814. return child.isFile() || child.isGroup();
  815. jassertfalse;
  816. return false;
  817. }
  818. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  819. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  820. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  821. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  822. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  823. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  824. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  825. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  826. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  827. bool Project::Item::isModuleCode() const { return belongsToModule; }
  828. String Project::Item::getFilePath() const
  829. {
  830. if (isFile())
  831. return state [Ids::file].toString();
  832. return {};
  833. }
  834. File Project::Item::getFile() const
  835. {
  836. if (isFile())
  837. return project.resolveFilename (state [Ids::file].toString());
  838. return {};
  839. }
  840. void Project::Item::setFile (const File& file)
  841. {
  842. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  843. jassert (getFile() == file);
  844. }
  845. void Project::Item::setFile (const RelativePath& file)
  846. {
  847. jassert (isFile());
  848. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  849. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  850. }
  851. bool Project::Item::renameFile (const File& newFile)
  852. {
  853. auto oldFile = getFile();
  854. if (oldFile.moveFileTo (newFile)
  855. || (newFile.exists() && ! oldFile.exists()))
  856. {
  857. setFile (newFile);
  858. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  859. return true;
  860. }
  861. return false;
  862. }
  863. bool Project::Item::containsChildForFile (const RelativePath& file) const
  864. {
  865. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  866. }
  867. Project::Item Project::Item::findItemForFile (const File& file) const
  868. {
  869. if (getFile() == file)
  870. return *this;
  871. if (isGroup())
  872. {
  873. for (auto i = getNumChildren(); --i >= 0;)
  874. {
  875. auto found = getChild(i).findItemForFile (file);
  876. if (found.isValid())
  877. return found;
  878. }
  879. }
  880. return Item (project, ValueTree(), false);
  881. }
  882. File Project::Item::determineGroupFolder() const
  883. {
  884. jassert (isGroup());
  885. File f;
  886. for (int i = 0; i < getNumChildren(); ++i)
  887. {
  888. f = getChild(i).getFile();
  889. if (f.exists())
  890. return f.getParentDirectory();
  891. }
  892. auto parent = getParent();
  893. if (parent != *this)
  894. {
  895. f = parent.determineGroupFolder();
  896. if (f.getChildFile (getName()).isDirectory())
  897. f = f.getChildFile (getName());
  898. }
  899. else
  900. {
  901. f = project.getProjectFolder();
  902. if (f.getChildFile ("Source").isDirectory())
  903. f = f.getChildFile ("Source");
  904. }
  905. return f;
  906. }
  907. void Project::Item::initialiseMissingProperties()
  908. {
  909. if (! state.hasProperty (Ids::ID))
  910. setID (createAlphaNumericUID());
  911. if (isFile())
  912. {
  913. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  914. }
  915. else if (isGroup())
  916. {
  917. for (auto i = getNumChildren(); --i >= 0;)
  918. getChild(i).initialiseMissingProperties();
  919. }
  920. }
  921. Value Project::Item::getNameValue()
  922. {
  923. return state.getPropertyAsValue (Ids::name, getUndoManager());
  924. }
  925. String Project::Item::getName() const
  926. {
  927. return state [Ids::name];
  928. }
  929. void Project::Item::addChild (const Item& newChild, int insertIndex)
  930. {
  931. state.addChild (newChild.state, insertIndex, getUndoManager());
  932. }
  933. void Project::Item::removeItemFromProject()
  934. {
  935. state.getParent().removeChild (state, getUndoManager());
  936. }
  937. Project::Item Project::Item::getParent() const
  938. {
  939. if (isMainGroup() || ! isGroup())
  940. return *this;
  941. return { project, state.getParent(), belongsToModule };
  942. }
  943. struct ItemSorter
  944. {
  945. static int compareElements (const ValueTree& first, const ValueTree& second)
  946. {
  947. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  948. }
  949. };
  950. struct ItemSorterWithGroupsAtStart
  951. {
  952. static int compareElements (const ValueTree& first, const ValueTree& second)
  953. {
  954. auto firstIsGroup = first.hasType (Ids::GROUP);
  955. auto secondIsGroup = second.hasType (Ids::GROUP);
  956. if (firstIsGroup == secondIsGroup)
  957. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  958. return firstIsGroup ? -1 : 1;
  959. }
  960. };
  961. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  962. {
  963. if (keepGroupsAtStart)
  964. {
  965. ItemSorterWithGroupsAtStart sorter;
  966. state.sort (sorter, undoManager, true);
  967. }
  968. else
  969. {
  970. ItemSorter sorter;
  971. state.sort (sorter, undoManager, true);
  972. }
  973. }
  974. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  975. {
  976. if (state.getNumChildren() == 0)
  977. return false;
  978. if (state.getNumChildren() == 1)
  979. return true;
  980. auto stateCopy = state.createCopy();
  981. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  982. return stateCopy.isEquivalentTo (state);
  983. }
  984. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  985. {
  986. sortGroup (state, keepGroupsAtStart, getUndoManager());
  987. if (recursive)
  988. for (auto i = getNumChildren(); --i >= 0;)
  989. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  990. }
  991. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  992. {
  993. for (auto i = state.getNumChildren(); --i >= 0;)
  994. {
  995. auto child = state.getChild (i);
  996. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  997. return { project, child, belongsToModule };
  998. }
  999. return addNewSubGroup (name, -1);
  1000. }
  1001. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  1002. {
  1003. auto newID = createGUID (getID() + name + String (getNumChildren()));
  1004. int n = 0;
  1005. while (project.getMainGroup().findItemWithID (newID).isValid())
  1006. newID = createGUID (newID + String (++n));
  1007. auto group = createGroup (project, name, newID, belongsToModule);
  1008. jassert (canContain (group));
  1009. addChild (group, insertIndex);
  1010. return group;
  1011. }
  1012. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  1013. {
  1014. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  1015. return false;
  1016. if (file.isDirectory())
  1017. {
  1018. auto group = addNewSubGroup (file.getFileName(), insertIndex);
  1019. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  1020. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  1021. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  1022. }
  1023. else if (file.existsAsFile())
  1024. {
  1025. if (! project.getMainGroup().findItemForFile (file).isValid())
  1026. addFileUnchecked (file, insertIndex, shouldCompile);
  1027. }
  1028. else
  1029. {
  1030. jassertfalse;
  1031. }
  1032. return true;
  1033. }
  1034. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  1035. {
  1036. auto wasSortedGroupsNotFirst = isGroupSorted (state, false);
  1037. auto wasSortedGroupsFirst = isGroupSorted (state, true);
  1038. if (! addFileAtIndex (file, 0, shouldCompile))
  1039. return false;
  1040. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  1041. sortAlphabetically (wasSortedGroupsFirst, false);
  1042. return true;
  1043. }
  1044. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  1045. {
  1046. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1047. item.initialiseMissingProperties();
  1048. item.getNameValue() = file.getFileName();
  1049. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  1050. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1051. if (canContain (item))
  1052. {
  1053. item.setFile (file);
  1054. addChild (item, insertIndex);
  1055. }
  1056. }
  1057. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  1058. {
  1059. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  1060. item.initialiseMissingProperties();
  1061. item.getNameValue() = file.getFileName();
  1062. item.getShouldCompileValue() = shouldCompile;
  1063. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  1064. if (canContain (item))
  1065. {
  1066. item.setFile (file);
  1067. addChild (item, insertIndex);
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. Icon Project::Item::getIcon (bool isOpen) const
  1073. {
  1074. auto& icons = getIcons();
  1075. if (isFile())
  1076. {
  1077. if (isImageFile())
  1078. return Icon (icons.imageDoc, Colours::transparentBlack);
  1079. return { icons.file, Colours::transparentBlack };
  1080. }
  1081. if (isMainGroup())
  1082. return { icons.juceLogo, Colours::orange };
  1083. return { isOpen ? icons.openFolder : icons.closedFolder, Colours::transparentBlack };
  1084. }
  1085. bool Project::Item::isIconCrossedOut() const
  1086. {
  1087. return isFile()
  1088. && ! (shouldBeCompiled()
  1089. || shouldBeAddedToBinaryResources()
  1090. || getFile().hasFileExtension (headerFileExtensions));
  1091. }
  1092. //==============================================================================
  1093. ValueTree Project::getConfigNode()
  1094. {
  1095. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  1096. }
  1097. ValueWithDefault Project::getConfigFlag (const String& name)
  1098. {
  1099. auto configNode = getConfigNode();
  1100. return { configNode, name, getUndoManagerFor (configNode) };
  1101. }
  1102. bool Project::isConfigFlagEnabled (const String& name, bool defaultIsEnabled) const
  1103. {
  1104. auto configValue = projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name, "default");
  1105. if (configValue == "default")
  1106. return defaultIsEnabled;
  1107. return configValue;
  1108. }
  1109. //==============================================================================
  1110. String Project::getPluginRTASCategoryCode()
  1111. {
  1112. if (static_cast<bool> (isPluginSynth()))
  1113. return "ePlugInCategory_SWGenerators";
  1114. auto s = getPluginRTASCategoryString();
  1115. if (s.isEmpty())
  1116. s = "ePlugInCategory_None";
  1117. return s;
  1118. }
  1119. String Project::getAUMainTypeString()
  1120. {
  1121. auto s = getPluginAUMainTypeString();
  1122. if (s.isEmpty())
  1123. {
  1124. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  1125. // Use aumi instead.
  1126. if (isPluginMidiEffect()) s = "'aumi'";
  1127. else if (isPluginSynth()) s = "kAudioUnitType_MusicDevice";
  1128. else if (pluginWantsMidiInput()) s = "kAudioUnitType_MusicEffect";
  1129. else s = "kAudioUnitType_Effect";
  1130. }
  1131. return s;
  1132. }
  1133. String Project::getAUMainTypeCode()
  1134. {
  1135. auto s = getPluginAUMainTypeString();
  1136. if (s.isEmpty())
  1137. {
  1138. if (isPluginMidiEffect()) s = "aumi";
  1139. else if (isPluginSynth()) s = "aumu";
  1140. else if (pluginWantsMidiInput()) s = "aumf";
  1141. else s = "aufx";
  1142. }
  1143. return s;
  1144. }
  1145. String Project::getIAATypeCode()
  1146. {
  1147. String s;
  1148. if (pluginWantsMidiInput())
  1149. {
  1150. if (isPluginSynth())
  1151. s = "auri";
  1152. else
  1153. s = "aurm";
  1154. }
  1155. else
  1156. {
  1157. if (isPluginSynth())
  1158. s = "aurg";
  1159. else
  1160. s = "aurx";
  1161. }
  1162. return s;
  1163. }
  1164. String Project::getIAAPluginName()
  1165. {
  1166. auto s = getPluginManufacturerString();
  1167. s << ": ";
  1168. s << getPluginNameString();
  1169. return s;
  1170. }
  1171. String Project::getPluginVSTCategoryString()
  1172. {
  1173. auto s = pluginVSTCategoryValue.get().toString().trim();
  1174. if (s.isEmpty())
  1175. s = isPluginSynth() ? "kPlugCategSynth" : "kPlugCategEffect";
  1176. return s;
  1177. }
  1178. bool Project::isAUPluginHost()
  1179. {
  1180. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1181. }
  1182. bool Project::isVSTPluginHost()
  1183. {
  1184. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1185. }
  1186. bool Project::isVST3PluginHost()
  1187. {
  1188. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1189. }
  1190. //==============================================================================
  1191. EnabledModuleList& Project::getModules()
  1192. {
  1193. if (enabledModulesList == nullptr)
  1194. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  1195. return *enabledModulesList;
  1196. }
  1197. //==============================================================================
  1198. ValueTree Project::getExporters()
  1199. {
  1200. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1201. }
  1202. int Project::getNumExporters()
  1203. {
  1204. return getExporters().getNumChildren();
  1205. }
  1206. ProjectExporter* Project::createExporter (int index)
  1207. {
  1208. jassert (index >= 0 && index < getNumExporters());
  1209. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1210. }
  1211. void Project::addNewExporter (const String& exporterName)
  1212. {
  1213. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1214. exp->getTargetLocationValue() = exp->getTargetLocationString()
  1215. + getUniqueTargetFolderSuffixForExporter (exp->getName(), exp->getTargetLocationString());
  1216. auto exportersTree = getExporters();
  1217. exportersTree.appendChild (exp->settings, getUndoManagerFor (exportersTree));
  1218. }
  1219. void Project::createExporterForCurrentPlatform()
  1220. {
  1221. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1222. }
  1223. String Project::getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& base)
  1224. {
  1225. StringArray buildFolders;
  1226. auto exportersTree = getExporters();
  1227. auto type = ProjectExporter::getValueTreeNameForExporter (exporterName);
  1228. for (int i = 0; i < exportersTree.getNumChildren(); ++i)
  1229. {
  1230. auto exporterNode = exportersTree.getChild (i);
  1231. if (exporterNode.getType() == Identifier (type))
  1232. buildFolders.add (exporterNode.getProperty ("targetFolder").toString());
  1233. }
  1234. if (buildFolders.size() == 0 || ! buildFolders.contains (base))
  1235. return {};
  1236. buildFolders.remove (buildFolders.indexOf (base));
  1237. int num = 1;
  1238. for (auto f : buildFolders)
  1239. {
  1240. if (! f.endsWith ("_" + String (num)))
  1241. break;
  1242. ++num;
  1243. }
  1244. return "_" + String (num);
  1245. }
  1246. //==============================================================================
  1247. String Project::getFileTemplate (const String& templateName)
  1248. {
  1249. int dataSize;
  1250. if (auto* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1251. return String::fromUTF8 (data, dataSize);
  1252. jassertfalse;
  1253. return {};
  1254. }
  1255. //==============================================================================
  1256. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1257. Project::ExporterIterator::~ExporterIterator() {}
  1258. bool Project::ExporterIterator::next()
  1259. {
  1260. if (++index >= project.getNumExporters())
  1261. return false;
  1262. exporter = project.createExporter (index);
  1263. if (exporter == nullptr)
  1264. {
  1265. jassertfalse; // corrupted project file?
  1266. return next();
  1267. }
  1268. return true;
  1269. }