diff --git a/IFME/CustomForms/TimespanTextBox.cs b/IFME/CustomForms/TimespanTextBox.cs
deleted file mode 100644
index 7fcd38b..0000000
--- a/IFME/CustomForms/TimespanTextBox.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-using System;
-using System.Drawing;
-using System.Text.RegularExpressions;
-using System.Windows.Forms;
-
-namespace IFME
-{
- internal class TimespanTextBox : TextBox
- {
- private string lastValidText = "";
- public TimeSpan? MaxValue { get; set; } = null;
-
- public TimeSpan TimeSpan
- {
- get
- {
- TimeSpan.TryParse(this.Text, out var timeStart);
- return timeStart;
- }
- set
- {
- setValueTimespan(value);
- }
- }
-
- public TimespanTextBox()
- {
- this.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
- this.TextChanged += new EventHandler(this.textBox_Validating);
- }
-
- public TimespanTextBox(TimeSpan maxValue) : base()
- {
- this.MaxValue = maxValue;
- }
-
- public void setValueSeconds(float seconds)
- {
- setValueTimespan(TimeSpan.FromSeconds((double)(new decimal(seconds))));
- }
-
- private void setValueTimespan(TimeSpan timespan)
- {
- string sign = (timespan.TotalMilliseconds < 0) ? "-" : "";
- this.Text = $"{sign}{timespan:hh\\:mm\\:ss\\.fff}";
- }
-
- private void textBox_Validating(object sender, EventArgs e)
- {
- if (string.IsNullOrWhiteSpace(this.Text) || this.Text.Equals("0"))
- this.Text = "00:00:00.000";
-
- var rTime = new Regex(@"-?[0-9][0-9]\:[0-6][0-9]\:[0-6][0-9]\.[0-9]{1,3}");
-
- if (!rTime.IsMatch(this.Text))
- {
- MessageBox.Show("Please provide the time in hh:mm:ss.xxx format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- this.Text = lastValidText;
- }
- else if (this.MaxValue != null && this.TimeSpan > this.MaxValue)
- {
- MessageBox.Show("Time set exceeds file duration", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- this.Text = lastValidText;
- }
- else
- {
- lastValidText = this.Text;
- }
-
- if (this.Text.Contains("-"))
- {
- this.BackColor = Color.PaleVioletRed;
- this.ForeColor = Color.DarkRed;
- } else
- {
- this.BackColor = TextBox.DefaultBackColor;
- this.ForeColor = TextBox.DefaultForeColor;
- }
- }
-
- private void textBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar) || (e.KeyChar.ToString() == ":") || (e.KeyChar.ToString() == "."))
- {
- e.Handled = false;
- }
- else
- {
- e.Handled = true;
- }
- }
- }
-}
diff --git a/IFME/IFME.csproj b/IFME/IFME.csproj
index c600560..554b86f 100644
--- a/IFME/IFME.csproj
+++ b/IFME/IFME.csproj
@@ -60,9 +60,6 @@
Component
-
- Component
-
diff --git a/IFME/frmMain.Designer.cs b/IFME/frmMain.Designer.cs
index c15e141..97e2e9e 100644
--- a/IFME/frmMain.Designer.cs
+++ b/IFME/frmMain.Designer.cs
@@ -101,16 +101,16 @@ private void InitializeComponent()
this.chkAdvCropAuto = new System.Windows.Forms.CheckBox();
this.grpAdvCrop = new System.Windows.Forms.GroupBox();
this.lblAdvCropNote = new System.Windows.Forms.Label();
- this.txtAdvCropDuration = new TimespanTextBox();
+ this.txtAdvCropDuration = new System.Windows.Forms.TextBox();
this.lblAdvCropDuration = new System.Windows.Forms.Label();
- this.txtAdvCropStart = new TimespanTextBox();
+ this.txtAdvCropStart = new System.Windows.Forms.TextBox();
this.lblAdvCropStart = new System.Windows.Forms.Label();
this.grpAdvHdr = new System.Windows.Forms.GroupBox();
this.grpAdvTrim = new System.Windows.Forms.GroupBox();
this.lblAdvTrimNote = new System.Windows.Forms.Label();
- this.txtAdvTrimDuration = new TimespanTextBox();
- this.txtAdvTrimEnd = new TimespanTextBox();
- this.txtAdvTrimStart = new TimespanTextBox();
+ this.txtAdvTrimDuration = new System.Windows.Forms.TextBox();
+ this.txtAdvTrimEnd = new System.Windows.Forms.TextBox();
+ this.txtAdvTrimStart = new System.Windows.Forms.TextBox();
this.lblAdvTimeEqual = new System.Windows.Forms.Label();
this.lblAdvTimeUntil = new System.Windows.Forms.Label();
this.lblAdvTimeEnd = new System.Windows.Forms.Label();
@@ -988,7 +988,9 @@ private void InitializeComponent()
this.txtAdvCropDuration.Size = new System.Drawing.Size(100, 22);
this.txtAdvCropDuration.TabIndex = 12;
this.txtAdvCropDuration.Text = "00:00:09.000";
+ this.txtAdvCropDuration.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtTrim_KeyPress);
this.txtAdvCropDuration.Leave += new System.EventHandler(this.txtCrop_Event);
+ this.txtAdvCropDuration.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Validating);
//
// lblAdvCropDuration
//
@@ -1009,7 +1011,9 @@ private void InitializeComponent()
this.txtAdvCropStart.Size = new System.Drawing.Size(100, 22);
this.txtAdvCropStart.TabIndex = 10;
this.txtAdvCropStart.Text = "00:00:05.000";
+ this.txtAdvCropStart.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtTrim_KeyPress);
this.txtAdvCropStart.Leave += new System.EventHandler(this.txtCrop_Event);
+ this.txtAdvCropStart.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Validating);
//
// lblAdvCropStart
//
@@ -1072,7 +1076,9 @@ private void InitializeComponent()
this.txtAdvTrimDuration.Size = new System.Drawing.Size(100, 22);
this.txtAdvTrimDuration.TabIndex = 10;
this.txtAdvTrimDuration.Text = "00:01:00.000";
- this.txtAdvTrimDuration.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Event);
+ this.txtAdvTrimDuration.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtTrim_KeyPress);
+ this.txtAdvTrimDuration.Leave += new System.EventHandler(this.txtTrim_Event);
+ this.txtAdvTrimDuration.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Validating);
//
// txtAdvTrimEnd
//
@@ -1083,7 +1089,9 @@ private void InitializeComponent()
this.txtAdvTrimEnd.Size = new System.Drawing.Size(100, 22);
this.txtAdvTrimEnd.TabIndex = 9;
this.txtAdvTrimEnd.Text = "00:10:05.000";
- this.txtAdvTrimEnd.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Event);
+ this.txtAdvTrimEnd.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtTrim_KeyPress);
+ this.txtAdvTrimEnd.Leave += new System.EventHandler(this.txtTrim_Event);
+ this.txtAdvTrimEnd.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Validating);
//
// txtAdvTrimStart
//
@@ -1094,7 +1102,9 @@ private void InitializeComponent()
this.txtAdvTrimStart.Size = new System.Drawing.Size(100, 22);
this.txtAdvTrimStart.TabIndex = 8;
this.txtAdvTrimStart.Text = "00:09:45.500";
- this.txtAdvTrimStart.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Event);
+ this.txtAdvTrimStart.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.txtTrim_KeyPress);
+ this.txtAdvTrimStart.Leave += new System.EventHandler(this.txtTrim_Event);
+ this.txtAdvTrimStart.Validating += new System.ComponentModel.CancelEventHandler(this.txtTrim_Validating);
//
// lblAdvTimeEqual
//
@@ -2256,9 +2266,9 @@ private void InitializeComponent()
private System.Windows.Forms.ColumnHeader colVideoPixFmt;
private System.Windows.Forms.ColumnHeader colAudioSampleRate;
private System.Windows.Forms.ColumnHeader colAudioChannel;
- private TimespanTextBox txtAdvTrimDuration;
- private TimespanTextBox txtAdvTrimEnd;
- private TimespanTextBox txtAdvTrimStart;
+ private System.Windows.Forms.TextBox txtAdvTrimDuration;
+ private System.Windows.Forms.TextBox txtAdvTrimEnd;
+ private System.Windows.Forms.TextBox txtAdvTrimStart;
private System.Windows.Forms.GroupBox grpAdvHdr;
private System.Windows.Forms.CheckBox chkAudioMP4Compt;
private System.Windows.Forms.CheckBox chkVideoMP4Compt;
@@ -2266,9 +2276,9 @@ private void InitializeComponent()
private System.Windows.Forms.ToolStripMenuItem tsmiUseAsIngestStation;
private System.Windows.Forms.GroupBox grpAdvCrop;
private System.Windows.Forms.CheckBox chkAdvCropAuto;
- private TimespanTextBox txtAdvCropDuration;
+ private System.Windows.Forms.TextBox txtAdvCropDuration;
private System.Windows.Forms.Label lblAdvCropDuration;
- private TimespanTextBox txtAdvCropStart;
+ private System.Windows.Forms.TextBox txtAdvCropStart;
private System.Windows.Forms.Label lblAdvCropStart;
private System.Windows.Forms.Label lblAdvCropNote;
private System.Windows.Forms.Label lblAdvTrimNote;
diff --git a/IFME/frmMain.cs b/IFME/frmMain.cs
index 81ec935..6ff7e7e 100644
--- a/IFME/frmMain.cs
+++ b/IFME/frmMain.cs
@@ -381,9 +381,7 @@ private void lstFile_SelectedIndexChanged(object sender, EventArgs e)
if (data.Attachment.Count > 0)
lstAttach.Items[0].Selected = true;
- refreshTrimFieldsEnabled();
- chkAdvTrim.Checked = chkAdvTrim.Enabled && data.Trim.Enable;
- grpAdvTrim.Enabled = chkAdvTrim.Checked;
+ chkAdvTrim.Checked = data.Trim.Enable;
txtAdvTrimStart.Text = data.Trim.Start;
txtAdvTrimEnd.Text = data.Trim.End;
txtAdvTrimDuration.Text = data.Trim.Duration;
@@ -392,17 +390,6 @@ private void lstFile_SelectedIndexChanged(object sender, EventArgs e)
txtAdvCropStart.Text = data.Crop.Start;
txtAdvCropDuration.Text = data.Crop.Duration;
- // Advanced Trim and Cut
- if (txtAdvTrimEnd.TimeSpan.TotalMilliseconds == 0 && txtAdvTrimDuration.TimeSpan.TotalMilliseconds == 0)
- {
- TimeSpan auxValue = TimeSpan.FromSeconds((double)(new decimal(data.Duration)));
- txtAdvTrimEnd.TimeSpan = auxValue;
- txtAdvTrimDuration.TimeSpan = auxValue;
- txtAdvTrimEnd.MaxValue = auxValue;
- txtAdvTrimDuration.MaxValue = auxValue;
- txtAdvTrimStart.MaxValue = auxValue;
- }
-
// Media Info
txtMediaInfo.Text = FFmpeg.MediaInfo.Print(data.Info);
}
@@ -418,7 +405,6 @@ private void lstFile_SelectedIndexChanged(object sender, EventArgs e)
chkAudioMP4Compt.Checked = false;
chkSubHard.Checked = false;
chkAdvTrim.Checked = false;
- refreshTrimFieldsEnabled();
}
}
@@ -1993,12 +1979,7 @@ private void tsmiFileAddAttachEmbed_Click(object sender, EventArgs e)
private void tabConfigAdvance_Enter(object sender, EventArgs e)
{
- refreshTrimFieldsEnabled();
- }
-
- private void refreshTrimFieldsEnabled()
- {
- chkAdvTrim.Enabled = lstFile.SelectedItems.Count > 0 && !(chkAudioMP4Compt.Checked || chkVideoMP4Compt.Checked); // prevent user trim when do Fast Remux
+ chkAdvTrim.Enabled = !(chkAudioMP4Compt.Checked || chkVideoMP4Compt.Checked); // prevent user trim when do Fast Remux
chkAdvCropAuto.Enabled = !chkVideoMP4Compt.Checked; // prevent user crop when do Fast Remux
grpAdvTrim.Enabled = chkAdvTrim.Checked;
@@ -2024,43 +2005,69 @@ private void chkAdvTrim_CheckedChanged(object sender, EventArgs e)
}
}
- private void txtTrim_Event(object sender, EventArgs e)
+ private void txtTrim_Validating(object sender, CancelEventArgs e)
{
- var ctrl = sender as TextBox;
+ var rTime = new Regex(@"[0-9][0-9]\:[0-6][0-9]\:[0-6][0-9]\.[0-9]{1,}");
- var timeStart = txtAdvTrimStart.TimeSpan;
- var timeEnd = txtAdvTrimEnd.TimeSpan;
- var timeSpan = txtAdvTrimDuration.TimeSpan;
-
-
- if (ctrl == txtAdvTrimStart || ctrl == txtAdvTrimEnd)
+ if ((sender as TextBox).Text.Length > 0)
{
- timeSpan = timeEnd - timeStart;
+ if (!rTime.IsMatch((sender as TextBox).Text))
+ {
+ MessageBox.Show("Please provide the time in hh:mm:ss.xxx format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
}
+ }
- if (ctrl == txtAdvTrimDuration)
+ private void txtTrim_KeyPress(object sender, KeyPressEventArgs e)
+ {
+ if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar) || (e.KeyChar.ToString() == ":") || (e.KeyChar.ToString() == "."))
{
- timeEnd = timeStart + timeSpan;
+ e.Handled = false;
}
-
- if (timeSpan.TotalMilliseconds == 0 && timeEnd.TotalMilliseconds == 0 && (lstFile.SelectedItems.Count > 0))
+ else
{
- var data = lstFile.SelectedItems[0].Tag as MediaQueue;
- txtAdvTrimEnd.setValueSeconds(data.Duration);
- txtAdvTrimDuration.setValueSeconds(data.Duration);
- timeEnd = txtAdvTrimEnd.TimeSpan;
- timeSpan = txtAdvTrimDuration.TimeSpan;
+ e.Handled = true;
}
+ }
- txtAdvTrimStart.TimeSpan = timeStart;
- txtAdvTrimEnd.TimeSpan = timeEnd;
- txtAdvTrimDuration.TimeSpan = timeSpan;
+ private void txtTrim_Event(object sender, EventArgs e)
+ {
+ var ctrl = sender as TextBox;
- foreach (ListViewItem item in lstFile.SelectedItems)
+ var bTimeStart = TimeSpan.TryParse(txtAdvTrimStart.Text, out var timeStart);
+ var bTimeEnd = TimeSpan.TryParse(txtAdvTrimEnd.Text, out var timeEnd);
+ var bTimeSpan = TimeSpan.TryParse(txtAdvTrimDuration.Text, out var timeSpan);
+
+ if (bTimeStart && bTimeEnd && bTimeSpan)
{
- (item.Tag as MediaQueue).Trim.Start = txtAdvTrimStart.Text;
- (item.Tag as MediaQueue).Trim.End = txtAdvTrimEnd.Text;
- (item.Tag as MediaQueue).Trim.Duration = txtAdvTrimDuration.Text;
+ if (ctrl.Focused)
+ {
+ if (ctrl == txtAdvTrimStart)
+ {
+ timeSpan = timeEnd - timeStart;
+ }
+
+ if (ctrl == txtAdvTrimEnd)
+ {
+ timeSpan = timeEnd - timeStart;
+ }
+
+ if (ctrl == txtAdvTrimDuration)
+ {
+ timeEnd = timeStart + timeSpan;
+ }
+
+ txtAdvTrimStart.Text = $"{timeStart:hh\\:mm\\:ss\\.fff}";
+ txtAdvTrimEnd.Text = $"{timeEnd:hh\\:mm\\:ss\\.fff}";
+ txtAdvTrimDuration.Text = $"{timeSpan:hh\\:mm\\:ss\\.fff}";
+ }
+
+ foreach (ListViewItem item in lstFile.SelectedItems)
+ {
+ (item.Tag as MediaQueue).Trim.Start = $"{timeStart:hh\\:mm\\:ss\\.fff}";
+ (item.Tag as MediaQueue).Trim.End = $"{timeEnd:hh\\:mm\\:ss\\.fff}";
+ (item.Tag as MediaQueue).Trim.Duration = $"{timeSpan:hh\\:mm\\:ss\\.fff}";
+ }
}
}