OSDN Git Service

remove crf flag and all uses of it
[handbrake-jp/handbrake-jp-git.git] / win / C# / Functions / PresetLoader.cs
index 8fabbe6..3018b91 100644 (file)
@@ -1,4 +1,11 @@
-using System;\r
+/*  PresetLoader.cs $\r
+       \r
+          This file is part of the HandBrake source code.\r
+          Homepage: <http://handbrake.fr>.\r
+          It may be used under the terms of the GNU General Public License. */\r
+\r
+using System;\r
+using System.Drawing;\r
 using System.Windows.Forms;\r
 \r
 namespace Handbrake.Functions\r
@@ -39,15 +46,20 @@ namespace Handbrake.Functions
 \r
             if (presetQuery.Format != null)\r
             {\r
-                if (presetQuery.Format == "mp4")\r
-                    mainWindow.drop_format.SelectedIndex = 0;\r
-                else if (presetQuery.Format == "m4v")\r
-                    mainWindow.drop_format.SelectedIndex = 1;\r
+                if (presetQuery.Format == "mp4" || presetQuery.Format == "m4v")\r
+                {\r
+                    if (mainWindow.drop_format.SelectedIndex == 0)\r
+                        mainWindow.SetExtension(".mp4");\r
+                    else \r
+                        mainWindow.drop_format.SelectedIndex = 0;\r
+                }\r
                 else if (presetQuery.Format == "mkv")\r
-                    mainWindow.drop_format.SelectedIndex = 2;\r
-\r
-                if (presetQuery.ChapterMarkers && presetQuery.Format == "mp4")\r
-                    mainWindow.drop_format.SelectedIndex = 1;\r
+                {\r
+                    if(mainWindow.drop_format.SelectedIndex == 1)\r
+                        mainWindow.SetExtension(".mkv");\r
+                    else\r
+                        mainWindow.drop_format.SelectedIndex = 1;\r
+                }\r
             }\r
 \r
             mainWindow.check_iPodAtom.CheckState = presetQuery.IpodAtom ? CheckState.Checked : CheckState.Unchecked;\r
@@ -61,17 +73,10 @@ namespace Handbrake.Functions
             #endregion\r
 \r
             #region Picture\r
-            mainWindow.check_autoCrop.Checked = true;\r
-            if (presetQuery.CropBottom == "0" && presetQuery.CropTop == "0")\r
-                if (presetQuery.CropLeft == "0" && presetQuery.CropRight == "0")\r
-                    mainWindow.check_customCrop.Checked = true;\r
-\r
-            mainWindow.text_width.Text = "";\r
-            mainWindow.text_height.Text = "";\r
-\r
-            if (pictureSettings)\r
+            mainWindow.PictureSettings.check_autoCrop.Checked = true;\r
+            if (pictureSettings) // only Load picture settings if the perset requires it\r
             {\r
-                if (presetQuery.CropTop != null)\r
+                if (presetQuery.CropValues != null)\r
                 {\r
                     int top, bottom, left, right;\r
                     int.TryParse(presetQuery.CropTop, out top);\r
@@ -79,69 +84,59 @@ namespace Handbrake.Functions
                     int.TryParse(presetQuery.CropLeft, out left);\r
                     int.TryParse(presetQuery.CropRight, out right);\r
 \r
-                    mainWindow.check_customCrop.Checked = true;\r
-                    mainWindow.text_top.Value = top;\r
-                    mainWindow.text_bottom.Value = bottom;\r
-                    mainWindow.text_left.Value = left;\r
-                    mainWindow.text_right.Value = right;\r
+                    mainWindow.PictureSettings.check_customCrop.Checked = true;\r
+                    mainWindow.PictureSettings.crop_top.Value = top;\r
+                    mainWindow.PictureSettings.crop_bottom.Value = bottom;\r
+                    mainWindow.PictureSettings.crop_left.Value = left;\r
+                    mainWindow.PictureSettings.crop_right.Value = right;\r
                 }\r
-\r
-                if (presetQuery.Width != 0)\r
-                    mainWindow.text_width.Text = presetQuery.Width.ToString();\r
-\r
-                if (presetQuery.Height != 0)\r
-                    mainWindow.text_height.Text = presetQuery.Height.ToString();\r
             }\r
+            \r
+            // Set the anamorphic mode 0,1,2,3\r
+            mainWindow.PictureSettings.drp_anamorphic.SelectedIndex = presetQuery.AnamorphicMode;\r
 \r
