]> granicus.if.org Git - handbrake/commitdiff
WinGui: Initial implementation of quality based encoding option. Please note, the...
authorsr55 <sr55.hb@outlook.com>
Sat, 20 Jun 2015 19:45:31 +0000 (19:45 +0000)
committersr55 <sr55.hb@outlook.com>
Sat, 20 Jun 2015 19:45:31 +0000 (19:45 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7306 b64f7644-9d1e-0410-96f1-a4d463321fa5

12 files changed:
win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj
win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
win/CS/HandBrake.ApplicationServices/Interop/HbLib/HbFunctions.cs
win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs
win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoder.cs [moved from win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/AudioEncoder.cs with 93% similarity]
win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioEncoderRateType.cs [new file with mode: 0644]
win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs
win/CS/HandBrakeWPF/Converters/Audio/AudioRateTypeConverter.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs
win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Services/Presets/PresetService.cs
win/CS/HandBrakeWPF/Views/AudioView.xaml

index a5feef9b2dfc7446e2c918d4572769342a1fc3f4..524729f2094c0fecccb27cff6009032befc2dfc4 100644 (file)
     <Compile Include="Interop\Model\BitrateLimits.cs" />\r
     <Compile Include="Interop\Model\Cropping.cs" />\r
     <Compile Include="Interop\Model\Encoding\Anamorphic.cs" />\r
-    <Compile Include="Interop\Model\Encoding\AudioEncoder.cs" />\r
+    <Compile Include="Services\Encode\Model\Models\AudioEncoder.cs" />\r
     <Compile Include="Interop\Model\Encoding\Container.cs" />\r
     <Compile Include="Interop\Model\Encoding\Decomb.cs" />\r
     <Compile Include="Interop\Model\Encoding\Deinterlace.cs" />\r
     <Compile Include="Services\Encode\Factories\VideoPresetFactory.cs" />\r
     <Compile Include="Services\Encode\Factories\VideoLevelFactory.cs" />\r
     <Compile Include="Services\Encode\Factories\VideoTuneFactory.cs" />\r
+    <Compile Include="Services\Encode\Model\Models\AudioEncoderRateType.cs" />\r
     <Compile Include="Services\Encode\Model\Models\DenoisePreset.cs" />\r
     <Compile Include="Services\Encode\Model\Models\DenoiseTune.cs" />\r
     <Compile Include="Model\HBConfiguration.cs" />\r
index 524b6b0ad5c9d48b805e2e9deb0dcc578dfeea95..cddfd363447141f8143ff8615723c90d0cee90a5 100644 (file)
@@ -9,7 +9,6 @@
 \r
 namespace HandBrake.ApplicationServices.Interop\r
 {\r
-    using System;\r
     using System.Collections.Generic;\r
     using System.Linq;\r
 \r
@@ -45,7 +44,7 @@ namespace HandBrake.ApplicationServices.Interop
 \r
         /// <summary>\r
         /// List of HandBrake containers.\r
-        /// </summary>\r
+        /// </summary> \r
         private static List<HBContainer> containers;\r
 \r
         /// <summary>\r
@@ -262,8 +261,12 @@ namespace HandBrake.ApplicationServices.Interop
         /// <summary>\r
         /// Returns true if the subtitle source type can be set to forced only.\r
         /// </summary>\r
-        /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>\r
-        /// <returns>True if the subtitle source type can be set to forced only.</returns>\r
+        /// <param name="source">\r
+        /// The subtitle source type (SSA, VobSub, etc)\r
+        /// </param>\r
+        /// <returns>\r
+        /// True if the subtitle source type can be set to forced only.\r
+        /// </returns>\r
         public static bool SubtitleCanSetForcedOnly(int source)\r
         {\r
             return HBFunctions.hb_subtitle_can_force(source) > 0;\r
@@ -272,8 +275,12 @@ namespace HandBrake.ApplicationServices.Interop
         /// <summary>\r
         /// Returns true if the subtitle source type can be burned in.\r
         /// </summary>\r
-        /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>\r
-        /// <returns>True if the subtitle source type can be burned in.</returns>\r
+        /// <param name="source">\r
+        /// The subtitle source type (SSA, VobSub, etc)\r
+        /// </param>\r
+        /// <returns>\r
+        /// True if the subtitle source type can be burned in.\r
+        /// </returns>\r
         public static bool SubtitleCanBurn(int source)\r
         {\r
             return HBFunctions.hb_subtitle_can_burn(source) > 0;\r
@@ -282,9 +289,15 @@ namespace HandBrake.ApplicationServices.Interop
         /// <summary>\r
         /// Returns true if the subtitle type can be passed through using the given muxer.\r
         /// </summary>\r
-        /// <param name="subtitleSourceType">The subtitle source type (SSA, VobSub, etc)</param>\r
-        /// <param name="muxer">The ID of the muxer.</param>\r
-        /// <returns>True if the subtitle type can be passed through with the given muxer.</returns>\r
+        /// <param name="subtitleSourceType">\r
+        /// The subtitle source type (SSA, VobSub, etc)\r
+        /// </param>\r
+        /// <param name="muxer">\r
+        /// The ID of the muxer.\r
+        /// </param>\r
+        /// <returns>\r
+        /// True if the subtitle type can be passed through with the given muxer.\r
+        /// </returns>\r
         public static bool SubtitleCanPassthrough(int subtitleSourceType, int muxer)\r
         {\r
             return HBFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0;\r
@@ -293,8 +306,12 @@ namespace HandBrake.ApplicationServices.Interop
         /// <summary>\r
         /// Gets the subtitle source type's name.\r
         /// </summary>\r
-        /// <param name="source">The subtitle source type (SSA, VobSub, etc).</param>\r
-        /// <returns>The name of the subtitle source.</returns>\r
+        /// <param name="source">\r
+        /// The subtitle source type (SSA, VobSub, etc).\r
+        /// </param>\r
+        /// <returns>\r
+        /// The name of the subtitle source.\r
+        /// </returns>\r
         public static string GetSubtitleSourceName(int source)\r
         {\r
             switch ((hb_subtitle_s_subsource)source)\r
@@ -492,9 +509,9 @@ namespace HandBrake.ApplicationServices.Interop
 \r
             return new VideoQualityLimits\r
                 {\r
-                    Low = low,\r
-                    High = high,\r
-                    Granularity = granularity,\r
+                    Low = low, \r
+                    High = high, \r
+                    Granularity = granularity, \r
                     Ascending = direction == 0\r
                 };\r
         }\r
@@ -551,7 +568,7 @@ namespace HandBrake.ApplicationServices.Interop
         /// <returns>\r
         /// Limits on the audio quality for the given encoder.\r
         /// </returns>\r
-        internal static RangeLimits GetAudioQualityLimits(int encoderId)\r
+        public static RangeLimits GetAudioQualityLimits(int encoderId)\r
         {\r
             float low = 0, high = 0, granularity = 0;\r
             int direction = 0;\r
@@ -559,9 +576,9 @@ namespace HandBrake.ApplicationServices.Interop
 \r
             return new RangeLimits\r
             {\r
-                Low = low,\r
-                High = high,\r
-                Granularity = granularity,\r
+                Low = low, \r
+                High = high, \r
+                Granularity = granularity, \r
                 Ascending = direction == 0\r
             };\r
         }\r
@@ -575,7 +592,7 @@ namespace HandBrake.ApplicationServices.Interop
         /// <returns>\r
         /// Limits on the audio compression for the given encoder.\r
         /// </returns>\r
-        internal static RangeLimits GetAudioCompressionLimits(int encoderId)\r
+        public static RangeLimits GetAudioCompressionLimits(int encoderId)\r
         {\r
             float low = 0, high = 0, granularity = 0;\r
             int direction = 0;\r
@@ -583,11 +600,39 @@ namespace HandBrake.ApplicationServices.Interop
 \r
             return new RangeLimits\r
             {\r
-                Low = low,\r
-                High = high,\r
-                Granularity = granularity,\r
+                Low = low, \r
+                High = high, \r
+                Granularity = granularity, \r
                 Ascending = direction == 0\r
             };\r
         }\r
+\r
+        /// <summary>\r
+        /// The get default quality.\r
+        /// </summary>\r
+        /// <param name="encoder">\r
+        /// The encoder.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="double"/>.\r
+        /// </returns>\r
+        public static double GetDefaultQuality(HBAudioEncoder encoder)\r
+        {\r
+           return HBFunctions.hb_audio_quality_get_default((uint)encoder.Id);\r
+        }\r
+\r
+        /// <summary>\r
+        /// The get default audio compression.\r
+        /// </summary>\r
+        /// <param name="encoder">\r
+        /// The encoder.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="double"/>.\r
+        /// </returns>\r
+        public static double GetDefaultAudioCompression(HBAudioEncoder encoder)\r
+        {\r
+            return HBFunctions.hb_audio_compression_get_default((uint)encoder.Id);\r
+        }\r
     }\r
 }\r
index a1e93f28b56a7fff5a3cf31eddd62d9f9d07689c..1b68df438ba726d2fe2266cdb22166177c57ec47 100644 (file)
@@ -402,7 +402,6 @@ namespace HandBrake.ApplicationServices.Interop.HbLib
         [DllImport("hb.dll", EntryPoint = "hb_image_close", CallingConvention = CallingConvention.Cdecl)]\r
         public static extern IntPtr hb_image_close(IntPtr image);\r
 \r
-\r
         /* JSON API */\r
 \r
         // char     * hb_get_title_set_json(hb_handle_t * h);\r
index 12c06f011a2e5b9fcab8226ab0d97e25cc99a7b7..e133492fff3b57f6e248ab25738c17fee3db02bb 100644 (file)
@@ -11,6 +11,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
 {\r
     using System;\r
     using System.Collections.Generic;\r
+    using System.Globalization;\r
     using System.Linq;\r
     using System.Runtime.InteropServices;\r
 \r
@@ -341,6 +342,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
                 HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper<Mixdown>.GetShortName(item.MixDown));\r
                 Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + item.MixDown);\r
 \r
+                HBRate sampleRate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(s => s.Name == item.SampleRate.ToString(CultureInfo.InvariantCulture));\r
+\r
                 HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack\r
                     {\r
                         Track = (item.Track.HasValue ? item.Track.Value : 0) - 1,\r
@@ -349,27 +352,21 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
                         Gain = item.Gain,\r
                         Mixdown = mixdown.Id,\r
                         NormalizeMixLevel = false,\r
-                        Samplerate = GetSampleRateRaw(item.SampleRate),\r
+                        Samplerate = sampleRate != null ? sampleRate.Rate : 0,\r
                         Name = item.TrackName,\r
                     };\r
 \r
                 if (!item.IsPassthru)\r
                 {\r
-                    // TODO Impiment Quality and Compression. We only support bitrate right now.\r
-                    // if (item.EncodeRateType == AudioEncodeRateType.Quality)\r
-                    // {\r
-                    //    audioTrack.Quality = item.Quality;\r
-                    // }\r
-\r
-                    // if (item.EncodeRateType == AudioEncodeRateType.Compression)\r
-                    // {\r
-                    //    audioTrack.CompressionLevel = item.Compression;\r
-                    // }\r
-\r
-                    // if (item.EncodeRateType == AudioEncodeRateType.Bitrate)\r
-                    // {\r
-                    audioTrack.Bitrate = item.Bitrate;\r
-                    // }\r
+                     if (item.EncoderRateType == AudioEncoderRateType.Quality)\r
+                     {\r
+                        audioTrack.Quality = item.Quality;\r
+                     }\r
+\r
+                     if (item.EncoderRateType == AudioEncoderRateType.Bitrate)\r
+                     {\r
+                        audioTrack.Bitrate = item.Bitrate;\r
+                     }\r
                 }\r
 \r
                 audio.AudioList.Add(audioTrack);\r
@@ -378,28 +375,6 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
             return audio;\r
         }\r
 \r
-        /// <summary>\r
-        /// The get sample rate raw.\r
-        /// </summary>\r
-        /// <param name="rate">\r
-        /// The rate.\r
-        /// </param>\r
-        /// <returns>\r
-        /// The <see cref="int"/>.\r
-        /// </returns>\r
-        private static int GetSampleRateRaw(double rate)\r
-        {\r
-            if (rate == 22.05)\r
-                return 22050;\r
-            else if (rate == 24)\r
-                return 24000;\r
-            else if (rate == 44.1)\r
-                return 32000;\r
-            else if (rate == 48)\r
-                return 48000;\r
-            else return 48000;\r
-        }\r
-\r
         /// <summary>\r
         /// The create filter.\r
         /// </summary>\r
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 3aef81c38c33486244b6c84c5ef907ceb5fab7b0..0b152b656cc2c804c78b49d04339f3b88a66ab8a 100644 (file)
@@ -7,7 +7,7 @@
 // </summary>\r
 // --------------------------------------------------------------------------------------------------------------------\r
 \r
-namespace HandBrake.ApplicationServices.Interop.Model.Encoding\r
+namespace HandBrake.ApplicationServices.Services.Encode.Model.Models\r
 {\r
     using System.ComponentModel.DataAnnotations;\r
 \r
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 (file)
index 0000000..fb245a9
--- /dev/null
@@ -0,0 +1,31 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="AudioEncoderRateType.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The audio encoder rate type.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrake.ApplicationServices.Services.Encode.Model.Models\r
+{\r
+    using System.ComponentModel.DataAnnotations;\r
+\r
+    /// <summary>\r
+    /// The audio encoder rate type.\r
+    /// </summary>\r
+    public enum AudioEncoderRateType\r
+    {\r
+        /// <summary>\r
+        /// The bitrate.\r
+        /// </summary>\r
+        [Display(Name = "Bitrate: ")]\r
+        Bitrate, \r
+\r
+        /// <summary>\r
+        /// The quality.\r
+        /// </summary>\r
+        [Display(Name = "Quality: ")]\r
+        Quality, \r
+    }\r
+}\r
index d1c980e543292a095e27ba34a2bf215c85608ac6..d59bf870192f839aa85567726a90c0c6d760f500 100644 (file)
@@ -14,6 +14,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
     using System.ComponentModel;\r
     using System.Globalization;\r
     using System.Linq;\r
+    using System.Runtime.CompilerServices;\r
 \r
     using HandBrake.ApplicationServices.Interop;\r
     using HandBrake.ApplicationServices.Interop.Model;\r
@@ -39,6 +40,9 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         private Audio scannedTrack;\r
         private bool isDefault;\r
         private IEnumerable<int> bitrates;\r
+        private IEnumerable<double> encoderQualityValues;\r
+        private AudioEncoderRateType encoderRateType;\r
+        private double? quality;\r
 \r
         /// <summary>\r
         ///   Initializes a new instance of the <see cref = "AudioTrack" /> class.\r
@@ -55,7 +59,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
             this.TrackName = string.Empty;\r
 \r
             // Setup Backing Properties\r
-            this.SetupBitrateLimits();\r
+            this.EncoderRateType = AudioEncoderRateType.Bitrate;\r
+            this.SetupLimits();\r
         }\r
 \r
         /// <summary>\r
@@ -81,31 +86,15 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
                 this.scannedTrack = track.ScannedTrack ?? new Audio();\r
             }\r
             this.TrackName = track.TrackName;\r
