From bc79d3b5b63a3220d3cdcd29819427eb0a215de2 Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 5 Oct 2008 19:18:25 +0000 Subject: [PATCH] WinGui: - Just moving stuff functions around to different places. Probably some more of this to come. frmMain / common.cs are a bit of a mess right now git-svn-id: svn://localhost/HandBrake/trunk@1814 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/C#/Functions/Common.cs | 620 +------------------------------------ win/C#/Functions/Presets.cs | 21 +- win/C#/Functions/QueryGenerator.cs | 590 +++++++++++++++++++++++++++++++++++ win/C#/HandBrakeCS.csproj | 1 + win/C#/frmAddPreset.cs | 4 +- win/C#/frmMain.cs | 13 +- 6 files changed, 620 insertions(+), 629 deletions(-) create mode 100644 win/C#/Functions/QueryGenerator.cs diff --git a/win/C#/Functions/Common.cs b/win/C#/Functions/Common.cs index 48c131ed..7b702c48 100644 --- a/win/C#/Functions/Common.cs +++ b/win/C#/Functions/Common.cs @@ -18,26 +18,6 @@ namespace Handbrake.Functions { class Common { - #region Presets - - /// - /// Update the presets.dat file with the latest version of HandBrak's presets from the CLI - /// - public void grabCLIPresets() - { - string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe"); - string presetsPath = Path.Combine(Application.StartupPath, "presets.dat"); - - string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath); - - ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine); - hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden; - - Process hbproc = Process.Start(hbGetPresets); - hbproc.WaitForExit(); - hbproc.Dispose(); - hbproc.Close(); - } /// /// This function takes in a Query which has been parsed by QueryParser and @@ -160,7 +140,7 @@ namespace Handbrake.Functions mainWindow.text_height.Text = ""; } - #endregion + #endregion // Video Settings Tab #region video @@ -383,602 +363,6 @@ namespace Handbrake.Functions #endregion } - #endregion - - #region Query Generator Functions - - /// - /// Generates a CLI query based on the GUI widgets. - /// - /// - /// The CLI String - public string GenerateTheQuery(frmMain mainWindow) - { - // Source tab - #region source - string query = ""; - - if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue")) - query = " -i " + '"' + mainWindow.text_source.Text + '"'; - - if (mainWindow.drp_dvdtitle.Text != "Automatic") - { - string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' '); - query += " -t " + titleInfo[0]; - } - - if (mainWindow.drop_chapterFinish.Text == mainWindow.drop_chapterStart.Text && mainWindow.drop_chapterStart.Text != "Auto") - query += " -c " + mainWindow.drop_chapterStart.Text; - else if (mainWindow.drop_chapterStart.Text == "Auto" && mainWindow.drop_chapterFinish.Text != "Auto") - query += " -c " + "0-" + mainWindow.drop_chapterFinish.Text; - else if (mainWindow.drop_chapterStart.Text != "Auto" && mainWindow.drop_chapterFinish.Text != "Auto") - query += " -c " + mainWindow.drop_chapterStart.Text + "-" + mainWindow.drop_chapterFinish.Text; - - #endregion - - // Destination tab - #region Destination - if (mainWindow.text_destination.Text != "") - query += " -o " + '"' + mainWindow.text_destination.Text + '"'; - #endregion - - query += generateTabbedComponentsQuery(mainWindow); - return query; - } - - /// - /// Generates a CLI query for the preview function. - /// This basically forces a shortened version of the encdode. - /// - /// - /// Returns a CLI query String. - public string GeneratePreviewQuery(frmMain mainWindow) - { - // Source tab - #region source - string query = ""; - - if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue")) - query = " -i " + '"' + mainWindow.text_source.Text + '"'; - - if (mainWindow.drp_dvdtitle.Text != "Automatic") - { - string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' '); - query += " -t " + titleInfo[0]; - } - - query += " -c 2"; - #endregion - - // Destination tab - #region Destination - if (mainWindow.text_destination.Text != "") - query += " -o " + '"' + mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm") + '"'; - - #endregion - - query += generateTabbedComponentsQuery(mainWindow); - return query; - } - - /// - /// Generates part of the CLI query, for the tabbed components only. - /// - /// - /// - /// - public string generateTabbedComponentsQuery(frmMain mainWindow) - { - string query = ""; - - // The Output Settings box above the tabbed section. - #region Output Settings Box - query += " -f " + mainWindow.drop_format.Text.ToLower().Replace(" file", ""); - - // These are output settings features - if (mainWindow.check_largeFile.Checked) - query += " -4 "; - - if (mainWindow.check_iPodAtom.Checked) - query += " -I "; - - if (mainWindow.check_optimiseMP4.Checked) - query += " -O "; - #endregion - - // Picture Settings Tab - #region Picture Settings Tab - - if (mainWindow.text_width.Text != "") - query += " -w " + mainWindow.text_width.Text; - - if (mainWindow.text_height.Text != "") - query += " -l " + mainWindow.text_height.Text; - - string cropTop = mainWindow.text_top.Text; - string cropBottom = mainWindow.text_bottom.Text; - string cropLeft = mainWindow.text_left.Text; - string cropRight = mainWindow.text_right.Text; - - if (mainWindow.check_customCrop.Checked) - { - if (mainWindow.text_top.Text == string.Empty) - cropTop = "0"; - if (mainWindow.text_bottom.Text == string.Empty) - cropBottom = "0"; - if (mainWindow.text_left.Text == string.Empty) - cropLeft = "0"; - if (mainWindow.text_right.Text == string.Empty) - cropRight = "0"; - - query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight; - } - - switch (mainWindow.drp_deInterlace_option.Text) - { - case "None": - query += ""; - break; - case "Fast": - query += " --deinterlace=\"fast\""; - break; - case "Slow": - query += " --deinterlace=\"slow\""; - break; - case "Slower": - query += " --deinterlace=\"slower\""; - break; - case "Slowest": - query += " --deinterlace=\"slowest\""; - break; - default: - query += ""; - break; - } - - if (mainWindow.check_decomb.Checked) - { - string decombValue = Properties.Settings.Default.decomb; - if (decombValue != "" && decombValue != Properties.Settings.Default.default_decomb) - query += " --decomb=\"" + decombValue + "\""; - else - query += " --decomb "; - } - - if (mainWindow.drp_anamorphic.SelectedIndex == 1) - query += " -p "; - else if (mainWindow.drp_anamorphic.SelectedIndex == 2) - query += " -P "; - - if (mainWindow.slider_deblock.Value != 4) - query += " --deblock=" + mainWindow.slider_deblock.Value; - - if (mainWindow.check_detelecine.Checked) - query += " --detelecine"; - #endregion - - // Video Settings Tab - #region Video Settings Tab - - switch (mainWindow.drp_videoEncoder.Text) - { - case "MPEG-4 (FFmpeg)": - query += " -e ffmpeg"; - break; - case "MPEG-4 (XviD)": - query += " -e xvid"; - break; - case "H.264 (x264)": - query += " -e x264"; - break; - case "VP3 (Theora)": - query += " -e theora"; - break; - default: - query += " -e x264"; - break; - } - - if (mainWindow.check_grayscale.Checked) - query += " -g "; - - // Video Settings - if (mainWindow.text_bitrate.Text != "") - query += " -b " + mainWindow.text_bitrate.Text; - - if (mainWindow.text_filesize.Text != "") - query += " -S " + mainWindow.text_filesize.Text; - - // Video Quality Setting - double videoQuality = mainWindow.slider_videoQuality.Value; - if (videoQuality != 0) - { - videoQuality = videoQuality / 100; - query += " -q " + videoQuality.ToString(new CultureInfo("en-US")); - } - - if (mainWindow.check_2PassEncode.Checked) - query += " -2 "; - - if (mainWindow.check_turbo.Checked) - query += " -T "; - - if (mainWindow.drp_videoFramerate.Text != "Same as source") - query += " -r " + mainWindow.drp_videoFramerate.Text; - - switch (mainWindow.drp_deNoise.Text) - { - case "None": - query += ""; - break; - case "Weak": - query += " --denoise=\"weak\""; - break; - case "Medium": - query += " --denoise=\"medium\""; - break; - case "Strong": - query += " --denoise=\"strong\""; - break; - default: - query += ""; - break; - } - #endregion - - // Audio Settings Tab - #region Audio Settings Tab - // Track 1 - string track1 = mainWindow.drp_track1Audio.Text; - string aencoder1 = mainWindow.drp_audenc_1.Text; - string audioBitrate1 = mainWindow.drp_audbit_1.Text; - string audioSampleRate1 = mainWindow.drp_audsr_1.Text; - string Mixdown1 = mainWindow.drp_audmix_1.Text; - string drc1 = mainWindow.trackBar1.Value.ToString(); - - // Track 2 - string track2 = mainWindow.drp_track2Audio.Text; - string aencoder2 = mainWindow.drp_audenc_2.Text; - string audioBitrate2 = mainWindow.drp_audbit_2.Text; - string audioSampleRate2 = mainWindow.drp_audsr_2.Text; - string Mixdown2 = mainWindow.drp_audmix_2.Text; - string drc2 = mainWindow.trackBar2.Value.ToString(); - - // Track 3 - string track3 = mainWindow.drp_track3Audio.Text; - string aencoder3 = mainWindow.drp_audenc_3.Text; - string audioBitrate3 = mainWindow.drp_audbit_3.Text; - string audioSampleRate3 = mainWindow.drp_audsr_3.Text; - string Mixdown3 = mainWindow.drp_audmix_3.Text; - string drc3 = mainWindow.trackBar3.Value.ToString(); - - // Track 4 - string track4 = mainWindow.drp_track4Audio.Text; - string aencoder4 = mainWindow.drp_audenc_4.Text; - string audioBitrate4 = mainWindow.drp_audbit_4.Text; - string audioSampleRate4 = mainWindow.drp_audsr_4.Text; - string Mixdown4 = mainWindow.drp_audmix_4.Text; - string drc4 = mainWindow.trackBar4.Value.ToString(); - - // - // Audio Track Selections - // - if (track1 == "Automatic") - query += " -a 1"; - else if (track1 != "None") - { - string[] tempSub = track1.Split(' '); - query += " -a " + tempSub[0]; - } - - if (track2 == "Automatic") - query += ",1"; - else if (track2 != "None") - { - string[] tempSub; - tempSub = track2.Split(' '); - - if (track1 == "None") - query += " -a none," + tempSub[0]; - else - query += "," + tempSub[0]; - } - - if (track3 != "None") - { - string[] tempSub; - tempSub = track3.Split(' '); - query += "," + tempSub[0]; - } - - if (track4 != "None") - { - string[] tempSub; - tempSub = track4.Split(' '); - query += "," + tempSub[0]; - } - - // - // Audio Encoder - // - if (aencoder1 != "") - query += " -E " + getAudioEncoder(aencoder1); - - if (aencoder2 != "") - { - if (aencoder1 == string.Empty) - query += " -E faac," + getAudioEncoder(aencoder2); - else - query += "," + getAudioEncoder(aencoder2); - } - - if (aencoder3 != "") - query += "," + getAudioEncoder(aencoder3); - - if (aencoder4 != "") - query += "," + getAudioEncoder(aencoder4); - - // - // Audio Bitrate Selections - // - if (audioBitrate1 != "") - query += " -B " + audioBitrate1; - - if (audioBitrate2 != "") - { - if (audioBitrate1 == string.Empty) - query += " -B 160," + audioBitrate2; - else - query += "," + audioBitrate2; - } - - if (audioBitrate3 != "") - query += "," + audioBitrate3; - - if (audioBitrate4 != "") - query += "," + audioBitrate4; - - - //Audio Sample Rate - audioSampleRate - if (audioSampleRate1 != "") - query += " -R " + audioSampleRate1.Replace("Auto", "0"); - - if (audioSampleRate2 != "") - { - if (audioSampleRate1 == string.Empty) - query += " -R 0," + audioSampleRate2.Replace("Auto", "0"); - else - query += "," + audioSampleRate2.Replace("Auto", "0"); - } - else - { - // All this is a hack, because when AppleTV is selected, there is no sample rate selected. so just add a 48 - // It should probably be setup later so the GUI widget has the value 48 in it. - - if ((track2 != "") && (track2 != "None")) - { - if (audioSampleRate1 == string.Empty) - query += " -R 0,0"; - else - query += ",0"; - } - } - - if (audioSampleRate3 != "") - query += "," + audioSampleRate3.Replace("Auto", "0"); - - if (audioSampleRate4 != "") - query += "," + audioSampleRate4.Replace("Auto", "0"); - - // - // Audio Mixdown Selections - // - - if (Mixdown1 != "") - query += " -6 " + getMixDown(Mixdown1); - else - query += " -6 dpl2"; - - if (Mixdown2 != "" && track2 != "None") - query += "," + getMixDown(Mixdown2); - - if (Mixdown3 != "" && track3 != "None" && track2 != "None") - query += "," + getMixDown(Mixdown3); - - if (Mixdown4 != "" && track4 != "None" && track3 != "None") - query += "," + getMixDown(Mixdown4); - - - // - // DRC - // - double value = 0; - - value = mainWindow.trackBar1.Value / 10.0; - value++; - - if (value > 1.0) - query += " -D " + value; - else - query += " -D 1"; - - value = mainWindow.trackBar2.Value / 10.0; - value++; - if (track2 != "None" && drc2 != "0") - query += "," + value; - else if (track2 != "None" && drc2 == "0") - query += ",1"; - - value = mainWindow.trackBar3.Value / 10.0; - value++; - if (track3 != "None" && drc3 != "0") - query += "," + value; - else if (track3 != "None" && drc3 == "0") - query += ",1"; - - value = mainWindow.trackBar4.Value / 10.0; - value++; - if (track4 != "None" && drc4 != "0") - query += "," + value; - else if (track4 != "None" && drc4 == "0") - query += ",1"; - - // Subtitles - string subtitles = mainWindow.drp_subtitle.Text; - if (subtitles == "Autoselect") - query += " -U "; - else if (subtitles != "" && subtitles != "None") - { - string[] tempSub; - tempSub = subtitles.Split(' '); - query += " -s " + tempSub[0]; - } - - if (mainWindow.check_forced.Checked) - query += " -F "; - - #endregion - - // Chapter Markers Tab - #region Chapter Markers - - // Attach Source name and dvd title to the start of the chapters.csv filename. - // This is for the queue. It allows different chapter name files for each title. - string source_name = mainWindow.text_source.Text; - string[] sourceName = source_name.Split('\\'); - source_name = sourceName[sourceName.Length - 1]; - source_name = source_name.Replace("\"", ""); - - string source_title = mainWindow.drp_dvdtitle.Text; - string[] titlesplit = source_title.Split(' '); - source_title = titlesplit[0]; - - if (mainWindow.Check_ChapterMarkers.Checked) - { - if ((source_name.Trim() != "Click 'Source' to continue") && (source_name.Trim() != "")) - { - string path = ""; - if (source_title != "Automatic") - path = Path.Combine(Path.GetTempPath(), source_name + "-" + source_title + "-chapters.csv"); - else - path = Path.Combine(Path.GetTempPath(), source_name + "-chapters.csv"); - - if (chapterCSVSave(mainWindow, path) == false) - query += " -m "; - else - query += " --markers=" + "\"" + path + "\""; - } - else - query += " -m"; - } - #endregion - - // H264 Tab - #region H264 Tab - if (mainWindow.rtf_x264Query.Text != "") - query += " -x " + mainWindow.rtf_x264Query.Text; - #endregion - - // Other - #region Processors / Other - string processors = Properties.Settings.Default.Processors; - if (processors != "Automatic") - query += " -C " + processors + " "; - - query += " -v "; - #endregion - - return query; - } - - /// - /// Get the CLI equive of the audio mixdown from the widget name. - /// - /// - /// - /// - private string getMixDown(string selectedAudio) - { - switch (selectedAudio) - { - case "Automatic": - return "dpl2"; - case "Mono": - return "mono"; - case "Stereo": - return "stereo"; - case "Dolby Surround": - return "dpl1"; - case "Dolby Pro Logic II": - return "dpl2"; - case "6 Channel Discrete": - return "6ch"; - default: - return "dpl2"; - } - } - - /// - /// Get the CLI equiv of the audio encoder from the widget name. - /// - /// - /// - /// - private string getAudioEncoder(string selectedEncoder) - { - switch (selectedEncoder) - { - case "AAC": - return "faac"; - case "MP3": - return "lame"; - case "Vorbis": - return "vorbis"; - case "AC3": - return "ac3"; - default: - return ""; - } - } - - /// - /// This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv - /// in a directory specified by file_path_name - /// - /// - /// - /// - private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name) - { - try - { - StringBuilder csv = new StringBuilder(); - - foreach (DataGridViewRow row in mainWindow.data_chpt.Rows) - { - csv.Append(row.Cells[0].Value.ToString()); - csv.Append(","); - csv.Append(row.Cells[1].Value.ToString()); - csv.Append(Environment.NewLine); - } - StreamWriter file = new StreamWriter(file_path_name); - file.Write(csv.ToString()); - file.Close(); - file.Dispose(); - return true; - - } - catch (Exception exc) - { - MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); - return false; - } - } - - #endregion - - #region Actions, Versioning etc - /// /// Select the longest title in the DVD title dropdown menu on frmMain /// @@ -1268,7 +652,5 @@ namespace Handbrake.Functions } } - #endregion - } } \ No newline at end of file diff --git a/win/C#/Functions/Presets.cs b/win/C#/Functions/Presets.cs index 353846b2..3faa8b8d 100644 --- a/win/C#/Functions/Presets.cs +++ b/win/C#/Functions/Presets.cs @@ -4,7 +4,7 @@ using System.Text; using System.Windows.Forms; using System.IO; using System.Text.RegularExpressions; - +using System.Diagnostics; namespace Handbrake.Functions { @@ -158,6 +158,25 @@ namespace Handbrake.Functions } /// + /// Update the presets.dat file with the latest version of HandBrake's presets from the CLI + /// + public void grabCLIPresets() + { + string handbrakeCLIPath = Path.Combine(Application.StartupPath, "HandBrakeCLI.exe"); + string presetsPath = Path.Combine(Application.StartupPath, "presets.dat"); + + string strCmdLine = String.Format(@"cmd /c """"{0}"" --preset-list >""{1}"" 2>&1""", handbrakeCLIPath, presetsPath); + + ProcessStartInfo hbGetPresets = new ProcessStartInfo("CMD.exe", strCmdLine); + hbGetPresets.WindowStyle = ProcessWindowStyle.Hidden; + + Process hbproc = Process.Start(hbGetPresets); + hbproc.WaitForExit(); + hbproc.Dispose(); + hbproc.Close(); + } + + /// /// Load in the preset data from presets.dat and user_presets.dat /// Load it into the 2 arraylist's presets and user_presets /// diff --git a/win/C#/Functions/QueryGenerator.cs b/win/C#/Functions/QueryGenerator.cs new file mode 100644 index 00000000..aa4bdd38 --- /dev/null +++ b/win/C#/Functions/QueryGenerator.cs @@ -0,0 +1,590 @@ +using System; +using System.Collections; +using System.Text; +using System.Windows.Forms; +using System.Globalization; +using System.IO; + +namespace Handbrake.Functions +{ + class QueryGenerator + { + /// + /// Generates a CLI query based on the GUI widgets. + /// + /// + /// The CLI String + public string GenerateTheQuery(frmMain mainWindow) + { + // Source tab + string query = ""; + + if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue")) + query = " -i " + '"' + mainWindow.text_source.Text + '"'; + + if (mainWindow.drp_dvdtitle.Text != "Automatic") + { + string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' '); + query += " -t " + titleInfo[0]; + } + + if (mainWindow.drop_chapterFinish.Text == mainWindow.drop_chapterStart.Text && mainWindow.drop_chapterStart.Text != "Auto") + query += " -c " + mainWindow.drop_chapterStart.Text; + else if (mainWindow.drop_chapterStart.Text == "Auto" && mainWindow.drop_chapterFinish.Text != "Auto") + query += " -c " + "0-" + mainWindow.drop_chapterFinish.Text; + else if (mainWindow.drop_chapterStart.Text != "Auto" && mainWindow.drop_chapterFinish.Text != "Auto") + query += " -c " + mainWindow.drop_chapterStart.Text + "-" + mainWindow.drop_chapterFinish.Text; + + // Destination tab + if (mainWindow.text_destination.Text != "") + query += " -o " + '"' + mainWindow.text_destination.Text + '"'; + + query += generateTabbedComponentsQuery(mainWindow); + return query; + } + + /// + /// Generates a CLI query for the preview function. + /// This basically forces a shortened version of the encdode. + /// + /// + /// Returns a CLI query String. + public string GeneratePreviewQuery(frmMain mainWindow) + { + // Source tab + string query = ""; + + if ((mainWindow.text_source.Text != "") && (mainWindow.text_source.Text.Trim() != "Click 'Source' to continue")) + query = " -i " + '"' + mainWindow.text_source.Text + '"'; + + if (mainWindow.drp_dvdtitle.Text != "Automatic") + { + string[] titleInfo = mainWindow.drp_dvdtitle.Text.Split(' '); + query += " -t " + titleInfo[0]; + } + + query += " -c 2"; + + // Destination tab + if (mainWindow.text_destination.Text != "") + query += " -o " + '"' + mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm") + '"'; + + query += generateTabbedComponentsQuery(mainWindow); + return query; + } + + /// + /// Generates part of the CLI query, for the tabbed components only. + /// + /// + /// + /// + public string generateTabbedComponentsQuery(frmMain mainWindow) + { + string query = ""; + + // The Output Settings box above the tabbed section. + #region Output Settings Box + query += " -f " + mainWindow.drop_format.Text.ToLower().Replace(" file", ""); + + // These are output settings features + if (mainWindow.check_largeFile.Checked) + query += " -4 "; + + if (mainWindow.check_iPodAtom.Checked) + query += " -I "; + + if (mainWindow.check_optimiseMP4.Checked) + query += " -O "; + #endregion + + // Picture Settings Tab + #region Picture Settings Tab + + if (mainWindow.text_width.Text != "") + query += " -w " + mainWindow.text_width.Text; + + if (mainWindow.text_height.Text != "") + query += " -l " + mainWindow.text_height.Text; + + string cropTop = mainWindow.text_top.Text; + string cropBottom = mainWindow.text_bottom.Text; + string cropLeft = mainWindow.text_left.Text; + string cropRight = mainWindow.text_right.Text; + + if (mainWindow.check_customCrop.Checked) + { + if (mainWindow.text_top.Text == string.Empty) + cropTop = "0"; + if (mainWindow.text_bottom.Text == string.Empty) + cropBottom = "0"; + if (mainWindow.text_left.Text == string.Empty) + cropLeft = "0"; + if (mainWindow.text_right.Text == string.Empty) + cropRight = "0"; + + query += " --crop " + cropTop + ":" + cropBottom + ":" + cropLeft + ":" + cropRight; + } + + switch (mainWindow.drp_deInterlace_option.Text) + { + case "None": + query += ""; + break; + case "Fast": + query += " --deinterlace=\"fast\""; + break; + case "Slow": + query += " --deinterlace=\"slow\""; + break; + case "Slower": + query += " --deinterlace=\"slower\""; + break; + case "Slowest": + query += " --deinterlace=\"slowest\""; + break; + default: + query += ""; + break; + } + + if (mainWindow.check_decomb.Checked) + { + string decombValue = Properties.Settings.Default.decomb; + if (decombValue != "" && decombValue != Properties.Settings.Default.default_decomb) + query += " --decomb=\"" + decombValue + "\""; + else + query += " --decomb "; + } + + if (mainWindow.drp_anamorphic.SelectedIndex == 1) + query += " -p "; + else if (mainWindow.drp_anamorphic.SelectedIndex == 2) + query += " -P "; + + if (mainWindow.slider_deblock.Value != 4) + query += " --deblock=" + mainWindow.slider_deblock.Value; + + if (mainWindow.check_detelecine.Checked) + query += " --detelecine"; + #endregion + + // Video Settings Tab + #region Video Settings Tab + + switch (mainWindow.drp_videoEncoder.Text) + { + case "MPEG-4 (FFmpeg)": + query += " -e ffmpeg"; + break; + case "MPEG-4 (XviD)": + query += " -e xvid"; + break; + case "H.264 (x264)": + query += " -e x264"; + break; + case "VP3 (Theora)": + query += " -e theora"; + break; + default: + query += " -e x264"; + break; + } + + if (mainWindow.check_grayscale.Checked) + query += " -g "; + + // Video Settings + if (mainWindow.text_bitrate.Text != "") + query += " -b " + mainWindow.text_bitrate.Text; + + if (mainWindow.text_filesize.Text != "") + query += " -S " + mainWindow.text_filesize.Text; + + // Video Quality Setting + double videoQuality = mainWindow.slider_videoQuality.Value; + if (videoQuality != 0) + { + videoQuality = videoQuality / 100; + query += " -q " + videoQuality.ToString(new CultureInfo("en-US")); + } + + if (mainWindow.check_2PassEncode.Checked) + query += " -2 "; + + if (mainWindow.check_turbo.Checked) + query += " -T "; + + if (mainWindow.drp_videoFramerate.Text != "Same as source") + query += " -r " + mainWindow.drp_videoFramerate.Text; + + switch (mainWindow.drp_deNoise.Text) + { + case "None": + query += ""; + break; + case "Weak": + query += " --denoise=\"weak\""; + break; + case "Medium": + query += " --denoise=\"medium\""; + break; + case "Strong": + query += " --denoise=\"strong\""; + break; + default: + query += ""; + break; + } + #endregion + + // Audio Settings Tab + #region Audio Settings Tab + // Track 1 + string track1 = mainWindow.drp_track1Audio.Text; + string aencoder1 = mainWindow.drp_audenc_1.Text; + string audioBitrate1 = mainWindow.drp_audbit_1.Text; + string audioSampleRate1 = mainWindow.drp_audsr_1.Text; + string Mixdown1 = mainWindow.drp_audmix_1.Text; + string drc1 = mainWindow.trackBar1.Value.ToString(); + + // Track 2 + string track2 = mainWindow.drp_track2Audio.Text; + string aencoder2 = mainWindow.drp_audenc_2.Text; + string audioBitrate2 = mainWindow.drp_audbit_2.Text; + string audioSampleRate2 = mainWindow.drp_audsr_2.Text; + string Mixdown2 = mainWindow.drp_audmix_2.Text; + string drc2 = mainWindow.trackBar2.Value.ToString(); + + // Track 3 + string track3 = mainWindow.drp_track3Audio.Text; + string aencoder3 = mainWindow.drp_audenc_3.Text; + string audioBitrate3 = mainWindow.drp_audbit_3.Text; + string audioSampleRate3 = mainWindow.drp_audsr_3.Text; + string Mixdown3 = mainWindow.drp_audmix_3.Text; + string drc3 = mainWindow.trackBar3.Value.ToString(); + + // Track 4 + string track4 = mainWindow.drp_track4Audio.Text; + string aencoder4 = mainWindow.drp_audenc_4.Text; + string audioBitrate4 = mainWindow.drp_audbit_4.Text; + string audioSampleRate4 = mainWindow.drp_audsr_4.Text; + string Mixdown4 = mainWindow.drp_audmix_4.Text; + string drc4 = mainWindow.trackBar4.Value.ToString(); + + // + // Audio Track Selections + // + if (track1 == "Automatic") + query += " -a 1"; + else if (track1 != "None") + { + string[] tempSub = track1.Split(' '); + query += " -a " + tempSub[0]; + } + + if (track2 == "Automatic") + query += ",1"; + else if (track2 != "None") + { + string[] tempSub; + tempSub = track2.Split(' '); + + if (track1 == "None") + query += " -a none," + tempSub[0]; + else + query += "," + tempSub[0]; + } + + if (track3 != "None") + { + string[] tempSub; + tempSub = track3.Split(' '); + query += "," + tempSub[0]; + } + + if (track4 != "None") + { + string[] tempSub; + tempSub = track4.Split(' '); + query += "," + tempSub[0]; + } + + // + // Audio Encoder + // + if (aencoder1 != "") + query += " -E " + getAudioEncoder(aencoder1); + + if (aencoder2 != "") + { + if (aencoder1 == string.Empty) + query += " -E faac," + getAudioEncoder(aencoder2); + else + query += "," + getAudioEncoder(aencoder2); + } + + if (aencoder3 != "") + query += "," + getAudioEncoder(aencoder3); + + if (aencoder4 != "") + query += "," + getAudioEncoder(aencoder4); + + // + // Audio Bitrate Selections + // + if (audioBitrate1 != "") + query += " -B " + audioBitrate1; + + if (audioBitrate2 != "") + { + if (audioBitrate1 == string.Empty) + query += " -B 160," + audioBitrate2; + else + query += "," + audioBitrate2; + } + + if (audioBitrate3 != "") + query += "," + audioBitrate3; + + if (audioBitrate4 != "") + query += "," + audioBitrate4; + + + //Audio Sample Rate - audioSampleRate + if (audioSampleRate1 != "") + query += " -R " + audioSampleRate1.Replace("Auto", "0"); + + if (audioSampleRate2 != "") + { + if (audioSampleRate1 == string.Empty) + query += " -R 0," + audioSampleRate2.Replace("Auto", "0"); + else + query += "," + audioSampleRate2.Replace("Auto", "0"); + } + else + { + // All this is a hack, because when AppleTV is selected, there is no sample rate selected. so just add a 48 + // It should probably be setup later so the GUI widget has the value 48 in it. + + if ((track2 != "") && (track2 != "None")) + { + if (audioSampleRate1 == string.Empty) + query += " -R 0,0"; + else + query += ",0"; + } + } + + if (audioSampleRate3 != "") + query += "," + audioSampleRate3.Replace("Auto", "0"); + + if (audioSampleRate4 != "") + query += "," + audioSampleRate4.Replace("Auto", "0"); + + // + // Audio Mixdown Selections + // + + if (Mixdown1 != "") + query += " -6 " + getMixDown(Mixdown1); + else + query += " -6 dpl2"; + + if (Mixdown2 != "" && track2 != "None") + query += "," + getMixDown(Mixdown2); + + if (Mixdown3 != "" && track3 != "None" && track2 != "None") + query += "," + getMixDown(Mixdown3); + + if (Mixdown4 != "" && track4 != "None" && track3 != "None") + query += "," + getMixDown(Mixdown4); + + + // + // DRC + // + double value = 0; + + value = mainWindow.trackBar1.Value / 10.0; + value++; + + if (value > 1.0) + query += " -D " + value; + else + query += " -D 1"; + + value = mainWindow.trackBar2.Value / 10.0; + value++; + if (track2 != "None" && drc2 != "0") + query += "," + value; + else if (track2 != "None" && drc2 == "0") + query += ",1"; + + value = mainWindow.trackBar3.Value / 10.0; + value++; + if (track3 != "None" && drc3 != "0") + query += "," + value; + else if (track3 != "None" && drc3 == "0") + query += ",1"; + + value = mainWindow.trackBar4.Value / 10.0; + value++; + if (track4 != "None" && drc4 != "0") + query += "," + value; + else if (track4 != "None" && drc4 == "0") + query += ",1"; + + // Subtitles + string subtitles = mainWindow.drp_subtitle.Text; + if (subtitles == "Autoselect") + query += " -U "; + else if (subtitles != "" && subtitles != "None") + { + string[] tempSub; + tempSub = subtitles.Split(' '); + query += " -s " + tempSub[0]; + } + + if (mainWindow.check_forced.Checked) + query += " -F "; + + #endregion + + // Chapter Markers Tab + #region Chapter Markers + + // Attach Source name and dvd title to the start of the chapters.csv filename. + // This is for the queue. It allows different chapter name files for each title. + string source_name = mainWindow.text_source.Text; + string[] sourceName = source_name.Split('\\'); + source_name = sourceName[sourceName.Length - 1]; + source_name = source_name.Replace("\"", ""); + + string source_title = mainWindow.drp_dvdtitle.Text; + string[] titlesplit = source_title.Split(' '); + source_title = titlesplit[0]; + + if (mainWindow.Check_ChapterMarkers.Checked) + { + if ((source_name.Trim() != "Click 'Source' to continue") && (source_name.Trim() != "")) + { + string path = ""; + if (source_title != "Automatic") + path = Path.Combine(Path.GetTempPath(), source_name + "-" + source_title + "-chapters.csv"); + else + path = Path.Combine(Path.GetTempPath(), source_name + "-chapters.csv"); + + if (chapterCSVSave(mainWindow, path) == false) + query += " -m "; + else + query += " --markers=" + "\"" + path + "\""; + } + else + query += " -m"; + } + #endregion + + // H264 Tab + #region H264 Tab + if (mainWindow.rtf_x264Query.Text != "") + query += " -x " + mainWindow.rtf_x264Query.Text; + #endregion + + // Other + #region Processors / Other + string processors = Properties.Settings.Default.Processors; + if (processors != "Automatic") + query += " -C " + processors + " "; + + query += " -v "; + #endregion + + return query; + } + + /// + /// Get the CLI equive of the audio mixdown from the widget name. + /// + /// + /// + /// + private string getMixDown(string selectedAudio) + { + switch (selectedAudio) + { + case "Automatic": + return "dpl2"; + case "Mono": + return "mono"; + case "Stereo": + return "stereo"; + case "Dolby Surround": + return "dpl1"; + case "Dolby Pro Logic II": + return "dpl2"; + case "6 Channel Discrete": + return "6ch"; + default: + return "dpl2"; + } + } + + /// + /// Get the CLI equiv of the audio encoder from the widget name. + /// + /// + /// + /// + private string getAudioEncoder(string selectedEncoder) + { + switch (selectedEncoder) + { + case "AAC": + return "faac"; + case "MP3": + return "lame"; + case "Vorbis": + return "vorbis"; + case "AC3": + return "ac3"; + default: + return ""; + } + } + + /// + /// This function saves the data in the chapters tab, dataGridView into a CSV file called chapters.csv + /// in a directory specified by file_path_name + /// + /// + /// + /// + private Boolean chapterCSVSave(frmMain mainWindow, string file_path_name) + { + try + { + StringBuilder csv = new StringBuilder(); + + foreach (DataGridViewRow row in mainWindow.data_chpt.Rows) + { + csv.Append(row.Cells[0].Value.ToString()); + csv.Append(","); + csv.Append(row.Cells[1].Value.ToString()); + csv.Append(Environment.NewLine); + } + StreamWriter file = new StreamWriter(file_path_name); + file.Write(csv.ToString()); + file.Close(); + file.Dispose(); + return true; + + } + catch (Exception exc) + { + MessageBox.Show("Unable to save Chapter Makrers file! \nChapter marker names will NOT be saved in your encode \n\n" + exc.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + return false; + } + } + } +} diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index cea26368..a1809da1 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -146,6 +146,7 @@ frmUpdater.cs + diff --git a/win/C#/frmAddPreset.cs b/win/C#/frmAddPreset.cs index 44e99105..c2f754ff 100644 --- a/win/C#/frmAddPreset.cs +++ b/win/C#/frmAddPreset.cs @@ -17,7 +17,7 @@ namespace Handbrake { public partial class frmAddPreset : Form { - Functions.Common hb_common_func = new Functions.Common(); + Functions.QueryGenerator queryGen = new Functions.QueryGenerator(); private frmMain frmMainWindow; Functions.Presets presetCode; @@ -30,7 +30,7 @@ namespace Handbrake private void btn_add_Click(object sender, EventArgs e) { - String query = hb_common_func.generateTabbedComponentsQuery(frmMainWindow); + String query = queryGen.generateTabbedComponentsQuery(frmMainWindow); if (presetCode.addPreset(txt_preset_name.Text.Trim(), query) == true) { diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index f7b06a42..14b0612b 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -27,6 +27,7 @@ namespace Handbrake Functions.Encode cliObj = new Functions.Encode(); Functions.Queue encodeQueue = new Functions.Queue(); Functions.Presets presetHandler = new Functions.Presets(); + Functions.QueryGenerator queryGen = new Functions.QueryGenerator(); Parsing.Title selectedTitle; internal Process hbProc; private Parsing.DVD thisDVD; @@ -224,7 +225,7 @@ namespace Handbrake #region Presets Menu private void mnu_presetReset_Click(object sender, EventArgs e) { - hb_common_func.grabCLIPresets(); + presetHandler.grabCLIPresets(); loadPresetPanel(); if (treeView_presets.Nodes.Count == 0) MessageBox.Show("Unable to load the presets.dat file. Please select \"Update Built-in Presets\" from the Presets Menu \nMake sure you are running the program in Admin mode if running on Vista. See Windows FAQ for details!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); @@ -315,7 +316,7 @@ namespace Handbrake if (rtf_query.Text != "") query = rtf_query.Text; else - query = hb_common_func.GenerateTheQuery(this); + query = queryGen.GenerateTheQuery(this); ThreadPool.QueueUserWorkItem(procMonitor, query); lbl_encode.Visible = true; @@ -333,7 +334,7 @@ namespace Handbrake else { - String query = hb_common_func.GenerateTheQuery(this); + String query = queryGen.GenerateTheQuery(this); if (rtf_query.Text != "") query = rtf_query.Text; @@ -1326,7 +1327,7 @@ namespace Handbrake // Query Editor Tab private void btn_generate_Query_Click(object sender, EventArgs e) { - rtf_query.Text = hb_common_func.GenerateTheQuery(this); + rtf_query.Text = queryGen.GenerateTheQuery(this); } private void btn_clear_Click(object sender, EventArgs e) { @@ -1352,7 +1353,7 @@ namespace Handbrake } private void btn_setDefault_Click(object sender, EventArgs e) { - String query = hb_common_func.GenerateTheQuery(this); + String query = queryGen.GenerateTheQuery(this); Properties.Settings.Default.defaultUserSettings = query; // Save the new default Settings Properties.Settings.Default.Save(); @@ -1858,7 +1859,6 @@ namespace Handbrake btn_start.ToolTipText = "Start the encoding process"; btn_start.Image = Properties.Resources.Play; } - #endregion @@ -1923,7 +1923,6 @@ namespace Handbrake } #endregion - // This is the END of the road ------------------------------------------------------------------------------ } } \ No newline at end of file -- 2.11.0