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.

342 lines
17KB

  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. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  85. Value shouldBuildVST() const { return getProjectValue ("buildVST"); }
  86. Value shouldBuildRTAS() const { return getProjectValue ("buildRTAS"); }
  87. Value shouldBuildAU() const { return getProjectValue ("buildAU"); }
  88. Value getPluginName() const { return getProjectValue ("pluginName"); }
  89. Value getPluginDesc() const { return getProjectValue ("pluginDesc"); }
  90. Value getPluginManufacturer() const { return getProjectValue ("pluginManufacturer"); }
  91. Value getPluginManufacturerCode() const { return getProjectValue ("pluginManufacturerCode"); }
  92. Value getPluginCode() const { return getProjectValue ("pluginCode"); }
  93. Value getPluginChannelConfigs() const { return getProjectValue ("pluginChannelConfigs"); }
  94. Value getPluginIsSynth() const { return getProjectValue ("pluginIsSynth"); }
  95. Value getPluginWantsMidiInput() const { return getProjectValue ("pluginWantsMidiIn"); }
  96. Value getPluginProducesMidiOut() const { return getProjectValue ("pluginProducesMidiOut"); }
  97. Value getPluginSilenceInProducesSilenceOut() const { return getProjectValue ("pluginSilenceInIsSilenceOut"); }
  98. Value getPluginTailLengthSeconds() const { return getProjectValue ("pluginTailLength"); }
  99. Value getPluginEditorNeedsKeyFocus() const { return getProjectValue ("pluginEditorRequiresKeys"); }
  100. Value getPluginAUExportPrefix() const { return getProjectValue ("pluginAUExportPrefix"); }
  101. Value getPluginAUCocoaViewClassName() const { return getProjectValue ("pluginAUViewClass"); }
  102. Value getPluginRTASCategory() const { return getProjectValue ("pluginRTASCategory"); }
  103. //==============================================================================
  104. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  105. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  106. File getPluginCharacteristicsFile() const { return getGeneratedCodeFolder().getChildFile (getPluginCharacteristicsFilename()); }
  107. File getLocalJuceFolder();
  108. //==============================================================================
  109. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  110. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  111. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  112. String getAppConfigFilename() const { return "AppConfig.h"; }
  113. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  114. int getNumSeparateAmalgamatedFiles() const { return 4; }
  115. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  116. String getJuceCodeGroupName() const { return "Juce Library Code"; }
  117. String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  118. //==============================================================================
  119. class Item
  120. {
  121. public:
  122. //==============================================================================
  123. Item (Project& project, const ValueTree& itemNode);
  124. Item (const Item& other);
  125. Item& operator= (const Item& other);
  126. ~Item();
  127. static Item createGroup (Project& project, const String& name);
  128. void initialiseNodeValues();
  129. //==============================================================================
  130. bool isValid() const { return node.isValid(); }
  131. const ValueTree& getNode() const noexcept { return node; }
  132. ValueTree& getNode() noexcept { return node; }
  133. Project& getProject() const noexcept { return *project; }
  134. bool operator== (const Item& other) const { return node == other.node && project == other.project; }
  135. bool operator!= (const Item& other) const { return ! operator== (other); }
  136. //==============================================================================
  137. bool isFile() const;
  138. bool isGroup() const;
  139. bool isMainGroup() const;
  140. bool isImageFile() const;
  141. String getID() const;
  142. Item findItemWithID (const String& targetId) const; // (recursive search)
  143. String getImageFileID() const;
  144. void setID (const String& newID);
  145. //==============================================================================
  146. Value getName() const;
  147. File getFile() const;
  148. String getFilePath() const;
  149. void setFile (const File& file);
  150. void setFile (const RelativePath& file);
  151. File determineGroupFolder() const;
  152. bool renameFile (const File& newFile);
  153. bool shouldBeAddedToTargetProject() const;
  154. bool shouldBeCompiled() const;
  155. Value getShouldCompileValue() const;
  156. bool shouldBeAddedToBinaryResources() const;
  157. Value getShouldAddToResourceValue() const;
  158. Value getShouldInhibitWarningsValue() const;
  159. //==============================================================================
  160. bool canContain (const Item& child) const;
  161. int getNumChildren() const { return node.getNumChildren(); }
  162. Item getChild (int index) const { return Item (getProject(), node.getChild (index)); }
  163. Item addNewSubGroup (const String& name, int insertIndex);
  164. void addChild (const Item& newChild, int insertIndex);
  165. bool addFile (const File& file, int insertIndex);
  166. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  167. void removeItemFromProject();
  168. void sortAlphabetically();
  169. Item findItemForFile (const File& file) const;
  170. Item getParent() const;
  171. const Drawable* getIcon() const;
  172. private:
  173. //==============================================================================
  174. Project* project;
  175. ValueTree node;
  176. UndoManager* getUndoManager() const { return getProject().getUndoManagerFor (node); }
  177. };
  178. Item getMainGroup();
  179. void findAllImageItems (OwnedArray<Item>& items);
  180. //==============================================================================
  181. class BuildConfiguration
  182. {
  183. public:
  184. BuildConfiguration (const BuildConfiguration&);
  185. const BuildConfiguration& operator= (const BuildConfiguration&);
  186. ~BuildConfiguration();
  187. //==============================================================================
  188. Project& getProject() const { return *project; }
  189. void createPropertyEditors (Array <PropertyComponent*>& properties);
  190. //==============================================================================
  191. Value getName() const { return getValue (Ids::name); }
  192. Value isDebug() const { return getValue (Ids::isDebug); }
  193. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  194. // the path relative to the build folder in which the binary should go
  195. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  196. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  197. String getGCCOptimisationFlag() const;
  198. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  199. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  200. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  201. StringArray getHeaderSearchPaths() const;
  202. static const char* const osxVersionDefault;
  203. static const char* const osxVersion10_4;
  204. static const char* const osxVersion10_5;
  205. static const char* const osxVersion10_6;
  206. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  207. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  208. static const char* const osxArch_Default;
  209. static const char* const osxArch_Native;
  210. static const char* const osxArch_32BitUniversal;
  211. static const char* const osxArch_64BitUniversal;
  212. static const char* const osxArch_64Bit;
  213. Value getMacArchitecture() const { return getValue (Ids::osxArchitecture); }
  214. //==============================================================================
  215. private:
  216. friend class Project;
  217. Project* project;
  218. ValueTree config;
  219. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  220. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  221. BuildConfiguration (Project* project, const ValueTree& configNode);
  222. };
  223. int getNumConfigurations() const;
  224. BuildConfiguration getConfiguration (int index);
  225. void addNewConfiguration (BuildConfiguration* configToCopy);
  226. void deleteConfiguration (int index);
  227. bool hasConfigurationNamed (const String& name) const;
  228. String getUniqueConfigName (String name) const;
  229. //==============================================================================
  230. ValueTree getExporters();
  231. int getNumExporters();
  232. ProjectExporter* createExporter (int index);
  233. void addNewExporter (int exporterIndex);
  234. void deleteExporter (int index);
  235. void createDefaultExporters();
  236. //==============================================================================
  237. struct ConfigFlag
  238. {
  239. String symbol, description;
  240. Value value; // 1 = true, 2 = false, anything else = use default
  241. };
  242. void getAllConfigFlags (OwnedArray <ConfigFlag>& flags);
  243. static const char* const configFlagDefault;
  244. static const char* const configFlagEnabled;
  245. static const char* const configFlagDisabled;
  246. Value getConfigFlag (const String& name);
  247. bool isConfigFlagEnabled (const String& name) const;
  248. //==============================================================================
  249. String getFileTemplate (const String& templateName);
  250. //==============================================================================
  251. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  252. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  253. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  254. void valueTreeChildOrderChanged (ValueTree& parentTree);
  255. void valueTreeParentChanged (ValueTree& tree);
  256. //==============================================================================
  257. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  258. //==============================================================================
  259. static const char* projectFileExtension;
  260. static void resaveJucerFile (const File& file);
  261. private:
  262. friend class Item;
  263. ValueTree projectRoot;
  264. static File lastDocumentOpened;
  265. DrawableImage mainProjectIcon;
  266. void updateProjectSettings();
  267. void setMissingDefaultValues();
  268. ValueTree getConfigurations() const;
  269. void createDefaultConfigs();
  270. ValueTree getConfigNode();
  271. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  272. };
  273. #endif // __JUCER_PROJECT_JUCEHEADER__