-            mainWindow.drp_anamorphic.SelectedIndex = presetQuery.Anamorphic ? 1 : 0;\r
+            // Aspect Ratio\r
+            mainWindow.PictureSettings.check_KeepAR.CheckState = presetQuery.keepDisplayAsect ? CheckState.Checked : CheckState.Unchecked;\r
+                \r
+            // Set the Width and height as Required.\r
+            if (presetQuery.Width != 0)\r
+                mainWindow.PictureSettings.text_width.Value = presetQuery.Width;\r
 \r
-            if (presetQuery.LooseAnamorphic)\r
-                mainWindow.drp_anamorphic.SelectedIndex = 2;\r
-            else\r
-            {\r
-                if (presetQuery.Anamorphic != true)\r
-                    mainWindow.drp_anamorphic.SelectedIndex = 0;\r
-            }\r
+            if (presetQuery.Height != 0)\r
+                mainWindow.PictureSettings.text_height.Value = presetQuery.Height;\r
 \r
-            // Set the public max width and max height varibles in frmMain\r
-            // These are used by the query generator to determine if it should use -X or -w  / -Y or -h\r
+            // Max Width/Height override Width/Height\r
             if (presetQuery.MaxWidth != 0)\r
-            {\r
-                mainWindow.text_width.Text = presetQuery.MaxWidth.ToString();\r
-                mainWindow.maxWidth = presetQuery.MaxWidth;\r
-            }\r
+                mainWindow.PictureSettings.text_width.Value = presetQuery.MaxWidth;\r
 \r
             if (presetQuery.MaxHeight != 0)\r
-            {\r
-                mainWindow.text_height.Text = presetQuery.MaxHeight.ToString();\r
-                mainWindow.maxHeight = presetQuery.MaxHeight;\r
-            }\r
+                mainWindow.PictureSettings.text_height.Value = presetQuery.MaxHeight;\r
 \r
+            mainWindow.PictureSettings.PresetMaximumResolution = new Size(presetQuery.MaxWidth, presetQuery.MaxHeight);\r
 \r
-            #endregion\r
+            // Case where both height and max height are 0 - For built-in presets\r
+            if (presetQuery.MaxHeight == 0 && presetQuery.Height == 0)\r
+                mainWindow.PictureSettings.text_height.Value = 0;\r
 \r
-            #region Filters\r
+            if (presetQuery.MaxWidth == 0 && presetQuery.Width == 0)\r
+                if (mainWindow.selectedTitle != null && mainWindow.selectedTitle.Resolution.Width != 0)\r
+                    mainWindow.PictureSettings.text_width.Value = mainWindow.selectedTitle.Resolution.Width;\r
 \r
-            mainWindow.ctl_decomb.setOption(presetQuery.Decomb);\r
+            // Custom Anamorphic Controls\r
+            mainWindow.PictureSettings.updownDisplayWidth.Text = presetQuery.displayWidthValue.ToString();\r
+            mainWindow.PictureSettings.updownParHeight.Text = presetQuery.pixelAspectWidth.ToString();\r
+            mainWindow.PictureSettings.updownParWidth.Text = presetQuery.pixelAspectHeight.ToString();\r
+            mainWindow.PictureSettings.drp_modulus.SelectedItem = presetQuery.AnamorphicModulus;\r
 \r
-            if (mainWindow.ctl_decomb.getDropValue == "Off")\r
-                mainWindow.ctl_deinterlace.setOption(presetQuery.DeInterlace);\r
-            else\r
-                mainWindow.ctl_deinterlace.setOption("None"); // Don't want decomb and deinterlace on at the same time\r
-\r
-            mainWindow.ctl_denoise.setOption(presetQuery.DeNoise);\r
-            mainWindow.ctl_detelecine.setOption(presetQuery.DeTelecine);\r
+            #endregion\r
 \r
-            if (presetQuery.DeBlock != 0)\r
-            {\r
-                mainWindow.slider_deblock.Value = presetQuery.DeBlock;\r
-                mainWindow.lbl_deblockVal.Text = presetQuery.DeBlock.ToString();\r
-            }\r
-            else\r
-            {\r
-                mainWindow.slider_deblock.Value = 4;\r
-                mainWindow.lbl_deblockVal.Text = "Off";\r
-            }\r
+            #region Filters\r
+            mainWindow.Filters.setDecomb(presetQuery.Decomb);\r
+            mainWindow.Filters.setDeInterlace(presetQuery.DeInterlace);\r
+            mainWindow.Filters.setDeNoise(presetQuery.DeNoise);\r
+            mainWindow.Filters.setDeTelecine(presetQuery.DeTelecine);\r
+            mainWindow.Filters.setDeBlock(presetQuery.DeBlock);\r
+            mainWindow.Filters.setGrayScale(presetQuery.Grayscale);\r
             #endregion\r
 \r
             #region Video\r
