diff options
Diffstat (limited to 'win/C#')
-rw-r--r-- | win/C#/Functions/QueryGenerator.cs | 214 | ||||
-rw-r--r-- | win/C#/HandBrakeCS.csproj | 2 | ||||
-rw-r--r-- | win/C#/Model/QueryEncodeMode.cs | 16 | ||||
-rw-r--r-- | win/C#/Model/QueryPictureSettingsMode.cs | 18 | ||||
-rw-r--r-- | win/C#/frmMain.cs | 22 | ||||
-rw-r--r-- | win/C#/frmPreview.cs | 4 |
6 files changed, 209 insertions, 67 deletions
diff --git a/win/C#/Functions/QueryGenerator.cs b/win/C#/Functions/QueryGenerator.cs index 203e4e659..f29bdd4fe 100644 --- a/win/C#/Functions/QueryGenerator.cs +++ b/win/C#/Functions/QueryGenerator.cs @@ -11,30 +11,86 @@ namespace Handbrake.Functions using System.IO;
using System.Windows.Forms;
+ using Handbrake.Model;
+
/// <summary>
/// Generate a CLI Query for HandBrakeCLI
/// </summary>
public class QueryGenerator
{
- /// <summary>
- /// Generates a full CLI query for either encoding or previe encoeds if duration and preview are defined.
- /// </summary>
- /// <param name="mainWindow">
- /// The Main Window
- /// </param>
- /// <param name="mode">
- /// What Mode. (Point to Point Encoding) Chapters, Seconds, Frames OR Preview Encode
- /// </param>
- /// <param name="duration">
- /// Time in seconds for preview mode
- /// </param>
- /// <param name="preview">
- /// Preview --start-at-preview (int)
- /// </param>
- /// <returns>
- /// CLI Query
- /// </returns>
- public static string GenerateCliQuery(frmMain mainWindow, int mode, int duration, string preview)
+ public static string GenerateQueryForPreset(frmMain mainWindow, QueryPictureSettingsMode mode, bool filters, int width, int height)
+ {
+ string query = string.Empty;
+
+ query += GenerateTabbedComponentsQuery(mainWindow, filters, mode, width, height);
+
+ return query;
+ }
+
+ public static string GeneratePreviewQuery(frmMain mainWindow, int duration, string preview)
+ {
+ string query = string.Empty;
+
+ query += SourceQuery(mainWindow, 3, duration, preview);
+
+ query += DestinationQuery(mainWindow, QueryEncodeMode.Preview);
+
+ query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0);
+
+ return query;
+ }
+
+ public static string GenerateFullQuery(frmMain mainWindow)
+ {
+ string query = string.Empty;
+
+ query += SourceQuery(mainWindow, mainWindow.drop_mode.SelectedIndex, 0, null);
+
+ query += DestinationQuery(mainWindow, QueryEncodeMode.Standard);
+
+ query += GenerateTabbedComponentsQuery(mainWindow, true, QueryPictureSettingsMode.UserInterfaceSettings, 0, 0);
+
+ return query;
+ }
+
+ #region Individual Query Sections
+
+ private static string GenerateTabbedComponentsQuery(frmMain mainWindow, bool filters, QueryPictureSettingsMode mode, int width, int height)
+ {
+ string query = string.Empty;
+
+ // Output Settings
+ query += OutputSettingsQuery(mainWindow);
+
+ // Filters Panel
+ if (filters)
+ query += FiltersQuery(mainWindow);
+
+ // Picture Settings
+ query += PictureSettingsQuery(mainWindow, mode, width, height);
+
+ // Video Settings
+ query += VideoSettingsQuery(mainWindow);
+
+ // Audio Settings
+ query += AudioSettingsQuery(mainWindow);
+
+ // Subtitles Panel
+ query += mainWindow.Subtitles.GetCliQuery;
+
+ // Chapter Markers
+ query += ChapterMarkersQuery(mainWindow);
+
+ // X264 Panel
+ query += X264Query(mainWindow);
+
+ // Extra Settings
+ query += ExtraSettings();
+
+ return query;
+ }
+
+ private static string SourceQuery(frmMain mainWindow, int mode, int duration, string preview)
{
string query = string.Empty;
@@ -82,31 +138,32 @@ namespace Handbrake.Functions query += " --previews " + Properties.Settings.Default.previewScanCount + " ";
query += " --start-at-preview " + preview;
query += " --stop-at duration:" + duration + " ";
-
- if (mainWindow.text_destination.Text != string.Empty)
- query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text.Replace(".m", "_sample.m"));
break;
default:
break;
}
- if (mode != 3)
- query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text);
-
- query += GenerateTabbedComponentsQuery(mainWindow);
return query;
}
- /// <summary>
- /// Generates part of the CLI query, for the tabbed components only.
- /// </summary>
- /// <param name="mainWindow">frmMain the main window</param>
- /// <returns>The CLI Query for the Tab Screens on the main window</returns>
- public static string GenerateTabbedComponentsQuery(frmMain mainWindow)
+ private static string DestinationQuery(frmMain mainWindow, QueryEncodeMode mode)
{
string query = string.Empty;
- #region Output Settings Box
+ if (mode != QueryEncodeMode.Preview)
+ query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text);
+ else
+ {
+ if (mainWindow.text_destination.Text != string.Empty)
+ query += string.Format(" -o \"{0}\" ", mainWindow.text_destination.Text.Replace(".m", "_sample.m"));
+ }
+
+ return query;
+ }
+
+ private static string OutputSettingsQuery(frmMain mainWindow)
+ {
+ string query = string.Empty;
query += " -f " + mainWindow.drop_format.Text.ToLower().Replace(" file", string.Empty);
@@ -120,17 +177,42 @@ namespace Handbrake.Functions if (mainWindow.check_optimiseMP4.Checked)
query += " -O ";
- #endregion
-
- #region Picture Settings Tab
+ return query;
+ }
- if (mainWindow.PictureSettings.text_width.Value != 0)
- if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic
- query += " -w " + mainWindow.PictureSettings.text_width.Text;
+ private static string PictureSettingsQuery(frmMain mainWindow, QueryPictureSettingsMode mode, int width, int height)
+ {
+ string query = string.Empty;
- if (mainWindow.PictureSettings.text_height.Value != 0 && mainWindow.PictureSettings.text_height.Text != string.Empty)
- if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 || mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic
+ if (mode == QueryPictureSettingsMode.UserInterfaceSettings)
+ {
+ if (mainWindow.PictureSettings.text_width.Value != 0)
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic
+ query += " -w " + mainWindow.PictureSettings.text_width.Text;
+
+ if (mainWindow.PictureSettings.text_height.Value != 0 &&
+ mainWindow.PictureSettings.text_height.Text != string.Empty)
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 ||
+ mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic
query += " -l " + mainWindow.PictureSettings.text_height.Text;
+ }
+ else if (mode == QueryPictureSettingsMode.Custom) // For Add Preset Only.
+ {
+ query += " -X " + width;
+ query += " -Y " + height;
+ }
+ else if (mode == QueryPictureSettingsMode.SourceMaximum) // For Add Preset Only.
+ {
+ if (mainWindow.PictureSettings.text_width.Value != 0)
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex != 1) // Prevent usage for strict anamorphic
+ query += " -X " + mainWindow.PictureSettings.text_width.Text;
+
+ if (mainWindow.PictureSettings.text_height.Value != 0 &&
+ mainWindow.PictureSettings.text_height.Text != string.Empty)
+ if (mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 0 ||
+ mainWindow.PictureSettings.drp_anamorphic.SelectedIndex == 3) // Prevent usage for strict anamorphic
+ query += " -Y " + mainWindow.PictureSettings.text_height.Text;
+ }
string cropTop = mainWindow.PictureSettings.crop_top.Text;
string cropBottom = mainWindow.PictureSettings.crop_bottom.Text;
@@ -185,12 +267,17 @@ namespace Handbrake.Functions break;
}
- #endregion
+ return query;
+ }
- // Filters Panel
- query += mainWindow.Filters.GetCliQuery;
+ private static string FiltersQuery(frmMain mainWindow)
+ {
+ return mainWindow.Filters.GetCliQuery;
+ }
- #region Video Settings Tab
+ private static string VideoSettingsQuery(frmMain mainWindow)
+ {
+ string query = string.Empty;
switch (mainWindow.drp_videoEncoder.Text)
{
@@ -251,9 +338,12 @@ namespace Handbrake.Functions if (mainWindow.checkMaximumFramerate.Checked)
query += " --pfr ";
- #endregion
+ return query;
+ }
- #region Audio Settings Tab
+ private static string AudioSettingsQuery(frmMain mainWindow)
+ {
+ string query = string.Empty;
DataGridView audioTracks = mainWindow.AudioSettings.GetAudioPanel();
List<string> tracks = new List<string>();
@@ -398,12 +488,12 @@ namespace Handbrake.Functions if (audioItems.Trim() != String.Empty)
query += " -D " + audioItems;
- #endregion
-
- // Subtitles Panel
- query += mainWindow.Subtitles.GetCliQuery;
+ return query;
+ }
- #region Chapter Markers
+ private static string ChapterMarkersQuery(frmMain mainWindow)
+ {
+ string query = string.Empty;
// 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.
@@ -433,10 +523,19 @@ namespace Handbrake.Functions query += " -m";
}
- #endregion
+ return query;
+ }
- // X264 Panel
- query += " -x " + mainWindow.x264Panel.X264Query;
+ private static string X264Query(frmMain mainWindow)
+ {
+ if (string.IsNullOrEmpty(mainWindow.x264Panel.X264Query)) return string.Empty;
+
+ return " -x " + mainWindow.x264Panel.X264Query;
+ }
+
+ private static string ExtraSettings()
+ {
+ string query = string.Empty;
// Verbosity Level
query += " -v " + Properties.Settings.Default.verboseLevel;
@@ -448,6 +547,10 @@ namespace Handbrake.Functions return query;
}
+ #endregion
+
+ #region Helpers
+
/// <summary>
/// Return the CLI Mixdown name
/// </summary>
@@ -533,5 +636,6 @@ namespace Handbrake.Functions return false;
}
}
+ #endregion
}
}
\ No newline at end of file diff --git a/win/C#/HandBrakeCS.csproj b/win/C#/HandBrakeCS.csproj index 5e0a123ff..75d4621e7 100644 --- a/win/C#/HandBrakeCS.csproj +++ b/win/C#/HandBrakeCS.csproj @@ -217,6 +217,8 @@ <DependentUpon>frmExceptionWindow.cs</DependentUpon>
</Compile>
<Compile Include="Model\ActivityLogMode.cs" />
+ <Compile Include="Model\QueryPictureSettingsMode.cs" />
+ <Compile Include="Model\QueryEncodeMode.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="frmPreview.cs">
<SubType>Form</SubType>
diff --git a/win/C#/Model/QueryEncodeMode.cs b/win/C#/Model/QueryEncodeMode.cs new file mode 100644 index 000000000..63e6eccff --- /dev/null +++ b/win/C#/Model/QueryEncodeMode.cs @@ -0,0 +1,16 @@ +/* AddPresetMode.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace Handbrake.Model
+{
+ /// <summary>
+ /// Picture Settings Mode when adding presets
+ /// </summary>
+ public enum QueryEncodeMode
+ {
+ Preview,
+ Standard
+ }
+}
\ No newline at end of file diff --git a/win/C#/Model/QueryPictureSettingsMode.cs b/win/C#/Model/QueryPictureSettingsMode.cs new file mode 100644 index 000000000..539027145 --- /dev/null +++ b/win/C#/Model/QueryPictureSettingsMode.cs @@ -0,0 +1,18 @@ +/* AddPresetMode.cs $
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
+
+namespace Handbrake.Model
+{
+ /// <summary>
+ /// Picture Settings Mode when adding presets
+ /// </summary>
+ public enum QueryPictureSettingsMode
+ {
+ None,
+ Custom,
+ SourceMaximum,
+ UserInterfaceSettings
+ }
+}
\ No newline at end of file diff --git a/win/C#/frmMain.cs b/win/C#/frmMain.cs index 7074f1155..b0fb65ce2 100644 --- a/win/C#/frmMain.cs +++ b/win/C#/frmMain.cs @@ -538,7 +538,7 @@ namespace Handbrake /// </param>
private void btn_new_preset_Click(object sender, EventArgs e)
{
- Form preset = new frmAddPreset(this, QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
+ Form preset = new frmAddPreset(this, QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0),
presetHandler);
preset.ShowDialog();
}
@@ -650,6 +650,7 @@ namespace Handbrake /// </param>
private void pmnu_saveChanges_Click(object sender, EventArgs e)
{
+ // TODO this requires a re-think since the Query Editor has changed.
DialogResult result =
MessageBox.Show(
"Do you wish to include picture settings when updating the preset: " +
@@ -657,10 +658,10 @@ namespace Handbrake MessageBoxIcon.Question);
if (result == DialogResult.Yes)
presetHandler.Update(treeView_presets.SelectedNode.Text,
- QueryGenerator.GenerateTabbedComponentsQuery(this), true);
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), true);
else if (result == DialogResult.No)
presetHandler.Update(treeView_presets.SelectedNode.Text,
- QueryGenerator.GenerateTabbedComponentsQuery(this), false);
+ QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), false);
}
/// <summary>
@@ -717,7 +718,8 @@ namespace Handbrake /// </param>
private void btn_addPreset_Click(object sender, EventArgs e)
{
- Form preset = new frmAddPreset(this, QueryGenerator.GenerateTabbedComponentsQuery(this), presetHandler);
+ // TODO this requires a re-think due to the Query Editor Changing.
+ Form preset = new frmAddPreset(this, QueryGenerator.GenerateQueryForPreset(this, QueryPictureSettingsMode.SourceMaximum, true, 0, 0), presetHandler);
preset.ShowDialog();
}
@@ -922,7 +924,7 @@ namespace Handbrake {
PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
presetHandler.Update(parsed.PresetName + " (Imported)",
- QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
+ QueryGenerator.GenerateFullQuery(this),
parsed.UsesPictureSettings);
}
}
@@ -930,7 +932,7 @@ namespace Handbrake {
PresetLoader.LoadPreset(this, parsed, parsed.PresetName, parsed.UsesPictureSettings);
if (presetHandler.Add(parsed.PresetName + " (Imported)",
- QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null),
+ QueryGenerator.GenerateFullQuery(this),
parsed.UsesPictureSettings))
{
TreeNode preset_treeview = new TreeNode(parsed.PresetName + " (Imported)")
@@ -1051,10 +1053,10 @@ namespace Handbrake if (encodeQueue.Count != 0 || (!string.IsNullOrEmpty(jobSourcePath) && !string.IsNullOrEmpty(jobDestination)))
{
- string generatedQuery = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
+ string generatedQuery = QueryGenerator.GenerateFullQuery(this);
string specifiedQuery = rtf_query.Text != string.Empty
? rtf_query.Text
- : QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
+ : QueryGenerator.GenerateFullQuery(this);
string query = string.Empty;
// Check to make sure the generated query matches the GUI settings
@@ -1135,7 +1137,7 @@ namespace Handbrake private void btn_add2Queue_Click(object sender, EventArgs e)
{
// Get the CLI query or use the query editor if it's not empty.
- string query = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
+ string query = QueryGenerator.GenerateFullQuery(this);
if (!string.IsNullOrEmpty(rtf_query.Text))
query = rtf_query.Text;
@@ -1955,7 +1957,7 @@ namespace Handbrake // Query Editor Tab
private void btn_generate_Query_Click(object sender, EventArgs e)
{
- rtf_query.Text = QueryGenerator.GenerateCliQuery(this, drop_mode.SelectedIndex, 0, null);
+ rtf_query.Text = QueryGenerator.GenerateFullQuery(this);
}
private void btn_clear_Click(object sender, EventArgs e)
diff --git a/win/C#/frmPreview.cs b/win/C#/frmPreview.cs index 2c9e6c87d..a5bf3310e 100644 --- a/win/C#/frmPreview.cs +++ b/win/C#/frmPreview.cs @@ -219,7 +219,7 @@ namespace Handbrake this.Text += " (Encoding)";
int duration;
int.TryParse(cb_duration.Text, out duration);
- string query = QueryGenerator.GenerateCliQuery(this.mainWindow, 3, duration, cb_preview.Text);
+ string query = QueryGenerator.GeneratePreviewQuery(this.mainWindow, duration, cb_preview.Text);
ThreadPool.QueueUserWorkItem(this.CreatePreview, query);
}
@@ -271,7 +271,7 @@ namespace Handbrake this.Text += " (Encoding)";
int duration;
int.TryParse(cb_duration.Text, out duration);
- string query = QueryGenerator.GenerateCliQuery(this.mainWindow, 3, duration, cb_preview.Text);
+ string query = QueryGenerator.GeneratePreviewQuery(this.mainWindow, duration, cb_preview.Text);
ThreadPool.QueueUserWorkItem(this.CreatePreview, query);
}
|