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.

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