@@ -164,15 +159,10 @@ namespace Handbrake.Functions
                 mainWindow.radio_cq.Checked = true;\r
                 if (presetQuery.VideoEncoder == "H.264 (x264)")\r
                 {\r
+                    double cqStep = Properties.Settings.Default.x264cqstep;\r
                     int value;\r
-                    System.Globalization.CultureInfo culture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US");\r
-\r
-                    double x264step;\r
+                    double x264step = cqStep;\r
                     double presetValue = presetQuery.VideoQuality;\r
-                    double.TryParse(Properties.Settings.Default.x264cqstep,\r
-                                    System.Globalization.NumberStyles.Number,\r
-                                    culture,\r
-                                    out x264step);\r
 \r
                     double x = 51 / x264step;\r
 \r
@@ -188,8 +178,8 @@ namespace Handbrake.Functions
                         double val = Math.Round(calculated, 0);\r
                         int.TryParse(val.ToString(), out value);\r
                     }\r
-\r
-                    mainWindow.slider_videoQuality.Value = value;\r
+                    if (value < mainWindow.slider_videoQuality.Maximum)\r
+                        mainWindow.slider_videoQuality.Value = value;\r
                 }\r
                 else\r
                 {\r
@@ -201,8 +191,6 @@ namespace Handbrake.Functions
 \r
             mainWindow.check_2PassEncode.CheckState = presetQuery.TwoPass ? CheckState.Checked : CheckState.Unchecked;\r
 \r
-            mainWindow.check_grayscale.CheckState = presetQuery.Grayscale ? CheckState.Checked : CheckState.Unchecked;\r
-\r
             mainWindow.drp_videoFramerate.Text = presetQuery.VideoFramerate;\r
 \r
             mainWindow.check_turbo.CheckState = presetQuery.TurboFirstPass ? CheckState.Checked : CheckState.Unchecked;\r
@@ -223,38 +211,31 @@ namespace Handbrake.Functions
 \r
             #region Audio\r
             // Clear the audio listing\r
-            mainWindow.lv_audioList.Items.Clear();\r
+            mainWindow.AudioSettings.ClearAudioList();\r
 \r
             if (presetQuery.AudioInformation != null)\r
                 foreach (AudioTrack track in presetQuery.AudioInformation)\r
                 {\r
-                    ListViewItem newTrack = new ListViewItem("Automatic");\r
+                    ListViewItem newTrack = new ListViewItem(mainWindow.AudioSettings.GetNewID().ToString());\r
+\r
+                    newTrack.SubItems.Add("Automatic");\r
                     newTrack.SubItems.Add(track.Encoder);\r
                     newTrack.SubItems.Add(track.MixDown);\r
                     newTrack.SubItems.Add(track.SampleRate);\r
-                    newTrack.SubItems.Add(track.Bitrate);\r
+                    if (track.Encoder.Contains("AC3"))\r
+                        newTrack.SubItems.Add("Auto");\r
+                    else\r
+                        newTrack.SubItems.Add(track.Bitrate);\r
                     newTrack.SubItems.Add(track.DRC);\r
-                    mainWindow.lv_audioList.Items.Add(newTrack);\r
+                    mainWindow.AudioSettings.AddTrackForPreset(newTrack);\r
                 }\r
-\r
-            // Subtitle Stuff\r
-            mainWindow.drp_subtitle.Text = presetQuery.Subtitles;\r
-\r
-            if (presetQuery.ForcedSubtitles)\r
-            {\r
-                mainWindow.check_forced.CheckState = CheckState.Checked;\r
-                mainWindow.check_forced.Enabled = true;\r
-            }\r
-            else\r
-                mainWindow.check_forced.CheckState = CheckState.Unchecked;\r
-\r
             #endregion\r
 \r
             #region Other\r
             mainWindow.x264Panel.x264Query = presetQuery.H264Query;\r
 \r
             // Set the preset name\r
-            mainWindow.groupBox_output.Text = "Output Settings (Preset: " + name + ")";\r
+            mainWindow.labelPreset.Text = "Output Settings (Preset: " + name + ")";\r
             #endregion\r
         }\r
     }\r