From ae9dbce961c2d87e5f52288c35fbf882de8430c7 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sat, 20 Jun 2015 19:45:31 +0000 Subject: [PATCH] WinGui: Initial implementation of quality based encoding option. Please note, the preset version has been bumped so user presets will need to be re-created. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7306 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../HandBrake.ApplicationServices.csproj | 3 +- .../Interop/HandBrakeEncoderHelpers.cs | 89 ++++-- .../Interop/HbLib/HbFunctions.cs | 1 - .../Encode/Factories/EncodeFactory.cs | 51 +--- .../Encode/Model/Models}/AudioEncoder.cs | 2 +- .../Model/Models/AudioEncoderRateType.cs | 31 ++ .../Encode/Model/Models/AudioTrack.cs | 269 ++++++++++++++++-- .../Audio/AudioRateTypeConverter.cs | 94 ++++++ .../Converters/EnumComboConverter.cs | 1 + win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + .../Services/Presets/PresetService.cs | 2 +- win/CS/HandBrakeWPF/Views/AudioView.xaml | 25 +- 12 files changed, 467 insertions(+), 102 deletions(-) rename win/CS/HandBrake.ApplicationServices/{Interop/Model/Encoding => Services/Encode/Model/Models}/AudioEncoder.cs (93%) create mode 100644 win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs create mode 100644 win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index a5feef9b2..524729f20 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -150,7 +150,7 @@ - + @@ -176,6 +176,7 @@ + diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs index 524b6b0ad..cddfd3634 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs @@ -9,7 +9,6 @@ namespace HandBrake.ApplicationServices.Interop { - using System; using System.Collections.Generic; using System.Linq; @@ -45,7 +44,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// List of HandBrake containers. - /// + /// private static List containers; /// @@ -262,8 +261,12 @@ namespace HandBrake.ApplicationServices.Interop /// /// Returns true if the subtitle source type can be set to forced only. /// - /// The subtitle source type (SSA, VobSub, etc) - /// True if the subtitle source type can be set to forced only. + /// + /// The subtitle source type (SSA, VobSub, etc) + /// + /// + /// True if the subtitle source type can be set to forced only. + /// public static bool SubtitleCanSetForcedOnly(int source) { return HBFunctions.hb_subtitle_can_force(source) > 0; @@ -272,8 +275,12 @@ namespace HandBrake.ApplicationServices.Interop /// /// Returns true if the subtitle source type can be burned in. /// - /// The subtitle source type (SSA, VobSub, etc) - /// True if the subtitle source type can be burned in. + /// + /// The subtitle source type (SSA, VobSub, etc) + /// + /// + /// True if the subtitle source type can be burned in. + /// public static bool SubtitleCanBurn(int source) { return HBFunctions.hb_subtitle_can_burn(source) > 0; @@ -282,9 +289,15 @@ namespace HandBrake.ApplicationServices.Interop /// /// Returns true if the subtitle type can be passed through using the given muxer. /// - /// The subtitle source type (SSA, VobSub, etc) - /// The ID of the muxer. - /// True if the subtitle type can be passed through with the given muxer. + /// + /// The subtitle source type (SSA, VobSub, etc) + /// + /// + /// The ID of the muxer. + /// + /// + /// True if the subtitle type can be passed through with the given muxer. + /// public static bool SubtitleCanPassthrough(int subtitleSourceType, int muxer) { return HBFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0; @@ -293,8 +306,12 @@ namespace HandBrake.ApplicationServices.Interop /// /// Gets the subtitle source type's name. /// - /// The subtitle source type (SSA, VobSub, etc). - /// The name of the subtitle source. + /// + /// The subtitle source type (SSA, VobSub, etc). + /// + /// + /// The name of the subtitle source. + /// public static string GetSubtitleSourceName(int source) { switch ((hb_subtitle_s_subsource)source) @@ -492,9 +509,9 @@ namespace HandBrake.ApplicationServices.Interop return new VideoQualityLimits { - Low = low, - High = high, - Granularity = granularity, + Low = low, + High = high, + Granularity = granularity, Ascending = direction == 0 }; } @@ -551,7 +568,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// Limits on the audio quality for the given encoder. /// - internal static RangeLimits GetAudioQualityLimits(int encoderId) + public static RangeLimits GetAudioQualityLimits(int encoderId) { float low = 0, high = 0, granularity = 0; int direction = 0; @@ -559,9 +576,9 @@ namespace HandBrake.ApplicationServices.Interop return new RangeLimits { - Low = low, - High = high, - Granularity = granularity, + Low = low, + High = high, + Granularity = granularity, Ascending = direction == 0 }; } @@ -575,7 +592,7 @@ namespace HandBrake.ApplicationServices.Interop /// /// Limits on the audio compression for the given encoder. /// - internal static RangeLimits GetAudioCompressionLimits(int encoderId) + public static RangeLimits GetAudioCompressionLimits(int encoderId) { float low = 0, high = 0, granularity = 0; int direction = 0; @@ -583,11 +600,39 @@ namespace HandBrake.ApplicationServices.Interop return new RangeLimits { - Low = low, - High = high, - Granularity = granularity, + Low = low, + High = high, + Granularity = granularity, Ascending = direction == 0 }; } + + /// + /// The get default quality. + /// + /// + /// The encoder. + /// + /// + /// The . + /// + public static double GetDefaultQuality(HBAudioEncoder encoder) + { + return HBFunctions.hb_audio_quality_get_default((uint)encoder.Id); + } + + /// + /// The get default audio compression. + /// + /// + /// The encoder. + /// + /// + /// The . + /// + public static double GetDefaultAudioCompression(HBAudioEncoder encoder) + { + return HBFunctions.hb_audio_compression_get_default((uint)encoder.Id); + } } } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs index a1e93f28b..1b68df438 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs @@ -402,7 +402,6 @@ namespace HandBrake.ApplicationServices.Interop.HbLib [DllImport("hb.dll", EntryPoint = "hb_image_close", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr hb_image_close(IntPtr image); - /* JSON API */ // char * hb_get_title_set_json(hb_handle_t * h); diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs index 12c06f011..e133492ff 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs @@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories { using System; using System.Collections.Generic; + using System.Globalization; using System.Linq; using System.Runtime.InteropServices; @@ -341,6 +342,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper.GetShortName(item.MixDown)); Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + item.MixDown); + HBRate sampleRate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(s => s.Name == item.SampleRate.ToString(CultureInfo.InvariantCulture)); + HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack { Track = (item.Track.HasValue ? item.Track.Value : 0) - 1, @@ -349,27 +352,21 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories Gain = item.Gain, Mixdown = mixdown.Id, NormalizeMixLevel = false, - Samplerate = GetSampleRateRaw(item.SampleRate), + Samplerate = sampleRate != null ? sampleRate.Rate : 0, Name = item.TrackName, }; if (!item.IsPassthru) { - // TODO Impiment Quality and Compression. We only support bitrate right now. - // if (item.EncodeRateType == AudioEncodeRateType.Quality) - // { - // audioTrack.Quality = item.Quality; - // } - - // if (item.EncodeRateType == AudioEncodeRateType.Compression) - // { - // audioTrack.CompressionLevel = item.Compression; - // } - - // if (item.EncodeRateType == AudioEncodeRateType.Bitrate) - // { - audioTrack.Bitrate = item.Bitrate; - // } + if (item.EncoderRateType == AudioEncoderRateType.Quality) + { + audioTrack.Quality = item.Quality; + } + + if (item.EncoderRateType == AudioEncoderRateType.Bitrate) + { + audioTrack.Bitrate = item.Bitrate; + } } audio.AudioList.Add(audioTrack); @@ -378,28 +375,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories return audio; } - /// - /// The get sample rate raw. - /// - /// - /// The rate. - /// - /// - /// The . - /// - private static int GetSampleRateRaw(double rate) - { - if (rate == 22.05) - return 22050; - else if (rate == 24) - return 24000; - else if (rate == 44.1) - return 32000; - else if (rate == 48) - return 48000; - else return 48000; - } - /// /// The create filter. /// diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/AudioEncoder.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs similarity index 93% rename from win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/AudioEncoder.cs rename to win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs index 3aef81c38..0b152b656 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/AudioEncoder.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs @@ -7,7 +7,7 @@ // // -------------------------------------------------------------------------------------------------------------------- -namespace HandBrake.ApplicationServices.Interop.Model.Encoding +namespace HandBrake.ApplicationServices.Services.Encode.Model.Models { using System.ComponentModel.DataAnnotations; diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs new file mode 100644 index 000000000..fb245a9b5 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs @@ -0,0 +1,31 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The audio encoder rate type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrake.ApplicationServices.Services.Encode.Model.Models +{ + using System.ComponentModel.DataAnnotations; + + /// + /// The audio encoder rate type. + /// + public enum AudioEncoderRateType + { + /// + /// The bitrate. + /// + [Display(Name = "Bitrate: ")] + Bitrate, + + /// + /// The quality. + /// + [Display(Name = "Quality: ")] + Quality, + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs index d1c980e54..d59bf8701 100644 --- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs @@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models using System.ComponentModel; using System.Globalization; using System.Linq; + using System.Runtime.CompilerServices; using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.Model; @@ -39,6 +40,9 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models private Audio scannedTrack; private bool isDefault; private IEnumerable bitrates; + private IEnumerable encoderQualityValues; + private AudioEncoderRateType encoderRateType; + private double? quality; /// /// Initializes a new instance of the class. @@ -55,7 +59,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.TrackName = string.Empty; // Setup Backing Properties - this.SetupBitrateLimits(); + this.EncoderRateType = AudioEncoderRateType.Bitrate; + this.SetupLimits(); } /// @@ -81,31 +86,15 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.scannedTrack = track.ScannedTrack ?? new Audio(); } this.TrackName = track.TrackName; + this.Quality = track.Quality; // Setup Backing Properties - this.SetupBitrateLimits(); + this.encoderRateType = track.EncoderRateType; + this.SetupLimits(); } #region Track Properties - /// - /// Gets or sets Audio Bitrate - /// - public int Bitrate - { - get - { - return this.bitrate; - } - - set - { - this.bitrate = value; - this.NotifyOfPropertyChange(() => this.Bitrate); - } - } - - /// /// Gets or sets Dynamic Range Compression /// @@ -160,7 +149,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models { this.mixDown = value; this.NotifyOfPropertyChange(() => this.MixDown); - this.SetupBitrateLimits(); + this.SetupLimits(); this.NotifyOfPropertyChange(() => this.TrackReference); } } @@ -180,9 +169,18 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.encoder = value; this.NotifyOfPropertyChange(() => this.Encoder); this.NotifyOfPropertyChange(() => this.IsPassthru); - this.NotifyOfPropertyChange(() => this.CannotSetBitrate); - this.SetupBitrateLimits(); + this.NotifyOfPropertyChange(() => this.IsBitrateVisible); + this.NotifyOfPropertyChange(() => this.IsQualityVisible); + this.NotifyOfPropertyChange(() => this.IsRateTypeVisible); + this.SetupLimits(); this.NotifyOfPropertyChange(() => this.TrackReference); + + // Refresh the available encoder rate types. + this.NotifyOfPropertyChange(() => this.AudioEncoderRateTypes); + if (!this.AudioEncoderRateTypes.Contains(this.EncoderRateType)) + { + this.EncoderRateType = AudioEncoderRateType.Bitrate; // Default to bitrate. + } } } @@ -200,16 +198,81 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models { this.sampleRate = value; this.NotifyOfPropertyChange(() => this.SampleRate); - this.SetupBitrateLimits(); + this.SetupLimits(); this.NotifyOfPropertyChange(() => this.TrackReference); } } + /// + /// Gets or sets the encoder rate type. + /// + public AudioEncoderRateType EncoderRateType + { + get + { + return this.encoderRateType; + } + + set + { + this.encoderRateType = value; + this.SetupLimits(); + this.NotifyOfPropertyChange(() => this.EncoderRateType); + this.NotifyOfPropertyChange(() => this.IsBitrateVisible); + this.NotifyOfPropertyChange(() => this.IsQualityVisible); + + if (!this.Quality.HasValue) + { + HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.Encoder)); + this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder); + } + } + } + + /// + /// Gets or sets Audio Bitrate + /// + public int Bitrate + { + get + { + return this.bitrate; + } + + set + { + this.bitrate = value; + this.NotifyOfPropertyChange(() => this.Bitrate); + } + } + + /// + /// Gets or sets Audio quality + /// + public double? Quality + { + get + { + return this.quality; + } + + set + { + this.quality = value; + this.NotifyOfPropertyChange(() => this.quality); + } + } + + /// + /// Gets or sets the track name. + /// + public string TrackName { get; set; } #endregion /// /// Gets AudioEncoderDisplayValue. /// + [JsonIgnore] public string AudioEncoderDisplayValue { get @@ -221,6 +284,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets AudioMixdownDisplayValue. /// + [JsonIgnore] public string AudioMixdownDisplayValue { get @@ -232,6 +296,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets the The UI display value for bit rate /// + [JsonIgnore] public string BitRateDisplayValue { get @@ -244,12 +309,13 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models return this.Bitrate.ToString(); } - } + } /// /// Gets or sets a value indicating whether is default. /// TODO - Can this be removed? May have been added as a quick fix for a styling quirk. /// + [JsonIgnore] public bool IsDefault { get @@ -265,6 +331,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets or sets the The UI display value for sample rate /// + [JsonIgnore] public string SampleRateDisplayValue { get @@ -307,6 +374,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets the Audio Track Name /// + [JsonIgnore] public int? Track { get @@ -323,6 +391,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets a value indicating whether IsPassthru. /// + [JsonIgnore] public bool IsPassthru { get @@ -342,6 +411,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models /// /// Gets the bitrates. /// + [JsonIgnore] public IEnumerable Bitrates { get @@ -350,20 +420,92 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models } } + /// + /// Gets the quality compression values. + /// + [JsonIgnore] + public IEnumerable EncoderQualityValues + { + get + { + return this.encoderQualityValues; + } + } + + /// + /// Gets the audio encoder rate types. + /// + [JsonIgnore] + public IEnumerable AudioEncoderRateTypes + { + get + { + IList types = EnumHelper.GetEnumList().ToList(); + HBAudioEncoder hbaenc = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.Encoder)); + if (hbaenc == null || !hbaenc.SupportsQuality) + { + types.Remove(AudioEncoderRateType.Quality); + } + + return types; + } + } + /// /// Gets a value indicating whether can set bitrate. /// - public bool CannotSetBitrate + [JsonIgnore] + public bool IsBitrateVisible + { + get + { + if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24) + { + return false; + } + + return Equals(this.EncoderRateType, AudioEncoderRateType.Bitrate); + } + } + + /// + /// Gets a value indicating whether is quality visible. + /// + [JsonIgnore] + public bool IsQualityVisible { get { - return this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24; + if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24) + { + return false; + } + + return Equals(this.EncoderRateType, AudioEncoderRateType.Quality); + } + } + + /// + /// Gets a value indicating whether is rate type visible. + /// + [JsonIgnore] + public bool IsRateTypeVisible + { + get + { + if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24) + { + return false; + } + + return true; } } /// /// Gets a value indicating whether IsLossless. /// + [JsonIgnore] public bool IsLossless { get @@ -381,10 +523,16 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models get { return this; } } + #region Handler Methods + /// - /// Gets or sets the track name. + /// The setup limits. /// - public string TrackName { get; set; } + private void SetupLimits() + { + this.SetupBitrateLimits(); + this.SetupQualityCompressionLimits(); + } /// /// The calculate bitrate limits. @@ -421,5 +569,68 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models this.Bitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(hbaenc, rate != null ? rate.Rate : 48000, mixdown); } } + + /// + /// The setup quality compression limits. + /// + private void SetupQualityCompressionLimits() + { + HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.Encoder)); + if (hbAudioEncoder.SupportsQuality) + { + RangeLimits limits = null; + + if (hbAudioEncoder.SupportsQuality) + { + limits = hbAudioEncoder.QualityLimits; + } + + if (limits != null) + { + double value = limits.Ascending ? limits.Low : limits.High; + List values = new List { value }; + + if (limits.Ascending) + { + while (value < limits.High) + { + value += limits.Granularity; + values.Add(value); + } + } + else + { + while (value > limits.Low) + { + value -= limits.Granularity; + values.Add(value); + } + } + + this.encoderQualityValues = values; + } + else + { + this.encoderQualityValues = new List(); + } + } + else + { + this.encoderQualityValues = new List(); + } + + // Default the audio quality value if it's out of range. + if (Equals(this.EncoderRateType, AudioEncoderRateType.Quality)) + { + if (this.Quality.HasValue && !this.encoderQualityValues.Contains(this.Quality.Value)) + { + this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder); + } + } + + this.NotifyOfPropertyChange(() => this.EncoderQualityValues); + } + + #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs new file mode 100644 index 000000000..1aaba88a2 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs @@ -0,0 +1,94 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// The audio rate type converter. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Windows.Data; + + using HandBrake.ApplicationServices.Services.Encode.Model.Models; + using HandBrake.ApplicationServices.Utilities; + + /// + /// The audio rate type converter. + /// + public class AudioRateTypeConverter : IValueConverter + { + /// + /// The convert. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var types = value as IEnumerable; + if (types != null) + { + List rateTypes = new List(); + foreach (var item in types) + { + rateTypes.Add(EnumHelper.GetDisplay(item)); + } + + return rateTypes; + } + + + if (targetType == typeof(AudioEncoderRateType) || value.GetType() == typeof(AudioEncoderRateType)) + { + return EnumHelper.GetDisplay((AudioEncoderRateType)value); + } + + return null; + } + + /// + /// The convert back. + /// + /// + /// The value. + /// + /// + /// The target type. + /// + /// + /// The parameter. + /// + /// + /// The culture. + /// + /// + /// The . + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value == null) + { + return null; + } + + return EnumHelper.GetValue(value.ToString()); + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index 10fb8fd3c..4c5599d62 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -134,6 +134,7 @@ namespace HandBrakeWPF.Converters return EnumHelper.GetDisplay((OutputFormat)value); } + return null; } diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 5cbc6d1b2..87a26cade 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -140,6 +140,7 @@ AlertPanel.xaml + diff --git a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs index 87f6188b5..ec0098358 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/PresetService.cs @@ -38,7 +38,7 @@ namespace HandBrakeWPF.Services.Presets { #region Private Variables - private static readonly int CurrentPresetVersion = 3; + private static readonly int CurrentPresetVersion = 4; /// /// User Preset Default Catgory Name diff --git a/win/CS/HandBrakeWPF/Views/AudioView.xaml b/win/CS/HandBrakeWPF/Views/AudioView.xaml index ef8a29cf9..1a7048b60 100644 --- a/win/CS/HandBrakeWPF/Views/AudioView.xaml +++ b/win/CS/HandBrakeWPF/Views/AudioView.xaml @@ -24,6 +24,7 @@ + @@ -145,7 +146,7 @@ @@ -188,12 +189,18 @@ - + + + + - + Visibility="{Binding IsBitrateVisible, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" /> - - -- 2.40.0