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