From 0a8dde9d78fc57ef19e53f50405e9a3124802267 Mon Sep 17 00:00:00 2001 From: sr55 Date: Mon, 10 Apr 2017 17:03:32 +0100 Subject: [PATCH] WinGui: Audio Defaults: Improve the Mixdown dropdown. Only show supported mixdowns and automatically select the highest available mixdown if the encoder is limited and doesn't support the current selection. --- .../Model/Audio/AudioBehaviourTrack.cs | 42 +++++++++++++++++++ .../ViewModels/AudioDefaultsViewModel.cs | 6 --- .../HandBrakeWPF/Views/AudioDefaultsView.xaml | 2 +- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs index 78c20d52c..c59b15b8c 100644 --- a/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs +++ b/win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs @@ -10,6 +10,7 @@ namespace HandBrakeWPF.Model.Audio { using System.Collections.Generic; + using System.ComponentModel; using System.Globalization; using System.Linq; using HandBrake.ApplicationServices.Interop; @@ -35,6 +36,7 @@ namespace HandBrakeWPF.Model.Audio private IEnumerable encoderQualityValues; private AudioEncoderRateType encoderRateType; private double? quality; + private IEnumerable mixdowns; /// /// Initializes a new instance of the class. @@ -48,6 +50,7 @@ namespace HandBrakeWPF.Model.Audio this.Bitrate = 160; this.DRC = 0; this.EncoderRateType = AudioEncoderRateType.Bitrate; + this.SetupLimits(); } @@ -68,6 +71,7 @@ namespace HandBrakeWPF.Model.Audio this.sampleRate = track.SampleRate; this.Quality = track.Quality; this.encoderRateType = track.EncoderRateType; + this.SetupLimits(); } @@ -354,6 +358,15 @@ namespace HandBrakeWPF.Model.Audio } } + [JsonIgnore] + public IEnumerable Mixdowns + { + get + { + return this.mixdowns; + } + } + /// /// Gets the quality compression values. /// @@ -466,6 +479,7 @@ namespace HandBrakeWPF.Model.Audio { this.SetupBitrateLimits(); this.SetupQualityCompressionLimits(); + this.SetupMixdowns(); } /// @@ -565,6 +579,34 @@ namespace HandBrakeWPF.Model.Audio this.NotifyOfPropertyChange(() => this.EncoderQualityValues); } + /// + /// Restrict the available mixdowns to those that the enocder actually supports. + /// + private void SetupMixdowns() + { + this.mixdowns = new BindingList(HandBrakeEncoderHelpers.Mixdowns.ToList()); + + HBAudioEncoder audioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.Encoder)); + + BindingList mixdownList = new BindingList(); + foreach (HBMixdown mixdown in HandBrakeEncoderHelpers.Mixdowns) + { + if (HandBrakeEncoderHelpers.MixdownHasCodecSupport(mixdown, audioEncoder)) + { + mixdownList.Add(mixdown); + } + } + + this.mixdowns = new BindingList(mixdownList); + this.NotifyOfPropertyChange(() => this.Mixdowns); + + // If the mixdown isn't supported, downgrade it to the best available. + if (!this.Mixdowns.Contains(this.MixDown)) + { + this.MixDown = this.Mixdowns.LastOrDefault(); + } + } + /// /// Set the default mixdown when the mixdown is null or "none" /// diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioDefaultsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioDefaultsViewModel.cs index 6389b58db..3d560ce5b 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioDefaultsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioDefaultsViewModel.cs @@ -54,7 +54,6 @@ namespace HandBrakeWPF.ViewModels this.SelectedLangaugesToMove = new BindingList(); this.AvailableLanguages = new BindingList(); this.AudioEncoders = EnumHelper.GetEnumList(); - this.Mixdowns = new BindingList(HandBrakeEncoderHelpers.Mixdowns.Where(m => m.ShortName != "none").ToList()); this.SampleRates = new ObservableCollection { "Auto" }; foreach (var item in HandBrakeEncoderHelpers.AudioSampleRates) @@ -340,11 +339,6 @@ namespace HandBrakeWPF.ViewModels /// public IEnumerable AudioEncoders { get; set; } - /// - /// Gets or sets AudioEncoders. - /// - public IEnumerable Mixdowns { get; set; } - /// /// Gets or sets SampleRates. /// diff --git a/win/CS/HandBrakeWPF/Views/AudioDefaultsView.xaml b/win/CS/HandBrakeWPF/Views/AudioDefaultsView.xaml index b5848d5f9..5fdbaa59c 100644 --- a/win/CS/HandBrakeWPF/Views/AudioDefaultsView.xaml +++ b/win/CS/HandBrakeWPF/Views/AudioDefaultsView.xaml @@ -270,7 +270,7 @@ -- 2.40.0