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.

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