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.

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