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.

203 lines
7.8KB

  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. #pragma once
  20. #include "jucer_Project.h"
  21. class ProjectExporter;
  22. class ProjectSaver;
  23. //==============================================================================
  24. bool isJUCEModulesFolder (const File&);
  25. bool isJUCEFolder (const File&);
  26. //==============================================================================
  27. struct ModuleDescription
  28. {
  29. ModuleDescription() {}
  30. ModuleDescription (const File& folder);
  31. ModuleDescription (const var& info) : moduleInfo (info) {}
  32. bool isValid() const { return getID().isNotEmpty(); }
  33. String getID() const { return moduleInfo [Ids::ID_uppercase].toString(); }
  34. String getVendor() const { return moduleInfo [Ids::vendor].toString(); }
  35. String getVersion() const { return moduleInfo [Ids::version].toString(); }
  36. String getName() const { return moduleInfo [Ids::name].toString(); }
  37. String getDescription() const { return moduleInfo [Ids::description].toString(); }
  38. String getLicense() const { return moduleInfo [Ids::license].toString(); }
  39. String getMinimumCppStandard() const { return moduleInfo [Ids::minimumCppStandard].toString(); }
  40. String getPreprocessorDefs() const { return moduleInfo [Ids::defines].toString(); }
  41. String getExtraSearchPaths() const { return moduleInfo [Ids::searchpaths].toString(); }
  42. StringArray getDependencies() const;
  43. File getFolder() const { jassert (moduleFolder != File()); return moduleFolder; }
  44. File getHeader() const;
  45. bool isPluginClient() const { return getID() == "juce_audio_plugin_client"; }
  46. File moduleFolder;
  47. var moduleInfo;
  48. URL url;
  49. };
  50. //==============================================================================
  51. class LibraryModule
  52. {
  53. public:
  54. LibraryModule (const ModuleDescription&);
  55. bool isValid() const { return moduleInfo.isValid(); }
  56. String getID() const { return moduleInfo.getID(); }
  57. String getVendor() const { return moduleInfo.getVendor(); }
  58. String getVersion() const { return moduleInfo.getVersion(); }
  59. String getName() const { return moduleInfo.getName(); }
  60. String getDescription() const { return moduleInfo.getDescription(); }
  61. String getLicense() const { return moduleInfo.getLicense(); }
  62. String getMinimumCppStandard() const { return moduleInfo.getMinimumCppStandard(); }
  63. File getFolder() const { return moduleInfo.getFolder(); }
  64. void writeIncludes (ProjectSaver&, OutputStream&);
  65. void addSettingsForModuleToExporter (ProjectExporter&, ProjectSaver&) const;
  66. void getConfigFlags (Project&, OwnedArray<Project::ConfigFlag>& flags) const;
  67. void findBrowseableFiles (const File& localModuleFolder, Array<File>& files) const;
  68. struct CompileUnit
  69. {
  70. File file;
  71. bool isCompiledForObjC, isCompiledForNonObjC;
  72. void writeInclude (MemoryOutputStream&) const;
  73. bool isNeededForExporter (ProjectExporter&) const;
  74. String getFilenameForProxyFile() const;
  75. static bool hasSuffix (const File&, const char*);
  76. };
  77. Array<CompileUnit> getAllCompileUnits (ProjectType::Target::Type forTarget = ProjectType::Target::unspecified) const;
  78. void findAndAddCompiledUnits (ProjectExporter&, ProjectSaver*, Array<File>& result,
  79. ProjectType::Target::Type forTarget = ProjectType::Target::unspecified) const;
  80. ModuleDescription moduleInfo;
  81. private:
  82. mutable Array<File> sourceFiles;
  83. OwnedArray<Project::ConfigFlag> configFlags;
  84. void addBrowseableCode (ProjectExporter&, const Array<File>& compiled, const File& localModuleFolder) const;
  85. };
  86. //==============================================================================
  87. using ModuleIDAndFolder = std::pair<String, File>;
  88. using ModuleIDAndFolderList = std::vector<ModuleIDAndFolder>;
  89. class AvailableModuleList
  90. {
  91. public:
  92. AvailableModuleList();
  93. void scanPaths (const Array<File>&);
  94. void scanPathsAsync (const Array<File>&);
  95. ModuleIDAndFolderList getAllModules() const;
  96. ModuleIDAndFolder getModuleWithID (const String&) const;
  97. void removeDuplicates (const ModuleIDAndFolderList& other);
  98. //==============================================================================
  99. struct Listener
  100. {
  101. virtual ~Listener() {}
  102. virtual void availableModulesChanged() = 0;
  103. };
  104. void addListener (Listener* listenerToAdd) { listeners.add (listenerToAdd); }
  105. void removeListener (Listener* listenerToRemove) { listeners.remove (listenerToRemove); }
  106. private:
  107. ThreadPoolJob* createScannerJob (const Array<File>&);
  108. void removePendingAndAddJob (ThreadPoolJob*);
  109. ThreadPool scanPool { 1 };
  110. ModuleIDAndFolderList moduleList;
  111. ListenerList<Listener> listeners;
  112. CriticalSection lock;
  113. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AvailableModuleList)
  114. };
  115. //==============================================================================
  116. class EnabledModuleList
  117. {
  118. public:
  119. EnabledModuleList (Project&, const ValueTree&);
  120. static File findDefaultModulesFolder (Project&);
  121. bool isModuleEnabled (const String& moduleID) const;
  122. bool shouldUseGlobalPath (const String& moduleID) const;
  123. Value getShouldUseGlobalPathValue (const String& moduleID) const;
  124. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  125. Value shouldCopyModuleFilesLocally (const String& moduleID) const;
  126. void removeModule (String moduleID);
  127. bool isAudioPluginModuleMissing() const;
  128. ModuleDescription getModuleInfo (const String& moduleID);
  129. void addModule (const File& moduleManifestFile, bool copyLocally, bool useGlobalPath, bool sendAnalyticsEvent);
  130. void addModuleInteractive (const String& moduleID);
  131. void addModuleFromUserSelectedFile();
  132. void addModuleOfferingToCopy (const File&, bool isFromUserSpecifiedFolder);
  133. StringArray getAllModules() const;
  134. StringArray getExtraDependenciesNeeded (const String& moduleID) const;
  135. bool doesModuleHaveHigherCppStandardThanProject (const String& moduleID);
  136. void createRequiredModules (OwnedArray<LibraryModule>& modules);
  137. int getNumModules() const { return state.getNumChildren(); }
  138. String getModuleID (int index) const { return state.getChild (index) [Ids::ID].toString(); }
  139. bool areMostModulesUsingGlobalPath() const;
  140. bool areMostModulesCopiedLocally() const;
  141. void setLocalCopyModeForAllModules (bool copyLocally);
  142. void sortAlphabetically();
  143. Project& project;
  144. ValueTree state;
  145. private:
  146. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  147. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (EnabledModuleList)
  148. };