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.

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