// -------------------------------------------------------------------------------------------------------------------- // // This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. // // // The Filters View Model // // -------------------------------------------------------------------------------------------------------------------- namespace HandBrakeWPF.ViewModels { using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using Caliburn.Micro; using HandBrake.ApplicationServices.Interop.Model.Encoding; using HandBrakeWPF.Services.Interfaces; using HandBrakeWPF.Services.Presets.Model; using HandBrakeWPF.Services.Scan.Model; using HandBrakeWPF.Utilities; using HandBrakeWPF.ViewModels.Interfaces; using DenoisePreset = HandBrakeWPF.Services.Encode.Model.Models.DenoisePreset; using DenoiseTune = HandBrakeWPF.Services.Encode.Model.Models.DenoiseTune; using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask; /// /// The Filters View Model /// public class FiltersViewModel : ViewModelBase, IFiltersViewModel { private DeinterlaceFilter deinterlaceFilter; #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The window manager. /// /// /// The user Setting Service. /// public FiltersViewModel(IWindowManager windowManager, IUserSettingService userSettingService) { this.CurrentTask = new EncodeTask(); this.DeblockValue = 4; // OFF this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; } #endregion #region Properties /// /// Gets CurrentTask. /// public EncodeTask CurrentTask { get; private set; } /// /// Gets or sets CustomDecomb. /// public string CustomDecomb { get { return this.CurrentTask.CustomDecomb; } set { this.CurrentTask.CustomDecomb = value; this.NotifyOfPropertyChange(() => this.CustomDecomb); } } /// /// Gets or sets CustomDeinterlace. /// public string CustomDeinterlace { get { return this.CurrentTask.CustomDeinterlace; } set { this.CurrentTask.CustomDeinterlace = value; this.NotifyOfPropertyChange(() => this.CustomDeinterlace); } } /// /// Gets or sets CustomDenoise. /// public string CustomDenoise { get { return this.CurrentTask.CustomDenoise; } set { this.CurrentTask.CustomDenoise = value; this.NotifyOfPropertyChange(() => this.CustomDenoise); } } /// /// Gets or sets CustomDetelecine. /// public string CustomDetelecine { get { return this.CurrentTask.CustomDetelecine; } set { this.CurrentTask.CustomDetelecine = value; this.NotifyOfPropertyChange(() => this.CustomDetelecine); } } /// /// Gets DeInterlaceOptions. /// public IEnumerable DeInterlaceOptions { get { return EnumHelper.GetEnumList(); } } /// /// Gets DeblockText. /// public string DeblockText { get { return this.DeblockValue == 4 ? "Off" : this.DeblockValue.ToString(CultureInfo.InvariantCulture); } } /// /// Gets or sets DeblockValue. /// public int DeblockValue { get { return this.CurrentTask.Deblock; } set { this.CurrentTask.Deblock = value; this.NotifyOfPropertyChange(() => this.DeblockValue); this.NotifyOfPropertyChange(() => this.DeblockText); } } /// /// Gets DecombOptions. /// public IEnumerable DecombOptions { get { return EnumHelper.GetEnumList(); } } /// /// Gets DenoiseOptions. /// public IEnumerable DenoiseOptions { get { return EnumHelper.GetEnumList(); } } /// /// Gets DetelecineOptions. /// public IEnumerable DetelecineOptions { get { return EnumHelper.GetEnumList(); } } /// /// Gets DeinterlaceFilterOptions. /// public IEnumerable DeinterlaceFilterOptions { get { return EnumHelper.GetEnumList(); } } /// /// Comb Detection Presets /// public IEnumerable CombDetectPresets { get { return EnumHelper.GetEnumList(); } } /// /// Gets or sets a value indicating whether Grayscale. /// public bool Grayscale { get { return this.CurrentTask.Grayscale; } set { this.CurrentTask.Grayscale = value; this.NotifyOfPropertyChange(() => this.Grayscale); } } /// /// Gets or sets SelectedDeInterlace. /// public Deinterlace SelectedDeInterlace { get { return this.CurrentTask.Deinterlace; } set { this.CurrentTask.Deinterlace = value; this.NotifyOfPropertyChange(() => this.SelectedDeInterlace); if (value != Deinterlace.Custom) this.CustomDeinterlace = string.Empty; // Show / Hide the Custom Control this.NotifyOfPropertyChange(() => this.ShowDecombCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceDecombCustom); } } /// /// Gets or sets the selected comb detect preset. /// public CombDetect SelectedCombDetectPreset { get { return this.CurrentTask.CombDetect; } set { this.CurrentTask.CombDetect = value; this.NotifyOfPropertyChange(() => this.SelectedCombDetectPreset); // Show / Hide the Custom Control this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); } } /// /// Show the CombDetect Custom Box. /// public bool ShowCombDetectCustom { get { return this.SelectedCombDetectPreset == CombDetect.Custom; } } /// /// Gets or sets the custom comb detect. /// public string CustomCombDetect { get { return this.CurrentTask.CustomCombDetect; } set { this.CurrentTask.CustomCombDetect = value; this.NotifyOfPropertyChange(() => this.CustomCombDetect); } } /// /// Gets or sets SelectedDecomb. /// public Decomb SelectedDecomb { get { return this.CurrentTask.Decomb; } set { this.CurrentTask.Decomb = value; this.NotifyOfPropertyChange(() => this.SelectedDecomb); if (value != Decomb.Custom) this.CustomDecomb = string.Empty; // Show / Hide the Custom Control this.NotifyOfPropertyChange(() => this.ShowDecombCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceDecombCustom); } } /// /// Gets or sets SelectedDenoise. /// public Denoise SelectedDenoise { get { return this.CurrentTask.Denoise; } set { this.CurrentTask.Denoise = value; this.NotifyOfPropertyChange(() => this.SelectedDenoise); // Show / Hide the Custom Control this.ShowDenoiseCustom = this.CurrentTask.DenoisePreset == DenoisePreset.Custom; this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); this.SelectedDenoisePreset = this.CurrentTask.Denoise == Denoise.hqdn3d ? DenoisePreset.Weak : DenoisePreset.Ultralight; // Default so we don't have an invalid preset. this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); } } /// /// Gets or sets SelectedDetelecine. /// public Detelecine SelectedDetelecine { get { return this.CurrentTask.Detelecine; } set { this.CurrentTask.Detelecine = value; this.NotifyOfPropertyChange(() => this.SelectedDetelecine); // Show / Hide the Custom Control this.ShowDetelecineCustom = this.CurrentTask.Detelecine == Detelecine.Custom; if (value != Detelecine.Custom) this.CustomDetelecine = string.Empty; this.NotifyOfPropertyChange(() => this.ShowDetelecineCustom); } } /// /// Gets or sets a value indicating whether ShowDecombCustom. /// public bool ShowDecombCustom => this.SelectedDeinterlaceFilter == DeinterlaceFilter.Decomb && this.SelectedDecomb == Decomb.Custom; /// /// Gets or sets a value indicating whether ShowDeinterlaceDecombCustom. /// public bool ShowDeinterlaceDecombCustom => (this.SelectedDeinterlaceFilter == DeinterlaceFilter.Decomb && this.SelectedDecomb == Decomb.Custom) || (this.SelectedDeinterlaceFilter == DeinterlaceFilter.Yadif && this.SelectedDeInterlace == Deinterlace.Custom); /// /// Gets or sets a value indicating whether ShowDelelecineCustom. /// public bool ShowDeinterlaceCustom => this.SelectedDeinterlaceFilter == DeinterlaceFilter.Yadif && this.SelectedDeInterlace == Deinterlace.Custom; /// /// Gets or sets a value indicating whether ShowDenoiseCustom. /// public bool ShowDenoiseCustom { get; set; } /// /// Gets or sets a value indicating whether ShowDetelecineCustom. /// public bool ShowDetelecineCustom { get; set; } /// /// Gets or sets the selected deinterlace filter mode. /// public DeinterlaceFilter SelectedDeinterlaceFilter { get { return this.deinterlaceFilter; } set { if (value == this.deinterlaceFilter) { return; } this.deinterlaceFilter = value; this.CurrentTask.DeinterlaceFilter = value; if (this.deinterlaceFilter == DeinterlaceFilter.Yadif) { this.IsDeinterlaceMode = true; this.IsDecombMode = false; } else if (this.deinterlaceFilter == DeinterlaceFilter.Decomb) { this.IsDeinterlaceMode = false; this.IsDecombMode = true; } else { this.IsDeinterlaceMode = false; this.IsDecombMode = false; } this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); this.NotifyOfPropertyChange(() => this.IsDeinterlaceMode); this.NotifyOfPropertyChange(() => this.IsDecombMode); this.NotifyOfPropertyChange(() => this.IsDeinterlaceDecomb); this.NotifyOfPropertyChange(() => this.ShowDecombCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceCustom); this.NotifyOfPropertyChange(() => this.ShowDeinterlaceDecombCustom); } } /// /// Gets or sets a value indicating whether is deinterlace mode. /// public bool IsDeinterlaceMode { get; set; } /// /// Gets or sets a value indicating whether is decomb mode. /// public bool IsDecombMode { get; set; } /// /// Gets or sets a value indicating whether is deinterlace or decomb mode. /// public bool IsDeinterlaceDecomb => this.SelectedDeinterlaceFilter != DeinterlaceFilter.Off; /// /// Gets or sets the selected denoise tune. /// public DenoiseTune SelectedDenoiseTune { get { return this.CurrentTask.DenoiseTune; } set { this.CurrentTask.DenoiseTune = value; this.NotifyOfPropertyChange(() => this.SelectedDenoiseTune); } } /// /// Gets or sets the selected denoise preset. /// public DenoisePreset SelectedDenoisePreset { get { return this.CurrentTask.DenoisePreset; } set { this.CurrentTask.DenoisePreset = value; this.NotifyOfPropertyChange(() => this.SelectedDenoisePreset); // Show / Hide the Custom Control this.ShowDenoiseCustom = this.CurrentTask.DenoisePreset == DenoisePreset.Custom; if (value != DenoisePreset.Custom) this.CustomDenoise = string.Empty; this.NotifyOfPropertyChange(() => this.ShowDenoiseCustom); this.NotifyOfPropertyChange(() => this.ShowDenoiseOptions); this.NotifyOfPropertyChange(() => this.ShowDenoiseTune); } } /// /// Gets the denoise presets. /// public IEnumerable DenoisePresets { get { return EnumHelper.GetEnumList(); } } /// /// Gets the denoise tunes. /// public IEnumerable DenoiseTunes { get { return EnumHelper.GetEnumList(); } } /// /// Gets a value indicating whether show denoise options. /// public bool ShowDenoiseOptions { get { return this.SelectedDenoise != Denoise.Off; } } /// /// Gets a value indicating whether show denoise tune. /// public bool ShowDenoiseTune { get { return this.SelectedDenoise == Denoise.NLMeans && this.SelectedDenoisePreset != DenoisePreset.Custom; } } /// /// The rotation options. /// public BindingList RotationOptions => new BindingList { 0, 90, 180, 270 }; /// /// Selected Rotation. /// public int SelectedRotation { get { return this.CurrentTask.Rotation; } set { this.CurrentTask.Rotation = value; this.NotifyOfPropertyChange(() => this.SelectedRotation); } } /// /// Flip the Video /// public bool FlipVideo { get { return this.CurrentTask.FlipVideo; } set { this.CurrentTask.FlipVideo = value; this.NotifyOfPropertyChange(() => this.FlipVideo); } } #endregion #region Implemented Interfaces #region ITabInterface /// /// Setup this tab for the specified preset. /// /// /// The preset. /// /// /// The task. /// public void SetPreset(Preset preset, EncodeTask task) { this.CurrentTask = task; if (preset != null) { // Properties this.SelectedDenoise = preset.Task.Denoise; this.SelectedDetelecine = preset.Task.Detelecine; this.SelectedDecomb = preset.Task.Decomb; this.SelectedDeInterlace = preset.Task.Deinterlace; if (preset.Task.DeinterlaceFilter == DeinterlaceFilter.Yadif) { this.SelectedDeinterlaceFilter = DeinterlaceFilter.Yadif; } else if (preset.Task.DeinterlaceFilter == DeinterlaceFilter.Decomb) { this.SelectedDeinterlaceFilter = DeinterlaceFilter.Decomb; } else { this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; } this.SelectedCombDetectPreset = preset.Task.CombDetect; this.Grayscale = preset.Task.Grayscale; this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; this.SelectedDenoisePreset = preset.Task.DenoisePreset; this.SelectedDenoiseTune = preset.Task.DenoiseTune; // Custom Values this.CustomDecomb = preset.Task.CustomDecomb; this.CustomDeinterlace = preset.Task.CustomDeinterlace; this.CustomDetelecine = preset.Task.CustomDetelecine; this.CustomDenoise = preset.Task.CustomDenoise; this.SelectedRotation = preset.Task.Rotation; this.FlipVideo = preset.Task.FlipVideo; } else { // Default everything to off this.SelectedDenoise = Denoise.Off; this.SelectedDecomb = Decomb.Default; this.SelectedDeInterlace = Deinterlace.Default; this.SelectedDetelecine = Detelecine.Off; this.Grayscale = false; this.DeblockValue = 0; this.SelectedRotation = 0; this.FlipVideo = false; } } /// /// Update all the UI controls based on the encode task passed in. /// /// /// The task. /// public void UpdateTask(EncodeTask task) { this.CurrentTask = task; this.NotifyOfPropertyChange(() => this.SelectedDenoise); this.NotifyOfPropertyChange(() => this.SelectedDecomb); this.NotifyOfPropertyChange(() => this.SelectedDeInterlace); this.NotifyOfPropertyChange(() => this.SelectedDetelecine); this.NotifyOfPropertyChange(() => this.Grayscale); this.NotifyOfPropertyChange(() => this.DeblockValue); this.NotifyOfPropertyChange(() => this.CustomDecomb); this.NotifyOfPropertyChange(() => this.CustomDeinterlace); this.NotifyOfPropertyChange(() => this.CustomDetelecine); this.NotifyOfPropertyChange(() => this.CustomDenoise); this.NotifyOfPropertyChange(() => this.IsDeinterlaceMode); this.NotifyOfPropertyChange(() => this.IsDecombMode); this.NotifyOfPropertyChange(() => this.IsDeinterlaceDecomb); this.NotifyOfPropertyChange(() => this.FlipVideo); this.NotifyOfPropertyChange(() => this.SelectedRotation); } /// /// Setup this window for a new source /// /// /// The source. /// /// /// The title. /// /// /// The preset. /// /// /// The task. /// public void SetSource(Source source, Title title, Preset preset, EncodeTask task) { this.CurrentTask = task; } #endregion #endregion } }