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.

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