+            this.Quality = track.Quality;\r
 \r
             // Setup Backing Properties\r
-            this.SetupBitrateLimits();\r
+            this.encoderRateType = track.EncoderRateType;\r
+            this.SetupLimits();\r
         }\r
 \r
         #region Track Properties\r
 \r
-        /// <summary>\r
-        ///   Gets or sets Audio Bitrate\r
-        /// </summary>\r
-        public int Bitrate\r
-        {\r
-            get\r
-            {\r
-                return this.bitrate;\r
-            }\r
-\r
-            set\r
-            {\r
-                this.bitrate = value;\r
-                this.NotifyOfPropertyChange(() => this.Bitrate);\r
-            }\r
-        }\r
-        \r
-\r
         /// <summary>\r
         ///   Gets or sets Dynamic Range Compression\r
         /// </summary>\r
@@ -160,7 +149,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
             {\r
                 this.mixDown = value;\r
                 this.NotifyOfPropertyChange(() => this.MixDown);\r
-                this.SetupBitrateLimits();\r
+                this.SetupLimits();\r
                 this.NotifyOfPropertyChange(() => this.TrackReference);\r
             }\r
         }\r
@@ -180,9 +169,18 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
                 this.encoder = value;\r
                 this.NotifyOfPropertyChange(() => this.Encoder);\r
                 this.NotifyOfPropertyChange(() => this.IsPassthru);\r
