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.

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