From fc3324c8fa6c0aaa37c89d8d0bf098092d705932 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 9 Apr 2016 14:46:54 +0100 Subject: WinGui: Use Mixdowns from LibHBand sanitise the choices. The GUI no longer shows invalid mixdowns. --- .../Converters/Audio/AudioMixdownConverter.cs | 61 ++++++++++++++++++ .../Converters/Audio/AudioMixdownListConverter.cs | 75 ++++++++++++++++++++++ .../HandBrakeWPF/Converters/EnumComboConverter.cs | 15 +---- 3 files changed, 137 insertions(+), 14 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs (limited to 'win/CS/HandBrakeWPF/Converters') diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs new file mode 100644 index 000000000..e1a371743 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs @@ -0,0 +1,61 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the AudioMixdownConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System.Globalization; + using System.Windows.Data; + using System; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + /// + /// The audio mixdown converter. + /// Handles conversion between HBMixdown and it's shortname. + /// + public class AudioMixdownConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string mixdown = value as string; + if (!string.IsNullOrEmpty(mixdown)) + { + return HandBrakeEncoderHelpers.GetMixdown(mixdown); + } + + return HandBrakeEncoderHelpers.GetMixdown("dpl2"); // Default + } + + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + HBMixdown mixdown = value as HBMixdown; + if (mixdown != null) + { + return mixdown.ShortName; + } + + return "none"; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs new file mode 100644 index 000000000..cad01f88a --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs @@ -0,0 +1,75 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the AudioMixdownListConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System.Globalization; + using System.Windows.Data; + using System; + using System.ComponentModel; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + using HandBrakeWPF.Services.Encode.Model.Models; + using HandBrakeWPF.Utilities; + + /// + /// The audio mixdown converter. + /// Returns the list of available mixdowns for the given track and encoder. + /// + public class AudioMixdownListConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + AudioTrack track = value as AudioTrack; + if (track != null && track.ScannedTrack != null) + { + HBAudioEncoder encoder = + HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(track.Encoder)); + + BindingList mixdowns = new BindingList(); + foreach (HBMixdown mixdown in HandBrakeEncoderHelpers.Mixdowns) + { + if (HandBrakeEncoderHelpers.MixdownIsSupported( + mixdown, + encoder, + track.ScannedTrack.ChannelLayout)) + { + mixdowns.Add(mixdown); + } + } + + return mixdowns; + } + + return value; + } + + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + + return value; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index a25cd1100..b803e1126 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -58,10 +58,6 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetEnumDisplayValues(typeof(VideoEncoder)); } - if (value is IEnumerable) - { - return EnumHelper.GetEnumDisplayValues(typeof(Mixdown)); - } if (value is IEnumerable) { return EnumHelper.GetEnumDisplayValues(typeof(PresetPictureSettingsMode)); @@ -103,12 +99,7 @@ namespace HandBrakeWPF.Converters if (targetType == typeof(VideoEncoder) || value.GetType() == typeof(VideoEncoder)) { return EnumHelper.GetDisplay((VideoEncoder)value); - } - if (targetType == typeof(Mixdown) || value.GetType() == typeof(Mixdown)) - { - return EnumHelper.GetDisplay((Mixdown)value); - } - + } if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetDisplay((PresetPictureSettingsMode)value); @@ -183,10 +174,6 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetValue(value.ToString()); } - if (targetType == typeof(Mixdown) || value.GetType() == typeof(Mixdown)) - { - return EnumHelper.GetValue(value.ToString()); - } if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetValue(value.ToString()); -- cgit v1.2.3