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.

455 lines
23KB

  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. #include "../LiveBuildEngine/jucer_CompileEngineSettings.h"
  22. class ProjectExporter;
  23. class LibraryModule;
  24. class EnabledModuleList;
  25. class ProjectContentComponent;
  26. //==============================================================================
  27. class Project : public FileBasedDocument,
  28. public ValueTree::Listener
  29. {
  30. public:
  31. //==============================================================================
  32. Project (const File&);
  33. ~Project();
  34. //==============================================================================
  35. // FileBasedDocument stuff..
  36. String getDocumentTitle() override;
  37. Result loadDocument (const File& file) override;
  38. Result saveDocument (const File& file) override;
  39. Result saveProject (const File& file, bool isCommandLineApp);
  40. Result saveResourcesOnly (const File& file);
  41. File getLastDocumentOpened() override;
  42. void setLastDocumentOpened (const File& file) override;
  43. void setTitle (const String& newTitle);
  44. //==============================================================================
  45. File getProjectFolder() const { return getFile().getParentDirectory(); }
  46. File getGeneratedCodeFolder() const { return getFile().getSiblingFile ("JuceLibraryCode"); }
  47. File getSourceFilesFolder() const { return getProjectFolder().getChildFile ("Source"); }
  48. File getLocalModulesFolder() const { return getGeneratedCodeFolder().getChildFile ("modules"); }
  49. File getLocalModuleFolder (const String& moduleID) const { return getLocalModulesFolder().getChildFile (moduleID); }
  50. File getAppIncludeFile() const { return getGeneratedCodeFolder().getChildFile (getJuceSourceHFilename()); }
  51. File getBinaryDataCppFile (int index) const;
  52. File getBinaryDataHeaderFile() const { return getBinaryDataCppFile (0).withFileExtension (".h"); }
  53. String getAppConfigFilename() const { return "AppConfig.h"; }
  54. String getJuceSourceFilenameRoot() const { return "JuceLibraryCode"; }
  55. String getJuceSourceHFilename() const { return "JuceHeader.h"; }
  56. //==============================================================================
  57. template <class FileType>
  58. bool shouldBeAddedToBinaryResourcesByDefault (const FileType& file)
  59. {
  60. return ! file.hasFileExtension (sourceOrHeaderFileExtensions);
  61. }
  62. File resolveFilename (String filename) const;
  63. String getRelativePathForFile (const File& file) const;
  64. //==============================================================================
  65. // Creates editors for the project settings
  66. void createPropertyEditors (PropertyListBuilder&);
  67. //==============================================================================
  68. ValueTree getProjectRoot() const { return projectRoot; }
  69. Value getProjectValue (const Identifier& name) { return projectRoot.getPropertyAsValue (name, getUndoManagerFor (projectRoot)); }
  70. var getProjectVar (const Identifier& name) const { return projectRoot.getProperty (name); }
  71. const ProjectType& getProjectType() const;
  72. String getProjectTypeString() const { return projectTypeValue.get(); }
  73. void setProjectType (const String& newProjectType) { projectTypeValue = newProjectType; }
  74. String getProjectNameString() const { return projectNameValue.get(); }
  75. String getProjectFilenameRootString() { return File::createLegalFileName (getDocumentTitle()); }
  76. String getProjectUIDString() const { return projectUIDValue.get(); }
  77. String getVersionString() const { return versionValue.get(); }
  78. String getVersionAsHex() const;
  79. int getVersionAsHexInteger() const;
  80. void setProjectVersion (const String& newVersion) { versionValue = newVersion; }
  81. String getBundleIdentifierString() const { return bundleIdentifierValue.get(); }
  82. String getDefaultBundleIdentifierString() { return "com.yourcompany." + CodeHelpers::makeValidIdentifier (getProjectNameString(), false, true, false); }
  83. String getDefaultAAXIdentifierString() { return getDefaultBundleIdentifierString(); }
  84. String getCompanyNameString() const { return companyNameValue.get(); }
  85. String getCompanyCopyrightString() const { return companyCopyrightValue.get(); }
  86. String getCompanyWebsiteString() const { return companyWebsiteValue.get(); }
  87. String getCompanyEmailString() const { return companyEmailValue.get(); }
  88. String getHeaderSearchPathsString() const { return headerSearchPathsValue.get(); }
  89. StringPairArray getPreprocessorDefs() const { return parsedPreprocessorDefs; }
  90. int getMaxBinaryFileSize() const { return maxBinaryFileSizeValue.get(); }
  91. bool shouldIncludeBinaryInAppConfig() const { return includeBinaryDataInAppConfigValue.get(); }
  92. String getBinaryDataNamespaceString() const { return binaryDataNamespaceValue.get(); }
  93. bool shouldDisplaySplashScreen() const { return displaySplashScreenValue.get(); }
  94. bool shouldReportAppUsage() const { return reportAppUsageValue.get(); }
  95. String getSplashScreenColourString() const { return splashScreenColourValue.get(); }
  96. String getCppStandardString() const { return cppStandardValue.get(); }
  97. //==============================================================================
  98. String getPluginNameString() const { return pluginNameValue.get(); }
  99. String getPluginDescriptionString() const { return pluginDescriptionValue.get();}
  100. String getPluginManufacturerString() const { return pluginManufacturerValue.get(); }
  101. String getPluginManufacturerCodeString() const { return pluginManufacturerCodeValue.get(); }
  102. String getPluginCodeString() const { return pluginCodeValue.get(); }
  103. String getPluginChannelConfigsString() const { return pluginChannelConfigsValue.get(); }
  104. String getAAXIdentifierString() const { return pluginAAXIdentifierValue.get(); }
  105. String getPluginAUExportPrefixString() const { return pluginAUExportPrefixValue.get(); }
  106. String getPluginAUMainTypeString() const { return pluginAUMainTypeValue.get(); }
  107. //==============================================================================
  108. static bool checkMultiChoiceVar (const ValueWithDefault& valueToCheck, Identifier idToCheck) noexcept
  109. {
  110. if (! valueToCheck.get().isArray())
  111. return false;
  112. auto v = valueToCheck.get();
  113. if (auto* varArray = v.getArray())
  114. return varArray->contains (idToCheck.toString());
  115. return false;
  116. }
  117. //==============================================================================
  118. bool shouldBuildVST() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildVST); }
  119. bool shouldBuildVST3() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildVST3); }
  120. bool shouldBuildAU() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildAU); }
  121. bool shouldBuildAUv3() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildAUv3); }
  122. bool shouldBuildRTAS() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildRTAS); }
  123. bool shouldBuildAAX() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildAAX); }
  124. bool shouldBuildStandalonePlugin() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::buildStandalone); }
  125. bool shouldEnableIAA() const { return checkMultiChoiceVar (pluginFormatsValue, Ids::enableIAA); }
  126. //==============================================================================
  127. bool isPluginSynth() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginIsSynth); }
  128. bool pluginWantsMidiInput() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginWantsMidiIn); }
  129. bool pluginProducesMidiOutput() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginProducesMidiOut); }
  130. bool isPluginMidiEffect() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginIsMidiEffectPlugin); }
  131. bool pluginEditorNeedsKeyFocus() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginEditorRequiresKeys); }
  132. bool isPluginRTASBypassDisabled() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginRTASDisableBypass); }
  133. bool isPluginRTASMultiMonoDisabled() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginRTASDisableMultiMono); }
  134. bool isPluginAAXBypassDisabled() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginAAXDisableBypass); }
  135. bool isPluginAAXMultiMonoDisabled() const { return checkMultiChoiceVar (pluginCharacteristicsValue, Ids::pluginAAXDisableMultiMono); }
  136. //==============================================================================
  137. static StringArray getAllVSTCategoryStrings() noexcept;
  138. Array<var> getDefaultVSTCategories() const noexcept;
  139. static StringArray getAllVST3CategoryStrings() noexcept;
  140. Array<var> getDefaultVST3Categories() const noexcept;
  141. static StringArray getAllAAXCategoryStrings() noexcept;
  142. static Array<var> getAllAAXCategoryVars() noexcept;
  143. Array<var> getDefaultAAXCategories() const noexcept;
  144. static StringArray getAllRTASCategoryStrings() noexcept;
  145. static Array<var> getAllRTASCategoryVars() noexcept;
  146. Array<var> getDefaultRTASCategories() const noexcept;
  147. String getVSTCategoryString() const noexcept;
  148. String getVST3CategoryString() const noexcept;
  149. int getAAXCategory() const noexcept;
  150. int getRTASCategory() const noexcept;
  151. String getAUMainTypeString();
  152. String getAUMainTypeCode();
  153. String getIAATypeCode();
  154. String getIAAPluginName();
  155. //==============================================================================
  156. bool isAUPluginHost();
  157. bool isVSTPluginHost();
  158. bool isVST3PluginHost();
  159. //==============================================================================
  160. bool shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept;
  161. static ProjectType::Target::Type getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix);
  162. //==============================================================================
  163. void updateDeprecatedProjectSettingsInteractively();
  164. //==============================================================================
  165. class Item
  166. {
  167. public:
  168. //==============================================================================
  169. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  170. Item (const Item& other);
  171. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  172. void initialiseMissingProperties();
  173. //==============================================================================
  174. bool isValid() const { return state.isValid(); }
  175. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  176. bool operator!= (const Item& other) const { return ! operator== (other); }
  177. //==============================================================================
  178. bool isFile() const;
  179. bool isGroup() const;
  180. bool isMainGroup() const;
  181. bool isImageFile() const;
  182. String getID() const;
  183. void setID (const String& newID);
  184. Item findItemWithID (const String& targetId) const; // (recursive search)
  185. String getImageFileID() const;
  186. Drawable* loadAsImageFile() const;
  187. //==============================================================================
  188. Value getNameValue();
  189. String getName() const;
  190. File getFile() const;
  191. String getFilePath() const;
  192. void setFile (const File& file);
  193. void setFile (const RelativePath& file);
  194. File determineGroupFolder() const;
  195. bool renameFile (const File& newFile);
  196. bool shouldBeAddedToTargetProject() const;
  197. bool shouldBeCompiled() const;
  198. Value getShouldCompileValue();
  199. bool shouldBeAddedToBinaryResources() const;
  200. Value getShouldAddToBinaryResourcesValue();
  201. bool shouldBeAddedToXcodeResources() const;
  202. Value getShouldAddToXcodeResourcesValue();
  203. Value getShouldInhibitWarningsValue();
  204. bool shouldInhibitWarnings() const;
  205. bool isModuleCode() const;
  206. //==============================================================================
  207. bool canContain (const Item& child) const;
  208. int getNumChildren() const { return state.getNumChildren(); }
  209. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  210. Item addNewSubGroup (const String& name, int insertIndex);
  211. Item getOrCreateSubGroup (const String& name);
  212. void addChild (const Item& newChild, int insertIndex);
  213. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  214. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  215. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  216. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  217. void removeItemFromProject();
  218. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  219. Item findItemForFile (const File& file) const;
  220. bool containsChildForFile (const RelativePath& file) const;
  221. Item getParent() const;
  222. Item createCopy();
  223. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  224. Icon getIcon (bool isOpen = false) const;
  225. bool isIconCrossedOut() const;
  226. Project& project;
  227. ValueTree state;
  228. private:
  229. Item& operator= (const Item&);
  230. bool belongsToModule;
  231. };
  232. Item getMainGroup();
  233. void findAllImageItems (OwnedArray<Item>& items);
  234. //==============================================================================
  235. ValueTree getExporters();
  236. int getNumExporters();
  237. ProjectExporter* createExporter (int index);
  238. void addNewExporter (const String& exporterName);
  239. void createExporterForCurrentPlatform();
  240. struct ExporterIterator
  241. {
  242. ExporterIterator (Project& project);
  243. ~ExporterIterator();
  244. bool next();
  245. ProjectExporter& operator*() const { return *exporter; }
  246. ProjectExporter* operator->() const { return exporter.get(); }
  247. ScopedPointer<ProjectExporter> exporter;
  248. int index;
  249. private:
  250. Project& project;
  251. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  252. };
  253. //==============================================================================
  254. struct ConfigFlag
  255. {
  256. String symbol, description, sourceModuleID;
  257. ValueWithDefault value;
  258. };
  259. ValueWithDefault getConfigFlag (const String& name);
  260. bool isConfigFlagEnabled (const String& name, bool defaultIsEnabled = false) const;
  261. //==============================================================================
  262. EnabledModuleList& getModules();
  263. //==============================================================================
  264. String getFileTemplate (const String& templateName);
  265. //==============================================================================
  266. PropertiesFile& getStoredProperties() const;
  267. //==============================================================================
  268. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  269. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  270. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  271. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  272. void valueTreeParentChanged (ValueTree&) override;
  273. //==============================================================================
  274. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  275. UndoManager* getUndoManager() const { return nullptr; }
  276. //==============================================================================
  277. static const char* projectFileExtension;
  278. //==============================================================================
  279. bool hasProjectBeenModified();
  280. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  281. //==============================================================================
  282. String getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& baseTargetFolder);
  283. //==============================================================================
  284. bool isCurrentlySaving() const noexcept { return isSaving; }
  285. bool shouldWaitAfterSaving = false;
  286. String specifiedExporterToSave = {};
  287. //==============================================================================
  288. bool isTemporaryProject() const noexcept { return tempDirectory != File(); }
  289. File getTemporaryDirectory() const noexcept { return tempDirectory; }
  290. void setTemporaryDirectory (const File&) noexcept;
  291. void setOpenInIDEAfterSaving (bool open) noexcept { openInIDEAfterSaving = open; }
  292. bool shouldOpenInIDEAfterSaving() const noexcept { return openInIDEAfterSaving; }
  293. //==============================================================================
  294. bool shouldSendGUIBuilderAnalyticsEvent() noexcept;
  295. //==============================================================================
  296. CompileEngineSettings& getCompileEngineSettings() { return compileEngineSettings; }
  297. private:
  298. ValueTree projectRoot { Ids::JUCERPROJECT };
  299. ValueWithDefault projectNameValue, projectUIDValue, projectTypeValue, versionValue, bundleIdentifierValue, companyNameValue, companyCopyrightValue,
  300. companyWebsiteValue, companyEmailValue, displaySplashScreenValue, reportAppUsageValue, splashScreenColourValue, cppStandardValue,
  301. headerSearchPathsValue, preprocessorDefsValue, userNotesValue, maxBinaryFileSizeValue, includeBinaryDataInAppConfigValue, binaryDataNamespaceValue;
  302. ValueWithDefault pluginFormatsValue, pluginNameValue, pluginDescriptionValue, pluginManufacturerValue, pluginManufacturerCodeValue,
  303. pluginCodeValue, pluginChannelConfigsValue, pluginCharacteristicsValue, pluginAUExportPrefixValue, pluginAAXIdentifierValue,
  304. pluginAUMainTypeValue, pluginRTASCategoryValue, pluginVSTCategoryValue, pluginVST3CategoryValue, pluginAAXCategoryValue;
  305. //==============================================================================
  306. CompileEngineSettings compileEngineSettings { projectRoot };
  307. //==============================================================================
  308. bool shouldWriteLegacyPluginFormatSettings = false;
  309. bool shouldWriteLegacyPluginCharacteristicsSettings = false;
  310. static Array<Identifier> getLegacyPluginFormatIdentifiers() noexcept;
  311. static Array<Identifier> getLegacyPluginCharacteristicsIdentifiers() noexcept;
  312. void writeLegacyPluginFormatSettings();
  313. void writeLegacyPluginCharacteristicsSettings();
  314. void coalescePluginFormatValues();
  315. void coalescePluginCharacteristicsValues();
  316. void updatePluginCategories();
  317. //==============================================================================
  318. File tempDirectory = {};
  319. bool openInIDEAfterSaving = false;
  320. void askUserWhereToSaveProject();
  321. void moveTemporaryDirectory (const File&);
  322. bool saveProjectRootToFile();
  323. //==============================================================================
  324. bool hasSentGUIBuilderAnalyticsEvent = false;
  325. //==============================================================================
  326. friend class Item;
  327. ScopedPointer<EnabledModuleList> enabledModulesList;
  328. bool isSaving = false;
  329. Time modificationTime;
  330. StringPairArray parsedPreprocessorDefs;
  331. //==============================================================================
  332. void initialiseProjectValues();
  333. void initialiseMainGroup();
  334. void initialiseAudioPluginValues();
  335. bool setCppVersionFromOldExporterSettings();
  336. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  337. //==============================================================================
  338. void updateTitle();
  339. void updateProjectSettings();
  340. ValueTree getConfigurations() const;
  341. ValueTree getConfigNode();
  342. void updateOldStyleConfigList();
  343. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  344. void removeDefunctExporters();
  345. void updateOldModulePaths();
  346. void warnAboutOldProjucerVersion();
  347. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  348. };