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.

471 lines
23KB

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