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.

307 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. //==============================================================================
  130. const ValueTree& getNode() const throw() { return node; }
  131. ValueTree& getNode() throw() { return node; }
  132. Project& getProject() const throw() { 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. const String getID() const;
  140. void createUIDIfMissing();
  141. //==============================================================================
  142. Value getName() const;
  143. const File getFile() const;
  144. void setFile (const File& file);
  145. const File determineGroupFolder() const;
  146. bool shouldBeAddedToTargetProject() const;
  147. bool shouldBeCompiled() const;
  148. Value getShouldCompileValue() const;
  149. bool shouldBeAddedToBinaryResources() const;
  150. Value getShouldAddToResourceValue() const;
  151. //==============================================================================
  152. bool canContain (const Item& child) const;
  153. int getNumChildren() const { return node.getNumChildren(); }
  154. const Item getChild (int index) const { return Item (project, node.getChild (index)); }
  155. void addChild (const Item& newChild, int insertIndex);
  156. bool addFile (const File& file, int insertIndex);
  157. void removeItemFromProject();
  158. void sortAlphabetically();
  159. Item getParent() const;
  160. Image* getIcon() const;
  161. private:
  162. //==============================================================================
  163. Project& project;
  164. ValueTree node;
  165. UndoManager* getUndoManager() const { return project.getUndoManagerFor (node); }
  166. Item& operator= (const Item&);
  167. };
  168. Item getMainGroup();
  169. Item createNewGroup();
  170. Item createNewItem (const File& file);
  171. //==============================================================================
  172. class BuildConfiguration
  173. {
  174. public:
  175. BuildConfiguration (const BuildConfiguration&);
  176. const BuildConfiguration& operator= (const BuildConfiguration&);
  177. ~BuildConfiguration();
  178. //==============================================================================
  179. Project& getProject() const { return *project; }
  180. void createPropertyEditors (Array <PropertyComponent*>& properties);
  181. //==============================================================================
  182. Value getName() const { return config.getPropertyAsValue ("name", getUndoManager()); }
  183. Value isDebug() const { return config.getPropertyAsValue ("isDebug", getUndoManager()); }
  184. Value getTargetBinaryName() const { return config.getPropertyAsValue ("targetName", getUndoManager()); }
  185. // the path relative to the build folder in which the binary should go
  186. Value getTargetBinaryRelativePath() const { return config.getPropertyAsValue ("binaryPath", getUndoManager()); }
  187. Value getOptimisationLevel() const { return config.getPropertyAsValue ("optimisation", getUndoManager()); }
  188. const String getGCCOptimisationFlag() const;
  189. Value getPreprocessorDefs() const { return config.getPropertyAsValue ("defines", getUndoManager()); }
  190. const StringArray parsePreprocessorDefs() const;
  191. Value getHeaderSearchPath() const { return config.getPropertyAsValue ("headerPath", getUndoManager()); }
  192. const StringArray getHeaderSearchPaths() const;
  193. Value getMacSDKVersion() const;
  194. Value getMacCompatibilityVersion() const;
  195. //==============================================================================
  196. private:
  197. friend class Project;
  198. Project* project;
  199. ValueTree config;
  200. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  201. BuildConfiguration (Project* project, const ValueTree& configNode);
  202. };
  203. int getNumConfigurations() const;
  204. BuildConfiguration getConfiguration (int index);
  205. void addNewConfiguration (BuildConfiguration* configToCopy);
  206. void deleteConfiguration (int index);
  207. bool hasConfigurationNamed (const String& name) const;
  208. const String getUniqueConfigName (String name) const;
  209. //==============================================================================
  210. ValueTree getExporters();
  211. int getNumExporters();
  212. ProjectExporter* createExporter (int index);
  213. void addNewExporter (int exporterIndex);
  214. void deleteExporter (int index);
  215. void createDefaultExporters();
  216. //==============================================================================
  217. struct JuceConfigFlag
  218. {
  219. String symbol, description;
  220. Value value; // 1 = true, 2 = false, anything else = use default
  221. };
  222. void getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags);
  223. Value getJuceConfigFlag (const String& name);
  224. //==============================================================================
  225. const String getFileTemplate (const String& templateName);
  226. //==============================================================================
  227. void valueTreePropertyChanged (ValueTree& tree, const var::identifier& property);
  228. void valueTreeChildrenChanged (ValueTree& tree);
  229. void valueTreeParentChanged (ValueTree& tree);
  230. //==============================================================================
  231. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  232. //==============================================================================
  233. static const char* projectFileExtension;
  234. private:
  235. ValueTree projectRoot;
  236. static File lastDocumentOpened;
  237. const File getLocalJuceFolder();
  238. void updateProjectSettings();
  239. void setMissingDefaultValues();
  240. ValueTree getConfigurations() const;
  241. void createDefaultConfigs();
  242. ValueTree getJuceConfigNode();
  243. Project (const Project&);
  244. const Project& operator= (const Project&);
  245. };
  246. #endif // __JUCER_PROJECT_JUCEHEADER__