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.

297 lines
13KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef __JUCER_PROJECT_JUCEHEADER__
  18. #define __JUCER_PROJECT_JUCEHEADER__
  19. #include "../jucer_Headers.h"
  20. class ProjectExporter;
  21. class ProjectType;
  22. class ModuleList;
  23. class LibraryModule;
  24. //==============================================================================
  25. class Project : public FileBasedDocument,
  26. public ValueTree::Listener
  27. {
  28. public:
  29. //==============================================================================
  30. Project (const File& file);
  31. ~Project();
  32. //==============================================================================
  33. // FileBasedDocument stuff..
  34. String getDocumentTitle() override;
  35. Result loadDocument (const File& file) override;
  36. Result saveDocument (const File& file) override;
  37. Result saveProject (const File& file, bool isCommandLineApp);
  38. Result saveResourcesOnly (const File& file);
  39. File getLastDocumentOpened() override;
  40. void setLastDocumentOpened (const File& file) override;
  41. void setTitle (const String& newTitle);
  42. //==============================================================================
  43. ValueTree getProjectRoot() const { return projectRoot; }
  44. String getTitle() const;
  45. Value getProjectNameValue() { return getMainGroup().getNameValue(); }
  46. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  47. String getProjectUID() const { return projectRoot [Ids::ID]; }
  48. //==============================================================================
  49. template <class FileType>
  50. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  51. {
  52. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  53. }
  54. File resolveFilename (String filename) const;
  55. String getRelativePathForFile (const File& file) const;
  56. //==============================================================================
  57. // Creates editors for the project settings
  58. void createPropertyEditors (PropertyListBuilder&);
  59. //==============================================================================
  60. // project types
  61. const ProjectType& getProjectType() const;
  62. Value getProjectTypeValue() { return getProjectValue (Ids::projectType); }
  63. String getProjectTypeString() const { return projectRoot [Ids::projectType]; }
  64. Value getVersionValue() { return getProjectValue (Ids::version); }
  65. String getVersionString() const { return projectRoot [Ids::version]; }
  66. String getVersionAsHex() const;
  67. int getVersionAsHexInteger() const;
  68. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  69. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getTitle(), false, true, false); }
  70. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  71. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  72. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  73. //==============================================================================
  74. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  75. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  76. StringPairArray getPreprocessorDefs() const;
  77. Value getProjectUserNotes() { return getProjectValue (Ids::userNotes); }
  78. //==============================================================================
  79. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  80. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  81. File getBinaryDataCppFile (int index) const;
  82. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  83. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  84. //==============================================================================
  85. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  86. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  87. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  88. String getAppConfigFilename() const { return "AppConfig.h"; }
  89. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  90. int getNumSeparateAmalgamatedFiles() const { return 4; }
  91. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  92. //==============================================================================
  93. class Item
  94. {
  95. public:
  96. //==============================================================================
  97. Item (Project& project, const ValueTree& itemNode);
  98. Item (const Item& other);
  99. static Item createGroup (Project& project, const String& name, const String& uid);
  100. void initialiseMissingProperties();
  101. //==============================================================================
  102. bool isValid() const { return state.isValid(); }
  103. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  104. bool operator!= (const Item& other) const { return ! operator== (other); }
  105. //==============================================================================
  106. bool isFile() const;
  107. bool isGroup() const;
  108. bool isMainGroup() const;
  109. bool isImageFile() const;
  110. String getID() const;
  111. void setID (const String& newID);
  112. Item findItemWithID (const String& targetId) const; // (recursive search)
  113. String getImageFileID() const;
  114. Image loadAsImageFile() const;
  115. //==============================================================================
  116. Value getNameValue();
  117. String getName() const;
  118. File getFile() const;
  119. String getFilePath() const;
  120. void setFile (const File& file);
  121. void setFile (const RelativePath& file);
  122. File determineGroupFolder() const;
  123. bool renameFile (const File& newFile);
  124. bool shouldBeAddedToTargetProject() const;
  125. bool shouldBeCompiled() const;
  126. Value getShouldCompileValue();
  127. bool shouldBeAddedToBinaryResources() const;
  128. Value getShouldAddToResourceValue();
  129. Value getShouldInhibitWarningsValue();
  130. bool shouldInhibitWarnings() const;
  131. Value getShouldUseStdCallValue();
  132. bool shouldUseStdCall() const;
  133. //==============================================================================
  134. bool canContain (const Item& child) const;
  135. int getNumChildren() const { return state.getNumChildren(); }
  136. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  137. Item addNewSubGroup (const String& name, int insertIndex);
  138. Item getOrCreateSubGroup (const String& name);
  139. void addChild (const Item& newChild, int insertIndex);
  140. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  141. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  142. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  143. void removeItemFromProject();
  144. void sortAlphabetically (bool keepGroupsAtStart);
  145. Item findItemForFile (const File& file) const;
  146. bool containsChildForFile (const RelativePath& file) const;
  147. Item getParent() const;
  148. Item createCopy();
  149. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  150. Icon getIcon() const;
  151. bool isIconCrossedOut() const;
  152. Project& project;
  153. ValueTree state;
  154. private:
  155. Item& operator= (const Item&);
  156. };
  157. Item getMainGroup();
  158. void findAllImageItems (OwnedArray<Item>& items);
  159. //==============================================================================
  160. ValueTree getExporters();
  161. int getNumExporters();
  162. ProjectExporter* createExporter (int index);
  163. void addNewExporter (const String& exporterName);
  164. void createExporterForCurrentPlatform();
  165. struct ExporterIterator
  166. {
  167. ExporterIterator (Project& project);
  168. ~ExporterIterator();
  169. bool next();
  170. ProjectExporter& operator*() const { return *exporter; }
  171. ProjectExporter* operator->() const { return exporter; }
  172. ScopedPointer<ProjectExporter> exporter;
  173. int index;
  174. private:
  175. Project& project;
  176. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  177. };
  178. //==============================================================================
  179. struct ConfigFlag
  180. {
  181. String symbol, description, sourceModuleID;
  182. Value value; // 1 = true, 2 = false, anything else = use default
  183. };
  184. static const char* const configFlagDefault;
  185. static const char* const configFlagEnabled;
  186. static const char* const configFlagDisabled;
  187. Value getConfigFlag (const String& name);
  188. bool isConfigFlagEnabled (const String& name) const;
  189. //==============================================================================
  190. bool isModuleEnabled (const String& moduleID) const;
  191. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  192. Value shouldCopyModuleFilesLocally (const String& moduleID);
  193. void addModule (const String& moduleID, bool shouldCopyFilesLocally);
  194. void removeModule (const String& moduleID);
  195. int getNumModules() const;
  196. String getModuleID (int index) const;
  197. void addDefaultModules (bool shouldCopyFilesLocally);
  198. bool isAudioPluginModuleMissing() const;
  199. void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;
  200. //==============================================================================
  201. String getFileTemplate (const String& templateName);
  202. //==============================================================================
  203. PropertiesFile& getStoredProperties() const;
  204. //==============================================================================
  205. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  206. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  207. void valueTreeChildRemoved (ValueTree&, ValueTree&) override;
  208. void valueTreeChildOrderChanged (ValueTree&) override;
  209. void valueTreeParentChanged (ValueTree&) override;
  210. //==============================================================================
  211. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  212. //==============================================================================
  213. static const char* projectFileExtension;
  214. private:
  215. friend class Item;
  216. ValueTree projectRoot;
  217. void updateProjectSettings();
  218. void sanitiseConfigFlags();
  219. void setMissingDefaultValues();
  220. ValueTree getConfigurations() const;
  221. ValueTree getConfigNode();
  222. ValueTree getModulesNode();
  223. void updateOldStyleConfigList();
  224. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  225. void removeDefunctExporters();
  226. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  227. };
  228. #endif // __JUCER_PROJECT_JUCEHEADER__