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.

365 lines
18KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCER_PROJECT_H_INCLUDED
  18. #define JUCER_PROJECT_H_INCLUDED
  19. #include "jucer_ProjectType.h"
  20. class ProjectExporter;
  21. class LibraryModule;
  22. class EnabledModuleList;
  23. //==============================================================================
  24. class Project : public FileBasedDocument,
  25. public ValueTree::Listener
  26. {
  27. public:
  28. //==============================================================================
  29. Project (const File&);
  30. ~Project();
  31. //==============================================================================
  32. // FileBasedDocument stuff..
  33. String getDocumentTitle() override;
  34. Result loadDocument (const File& file) override;
  35. Result saveDocument (const File& file) override;
  36. Result saveProject (const File& file, bool isCommandLineApp);
  37. Result saveResourcesOnly (const File& file);
  38. File getLastDocumentOpened() override;
  39. void setLastDocumentOpened (const File& file) override;
  40. void setTitle (const String& newTitle);
  41. //==============================================================================
  42. File getProjectFolder() const { return getFile().getParentDirectory(); }
  43. ValueTree getProjectRoot() const { return projectRoot; }
  44. String getTitle() const;
  45. Value getProjectNameValue() { return getMainGroup().getNameValue(); }
  46. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  47. String getProjectUID() const { return projectRoot [Ids::ID]; }
  48. //==============================================================================
  49. template <class FileType>
  50. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  51. {
  52. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  53. }
  54. File resolveFilename (String filename) const;
  55. String getRelativePathForFile (const File& file) const;
  56. //==============================================================================
  57. // Creates editors for the project settings
  58. void createPropertyEditors (PropertyListBuilder&);
  59. //==============================================================================
  60. // project types
  61. const ProjectType& getProjectType() const;
  62. Value getProjectTypeValue() { return getProjectValue (Ids::projectType); }
  63. String getProjectTypeString() const { return projectRoot [Ids::projectType]; }
  64. Value getVersionValue() { return getProjectValue (Ids::version); }
  65. String getVersionString() const { return projectRoot [Ids::version]; }
  66. String getVersionAsHex() const;
  67. int getVersionAsHexInteger() const;
  68. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  69. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getTitle(), false, true, false); }
  70. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  71. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  72. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  73. Value getCompanyWebsite() { return getProjectValue (Ids::companyWebsite); }
  74. Value getCompanyEmail() { return getProjectValue (Ids::companyEmail); }
  75. //==============================================================================
  76. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  77. var getProjectVar (const Identifier& name) const { return projectRoot.getProperty (name); }
  78. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  79. StringPairArray getPreprocessorDefs() const;
  80. Value getProjectUserNotes() { return getProjectValue (Ids::userNotes); }
  81. //==============================================================================
  82. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  83. File getSourceFilesFolder() const { return getProjectFolder().getChildFile ("Source"); }
  84. File getLocalModulesFolder() const { return getGeneratedCodeFolder().getChildFile ("modules"); }
  85. File getLocalModuleFolder (const String& moduleID) const { return getLocalModulesFolder().getChildFile (moduleID); }
  86. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  87. File getBinaryDataCppFile (int index) const;
  88. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  89. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  90. Value shouldIncludeBinaryInAppConfig() { return getProjectValue (Ids::includeBinaryInAppConfig); }
  91. Value binaryDataNamespace() { return getProjectValue (Ids::binaryDataNamespace); }
  92. //==============================================================================
  93. String getAppConfigFilename() const { return "AppConfig.h"; }
  94. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  95. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  96. //==============================================================================
  97. // Some helper methods for audio plugin/host projects.
  98. Value getShouldBuildVSTAsValue() { return getProjectValue ("buildVST"); }
  99. Value getShouldBuildVST3AsValue() { return getProjectValue ("buildVST3"); }
  100. Value getShouldBuildAUAsValue() { return getProjectValue ("buildAU"); }
  101. Value getShouldBuildAUv3AsValue() { return getProjectValue ("buildAUv3"); }
  102. Value getShouldBuildRTASAsValue() { return getProjectValue ("buildRTAS"); }
  103. Value getShouldBuildAAXAsValue() { return getProjectValue ("buildAAX"); }
  104. Value getShouldBuildStandalonePluginAsValue() { return getProjectValue ("buildStandalone");}
  105. bool shouldBuildVST() const { return getProjectVar ("buildVST"); }
  106. bool shouldBuildVST3() const { return getProjectVar ("buildVST3"); }
  107. bool shouldBuildAU() const { return getProjectVar ("buildAU"); }
  108. bool shouldBuildAUv3() const { return getProjectVar ("buildAUv3"); }
  109. bool shouldBuildRTAS() const { return getProjectVar ("buildRTAS"); }
  110. bool shouldBuildAAX() const { return getProjectVar ("buildAAX"); }
  111. bool shouldBuildStandalonePlugin() const { return getProjectVar ("buildStandalone"); }
  112. //==============================================================================
  113. Value getPluginName() { return getProjectValue ("pluginName"); }
  114. Value getPluginDesc() { return getProjectValue ("pluginDesc"); }
  115. Value getPluginManufacturer() { return getProjectValue ("pluginManufacturer"); }
  116. Value getPluginManufacturerCode() { return getProjectValue ("pluginManufacturerCode"); }
  117. Value getPluginCode() { return getProjectValue ("pluginCode"); }
  118. Value getPluginChannelConfigs() { return getProjectValue ("pluginChannelConfigs"); }
  119. Value getPluginIsSynth() { return getProjectValue ("pluginIsSynth"); }
  120. Value getPluginWantsMidiInput() { return getProjectValue ("pluginWantsMidiIn"); }
  121. Value getPluginProducesMidiOut() { return getProjectValue ("pluginProducesMidiOut"); }
  122. Value getPluginIsMidiEffectPlugin() { return getProjectValue ("pluginIsMidiEffectPlugin"); }
  123. Value getPluginEditorNeedsKeyFocus() { return getProjectValue ("pluginEditorRequiresKeys"); }
  124. Value getPluginVSTCategory() { return getProjectValue ("pluginVSTCategory"); }
  125. Value getPluginAUExportPrefix() { return getProjectValue ("pluginAUExportPrefix"); }
  126. Value getPluginAUMainType() { return getProjectValue ("pluginAUMainType"); }
  127. Value getPluginRTASCategory() { return getProjectValue ("pluginRTASCategory"); }
  128. Value getPluginRTASBypassDisabled() { return getProjectValue ("pluginRTASDisableBypass"); }
  129. Value getPluginRTASMultiMonoDisabled() { return getProjectValue ("pluginRTASDisableMultiMono"); }
  130. Value getPluginAAXCategory() { return getProjectValue ("pluginAAXCategory"); }
  131. Value getPluginAAXBypassDisabled() { return getProjectValue ("pluginAAXDisableBypass"); }
  132. Value getPluginAAXMultiMonoDisabled() { return getProjectValue ("pluginAAXDisableMultiMono"); }
  133. String getPluginRTASCategoryCode();
  134. String getAUMainTypeString();
  135. String getAUMainTypeCode();
  136. String getPluginVSTCategoryString();
  137. bool isAUPluginHost();
  138. bool isVSTPluginHost();
  139. bool isVST3PluginHost();
  140. bool shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept;
  141. static ProjectType::Target::Type getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix);
  142. //==============================================================================
  143. void updateDeprecatedProjectSettingsInteractively();
  144. //==============================================================================
  145. class Item
  146. {
  147. public:
  148. //==============================================================================
  149. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  150. Item (const Item& other);
  151. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  152. void initialiseMissingProperties();
  153. //==============================================================================
  154. bool isValid() const { return state.isValid(); }
  155. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  156. bool operator!= (const Item& other) const { return ! operator== (other); }
  157. //==============================================================================
  158. bool isFile() const;
  159. bool isGroup() const;
  160. bool isMainGroup() const;
  161. bool isImageFile() const;
  162. String getID() const;
  163. void setID (const String& newID);
  164. Item findItemWithID (const String& targetId) const; // (recursive search)
  165. String getImageFileID() const;
  166. Drawable* loadAsImageFile() const;
  167. //==============================================================================
  168. Value getNameValue();
  169. String getName() const;
  170. File getFile() const;
  171. String getFilePath() const;
  172. void setFile (const File& file);
  173. void setFile (const RelativePath& file);
  174. File determineGroupFolder() const;
  175. bool renameFile (const File& newFile);
  176. bool shouldBeAddedToTargetProject() const;
  177. bool shouldBeCompiled() const;
  178. Value getShouldCompileValue();
  179. bool shouldBeAddedToBinaryResources() const;
  180. Value getShouldAddToBinaryResourcesValue();
  181. bool shouldBeAddedToXcodeResources() const;
  182. Value getShouldAddToXcodeResourcesValue();
  183. Value getShouldInhibitWarningsValue();
  184. bool shouldInhibitWarnings() const;
  185. bool isModuleCode() const;
  186. //==============================================================================
  187. bool canContain (const Item& child) const;
  188. int getNumChildren() const { return state.getNumChildren(); }
  189. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  190. Item addNewSubGroup (const String& name, int insertIndex);
  191. Item getOrCreateSubGroup (const String& name);
  192. void addChild (const Item& newChild, int insertIndex);
  193. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  194. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  195. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  196. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  197. void removeItemFromProject();
  198. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  199. Item findItemForFile (const File& file) const;
  200. bool containsChildForFile (const RelativePath& file) const;
  201. Item getParent() const;
  202. Item createCopy();
  203. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  204. Icon getIcon() const;
  205. bool isIconCrossedOut() const;
  206. Project& project;
  207. ValueTree state;
  208. private:
  209. Item& operator= (const Item&);
  210. bool belongsToModule;
  211. };
  212. Item getMainGroup();
  213. void findAllImageItems (OwnedArray<Item>& items);
  214. //==============================================================================
  215. ValueTree getExporters();
  216. int getNumExporters();
  217. ProjectExporter* createExporter (int index);
  218. void addNewExporter (const String& exporterName);
  219. void createExporterForCurrentPlatform();
  220. struct ExporterIterator
  221. {
  222. ExporterIterator (Project& project);
  223. ~ExporterIterator();
  224. bool next();
  225. ProjectExporter& operator*() const { return *exporter; }
  226. ProjectExporter* operator->() const { return exporter; }
  227. ScopedPointer<ProjectExporter> exporter;
  228. int index;
  229. private:
  230. Project& project;
  231. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  232. };
  233. //==============================================================================
  234. struct ConfigFlag
  235. {
  236. String symbol, description, sourceModuleID, defaultValue;
  237. Value value; // 1 = true, 2 = false, anything else = use default
  238. };
  239. static const char* const configFlagDefault;
  240. static const char* const configFlagEnabled;
  241. static const char* const configFlagDisabled;
  242. Value getConfigFlag (const String& name);
  243. bool isConfigFlagEnabled (const String& name) const;
  244. //==============================================================================
  245. EnabledModuleList& getModules();
  246. //==============================================================================
  247. String getFileTemplate (const String& templateName);
  248. //==============================================================================
  249. PropertiesFile& getStoredProperties() const;
  250. //==============================================================================
  251. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  252. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  253. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  254. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  255. void valueTreeParentChanged (ValueTree&) override;
  256. //==============================================================================
  257. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  258. //==============================================================================
  259. static const char* projectFileExtension;
  260. //==============================================================================
  261. bool hasProjectBeenModified();
  262. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  263. private:
  264. //==============================================================================
  265. void setMissingAudioPluginDefaultValues();
  266. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  267. //==============================================================================
  268. friend class Item;
  269. ValueTree projectRoot;
  270. ScopedPointer<EnabledModuleList> enabledModulesList;
  271. bool isSaving;
  272. void updateProjectSettings();
  273. void sanitiseConfigFlags();
  274. void setMissingDefaultValues();
  275. ValueTree getConfigurations() const;
  276. ValueTree getConfigNode();
  277. void updateOldStyleConfigList();
  278. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  279. void removeDefunctExporters();
  280. void updateOldModulePaths();
  281. void warnAboutOldProjucerVersion();
  282. Time modificationTime;
  283. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  284. };
  285. #endif // JUCER_PROJECT_H_INCLUDED