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.

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