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.

480 lines
24KB

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