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.

340 lines
18KB

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