-                this.NotifyOfPropertyChange(() => this.CannotSetBitrate);\r
-                this.SetupBitrateLimits();\r
+                this.NotifyOfPropertyChange(() => this.IsBitrateVisible);\r
+                this.NotifyOfPropertyChange(() => this.IsQualityVisible);\r
+                this.NotifyOfPropertyChange(() => this.IsRateTypeVisible);\r
+                this.SetupLimits();\r
                 this.NotifyOfPropertyChange(() => this.TrackReference);\r
+\r
+                // Refresh the available encoder rate types.\r
+                this.NotifyOfPropertyChange(() => this.AudioEncoderRateTypes);\r
+                if (!this.AudioEncoderRateTypes.Contains(this.EncoderRateType))\r
+                {\r
+                    this.EncoderRateType = AudioEncoderRateType.Bitrate; // Default to bitrate.\r
+                }\r
             }\r
         }\r
 \r
@@ -200,16 +198,81 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
             {\r
                 this.sampleRate = value;\r
                 this.NotifyOfPropertyChange(() => this.SampleRate);\r
-                this.SetupBitrateLimits();\r
+                this.SetupLimits();\r
                 this.NotifyOfPropertyChange(() => this.TrackReference);\r
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets or sets the encoder rate type.\r
+        /// </summary>\r
+        public AudioEncoderRateType EncoderRateType\r
+        {\r
+            get\r
+            {\r
+                return this.encoderRateType;\r
+            }\r
+\r
+            set\r
+            {\r
+                this.encoderRateType = value;\r
+                this.SetupLimits();\r
+                this.NotifyOfPropertyChange(() => this.EncoderRateType);\r
+                this.NotifyOfPropertyChange(() => this.IsBitrateVisible);\r
+                this.NotifyOfPropertyChange(() => this.IsQualityVisible);\r
+\r
+                if (!this.Quality.HasValue)\r
+                {\r
+                    HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));\r
+                    this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder);\r
+                }\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        ///   Gets or sets Audio Bitrate\r
+        /// </summary>\r
+        public int Bitrate\r
+        {\r
+            get\r
+            {\r
+                return this.bitrate;\r
+            }\r
+\r
+            set\r
+            {\r
+                this.bitrate = value;\r
+                this.NotifyOfPropertyChange(() => this.Bitrate);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        ///   Gets or sets Audio quality\r
+        /// </summary>\r
+        public double? Quality\r
+        {\r
+            get\r
+            {\r
+                return this.quality;\r
+            }\r
+\r
+            set\r
+            {\r
+                this.quality = value;\r
+                this.NotifyOfPropertyChange(() => this.quality);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets or sets the track name.\r
+        /// </summary>\r
+        public string TrackName { get; set; }\r
         #endregion\r
 \r
         /// <summary>\r
         ///   Gets AudioEncoderDisplayValue.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public string AudioEncoderDisplayValue\r
         {\r
             get\r
@@ -221,6 +284,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         ///   Gets AudioMixdownDisplayValue.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public string AudioMixdownDisplayValue\r
         {\r
             get\r
@@ -232,6 +296,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         ///   Gets the The UI display value for bit rate\r
         /// </summary>\r
+        [JsonIgnore]\r
         public string BitRateDisplayValue\r
         {\r
             get\r
@@ -244,12 +309,13 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
 \r
                 return this.Bitrate.ToString();\r
             }\r
-        }     \r
+        }\r
 \r
         /// <summary>\r
         /// Gets or sets a value indicating whether is default.\r
         /// TODO - Can this be removed? May have been added as a quick fix for a styling quirk.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public bool IsDefault\r
         {\r
             get\r
@@ -265,6 +331,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         ///  Gets or sets the The UI display value for sample rate\r
         /// </summary>\r
+        [JsonIgnore]\r
         public string SampleRateDisplayValue\r
         {\r
             get\r
@@ -307,6 +374,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         ///   Gets the Audio Track Name\r
         /// </summary>\r
+        [JsonIgnore]\r
         public int? Track\r
         {\r
             get\r
@@ -323,6 +391,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         /// Gets a value indicating whether IsPassthru.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public bool IsPassthru\r
         {\r
             get\r
@@ -342,6 +411,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
         /// <summary>\r
         /// Gets the bitrates.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public IEnumerable<int> Bitrates\r
         {\r
             get\r
@@ -350,20 +420,92 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Gets the quality compression values.\r
+        /// </summary>\r
+        [JsonIgnore]\r
+        public IEnumerable<double> EncoderQualityValues\r
+        {\r
+            get\r
+            {\r
+                return this.encoderQualityValues;\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets the audio encoder rate types.\r
+        /// </summary>\r
+        [JsonIgnore]\r
+        public IEnumerable<AudioEncoderRateType> AudioEncoderRateTypes\r
+        {\r
+            get\r
+            {\r
+                IList<AudioEncoderRateType> types = EnumHelper<AudioEncoderRateType>.GetEnumList().ToList();\r
+                HBAudioEncoder hbaenc = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));\r
+                if (hbaenc == null || !hbaenc.SupportsQuality)\r
+                {\r
+                    types.Remove(AudioEncoderRateType.Quality);\r
+                }\r
+\r
+                return types;\r
+            }\r
+        }\r
+\r
         /// <summary>\r
         /// Gets a value indicating whether can set bitrate.\r
         /// </summary>\r
-        public bool CannotSetBitrate\r
+        [JsonIgnore]\r
+        public bool IsBitrateVisible\r
+        {\r
+            get\r
+            {\r
+                if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)\r
+                {\r
+                    return false;\r
+                }\r
+\r
+                return Equals(this.EncoderRateType, AudioEncoderRateType.Bitrate);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets a value indicating whether is quality visible.\r
+        /// </summary>\r
+        [JsonIgnore]\r
+        public bool IsQualityVisible\r
         {\r
             get\r
             {\r
-                return this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24;\r
+                if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)\r
+                {\r
+                    return false;\r
+                }\r
+\r
+                return Equals(this.EncoderRateType, AudioEncoderRateType.Quality);\r
+            }\r
+        }\r
+\r
+        /// <summary>\r
+        /// Gets a value indicating whether is rate type visible.\r
+        /// </summary>\r
+        [JsonIgnore]\r
+        public bool IsRateTypeVisible\r
+        {\r
+            get\r
+            {\r
+                if (this.IsPassthru || this.Encoder == AudioEncoder.ffflac || this.Encoder == AudioEncoder.ffflac24)\r
+                {\r
+                    return false;\r
+                }\r
+\r
+                return true;\r
             }\r
         }\r
 \r
         /// <summary>\r
         /// Gets a value indicating whether IsLossless.\r
         /// </summary>\r
+        [JsonIgnore]\r
         public bool IsLossless\r
         {\r
             get\r
@@ -381,10 +523,16 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
             get { return this; }\r
         }\r
 \r
+        #region Handler Methods\r
+\r
         /// <summary>\r
-        /// Gets or sets the track name.\r
+        /// The setup limits.\r
         /// </summary>\r
-        public string TrackName { get; set; }\r
+        private void SetupLimits()\r
+        {\r
+            this.SetupBitrateLimits();\r
+            this.SetupQualityCompressionLimits();\r
+        }\r
 \r
         /// <summary>\r
         /// The calculate bitrate limits.\r
@@ -421,5 +569,68 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
                 this.Bitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(hbaenc, rate != null ? rate.Rate : 48000, mixdown);\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// The setup quality compression limits.\r
+        /// </summary>\r
+        private void SetupQualityCompressionLimits()\r
+        {\r
+            HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));\r
+            if (hbAudioEncoder.SupportsQuality)\r
+            {\r
+                RangeLimits limits = null;\r
+\r
+                if (hbAudioEncoder.SupportsQuality)\r
+                {\r
+                    limits = hbAudioEncoder.QualityLimits;\r
+                }\r
+\r
+                if (limits != null)\r
+                {\r
+                    double value = limits.Ascending ? limits.Low : limits.High;\r
+                    List<double> values = new List<double> { value };\r
+\r
+                    if (limits.Ascending)\r
+                    {\r
+                        while (value < limits.High)\r
+                        {\r
+                            value += limits.Granularity;\r
+                            values.Add(value);\r
+                        }\r
+                    }\r
+                    else\r
+                    {\r
+                        while (value > limits.Low)\r
+                        {\r
+                            value -= limits.Granularity;\r
+                            values.Add(value);\r
+                        }\r
+                    }\r
+\r
+                    this.encoderQualityValues = values;\r
+                }\r
+                else\r
+                {\r
+                    this.encoderQualityValues = new List<double>();\r
+                }\r
+            }\r
+            else\r
+            {\r
+                this.encoderQualityValues = new List<double>();\r
+            }\r
+\r
+            // Default the audio quality value if it's out of range.\r
+            if (Equals(this.EncoderRateType, AudioEncoderRateType.Quality))\r
+            {\r
+                if (this.Quality.HasValue && !this.encoderQualityValues.Contains(this.Quality.Value))\r
+                {\r
+                    this.Quality = HandBrakeEncoderHelpers.GetDefaultQuality(hbAudioEncoder);\r
+                }\r
+            }\r
+\r
+            this.NotifyOfPropertyChange(() => this.EncoderQualityValues);\r
+        }\r
+\r
+        #endregion\r
     }\r
 }
\ 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 (file)
index 0000000..1aaba88
--- /dev/null
@@ -0,0 +1,94 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="AudioRateTypeConverter.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   The audio rate type converter.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Converters.Audio\r
+{\r
+    using System;\r
+    using System.Collections.Generic;\r
+    using System.Globalization;\r
+    using System.Windows.Data;\r
+\r
+    using HandBrake.ApplicationServices.Services.Encode.Model.Models;\r
+    using HandBrake.ApplicationServices.Utilities;\r
+\r
+    /// <summary>\r
+    /// The audio rate type converter.\r
+    /// </summary>\r
+    public class AudioRateTypeConverter : IValueConverter\r
+    {\r
+        /// <summary>\r
+        /// The convert.\r
+        /// </summary>\r
+        /// <param name="value">\r
+        /// The value.\r
+        /// </param>\r
+        /// <param name="targetType">\r
+        /// The target type.\r
+        /// </param>\r
+        /// <param name="parameter">\r
+        /// The parameter.\r
+        /// </param>\r
+        /// <param name="culture">\r
+        /// The culture.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="object"/>.\r
+        /// </returns>\r
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\r
+        {\r
+            var types = value as IEnumerable<AudioEncoderRateType>;\r
+            if (types != null)\r
+            {\r
+                List<string> rateTypes = new List<string>();\r
+                foreach (var item in types)\r
+                {\r
+                    rateTypes.Add(EnumHelper<AudioEncoderRateType>.GetDisplay(item));\r
+                }\r
+\r
+                return rateTypes;\r
+            }\r
+\r
+\r
+            if (targetType == typeof(AudioEncoderRateType) || value.GetType() == typeof(AudioEncoderRateType))\r
+            {\r
+                return EnumHelper<AudioEncoderRateType>.GetDisplay((AudioEncoderRateType)value);\r
+            }\r
+\r
+            return null;\r
+        }\r
+\r
+        /// <summary>\r
+        /// The convert back.\r
+        /// </summary>\r
+        /// <param name="value">\r
+        /// The value.\r
+        /// </param>\r
+        /// <param name="targetType">\r
+        /// The target type.\r
+        /// </param>\r
+        /// <param name="parameter">\r
+        /// The parameter.\r
+        /// </param>\r
+        /// <param name="culture">\r
+        /// The culture.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="object"/>.\r
+        /// </returns>\r
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\r
+        {\r
+            if (value == null)\r
+            {\r
+                return null;\r
+            }\r
+\r
+            return EnumHelper<AudioEncoderRateType>.GetValue(value.ToString());\r
+        }\r
+    }\r
+}\r
index 10fb8fd3c0d3bfd61a78e2fa29051b5f6ca81da9..4c5599d6242c6419b5829922d540e837e92a66db 100644 (file)
@@ -134,6 +134,7 @@ namespace HandBrakeWPF.Converters
                 return EnumHelper<OutputFormat>.GetDisplay((OutputFormat)value);\r
             }\r
 \r
\r
             return null;\r
         }\r
 \r
index 5cbc6d1b2cae24d5f9fc759a4c8b6cf03fcea8ba..87a26cadec5656d945ba464105ce99bc9983b955 100644 (file)
     <Compile Include="Controls\AlertPanel.xaml.cs">\r
       <DependentUpon>AlertPanel.xaml</DependentUpon>\r
     </Compile>\r
+    <Compile Include="Converters\Audio\AudioRateTypeConverter.cs" />\r
     <Compile Include="Converters\Audio\AudioTrackDefaultBehaviourConverter.cs" />\r
     <Compile Include="Converters\Audio\AudioBehaviourConverter.cs" />\r
     <Compile Include="Converters\Filters\DenoisePresetConverter.cs" />\r
index 87f6188b5d51b3acb6af351b95a9b0c04ca7a79b..ec009835886e2923300bcd698652f9f2eed0df9d 100644 (file)
@@ -38,7 +38,7 @@ namespace HandBrakeWPF.Services.Presets
     {\r
         #region Private Variables\r
 \r
-        private static readonly int CurrentPresetVersion = 3;\r
+        private static readonly int CurrentPresetVersion = 4;\r
 \r
         /// <summary>\r
         /// User Preset Default Catgory Name\r
index ef8a29cf98c89643fab73567f2608f47badb9129..1a7048b60cfd21a9ef548f29d8e242849a89d218 100644 (file)
@@ -24,6 +24,7 @@
         <Audio:AudioEncoderConverter x:Key="audioEncoderConverter" />\r
         <Audio:AudioBehaviourConverter x:Key="audioBehaviourConverter" />\r
         <Audio:AudioTrackDefaultBehaviourConverter x:Key="audioTrackDefaultBehaviourConverter" />\r
+        <Audio:AudioRateTypeConverter x:Key="audioRateTypeConverter" />\r
     </UserControl.Resources>\r
 \r
     <Grid>\r
                         <Image Grid.Column="0" Grid.Row="0"\r
                                Width="16"\r
                                Height="16"\r
-                               Margin="10,0,10,0"\r
+                               Margin="8,0,8,0"\r
                                Source="Images/Movies.png" />\r
 \r
                         <!--  Settings  -->\r
                                 </ComboBox.ItemsSource>\r
                             </ComboBox>\r
 \r
-                            <TextBlock Grid.Column="4" VerticalAlignment="Center" FontWeight="Bold" Text="{x:Static Properties:ResourcesUI.AudioView_Bitrate}"\r
-                                       Visibility="{Binding CannotSetBitrate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />\r
+                            <ComboBox Grid.Column="4" Height="22" Width="65" HorizontalAlignment="Stretch"\r
+                                      ItemsSource="{Binding AudioEncoderRateTypes, Converter={StaticResource audioRateTypeConverter}}"\r
+                                      SelectedItem="{Binding EncoderRateType, Converter={StaticResource audioRateTypeConverter}}"\r
+                                      Visibility="{Binding IsRateTypeVisible, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />\r
+\r
+                            <ComboBox Grid.Column="5" Width="55" Height="22" Margin="5,0,5,0" ItemsSource="{Binding EncoderQualityValues}"\r
+                                      SelectedItem="{Binding Quality}"\r
+                                      Visibility="{Binding IsQualityVisible, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />\r
+\r
                             <ComboBox Grid.Column="5" Width="55" Height="22" Margin="5,0,5,0" ItemsSource="{Binding Bitrates}"\r
                                       SelectedItem="{Binding Bitrate}"\r
-                                      Visibility="{Binding CannotSetBitrate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />\r
-\r
+                                      Visibility="{Binding IsBitrateVisible, Converter={StaticResource boolToVisConverter}, ConverterParameter=false}" />\r
 \r
                             <!--  Row 2  -->\r
                             <TextBlock Grid.Row="0" Grid.Column="6" VerticalAlignment="Center" FontWeight="Bold" Text="{x:Static Properties:ResourcesUI.AudioView_Mixdown}"\r
                                       Visibility="{Binding IsPassthru, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />\r
 \r
 \r
-\r
-                            <ToggleButton Name="advancedOptionsToggle" VerticalAlignment="Center" Grid.Column="8" Grid.Row="0" Grid.ColumnSpan="2"\r
+                            <ToggleButton Name="advancedOptionsToggle" VerticalAlignment="Center" Grid.Column="8" Grid.Row="0" Grid.ColumnSpan="2" Margin="5,0,0,0"\r
                                            Padding="3,0" Height="22" HorizontalAlignment="Left" >\r
                                 <ToggleButton.Style>\r
                                     <Style TargetType="{x:Type ToggleButton}">\r
                                         <Setter Property="Content" Value="Show"/>\r
+                                        <Setter Property="FontWeight" Value="Bold" />\r
                                         <Style.Triggers>\r
                                             <Trigger Property="IsChecked" Value="True">\r
-                                                <Setter Property="Content" Value="Hide"/>\r
+                                                <Setter Property="Content" Value="˄"/>\r
                                             </Trigger>\r
                                             <Trigger Property="IsChecked" Value="False">\r
-                                                <Setter Property="Content" Value="Show"/>\r
+                                                <Setter Property="Content" Value="˅" />\r
                                             </Trigger>\r
                                         </Style.Triggers>\r
                                     </Style>\r