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.

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