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.

289 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. Value getProjectName() { return getMainGroup().getNameValue(); }
  46. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  47. String getProjectUID() const { return projectRoot [ComponentBuilder::idProperty]; }
  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. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  68. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  69. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  70. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  71. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  72. //==============================================================================
  73. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  74. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  75. StringPairArray getPreprocessorDefs() const;
  76. //==============================================================================
  77. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  78. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  79. File getBinaryDataCppFile() const { return getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"); }
  80. //==============================================================================
  81. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  82. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  83. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  84. String getAppConfigFilename() const { return "AppConfig.h"; }
  85. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  86. int getNumSeparateAmalgamatedFiles() const { return 4; }
  87. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  88. //==============================================================================
  89. class Item
  90. {
  91. public:
  92. //==============================================================================
  93. Item (Project& project, const ValueTree& itemNode);
  94. Item (const Item& other);
  95. static Item createGroup (Project& project, const String& name, const String& uid);
  96. void initialiseMissingProperties();
  97. //==============================================================================
  98. bool isValid() const { return state.isValid(); }
  99. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  100. bool operator!= (const Item& other) const { return ! operator== (other); }
  101. //==============================================================================
  102. bool isFile() const;
  103. bool isGroup() const;
  104. bool isMainGroup() const;
  105. bool isImageFile() const;
  106. String getID() const;
  107. void setID (const String& newID);
  108. Item findItemWithID (const String& targetId) const; // (recursive search)
  109. String getImageFileID() const;
  110. Image loadAsImageFile() const;
  111. //==============================================================================
  112. Value getNameValue();
  113. String getName() const;
  114. File getFile() const;
  115. String getFilePath() const;
  116. void setFile (const File& file);
  117. void setFile (const RelativePath& file);
  118. File determineGroupFolder() const;
  119. bool renameFile (const File& newFile);
  120. bool shouldBeAddedToTargetProject() const;
  121. bool shouldBeCompiled() const;
  122. Value getShouldCompileValue();
  123. bool shouldBeAddedToBinaryResources() const;
  124. Value getShouldAddToResourceValue();
  125. Value getShouldInhibitWarningsValue();
  126. bool shouldInhibitWarnings() const;
  127. Value getShouldUseStdCallValue();
  128. bool shouldUseStdCall() const;
  129. //==============================================================================
  130. bool canContain (const Item& child) const;
  131. int getNumChildren() const { return state.getNumChildren(); }
  132. Item getChild (int index) const { return Item (project, state.getChild (index)); }
  133. Item addNewSubGroup (const String& name, int insertIndex);
  134. Item getOrCreateSubGroup (const String& name);
  135. void addChild (const Item& newChild, int insertIndex);
  136. bool addFile (const File& file, int insertIndex, bool shouldCompile);
  137. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  138. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  139. void removeItemFromProject();
  140. void sortAlphabetically (bool keepGroupsAtStart);
  141. Item findItemForFile (const File& file) const;
  142. bool containsChildForFile (const RelativePath& file) const;
  143. Item getParent() const;
  144. Item createCopy();
  145. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  146. const Drawable* getIcon() const;
  147. Project& project;
  148. ValueTree state;
  149. private:
  150. Item& operator= (const Item&);
  151. };
  152. Item getMainGroup();
  153. void findAllImageItems (OwnedArray<Item>& items);
  154. //==============================================================================
  155. ValueTree getExporters();
  156. int getNumExporters();
  157. ProjectExporter* createExporter (int index);
  158. void addNewExporter (const String& exporterName);
  159. void deleteExporter (int index);
  160. void createDefaultExporters();
  161. struct ExporterIterator
  162. {
  163. ExporterIterator (Project& project);
  164. ~ExporterIterator();
  165. bool next();
  166. ProjectExporter& operator*() const { return *exporter; }
  167. ProjectExporter* operator->() const { return exporter; }
  168. ScopedPointer<ProjectExporter> exporter;
  169. int index;
  170. private:
  171. Project& project;
  172. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator);
  173. };
  174. //==============================================================================
  175. struct ConfigFlag
  176. {
  177. String symbol, description, sourceModuleID;
  178. Value value; // 1 = true, 2 = false, anything else = use default
  179. };
  180. static const char* const configFlagDefault;
  181. static const char* const configFlagEnabled;
  182. static const char* const configFlagDisabled;
  183. Value getConfigFlag (const String& name);
  184. bool isConfigFlagEnabled (const String& name) const;
  185. //==============================================================================
  186. bool isModuleEnabled (const String& moduleID) const;
  187. Value shouldShowAllModuleFilesInProject (const String& moduleID);
  188. Value shouldCopyModuleFilesLocally (const String& moduleID);
  189. void addModule (const String& moduleID, bool shouldCopyFilesLocally);
  190. void removeModule (const String& moduleID);
  191. int getNumModules() const;
  192. String getModuleID (int index) const;
  193. void addDefaultModules (bool shouldCopyFilesLocally);
  194. bool isAudioPluginModuleMissing() const;
  195. void createRequiredModules (const ModuleList& availableModules, OwnedArray<LibraryModule>& modules) const;
  196. //==============================================================================
  197. String getFileTemplate (const String& templateName);
  198. //==============================================================================
  199. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  200. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  201. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  202. void valueTreeChildOrderChanged (ValueTree& parentTree);
  203. void valueTreeParentChanged (ValueTree& tree);
  204. //==============================================================================
  205. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  206. //==============================================================================
  207. static const char* projectFileExtension;
  208. private:
  209. friend class Item;
  210. ValueTree projectRoot;
  211. DrawableImage mainProjectIcon;
  212. void updateProjectSettings();
  213. void sanitiseConfigFlags();
  214. void setMissingDefaultValues();
  215. ValueTree getConfigurations() const;
  216. ValueTree getConfigNode();
  217. ValueTree getModulesNode();
  218. void updateOldStyleConfigList();
  219. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  220. void removeDefunctExporters();
  221. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  222. };
  223. #endif // __JUCER_PROJECT_JUCEHEADER__