1 /* PresetLoader.cs $
\r
3 This file is part of the HandBrake source code.
\r
4 Homepage: <http://handbrake.fr>.
\r
5 It may be used under the terms of the GNU General Public License. */
\r
8 using System.Windows.Forms;
\r
10 namespace Handbrake.Functions
\r
15 /// This function takes in a Query which has been parsed by QueryParser and
\r
16 /// set's all the GUI widgets correctly.
\r
18 /// <param name="mainWindow"></param>
\r
19 /// <param name="presetQuery">The Parsed CLI Query</param>
\r
20 /// <param name="name">Name of the preset</param>
\r
21 /// <param name="pictureSettings">Save picture settings in the preset</param>
\r
22 public static void presetLoader(frmMain mainWindow, QueryParser presetQuery, string name, Boolean pictureSettings)
\r
24 // ---------------------------
\r
26 // ---------------------------
\r
29 // Reset some vaules to stock first to prevent errors.
\r
30 mainWindow.check_iPodAtom.CheckState = CheckState.Unchecked;
\r
32 // Now load all the new settings onto the main window
\r
33 if (presetQuery.Format != null)
\r
35 string destination = mainWindow.text_destination.Text;
\r
36 destination = destination.Replace(".mp4", "." + presetQuery.Format);
\r
37 destination = destination.Replace(".m4v", "." + presetQuery.Format);
\r
38 destination = destination.Replace(".mkv", "." + presetQuery.Format);
\r
39 mainWindow.text_destination.Text = destination;
\r
44 #region Destination and Output Settings
\r
46 if (presetQuery.Format != null)
\r
48 if (presetQuery.Format == "mp4")
\r
49 mainWindow.drop_format.SelectedIndex = 0;
\r
50 else if (presetQuery.Format == "m4v")
\r
51 mainWindow.drop_format.SelectedIndex = 1;
\r
52 else if (presetQuery.Format == "mkv")
\r
53 mainWindow.drop_format.SelectedIndex = 2;
\r
55 if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")
\r
56 mainWindow.drop_format.SelectedIndex = 1;
\r
59 mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;
\r
61 mainWindow.check_optimiseMP4.CheckState = presetQuery.OptimizeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
63 mainWindow.check_largeFile.CheckState = presetQuery.LargeMP4 ? CheckState.Checked : CheckState.Unchecked;
\r
65 mainWindow.setContainerOpts(); // select the container options according to the selected format
\r
70 mainWindow.PictureSettings.check_autoCrop.Checked = true;
\r
71 if (presetQuery.CropBottom == "0" && presetQuery.CropTop == "0")
\r
72 if (presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")
\r
73 mainWindow.PictureSettings.check_customCrop.Checked = true;
\r
75 if (pictureSettings) // only Load picture settings if the perset requires it
\r
77 if (presetQuery.CropTop != null)
\r
79 int top, bottom, left, right;
\r
80 int.TryParse(presetQuery.CropTop, out top);
\r
81 int.TryParse(presetQuery.CropBottom, out bottom);
\r
82 int.TryParse(presetQuery.CropLeft, out left);
\r
83 int.TryParse(presetQuery.CropRight, out right);
\r
85 mainWindow.PictureSettings.check_customCrop.Checked = true;
\r
86 mainWindow.PictureSettings.crop_top.Value = top;
\r
87 mainWindow.PictureSettings.crop_bottom.Value = bottom;
\r
88 mainWindow.PictureSettings.crop_left.Value = left;
\r
89 mainWindow.PictureSettings.crop_right.Value = right;
\r
93 // Reset maxWidth and MaxHeight to 0
\r
94 mainWindow.PictureSettings.maxWidth = 0;
\r
95 mainWindow.PictureSettings.maxHeight = 0;
\r
97 // Set the width and height
\r
98 if (presetQuery.Width != 0)
\r
99 mainWindow.PictureSettings.text_width.Value = presetQuery.Width;
\r
100 else if (presetQuery.MaxWidth == 0)
\r
101 mainWindow.PictureSettings.text_width.Value = 0;
\r
103 mainWindow.PictureSettings.text_height.Value = presetQuery.Height != 0 ? presetQuery.Height : 0;
\r
105 // Max Width/Height override Width/Height
\r
106 if (presetQuery.MaxWidth != 0)
\r
108 mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth;
\r
109 mainWindow.PictureSettings.maxWidth = presetQuery.MaxWidth;
\r
112 if (presetQuery.MaxHeight != 0)
\r
114 mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight;
\r
115 mainWindow.PictureSettings.maxHeight = presetQuery.MaxHeight;
\r
117 mainWindow.PictureSettings.setMax();
\r
119 // Set the anamorphic mode 0,1,2,3
\r
120 mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;
\r
122 // Custom Anamorphic Controls
\r
123 mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;
\r
124 mainWindow.PictureSettings.txt_displayWidth.Text = presetQuery.displayWidthValue.ToString();
\r
125 mainWindow.PictureSettings.txt_parWidth.Text = presetQuery.pixelAspectWidth.ToString();
\r
126 mainWindow.PictureSettings.txt_parHeight.Text = presetQuery.pixelAspectHeight.ToString();
\r
127 mainWindow.PictureSettings.drop_modulus.SelectedItem = presetQuery.AnamorphicModulus;
\r
133 mainWindow.Filters.setDecomb(presetQuery.Decomb);
\r
134 mainWindow.Filters.setDeInterlace(presetQuery.DeInterlace);
\r
135 mainWindow.Filters.setDeNoise(presetQuery.DeNoise);
\r
136 mainWindow.Filters.setDeTelecine(presetQuery.DeTelecine);
\r
137 mainWindow.Filters.setDeBlock(presetQuery.DeBlock);
\r
138 mainWindow.Filters.setGrayScale(presetQuery.Grayscale);
\r
142 mainWindow.drp_videoEncoder.Text = presetQuery.VideoEncoder;
\r
144 if (presetQuery.AverageVideoBitrate != null)
\r
146 mainWindow.radio_avgBitrate.Checked = true;
\r
147 mainWindow.text_bitrate.Text = presetQuery.AverageVideoBitrate;
\r
149 if (presetQuery.VideoTargetSize != null)
\r
151 mainWindow.radio_targetFilesize.Checked = true;
\r
152 mainWindow.text_filesize.Text = presetQuery.VideoTargetSize;
\r
156 if (presetQuery.VideoQuality != 0)
\r
158 mainWindow.radio_cq.Checked = true;
\r
159 if (presetQuery.VideoEncoder == "H.264 (x264)")
\r
162 double x264step = Properties.Settings.Default.x264cqstep;
\r
163 double presetValue = presetQuery.VideoQuality;
\r
165 double x = 51 / x264step;
\r
167 double calculated = presetValue / x264step;
\r
168 calculated = x - calculated;
\r
170 int.TryParse(calculated.ToString(), out value);
\r
172 // This will sometimes occur when the preset was generated
\r
173 // with a different granularity, so, round and try again.
\r
176 double val = Math.Round(calculated, 0);
\r
177 int.TryParse(val.ToString(), out value);
\r
179 mainWindow.slider_videoQuality.Value = value;
\r
184 int.TryParse(presetQuery.VideoQuality.ToString(), out presetVal);
\r
185 mainWindow.slider_videoQuality.Value = presetVal;
\r
189 mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;
\r
192 mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;
\r
194 mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;
\r
198 #region Chapter Markers
\r
200 if (presetQuery.ChapterMarkers)
\r
202 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Checked;
\r
203 mainWindow.Check_ChapterMarkers.Enabled = true;
\r
206 mainWindow.Check_ChapterMarkers.CheckState = CheckState.Unchecked;
\r
211 // Clear the audio listing
\r
212 mainWindow.AudioSettings.clearAudioList();
\r
214 if (presetQuery.AudioInformation != null)
\r
215 foreach (AudioTrack track in presetQuery.AudioInformation)
\r
217 ListViewItem newTrack = new ListViewItem(mainWindow.AudioSettings.getNewID().ToString());
\r
219 newTrack.SubItems.Add("Automatic");
\r
220 newTrack.SubItems.Add(track.Encoder);
\r
221 newTrack.SubItems.Add(track.MixDown);
\r
222 newTrack.SubItems.Add(track.SampleRate);
\r
223 if (track.Encoder.Contains("AC3"))
\r
224 newTrack.SubItems.Add("Auto");
\r
226 newTrack.SubItems.Add(track.Bitrate);
\r
227 newTrack.SubItems.Add(track.DRC);
\r
228 mainWindow.AudioSettings.addTrackForPreset(newTrack);
\r
233 mainWindow.x264Panel.x264Query = presetQuery.H264Query;
\r
235 // Set the preset name
\r
236 mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";
\r