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. #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. Value getShouldEnableIAAAsValue() { return getProjectValue ("enableIAA"); }
  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. bool shouldEnableIAA() const { return getProjectVar ("enableIAA"); }
  113. //==============================================================================
  114. Value getPluginName() { return getProjectValue ("pluginName"); }
  115. Value getPluginDesc() { return getProjectValue ("pluginDesc"); }
  116. Value getPluginManufacturer() { return getProjectValue ("pluginManufacturer"); }
  117. Value getPluginManufacturerCode() { return getProjectValue ("pluginManufacturerCode"); }
  118. Value getPluginCode() { return getProjectValue ("pluginCode"); }
  119. Value getPluginChannelConfigs() { return getProjectValue ("pluginChannelConfigs"); }
  120. Value getPluginIsSynth() { return getProjectValue ("pluginIsSynth"); }
  121. Value getPluginWantsMidiInput() { return getProjectValue ("pluginWantsMidiIn"); }
  122. Value getPluginProducesMidiOut() { return getProjectValue ("pluginProducesMidiOut"); }
  123. Value getPluginIsMidiEffectPlugin() { return getProjectValue ("pluginIsMidiEffectPlugin"); }
  124. Value getPluginEditorNeedsKeyFocus() { return getProjectValue ("pluginEditorRequiresKeys"); }
  125. Value getPluginVSTCategory() { return getProjectValue ("pluginVSTCategory"); }
  126. Value getPluginAUExportPrefix() { return getProjectValue ("pluginAUExportPrefix"); }
  127. Value getPluginAUMainType() { return getProjectValue ("pluginAUMainType"); }
  128. Value getPluginRTASCategory() { return getProjectValue ("pluginRTASCategory"); }
  129. Value getPluginRTASBypassDisabled() { return getProjectValue ("pluginRTASDisableBypass"); }
  130. Value getPluginRTASMultiMonoDisabled() { return getProjectValue ("pluginRTASDisableMultiMono"); }
  131. Value getPluginAAXCategory() { return getProjectValue ("pluginAAXCategory"); }
  132. Value getPluginAAXBypassDisabled() { return getProjectValue ("pluginAAXDisableBypass"); }
  133. Value getPluginAAXMultiMonoDisabled() { return getProjectValue ("pluginAAXDisableMultiMono"); }
  134. String getPluginRTASCategoryCode();
  135. String getAUMainTypeString();
  136. String getAUMainTypeCode();
  137. String getIAATypeCode();
  138. String getIAAPluginName();
  139. String getPluginVSTCategoryString();
  140. bool isAUPluginHost();
  141. bool isVSTPluginHost();
  142. bool isVST3PluginHost();
  143. bool shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept;
  144. static ProjectType::Target::Type getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix);
  145. //==============================================================================
  146. void updateDeprecatedProjectSettingsInteractively();
  147. //==============================================================================
  148. class Item
  149. {
  150. public:
  151. //==============================================================================
  152. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  153. Item (const Item& other);
  154. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  155. void initialiseMissingProperties();
  156. //==============================================================================
  157. bool isValid() const { return state.isValid(); }
  158. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  159. bool operator!= (const Item& other) const { return ! operator== (other); }
  160. //==============================================================================
  161. bool isFile() const;
  162. bool isGroup() const;
  163. bool isMainGroup() const;
  164. bool isImageFile() const;
  165. String getID() const;
  166. void setID (const String& newID);
  167. Item findItemWithID (const String& targetId) const; // (recursive search)
  168. String getImageFileID() const;
  169. Drawable* loadAsImageFile() const;
  170. //==============================================================================
  171. Value getNameValue();
  172. String getName() const;
  173. File getFile() const;
  174. String getFilePath() const;
  175. void setFile (const File& file);
  176. void setFile (const RelativePath& file);
  177. File determineGroupFolder() const;
  178. bool renameFile (const File& newFile);
  179. bool shouldBeAddedToTargetProject() const;
  180. bool shouldBeCompiled() const;
  181. Value getShouldCompileValue();
  182. bool shouldBeAddedToBinaryResources() const;
  183. Value getShouldAddToBinaryResourcesValue();
  184. bool shouldBeAddedToXcodeResources() const;
  185. Value getShouldAddToXcodeResourcesValue();
  186. Value getShouldInhibitWarningsValue();
  187. bool shouldInhibitWarnings() const;
  188. bool isModuleCode() const;
  189. //==============================================================================
  190. bool canContain (const Item& child) const;
  191. int getNumChildren() const { return state.getNumChildren(); }
  192. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  193. Item addNewSubGroup (const String& name, int insertIndex);
  194. Item getOrCreateSubGroup (const String& name);
  195. void addChild (const Item& newChild, int insertIndex);
  196. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  197. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  198. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  199. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  200. void removeItemFromProject();
  201. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  202. Item findItemForFile (const File& file) const;
  203. bool containsChildForFile (const RelativePath& file) const;
  204. Item getParent() const;
  205. Item createCopy();
  206. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  207. Icon getIcon (bool isOpen = false) const;
  208. bool isIconCrossedOut() const;
  209. Project& project;
  210. ValueTree state;
  211. private:
  212. Item& operator= (const Item&);
  213. bool belongsToModule;
  214. };
  215. Item getMainGroup();
  216. void findAllImageItems (OwnedArray<Item>& items);
  217. //==============================================================================
  218. ValueTree getExporters();
  219. int getNumExporters();
  220. ProjectExporter* createExporter (int index);
  221. void addNewExporter (const String& exporterName);
  222. void createExporterForCurrentPlatform();
  223. struct ExporterIterator
  224. {
  225. ExporterIterator (Project& project);
  226. ~ExporterIterator();
  227. bool next();
  228. ProjectExporter& operator*() const { return *exporter; }
  229. ProjectExporter* operator->() const { return exporter; }
  230. ScopedPointer<ProjectExporter> exporter;
  231. int index;
  232. private:
  233. Project& project;
  234. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  235. };
  236. //==============================================================================
  237. struct ConfigFlag
  238. {
  239. String symbol, description, sourceModuleID, defaultValue;
  240. Value value; // 1 = true, 2 = false, anything else = use default
  241. };
  242. static const char* const configFlagDefault;
  243. static const char* const configFlagEnabled;
  244. static const char* const configFlagDisabled;
  245. Value getConfigFlag (const String& name);
  246. bool isConfigFlagEnabled (const String& name) const;
  247. //==============================================================================
  248. EnabledModuleList& getModules();
  249. //==============================================================================
  250. String getFileTemplate (const String& templateName);
  251. //==============================================================================
  252. PropertiesFile& getStoredProperties() const;
  253. //==============================================================================
  254. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  255. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  256. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  257. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  258. void valueTreeParentChanged (ValueTree&) override;
  259. //==============================================================================
  260. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  261. //==============================================================================
  262. static const char* projectFileExtension;
  263. //==============================================================================
  264. bool hasProjectBeenModified();
  265. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  266. private:
  267. //==============================================================================
  268. void setMissingAudioPluginDefaultValues();
  269. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  270. //==============================================================================
  271. friend class Item;
  272. ValueTree projectRoot;
  273. ScopedPointer<EnabledModuleList> enabledModulesList;
  274. bool isSaving;
  275. void updateProjectSettings();
  276. void sanitiseConfigFlags();
  277. void setMissingDefaultValues();
  278. ValueTree getConfigurations() const;
  279. ValueTree getConfigNode();
  280. void updateOldStyleConfigList();
  281. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  282. void removeDefunctExporters();
  283. void updateOldModulePaths();
  284. void warnAboutOldProjucerVersion();
  285. Time modificationTime;
  286. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  287. };