From 3c5adac3feef83d30cba159e97715a3df726c0b0 Mon Sep 17 00:00:00 2001 From: sr55 Date: Thu, 25 Apr 2019 15:16:33 +0100 Subject: [PATCH] WinGui: Refactor Filters View Model - (Deinterlace and Detection Filters) --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../Filters/DeinterlaceFilterItem.cs | 235 ++++++++++++++++++ .../ViewModelItems/Filters/DetelecineItem.cs | 3 - .../ViewModels/FiltersViewModel.cs | 234 ++--------------- win/CS/HandBrakeWPF/Views/FiltersView.xaml | 26 +- 5 files changed, 264 insertions(+), 235 deletions(-) create mode 100644 win/CS/HandBrakeWPF/ViewModelItems/Filters/DeinterlaceFilterItem.cs diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 2a5c2d21c..e85382f0e 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -272,6 +272,7 @@ + diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeinterlaceFilterItem.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeinterlaceFilterItem.cs new file mode 100644 index 000000000..8fd5ebb77 --- /dev/null +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DeinterlaceFilterItem.cs @@ -0,0 +1,235 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the DeinterlaceFilter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.ViewModelItems.Filters +{ + using System.Collections.Generic; + using System.ComponentModel; + using System.Linq; + + using Caliburn.Micro; + + using HandBrake.Interop.Interop; + using HandBrake.Interop.Interop.HbLib; + using HandBrake.Interop.Interop.Model.Encoding; + + using HandBrakeWPF.Services.Encode.Model; + using HandBrakeWPF.Services.Presets.Model; + using HandBrakeWPF.Services.Scan.Model; + using HandBrakeWPF.Utilities; + + using Action = System.Action; + + public class DeinterlaceFilterItem : PropertyChangedBase + { + private readonly Action triggerTabChanged; + + public DeinterlaceFilterItem(EncodeTask currentTask, Action triggerTabChanged) + { + this.triggerTabChanged = triggerTabChanged; + this.CurrentTask = currentTask; + this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; + } + + public EncodeTask CurrentTask { get; private set; } + + public IEnumerable DeinterlaceFilterOptions => EnumHelper.GetEnumList(); + + public IEnumerable CombDetectPresets => EnumHelper.GetEnumList(); + + public bool IsDeinterlaceEnabled => this.CurrentTask.DeinterlaceFilter != DeinterlaceFilter.Off; + + public bool ShowCustomDeinterlace => this.IsDeinterlaceEnabled && this.CurrentTask.DeinterlacePreset?.ShortName == "custom"; + + public bool ShowCombDetectCustom => this.SelectedCombDetectPreset == CombDetect.Custom; + + public DeinterlaceFilter SelectedDeinterlaceFilter + { + get + { + return this.CurrentTask.DeinterlaceFilter; + } + + set + { + if (value == this.CurrentTask.DeinterlaceFilter) + { + return; + } + + this.CurrentTask.DeinterlaceFilter = value; + + this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); + this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); + this.NotifyOfPropertyChange(() => this.DeinterlacePresets); + this.NotifyOfPropertyChange(() => this.IsDeinterlaceEnabled); + + if (!this.DeinterlacePresets.Contains(this.SelectedDeInterlacePreset)) + { + this.SelectedDeInterlacePreset = this.DeinterlacePresets.FirstOrDefault(p => p.ShortName == "default"); + } + + this.triggerTabChanged(); + } + } + + public IEnumerable DeinterlacePresets + { + get + { + switch (this.SelectedDeinterlaceFilter) + { + case DeinterlaceFilter.Yadif: + return new BindingList(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DEINTERLACE)); + case DeinterlaceFilter.Decomb: + return new BindingList(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DECOMB)); + default: + return new BindingList(); + } + } + } + + public HBPresetTune SelectedDeInterlacePreset + { + get + { + return this.CurrentTask.DeinterlacePreset; + } + + set + { + this.CurrentTask.DeinterlacePreset = value; + this.NotifyOfPropertyChange(() => this.SelectedDeInterlacePreset); + + if (value?.ShortName == "custom") this.CustomDeinterlaceSettings = string.Empty; + + // Show / Hide the Custom Control + this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); + this.triggerTabChanged(); + } + } + + public CombDetect SelectedCombDetectPreset + { + get + { + return this.CurrentTask.CombDetect; + } + + set + { + this.CurrentTask.CombDetect = value; + this.NotifyOfPropertyChange(() => this.SelectedCombDetectPreset); + + if (value != CombDetect.Custom) this.CustomCombDetect = string.Empty; + + // Show / Hide the Custom Control + this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); + this.triggerTabChanged(); + } + } + + /// + /// Gets or sets the custom comb detect. + /// + public string CustomCombDetect + { + get + { + return this.CurrentTask.CustomCombDetect; + } + + set + { + this.CurrentTask.CustomCombDetect = value; + this.NotifyOfPropertyChange(() => this.CustomCombDetect); + this.triggerTabChanged(); + } + } + + public string CustomDeinterlaceSettings + { + get + { + return this.CurrentTask.CustomDeinterlaceSettings; + } + + set + { + this.CurrentTask.CustomDeinterlaceSettings = value; + this.NotifyOfPropertyChange(() => this.CustomDeinterlaceSettings); + this.triggerTabChanged(); + } + } + + public void SetPreset(Preset preset, EncodeTask task) + { + this.CurrentTask = task; + + if (preset == null) + { + this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; + return; + } + + this.SelectedDeinterlaceFilter = preset.Task.DeinterlaceFilter; + this.SelectedDeInterlacePreset = preset.Task.DeinterlacePreset; + this.CustomDeinterlaceSettings = preset.Task.CustomDeinterlaceSettings; + this.SelectedCombDetectPreset = preset.Task.CombDetect; + this.CustomCombDetect = preset.Task.CustomCombDetect; + } + + public void UpdateTask(EncodeTask task) + { + this.CurrentTask = task; + this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); + this.NotifyOfPropertyChange(() => this.SelectedDeInterlacePreset); + this.NotifyOfPropertyChange(() => this.CustomDeinterlaceSettings); + this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); + this.NotifyOfPropertyChange(() => this.CustomCombDetect); + this.NotifyOfPropertyChange(() => this.SelectedCombDetectPreset); + this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); + } + + public bool MatchesPreset(Preset preset) + { + if (preset.Task.DeinterlaceFilter != this.SelectedDeinterlaceFilter) + { + return false; + } + + if (preset.Task.DeinterlacePreset != this.SelectedDeInterlacePreset) + { + return false; + } + + if (preset.Task.CustomDeinterlaceSettings != this.CustomDeinterlaceSettings) + { + return false; + } + + if (preset.Task.CombDetect != this.SelectedCombDetectPreset) + { + return false; + } + + if ((preset.Task.CustomCombDetect ?? string.Empty) != (this.CustomCombDetect ?? string.Empty)) + { + return false; + } + + return true; + } + + public void SetSource(Source source, Title title, Preset preset, EncodeTask task) + { + this.CurrentTask = task; + } + } +} diff --git a/win/CS/HandBrakeWPF/ViewModelItems/Filters/DetelecineItem.cs b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DetelecineItem.cs index 755edd536..8bf775dbc 100644 --- a/win/CS/HandBrakeWPF/ViewModelItems/Filters/DetelecineItem.cs +++ b/win/CS/HandBrakeWPF/ViewModelItems/Filters/DetelecineItem.cs @@ -34,9 +34,6 @@ namespace HandBrakeWPF.ViewModelItems.Filters public EncodeTask CurrentTask { get; private set; } - - public DetelecineItem DetelecineFilter { get; set; } - public Detelecine SelectedDetelecine { get diff --git a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs index 171d29a29..50d4a2d1f 100644 --- a/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/FiltersViewModel.cs @@ -39,8 +39,6 @@ namespace HandBrakeWPF.ViewModels /// public class FiltersViewModel : ViewModelBase, IFiltersViewModel { - private DeinterlaceFilter deinterlaceFilter; - #region Constructors and Destructors /// @@ -56,11 +54,11 @@ namespace HandBrakeWPF.ViewModels { this.CurrentTask = new EncodeTask(); this.DeblockValue = 4; // OFF - this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; - + this.SharpenFilter = new SharpenItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.DenoiseFilter = new DenoiseItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); this.DetelecineFilter = new DetelecineItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); + this.DeinterlaceFilter = new DeinterlaceFilterItem(this.CurrentTask, () => this.OnTabStatusChanged(null)); } #endregion @@ -122,167 +120,14 @@ namespace HandBrakeWPF.ViewModels } } - #region Interlace Detection - - /// - /// Comb Detection Presets - /// - public IEnumerable CombDetectPresets - { - get - { - return EnumHelper.GetEnumList(); - } - } - - /// - /// Show the CombDetect Custom Box. - /// - public bool ShowCombDetectCustom => this.SelectedCombDetectPreset == CombDetect.Custom; - - /// - /// 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); - - if (value != CombDetect.Custom) this.CustomCombDetect = string.Empty; - - // Show / Hide the Custom Control - this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); - this.OnTabStatusChanged(null); - } - } - - /// - /// Gets or sets the custom comb detect. - /// - public string CustomCombDetect - { - get - { - return this.CurrentTask.CustomCombDetect; - } - - set - { - this.CurrentTask.CustomCombDetect = value; - this.NotifyOfPropertyChange(() => this.CustomCombDetect); - this.OnTabStatusChanged(null); - } - } - - #endregion - - #region Deinterlace and Decomb - - public IEnumerable DeinterlaceFilterOptions => EnumHelper.GetEnumList(); - - public DeinterlaceFilter SelectedDeinterlaceFilter - { - get - { - return this.deinterlaceFilter; - } - - set - { - if (value == this.deinterlaceFilter) - { - return; - } - - this.deinterlaceFilter = value; - this.CurrentTask.DeinterlaceFilter = value; - - this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); - this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); - this.NotifyOfPropertyChange(() => this.DeinterlacePresets); - this.NotifyOfPropertyChange(() => this.IsDeinterlaceEnabled); - - if (!this.DeinterlacePresets.Contains(this.SelectedDeInterlacePreset)) - { - this.SelectedDeInterlacePreset = this.DeinterlacePresets.FirstOrDefault(p => p.ShortName == "default"); - } - - this.OnTabStatusChanged(null); - } - } - - public IEnumerable DeinterlacePresets - { - get - { - switch (this.SelectedDeinterlaceFilter) - { - case DeinterlaceFilter.Yadif: - return new BindingList(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DEINTERLACE)); - case DeinterlaceFilter.Decomb: - return new BindingList(HandBrakeFilterHelpers.GetFilterPresets((int)hb_filter_ids.HB_FILTER_DECOMB)); - default: - return new BindingList(); - } - } - } - - public HBPresetTune SelectedDeInterlacePreset - { - get - { - return this.CurrentTask.DeinterlacePreset; - } - set - { - this.CurrentTask.DeinterlacePreset = value; - this.NotifyOfPropertyChange(() => this.SelectedDeInterlacePreset); - - if (value?.ShortName == "custom") this.CustomDeinterlaceSettings = string.Empty; - - // Show / Hide the Custom Control - this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); - this.OnTabStatusChanged(null); - } - } - - public bool IsDeinterlaceEnabled => this.CurrentTask.DeinterlaceFilter != DeinterlaceFilter.Off; - - public bool ShowCustomDeinterlace => this.IsDeinterlaceEnabled && this.CurrentTask.DeinterlacePreset?.ShortName == "custom"; - - /// - /// Gets or sets CustomDecomb. - /// - public string CustomDeinterlaceSettings - { - get - { - return this.CurrentTask.CustomDeinterlaceSettings; - } - - set - { - this.CurrentTask.CustomDeinterlaceSettings = value; - this.NotifyOfPropertyChange(() => this.CustomDeinterlaceSettings); - this.OnTabStatusChanged(null); - } - } + public DenoiseItem DenoiseFilter { get; set; } - #endregion + public SharpenItem SharpenFilter { get; set; } public DetelecineItem DetelecineFilter { get; set; } - public DenoiseItem DenoiseFilter { get; set; } - - public SharpenItem SharpenFilter { get; set; } + public DeinterlaceFilterItem DeinterlaceFilter { get; set; } /// /// The rotation options. @@ -325,21 +170,6 @@ namespace HandBrakeWPF.ViewModels } } - #region Sharpen Filter - - public IEnumerable SharpenOptions - { - get - { - return EnumHelper.GetEnumList(); - } - } - - public object SharpenPresets { get; set; } - - public object SharpenTunes { get; set; } - - #endregion #endregion @@ -361,10 +191,7 @@ namespace HandBrakeWPF.ViewModels if (preset != null) { // Properties - this.SelectedDeinterlaceFilter = preset.Task.DeinterlaceFilter; - this.SelectedDeInterlacePreset = preset.Task.DeinterlacePreset; - - this.SelectedCombDetectPreset = preset.Task.CombDetect; + this.Grayscale = preset.Task.Grayscale; this.DeblockValue = preset.Task.Deblock == 0 ? 4 : preset.Task.Deblock; @@ -372,18 +199,14 @@ namespace HandBrakeWPF.ViewModels this.SharpenFilter.SetPreset(preset, task); this.DenoiseFilter.SetPreset(preset, task); this.DetelecineFilter.SetPreset(preset, task); - - // Custom Values - this.CustomDeinterlaceSettings = preset.Task.CustomDeinterlaceSettings; - this.CustomCombDetect = preset.Task.CustomCombDetect; - + this.DeinterlaceFilter.SetPreset(preset, task); + this.SelectedRotation = preset.Task.Rotation; this.FlipVideo = preset.Task.FlipVideo; } else { // Default everything to off - this.SelectedDeinterlaceFilter = DeinterlaceFilter.Off; this.Grayscale = false; this.DeblockValue = 0; @@ -401,65 +224,37 @@ namespace HandBrakeWPF.ViewModels public void UpdateTask(EncodeTask task) { this.CurrentTask = task; - this.NotifyOfPropertyChange(() => this.SelectedDeinterlaceFilter); - this.NotifyOfPropertyChange(() => this.SelectedDeInterlacePreset); this.NotifyOfPropertyChange(() => this.Grayscale); this.NotifyOfPropertyChange(() => this.DeblockValue); - this.NotifyOfPropertyChange(() => this.SelectedCombDetectPreset); + this.NotifyOfPropertyChange(() => this.FlipVideo); this.NotifyOfPropertyChange(() => this.SelectedRotation); - this.NotifyOfPropertyChange(() => this.CustomDeinterlaceSettings); - this.NotifyOfPropertyChange(() => this.CustomCombDetect); - - this.NotifyOfPropertyChange(() => this.ShowCustomDeinterlace); - this.NotifyOfPropertyChange(() => this.ShowCombDetectCustom); - this.SharpenFilter.UpdateTask(task); this.DenoiseFilter.UpdateTask(task); this.DetelecineFilter.UpdateTask(task); + this.DeinterlaceFilter.UpdateTask(task); } public bool MatchesPreset(Preset preset) { - - if (preset.Task.DeinterlaceFilter != this.SelectedDeinterlaceFilter) - { - return false; - } - - if (preset.Task.DeinterlacePreset != this.SelectedDeInterlacePreset) - { - return false; - } - - if (preset.Task.CustomDeinterlaceSettings != this.CustomDeinterlaceSettings) - { - return false; - } - - if (preset.Task.CombDetect != this.SelectedCombDetectPreset) - { - return false; - } - - if ((preset.Task.CustomCombDetect ?? string.Empty) != (this.CustomCombDetect ?? string.Empty)) + if (!this.DenoiseFilter.MatchesPreset(preset)) { return false; } - if (!this.DenoiseFilter.MatchesPreset(preset)) + if (!this.SharpenFilter.MatchesPreset(preset)) { return false; } - if (!this.SharpenFilter.MatchesPreset(preset)) + if (!this.DetelecineFilter.MatchesPreset(preset)) { return false; } - if (!this.DetelecineFilter.MatchesPreset(preset)) + if (!this.DeinterlaceFilter.MatchesPreset(preset)) { return false; } @@ -510,6 +305,7 @@ namespace HandBrakeWPF.ViewModels this.SharpenFilter.SetSource(source, title, preset, task); this.DenoiseFilter.SetSource(source, title, preset, task); this.DetelecineFilter.SetSource(source, title, preset, task); + this.DeinterlaceFilter.SetSource(source, title, preset, task); } #endregion diff --git a/win/CS/HandBrakeWPF/Views/FiltersView.xaml b/win/CS/HandBrakeWPF/Views/FiltersView.xaml index 8379c6eb6..a311900eb 100644 --- a/win/CS/HandBrakeWPF/Views/FiltersView.xaml +++ b/win/CS/HandBrakeWPF/Views/FiltersView.xaml @@ -61,33 +61,33 @@ - - - + + - - - + - - + + -- 2.40.0