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