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.

497 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 shouldBeCompiled() const;
  218. Value getShouldCompileValue();
  219. bool shouldBeAddedToBinaryResources() const;
  220. Value getShouldAddToBinaryResourcesValue();
  221. bool shouldBeAddedToXcodeResources() const;
  222. Value getShouldAddToXcodeResourcesValue();
  223. Value getShouldInhibitWarningsValue();
  224. bool shouldInhibitWarnings() const;
  225. bool isModuleCode() const;
  226. Value getCompilerFlagSchemeValue();
  227. String getCompilerFlagSchemeString() const;
  228. void setCompilerFlagScheme (const String&);
  229. void clearCurrentCompilerFlagScheme();
  230. //==============================================================================
  231. bool canContain (const Item& child) const;
  232. int getNumChildren() const { return state.getNumChildren(); }
  233. Item getChild (int index) const { return Item (project, state.getChild (index), belongsToModule); }
  234. Item addNewSubGroup (const String& name, int insertIndex);
  235. Item getOrCreateSubGroup (const String& name);
  236. void addChild (const Item& newChild, int insertIndex);
  237. bool addFileAtIndex (const File& file, int insertIndex, bool shouldCompile);
  238. bool addFileRetainingSortOrder (const File& file, bool shouldCompile);
  239. void addFileUnchecked (const File& file, int insertIndex, bool shouldCompile);
  240. bool addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile);
  241. void removeItemFromProject();
  242. void sortAlphabetically (bool keepGroupsAtStart, bool recursive);
  243. Item findItemForFile (const File& file) const;
  244. bool containsChildForFile (const RelativePath& file) const;
  245. Item getParent() const;
  246. Item createCopy();
  247. UndoManager* getUndoManager() const { return project.getUndoManagerFor (state); }
  248. Icon getIcon (bool isOpen = false) const;
  249. bool isIconCrossedOut() const;
  250. bool needsSaving() const noexcept;
  251. Project& project;
  252. ValueTree state;
  253. private:
  254. Item& operator= (const Item&);
  255. bool belongsToModule;
  256. };
  257. Item getMainGroup();
  258. void findAllImageItems (OwnedArray<Item>& items);
  259. //==============================================================================
  260. ValueTree getExporters();
  261. int getNumExporters();
  262. ProjectExporter* createExporter (int index);
  263. void addNewExporter (const String& exporterName);
  264. void createExporterForCurrentPlatform();
  265. struct ExporterIterator
  266. {
  267. ExporterIterator (Project& project);
  268. ~ExporterIterator();
  269. bool next();
  270. ProjectExporter& operator*() const { return *exporter; }
  271. ProjectExporter* operator->() const { return exporter.get(); }
  272. std::unique_ptr<ProjectExporter> exporter;
  273. int index;
  274. private:
  275. Project& project;
  276. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ExporterIterator)
  277. };
  278. //==============================================================================
  279. struct ConfigFlag
  280. {
  281. String symbol, description, sourceModuleID;
  282. ValueWithDefault value;
  283. };
  284. ValueWithDefault getConfigFlag (const String& name);
  285. bool isConfigFlagEnabled (const String& name, bool defaultIsEnabled = false) const;
  286. //==============================================================================
  287. EnabledModuleList& getEnabledModules();
  288. AvailableModuleList& getExporterPathsModuleList();
  289. void rescanExporterPathModules (bool async = false);
  290. std::pair<String, File> getModuleWithID (const String&);
  291. //==============================================================================
  292. String getFileTemplate (const String& templateName);
  293. //==============================================================================
  294. PropertiesFile& getStoredProperties() const;
  295. //==============================================================================
  296. void valueTreePropertyChanged (ValueTree&, const Identifier&) override;
  297. void valueTreeChildAdded (ValueTree&, ValueTree&) override;
  298. void valueTreeChildRemoved (ValueTree&, ValueTree&, int) override;
  299. void valueTreeChildOrderChanged (ValueTree&, int, int) override;
  300. //==============================================================================
  301. UndoManager* getUndoManagerFor (const ValueTree&) const { return nullptr; }
  302. UndoManager* getUndoManager() const { return nullptr; }
  303. //==============================================================================
  304. static const char* projectFileExtension;
  305. //==============================================================================
  306. bool hasProjectBeenModified();
  307. void updateModificationTime() { modificationTime = getFile().getLastModificationTime(); }
  308. //==============================================================================
  309. String getUniqueTargetFolderSuffixForExporter (const String& exporterName, const String& baseTargetFolder);
  310. //==============================================================================
  311. bool isCurrentlySaving() const noexcept { return isSaving; }
  312. bool shouldWaitAfterSaving = false;
  313. String specifiedExporterToSave = {};
  314. //==============================================================================
  315. bool isTemporaryProject() const noexcept { return tempDirectory != File(); }
  316. File getTemporaryDirectory() const noexcept { return tempDirectory; }
  317. void setTemporaryDirectory (const File&) noexcept;
  318. void setOpenInIDEAfterSaving (bool open) noexcept { openInIDEAfterSaving = open; }
  319. bool shouldOpenInIDEAfterSaving() const noexcept { return openInIDEAfterSaving; }
  320. //==============================================================================
  321. bool shouldSendGUIBuilderAnalyticsEvent() noexcept;
  322. //==============================================================================
  323. CompileEngineSettings& getCompileEngineSettings() { return *compileEngineSettings; }
  324. private:
  325. ValueTree projectRoot { Ids::JUCERPROJECT };
  326. ValueWithDefault projectNameValue, projectUIDValue, projectLineFeedValue, projectTypeValue, versionValue, bundleIdentifierValue, companyNameValue,
  327. companyCopyrightValue, companyWebsiteValue, companyEmailValue, displaySplashScreenValue, reportAppUsageValue, splashScreenColourValue, cppStandardValue,
  328. headerSearchPathsValue, preprocessorDefsValue, userNotesValue, maxBinaryFileSizeValue, includeBinaryDataInJuceHeaderValue, binaryDataNamespaceValue,
  329. compilerFlagSchemesValue, postExportShellCommandPosixValue, postExportShellCommandWinValue;
  330. ValueWithDefault pluginFormatsValue, pluginNameValue, pluginDescriptionValue, pluginManufacturerValue, pluginManufacturerCodeValue,
  331. pluginCodeValue, pluginChannelConfigsValue, pluginCharacteristicsValue, pluginAUExportPrefixValue, pluginAAXIdentifierValue,
  332. pluginAUMainTypeValue, pluginAUSandboxSafeValue, pluginRTASCategoryValue, pluginVSTCategoryValue, pluginVST3CategoryValue, pluginAAXCategoryValue,
  333. pluginVSTNumMidiInputsValue, pluginVSTNumMidiOutputsValue;
  334. //==============================================================================
  335. std::unique_ptr<CompileEngineSettings> compileEngineSettings;
  336. std::unique_ptr<EnabledModuleList> enabledModuleList;
  337. std::unique_ptr<AvailableModuleList> exporterPathsModuleList;
  338. //==============================================================================
  339. bool shouldWriteLegacyPluginFormatSettings = false;
  340. bool shouldWriteLegacyPluginCharacteristicsSettings = false;
  341. static Array<Identifier> getLegacyPluginFormatIdentifiers() noexcept;
  342. static Array<Identifier> getLegacyPluginCharacteristicsIdentifiers() noexcept;
  343. void writeLegacyPluginFormatSettings();
  344. void writeLegacyPluginCharacteristicsSettings();
  345. void coalescePluginFormatValues();
  346. void coalescePluginCharacteristicsValues();
  347. void updatePluginCategories();
  348. //==============================================================================
  349. File tempDirectory = {};
  350. bool openInIDEAfterSaving = false;
  351. void askUserWhereToSaveProject();
  352. void moveTemporaryDirectory (const File&);
  353. bool saveProjectRootToFile();
  354. //==============================================================================
  355. bool hasSentGUIBuilderAnalyticsEvent = false;
  356. //==============================================================================
  357. friend class Item;
  358. bool isSaving = false;
  359. Time modificationTime;
  360. StringPairArray parsedPreprocessorDefs;
  361. //==============================================================================
  362. void initialiseProjectValues();
  363. void initialiseMainGroup();
  364. void initialiseAudioPluginValues();
  365. bool setCppVersionFromOldExporterSettings();
  366. void createAudioPluginPropertyEditors (PropertyListBuilder& props);
  367. //==============================================================================
  368. void updateTitleDependencies();
  369. void updateCompanyNameDependencies();
  370. void updateProjectSettings();
  371. ValueTree getConfigurations() const;
  372. ValueTree getConfigNode();
  373. void updateOldStyleConfigList();
  374. void moveOldPropertyFromProjectToAllExporters (Identifier name);
  375. void removeDefunctExporters();
  376. void updateOldModulePaths();
  377. void warnAboutOldProjucerVersion();
  378. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Project)
  379. };