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.

294 lines
13KB

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