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.

1546 lines
58KB

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