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.

381 lines
19KB

  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. Value getCompanyWebsite() { return getProjectValue (Ids::companyWebsite); }
  75. Value getCompanyEmail() { return getProjectValue (Ids::companyEmail); }
  76. Value shouldDisplaySplashScreen() { return getProjectValue (Ids::displaySplashScreen); }
  77. Value shouldReportAppUsage() { return getProjectValue (Ids::reportAppUsage); }
  78. Value splashScreenColour() { return getProjectValue (Ids::splashScreenColour); }
  79. Value getCppStandardValue() { return getProjectValue (Ids::cppLanguageStandard); }
  80. //==============================================================================
  81. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  82. var getProjectVar (const Identifier& name) const { return projectRoot.getProperty (name); }
  83. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  84. StringPairArray getPreprocessorDefs() const;
  85. Value getProjectUserNotes() { return getProjectValue (Ids::userNotes); }
  86. //==============================================================================
  87. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  88. File getSourceFilesFolder() const { return getProjectFolder().getChildFile ("Source"); }
  89. File getLocalModulesFolder() const { return getGeneratedCodeFolder().getChildFile ("modules"); }
  90. File getLocalModuleFolder (const String& moduleID) const { return getLocalModulesFolder().getChildFile (moduleID); }
  91. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  92. File getBinaryDataCppFile (int index) const;
  93. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  94. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  95. Value shouldIncludeBinaryInAppConfig() { return getProjectValue (Ids::includeBinaryInAppConfig); }
  96. Value binaryDataNamespace() { return getProjectValue (Ids::binaryDataNamespace); }
  97. //==============================================================================
  98. String getAppConfigFilename() const { return "AppConfig.h"; }
  99. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  100. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  101. //==============================================================================
  102. // Some helper methods for audio plugin/host projects.
  103. Value getShouldBuildVSTAsValue() { return getProjectValue ("buildVST"); }
  104. Value getShouldBuildVST3AsValue() { return getProjectValue ("buildVST3"); }
  105. Value getShouldBuildAUAsValue() { return getProjectValue ("buildAU"); }
  106. Value getShouldBuildAUv3AsValue() { return getProjectValue ("buildAUv3"); }
  107. Value getShouldBuildRTASAsValue() { return getProjectValue ("buildRTAS"); }
  108. Value getShouldBuildAAXAsValue() { return getProjectValue ("buildAAX"); }
  109. Value getShouldBuildStandalonePluginAsValue() { return getProjectValue ("buildStandalone");}
  110. Value getShouldEnableIAAAsValue() { return getProjectValue ("enableIAA"); }
  111. bool shouldBuildVST() const { return getProjectVar ("buildVST"); }
  112. bool shouldBuildVST3() const { return getProjectVar ("buildVST3"); }
  113. bool shouldBuildAU() const { return getProjectVar ("buildAU"); }
  114. bool shouldBuildAUv3() const { return getProjectVar ("buildAUv3"); }
  115. bool shouldBuildRTAS() const { return getProjectVar ("buildRTAS"); }
  116. bool shouldBuildAAX() const { return getProjectVar ("buildAAX"); }
  117. bool shouldBuildStandalonePlugin() const { return getProjectVar ("buildStandalone"); }
  118. bool shouldEnableIAA() const { return getProjectVar ("enableIAA"); }
  119. //==============================================================================
  120. Value getPluginName() { return getProjectValue ("pluginName"); }
  121. Value getPluginDesc() { return getProjectValue ("pluginDesc"); }
  122. Value getPluginManufacturer() { return getProjectValue ("pluginManufacturer"); }
  123. Value getPluginManufacturerCode() { return getProjectValue ("pluginManufacturerCode"); }
  124. Value getPluginCode() { return getProjectValue ("pluginCode"); }
  125. Value getPluginChannelConfigs() { return getProjectValue ("pluginChannelConfigs"); }
  126. Value getPluginIsSynth() { return getProjectValue ("pluginIsSynth"); }
  127. Value getPluginWantsMidiInput() { return getProjectValue ("pluginWantsMidiIn"); }
  128. Value getPluginProducesMidiOut() { return getProjectValue ("pluginProducesMidiOut"); }
  129. Value getPluginIsMidiEffectPlugin() { return getProjectValue ("pluginIsMidiEffectPlugin"); }
  130. Value getPluginEditorNeedsKeyFocus() { return getProjectValue ("pluginEditorRequiresKeys"); }
  131. Value getPluginVSTCategory() { return getProjectValue ("pluginVSTCategory"); }
  132. Value getPluginAUExportPrefix() { return getProjectValue ("pluginAUExportPrefix"); }
  133. Value getPluginAUMainType() { return getProjectValue ("pluginAUMainType"); }
  134. Value getPluginRTASCategory() { return getProjectValue ("pluginRTASCategory"); }
  135. Value getPluginRTASBypassDisabled() { return getProjectValue ("pluginRTASDisableBypass"); }
  136. Value getPluginRTASMultiMonoDisabled() { return getProjectValue ("pluginRTASDisableMultiMono"); }
  137. Value getPluginAAXCategory() { return getProjectValue ("pluginAAXCategory"); }
  138. Value getPluginAAXBypassDisabled() { return getProjectValue ("pluginAAXDisableBypass"); }
  139. Value getPluginAAXMultiMonoDisabled() { return getProjectValue ("pluginAAXDisableMultiMono"); }
  140. String getPluginRTASCategoryCode();
  141. String getAUMainTypeString();
  142. String getAUMainTypeCode();
  143. String getIAATypeCode();
  144. String getIAAPluginName();
  145. String getPluginVSTCategoryString();
  146. bool isAUPluginHost();
  147. bool isVSTPluginHost();
  148. bool isVST3PluginHost();
  149. bool shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept;
  150. static ProjectType::Target::Type getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix);
  151. //==============================================================================
  152. void updateDeprecatedProjectSettingsInteractively();
  153. //==============================================================================
  154. class Item
  155. {
  156. public:
  157. //==============================================================================
  158. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  159. Item (const Item& other);
  160. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  161. void initialiseMissingProperties();
  162. //==============================================================================
  163. bool isValid() const { return state.isValid(); }
  164. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  165. bool operator!= (const Item& other) const { return ! operator== (other); }
  166. //==============================================================================
  167. bool isFile() const;
  168. bool isGroup() const;
  169. bool isMainGroup() const;
  170. bool isImageFile() const;
  171. String getID() const;
  172. void setID (const String& newID);
  173. Item findItemWithID (const String& targetId) const; // (recursive search)
  174. String getImageFileID() const;
  175. Drawable* loadAsImageFile() const;
  176. //==============================================================================
  177. Value getNameValue();
  178. String getName() const;
  179. File getFile() const;
  180. String getFilePath() const;
  181. void setFile (const File& file);
  182. void setFile (const RelativePath& file);
  183. File determineGroupFolder() const;
  184. bool renameFile (const File& newFile);
  185. bool shouldBeAddedToTargetProject() const;
  186. bool shouldBeCompiled() const;
  187. Value getShouldCompileValue();
  188. bool shouldBeAddedToBinaryResources() const;
  189. Value getShouldAddToBinaryResourcesValue();
  190. bool shouldBeAddedToXcodeResources() const;
  191. Value getShouldAddToXcodeResourcesValue();
  192. Value getShouldInhibitWarningsValue();
  193. bool shouldInhibitWarnings() const;
  194. bool isModuleCode() const;
  195. //==============================================================================
  196. bool canContain (const Item& child) const;
  197. int getNumChildren() const { return state.getNumChildren(); }
  198. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  199. Item addNewSubGroup (const String& name, int insertIndex);
  200. Item getOrCreateSubGroup (const String& name);
  201. void addChild (const Item& newChild, int insertIndex);
  202. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  203. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  204. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  205. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  206. void removeItemFromProject();
  207. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  208. Item findItemForFile (const File& file) const;
  209. bool containsChildForFile (const RelativePath& file) const;
  210. Item getParent() const;
  211. Item createCopy();
  212. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  213. Icon getIcon (bool isOpen = false) const;
  214. bool isIconCrossedOut() const;
  215. Project& project;
  216. ValueTree state;
  217. private:
  218. Item& operator= (const Item&);
  219. bool belongsToModule;
  220. };
  221. Item getMainGroup();
  222. void findAllImageItems (OwnedArray<Item>& items);
  223. //==============================================================================
  224. ValueTree getExporters();
  225. int getNumExporters();
  226. ProjectExporter* createExporter (int index);
  227. void addNewExporter (const String& exporterName);
  228. void createExporterForCurrentPlatform();
  229. struct ExporterIterator
  230. {
  231. ExporterIterator (Project& project);
  232. ~ExporterIterator();
  233. bool next();
  234. ProjectExporter& operator*() const { return *exporter; }
  235. ProjectExporter* operator->() const { return exporter; }
  236. ScopedPointer<ProjectExporter> exporter;
  237. int index;
  238. private:
  239. Project& project;
  240. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  241. };
  242. //==============================================================================
  243. struct ConfigFlag
  244. {
  245. String symbol, description, sourceModuleID, defaultValue;
  246. Value value; // 1 = true, 2 = false, anything else = use default
  247. };
  248. static const char* const configFlagDefault;
  249. static const char* const configFlagEnabled;
  250. static const char* const configFlagDisabled;
  251. Value getConfigFlag (const String& name);
  252. bool isConfigFlagEnabled (const String& name, bool defaultIsEnabled = false) const;
  253. //==============================================================================
  254. EnabledModuleList& getModules();
  255. //==============================================================================
  256. String getFileTemplate (const String& templateName);
  257. //==============================================================================
  258. PropertiesFile& getStoredProperties() const;
  259. //==============================================================================
  260. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  261. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  262. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  263. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  264. void valueTreeParentChanged (ValueTree&) override;
  265. //==============================================================================
  266. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  267. //==============================================================================
  268. static const char* projectFileExtension;
  269. //==============================================================================
  270. bool hasProjectBeenModified();
  271. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  272. //==============================================================================
  273. String getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& baseTargetFolder);
  274. //==============================================================================
  275. bool shouldWaitAfterSaving = false;
  276. String specifiedExporterToSave = {};
  277. private:
  278. //==============================================================================
  279. void setMissingAudioPluginDefaultValues();
  280. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  281. bool setCppVersionFromOldExporterSettings();
  282. //==============================================================================
  283. friend class Item;
  284. ValueTree projectRoot;
  285. ScopedPointer<EnabledModuleList> enabledModulesList;
  286. bool isSaving;
  287. void updateProjectSettings();
  288. void sanitiseConfigFlags();
  289. void setMissingDefaultValues();
  290. ValueTree getConfigurations() const;
  291. ValueTree getConfigNode();
  292. void updateOldStyleConfigList();
  293. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  294. void removeDefunctExporters();
  295. void updateOldModulePaths();
  296. void warnAboutOldProjucerVersion();
  297. Time modificationTime;
  298. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  299. };