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.

392 lines
20KB

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