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.

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