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.

498 lines
25KB

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