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.

315 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 [Ids::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 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 shouldBuildVST() const { return getProjectValue ("buildVST"); }
  82. Value shouldBuildRTAS() const { return getProjectValue ("buildRTAS"); }
  83. Value shouldBuildAU() const { return getProjectValue ("buildAU"); }
  84. bool shouldAddVSTFolderToPath() { return (isAudioPlugin() && (bool) shouldBuildVST().getValue()) || getJuceConfigFlag ("JUCE_PLUGINHOST_VST").toString() == configFlagEnabled; }
  85. Value getPluginName() const { return getProjectValue ("pluginName"); }
  86. Value getPluginDesc() const { return getProjectValue ("pluginDesc"); }
  87. Value getPluginManufacturer() const { return getProjectValue ("pluginManufacturer"); }
  88. Value getPluginManufacturerCode() const { return getProjectValue ("pluginManufacturerCode"); }
  89. Value getPluginCode() const { return getProjectValue ("pluginCode"); }
  90. Value getPluginChannelConfigs() const { return getProjectValue ("pluginChannelConfigs"); }
  91. Value getPluginIsSynth() const { return getProjectValue ("pluginIsSynth"); }
  92. Value getPluginWantsMidiInput() const { return getProjectValue ("pluginWantsMidiIn"); }
  93. Value getPluginProducesMidiOut() const { return getProjectValue ("pluginProducesMidiOut"); }
  94. Value getPluginSilenceInProducesSilenceOut() const { return getProjectValue ("pluginSilenceInIsSilenceOut"); }
  95. Value getPluginTailLengthSeconds() const { return getProjectValue ("pluginTailLength"); }
  96. Value getPluginEditorNeedsKeyFocus() const { return getProjectValue ("pluginEditorRequiresKeys"); }
  97. Value getPluginAUExportPrefix() const { return getProjectValue ("pluginAUExportPrefix"); }
  98. Value getPluginAUCocoaViewClassName() const { return getProjectValue ("pluginAUViewClass"); }
  99. Value getPluginRTASCategory() const { return getProjectValue ("pluginRTASCategory"); }
  100. //==============================================================================
  101. const File getAppIncludeFile() const { return getWrapperFolder().getChildFile (getJuceSourceHFilename()); }
  102. const File getWrapperFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  103. const File getPluginCharacteristicsFile() const { return getWrapperFolder().getChildFile (getPluginCharacteristicsFilename()); }
  104. //==============================================================================
  105. const String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  106. const String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  107. const String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  108. const String getAppConfigFilename() const { return "AppConfig.h"; }
  109. const String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  110. int getNumSeparateAmalgamatedFiles() const { return 4; }
  111. const String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  112. const String getJuceCodeGroupName() const { return "Juce Library Code"; }
  113. const String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  114. //==============================================================================
  115. class Item
  116. {
  117. public:
  118. //==============================================================================
  119. Item (Project& project, const ValueTree& itemNode);
  120. Item (const Item& other);
  121. ~Item();
  122. void initialiseNodeValues();
  123. //==============================================================================
  124. bool isValid() const { return node.isValid(); }
  125. const ValueTree& getNode() const throw() { return node; }
  126. ValueTree& getNode() throw() { return node; }
  127. Project& getProject() const throw() { 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. const String getID() const;
  135. Item findItemWithID (const String& targetId) const; // (recursive search)
  136. //==============================================================================
  137. Value getName() const;
  138. const File getFile() const;
  139. void setFile (const File& file);
  140. const File determineGroupFolder() const;
  141. bool renameFile (const File& newFile);
  142. bool shouldBeAddedToTargetProject() const;
  143. bool shouldBeCompiled() const;
  144. Value getShouldCompileValue() const;
  145. bool shouldBeAddedToBinaryResources() const;
  146. Value getShouldAddToResourceValue() const;
  147. //==============================================================================
  148. bool canContain (const Item& child) const;
  149. int getNumChildren() const { return node.getNumChildren(); }
  150. Item getChild (int index) const { return Item (project, node.getChild (index)); }
  151. void addChild (const Item& newChild, int insertIndex);
  152. bool addFile (const File& file, int insertIndex);
  153. void removeItemFromProject();
  154. void sortAlphabetically();
  155. Item findItemForFile (const File& file) const;
  156. Item getParent() const;
  157. Image* getIcon() const;
  158. private:
  159. //==============================================================================
  160. Project& project;
  161. ValueTree node;
  162. UndoManager* getUndoManager() const { return project.getUndoManagerFor (node); }
  163. Item& operator= (const Item&);
  164. };
  165. Item getMainGroup();
  166. Item createNewGroup();
  167. Item createNewItem (const File& file);
  168. //==============================================================================
  169. class BuildConfiguration
  170. {
  171. public:
  172. BuildConfiguration (const BuildConfiguration&);
  173. const BuildConfiguration& operator= (const BuildConfiguration&);
  174. ~BuildConfiguration();
  175. //==============================================================================
  176. Project& getProject() const { return *project; }
  177. void createPropertyEditors (Array <PropertyComponent*>& properties);
  178. //==============================================================================
  179. Value getName() const { return getValue (Ids::name); }
  180. Value isDebug() const { return getValue (Ids::isDebug); }
  181. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  182. // the path relative to the build folder in which the binary should go
  183. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  184. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  185. const String getGCCOptimisationFlag() const;
  186. Value getPreprocessorDefs() const { return getValue (Ids::defines); }
  187. const StringArray parsePreprocessorDefs() const;
  188. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  189. const StringArray getHeaderSearchPaths() const;
  190. static const char* const osxVersionDefault;
  191. static const char* const osxVersion10_4;
  192. static const char* const osxVersion10_5;
  193. static const char* const osxVersion10_6;
  194. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  195. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  196. //==============================================================================
  197. private:
  198. friend class Project;
  199. Project* project;
  200. ValueTree config;
  201. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  202. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  203. BuildConfiguration (Project* project, const ValueTree& configNode);
  204. };
  205. int getNumConfigurations() const;
  206. BuildConfiguration getConfiguration (int index);
  207. void addNewConfiguration (BuildConfiguration* configToCopy);
  208. void deleteConfiguration (int index);
  209. bool hasConfigurationNamed (const String& name) const;
  210. const String getUniqueConfigName (String name) const;
  211. //==============================================================================
  212. ValueTree getExporters();
  213. int getNumExporters();
  214. ProjectExporter* createExporter (int index);
  215. void addNewExporter (int exporterIndex);
  216. void deleteExporter (int index);
  217. void createDefaultExporters();
  218. //==============================================================================
  219. struct JuceConfigFlag
  220. {
  221. String symbol, description;
  222. Value value; // 1 = true, 2 = false, anything else = use default
  223. };
  224. void getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags);
  225. static const char* const configFlagDefault;
  226. static const char* const configFlagEnabled;
  227. static const char* const configFlagDisabled;
  228. Value getJuceConfigFlag (const String& name);
  229. //==============================================================================
  230. const String getFileTemplate (const String& templateName);
  231. //==============================================================================
  232. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  233. void valueTreeChildrenChanged (ValueTree& tree);
  234. void valueTreeParentChanged (ValueTree& tree);
  235. //==============================================================================
  236. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  237. //==============================================================================
  238. static const char* projectFileExtension;
  239. private:
  240. ValueTree projectRoot;
  241. static File lastDocumentOpened;
  242. const File getLocalJuceFolder();
  243. void updateProjectSettings();
  244. void setMissingDefaultValues();
  245. ValueTree getConfigurations() const;
  246. void createDefaultConfigs();
  247. ValueTree getJuceConfigNode();
  248. Project (const Project&);
  249. const Project& operator= (const Project&);
  250. };
  251. #endif // __JUCER_PROJECT_JUCEHEADER__