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.

458 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 getAllAUMainTypeStrings() noexcept;
  138. static Array<var> getAllAUMainTypeVars() noexcept;
  139. Array<var> getDefaultAUMainTypes() const noexcept;
  140. static StringArray getAllVSTCategoryStrings() noexcept;
  141. Array<var> getDefaultVSTCategories() const noexcept;
  142. static StringArray getAllVST3CategoryStrings() noexcept;
  143. Array<var> getDefaultVST3Categories() const noexcept;
  144. static StringArray getAllAAXCategoryStrings() noexcept;
  145. static Array<var> getAllAAXCategoryVars() noexcept;
  146. Array<var> getDefaultAAXCategories() const noexcept;
  147. static StringArray getAllRTASCategoryStrings() noexcept;
  148. static Array<var> getAllRTASCategoryVars() noexcept;
  149. Array<var> getDefaultRTASCategories() const noexcept;
  150. String getAUMainTypeString() const noexcept;
  151. String getVSTCategoryString() const noexcept;
  152. String getVST3CategoryString() const noexcept;
  153. int getAAXCategory() const noexcept;
  154. int getRTASCategory() const noexcept;
  155. String getIAATypeCode();
  156. String getIAAPluginName();
  157. //==============================================================================
  158. bool isAUPluginHost();
  159. bool isVSTPluginHost();
  160. bool isVST3PluginHost();
  161. //==============================================================================
  162. bool shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept;
  163. static ProjectType::Target::Type getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix);
  164. //==============================================================================
  165. void updateDeprecatedProjectSettingsInteractively();
  166. //==============================================================================
  167. class Item
  168. {
  169. public:
  170. //==============================================================================
  171. Item (Project& project, const ValueTree& itemNode, bool isModuleCode);
  172. Item (const Item& other);
  173. static Item createGroup (Project& project, const String& name, const String& uid, bool isModuleCode);
  174. void initialiseMissingProperties();
  175. //==============================================================================
  176. bool isValid() const { return state.isValid(); }
  177. bool operator== (const Item& other) const { return state == other.state && &project == &other.project; }
  178. bool operator!= (const Item& other) const { return ! operator== (other); }
  179. //==============================================================================
  180. bool isFile() const;
  181. bool isGroup() const;
  182. bool isMainGroup() const;
  183. bool isImageFile() const;
  184. String getID() const;
  185. void setID (const String& newID);
  186. Item findItemWithID (const String& targetId) const; // (recursive search)
  187. String getImageFileID() const;
  188. Drawable* loadAsImageFile() const;
  189. //==============================================================================
  190. Value getNameValue();
  191. String getName() const;
  192. File getFile() const;
  193. String getFilePath() const;
  194. void setFile (const File& file);
  195. void setFile (const RelativePath& file);
  196. File determineGroupFolder() const;
  197. bool renameFile (const File& newFile);
  198. bool shouldBeAddedToTargetProject() const;
  199. bool shouldBeCompiled() const;
  200. Value getShouldCompileValue();
  201. bool shouldBeAddedToBinaryResources() const;
  202. Value getShouldAddToBinaryResourcesValue();
  203. bool shouldBeAddedToXcodeResources() const;
  204. Value getShouldAddToXcodeResourcesValue();
  205. Value getShouldInhibitWarningsValue();
  206. bool shouldInhibitWarnings() const;
  207. bool isModuleCode() const;
  208. //==============================================================================
  209. bool canContain (const Item& child) const;
  210. int getNumChildren() const { return state.getNumChildren(); }
  211. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  212. Item addNewSubGroup (const String& name, int insertIndex);
  213. Item getOrCreateSubGroup (const String& name);
  214. void addChild (const Item& newChild, int insertIndex);
  215. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  216. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  217. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  218. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  219. void removeItemFromProject();
  220. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  221. Item findItemForFile (const File& file) const;
  222. bool containsChildForFile (const RelativePath& file) const;
  223. Item getParent() const;
  224. Item createCopy();
  225. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  226. Icon getIcon (bool isOpen = false) const;
  227. bool isIconCrossedOut() const;
  228. Project& project;
  229. ValueTree state;
  230. private:
  231. Item& operator= (const Item&);
  232. bool belongsToModule;
  233. };
  234. Item getMainGroup();
  235. void findAllImageItems (OwnedArray<Item>& items);
  236. //==============================================================================
  237. ValueTree getExporters();
  238. int getNumExporters();
  239. ProjectExporter* createExporter (int index);
  240. void addNewExporter (const String& exporterName);
  241. void createExporterForCurrentPlatform();
  242. struct ExporterIterator
  243. {
  244. ExporterIterator (Project& project);
  245. ~ExporterIterator();
  246. bool next();
  247. ProjectExporter& operator*() const { return *exporter; }
  248. ProjectExporter* operator->() const { return exporter.get(); }
  249. ScopedPointer<ProjectExporter> exporter;
  250. int index;
  251. private:
  252. Project& project;
  253. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  254. };
  255. //==============================================================================
  256. struct ConfigFlag
  257. {
  258. String symbol, description, sourceModuleID;
  259. ValueWithDefault value;
  260. };
  261. ValueWithDefault getConfigFlag (const String& name);
  262. bool isConfigFlagEnabled (const String& name, bool defaultIsEnabled = false) const;
  263. //==============================================================================
  264. EnabledModuleList& getModules();
  265. //==============================================================================
  266. String getFileTemplate (const String& templateName);
  267. //==============================================================================
  268. PropertiesFile& getStoredProperties() const;
  269. //==============================================================================
  270. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  271. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  272. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  273. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  274. void valueTreeParentChanged (ValueTree&) override;
  275. //==============================================================================
  276. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  277. UndoManager* getUndoManager() const { return nullptr; }
  278. //==============================================================================
  279. static const char* projectFileExtension;
  280. //==============================================================================
  281. bool hasProjectBeenModified();
  282. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  283. //==============================================================================
  284. String getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& baseTargetFolder);
  285. //==============================================================================
  286. bool isCurrentlySaving() const noexcept { return isSaving; }
  287. bool shouldWaitAfterSaving = false;
  288. String specifiedExporterToSave = {};
  289. //==============================================================================
  290. bool isTemporaryProject() const noexcept { return tempDirectory != File(); }
  291. File getTemporaryDirectory() const noexcept { return tempDirectory; }
  292. void setTemporaryDirectory (const File&) noexcept;
  293. void setOpenInIDEAfterSaving (bool open) noexcept { openInIDEAfterSaving = open; }
  294. bool shouldOpenInIDEAfterSaving() const noexcept { return openInIDEAfterSaving; }
  295. //==============================================================================
  296. bool shouldSendGUIBuilderAnalyticsEvent() noexcept;
  297. //==============================================================================
  298. CompileEngineSettings& getCompileEngineSettings() { return compileEngineSettings; }
  299. private:
  300. ValueTree projectRoot { Ids::JUCERPROJECT };
  301. ValueWithDefault projectNameValue, projectUIDValue, projectTypeValue, versionValue, bundleIdentifierValue, companyNameValue, companyCopyrightValue,
  302. companyWebsiteValue, companyEmailValue, displaySplashScreenValue, reportAppUsageValue, splashScreenColourValue, cppStandardValue,
  303. headerSearchPathsValue, preprocessorDefsValue, userNotesValue, maxBinaryFileSizeValue, includeBinaryDataInAppConfigValue, binaryDataNamespaceValue;
  304. ValueWithDefault pluginFormatsValue, pluginNameValue, pluginDescriptionValue, pluginManufacturerValue, pluginManufacturerCodeValue,
  305. pluginCodeValue, pluginChannelConfigsValue, pluginCharacteristicsValue, pluginAUExportPrefixValue, pluginAAXIdentifierValue,
  306. pluginAUMainTypeValue, pluginRTASCategoryValue, pluginVSTCategoryValue, pluginVST3CategoryValue, pluginAAXCategoryValue;
  307. //==============================================================================
  308. CompileEngineSettings compileEngineSettings { projectRoot };
  309. //==============================================================================
  310. bool shouldWriteLegacyPluginFormatSettings = false;
  311. bool shouldWriteLegacyPluginCharacteristicsSettings = false;
  312. static Array<Identifier> getLegacyPluginFormatIdentifiers() noexcept;
  313. static Array<Identifier> getLegacyPluginCharacteristicsIdentifiers() noexcept;
  314. void writeLegacyPluginFormatSettings();
  315. void writeLegacyPluginCharacteristicsSettings();
  316. void coalescePluginFormatValues();
  317. void coalescePluginCharacteristicsValues();
  318. void updatePluginCategories();
  319. //==============================================================================
  320. File tempDirectory = {};
  321. bool openInIDEAfterSaving = false;
  322. void askUserWhereToSaveProject();
  323. void moveTemporaryDirectory (const File&);
  324. bool saveProjectRootToFile();
  325. //==============================================================================
  326. bool hasSentGUIBuilderAnalyticsEvent = false;
  327. //==============================================================================
  328. friend class Item;
  329. ScopedPointer<EnabledModuleList> enabledModulesList;
  330. bool isSaving = false;
  331. Time modificationTime;
  332. StringPairArray parsedPreprocessorDefs;
  333. //==============================================================================
  334. void initialiseProjectValues();
  335. void initialiseMainGroup();
  336. void initialiseAudioPluginValues();
  337. bool setCppVersionFromOldExporterSettings();
  338. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  339. //==============================================================================
  340. void updateTitle();
  341. void updateProjectSettings();
  342. ValueTree getConfigurations() const;
  343. ValueTree getConfigNode();
  344. void updateOldStyleConfigList();
  345. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  346. void removeDefunctExporters();
  347. void updateOldModulePaths();
  348. void warnAboutOldProjucerVersion();
  349. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  350. };