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.

311 lines
16KB

  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 ["id"]; }
  43. //==============================================================================
  44. bool shouldBeAddedToBinaryResourcesByDefault (const File& file);
  45. const File resolveFilename (const 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 type info
  52. enum ProjectType
  53. {
  54. application = 1, // must all be sequntial, starting from 1, so that combo boxes can update correctly
  55. commandLineApp = 2,
  56. audioPlugin = 3,
  57. library = 4,
  58. browserPlugin = 5
  59. };
  60. const StringArray getProjectTypes() const;
  61. Value getProjectType() const;
  62. bool isLibrary() const { return (int) getProjectType().getValue() == (int) library; }
  63. bool isGUIApplication() const { return (int) getProjectType().getValue() == (int) application; }
  64. bool isCommandLineApp() const { return (int) getProjectType().getValue() == (int) commandLineApp; }
  65. bool isAudioPlugin() const { return (int) getProjectType().getValue() == (int) audioPlugin; }
  66. bool isBrowserPlugin() const { return (int) getProjectType().getValue() == (int) browserPlugin; }
  67. Value getVersion() const { return getProjectValue ("version"); }
  68. Value getBundleIdentifier() const { return getProjectValue ("bundleIdentifier"); }
  69. void setBundleIdentifierToDefault() { getBundleIdentifier() = "com.yourcompany." + makeValidCppIdentifier (getProjectName().toString(), false, true, false); }
  70. //==============================================================================
  71. enum JuceLinkage
  72. {
  73. notLinkedToJuce = 1, // must all be sequntial, starting from 1, so that combo boxes can update correctly
  74. useLinkedJuce = 2,
  75. useAmalgamatedJuce = 3,
  76. useAmalgamatedJuceViaSingleTemplate = 4,
  77. useAmalgamatedJuceViaMultipleTemplates = 5,
  78. };
  79. const StringArray getJuceLinkageModes() const;
  80. Value getJuceLinkageModeValue() const;
  81. JuceLinkage getJuceLinkageMode() const { return (JuceLinkage) (int) getJuceLinkageModeValue().getValue(); }
  82. bool isUsingWrapperFiles() const { return isUsingFullyAmalgamatedFile() || isUsingSingleTemplateFile() || isUsingMultipleTemplateFiles(); }
  83. bool isUsingFullyAmalgamatedFile() const { return getJuceLinkageMode() == useAmalgamatedJuce; }
  84. bool isUsingSingleTemplateFile() const { return getJuceLinkageMode() == useAmalgamatedJuceViaSingleTemplate; }
  85. bool isUsingMultipleTemplateFiles() const { return getJuceLinkageMode() == useAmalgamatedJuceViaMultipleTemplates; }
  86. //==============================================================================
  87. Value getProjectValue (const var::identifier& name) const { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  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()) || (int) getJuceConfigFlag ("JUCE_PLUGINHOST_VST").getValue() == 1; }
  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();
  129. void initialiseNodeValues();
  130. //==============================================================================
  131. bool isValid() const { return node.isValid(); }
  132. const ValueTree& getNode() const throw() { return node; }
  133. ValueTree& getNode() throw() { return node; }
  134. Project& getProject() const throw() { return project; }
  135. bool operator== (const Item& other) const { return node == other.node && &project == &other.project; }
  136. bool operator!= (const Item& other) const { return ! operator== (other); }
  137. //==============================================================================
  138. bool isFile() const;
  139. bool isGroup() const;
  140. bool isMainGroup() const;
  141. const String getID() const;
  142. //==============================================================================
  143. Value getName() const;
  144. const File getFile() const;
  145. void setFile (const File& file);
  146. const File determineGroupFolder() const;
  147. bool renameFile (const File& newFile);
  148. bool shouldBeAddedToTargetProject() const;
  149. bool shouldBeCompiled() const;
  150. Value getShouldCompileValue() const;
  151. bool shouldBeAddedToBinaryResources() const;
  152. Value getShouldAddToResourceValue() const;
  153. //==============================================================================
  154. bool canContain (const Item& child) const;
  155. int getNumChildren() const { return node.getNumChildren(); }
  156. Item getChild (int index) const { return Item (project, node.getChild (index)); }
  157. void addChild (const Item& newChild, int insertIndex);
  158. bool addFile (const File& file, int insertIndex);
  159. void removeItemFromProject();
  160. void sortAlphabetically();
  161. Item findItemForFile (const File& file) const;
  162. Item getParent() const;
  163. Image* getIcon() const;
  164. private:
  165. //==============================================================================
  166. Project& project;
  167. ValueTree node;
  168. UndoManager* getUndoManager() const { return project.getUndoManagerFor (node); }
  169. Item& operator= (const Item&);
  170. };
  171. Item getMainGroup();
  172. Item createNewGroup();
  173. Item createNewItem (const File& file);
  174. //==============================================================================
  175. class BuildConfiguration
  176. {
  177. public:
  178. BuildConfiguration (const BuildConfiguration&);
  179. const BuildConfiguration& operator= (const BuildConfiguration&);
  180. ~BuildConfiguration();
  181. //==============================================================================
  182. Project& getProject() const { return *project; }
  183. void createPropertyEditors (Array <PropertyComponent*>& properties);
  184. //==============================================================================
  185. Value getName() const { return config.getPropertyAsValue ("name", getUndoManager()); }
  186. Value isDebug() const { return config.getPropertyAsValue ("isDebug", getUndoManager()); }
  187. Value getTargetBinaryName() const { return config.getPropertyAsValue ("targetName", getUndoManager()); }
  188. // the path relative to the build folder in which the binary should go
  189. Value getTargetBinaryRelativePath() const { return config.getPropertyAsValue ("binaryPath", getUndoManager()); }
  190. Value getOptimisationLevel() const { return config.getPropertyAsValue ("optimisation", getUndoManager()); }
  191. const String getGCCOptimisationFlag() const;
  192. Value getPreprocessorDefs() const { return config.getPropertyAsValue ("defines", getUndoManager()); }
  193. const StringArray parsePreprocessorDefs() const;
  194. Value getHeaderSearchPath() const { return config.getPropertyAsValue ("headerPath", getUndoManager()); }
  195. const StringArray getHeaderSearchPaths() const;
  196. Value getMacSDKVersion() const;
  197. Value getMacCompatibilityVersion() const;
  198. //==============================================================================
  199. private:
  200. friend class Project;
  201. Project* project;
  202. ValueTree config;
  203. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  204. BuildConfiguration (Project* project, const ValueTree& configNode);
  205. };
  206. int getNumConfigurations() const;
  207. BuildConfiguration getConfiguration (int index);
  208. void addNewConfiguration (BuildConfiguration* configToCopy);
  209. void deleteConfiguration (int index);
  210. bool hasConfigurationNamed (const String& name) const;
  211. const String getUniqueConfigName (String name) const;
  212. //==============================================================================
  213. ValueTree getExporters();
  214. int getNumExporters();
  215. ProjectExporter* createExporter (int index);
  216. void addNewExporter (int exporterIndex);
  217. void deleteExporter (int index);
  218. void createDefaultExporters();
  219. //==============================================================================
  220. struct JuceConfigFlag
  221. {
  222. String symbol, description;
  223. Value value; // 1 = true, 2 = false, anything else = use default
  224. };
  225. void getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags);
  226. Value getJuceConfigFlag (const String& name);
  227. //==============================================================================
  228. const String getFileTemplate (const String& templateName);
  229. //==============================================================================
  230. void valueTreePropertyChanged (ValueTree& tree, const var::identifier& property);
  231. void valueTreeChildrenChanged (ValueTree& tree);
  232. void valueTreeParentChanged (ValueTree& tree);
  233. //==============================================================================
  234. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  235. //==============================================================================
  236. static const char* projectFileExtension;
  237. private:
  238. ValueTree projectRoot;
  239. static File lastDocumentOpened;
  240. const File getLocalJuceFolder();
  241. void updateProjectSettings();
  242. void setMissingDefaultValues();
  243. ValueTree getConfigurations() const;
  244. void createDefaultConfigs();
  245. ValueTree getJuceConfigNode();
  246. Project (const Project&);
  247. const Project& operator= (const Project&);
  248. };
  249. #endif // __JUCER_PROJECT_JUCEHEADER__