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.

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