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.

341 lines
17KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCER_PROJECT_H_INCLUDED
  18. #define JUCER_PROJECT_H_INCLUDED
  19. class ProjectExporter;
  20. class ProjectType;
  21. class LibraryModule;
  22. class EnabledModuleList;
  23. //==============================================================================
  24. class Project : public FileBasedDocument,
  25. public ValueTree::Listener
  26. {
  27. public:
  28. //==============================================================================
  29. Project (const File&);
  30. ~Project();
  31. //==============================================================================
  32. // FileBasedDocument stuff..
  33. String getDocumentTitle() override;
  34. Result loadDocument (const File& file) override;
  35. Result saveDocument (const File& file) override;
  36. Result saveProject (const File& file, bool isCommandLineApp);
  37. Result saveResourcesOnly (const File& file);
  38. File getLastDocumentOpened() override;
  39. void setLastDocumentOpened (const File& file) override;
  40. void setTitle (const String& newTitle);
  41. //==============================================================================
  42. File getProjectFolder() const { return getFile().getParentDirectory(); }
  43. ValueTree getProjectRoot() const { return projectRoot; }
  44. String getTitle() const;
  45. Value getProjectNameValue() { return getMainGroup().getNameValue(); }
  46. String getProjectFilenameRoot() { return File::createLegalFileName (getDocumentTitle()); }
  47. String getProjectUID() const { return projectRoot [Ids::ID]; }
  48. //==============================================================================
  49. template <class FileType>
  50. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  51. {
  52. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  53. }
  54. File resolveFilename (String filename) const;
  55. String getRelativePathForFile (const File& file) const;
  56. //==============================================================================
  57. // Creates editors for the project settings
  58. void createPropertyEditors (PropertyListBuilder&);
  59. //==============================================================================
  60. // project types
  61. const ProjectType& getProjectType() const;
  62. Value getProjectTypeValue() { return getProjectValue (Ids::projectType); }
  63. String getProjectTypeString() const { return projectRoot [Ids::projectType]; }
  64. Value getVersionValue() { return getProjectValue (Ids::version); }
  65. String getVersionString() const { return projectRoot [Ids::version]; }
  66. String getVersionAsHex() const;
  67. int getVersionAsHexInteger() const;
  68. Value getBundleIdentifier() { return getProjectValue (Ids::bundleIdentifier); }
  69. String getDefaultBundleIdentifier() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getTitle(), false, true, false); }
  70. Value getAAXIdentifier() { return getProjectValue (Ids::aaxIdentifier); }
  71. String getDefaultAAXIdentifier() { return getDefaultBundleIdentifier(); }
  72. Value getCompanyName() { return getProjectValue (Ids::companyName); }
  73. Value getCompanyWebsite() { return getProjectValue (Ids::companyWebsite); }
  74. Value getCompanyEmail() { return getProjectValue (Ids::companyEmail); }
  75. //==============================================================================
  76. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  77. Value getProjectPreprocessorDefs() { return getProjectValue (Ids::defines); }
  78. StringPairArray getPreprocessorDefs() const;
  79. Value getProjectUserNotes() { return getProjectValue (Ids::userNotes); }
  80. //==============================================================================
  81. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  82. File getSourceFilesFolder() const { return getProjectFolder().getChildFile ("Source"); }
  83. File getLocalModulesFolder() const { return getGeneratedCodeFolder().getChildFile ("modules"); }
  84. File getLocalModuleFolder (const String& moduleID) const { return getLocalModulesFolder().getChildFile (moduleID); }
  85. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  86. File getBinaryDataCppFile (int index) const;
  87. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  88. Value getMaxBinaryFileSize() { return getProjectValue (Ids::maxBinaryFileSize); }
  89. Value shouldIncludeBinaryInAppConfig() { return getProjectValue (Ids::includeBinaryInAppConfig); }
  90. //==============================================================================
  91. String getAppConfigFilename() const { return "AppConfig.h"; }
  92. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  93. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  94. //==============================================================================
  95. // Some helper methods for audio plugin/host projects.
  96. Value shouldBuildVST() { return getProjectValue ("buildVST"); }
  97. Value shouldBuildVST3() { return getProjectValue ("buildVST3"); }
  98. Value shouldBuildAU() { return getProjectValue ("buildAU"); }
  99. Value shouldBuildAUv3() { return getProjectValue ("buildAUv3"); }
  100. Value shouldBuildRTAS() { return getProjectValue ("buildRTAS"); }
  101. Value shouldBuildAAX() { return getProjectValue ("buildAAX"); }
  102. Value shouldBuildStandalone() { return shouldBuildAUv3(); /* TODO: enable this when standalone becomes independent from AUv3: getProjectValue ("buildStandalone"); */}
  103. Value getPluginName() { return getProjectValue ("pluginName"); }
  104. Value getPluginDesc() { return getProjectValue ("pluginDesc"); }
  105. Value getPluginManufacturer() { return getProjectValue ("pluginManufacturer"); }
  106. Value getPluginManufacturerCode() { return getProjectValue ("pluginManufacturerCode"); }
  107. Value getPluginCode() { return getProjectValue ("pluginCode"); }
  108. Value getPluginChannelConfigs() { return getProjectValue ("pluginChannelConfigs"); }
  109. Value getPluginIsSynth() { return getProjectValue ("pluginIsSynth"); }
  110. Value getPluginWantsMidiInput() { return getProjectValue ("pluginWantsMidiIn"); }
  111. Value getPluginProducesMidiOut() { return getProjectValue ("pluginProducesMidiOut"); }
  112. Value getPluginIsMidiEffectPlugin() { return getProjectValue ("pluginIsMidiEffectPlugin"); }
  113. Value getPluginEditorNeedsKeyFocus() { return getProjectValue ("pluginEditorRequiresKeys"); }
  114. Value getPluginVSTCategory() { return getProjectValue ("pluginVSTCategory"); }
  115. Value getPluginAUExportPrefix() { return getProjectValue ("pluginAUExportPrefix"); }
  116. Value getPluginAUMainType() { return getProjectValue ("pluginAUMainType"); }
  117. Value getPluginRTASCategory() { return getProjectValue ("pluginRTASCategory"); }
  118. Value getPluginRTASBypassDisabled() { return getProjectValue ("pluginRTASDisableBypass"); }
  119. Value getPluginRTASMultiMonoDisabled() { return getProjectValue ("pluginRTASDisableMultiMono"); }
  120. Value getPluginAAXCategory() { return getProjectValue ("pluginAAXCategory"); }
  121. Value getPluginAAXBypassDisabled() { return getProjectValue ("pluginAAXDisableBypass"); }
  122. Value getPluginAAXMultiMonoDisabled() { return getProjectValue ("pluginAAXDisableMultiMono"); }
  123. String getPluginRTASCategoryCode();
  124. String getAUMainTypeString();
  125. String getAUMainTypeCode();
  126. String getPluginVSTCategoryString();
  127. bool isAUPluginHost();
  128. bool isVSTPluginHost();
  129. bool isVST3PluginHost();
  130. void updateDeprecatedProjectSettingsInteractively();
  131. //==============================================================================
  132. class Item
  133. {
  134. public:
  135. //==============================================================================
  136. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  137. Item (const Item& other);
  138. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  139. void initialiseMissingProperties();
  140. //==============================================================================
  141. bool isValid() const { return state.isValid(); }
  142. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  143. bool operator!= (const Item& other) const { return ! operator== (other); }
  144. //==============================================================================
  145. bool isFile() const;
  146. bool isGroup() const;
  147. bool isMainGroup() const;
  148. bool isImageFile() const;
  149. String getID() const;
  150. void setID (const String& newID);
  151. Item findItemWithID (const String& targetId) const; // (recursive search)
  152. String getImageFileID() const;
  153. Drawable* loadAsImageFile() const;
  154. //==============================================================================
  155. Value getNameValue();
  156. String getName() const;
  157. File getFile() const;
  158. String getFilePath() const;
  159. void setFile (const File& file);
  160. void setFile (const RelativePath& file);
  161. File determineGroupFolder() const;
  162. bool renameFile (const File& newFile);
  163. bool shouldBeAddedToTargetProject() const;
  164. bool shouldBeCompiled() const;
  165. Value getShouldCompileValue();
  166. bool shouldBeAddedToBinaryResources() const;
  167. Value getShouldAddToBinaryResourcesValue();
  168. bool shouldBeAddedToXcodeResources() const;
  169. Value getShouldAddToXcodeResourcesValue();
  170. Value getShouldInhibitWarningsValue();
  171. bool shouldInhibitWarnings() const;
  172. bool isModuleCode() const;
  173. //==============================================================================
  174. bool canContain (const Item& child) const;
  175. int getNumChildren() const { return state.getNumChildren(); }
  176. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  177. Item addNewSubGroup (const String& name, int insertIndex);
  178. Item getOrCreateSubGroup (const String& name);
  179. void addChild (const Item& newChild, int insertIndex);
  180. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  181. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  182. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  183. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  184. void removeItemFromProject();
  185. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  186. Item findItemForFile (const File& file) const;
  187. bool containsChildForFile (const RelativePath& file) const;
  188. Item getParent() const;
  189. Item createCopy();
  190. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  191. Icon getIcon() const;
  192. bool isIconCrossedOut() const;
  193. Project& project;
  194. ValueTree state;
  195. private:
  196. Item& operator= (const Item&);
  197. bool belongsToModule;
  198. };
  199. Item getMainGroup();
  200. void findAllImageItems (OwnedArray<Item>& items);
  201. //==============================================================================
  202. ValueTree getExporters();
  203. int getNumExporters();
  204. ProjectExporter* createExporter (int index);
  205. void addNewExporter (const String& exporterName);
  206. void createExporterForCurrentPlatform();
  207. struct ExporterIterator
  208. {
  209. ExporterIterator (Project& project);
  210. ~ExporterIterator();
  211. bool next();
  212. ProjectExporter& operator*() const { return *exporter; }
  213. ProjectExporter* operator->() const { return exporter; }
  214. ScopedPointer<ProjectExporter> exporter;
  215. int index;
  216. private:
  217. Project& project;
  218. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  219. };
  220. //==============================================================================
  221. struct ConfigFlag
  222. {
  223. String symbol, description, sourceModuleID;
  224. Value value; // 1 = true, 2 = false, anything else = use default
  225. };
  226. static const char* const configFlagDefault;
  227. static const char* const configFlagEnabled;
  228. static const char* const configFlagDisabled;
  229. Value getConfigFlag (const String& name);
  230. bool isConfigFlagEnabled (const String& name) const;
  231. //==============================================================================
  232. EnabledModuleList& getModules();
  233. //==============================================================================
  234. String getFileTemplate (const String& templateName);
  235. //==============================================================================
  236. PropertiesFile& getStoredProperties() const;
  237. //==============================================================================
  238. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  239. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  240. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  241. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  242. void valueTreeParentChanged (ValueTree&) override;
  243. //==============================================================================
  244. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  245. //==============================================================================
  246. static const char* projectFileExtension;
  247. private:
  248. //==============================================================================
  249. void setMissingAudioPluginDefaultValues();
  250. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  251. //==============================================================================
  252. friend class Item;
  253. ValueTree projectRoot;
  254. ScopedPointer<EnabledModuleList> enabledModulesList;
  255. bool isSaving;
  256. void updateProjectSettings();
  257. void sanitiseConfigFlags();
  258. void setMissingDefaultValues();
  259. ValueTree getConfigurations() const;
  260. ValueTree getConfigNode();
  261. void updateOldStyleConfigList();
  262. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  263. void removeDefunctExporters();
  264. void updateOldModulePaths();
  265. void warnAboutOldProjucerVersion();
  266. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  267. };
  268. #endif // JUCER_PROJECT_H_INCLUDED