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.

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