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.

327 lines
17KB

  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 getBigIconImageItemID() const { return getProjectValue ("bigIcon"); }
  82. Value getSmallIconImageItemID() const { return getProjectValue ("smallIcon"); }
  83. const Image getBigIcon();
  84. const Image getSmallIcon();
  85. Value getObjectiveCClassSuffix() const { return getProjectValue ("objCSuffix"); }
  86. Value shouldBuildVST() const { return getProjectValue ("buildVST"); }
  87. Value shouldBuildRTAS() const { return getProjectValue ("buildRTAS"); }
  88. Value shouldBuildAU() const { return getProjectValue ("buildAU"); }
  89. bool shouldAddVSTFolderToPath() { return (isAudioPlugin() && (bool) shouldBuildVST().getValue()) || getJuceConfigFlag ("JUCE_PLUGINHOST_VST").toString() == configFlagEnabled; }
  90. Value getPluginName() const { return getProjectValue ("pluginName"); }
  91. Value getPluginDesc() const { return getProjectValue ("pluginDesc"); }
  92. Value getPluginManufacturer() const { return getProjectValue ("pluginManufacturer"); }
  93. Value getPluginManufacturerCode() const { return getProjectValue ("pluginManufacturerCode"); }
  94. Value getPluginCode() const { return getProjectValue ("pluginCode"); }
  95. Value getPluginChannelConfigs() const { return getProjectValue ("pluginChannelConfigs"); }
  96. Value getPluginIsSynth() const { return getProjectValue ("pluginIsSynth"); }
  97. Value getPluginWantsMidiInput() const { return getProjectValue ("pluginWantsMidiIn"); }
  98. Value getPluginProducesMidiOut() const { return getProjectValue ("pluginProducesMidiOut"); }
  99. Value getPluginSilenceInProducesSilenceOut() const { return getProjectValue ("pluginSilenceInIsSilenceOut"); }
  100. Value getPluginTailLengthSeconds() const { return getProjectValue ("pluginTailLength"); }
  101. Value getPluginEditorNeedsKeyFocus() const { return getProjectValue ("pluginEditorRequiresKeys"); }
  102. Value getPluginAUExportPrefix() const { return getProjectValue ("pluginAUExportPrefix"); }
  103. Value getPluginAUCocoaViewClassName() const { return getProjectValue ("pluginAUViewClass"); }
  104. Value getPluginRTASCategory() const { return getProjectValue ("pluginRTASCategory"); }
  105. //==============================================================================
  106. const File getAppIncludeFile() const { return getWrapperFolder().getChildFile (getJuceSourceHFilename()); }
  107. const File getWrapperFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  108. const File getPluginCharacteristicsFile() const { return getWrapperFolder().getChildFile (getPluginCharacteristicsFilename()); }
  109. //==============================================================================
  110. const String getAmalgamatedHeaderFileName() const { return "juce_amalgamated.h"; }
  111. const String getAmalgamatedMMFileName() const { return "juce_amalgamated.mm"; }
  112. const String getAmalgamatedCppFileName() const { return "juce_amalgamated.cpp"; }
  113. const String getAppConfigFilename() const { return "AppConfig.h"; }
  114. const String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  115. int getNumSeparateAmalgamatedFiles() const { return 4; }
  116. const String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  117. const String getJuceCodeGroupName() const { return "Juce Library Code"; }
  118. const String getPluginCharacteristicsFilename() const { return "JucePluginCharacteristics.h"; }
  119. //==============================================================================
  120. class Item
  121. {
  122. public:
  123. //==============================================================================
  124. Item (Project& project, const ValueTree& itemNode);
  125. Item (const Item& other);
  126. ~Item();
  127. void initialiseNodeValues();
  128. //==============================================================================
  129. bool isValid() const { return node.isValid(); }
  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. Item findItemWithID (const String& targetId) const; // (recursive search)
  141. const String getImageFileID() 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. const 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. void findAllImageItems (OwnedArray<Item>& items);
  175. //==============================================================================
  176. class BuildConfiguration
  177. {
  178. public:
  179. BuildConfiguration (const BuildConfiguration&);
  180. const BuildConfiguration& operator= (const BuildConfiguration&);
  181. ~BuildConfiguration();
  182. //==============================================================================
  183. Project& getProject() const { return *project; }
  184. void createPropertyEditors (Array <PropertyComponent*>& properties);
  185. //==============================================================================
  186. Value getName() const { return getValue (Ids::name); }
  187. Value isDebug() const { return getValue (Ids::isDebug); }
  188. Value getTargetBinaryName() const { return getValue (Ids::targetName); }
  189. // the path relative to the build folder in which the binary should go
  190. Value getTargetBinaryRelativePath() const { return getValue (Ids::binaryPath); }
  191. Value getOptimisationLevel() const { return getValue (Ids::optimisation); }
  192. const String getGCCOptimisationFlag() const;
  193. Value getPreprocessorDefs() const { return getValue (Ids::defines); }
  194. const StringArray parsePreprocessorDefs() const;
  195. Value getHeaderSearchPath() const { return getValue (Ids::headerPath); }
  196. const StringArray getHeaderSearchPaths() const;
  197. static const char* const osxVersionDefault;
  198. static const char* const osxVersion10_4;
  199. static const char* const osxVersion10_5;
  200. static const char* const osxVersion10_6;
  201. Value getMacSDKVersion() const { return getValue (Ids::osxSDK); }
  202. Value getMacCompatibilityVersion() const { return getValue (Ids::osxCompatibility); }
  203. //==============================================================================
  204. private:
  205. friend class Project;
  206. Project* project;
  207. ValueTree config;
  208. Value getValue (const Identifier& name) const { return config.getPropertyAsValue (name, getUndoManager()); }
  209. UndoManager* getUndoManager() const { return project->getUndoManagerFor (config); }
  210. BuildConfiguration (Project* project, const ValueTree& configNode);
  211. };
  212. int getNumConfigurations() const;
  213. BuildConfiguration getConfiguration (int index);
  214. void addNewConfiguration (BuildConfiguration* configToCopy);
  215. void deleteConfiguration (int index);
  216. bool hasConfigurationNamed (const String& name) const;
  217. const String getUniqueConfigName (String name) const;
  218. //==============================================================================
  219. ValueTree getExporters();
  220. int getNumExporters();
  221. ProjectExporter* createExporter (int index);
  222. void addNewExporter (int exporterIndex);
  223. void deleteExporter (int index);
  224. void createDefaultExporters();
  225. //==============================================================================
  226. struct JuceConfigFlag
  227. {
  228. String symbol, description;
  229. Value value; // 1 = true, 2 = false, anything else = use default
  230. };
  231. void getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags);
  232. static const char* const configFlagDefault;
  233. static const char* const configFlagEnabled;
  234. static const char* const configFlagDisabled;
  235. Value getJuceConfigFlag (const String& name);
  236. //==============================================================================
  237. const String getFileTemplate (const String& templateName);
  238. //==============================================================================
  239. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property);
  240. void valueTreeChildrenChanged (ValueTree& tree);
  241. void valueTreeParentChanged (ValueTree& tree);
  242. //==============================================================================
  243. UndoManager* getUndoManagerFor (const ValueTree& node) const { return 0; }
  244. //==============================================================================
  245. static const char* projectFileExtension;
  246. static void resaveJucerFile (const File& file);
  247. private:
  248. ValueTree projectRoot;
  249. static File lastDocumentOpened;
  250. const File getLocalJuceFolder();
  251. void updateProjectSettings();
  252. void setMissingDefaultValues();
  253. ValueTree getConfigurations() const;
  254. void createDefaultConfigs();
  255. ValueTree getJuceConfigNode();
  256. Project (const Project&);
  257. const Project& operator= (const Project&);
  258. };
  259. #endif // __JUCER_PROJECT_JUCEHEADER__