From 5f692a69a63f106cabe9dad4dfc85cc5c6d93cb9 Mon Sep 17 00:00:00 2001 From: sr55 Date: Fri, 8 Apr 2011 19:34:20 +0000 Subject: WinGui: AudioPanel refactored. - Switch the Audio panel to use DataBinding to a BindingList collection leading to much cleaner code. - Added gain support (--gain=3,4) to the services library. (UI has not been done yet) git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3911 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- .../Converters/EnumToDescConverter.cs | 24 ++++++++++ .../Functions/EnumHelper.cs | 26 ++++++++++- .../HandBrake.ApplicationServices.csproj | 1 + .../Model/Encoding/AudioEncoder.cs | 3 ++ .../Model/Encoding/AudioTrack.cs | 52 ++++++++++++++++++++-- .../Model/Encoding/Mixdown.cs | 11 ++++- .../Parsing/Subtitle.cs | 3 +- .../Utilities/PlistUtility.cs | 8 ++-- .../Utilities/QueryGeneratorUtility.cs | 9 +++- .../Utilities/QueryParserUtility.cs | 2 +- 10 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 win/CS/HandBrake.ApplicationServices/Converters/EnumToDescConverter.cs (limited to 'win/CS/HandBrake.ApplicationServices') diff --git a/win/CS/HandBrake.ApplicationServices/Converters/EnumToDescConverter.cs b/win/CS/HandBrake.ApplicationServices/Converters/EnumToDescConverter.cs new file mode 100644 index 000000000..a03a3f071 --- /dev/null +++ b/win/CS/HandBrake.ApplicationServices/Converters/EnumToDescConverter.cs @@ -0,0 +1,24 @@ +namespace HandBrake.ApplicationServices.Converters +{ + using System.ComponentModel; + using System; + + using HandBrake.ApplicationServices.Functions; + + public class EnumToDescConveter : EnumConverter + { + public EnumToDescConveter(Type type) + : base(type) + { + } + + public override object ConvertTo( + ITypeDescriptorContext context, + System.Globalization.CultureInfo culture, + object value, + Type destinationType) + { + return EnumHelper.GetDescription((Enum)value); + } + } +} diff --git a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs index 0bbc746d7..657434f31 100644 --- a/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs +++ b/win/CS/HandBrake.ApplicationServices/Functions/EnumHelper.cs @@ -12,7 +12,10 @@ namespace HandBrake.ApplicationServices.Functions /// /// Enum Helpers /// - public class EnumHelper + /// + /// The Type Parameter + /// + public class EnumHelper { /// /// Get the description of an Enum @@ -23,7 +26,7 @@ namespace HandBrake.ApplicationServices.Functions /// /// The Description string /// - public static string GetDescription(Enum value) + public static string GetDescription(T value) { FieldInfo fieldInfo = value.GetType().GetField(value.ToString()); DescriptionAttribute[] attributes = @@ -31,5 +34,24 @@ namespace HandBrake.ApplicationServices.Functions typeof(DescriptionAttribute), false); return (attributes.Length > 0) ? attributes[0].Description : value.ToString(); } + + /// + /// Get the Enumeration for a given Enum Description + /// + /// The String description + /// The Enum Value + public static T GetValue(string description) + { + foreach (T val in Enum.GetValues(typeof(T))) + { + string currDescription = GetDescription(val); + if (currDescription == description) + { + return val; + } + } + + throw new ArgumentOutOfRangeException("The Description for the enum was not recognized."); + } } } diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index fcfb2fe03..48a1eb08a 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -83,6 +83,7 @@ + diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs index 23d7d9e2f..716f539f8 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioEncoder.cs @@ -7,6 +7,9 @@ namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; + using HandBrake.ApplicationServices.Converters; + + [TypeConverter(typeof(EnumToDescConveter))] public enum AudioEncoder { [Description("AAC (faac)")] diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs index 440f72226..6e47d3421 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/AudioTrack.cs @@ -16,17 +16,58 @@ namespace HandBrake.ApplicationServices.Model.Encoding public AudioTrack() { // Default Values - this.Track = 1; + this.Encoder = AudioEncoder.Faac; this.MixDown = Mixdown.DolbyProLogicII; this.SampleRate = 48; this.Bitrate = 160; this.DRC = 1; + this.SourceTrack = "Automatic"; } /// - /// Gets or sets Audio Track Name + /// Gets the Audio Track Name /// - public int Track { get; set; } + public int? Track + { + get + { + string[] tempSub = SourceTrack.Split(' '); + int value; + if (int.TryParse(tempSub[0], out value)) + { + return value; + } + return null; + } + } + + /// + /// Gets the The UI display value for sample rate + /// + public string SampleRateDisplayValue + { + get + { + return SampleRate == 0 ? "Auto" : SampleRate.ToString(); + } + } + + /// + /// Gets the The UI display value for bit rate + /// + public string BitRateDisplayValue + { + get + { + return Bitrate == 0 ? "Auto" : Bitrate.ToString(); + } + } + + /// + /// Gets or sets the Source Track + /// Used for display purposes only. + /// + public string SourceTrack { get; set; } /// /// Gets or sets Audio Mixdown @@ -52,5 +93,10 @@ namespace HandBrake.ApplicationServices.Model.Encoding /// Gets or sets Dynamic Range Compression /// public double DRC { get; set; } + + /// + /// Gets or sets the Gain for the audio track + /// + public int Gain { get; set; } } } \ No newline at end of file diff --git a/win/CS/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs b/win/CS/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs index 12611b454..8b0cc9005 100644 --- a/win/CS/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs +++ b/win/CS/HandBrake.ApplicationServices/Model/Encoding/Mixdown.cs @@ -7,9 +7,12 @@ namespace HandBrake.ApplicationServices.Model.Encoding { using System.ComponentModel; + using HandBrake.ApplicationServices.Converters; + /// /// The Mixdown Mode /// + [TypeConverter(typeof(EnumToDescConveter))] public enum Mixdown { [Description("Dolby Pro Logic II")] @@ -28,6 +31,12 @@ namespace HandBrake.ApplicationServices.Model.Encoding DolbySurround, [Description("6 Channel Discrete")] - SixChannelDiscrete + SixChannelDiscrete, + + [Description("AC3 Passthru")] + Ac3Passthrough, + + [Description("DTS Passthru")] + DtsPassthrough, } } diff --git a/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs b/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs index 1ac827037..5e7b89a10 100644 --- a/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs +++ b/win/CS/HandBrake.ApplicationServices/Parsing/Subtitle.cs @@ -5,6 +5,7 @@ namespace HandBrake.ApplicationServices.Parsing { + using System; using System.Collections.Generic; using System.IO; using System.Text.RegularExpressions; @@ -75,7 +76,7 @@ namespace HandBrake.ApplicationServices.Parsing { get { - return EnumHelper.GetDescription(this.SubtitleType); + return EnumHelper.GetDescription(this.SubtitleType); } } diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs index 0a8aa72ec..752141bf0 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/PlistUtility.cs @@ -68,7 +68,7 @@ namespace HandBrake.ApplicationServices.Utilities track.SampleRate = double.Parse(value); break; case "AudioTrack": - track.Track = int.Parse(value); + track.SourceTrack = value; break; case "AudioTrackDRCSlider": track.DRC = double.Parse(value); @@ -528,7 +528,7 @@ namespace HandBrake.ApplicationServices.Utilities // Video Settings AddEncodeElement(xmlWriter, "VideoAvgBitrate", "string", parsed.VideoBitrate.ToString()); - AddEncodeElement(xmlWriter, "VideoEncoder", "string", EnumHelper.GetDescription(parsed.VideoEncoder)); + AddEncodeElement(xmlWriter, "VideoEncoder", "string", EnumHelper.GetDescription(parsed.VideoEncoder)); AddEncodeElement(xmlWriter, "VideoFramerate", "string", parsed.Framerate.ToString()); AddEncodeElement(xmlWriter, "VideFrameratePFR", "integer", parsed.FramerateMode == FramerateMode.PFR ? "1" : "0"); AddEncodeElement(xmlWriter, "VideoGrayScale", "integer", parsed.Grayscale ? "1" : "0"); @@ -636,10 +636,10 @@ namespace HandBrake.ApplicationServices.Utilities xmlWriter.WriteElementString("string", audioTrack.Bitrate.ToString()); xmlWriter.WriteElementString("key", "AudioEncoder"); - xmlWriter.WriteElementString("string", EnumHelper.GetDescription(audioTrack.Encoder)); + xmlWriter.WriteElementString("string", EnumHelper.GetDescription(audioTrack.Encoder)); xmlWriter.WriteElementString("key", "AudioMixdown"); - xmlWriter.WriteElementString("string", EnumHelper.GetDescription(audioTrack.MixDown)); + xmlWriter.WriteElementString("string", EnumHelper.GetDescription(audioTrack.MixDown)); xmlWriter.WriteElementString("key", "AudioSamplerate"); xmlWriter.WriteElementString("string", audioTrack.SampleRate.ToString()); diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs index ce963188f..bd75880b9 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryGeneratorUtility.cs @@ -136,7 +136,7 @@ namespace HandBrake.ApplicationServices.Utilities { string query = string.Empty; - query += string.Format(" -f {0} ", EnumHelper.GetDescription(task.OutputFormat).ToLower()); + query += string.Format(" -f {0} ", EnumHelper.GetDescription(task.OutputFormat).ToLower()); // These are output settings features if (task.LargeFile) @@ -373,7 +373,12 @@ namespace HandBrake.ApplicationServices.Utilities // Gather information about each audio track and store them in the declared lists. foreach (AudioTrack track in audioTracks) { - tracks.Add(track.Track); + if (track.Track == null) + { + continue; + } + + tracks.Add(track.Track.Value); // Audio Codec (-E) codecs.Add(track.Encoder); diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs index 856114bb0..4d34ac937 100644 --- a/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs +++ b/win/CS/HandBrake.ApplicationServices/Utilities/QueryParserUtility.cs @@ -359,7 +359,7 @@ namespace HandBrake.ApplicationServices.Utilities AudioTrack track = new AudioTrack(); if (trackData != null) if (trackData.Length >= (x + 1)) // Audio Track - track.Track = int.Parse(trackData[x].Trim()); + track.SourceTrack = trackData[x].Trim(); if (trackMixes != null) if (trackMixes.Length >= (x + 1)) // Audio Mix -- cgit v1.2.3