]> granicus.if.org Git - handbrake/commitdiff
WinGui: Audio Defaults: Improve the Mixdown dropdown. Only show supported mixdowns...
authorsr55 <sr55.hb@outlook.com>
Mon, 10 Apr 2017 16:03:32 +0000 (17:03 +0100)
committersr55 <sr55.hb@outlook.com>
Mon, 10 Apr 2017 16:03:32 +0000 (17:03 +0100)
win/CS/HandBrakeWPF/Model/Audio/AudioBehaviourTrack.cs
win/CS/HandBrakeWPF/ViewModels/AudioDefaultsViewModel.cs
win/CS/HandBrakeWPF/Views/AudioDefaultsView.xaml

index 78c20d52c3eaaa96c2c4eec58ace7c91d6e02dc4..c59b15b8cbd1b4bd5c9cfda2655bce8e52ba9d68 100644 (file)
@@ -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<double> encoderQualityValues;
         private AudioEncoderRateType encoderRateType;
         private double? quality;
+        private IEnumerable<HBMixdown> mixdowns;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="AudioBehaviourTrack"/> 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<HBMixdown> Mixdowns
+        {
+            get
+            {
+                return this.mixdowns;
+            }
+        }
+
         /// <summary>
         /// Gets the quality compression values.
         /// </summary>
@@ -466,6 +479,7 @@ namespace HandBrakeWPF.Model.Audio
         {
             this.SetupBitrateLimits();
             this.SetupQualityCompressionLimits();
+            this.SetupMixdowns();
         }
 
         /// <summary>
@@ -565,6 +579,34 @@ namespace HandBrakeWPF.Model.Audio
             this.NotifyOfPropertyChange(() => this.EncoderQualityValues);
         }
 
+        /// <summary>
+        /// Restrict the available mixdowns to those that the enocder actually supports.
+        /// </summary>
+        private void SetupMixdowns()
+        {
+            this.mixdowns = new BindingList<HBMixdown>(HandBrakeEncoderHelpers.Mixdowns.ToList());
+
+            HBAudioEncoder audioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));
+
+            BindingList<HBMixdown> mixdownList = new BindingList<HBMixdown>();
+            foreach (HBMixdown mixdown in HandBrakeEncoderHelpers.Mixdowns)
+            {
+                if (HandBrakeEncoderHelpers.MixdownHasCodecSupport(mixdown, audioEncoder))
+                {
+                    mixdownList.Add(mixdown);
+                }
+            }
+
+            this.mixdowns = new BindingList<HBMixdown>(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();
+            }
+        }
+
         /// <summary>
         /// Set the default mixdown when the mixdown is null or "none"
         /// </summary>
index 6389b58db752b05ea63ee0b032da5c5f3fb27a5c..3d560ce5bb77094aa1d1134f38a05becb971a72e 100644 (file)
@@ -54,7 +54,6 @@ namespace HandBrakeWPF.ViewModels
             this.SelectedLangaugesToMove = new BindingList<string>();
             this.AvailableLanguages = new BindingList<string>();
             this.AudioEncoders = EnumHelper<AudioEncoder>.GetEnumList();
-            this.Mixdowns = new BindingList<HBMixdown>(HandBrakeEncoderHelpers.Mixdowns.Where(m => m.ShortName != "none").ToList());
 
             this.SampleRates = new ObservableCollection<string> { "Auto" };
             foreach (var item in HandBrakeEncoderHelpers.AudioSampleRates)
@@ -340,11 +339,6 @@ namespace HandBrakeWPF.ViewModels
         /// </summary>
         public IEnumerable<AudioEncoder> AudioEncoders { get; set; }
 
-        /// <summary>
-        /// Gets or sets AudioEncoders.
-        /// </summary>
-        public IEnumerable<HBMixdown> Mixdowns { get; set; }
-
         /// <summary>
         /// Gets or sets SampleRates.
         /// </summary>
index b5848d5f92d10498da952d183489b92d2a98f450..5fdbaa59c9f26072cf088cc878a0470e2c7bdf6d 100644 (file)
                             <TextBlock Grid.Row="0" Grid.Column="6" VerticalAlignment="Center" FontWeight="Bold" Text="{x:Static Properties:ResourcesUI.AudioView_Mixdown}"
                                        Visibility="{Binding IsPassthru, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
                             <ComboBox Grid.Row="0" Grid.Column="7" Height="22" Width="120" Margin="5,0,5,0" HorizontalAlignment="Stretch"
-                                      ItemsSource="{Binding DataContext.Mixdowns, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
+                                      ItemsSource="{Binding Mixdowns}"
                                       SelectedItem="{Binding MixDown}"
                                       DisplayMemberPath="DisplayName"
                                       Visibility="{Binding IsPassthru, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />