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.

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