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.

322 lines
16KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. //==============================================================================
  24. class Project : public FileBasedDocument,
  25. public ValueTree::Listener
  26. {
  27. public:
  28. //==============================================================================
  29. Project (const File& file);
  30. ~Project();
  31. //==============================================================================
  32. // FileBasedDocument stuff..
  33. const String getDocumentTitle();
  34. const String loadDocument (const File& file);
  35. const String saveDocument (const File& file);
  36. const File getLastDocumentOpened();
  37. void setLastDocumentOpened (const File& file);
  38. void setTitle (const String& newTitle);
  39. //==============================================================================
  40. ValueTree getProjectRoot() const { return projectRoot; }
  41. Value getProjectName() { return getMainGroup().getName(); }
  42. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  43. String getProjectUID() const { return projectRoot [Ids::id_]; }
  44. //==============================================================================
  45. template <class FileType>
  46. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  47. {
  48. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  49. }
  50. File resolveFilename (String filename) const;
  51. String getRelativePathForFile (const File& file) const;
  52. //==============================================================================
  53. // Creates editors for the project settings
  54. void createPropertyEditors (Array <PropertyComponent*>& properties);
  55. //==============================================================================
  56. // project types
  57. const ProjectType& getProjectType() const;
  58. Value getProjectTypeValue() const { return getProjectValue ("projectType"); }
  59. Value getVersion() const { return getProjectValue ("version"); }
  60. String getVersionAsHex() const;
  61. Value getBundleIdentifier() const { return getProjectValue ("bundleIdentifier"); }
  62. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  63. //==============================================================================
  64. // linkage modes..
  65. static const char* const notLinkedToJuce;
  66. static const char* const useLinkedJuce;
  67. static const char* const useAmalgamatedJuce;
  68. static const char* const useAmalgamatedJuceViaSingleTemplate;
  69. static const char* const useAmalgamatedJuceViaMultipleTemplates;
  70. Value getJuceLinkageModeValue() const { return getProjectValue ("juceLinkage"); }
  71. String getJuceLinkageMode() const { return getJuceLinkageModeValue().toString(); }
  72. bool isUsingWrapperFiles() const { return isUsingFullyAmalgamatedFile() || isUsingSingleTemplateFile() || isUsingMultipleTemplateFiles(); }
  73. bool isUsingFullyAmalgamatedFile() const { return getJuceLinkageMode() == useAmalgamatedJuce; }
  74. bool isUsingSingleTemplateFile() const { return getJuceLinkageMode() == useAmalgamatedJuceViaSingleTemplate; }
  75. bool isUsingMultipleTemplateFiles() const { return getJuceLinkageMode() == useAmalgamatedJuceViaMultipleTemplates; }
  76. //==============================================================================
  77. Value getProjectValue (const Identifier& name) const { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  78. Value getProjectPreprocessorDefs() const { return getProjectValue (Ids::defines); }
  79. StringPairArray getPreprocessorDefs() const;
  80. Value getBigIconImageItemID() const { return getProjectValue ("bigIcon"); }
  81. Value getSmallIconImageItemID() const { return getProjectValue ("smallIcon"); }
  82. Image getBigIcon();
  83. Image getSmallIcon();
  84. //==============================================================================
  85. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  86. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  87. File getPluginCharacteristicsFile() const { return getGeneratedCodeFolder().getChildFile (getPluginCharacteristicsFilename()); }
  88. File getLocalJuceFolder();
  89. //==============================================================================
  90. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  91. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  92. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  93. String getAppConfigFilename() const { return "AppConfig.h"; }
  94. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  95. int getNumSeparateAmalgamatedFiles() const { return 4; }
  96. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  97. String getJuceCodeGroupName() const { return "Juce Library Code"; }
  98. String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  99. //==============================================================================
  100. class Item
  101. {
  102. public:
  103. //==============================================================================
  104. Item (Project& project, const ValueTree& itemNode);
  105. Item (const Item& other);
  106. Item& operator= (const Item& other);
  107. ~Item();
  108. static Item createGroup (Project& project, const String& name);
  109. void initialiseNodeValues();
  110. //==============================================================================
  111. bool isValid() const { return node.isValid(); }
  112. const ValueTree& getNode() const noexcept { return node; }
  113. ValueTree& getNode() noexcept { return node; }
  114. Project& getProject() const noexcept { return *project; }
  115. bool operator== (const Item& other) const { return node == other.node && project == other.project; }
  116. bool operator!= (const Item& other) const { return ! operator== (other); }
  117. //==============================================================================
  118. bool isFile() const;
  119. bool isGroup() const;
  120. bool isMainGroup() const;
  121. bool isImageFile() const;
  122. String getID() const;
  123. Item findItemWithID (const String& targetId) const; // (recursive search)
  124. String getImageFileID() const;
  125. void setID (const String& newID);
  126. //==============================================================================
  127. Value getName() const;
  128. File getFile() const;
  129. String getFilePath() const;
  130. void setFile (const File& file);
  131. void setFile (const RelativePath& file);
  132. File determineGroupFolder() const;
  133. bool renameFile (const File& newFile);
  134. bool shouldBeAddedToTargetProject() const;
  135. bool shouldBeCompiled() const;
  136. Value getShouldCompileValue() const;
  137. bool shouldBeAddedToBinaryResources() const;
  138. Value getShouldAddToResourceValue() const;
  139. Value getShouldInhibitWarningsValue() const;
  140. //==============================================================================
  141. bool canContain (const Item& child) const;
  142. int getNumChildren() const { return node.getNumChildren(); }
  143. Item getChild (int index) const { return Item (getProject(), node.getChild (index)); }
  144. Item addNewSubGroup (const String& name, int insertIndex);
  145. void addChild (const Item& newChild, int insertIndex);
  146. bool addFile (const File& file, int insertIndex);
  147. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  148. void removeItemFromProject();
  149. void sortAlphabetically();
  150. Item findItemForFile (const File& file) const;
  151. Item getParent() const;
  152. Item createCopy();
  153. const Drawable* getIcon() const;
  154. private:
  155. //==============================================================================
  156. Project* project;
  157. ValueTree node;
  158. UndoManager* getUndoManager() const { return getProject().getUndoManagerFor (node); }
  159. };
  160. Item getMainGroup();
  161. void findAllImageItems (OwnedArray<Item>& items);
  162. //==============================================================================
  163. class BuildConfiguration
  164. {
  165. public:
  166. BuildConfiguration (const BuildConfiguration&);
  167. const BuildConfiguration& operator= (const BuildConfiguration&);
  168. ~BuildConfiguration();
  169. //==============================================================================
  170. Project& getProject() const { return *project; }
  171. void createPropertyEditors (Array <PropertyComponent*>& properties);
  172. //==============================================================================
  173. Value getName() const { return getValue (Ids::name); }
  174. Value isDebug() const { return getValue (Ids::isDebug); }
  175. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  176. // the path relative to the build folder in which the binary should go
  177. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  178. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  179. String getGCCOptimisationFlag() const;
  180. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  181. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  182. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  183. StringArray getHeaderSearchPaths() const;
  184. static const char* const osxVersionDefault;
  185. static const char* const osxVersion10_4;
  186. static const char* const osxVersion10_5;
  187. static const char* const osxVersion10_6;
  188. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  189. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  190. static const char* const osxArch_Default;
  191. static const char* const osxArch_Native;
  192. static const char* const osxArch_32BitUniversal;
  193. static const char* const osxArch_64BitUniversal;
  194. static const char* const osxArch_64Bit;
  195. Value getMacArchitecture() const { return getValue (Ids::osxArchitecture); }
  196. //==============================================================================
  197. private:
  198. friend class Project;
  199. Project* project;
  200. ValueTree config;
  201. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  202. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  203. BuildConfiguration (Project* project, const ValueTree& configNode);
  204. };
  205. int getNumConfigurations() const;
  206. BuildConfiguration getConfiguration (int index);
  207. void addNewConfiguration (BuildConfiguration* configToCopy);
  208. void deleteConfiguration (int index);
  209. bool hasConfigurationNamed (const String& name) const;
  210. String getUniqueConfigName (String name) const;
  211. //==============================================================================
  212. ValueTree getExporters();
  213. int getNumExporters();
  214. ProjectExporter* createExporter (int index);
  215. void addNewExporter (int exporterIndex);
  216. void deleteExporter (int index);
  217. void createDefaultExporters();
  218. //==============================================================================
  219. struct ConfigFlag
  220. {
  221. String symbol, description;
  222. Value value; // 1 = true, 2 = false, anything else = use default
  223. };
  224. void getAllConfigFlags (OwnedArray <ConfigFlag>& flags);
  225. static const char* const configFlagDefault;
  226. static const char* const configFlagEnabled;
  227. static const char* const configFlagDisabled;
  228. Value getConfigFlag (const String& name);
  229. bool isConfigFlagEnabled (const String& name) const;
  230. //==============================================================================
  231. String getFileTemplate (const String& templateName);
  232. //==============================================================================
  233. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  234. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  235. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  236. void valueTreeChildOrderChanged (ValueTree& parentTree);
  237. void valueTreeParentChanged (ValueTree& tree);
  238. //==============================================================================
  239. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  240. //==============================================================================
  241. static const char* projectFileExtension;
  242. static void resaveJucerFile (const File& file);
  243. private:
  244. friend class Item;
  245. ValueTree projectRoot;
  246. static File lastDocumentOpened;
  247. DrawableImage mainProjectIcon;
  248. void updateProjectSettings();
  249. void setMissingDefaultValues();
  250. ValueTree getConfigurations() const;
  251. void createDefaultConfigs();
  252. ValueTree getConfigNode();
  253. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  254. };
  255. #endif // __JUCER_PROJECT_JUCEHEADER__