using System.IO;\r
using System.Windows.Forms;\r
\r
+ using Handbrake.Model;\r
+\r
/// <summary>\r
/// Generate a CLI Query for HandBrakeCLI\r
/// </summary>\r
public class QueryGenerator\r
{\r
- /// <summary>\r
- /// Generates a full CLI query for either encoding or previe encoeds if duration and preview are defined.\r
- /// </summary>\r
- /// <param name="mainWindow">\r
- /// The Main Window\r
- /// </param>\r
- /// <param name="mode">\r
- /// What Mode. (Point to Point Encoding) Chapters, Seconds, Frames OR Preview Encode\r
- /// </param>\r
- /// <param name="duration">\r
- /// Time in seconds for preview mode\r
- /// </param>\r
- /// <param name="preview">\r
- /// Preview --start-at-preview (int) \r
- /// </param>\r
- /// <returns>\r
- /// CLI Query \r
- /// </returns>\r
- public static string GenerateCliQuery(frmMain mainWindow, int mode, int duration, string preview)\r
+ public static string GenerateQueryForPreset(frmMain mainWindow, QueryPictureSettingsMode mode, bool filters, int width, int height)\r
+ {\r
+ string query = string.Empty;\r
+\r
+ query += GenerateTabbedComponentsQuery(mainWindow, filters, mode, width, height);\r
+\r
+ return query;\r
+ }\r
+\r
+ public static string GeneratePreviewQuery(frmMain mainWindow, int duration, string preview)\r
+ {\r
+ string query = string.Empty;\r
+\r
+ query += SourceQuery(mainWindow, 3, duration, preview);\r
+\r
+ query += DestinationQuery(mainWindow, QueryEncodeMode.Preview);\r
+\r
+ query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0);\r
+\r
+ return query;\r
+ }\r
+\r
+ public static string GenerateFullQuery(frmMain mainWindow)\r
+ {\r
+ string query = string.Empty;\r
+\r
+ query += SourceQuery(mainWindow, mainWindow.drop_mode.SelectedIndex, 0, null);\r
+\r
+ query += DestinationQuery(mainWindow, QueryEncodeMode.Standard);\r
+\r
+ query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0);\r
+\r
+ return query;\r
+ }\r
+\r
+ #region Individual Query Sections\r
+\r
+ private static string GenerateTabbedComponentsQuery(frmMain mainWindow, bool filters, QueryPictureSettingsMode mode, int width, int height)\r
+ {\r
+ string query = string.Empty;\r
+\r
+ // Output Settings\r
+ query += OutputSettingsQuery(mainWindow);\r
+\r
+ // Filters Panel\r
+ if (filters)\r
+ query += FiltersQuery(mainWindow);\r
+\r
+ // Picture Settings\r
+ query += PictureSettingsQuery(mainWindow, mode, width, height);\r
+\r
+ // Video Settings\r
+ query += VideoSettingsQuery(mainWindow);\r
+\r
+ // Audio Settings\r
+ query += AudioSettingsQuery(mainWindow);\r
+\r
+ // Subtitles Panel\r
+ query += mainWindow.Subtitles.GetCliQuery;\r
+\r
+ // Chapter Markers\r
+ query += ChapterMarkersQuery(mainWindow);\r
+\r
+ // X264 Panel\r
+ query += X264Query(mainWindow);\r
+\r
+ // Extra Settings\r
+ query += ExtraSettings();\r
+\r
+ return query;\r
+ }\r
+\r
+ private static string SourceQuery(frmMain mainWindow, int mode, int duration, string preview)\r
{\r
string query = string.Empty;\r
\r
query += " --previews " + Properties.Settings.Default.previewScanCount + " ";\r
query += " --start-at-preview " + preview;\r
query += " --stop-at duration:" + duration + " ";\r
-\r
- if (mainWindow.text_destination.Text != string.Empty)\r
- query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text.Replace(".m", "_sample.m"));\r
break;\r
default:\r
break;\r
}\r
- if (mode != 3)\r
- query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text);\r
-\r
- query += GenerateTabbedComponentsQuery(mainWindow);\r
\r
return query;\r
}\r
\r
- /// <summary>\r
- /// Generates part of the CLI query, for the tabbed components only.\r
- /// </summary>\r
- /// <param name="mainWindow">frmMain the main window</param>\r
- /// <returns>The CLI Query for the Tab Screens on the main window</returns>\r
- public static string GenerateTabbedComponentsQuery(frmMain mainWindow)\r
+ private static string DestinationQuery(frmMain mainWindow, QueryEncodeMode mode)\r
{\r
string query = string.Empty;\r
\r
- #region Output Settings Box\r
+ if (mode != QueryEncodeMode.Preview)\r
+ query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text);\r
+ else\r
+ {\r
+ if (mainWindow.text_destination.Text != string.Empty)\r
+ query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text.Replace(".m", "_sample.m"));\r
+ }\r
+\r
+ return query;\r
+ }\r
+\r
+ private static string OutputSettingsQuery(frmMain mainWindow)\r
+ {\r
+ string query = string.Empty;\r
\r
query += " -f " + mainWindow.drop_format.Text.ToLower().Replace(" file", string.Empty);\r
\r
if (mainWindow.check_optimiseMP4.Checked)\r
query += " -O ";\r
\r
- #endregion\r
-\r
- #region Picture Settings Tab\r
+ return query;\r
+ }\r
\r
- if (mainWindow.PictureSettings.text_width.Value != 0)\r
- if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic\r
- query += " -w " + mainWindow.PictureSettings.text_width.Text;\r
+ private static string PictureSettingsQuery(frmMain mainWindow, QueryPictureSettingsMode mode, int width, int height)\r
+ {\r
+ string query = string.Empty;\r
\r
- if (mainWindow.PictureSettings.text_height.Value != 0 && mainWindow.PictureSettings.text_height.Text != string.Empty)\r
- if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 || mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic\r
+ if (mode == QueryPictureSettingsMode.UserInterfaceSettings)\r
+ {\r
+ if (mainWindow.PictureSettings.text_width.Value != 0)\r
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic\r
+ query += " -w " + mainWindow.PictureSettings.text_width.Text;\r
+\r
+ if (mainWindow.PictureSettings.text_height.Value != 0 &&\r
+ mainWindow.PictureSettings.text_height.Text != string.Empty)\r
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 ||\r
+ mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic\r
query += " -l " + mainWindow.PictureSettings.text_height.Text;\r
+ }\r
+ else if (mode == QueryPictureSettingsMode.Custom) // For Add Preset Only.\r
+ {\r
+ query += " -X " + width;\r
+ query += " -Y " + height;\r
+ }\r
+ else if (mode == QueryPictureSettingsMode.SourceMaximum) // For Add Preset Only.\r
+ {\r
+ if (mainWindow.PictureSettings.text_width.Value != 0)\r
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic\r
+ query += " -X " + mainWindow.PictureSettings.text_width.Text;\r
+\r
+ if (mainWindow.PictureSettings.text_height.Value != 0 &&\r
+ mainWindow.PictureSettings.text_height.Text != string.Empty)\r
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 ||\r
+ mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic\r
+ query += " -Y " + mainWindow.PictureSettings.text_height.Text;\r
+ }\r
\r
string cropTop = mainWindow.PictureSettings.crop_top.Text;\r
string cropBottom = mainWindow.PictureSettings.crop_bottom.Text;\r
break;\r
}\r
\r
- #endregion\r
+ return query;\r
+ }\r
\r
- // Filters Panel\r
- query += mainWindow.Filters.GetCliQuery;\r
+ private static string FiltersQuery(frmMain mainWindow)\r
+ {\r
+ return mainWindow.Filters.GetCliQuery;\r
+ }\r
\r
- #region Video Settings Tab\r
+ private static string VideoSettingsQuery(frmMain mainWindow)\r
+ {\r
+ string query = string.Empty;\r
\r
switch (mainWindow.drp_videoEncoder.Text)\r
{\r
if (mainWindow.checkMaximumFramerate.Checked)\r
query += " --pfr ";\r
\r
- #endregion\r
+ return query;\r
+ }\r
\r
- #region Audio Settings Tab\r
+ private static string AudioSettingsQuery(frmMain mainWindow)\r
+ {\r
+ string query = string.Empty;\r
\r
DataGridView audioTracks = mainWindow.AudioSettings.GetAudioPanel();\r
List<string> tracks = new List<string>();\r
if (audioItems.Trim() != String.Empty)\r
query += " -D " + audioItems;\r
\r
- #endregion\r
-\r
- // Subtitles Panel\r
- query += mainWindow.Subtitles.GetCliQuery;\r
+ return query;\r
+ }\r
\r
- #region Chapter Markers\r
+ private static string ChapterMarkersQuery(frmMain mainWindow)\r
+ {\r
+ string query = string.Empty;\r
\r
// Attach Source name and dvd title to the start of the chapters.csv filename.\r
// This is for the queue. It allows different chapter name files for each title.\r
query += " -m";\r
}\r
\r
- #endregion\r
+ return query;\r
+ }\r
\r
- // X264 Panel\r
- query += " -x " + mainWindow.x264Panel.X264Query;\r
+ private static string X264Query(frmMain mainWindow)\r
+ {\r
+ if (string.IsNullOrEmpty(mainWindow.x264Panel.X264Query)) return string.Empty;\r
+\r
+ return " -x " + mainWindow.x264Panel.X264Query;\r
+ }\r
+\r
+ private static string ExtraSettings()\r
+ {\r
+ string query = string.Empty;\r
\r
// Verbosity Level\r
query += " -v " + Properties.Settings.Default.verboseLevel;\r
return query;\r
}\r
\r
+ #endregion\r
+\r
+ #region Helpers\r
+\r
/// <summary>\r
/// Return the CLI Mixdown name\r
/// </summary>\r
return false;\r
}\r
}\r
+ #endregion\r
}\r
}
\ No newline at end of file
/// </param>\r
private void btn_new_preset_Click(object sender, EventArgs e)\r
{\r
- Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ Form preset = new frmAddPreset(this, QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0),\r
presetHandler);\r
preset.ShowDialog();\r
}\r
/// </param>\r
private void pmnu_saveChanges_Click(object sender, EventArgs e)\r
{\r
+ // TODO this requires a re-think since the Query Editor has changed.\r
DialogResult result =\r
MessageBox.Show(\r
"Do you wish to include picture settings when updating the preset: " +\r
MessageBoxIcon.Question);\r
if (result == DialogResult.Yes)\r
presetHandler.Update(treeView_presets.SelectedNode.Text,\r
- QueryGenerator.GenerateTabbedComponentsQuery(this), true);\r
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);\r
else if (result == DialogResult.No)\r
presetHandler.Update(treeView_presets.SelectedNode.Text,\r
- QueryGenerator.GenerateTabbedComponentsQuery(this), false);\r
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);\r
}\r
\r
/// <summary>\r
/// </param>\r
private void btn_addPreset_Click(object sender, EventArgs e)\r
{\r
- Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);\r
+ // TODO this requires a re-think due to the Query Editor Changing.\r
+ Form preset = new frmAddPreset(this, QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), presetHandler);\r
preset.ShowDialog();\r
}\r
\r
{\r
PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
presetHandler.Update(parsed.PresetName + " (Imported)",\r
- QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ QueryGenerator.GenerateFullQuery(this),\r
parsed.UsesPictureSettings);\r
}\r
}\r
{\r
PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);\r
if (presetHandler.Add(parsed.PresetName + " (Imported)",\r
- QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),\r
+ QueryGenerator.GenerateFullQuery(this),\r
parsed.UsesPictureSettings))\r
{\r
TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")\r
\r
if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))\r
{\r
- string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ string generatedQuery = QueryGenerator.GenerateFullQuery(this);\r
string specifiedQuery = rtf_query.Text != string.Empty\r
? rtf_query.Text\r
- : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ : QueryGenerator.GenerateFullQuery(this);\r
string query = string.Empty;\r
\r
// Check to make sure the generated query matches the GUI settings\r
private void btn_add2Queue_Click(object sender, EventArgs e)\r
{\r
// Get the CLI query or use the query editor if it's not empty.\r
- string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ string query = QueryGenerator.GenerateFullQuery(this);\r
if (!string.IsNullOrEmpty(rtf_query.Text))\r
query = rtf_query.Text;\r
\r
// Query Editor Tab\r
private void btn_generate_Query_Click(object sender, EventArgs e)\r
{\r
- rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);\r
+ rtf_query.Text = QueryGenerator.GenerateFullQuery(this);\r
}\r
\r
private void btn_clear_Click(object sender, EventArgs e)\r