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.

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