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.

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