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.

338 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. Value getBundleIdentifier() const { return getProjectValue ("bundleIdentifier"); }
  61. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectName().toString(), false, true, false); }
  62. //==============================================================================
  63. // linkage modes..
  64. static const char* const notLinkedToJuce;
  65. static const char* const useLinkedJuce;
  66. static const char* const useAmalgamatedJuce;
  67. static const char* const useAmalgamatedJuceViaSingleTemplate;
  68. static const char* const useAmalgamatedJuceViaMultipleTemplates;
  69. Value getJuceLinkageModeValue() const { return getProjectValue ("juceLinkage"); }
  70. String getJuceLinkageMode() const { return getJuceLinkageModeValue().toString(); }
  71. bool isUsingWrapperFiles() const { return isUsingFullyAmalgamatedFile() || isUsingSingleTemplateFile() || isUsingMultipleTemplateFiles(); }
  72. bool isUsingFullyAmalgamatedFile() const { return getJuceLinkageMode() == useAmalgamatedJuce; }
  73. bool isUsingSingleTemplateFile() const { return getJuceLinkageMode() == useAmalgamatedJuceViaSingleTemplate; }
  74. bool isUsingMultipleTemplateFiles() const { return getJuceLinkageMode() == useAmalgamatedJuceViaMultipleTemplates; }
  75. //==============================================================================
  76. Value getProjectValue (const Identifier& name) const { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  77. Value getProjectPreprocessorDefs() const { return getProjectValue (Ids::defines); }
  78. StringPairArray getPreprocessorDefs() const;
  79. Value getBigIconImageItemID() const { return getProjectValue ("bigIcon"); }
  80. Value getSmallIconImageItemID() const { return getProjectValue ("smallIcon"); }
  81. Image getBigIcon();
  82. Image getSmallIcon();
  83. Image getBestIconForSize (int size, bool returnNullIfNothingBigEnough);
  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 getWrapperFolder().getChildFile (getJuceSourceHFilename()); }
  104. File getWrapperFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  105. File getPluginCharacteristicsFile() const { return getWrapperFolder().getChildFile (getPluginCharacteristicsFilename()); }
  106. //==============================================================================
  107. String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  108. String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  109. String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  110. String getAppConfigFilename() const { return "AppConfig.h"; }
  111. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  112. int getNumSeparateAmalgamatedFiles() const { return 4; }
  113. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  114. String getJuceCodeGroupName() const { return "Juce Library Code"; }
  115. String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  116. //==============================================================================
  117. class Item
  118. {
  119. public:
  120. //==============================================================================
  121. Item (Project& project, const ValueTree& itemNode);
  122. Item (const Item& other);
  123. Item& operator= (const Item& other);
  124. ~Item();
  125. static Item createGroup (Project& project, const String& name);
  126. void initialiseNodeValues();
  127. //==============================================================================
  128. bool isValid() const { return node.isValid(); }
  129. const ValueTree& getNode() const noexcept { return node; }
  130. ValueTree& getNode() noexcept { return node; }
  131. Project& getProject() const noexcept { return *project; }
  132. bool operator== (const Item& other) const { return node == other.node && project == other.project; }
  133. bool operator!= (const Item& other) const { return ! operator== (other); }
  134. //==============================================================================
  135. bool isFile() const;
  136. bool isGroup() const;
  137. bool isMainGroup() const;
  138. bool isImageFile() const;
  139. String getID() const;
  140. Item findItemWithID (const String& targetId) const; // (recursive search)
  141. String getImageFileID() const;
  142. //==============================================================================
  143. Value getName() const;
  144. File getFile() const;
  145. void setFile (const File& file);
  146. void setFile (const RelativePath& file);
  147. File determineGroupFolder() const;
  148. bool renameFile (const File& newFile);
  149. bool shouldBeAddedToTargetProject() const;
  150. bool shouldBeCompiled() const;
  151. Value getShouldCompileValue() const;
  152. bool shouldBeAddedToBinaryResources() const;
  153. Value getShouldAddToResourceValue() const;
  154. //==============================================================================
  155. bool canContain (const Item& child) const;
  156. int getNumChildren() const { return node.getNumChildren(); }
  157. Item getChild (int index) const { return Item (getProject(), node.getChild (index)); }
  158. Item addNewSubGroup (const String& name, int insertIndex);
  159. void addChild (const Item& newChild, int insertIndex);
  160. bool addFile (const File& file, int insertIndex);
  161. bool addRelativeFile (const RelativePath& file, int insertIndex);
  162. void removeItemFromProject();
  163. void sortAlphabetically();
  164. Item findItemForFile (const File& file) const;
  165. Item getParent() const;
  166. const Drawable* getIcon() const;
  167. private:
  168. //==============================================================================
  169. Project* project;
  170. ValueTree node;
  171. UndoManager* getUndoManager() const { return getProject().getUndoManagerFor (node); }
  172. };
  173. Item getMainGroup();
  174. void findAllImageItems (OwnedArray<Item>& items);
  175. //==============================================================================
  176. class BuildConfiguration
  177. {
  178. public:
  179. BuildConfiguration (const BuildConfiguration&);
  180. const BuildConfiguration& operator= (const BuildConfiguration&);
  181. ~BuildConfiguration();
  182. //==============================================================================
  183. Project& getProject() const { return *project; }
  184. void createPropertyEditors (Array <PropertyComponent*>& properties);
  185. //==============================================================================
  186. Value getName() const { return getValue (Ids::name); }
  187. Value isDebug() const { return getValue (Ids::isDebug); }
  188. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  189. // the path relative to the build folder in which the binary should go
  190. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  191. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  192. String getGCCOptimisationFlag() const;
  193. Value getBuildConfigPreprocessorDefs() const { return getValue (Ids::defines); }
  194. StringPairArray getAllPreprocessorDefs() const; // includes inherited definitions
  195. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  196. StringArray getHeaderSearchPaths() const;
  197. static const char* const osxVersionDefault;
  198. static const char* const osxVersion10_4;
  199. static const char* const osxVersion10_5;
  200. static const char* const osxVersion10_6;
  201. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  202. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  203. static const char* const osxArch_Default;
  204. static const char* const osxArch_Native;
  205. static const char* const osxArch_32BitUniversal;
  206. static const char* const osxArch_64BitUniversal;
  207. static const char* const osxArch_64Bit;
  208. Value getMacArchitecture() const { return getValue (Ids::osxArchitecture); }
  209. //==============================================================================
  210. private:
  211. friend class Project;
  212. Project* project;
  213. ValueTree config;
  214. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  215. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  216. BuildConfiguration (Project* project, const ValueTree& configNode);
  217. };
  218. int getNumConfigurations() const;
  219. BuildConfiguration getConfiguration (int index);
  220. void addNewConfiguration (BuildConfiguration* configToCopy);
  221. void deleteConfiguration (int index);
  222. bool hasConfigurationNamed (const String& name) const;
  223. String getUniqueConfigName (String name) const;
  224. //==============================================================================
  225. ValueTree getExporters();
  226. int getNumExporters();
  227. ProjectExporter* createExporter (int index);
  228. void addNewExporter (int exporterIndex);
  229. void deleteExporter (int index);
  230. void createDefaultExporters();
  231. //==============================================================================
  232. struct JuceConfigFlag
  233. {
  234. String symbol, description;
  235. Value value; // 1 = true, 2 = false, anything else = use default
  236. };
  237. void getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags);
  238. static const char* const configFlagDefault;
  239. static const char* const configFlagEnabled;
  240. static const char* const configFlagDisabled;
  241. Value getJuceConfigFlag (const String& name);
  242. bool isJuceConfigFlagEnabled (const String& name) const;
  243. //==============================================================================
  244. String getFileTemplate (const String& templateName);
  245. //==============================================================================
  246. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  247. void valueTreeChildAdded (ValueTree& parentTree, ValueTree& childWhichHasBeenAdded);
  248. void valueTreeChildRemoved (ValueTree& parentTree, ValueTree& childWhichHasBeenRemoved);
  249. void valueTreeChildOrderChanged (ValueTree& parentTree);
  250. void valueTreeParentChanged (ValueTree& tree);
  251. //==============================================================================
  252. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  253. //==============================================================================
  254. static const char* projectFileExtension;
  255. static void resaveJucerFile (const File& file);
  256. private:
  257. friend class Item;
  258. ValueTree projectRoot;
  259. static File lastDocumentOpened;
  260. DrawableImage mainProjectIcon;
  261. File getLocalJuceFolder();
  262. void updateProjectSettings();
  263. void setMissingDefaultValues();
  264. ValueTree getConfigurations() const;
  265. void createDefaultConfigs();
  266. ValueTree getJuceConfigNode();
  267. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project);
  268. };
  269. #endif // __JUCER_PROJECT_JUCEHEADER__