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.

1357 lines
48KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../jucer_Headers.h"
  18. #include "jucer_Project.h"
  19. #include "../Project Saving/jucer_ProjectExporter.h"
  20. #include "../Project Saving/jucer_ProjectSaver.h"
  21. #include "../Application/jucer_OpenDocumentManager.h"
  22. #include "../Application/jucer_Application.h"
  23. namespace
  24. {
  25. String makeValid4CC (const String& seed)
  26. {
  27. String s (CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx");
  28. return s.substring (0, 1).toUpperCase()
  29. + s.substring (1, 4).toLowerCase();
  30. }
  31. }
  32. //==============================================================================
  33. Project::Project (const File& f)
  34. : FileBasedDocument (projectFileExtension,
  35. String ("*") + projectFileExtension,
  36. "Choose a Jucer project to load",
  37. "Save Jucer project"),
  38. projectRoot (Ids::JUCERPROJECT),
  39. isSaving (false)
  40. {
  41. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  42. setFile (f);
  43. removeDefunctExporters();
  44. updateOldModulePaths();
  45. setMissingDefaultValues();
  46. setChangedFlag (false);
  47. projectRoot.addListener (this);
  48. modificationTime = getFile().getLastModificationTime();
  49. }
  50. Project::~Project()
  51. {
  52. projectRoot.removeListener (this);
  53. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  54. }
  55. const char* Project::projectFileExtension = ".jucer";
  56. //==============================================================================
  57. void Project::setTitle (const String& newTitle)
  58. {
  59. projectRoot.setProperty (Ids::name, newTitle, getUndoManagerFor (projectRoot));
  60. getMainGroup().getNameValue() = newTitle;
  61. }
  62. String Project::getTitle() const
  63. {
  64. return projectRoot.getChildWithName (Ids::MAINGROUP) [Ids::name];
  65. }
  66. String Project::getDocumentTitle()
  67. {
  68. return getTitle();
  69. }
  70. void Project::updateProjectSettings()
  71. {
  72. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  73. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  74. }
  75. void Project::setMissingDefaultValues()
  76. {
  77. if (! projectRoot.hasProperty (Ids::ID))
  78. projectRoot.setProperty (Ids::ID, createAlphaNumericUID(), nullptr);
  79. // Create main file group if missing
  80. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  81. {
  82. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  83. projectRoot.addChild (mainGroup.state, 0, 0);
  84. }
  85. getMainGroup().initialiseMissingProperties();
  86. if (getDocumentTitle().isEmpty())
  87. setTitle ("JUCE Project");
  88. if (! projectRoot.hasProperty (Ids::projectType))
  89. getProjectTypeValue() = ProjectType_GUIApp::getTypeName();
  90. if (! projectRoot.hasProperty (Ids::version))
  91. getVersionValue() = "1.0.0";
  92. updateOldStyleConfigList();
  93. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  94. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  95. if (getProjectType().isAudioPlugin())
  96. setMissingAudioPluginDefaultValues();
  97. getModules().sortAlphabetically();
  98. if (getBundleIdentifier().toString().isEmpty())
  99. getBundleIdentifier() = getDefaultBundleIdentifier();
  100. if (shouldIncludeBinaryInAppConfig() == var())
  101. shouldIncludeBinaryInAppConfig() = true;
  102. ProjucerApplication::getApp().updateNewlyOpenedProject (*this);
  103. }
  104. void Project::updateDeprecatedProjectSettingsInteractively()
  105. {
  106. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  107. for (Project::ExporterIterator exporter (*this); exporter.next();)
  108. exporter->updateDeprecatedProjectSettingsInteractively();
  109. }
  110. void Project::setMissingAudioPluginDefaultValues()
  111. {
  112. const String sanitisedProjectName (CodeHelpers::makeValidIdentifier (getTitle(), false, true, false));
  113. setValueIfVoid (getShouldBuildVSTAsValue(), true);
  114. setValueIfVoid (getShouldBuildVST3AsValue(), false);
  115. setValueIfVoid (getShouldBuildAUAsValue(), true);
  116. setValueIfVoid (getShouldBuildAUv3AsValue(), false);
  117. setValueIfVoid (getShouldBuildRTASAsValue(), false);
  118. setValueIfVoid (getShouldBuildAAXAsValue(), false);
  119. setValueIfVoid (getShouldBuildStandalonePluginAsValue(), false);
  120. setValueIfVoid (getPluginName(), getTitle());
  121. setValueIfVoid (getPluginDesc(), getTitle());
  122. setValueIfVoid (getPluginManufacturer(), "yourcompany");
  123. setValueIfVoid (getPluginManufacturerCode(), "Manu");
  124. setValueIfVoid (getPluginCode(), makeValid4CC (getProjectUID() + getProjectUID()));
  125. setValueIfVoid (getPluginChannelConfigs(), String());
  126. setValueIfVoid (getPluginIsSynth(), false);
  127. setValueIfVoid (getPluginWantsMidiInput(), false);
  128. setValueIfVoid (getPluginProducesMidiOut(), false);
  129. setValueIfVoid (getPluginIsMidiEffectPlugin(), false);
  130. setValueIfVoid (getPluginEditorNeedsKeyFocus(), false);
  131. setValueIfVoid (getPluginAUExportPrefix(), sanitisedProjectName + "AU");
  132. setValueIfVoid (getPluginRTASCategory(), String());
  133. setValueIfVoid (getBundleIdentifier(), getDefaultBundleIdentifier());
  134. setValueIfVoid (getAAXIdentifier(), getDefaultAAXIdentifier());
  135. setValueIfVoid (getPluginAAXCategory(), "AAX_ePlugInCategory_Dynamics");
  136. }
  137. void Project::updateOldStyleConfigList()
  138. {
  139. ValueTree deprecatedConfigsList (projectRoot.getChildWithName (Ids::CONFIGURATIONS));
  140. if (deprecatedConfigsList.isValid())
  141. {
  142. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  143. for (Project::ExporterIterator exporter (*this); exporter.next();)
  144. {
  145. if (exporter->getNumConfigurations() == 0)
  146. {
  147. ValueTree newConfigs (deprecatedConfigsList.createCopy());
  148. if (! exporter->isXcode())
  149. {
  150. for (int j = newConfigs.getNumChildren(); --j >= 0;)
  151. {
  152. ValueTree config (newConfigs.getChild(j));
  153. config.removeProperty (Ids::osxSDK, nullptr);
  154. config.removeProperty (Ids::osxCompatibility, nullptr);
  155. config.removeProperty (Ids::osxArchitecture, nullptr);
  156. }
  157. }
  158. exporter->settings.addChild (newConfigs, 0, nullptr);
  159. }
  160. }
  161. }
  162. }
  163. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  164. {
  165. if (projectRoot.hasProperty (name))
  166. {
  167. for (Project::ExporterIterator exporter (*this); exporter.next();)
  168. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  169. projectRoot.removeProperty (name, nullptr);
  170. }
  171. }
  172. void Project::removeDefunctExporters()
  173. {
  174. ValueTree exporters (projectRoot.getChildWithName (Ids::EXPORTFORMATS));
  175. for (;;)
  176. {
  177. ValueTree oldVC6Exporter (exporters.getChildWithName ("MSVC6"));
  178. ValueTree oldAndroidAntExporter (exporters.getChildWithName ("ANDROID"));
  179. if (oldVC6Exporter.isValid())
  180. exporters.removeChild (oldVC6Exporter, nullptr);
  181. else if (oldAndroidAntExporter.isValid())
  182. {
  183. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  184. TRANS("Android Ant Exporter"),
  185. TRANS("The Android Ant Exporter is deprecated. The exporter will be removed from this project."));
  186. exporters.removeChild (oldAndroidAntExporter, nullptr);
  187. }
  188. else
  189. break;
  190. }
  191. }
  192. void Project::updateOldModulePaths()
  193. {
  194. for (Project::ExporterIterator exporter (*this); exporter.next();)
  195. exporter->updateOldModulePaths();
  196. }
  197. //==============================================================================
  198. static int getVersionElement (StringRef v, int index)
  199. {
  200. StringArray parts;
  201. parts.addTokens (v, "., ", StringRef());
  202. return parts [parts.size() - index - 1].getIntValue();
  203. }
  204. static int getJuceVersion (const String& v)
  205. {
  206. return getVersionElement (v, 2) * 100000
  207. + getVersionElement (v, 1) * 1000
  208. + getVersionElement (v, 0);
  209. }
  210. static int getBuiltJuceVersion()
  211. {
  212. return JUCE_MAJOR_VERSION * 100000
  213. + JUCE_MINOR_VERSION * 1000
  214. + JUCE_BUILDNUMBER;
  215. }
  216. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  217. {
  218. for (int i = modules.size(); --i >= 0;)
  219. {
  220. const ModuleDescription* m = modules.getUnchecked(i);
  221. if (m->getID().startsWith ("juce_")
  222. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  223. return true;
  224. }
  225. return false;
  226. }
  227. void Project::warnAboutOldProjucerVersion()
  228. {
  229. ModuleList available;
  230. available.scanAllKnownFolders (*this);
  231. if (isAnyModuleNewerThanProjucer (available.modules))
  232. {
  233. if (ProjucerApplication::getApp().isRunningCommandLine)
  234. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  235. else
  236. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  237. "Projucer",
  238. "This version of the Projucer is out-of-date!"
  239. "\n\n"
  240. "Always make sure that you're running the very latest version, "
  241. "preferably compiled directly from the JUCE repository that you're working with!");
  242. }
  243. }
  244. //==============================================================================
  245. static File lastDocumentOpened;
  246. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  247. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  248. static void registerRecentFile (const File& file)
  249. {
  250. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  251. getAppSettings().recentFiles.addFile (file);
  252. getAppSettings().flush();
  253. }
  254. //==============================================================================
  255. Result Project::loadDocument (const File& file)
  256. {
  257. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  258. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  259. return Result::fail ("Not a valid Jucer project!");
  260. ValueTree newTree (ValueTree::fromXml (*xml));
  261. if (! newTree.hasType (Ids::JUCERPROJECT))
  262. return Result::fail ("The document contains errors and couldn't be parsed!");
  263. registerRecentFile (file);
  264. enabledModulesList = nullptr;
  265. projectRoot = newTree;
  266. removeDefunctExporters();
  267. setMissingDefaultValues();
  268. updateOldModulePaths();
  269. setChangedFlag (false);
  270. if (! ProjucerApplication::getApp().isRunningCommandLine)
  271. warnAboutOldProjucerVersion();
  272. return Result::ok();
  273. }
  274. Result Project::saveDocument (const File& file)
  275. {
  276. return saveProject (file, false);
  277. }
  278. Result Project::saveProject (const File& file, bool isCommandLineApp)
  279. {
  280. if (isSaving)
  281. return Result::ok();
  282. updateProjectSettings();
  283. sanitiseConfigFlags();
  284. if (! isCommandLineApp)
  285. registerRecentFile (file);
  286. const ScopedValueSetter<bool> vs (isSaving, true, false);
  287. ProjectSaver saver (*this, file);
  288. return saver.save (! isCommandLineApp);
  289. }
  290. Result Project::saveResourcesOnly (const File& file)
  291. {
  292. ProjectSaver saver (*this, file);
  293. return saver.saveResourcesOnly();
  294. }
  295. //==============================================================================
  296. void Project::valueTreePropertyChanged (ValueTree&, const Identifier& property)
  297. {
  298. if (property == Ids::projectType)
  299. setMissingDefaultValues();
  300. changed();
  301. }
  302. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  303. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  304. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  305. void Project::valueTreeParentChanged (ValueTree&) {}
  306. //==============================================================================
  307. bool Project::hasProjectBeenModified()
  308. {
  309. Time newModificationTime = getFile().getLastModificationTime();
  310. Time oldModificationTime = modificationTime;
  311. modificationTime = newModificationTime;
  312. return (newModificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  313. }
  314. //==============================================================================
  315. File Project::resolveFilename (String filename) const
  316. {
  317. if (filename.isEmpty())
  318. return File();
  319. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  320. if (FileHelpers::isAbsolutePath (filename))
  321. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  322. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  323. }
  324. String Project::getRelativePathForFile (const File& file) const
  325. {
  326. String filename (file.getFullPathName());
  327. File relativePathBase (getFile().getParentDirectory());
  328. String p1 (relativePathBase.getFullPathName());
  329. String p2 (file.getFullPathName());
  330. while (p1.startsWithChar (File::separator))
  331. p1 = p1.substring (1);
  332. while (p2.startsWithChar (File::separator))
  333. p2 = p2.substring (1);
  334. if (p1.upToFirstOccurrenceOf (File::separatorString, true, false)
  335. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false)))
  336. {
  337. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  338. }
  339. return filename;
  340. }
  341. //==============================================================================
  342. const ProjectType& Project::getProjectType() const
  343. {
  344. if (const ProjectType* type = ProjectType::findType (getProjectTypeString()))
  345. return *type;
  346. const ProjectType* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  347. jassert (guiType != nullptr);
  348. return *guiType;
  349. }
  350. bool Project::shouldBuildTargetType (ProjectType::Target::Type targetType) const noexcept
  351. {
  352. const ProjectType& projectType = getProjectType();
  353. if (! projectType.supportsTargetType (targetType))
  354. return false;
  355. switch (targetType)
  356. {
  357. case ProjectType::Target::VSTPlugIn:
  358. return shouldBuildVST();
  359. case ProjectType::Target::VST3PlugIn:
  360. return shouldBuildVST3();
  361. case ProjectType::Target::AAXPlugIn:
  362. return shouldBuildAAX();
  363. case ProjectType::Target::RTASPlugIn:
  364. return shouldBuildRTAS();
  365. case ProjectType::Target::AudioUnitPlugIn:
  366. return shouldBuildAU();
  367. case ProjectType::Target::AudioUnitv3PlugIn:
  368. return shouldBuildAUv3();
  369. case ProjectType::Target::StandalonePlugIn:
  370. return shouldBuildStandalonePlugin();
  371. case ProjectType::Target::AggregateTarget:
  372. case ProjectType::Target::SharedCodeTarget:
  373. return projectType.isAudioPlugin();
  374. case ProjectType::Target::unspecified:
  375. return false;
  376. default:
  377. break;
  378. }
  379. return true;
  380. }
  381. ProjectType::Target::Type Project::getTargetTypeFromFilePath (const File& file, bool returnSharedTargetIfNoValidSuffix)
  382. {
  383. if (LibraryModule::CompileUnit::hasSuffix (file, "_AU")) return ProjectType::Target::AudioUnitPlugIn;
  384. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AUv3")) return ProjectType::Target::AudioUnitv3PlugIn;
  385. else if (LibraryModule::CompileUnit::hasSuffix (file, "_AAX")) return ProjectType::Target::AAXPlugIn;
  386. else if (LibraryModule::CompileUnit::hasSuffix (file, "_RTAS")) return ProjectType::Target::RTASPlugIn;
  387. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST2")) return ProjectType::Target::VSTPlugIn;
  388. else if (LibraryModule::CompileUnit::hasSuffix (file, "_VST3")) return ProjectType::Target::VST3PlugIn;
  389. else if (LibraryModule::CompileUnit::hasSuffix (file, "_Standalone")) return ProjectType::Target::StandalonePlugIn;
  390. return (returnSharedTargetIfNoValidSuffix ? ProjectType::Target::SharedCodeTarget : ProjectType::Target::unspecified);
  391. }
  392. const char* ProjectType::Target::getName() const noexcept
  393. {
  394. switch (type)
  395. {
  396. case GUIApp: return "App";
  397. case ConsoleApp: return "ConsoleApp";
  398. case StaticLibrary: return "Static Library";
  399. case DynamicLibrary: return "Dynamic Library";
  400. case VSTPlugIn: return "VST";
  401. case VST3PlugIn: return "VST3";
  402. case AudioUnitPlugIn: return "AU";
  403. case StandalonePlugIn: return "Standalone Plugin";
  404. case AudioUnitv3PlugIn: return "AUv3 AppExtension";
  405. case AAXPlugIn: return "AAX";
  406. case RTASPlugIn: return "RTAS";
  407. case SharedCodeTarget: return "Shared Code";
  408. case AggregateTarget: return "All";
  409. default: return "undefined";
  410. }
  411. }
  412. ProjectType::Target::TargetFileType ProjectType::Target::getTargetFileType() const noexcept
  413. {
  414. switch (type)
  415. {
  416. case GUIApp: return executable;
  417. case ConsoleApp: return executable;
  418. case StaticLibrary: return staticLibrary;
  419. case DynamicLibrary: return sharedLibraryOrDLL;
  420. case VSTPlugIn: return pluginBundle;
  421. case VST3PlugIn: return pluginBundle;
  422. case AudioUnitPlugIn: return pluginBundle;
  423. case StandalonePlugIn: return executable;
  424. case AudioUnitv3PlugIn: return macOSAppex;
  425. case AAXPlugIn: return pluginBundle;
  426. case RTASPlugIn: return pluginBundle;
  427. case SharedCodeTarget: return staticLibrary;
  428. default:
  429. break;
  430. }
  431. return unknown;
  432. }
  433. //==============================================================================
  434. void Project::createPropertyEditors (PropertyListBuilder& props)
  435. {
  436. props.add (new TextPropertyComponent (getProjectNameValue(), "Project Name", 256, false),
  437. "The name of the project.");
  438. props.add (new TextPropertyComponent (getVersionValue(), "Project Version", 16, false),
  439. "The project's version number, This should be in the format major.minor.point[.point]");
  440. props.add (new TextPropertyComponent (getCompanyName(), "Company Name", 256, false),
  441. "Your company name, which will be added to the properties of the binary where possible");
  442. props.add (new TextPropertyComponent (getCompanyWebsite(), "Company Website", 256, false),
  443. "Your company website, which will be added to the properties of the binary where possible");
  444. props.add (new TextPropertyComponent (getCompanyEmail(), "Company E-mail", 256, false),
  445. "Your company e-mail, which will be added to the properties of the binary where possible");
  446. {
  447. StringArray projectTypeNames;
  448. Array<var> projectTypeCodes;
  449. const Array<ProjectType*>& types = ProjectType::getAllTypes();
  450. for (int i = 0; i < types.size(); ++i)
  451. {
  452. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  453. projectTypeCodes.add (types.getUnchecked(i)->getType());
  454. }
  455. props.add (new ChoicePropertyComponent (getProjectTypeValue(), "Project Type", projectTypeNames, projectTypeCodes));
  456. }
  457. props.add (new TextPropertyComponent (getBundleIdentifier(), "Bundle Identifier", 256, false),
  458. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  459. if (getProjectType().isAudioPlugin())
  460. createAudioPluginPropertyEditors (props);
  461. {
  462. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  463. StringArray maxSizeNames;
  464. Array<var> maxSizeCodes;
  465. maxSizeNames.add (TRANS("Default"));
  466. maxSizeCodes.add (var());
  467. maxSizeNames.add (String());
  468. maxSizeCodes.add (var());
  469. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  470. {
  471. const int sizeInBytes = maxSizes[i] * 1024;
  472. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  473. maxSizeCodes.add (sizeInBytes);
  474. }
  475. props.add (new ChoicePropertyComponent (getMaxBinaryFileSize(), "BinaryData.cpp size limit", maxSizeNames, maxSizeCodes),
  476. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  477. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  478. }
  479. props.add (new BooleanPropertyComponent (shouldIncludeBinaryInAppConfig(), "Include Binary",
  480. "Include BinaryData.h in the AppConfig.h file"));
  481. props.add (new TextPropertyComponent (binaryDataNamespace(), "BinaryData Namespace", 256, false),
  482. "The namespace containing the binary assests. If left empty this defaults to \"BinaryData\".");
  483. props.add (new TextPropertyComponent (getProjectPreprocessorDefs(), "Preprocessor definitions", 32768, true),
  484. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  485. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  486. props.add (new TextPropertyComponent (getProjectUserNotes(), "Notes", 32768, true),
  487. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  488. }
  489. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  490. {
  491. props.add (new BooleanPropertyComponent (getShouldBuildVSTAsValue(), "Build VST", "Enabled"),
  492. "Whether the project should produce a VST plugin.");
  493. props.add (new BooleanPropertyComponent (getShouldBuildVST3AsValue(), "Build VST3", "Enabled"),
  494. "Whether the project should produce a VST3 plugin.");
  495. props.add (new BooleanPropertyComponent (getShouldBuildAUAsValue(), "Build AudioUnit", "Enabled"),
  496. "Whether the project should produce an AudioUnit plugin.");
  497. props.add (new BooleanPropertyComponent (getShouldBuildAUv3AsValue(), "Build AudioUnit v3", "Enabled"),
  498. "Whether the project should produce an AudioUnit version 3 plugin.");
  499. props.add (new BooleanPropertyComponent (getShouldBuildRTASAsValue(), "Build RTAS", "Enabled"),
  500. "Whether the project should produce an RTAS plugin.");
  501. props.add (new BooleanPropertyComponent (getShouldBuildAAXAsValue(), "Build AAX", "Enabled"),
  502. "Whether the project should produce an AAX plugin.");
  503. props.add (new BooleanPropertyComponent (getShouldBuildStandalonePluginAsValue(), "Build Standalone Plug-In", "Enabled"),
  504. "Whether the project should produce a standalone version of your plugin.");
  505. props.add (new TextPropertyComponent (getPluginName(), "Plugin Name", 128, false),
  506. "The name of your plugin (keep it short!)");
  507. props.add (new TextPropertyComponent (getPluginDesc(), "Plugin Description", 256, false),
  508. "A short description of your plugin.");
  509. props.add (new TextPropertyComponent (getPluginManufacturer(), "Plugin Manufacturer", 256, false),
  510. "The name of your company (cannot be blank).");
  511. props.add (new TextPropertyComponent (getPluginManufacturerCode(), "Plugin Manufacturer Code", 4, false),
  512. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  513. props.add (new TextPropertyComponent (getPluginCode(), "Plugin Code", 4, false),
  514. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  515. props.add (new TextPropertyComponent (getPluginChannelConfigs(), "Plugin Channel Configurations", 1024, false),
  516. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  517. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  518. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  519. "this field empty and override the setPreferredBusArrangement method in your AudioProcessor.");
  520. props.add (new BooleanPropertyComponent (getPluginIsSynth(), "Plugin is a Synth", "Is a Synth"),
  521. "Enable this if you want your plugin to be treated as a synth or generator. It doesn't make much difference to the plugin itself, but some hosts treat synths differently to other plugins.");
  522. props.add (new BooleanPropertyComponent (getPluginWantsMidiInput(), "Plugin Midi Input", "Plugin wants midi input"),
  523. "Enable this if you want your plugin to accept midi messages.");
  524. props.add (new BooleanPropertyComponent (getPluginProducesMidiOut(), "Plugin Midi Output", "Plugin produces midi output"),
  525. "Enable this if your plugin is going to produce midi messages.");
  526. props.add (new BooleanPropertyComponent (getPluginIsMidiEffectPlugin(), "Midi Effect Plugin", "Plugin is a midi effect plugin"),
  527. "Enable this if your plugin only processes midi and no audio.");
  528. props.add (new BooleanPropertyComponent (getPluginEditorNeedsKeyFocus(), "Key Focus", "Plugin editor requires keyboard focus"),
  529. "Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  530. props.add (new TextPropertyComponent (getPluginAUExportPrefix(), "Plugin AU Export Prefix", 64, false),
  531. "A prefix for the names of exported entry-point functions that the component exposes - typically this will be a version of your plugin's name that can be used as part of a C++ token.");
  532. props.add (new TextPropertyComponent (getPluginAUMainType(), "Plugin AU Main Type", 128, false),
  533. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  534. props.add (new TextPropertyComponent (getPluginVSTCategory(), "VST Category", 64, false),
  535. "In a VST, this is the value that is set as JucePlugin_VSTCategory. Leave it blank unless you want to use a custom value.");
  536. props.add (new TextPropertyComponent (getPluginRTASCategory(), "Plugin RTAS Category", 64, false),
  537. "(Leave this blank if your plugin is a synth). This is one of the RTAS categories from FicPluginEnums.h, such as: ePlugInCategory_None, ePlugInCategory_EQ, ePlugInCategory_Dynamics, "
  538. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  539. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  540. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  541. props.add (new TextPropertyComponent (getPluginAAXCategory(), "Plugin AAX Category", 64, false),
  542. "This is one of the categories from the AAX_EPlugInCategory enum");
  543. props.add (new TextPropertyComponent (getAAXIdentifier(), "Plugin AAX Identifier", 256, false),
  544. "The value to use for the JucePlugin_AAXIdentifier setting");
  545. }
  546. //==============================================================================
  547. static StringArray getVersionSegments (const Project& p)
  548. {
  549. StringArray segments;
  550. segments.addTokens (p.getVersionString(), ",.", "");
  551. segments.trim();
  552. segments.removeEmptyStrings();
  553. return segments;
  554. }
  555. int Project::getVersionAsHexInteger() const
  556. {
  557. const StringArray segments (getVersionSegments (*this));
  558. int value = (segments[0].getIntValue() << 16)
  559. + (segments[1].getIntValue() << 8)
  560. + segments[2].getIntValue();
  561. if (segments.size() >= 4)
  562. value = (value << 8) + segments[3].getIntValue();
  563. return value;
  564. }
  565. String Project::getVersionAsHex() const
  566. {
  567. return "0x" + String::toHexString (getVersionAsHexInteger());
  568. }
  569. StringPairArray Project::getPreprocessorDefs() const
  570. {
  571. return parsePreprocessorDefs (projectRoot [Ids::defines]);
  572. }
  573. File Project::getBinaryDataCppFile (int index) const
  574. {
  575. const File cpp (getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"));
  576. if (index > 0)
  577. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  578. .withFileExtension (cpp.getFileExtension());
  579. return cpp;
  580. }
  581. Project::Item Project::getMainGroup()
  582. {
  583. return Item (*this, projectRoot.getChildWithName (Ids::MAINGROUP), false);
  584. }
  585. PropertiesFile& Project::getStoredProperties() const
  586. {
  587. return getAppSettings().getProjectProperties (getProjectUID());
  588. }
  589. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  590. {
  591. if (item.isImageFile())
  592. {
  593. found.add (new Project::Item (item));
  594. }
  595. else if (item.isGroup())
  596. {
  597. for (int i = 0; i < item.getNumChildren(); ++i)
  598. findImages (item.getChild (i), found);
  599. }
  600. }
  601. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  602. {
  603. findImages (getMainGroup(), items);
  604. }
  605. //==============================================================================
  606. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  607. : project (p), state (s), belongsToModule (isModuleCode)
  608. {
  609. }
  610. Project::Item::Item (const Item& other)
  611. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  612. {
  613. }
  614. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  615. String Project::Item::getID() const { return state [Ids::ID]; }
  616. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  617. Drawable* Project::Item::loadAsImageFile() const
  618. {
  619. return isValid() ? Drawable::createFromImageFile (getFile())
  620. : nullptr;
  621. }
  622. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  623. {
  624. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  625. group.setID (uid);
  626. group.initialiseMissingProperties();
  627. group.getNameValue() = name;
  628. return group;
  629. }
  630. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  631. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  632. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  633. bool Project::Item::isImageFile() const
  634. {
  635. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  636. || getFile().hasFileExtension ("svg"));
  637. }
  638. Project::Item Project::Item::findItemWithID (const String& targetId) const
  639. {
  640. if (state [Ids::ID] == targetId)
  641. return *this;
  642. if (isGroup())
  643. {
  644. for (int i = getNumChildren(); --i >= 0;)
  645. {
  646. Item found (getChild(i).findItemWithID (targetId));
  647. if (found.isValid())
  648. return found;
  649. }
  650. }
  651. return Item (project, ValueTree(), false);
  652. }
  653. bool Project::Item::canContain (const Item& child) const
  654. {
  655. if (isFile())
  656. return false;
  657. if (isGroup())
  658. return child.isFile() || child.isGroup();
  659. jassertfalse;
  660. return false;
  661. }
  662. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  663. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  664. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  665. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  666. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  667. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  668. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  669. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  670. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  671. bool Project::Item::isModuleCode() const { return belongsToModule; }
  672. String Project::Item::getFilePath() const
  673. {
  674. if (isFile())
  675. return state [Ids::file].toString();
  676. return String();
  677. }
  678. File Project::Item::getFile() const
  679. {
  680. if (isFile())
  681. return project.resolveFilename (state [Ids::file].toString());
  682. return File();
  683. }
  684. void Project::Item::setFile (const File& file)
  685. {
  686. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  687. jassert (getFile() == file);
  688. }
  689. void Project::Item::setFile (const RelativePath& file)
  690. {
  691. jassert (isFile());
  692. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  693. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  694. }
  695. bool Project::Item::renameFile (const File& newFile)
  696. {
  697. const File oldFile (getFile());
  698. if (oldFile.moveFileTo (newFile)
  699. || (newFile.exists() && ! oldFile.exists()))
  700. {
  701. setFile (newFile);
  702. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  703. return true;
  704. }
  705. return false;
  706. }
  707. bool Project::Item::containsChildForFile (const RelativePath& file) const
  708. {
  709. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  710. }
  711. Project::Item Project::Item::findItemForFile (const File& file) const
  712. {
  713. if (getFile() == file)
  714. return *this;
  715. if (isGroup())
  716. {
  717. for (int i = getNumChildren(); --i >= 0;)
  718. {
  719. Item found (getChild(i).findItemForFile (file));
  720. if (found.isValid())
  721. return found;
  722. }
  723. }
  724. return Item (project, ValueTree(), false);
  725. }
  726. File Project::Item::determineGroupFolder() const
  727. {
  728. jassert (isGroup());
  729. File f;
  730. for (int i = 0; i < getNumChildren(); ++i)
  731. {
  732. f = getChild(i).getFile();
  733. if (f.exists())
  734. return f.getParentDirectory();
  735. }
  736. Item parent (getParent());
  737. if (parent != *this)
  738. {
  739. f = parent.determineGroupFolder();
  740. if (f.getChildFile (getName()).isDirectory())
  741. f = f.getChildFile (getName());
  742. }
  743. else
  744. {
  745. f = project.getProjectFolder();
  746. if (f.getChildFile ("Source").isDirectory())
  747. f = f.getChildFile ("Source");
  748. }
  749. return f;
  750. }
  751. void Project::Item::initialiseMissingProperties()
  752. {
  753. if (! state.hasProperty (Ids::ID))
  754. setID (createAlphaNumericUID());
  755. if (isFile())
  756. {
  757. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  758. }
  759. else if (isGroup())
  760. {
  761. for (int i = getNumChildren(); --i >= 0;)
  762. getChild(i).initialiseMissingProperties();
  763. }
  764. }
  765. Value Project::Item::getNameValue()
  766. {
  767. return state.getPropertyAsValue (Ids::name, getUndoManager());
  768. }
  769. String Project::Item::getName() const
  770. {
  771. return state [Ids::name];
  772. }
  773. void Project::Item::addChild (const Item& newChild, int insertIndex)
  774. {
  775. state.addChild (newChild.state, insertIndex, getUndoManager());
  776. }
  777. void Project::Item::removeItemFromProject()
  778. {
  779. state.getParent().removeChild (state, getUndoManager());
  780. }
  781. Project::Item Project::Item::getParent() const
  782. {
  783. if (isMainGroup() || ! isGroup())
  784. return *this;
  785. return Item (project, state.getParent(), belongsToModule);
  786. }
  787. struct ItemSorter
  788. {
  789. static int compareElements (const ValueTree& first, const ValueTree& second)
  790. {
  791. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  792. }
  793. };
  794. struct ItemSorterWithGroupsAtStart
  795. {
  796. static int compareElements (const ValueTree& first, const ValueTree& second)
  797. {
  798. const bool firstIsGroup = first.hasType (Ids::GROUP);
  799. const bool secondIsGroup = second.hasType (Ids::GROUP);
  800. if (firstIsGroup == secondIsGroup)
  801. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  802. return firstIsGroup ? -1 : 1;
  803. }
  804. };
  805. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  806. {
  807. if (keepGroupsAtStart)
  808. {
  809. ItemSorterWithGroupsAtStart sorter;
  810. state.sort (sorter, undoManager, true);
  811. }
  812. else
  813. {
  814. ItemSorter sorter;
  815. state.sort (sorter, undoManager, true);
  816. }
  817. }
  818. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  819. {
  820. if (state.getNumChildren() == 0)
  821. return false;
  822. if (state.getNumChildren() == 1)
  823. return true;
  824. ValueTree stateCopy (state.createCopy());
  825. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  826. return stateCopy.isEquivalentTo (state);
  827. }
  828. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  829. {
  830. sortGroup (state, keepGroupsAtStart, getUndoManager());
  831. if (recursive)
  832. for (int i = getNumChildren(); --i >= 0;)
  833. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  834. }
  835. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  836. {
  837. for (int i = state.getNumChildren(); --i >= 0;)
  838. {
  839. const ValueTree child (state.getChild (i));
  840. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  841. return Item (project, child, belongsToModule);
  842. }
  843. return addNewSubGroup (name, -1);
  844. }
  845. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  846. {
  847. String newID (createGUID (getID() + name + String (getNumChildren())));
  848. int n = 0;
  849. while (project.getMainGroup().findItemWithID (newID).isValid())
  850. newID = createGUID (newID + String (++n));
  851. Item group (createGroup (project, name, newID, belongsToModule));
  852. jassert (canContain (group));
  853. addChild (group, insertIndex);
  854. return group;
  855. }
  856. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  857. {
  858. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  859. return false;
  860. if (file.isDirectory())
  861. {
  862. Item group (addNewSubGroup (file.getFileName(), insertIndex));
  863. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  864. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  865. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  866. }
  867. else if (file.existsAsFile())
  868. {
  869. if (! project.getMainGroup().findItemForFile (file).isValid())
  870. addFileUnchecked (file, insertIndex, shouldCompile);
  871. }
  872. else
  873. {
  874. jassertfalse;
  875. }
  876. return true;
  877. }
  878. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  879. {
  880. const bool wasSortedGroupsNotFirst = isGroupSorted (state, false);
  881. const bool wasSortedGroupsFirst = isGroupSorted (state, true);
  882. if (! addFileAtIndex (file, 0, shouldCompile))
  883. return false;
  884. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  885. sortAlphabetically (wasSortedGroupsFirst, false);
  886. return true;
  887. }
  888. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  889. {
  890. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  891. item.initialiseMissingProperties();
  892. item.getNameValue() = file.getFileName();
  893. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  894. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  895. if (canContain (item))
  896. {
  897. item.setFile (file);
  898. addChild (item, insertIndex);
  899. }
  900. }
  901. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  902. {
  903. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  904. item.initialiseMissingProperties();
  905. item.getNameValue() = file.getFileName();
  906. item.getShouldCompileValue() = shouldCompile;
  907. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  908. if (canContain (item))
  909. {
  910. item.setFile (file);
  911. addChild (item, insertIndex);
  912. return true;
  913. }
  914. return false;
  915. }
  916. Icon Project::Item::getIcon() const
  917. {
  918. const Icons& icons = getIcons();
  919. if (isFile())
  920. {
  921. if (isImageFile())
  922. return Icon (icons.imageDoc, Colours::blue);
  923. return Icon (icons.document, Colours::yellow);
  924. }
  925. if (isMainGroup())
  926. return Icon (icons.juceLogo, Colours::orange);
  927. return Icon (icons.folder, Colours::darkgrey);
  928. }
  929. bool Project::Item::isIconCrossedOut() const
  930. {
  931. return isFile()
  932. && ! (shouldBeCompiled()
  933. || shouldBeAddedToBinaryResources()
  934. || getFile().hasFileExtension (headerFileExtensions));
  935. }
  936. //==============================================================================
  937. ValueTree Project::getConfigNode()
  938. {
  939. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  940. }
  941. const char* const Project::configFlagDefault = "default";
  942. const char* const Project::configFlagEnabled = "enabled";
  943. const char* const Project::configFlagDisabled = "disabled";
  944. Value Project::getConfigFlag (const String& name)
  945. {
  946. ValueTree configNode (getConfigNode());
  947. Value v (configNode.getPropertyAsValue (name, getUndoManagerFor (configNode)));
  948. if (v.getValue().toString().isEmpty())
  949. v = configFlagDefault;
  950. return v;
  951. }
  952. bool Project::isConfigFlagEnabled (const String& name) const
  953. {
  954. return projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name) == configFlagEnabled;
  955. }
  956. void Project::sanitiseConfigFlags()
  957. {
  958. ValueTree configNode (getConfigNode());
  959. for (int i = configNode.getNumProperties(); --i >= 0;)
  960. {
  961. const var value (configNode [configNode.getPropertyName(i)]);
  962. if (value != configFlagEnabled && value != configFlagDisabled)
  963. configNode.removeProperty (configNode.getPropertyName(i), getUndoManagerFor (configNode));
  964. }
  965. }
  966. //==============================================================================
  967. String Project::getPluginRTASCategoryCode()
  968. {
  969. if (static_cast<bool> (getPluginIsSynth().getValue()))
  970. return "ePlugInCategory_SWGenerators";
  971. String s (getPluginRTASCategory().toString());
  972. if (s.isEmpty())
  973. s = "ePlugInCategory_None";
  974. return s;
  975. }
  976. String Project::getAUMainTypeString()
  977. {
  978. String s (getPluginAUMainType().toString());
  979. if (s.isEmpty())
  980. {
  981. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  982. // Use aumi instead.
  983. if (getPluginIsMidiEffectPlugin().getValue()) s = "'aumi'";
  984. else if (getPluginIsSynth().getValue()) s = "kAudioUnitType_MusicDevice";
  985. else if (getPluginWantsMidiInput().getValue()) s = "kAudioUnitType_MusicEffect";
  986. else s = "kAudioUnitType_Effect";
  987. }
  988. return s;
  989. }
  990. String Project::getAUMainTypeCode()
  991. {
  992. String s (getPluginAUMainType().toString());
  993. if (s.isEmpty())
  994. {
  995. if (getPluginIsMidiEffectPlugin().getValue()) s = "aumi";
  996. else if (getPluginIsSynth().getValue()) s = "aumu";
  997. else if (getPluginWantsMidiInput().getValue()) s = "aumf";
  998. else s = "aufx";
  999. }
  1000. return s;
  1001. }
  1002. String Project::getPluginVSTCategoryString()
  1003. {
  1004. String s (getPluginVSTCategory().toString().trim());
  1005. if (s.isEmpty())
  1006. s = static_cast<bool> (getPluginIsSynth().getValue()) ? "kPlugCategSynth"
  1007. : "kPlugCategEffect";
  1008. return s;
  1009. }
  1010. bool Project::isAUPluginHost()
  1011. {
  1012. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  1013. }
  1014. bool Project::isVSTPluginHost()
  1015. {
  1016. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  1017. }
  1018. bool Project::isVST3PluginHost()
  1019. {
  1020. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  1021. }
  1022. //==============================================================================
  1023. EnabledModuleList& Project::getModules()
  1024. {
  1025. if (enabledModulesList == nullptr)
  1026. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  1027. return *enabledModulesList;
  1028. }
  1029. //==============================================================================
  1030. ValueTree Project::getExporters()
  1031. {
  1032. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  1033. }
  1034. int Project::getNumExporters()
  1035. {
  1036. return getExporters().getNumChildren();
  1037. }
  1038. ProjectExporter* Project::createExporter (int index)
  1039. {
  1040. jassert (index >= 0 && index < getNumExporters());
  1041. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  1042. }
  1043. void Project::addNewExporter (const String& exporterName)
  1044. {
  1045. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  1046. ValueTree exporters (getExporters());
  1047. exporters.addChild (exp->settings, -1, getUndoManagerFor (exporters));
  1048. }
  1049. void Project::createExporterForCurrentPlatform()
  1050. {
  1051. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  1052. }
  1053. //==============================================================================
  1054. String Project::getFileTemplate (const String& templateName)
  1055. {
  1056. int dataSize;
  1057. if (const char* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  1058. return String::fromUTF8 (data, dataSize);
  1059. jassertfalse;
  1060. return String();
  1061. }
  1062. //==============================================================================
  1063. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  1064. Project::ExporterIterator::~ExporterIterator() {}
  1065. bool Project::ExporterIterator::next()
  1066. {
  1067. if (++index >= project.getNumExporters())
  1068. return false;
  1069. exporter = project.createExporter (index);
  1070. if (exporter == nullptr)
  1071. {
  1072. jassertfalse; // corrupted project file?
  1073. return next();
  1074. }
  1075. return true;
  1076. }