diff --git a/src/Controls/WaveForm.cs b/src/Controls/WaveForm.cs index 5ed35a143..50a6caa8a 100644 --- a/src/Controls/WaveForm.cs +++ b/src/Controls/WaveForm.cs @@ -101,6 +101,8 @@ namespace Nikse.SubtitleEdit.Controls public bool DrawGridLines { get; set; } public bool AllowNewSelection { get; set; } + public bool Locked { get; set; } + public double EndPositionSeconds { get @@ -952,19 +954,19 @@ namespace Nikse.SubtitleEdit.Controls private void WaveForm_KeyDown(object sender, KeyEventArgs e) { - if (e.KeyCode == Keys.Add) + if (e.Modifiers == Keys.None && e.KeyCode == Keys.Add) { ZoomFactor = ZoomFactor + 0.1; if (OnZoomedChanged != null) OnZoomedChanged.Invoke(null, null); } - else if (e.KeyCode == Keys.Subtract) + else if (e.Modifiers == Keys.None && e.KeyCode == Keys.Subtract) { ZoomFactor = ZoomFactor - 0.1; if (OnZoomedChanged != null) OnZoomedChanged.Invoke(null, null); } - else if (e.Control == false && e.KeyCode == Keys.Z) + else if (e.Modifiers == Keys.None && e.KeyCode == Keys.Z) { if (StartPositionSeconds > 0.1) { @@ -974,7 +976,7 @@ namespace Nikse.SubtitleEdit.Controls e.SuppressKeyPress = true; } } - else if (e.Control == false && e.KeyCode == Keys.X) + else if (e.Modifiers == Keys.None && e.KeyCode == Keys.X) { if (StartPositionSeconds + 0.1 < _wavePeaks.Header.LengthInSeconds) { @@ -983,16 +985,29 @@ namespace Nikse.SubtitleEdit.Controls Invalidate(); e.SuppressKeyPress = true; } - } + } + else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.C) + { + Locked = !Locked; + Invalidate(); + e.SuppressKeyPress = true; + } } void WaveForm_MouseWheel(object sender, MouseEventArgs e) { int delta = e.Delta; { - StartPositionSeconds -= delta / 256.0; - if (_currentVideoPositionSeconds < StartPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds) - OnPositionSelected.Invoke(StartPositionSeconds, null); + if (Locked) + { + OnPositionSelected.Invoke(_currentVideoPositionSeconds + (-delta / 256.0), null); + } + else + { + StartPositionSeconds -= delta / 256.0; + if (_currentVideoPositionSeconds < StartPositionSeconds || _currentVideoPositionSeconds >= EndPositionSeconds) + OnPositionSelected.Invoke(StartPositionSeconds, null); + } Invalidate(); } } diff --git a/src/Forms/Main.Designer.cs b/src/Forms/Main.Designer.cs index 1b9cf2745..c24403407 100644 --- a/src/Forms/Main.Designer.cs +++ b/src/Forms/Main.Designer.cs @@ -1219,7 +1219,8 @@ // toolStripMenuItemAdjustAllTimes // this.toolStripMenuItemAdjustAllTimes.Name = "toolStripMenuItemAdjustAllTimes"; - this.toolStripMenuItemAdjustAllTimes.Size = new System.Drawing.Size(276, 22); + this.toolStripMenuItemAdjustAllTimes.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.D))); + this.toolStripMenuItemAdjustAllTimes.Size = new System.Drawing.Size(317, 22); this.toolStripMenuItemAdjustAllTimes.Text = "Adjust all times (show earlier/later)..."; this.toolStripMenuItemAdjustAllTimes.Click += new System.EventHandler(this.toolStripMenuItemAdjustAllTimes_Click); // @@ -1228,7 +1229,7 @@ this.visualSyncToolStripMenuItem.Name = "visualSyncToolStripMenuItem"; this.visualSyncToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) | System.Windows.Forms.Keys.V))); - this.visualSyncToolStripMenuItem.Size = new System.Drawing.Size(276, 22); + this.visualSyncToolStripMenuItem.Size = new System.Drawing.Size(317, 22); this.visualSyncToolStripMenuItem.Text = "Visual sync..."; this.visualSyncToolStripMenuItem.Click += new System.EventHandler(this.VisualSyncToolStripMenuItemClick); // @@ -1237,7 +1238,7 @@ this.toolStripMenuItemPointSync.Name = "toolStripMenuItemPointSync"; this.toolStripMenuItemPointSync.ShortcutKeys = ((System.Windows.Forms.Keys)(((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.Shift) | System.Windows.Forms.Keys.P))); - this.toolStripMenuItemPointSync.Size = new System.Drawing.Size(276, 22); + this.toolStripMenuItemPointSync.Size = new System.Drawing.Size(317, 22); this.toolStripMenuItemPointSync.Text = "Point sync..."; this.toolStripMenuItemPointSync.Click += new System.EventHandler(this.toolStripMenuItemPointSync_Click); // @@ -1358,14 +1359,14 @@ // this.helpToolStripMenuItem1.Name = "helpToolStripMenuItem1"; this.helpToolStripMenuItem1.ShortcutKeys = System.Windows.Forms.Keys.F1; - this.helpToolStripMenuItem1.Size = new System.Drawing.Size(152, 22); + this.helpToolStripMenuItem1.Size = new System.Drawing.Size(118, 22); this.helpToolStripMenuItem1.Text = "Help"; this.helpToolStripMenuItem1.Click += new System.EventHandler(this.HelpToolStripMenuItem1Click); // // aboutToolStripMenuItem // this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; - this.aboutToolStripMenuItem.Size = new System.Drawing.Size(152, 22); + this.aboutToolStripMenuItem.Size = new System.Drawing.Size(118, 22); this.aboutToolStripMenuItem.Text = "About"; this.aboutToolStripMenuItem.Click += new System.EventHandler(this.AboutToolStripMenuItemClick); // diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index 379aab751..9384410f0 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -11,10 +11,10 @@ using Nikse.SubtitleEdit.Controls; using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic.BluRaySup; using Nikse.SubtitleEdit.Logic.Enums; +using Nikse.SubtitleEdit.Logic.Networking; using Nikse.SubtitleEdit.Logic.SubtitleFormats; using Nikse.SubtitleEdit.Logic.VideoPlayers; using Nikse.SubtitleEdit.Logic.VobSub; -using Nikse.SubtitleEdit.Logic.Networking; namespace Nikse.SubtitleEdit.Forms { @@ -75,6 +75,8 @@ namespace Nikse.SubtitleEdit.Forms NikseWebServiceSession _networkSession; NetworkChat _networkChat = null; + ShowEarlierLater _showEarlierOrLater = null; + private bool AutoRepeatContinueOn { get @@ -2675,7 +2677,15 @@ namespace Nikse.SubtitleEdit.Forms textBoxListViewText.Text = string.Empty; MakeHistoryForUndo(_language.BeforeUndo); string subtitleFormatFriendlyName; + + string oldFileName = _fileName; + DateTime oldFileDateTime = _fileDateTime; + _fileName = _subtitle.UndoHistory(showHistory.SelectedIndex, out subtitleFormatFriendlyName, out _fileDateTime); + + if (string.Compare(oldFileName, _fileName, true) == 0) + _fileDateTime = oldFileDateTime; // undo will not give overwrite-newer-file warning + Text = Title + " - " + _fileName; ShowStatus(_language.UndoPerformed); @@ -3227,7 +3237,10 @@ namespace Nikse.SubtitleEdit.Forms private void UpdateListViewTextCharactersPerSeconds(Paragraph paragraph) { - string s = Utilities.RemoveHtmlTags(paragraph.Text).Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty); + const string zeroWhiteSpace = "\u200B"; + const string zeroWidthNoBreakSpace = "\uFEFF"; + + string s = Utilities.RemoveHtmlTags(paragraph.Text).Replace(" ", string.Empty).Replace(Environment.NewLine, string.Empty).Replace(zeroWhiteSpace, string.Empty).Replace(zeroWidthNoBreakSpace, string.Empty); if (paragraph.Duration.TotalSeconds > 0) { double charactersPerSecond = s.Length / paragraph.Duration.TotalSeconds; @@ -3360,6 +3373,38 @@ namespace Nikse.SubtitleEdit.Forms { e.SuppressKeyPress = true; } + else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R) + { + ButtonAutoBreakClick(null, null); + e.SuppressKeyPress = true; + } + else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R) + { + ButtonUnBreakClick(null, null); + e.SuppressKeyPress = true; + } + else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.I) + { + if (textBoxListViewText.SelectionLength == 0) + { + string tag = "i"; + if (textBoxListViewText.Text.Contains("<" + tag + ">")) + { + textBoxListViewText.Text = textBoxListViewText.Text.Replace("<" + tag + ">", string.Empty); + textBoxListViewText.Text = textBoxListViewText.Text.Replace("", string.Empty); + } + else + { + textBoxListViewText.Text = string.Format("<{0}>{1}", tag, textBoxListViewText.Text); + } + //SubtitleListview1.SetText(i, textBoxListViewText.Text); + + } + else + { + TextBoxListViewToogleTag("i"); + } + } // last key down in text _lastTextKeyDownTicks = DateTime.Now.Ticks; @@ -3940,7 +3985,21 @@ namespace Nikse.SubtitleEdit.Forms SubtitleFormat format; - if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[script info]")) + if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_VOBSUB") + { + MessageBox.Show("VobSub subtitles inside Matroska not supported - sorry!"); + if (_fileName == "123") + LoadVobSubFromMatroska(matroskaSubtitleInfo, fileName); + return; + } + if (matroskaSubtitleInfo.CodecId.ToUpper() == "S_HDMV/PGS") + { + MessageBox.Show("Blu-ray subtitles inside Matroska not supported - sorry!"); + if (_fileName == "123") + LoadBluRaySubFromMatroska(matroskaSubtitleInfo, fileName); + return; + } + else if (matroskaSubtitleInfo.CodecPrivate.ToLower().Contains("[script info]")) { format = new SubStationAlpha(); isSsa = true; @@ -3957,7 +4016,7 @@ namespace Nikse.SubtitleEdit.Forms ShowStatus(_language.ParsingMatroskaFile); Refresh(); Cursor.Current = Cursors.WaitCursor; - Subtitle sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid); + List sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid); Cursor.Current = Cursors.Default; if (isValid) { @@ -3970,7 +4029,7 @@ namespace Nikse.SubtitleEdit.Forms { int commaCount = 100; - foreach (Paragraph p in sub.Paragraphs) + foreach (SubtitleSequence p in sub) { string s1 = p.Text; if (s1.Contains(@"{\")) @@ -3980,7 +4039,7 @@ namespace Nikse.SubtitleEdit.Forms commaCount = temp; } - foreach (Paragraph p in sub.Paragraphs) + foreach (SubtitleSequence p in sub) { string s = string.Empty; string[] arr = p.Text.Split(','); @@ -3993,15 +4052,14 @@ namespace Nikse.SubtitleEdit.Forms s += arr[i-1]; } } - p.Text = s; - _subtitle.Paragraphs.Add(p); + _subtitle.Paragraphs.Add(new Paragraph(s, p.StartMilliseconds, p.EndMilliseconds)); } } else { - foreach (Paragraph p in sub.Paragraphs) + foreach (SubtitleSequence p in sub) { - _subtitle.Paragraphs.Add(p); + _subtitle.Paragraphs.Add(new Paragraph(p.Text, p.StartMilliseconds, p.EndMilliseconds)); } } @@ -4024,6 +4082,128 @@ namespace Nikse.SubtitleEdit.Forms } } + private void LoadVobSubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName) + { + bool isValid; + var matroska = new Matroska(); + + ShowStatus(_language.ParsingMatroskaFile); + Refresh(); + Cursor.Current = Cursors.WaitCursor; + List sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid); + Cursor.Current = Cursors.Default; + + + if (isValid) + { + MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile); + _subtitleListViewIndex = -1; + + _subtitle.Paragraphs.Clear(); + + List mergedVobSubPacks = new List(); + List vobSubPacks = new List(); + List palette = new List(); + + palette = null; + foreach (SubtitleSequence p in sub) + + { + SubPicture sp = new SubPicture(p.BinaryData); + MessageBox.Show(sp.SubPictureDateSize.ToString()); + MessageBox.Show(sp.ImageDisplayArea.ToString()); + + int length = p.BinaryData.Length; + if (length > 5000) + MessageBox.Show("Large"); + mergedVobSubPacks.Add(new VobSubMergedPack(p.BinaryData, TimeSpan.FromMilliseconds(p.StartMilliseconds), 32, null)); + } + + var formSubOcr = new VobSubOcr(); + formSubOcr.Initialize(mergedVobSubPacks, palette, Configuration.Settings.VobSubOcr); + if (formSubOcr.ShowDialog(this) == DialogResult.OK) + { + MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle); + + _subtitle.Paragraphs.Clear(); + SetCurrentFormat(new SubRip().FriendlyName); + _subtitle.WasLoadedWithFrameNumbers = false; + _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate); + foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs) + { + _subtitle.Paragraphs.Add(p); + } + + ShowSource(); + SubtitleListview1.Fill(_subtitle, _subtitleAlternate); + _change = true; + _subtitleListViewIndex = -1; + SubtitleListview1.FirstVisibleIndex = -1; + SubtitleListview1.SelectIndexAndEnsureVisible(0); + + _fileName = string.Empty; + Text = Title; + + Configuration.Settings.Save(); + } + } + } + + private void LoadBluRaySubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName) + { + bool isValid; + var matroska = new Matroska(); + + ShowStatus(_language.ParsingMatroskaFile); + Refresh(); + Cursor.Current = Cursors.WaitCursor; + List sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid); + Cursor.Current = Cursors.Default; + + + if (isValid) + { + MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile); + _subtitleListViewIndex = -1; + _subtitle.Paragraphs.Clear(); + + foreach (SubtitleSequence p in sub) + { + int length = p.BinaryData.Length; + if (length > 5000) + MessageBox.Show("Large"); + } + + var formSubOcr = new VobSubOcr(); +// formSubOcr.Initialize(mergedVobSubPacks, palette, Configuration.Settings.VobSubOcr); + if (formSubOcr.ShowDialog(this) == DialogResult.OK) + { + MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle); + + _subtitle.Paragraphs.Clear(); + SetCurrentFormat(new SubRip().FriendlyName); + _subtitle.WasLoadedWithFrameNumbers = false; + _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate); + foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs) + { + _subtitle.Paragraphs.Add(p); + } + + ShowSource(); + SubtitleListview1.Fill(_subtitle, _subtitleAlternate); + _change = true; + _subtitleListViewIndex = -1; + SubtitleListview1.FirstVisibleIndex = -1; + SubtitleListview1.SelectIndexAndEnsureVisible(0); + + _fileName = string.Empty; + Text = Title; + + Configuration.Settings.Save(); + } + } + } + private void SubtitleListview1_DragEnter(object sender, DragEventArgs e) { // make sure they're actually dropping files (not text or anything else) @@ -4351,35 +4531,23 @@ namespace Nikse.SubtitleEdit.Forms private void ShowSelectedLinesEarlierlaterToolStripMenuItemClick(object sender, EventArgs e) { if (_subtitle != null && _subtitle.Paragraphs.Count > 1) - { - var showEarlierOrLater = new ShowEarlierLater(); - SaveSubtitleListviewIndexes(); + { + bool waveFormEnabled = timerWaveForm.Enabled; + timerWaveForm.Stop(); + bool videoTimerEnabled = videoTimer.Enabled; + videoTimer.Stop(); + timer1.Stop(); - var selectedLines = new Subtitle { WasLoadedWithFrameNumbers = _subtitle.WasLoadedWithFrameNumbers }; - foreach (int index in SubtitleListview1.SelectedIndices) - selectedLines.Paragraphs.Add(_subtitle.Paragraphs[index]); - showEarlierOrLater.Initialize(selectedLines, _videoFileName); + _showEarlierOrLater = new ShowEarlierLater(); + _showEarlierOrLater.Initialize(ShowEarlierOrLaterSelectedLinesOnly, true); + MakeHistoryForUndo(_language.BeforeShowSelectedLinesEarlierLater); + _showEarlierOrLater.ShowDialog(this); - if (showEarlierOrLater.ShowDialog(this) == DialogResult.OK) - { - MakeHistoryForUndo(_language.BeforeShowSelectedLinesEarlierLater); + timerWaveForm.Enabled = waveFormEnabled; + videoTimer.Enabled = videoTimerEnabled; + timer1.Start(); - // we only update selected lines - int i = 0; - double frameRate = CurrentFrameRate; - foreach (int index in SubtitleListview1.SelectedIndices) - { - _subtitle.Paragraphs[index] = new Paragraph(showEarlierOrLater.Paragraphs[i]); - if (_subtitle.WasLoadedWithFrameNumbers) - _subtitle.Paragraphs[index].CalculateFrameNumbersFromTimeCodes(frameRate); - i++; - } - ShowStatus(_language.ShowSelectedLinesEarlierLaterPerformed); - ShowSource(); - SubtitleListview1.Fill(_subtitle, _subtitleAlternate); - RestoreSubtitleListviewIndexes(); - } - showEarlierOrLater.Dispose(); + RefreshSelectedParagraph(); } else { @@ -4670,6 +4838,50 @@ namespace Nikse.SubtitleEdit.Forms e.SuppressKeyPress = true; } } + else if (e.Modifiers == (Keys.Control | Keys.Alt | Keys.Shift) && e.KeyCode == Keys.W) // watermak + { + if (comboBoxEncoding.Text.StartsWith("ANSI - ")) + { + MessageBox.Show("Watermark only works with unicode file encoding"); + } + else + { + Watermark watermarkForm = new Watermark(); + watermarkForm.Initialize(_subtitle, FirstSelectedIndex); + if (watermarkForm.ShowDialog(this) == DialogResult.OK) + { + watermarkForm.AddOrRemove(_subtitle); + RefreshSelectedParagraph(); + } + } + } + else if (e.Modifiers == Keys.Shift && e.KeyCode == Keys.Insert) + { + InsertBefore(); + e.SuppressKeyPress = true; + } + else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.Insert) + { + InsertAfter(); + e.SuppressKeyPress = true; + } + //else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.D) + //{ + // InsertAfter(); + // e.SuppressKeyPress = true; + //} + + //else if (e.Modifiers == Keys.Alt && e.KeyCode == Keys.C) + //{ + // buttonSetStartTime_Click(null, null); + // e.SuppressKeyPress = true; + //} + //else if (e.Modifiers == Keys.None && e.KeyCode == Keys.B) + //{ + // StopAutoDuration(); + // buttonSetEnd_Click(null, null); + // e.SuppressKeyPress = true; + //} } private void SubtitleListview1_KeyDown(object sender, KeyEventArgs e) @@ -5352,6 +5564,7 @@ namespace Nikse.SubtitleEdit.Forms if (File.Exists(peakWaveFileName)) { AudioWaveForm.WavePeaks = new WavePeakGenerator(peakWaveFileName); + toolStripComboBoxWaveForm_SelectedIndexChanged(null, null); AudioWaveForm.WavePeaks.GenerateAllSamples(); AudioWaveForm.WavePeaks.Close(); @@ -5887,36 +6100,51 @@ namespace Nikse.SubtitleEdit.Forms Refresh(); } + public void ShowEarlierOrLater(double adjustMilliseconds) + { + double frameRate = CurrentFrameRate; + _subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(adjustMilliseconds)); + SubtitleListview1.BeginUpdate(); + for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + { + Paragraph p = _subtitle.GetParagraphOrDefault(i); + if (p != null) + SubtitleListview1.SetStartTime(i, p); + if (_subtitle.WasLoadedWithFrameNumbers) + p.CalculateFrameNumbersFromTimeCodes(frameRate); + } + SubtitleListview1.EndUpdate(); + RefreshSelectedParagraph(); + } + + public void ShowEarlierOrLaterSelectedLinesOnly(double adjustMilliseconds) + { + double frameRate = CurrentFrameRate; + _subtitle.AddTimeToAllParagraphs(TimeSpan.FromMilliseconds(adjustMilliseconds)); + SubtitleListview1.BeginUpdate(); + for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + { + if (SubtitleListview1.Items[i].Selected) + { + Paragraph p = _subtitle.GetParagraphOrDefault(i); + if (p != null) + SubtitleListview1.SetStartTime(i, p); + if (_subtitle.WasLoadedWithFrameNumbers) + p.CalculateFrameNumbersFromTimeCodes(frameRate); + } + } + SubtitleListview1.EndUpdate(); + } + private void toolStripMenuItemAdjustAllTimes_Click(object sender, EventArgs e) { if (_subtitle != null && _subtitle.Paragraphs.Count > 1) { mediaPlayer.Pause(); - var showEarlierOrLater = new ShowEarlierLater(); + _showEarlierOrLater = new ShowEarlierLater(); SaveSubtitleListviewIndexes(); - - showEarlierOrLater.Initialize(_subtitle, _videoFileName); - - if (showEarlierOrLater.ShowDialog(this) == DialogResult.OK) - { - MakeHistoryForUndo(_language.BeforeShowSelectedLinesEarlierLater); - - // we only update selected lines - int i = 0; - double frameRate = CurrentFrameRate; - for (int index = 0; i < _subtitle.Paragraphs.Count; index++) - { - _subtitle.Paragraphs[index] = new Paragraph(showEarlierOrLater.Paragraphs[i]); - if (_subtitle.WasLoadedWithFrameNumbers) - _subtitle.Paragraphs[index].CalculateFrameNumbersFromTimeCodes(frameRate); - i++; - } - ShowStatus(_language.ShowSelectedLinesEarlierLaterPerformed); - ShowSource(); - SubtitleListview1.Fill(_subtitle, _subtitleAlternate); - RestoreSubtitleListviewIndexes(); - } - showEarlierOrLater.Dispose(); + _showEarlierOrLater.Initialize(ShowEarlierOrLater, false); + _showEarlierOrLater.Show(this); } else { @@ -6385,7 +6613,15 @@ namespace Nikse.SubtitleEdit.Forms int index = -1; if (SubtitleListview1.SelectedItems.Count > 0) index = SubtitleListview1.SelectedItems[0].Index; - if (mediaPlayer.CurrentPosition > AudioWaveForm.EndPositionSeconds || mediaPlayer.CurrentPosition < AudioWaveForm.StartPositionSeconds) + + if (AudioWaveForm.Locked) + { + double startPos = mediaPlayer.CurrentPosition - ((AudioWaveForm.EndPositionSeconds - AudioWaveForm.StartPositionSeconds) / 2.0); + if (startPos < 0) + startPos = 0; + AudioWaveForm.SetPosition(startPos, _subtitle, mediaPlayer.CurrentPosition, index); + } + else if (mediaPlayer.CurrentPosition > AudioWaveForm.EndPositionSeconds || mediaPlayer.CurrentPosition < AudioWaveForm.StartPositionSeconds) { double startPos = mediaPlayer.CurrentPosition - 0.01; if (startPos < 0) diff --git a/src/Forms/SetSyncPoint.cs b/src/Forms/SetSyncPoint.cs index aefa65b58..ae5dd8fa4 100644 --- a/src/Forms/SetSyncPoint.cs +++ b/src/Forms/SetSyncPoint.cs @@ -95,6 +95,10 @@ namespace Nikse.SubtitleEdit.Forms { if (File.Exists(fileName)) { + FileInfo fi = new FileInfo(fileName); + if (fi.Length < 1000) + return; + labelVideoFileName.Text = fileName; VideoFileName = fileName; if (videoPlayerContainer1.VideoPlayer != null) diff --git a/src/Forms/ShowEarlierLater.Designer.cs b/src/Forms/ShowEarlierLater.Designer.cs index e29db8347..0aafd342b 100644 --- a/src/Forms/ShowEarlierLater.Designer.cs +++ b/src/Forms/ShowEarlierLater.Designer.cs @@ -34,12 +34,7 @@ namespace Nikse.SubtitleEdit.Forms this.labelHoursMinSecsMilliSecs = new System.Windows.Forms.Label(); this.buttonShowLater = new System.Windows.Forms.Button(); this.buttonShowEarlier = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.buttonOK = new System.Windows.Forms.Button(); - this.subtitleListView1 = new Nikse.SubtitleEdit.Controls.SubtitleListView(); this.labelTotalAdjustment = new System.Windows.Forms.Label(); - this.labelSubtitle = new System.Windows.Forms.Label(); - this.mediaPlayer = new Nikse.SubtitleEdit.Controls.VideoPlayerContainer(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.timeUpDownAdjust = new Nikse.SubtitleEdit.Controls.TimeUpDown(); this.SuspendLayout(); @@ -47,7 +42,7 @@ namespace Nikse.SubtitleEdit.Forms // labelHoursMinSecsMilliSecs // this.labelHoursMinSecsMilliSecs.AutoSize = true; - this.labelHoursMinSecsMilliSecs.Location = new System.Drawing.Point(11, 383); + this.labelHoursMinSecsMilliSecs.Location = new System.Drawing.Point(11, 7); this.labelHoursMinSecsMilliSecs.Name = "labelHoursMinSecsMilliSecs"; this.labelHoursMinSecsMilliSecs.Size = new System.Drawing.Size(108, 13); this.labelHoursMinSecsMilliSecs.TabIndex = 18; @@ -55,7 +50,7 @@ namespace Nikse.SubtitleEdit.Forms // // buttonShowLater // - this.buttonShowLater.Location = new System.Drawing.Point(14, 456); + this.buttonShowLater.Location = new System.Drawing.Point(110, 54); this.buttonShowLater.Name = "buttonShowLater"; this.buttonShowLater.Size = new System.Drawing.Size(119, 21); this.buttonShowLater.TabIndex = 20; @@ -65,7 +60,7 @@ namespace Nikse.SubtitleEdit.Forms // // buttonShowEarlier // - this.buttonShowEarlier.Location = new System.Drawing.Point(14, 429); + this.buttonShowEarlier.Location = new System.Drawing.Point(110, 27); this.buttonShowEarlier.Name = "buttonShowEarlier"; this.buttonShowEarlier.Size = new System.Drawing.Size(120, 21); this.buttonShowEarlier.TabIndex = 19; @@ -73,102 +68,34 @@ namespace Nikse.SubtitleEdit.Forms this.buttonShowEarlier.UseVisualStyleBackColor = true; this.buttonShowEarlier.Click += new System.EventHandler(this.ButtonShowEarlierClick); // - // buttonCancel - // - this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.buttonCancel.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonCancel.Location = new System.Drawing.Point(715, 630); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(75, 21); - this.buttonCancel.TabIndex = 37; - this.buttonCancel.Text = "C&ancel"; - this.buttonCancel.UseVisualStyleBackColor = true; - // - // buttonOK - // - this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.buttonOK.ImeMode = System.Windows.Forms.ImeMode.NoControl; - this.buttonOK.Location = new System.Drawing.Point(634, 630); - this.buttonOK.Name = "buttonOK"; - this.buttonOK.Size = new System.Drawing.Size(75, 21); - this.buttonOK.TabIndex = 36; - this.buttonOK.Text = "&OK"; - this.buttonOK.UseVisualStyleBackColor = true; - // - // subtitleListView1 - // - this.subtitleListView1.FirstVisibleIndex = -1; - this.subtitleListView1.FullRowSelect = true; - this.subtitleListView1.GridLines = true; - this.subtitleListView1.HideSelection = false; - this.subtitleListView1.Location = new System.Drawing.Point(14, 13); - this.subtitleListView1.Name = "subtitleListView1"; - this.subtitleListView1.Size = new System.Drawing.Size(776, 329); - this.subtitleListView1.TabIndex = 35; - this.subtitleListView1.UseCompatibleStateImageBehavior = false; - this.subtitleListView1.View = System.Windows.Forms.View.Details; - this.subtitleListView1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.subtitleListView1_MouseDoubleClick); - // // labelTotalAdjustment // this.labelTotalAdjustment.AutoSize = true; - this.labelTotalAdjustment.Location = new System.Drawing.Point(11, 348); + this.labelTotalAdjustment.Location = new System.Drawing.Point(12, 90); this.labelTotalAdjustment.Name = "labelTotalAdjustment"; this.labelTotalAdjustment.Size = new System.Drawing.Size(108, 13); this.labelTotalAdjustment.TabIndex = 38; this.labelTotalAdjustment.Text = "labelTotalAdjustment"; // - // labelSubtitle - // - this.labelSubtitle.BackColor = System.Drawing.Color.Black; - this.labelSubtitle.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.labelSubtitle.ForeColor = System.Drawing.Color.White; - this.labelSubtitle.Location = new System.Drawing.Point(387, 582); - this.labelSubtitle.Name = "labelSubtitle"; - this.labelSubtitle.Size = new System.Drawing.Size(403, 28); - this.labelSubtitle.TabIndex = 39; - this.labelSubtitle.Text = "labelSubtitle"; - this.labelSubtitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // mediaPlayer - // - this.mediaPlayer.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(18)))), ((int)(((byte)(18)))), ((int)(((byte)(18))))); - this.mediaPlayer.CurrentPosition = 0D; - this.mediaPlayer.Location = new System.Drawing.Point(387, 348); - this.mediaPlayer.Name = "mediaPlayer"; - this.mediaPlayer.ShowStopButton = true; - this.mediaPlayer.Size = new System.Drawing.Size(403, 234); - this.mediaPlayer.TabIndex = 40; - this.mediaPlayer.VideoPlayer = null; - this.mediaPlayer.Volume = 0D; - // // timer1 // this.timer1.Interval = 250; - this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // timeUpDownAdjust // this.timeUpDownAdjust.AutoSize = true; this.timeUpDownAdjust.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.timeUpDownAdjust.Location = new System.Drawing.Point(12, 399); + this.timeUpDownAdjust.Location = new System.Drawing.Point(12, 23); this.timeUpDownAdjust.Name = "timeUpDownAdjust"; - this.timeUpDownAdjust.Size = new System.Drawing.Size(89, 25); + this.timeUpDownAdjust.Size = new System.Drawing.Size(92, 25); this.timeUpDownAdjust.TabIndex = 21; // // ShowEarlierLater // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(804, 663); - this.Controls.Add(this.labelSubtitle); - this.Controls.Add(this.mediaPlayer); + this.ClientSize = new System.Drawing.Size(243, 113); this.Controls.Add(this.labelTotalAdjustment); - this.Controls.Add(this.subtitleListView1); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonOK); this.Controls.Add(this.timeUpDownAdjust); this.Controls.Add(this.labelHoursMinSecsMilliSecs); this.Controls.Add(this.buttonShowLater); @@ -180,7 +107,6 @@ namespace Nikse.SubtitleEdit.Forms this.MinimizeBox = false; this.Name = "ShowEarlierLater"; this.Text = "Show selected lines earlier/later"; - this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ShowEarlierLater_FormClosing); this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ShowEarlierLater_KeyDown); this.ResumeLayout(false); this.PerformLayout(); @@ -193,12 +119,7 @@ namespace Nikse.SubtitleEdit.Forms private System.Windows.Forms.Label labelHoursMinSecsMilliSecs; private System.Windows.Forms.Button buttonShowLater; private System.Windows.Forms.Button buttonShowEarlier; - private SubtitleListView subtitleListView1; - private System.Windows.Forms.Button buttonCancel; - private System.Windows.Forms.Button buttonOK; private System.Windows.Forms.Label labelTotalAdjustment; - private System.Windows.Forms.Label labelSubtitle; - private VideoPlayerContainer mediaPlayer; private System.Windows.Forms.Timer timer1; } } \ No newline at end of file diff --git a/src/Forms/ShowEarlierLater.cs b/src/Forms/ShowEarlierLater.cs index 5deb1f33c..45648ca7c 100644 --- a/src/Forms/ShowEarlierLater.cs +++ b/src/Forms/ShowEarlierLater.cs @@ -8,35 +8,21 @@ namespace Nikse.SubtitleEdit.Forms { public sealed partial class ShowEarlierLater : Form { - Subtitle _subtitle; + public delegate void AdjustEventHandler(double adjustMilliseconds); + TimeSpan _totalAdjustment = TimeSpan.FromMilliseconds(0); - VideoInfo _videoInfo; - - public List Paragraphs - { - get - { - return _subtitle.Paragraphs; - } - } - - public string VideoFileName { get; set; } + AdjustEventHandler _adjustCallback; public ShowEarlierLater() { InitializeComponent(); labelTotalAdjustment.Text = string.Empty; timeUpDownAdjust.MaskedTextBox.Text = "000000000"; - labelSubtitle.Text = string.Empty; Text = Configuration.Settings.Language.ShowEarlierLater.Title; labelHoursMinSecsMilliSecs.Text = Configuration.Settings.Language.General.HourMinutesSecondsMilliseconds; buttonShowEarlier.Text = Configuration.Settings.Language.ShowEarlierLater.ShowEarlier; buttonShowLater.Text = Configuration.Settings.Language.ShowEarlierLater.ShowLater; - buttonOK.Text = Configuration.Settings.Language.General.OK; - buttonCancel.Text = Configuration.Settings.Language.General.Cancel; - - subtitleListView1.InitializeLanguage(Configuration.Settings.Language.General, Configuration.Settings); } private void ShowEarlierLater_KeyDown(object sender, KeyEventArgs e) @@ -45,93 +31,17 @@ namespace Nikse.SubtitleEdit.Forms { DialogResult = DialogResult.Cancel; } - else if (e.KeyCode == Keys.Right && e.Modifiers == Keys.Control) - { - mediaPlayer.CurrentPosition += 0.10; - e.SuppressKeyPress = true; - } - else if (e.KeyCode == Keys.Left && e.Modifiers == Keys.Control) - { - mediaPlayer.CurrentPosition -= 0.10; - e.SuppressKeyPress = true; - } - else if (e.KeyCode == Keys.Right && e.Modifiers == Keys.Alt) - { - if (mediaPlayer.VideoPlayer != null) - { - mediaPlayer.CurrentPosition += 0.5; - e.SuppressKeyPress = true; - } - } - else if (e.KeyCode == Keys.Left && e.Modifiers == Keys.Alt) - { - if (mediaPlayer.VideoPlayer != null) - { - mediaPlayer.CurrentPosition -= 0.5; - e.SuppressKeyPress = true; - } - } - else if (e.Modifiers == Keys.None && e.KeyCode == Keys.Space) - { - mediaPlayer.TooglePlayPause(); - e.SuppressKeyPress = true; - } } - internal void Initialize(Subtitle subtitle, string videoFileName) + internal void Initialize(AdjustEventHandler adjustCallback, bool onlySelected) { - _subtitle = subtitle; - subtitleListView1.Fill(subtitle); - - timeUpDownAdjust.TimeCode = new TimeCode(TimeSpan.FromMilliseconds(Configuration.Settings.General.DefaultAdjustMilliseconds)); - - VideoFileName = videoFileName; - OpenVideo(videoFileName); - } - - private void OpenVideo(string fileName) - { - if (File.Exists(fileName)) - { - FileInfo fi = new FileInfo(fileName); - if (fi.Length < 1000) - return; - - VideoFileName = fileName; - if (mediaPlayer.VideoPlayer != null) - { - mediaPlayer.Pause(); - mediaPlayer.VideoPlayer.DisposeVideoPlayer(); - } - VideoInfo videoInfo = ShowVideoInfo(fileName); - Utilities.InitializeVideoPlayerAndContainer(fileName, videoInfo, mediaPlayer, VideoLoaded, VideoEnded); - } + if (onlySelected) + Text = Configuration.Settings.Language.ShowEarlierLater.Title; else - { - Height = buttonShowLater.Top + buttonShowLater.Height + 40; - mediaPlayer.Visible = false; - labelSubtitle.Visible = false; - } - } + Text = Configuration.Settings.Language.ShowEarlierLater.TitleAll; - private VideoInfo ShowVideoInfo(string fileName) - { - _videoInfo = Utilities.GetVideoInfo(fileName, delegate { Application.DoEvents(); }); - var info = new FileInfo(fileName); - long fileSizeInBytes = info.Length; - return _videoInfo; - } - - - void VideoLoaded(object sender, EventArgs e) - { - mediaPlayer.Stop(); - timer1.Start(); - } - - void VideoEnded(object sender, EventArgs e) - { - mediaPlayer.Pause(); + _adjustCallback = adjustCallback; + timeUpDownAdjust.TimeCode = new TimeCode(TimeSpan.FromMilliseconds(Configuration.Settings.General.DefaultAdjustMilliseconds)); } private void ButtonShowEarlierClick(object sender, EventArgs e) @@ -139,10 +49,10 @@ namespace Nikse.SubtitleEdit.Forms TimeCode tc = timeUpDownAdjust.TimeCode; if (tc != null && tc.TotalMilliseconds > 0) { + _adjustCallback.Invoke(-tc.TotalMilliseconds); _totalAdjustment = TimeSpan.FromMilliseconds(_totalAdjustment.TotalMilliseconds - tc.TotalMilliseconds); ShowTotalAdjustMent(); - _subtitle.AddTimeToAllParagraphs(-tc.TimeSpan); - subtitleListView1.Fill(_subtitle); + Configuration.Settings.General.DefaultAdjustMilliseconds = (int)tc.TotalMilliseconds; } } @@ -157,47 +67,10 @@ namespace Nikse.SubtitleEdit.Forms TimeCode tc = timeUpDownAdjust.TimeCode; if (tc != null && tc.TotalMilliseconds > 0) { + _adjustCallback.Invoke(tc.TotalMilliseconds); _totalAdjustment = TimeSpan.FromMilliseconds(_totalAdjustment.TotalMilliseconds + tc.TotalMilliseconds); ShowTotalAdjustMent(); - _subtitle.AddTimeToAllParagraphs(tc.TimeSpan); - subtitleListView1.Fill(_subtitle); - } - } - - private void timer1_Tick(object sender, EventArgs e) - { - if (mediaPlayer != null && mediaPlayer.VideoPlayer != null) - { - if (!mediaPlayer.IsPaused) - { - mediaPlayer.RefreshProgressBar(); - int index = Utilities.ShowSubtitle(_subtitle.Paragraphs, labelSubtitle, mediaPlayer.VideoPlayer); - } - } - } - - private void subtitleListView1_MouseDoubleClick(object sender, MouseEventArgs e) - { - if (subtitleListView1.SelectedItems.Count > 0 && VideoFileName != null) - { - int index = subtitleListView1.SelectedItems[0].Index; - - mediaPlayer.Pause(); - double pos = _subtitle.Paragraphs[index].StartTime.TotalSeconds; - if (pos > 1) - mediaPlayer.CurrentPosition = (_subtitle.Paragraphs[index].StartTime.TotalSeconds) - 0.5; - else - mediaPlayer.CurrentPosition = _subtitle.Paragraphs[index].StartTime.TotalSeconds; - mediaPlayer.Play(); - } - } - - private void ShowEarlierLater_FormClosing(object sender, FormClosingEventArgs e) - { - if (mediaPlayer.VideoPlayer != null) - { - mediaPlayer.VideoPlayer.Pause(); - mediaPlayer.VideoPlayer.DisposeVideoPlayer(); + Configuration.Settings.General.DefaultAdjustMilliseconds = (int)tc.TotalMilliseconds; } } diff --git a/src/Forms/VisualSync.cs b/src/Forms/VisualSync.cs index 02153a932..dddcad677 100644 --- a/src/Forms/VisualSync.cs +++ b/src/Forms/VisualSync.cs @@ -114,6 +114,10 @@ namespace Nikse.SubtitleEdit.Forms { VideoFileName = fileName; + FileInfo fi = new FileInfo(fileName); + if (fi.Length < 1000) + return; + if (MediaPlayerStart.VideoPlayer != null) { MediaPlayerStart.Pause(); diff --git a/src/Forms/Watermark.Designer.cs b/src/Forms/Watermark.Designer.cs new file mode 100644 index 000000000..e1fbbd631 --- /dev/null +++ b/src/Forms/Watermark.Designer.cs @@ -0,0 +1,158 @@ +namespace Nikse.SubtitleEdit.Forms +{ + partial class Watermark + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.LabelWatermark = new System.Windows.Forms.Label(); + this.groupBoxGenerate = new System.Windows.Forms.GroupBox(); + this.textBoxWatermark = new System.Windows.Forms.TextBox(); + this.radioButtonSpread = new System.Windows.Forms.RadioButton(); + this.radioButtonCurrentLine = new System.Windows.Forms.RadioButton(); + this.buttonGenerate = new System.Windows.Forms.Button(); + this.buttonRemove = new System.Windows.Forms.Button(); + this.buttonOK = new System.Windows.Forms.Button(); + this.groupBoxGenerate.SuspendLayout(); + this.SuspendLayout(); + // + // LabelWatermark + // + this.LabelWatermark.AutoSize = true; + this.LabelWatermark.Location = new System.Drawing.Point(4, 19); + this.LabelWatermark.Name = "LabelWatermark"; + this.LabelWatermark.Size = new System.Drawing.Size(62, 13); + this.LabelWatermark.TabIndex = 0; + this.LabelWatermark.Text = "Watermark:"; + // + // groupBoxGenerate + // + this.groupBoxGenerate.Controls.Add(this.textBoxWatermark); + this.groupBoxGenerate.Controls.Add(this.radioButtonSpread); + this.groupBoxGenerate.Controls.Add(this.radioButtonCurrentLine); + this.groupBoxGenerate.Controls.Add(this.buttonGenerate); + this.groupBoxGenerate.Location = new System.Drawing.Point(7, 69); + this.groupBoxGenerate.Name = "groupBoxGenerate"; + this.groupBoxGenerate.Size = new System.Drawing.Size(344, 100); + this.groupBoxGenerate.TabIndex = 1; + this.groupBoxGenerate.TabStop = false; + this.groupBoxGenerate.Text = "Generate watermark"; + // + // textBoxWatermark + // + this.textBoxWatermark.Location = new System.Drawing.Point(87, 68); + this.textBoxWatermark.MaxLength = 50; + this.textBoxWatermark.Name = "textBoxWatermark"; + this.textBoxWatermark.Size = new System.Drawing.Size(195, 20); + this.textBoxWatermark.TabIndex = 1; + // + // radioButtonSpread + // + this.radioButtonSpread.AutoSize = true; + this.radioButtonSpread.Checked = true; + this.radioButtonSpread.Location = new System.Drawing.Point(6, 19); + this.radioButtonSpread.Name = "radioButtonSpread"; + this.radioButtonSpread.Size = new System.Drawing.Size(148, 17); + this.radioButtonSpread.TabIndex = 2; + this.radioButtonSpread.TabStop = true; + this.radioButtonSpread.Text = "Spread over entire subtitle"; + this.radioButtonSpread.UseVisualStyleBackColor = true; + // + // radioButtonCurrentLine + // + this.radioButtonCurrentLine.AutoSize = true; + this.radioButtonCurrentLine.Location = new System.Drawing.Point(6, 42); + this.radioButtonCurrentLine.Name = "radioButtonCurrentLine"; + this.radioButtonCurrentLine.Size = new System.Drawing.Size(122, 17); + this.radioButtonCurrentLine.TabIndex = 1; + this.radioButtonCurrentLine.Text = "Only on current line: "; + this.radioButtonCurrentLine.UseVisualStyleBackColor = true; + // + // buttonGenerate + // + this.buttonGenerate.Location = new System.Drawing.Point(6, 65); + this.buttonGenerate.Name = "buttonGenerate"; + this.buttonGenerate.Size = new System.Drawing.Size(75, 21); + this.buttonGenerate.TabIndex = 0; + this.buttonGenerate.Text = "Generate"; + this.buttonGenerate.UseVisualStyleBackColor = true; + this.buttonGenerate.Click += new System.EventHandler(this.buttonGenerate_Click); + // + // buttonRemove + // + this.buttonRemove.Location = new System.Drawing.Point(7, 38); + this.buttonRemove.Name = "buttonRemove"; + this.buttonRemove.Size = new System.Drawing.Size(75, 21); + this.buttonRemove.TabIndex = 0; + this.buttonRemove.Text = "Remove"; + this.buttonRemove.UseVisualStyleBackColor = true; + this.buttonRemove.Click += new System.EventHandler(this.buttonRemove_Click); + // + // buttonOK + // + this.buttonOK.Location = new System.Drawing.Point(276, 175); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 21); + this.buttonOK.TabIndex = 1; + this.buttonOK.Text = "&OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // Watermark + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(356, 202); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonRemove); + this.Controls.Add(this.groupBoxGenerate); + this.Controls.Add(this.LabelWatermark); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "Watermark"; + this.Text = "Watermark"; + this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Watermark_KeyDown); + this.groupBoxGenerate.ResumeLayout(false); + this.groupBoxGenerate.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label LabelWatermark; + private System.Windows.Forms.GroupBox groupBoxGenerate; + private System.Windows.Forms.RadioButton radioButtonSpread; + private System.Windows.Forms.RadioButton radioButtonCurrentLine; + private System.Windows.Forms.Button buttonGenerate; + private System.Windows.Forms.Button buttonRemove; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.TextBox textBoxWatermark; + } +} \ No newline at end of file diff --git a/src/Forms/Watermark.cs b/src/Forms/Watermark.cs new file mode 100644 index 000000000..73799ad58 --- /dev/null +++ b/src/Forms/Watermark.cs @@ -0,0 +1,169 @@ +using System; +using System.Text; +using System.Windows.Forms; +using Nikse.SubtitleEdit.Logic; +using System.Collections.Generic; + +namespace Nikse.SubtitleEdit.Forms +{ + public sealed partial class Watermark : Form + { + const string zeroWhiteSpace = "\u200B"; + const string zeroWidthNoBreakSpace = "\uFEFF"; + + int _firstSelectedIndex; + + public Watermark() + { + InitializeComponent(); + } + + internal void Initialize(Logic.Subtitle subtitle, int firstSelectedIndex) + { + StringBuilder sb = new StringBuilder(); + foreach (Paragraph p in subtitle.Paragraphs) + sb.AppendLine(p.Text); + + string watermark = ReadWaterMark(sb.ToString().Trim()); + LabelWatermark.Text = string.Format("Watermark: {0}", watermark); + if (watermark.Length == 0) + { + buttonRemove.Enabled = false; + textBoxWatermark.Focus(); + } + else + { + groupBoxGenerate.Enabled = false; + buttonOK.Focus(); + } + + _firstSelectedIndex = firstSelectedIndex; + Paragraph current = subtitle.GetParagraphOrDefault(_firstSelectedIndex); + if (current != null) + radioButtonCurrentLine.Text = radioButtonCurrentLine.Text + " " + current.Text.Replace(Environment.NewLine, Configuration.Settings.General.ListViewLineSeparatorString); + else + radioButtonCurrentLine.Enabled = false; + } + + private string ReadWaterMark(string input) + { + int i = 0; + StringBuilder sb = new StringBuilder(); + bool letterOn = false; + int letter = 0; + while (i < input.Length) + { + string s = input.Substring(i, 1); + if (s == zeroWhiteSpace) + { + if (letter > 0) + sb.Append(Encoding.ASCII.GetString(new byte[] { (byte)letter })); + letterOn = true; + letter = 0; + } + else if (s == zeroWidthNoBreakSpace && letterOn) + { + letter++; + } + else + { + if (letter > 0) + sb.Append(Encoding.ASCII.GetString(new byte[] { (byte)letter })); + letterOn = false; + letter = 0; + } + i++; + } + return sb.ToString(); + } + + private void AddWaterMark(Subtitle subtitle, string input) + { + byte[] buffer = Encoding.ASCII.GetBytes(input); + + if (radioButtonCurrentLine.Checked) + { + StringBuilder sb = new StringBuilder(); + foreach (byte b in buffer) + { + sb.Append(zeroWhiteSpace); + for (int i = 0; i < b; i++) + sb.Append(zeroWidthNoBreakSpace); + } + Paragraph p = subtitle.GetParagraphOrDefault(_firstSelectedIndex); + if (p != null) + { + if (p.Text.Length > 1) + p.Text = p.Text.Insert(p.Text.Length / 2, sb.ToString()); + else + p.Text = sb.ToString() + p.Text; + } + } + else + { + Random r = new Random(); + List indices = new List(); + foreach (byte b in buffer) + { + int number = r.Next(subtitle.Paragraphs.Count - 1); + if (indices.Contains(number)) + number = r.Next(subtitle.Paragraphs.Count - 1); + if (indices.Contains(number)) + number = r.Next(subtitle.Paragraphs.Count - 1); + indices.Add(number); + } + + indices.Sort(); + int j = 0; + foreach (byte b in buffer) + { + StringBuilder sb = new StringBuilder(); + Paragraph p = subtitle.Paragraphs[indices[j]]; + sb.Append(zeroWhiteSpace); + for (int i = 0; i < b; i++) + sb.Append(zeroWidthNoBreakSpace); + if (p.Text.Length > 1) + p.Text = p.Text.Insert(p.Text.Length / 2, sb.ToString()); + else + p.Text = sb.ToString() + p.Text; + j++; + } + } + } + + private void buttonOK_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + } + + internal void AddOrRemove(Subtitle subtitle) + { + if (groupBoxGenerate.Enabled) + AddWaterMark(subtitle, textBoxWatermark.Text); + else + RemoveWaterMark(subtitle); + } + + private void RemoveWaterMark(Subtitle subtitle) + { + foreach (Paragraph p in subtitle.Paragraphs) + p.Text = p.Text.Replace(zeroWhiteSpace, string.Empty).Replace(zeroWidthNoBreakSpace, string.Empty); + } + + private void buttonGenerate_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.OK; + } + + private void Watermark_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Escape) + DialogResult = DialogResult.Cancel; + } + } +} diff --git a/src/Forms/Watermark.resx b/src/Forms/Watermark.resx new file mode 100644 index 000000000..5ea0895e3 --- /dev/null +++ b/src/Forms/Watermark.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/src/Logic/Language.cs b/src/Logic/Language.cs index 33332eacc..d7ccbba42 100644 --- a/src/Logic/Language.cs +++ b/src/Logic/Language.cs @@ -1069,6 +1069,7 @@ namespace Nikse.SubtitleEdit.Logic ShowEarlierLater = new LanguageStructure.ShowEarlierLater { Title = "Show selected lines earlier/later", + TitleAll = "Show all lines earlier/later", ShowEarlier = "Show earlier", ShowLater = "Show later", TotalAdjustmentX = "Total adjustment: {0}", diff --git a/src/Logic/LanguageStructure.cs b/src/Logic/LanguageStructure.cs index 549b0f3fa..26e1a3663 100644 --- a/src/Logic/LanguageStructure.cs +++ b/src/Logic/LanguageStructure.cs @@ -1006,6 +1006,7 @@ public class ShowEarlierLater { public string Title { get; set; } + public string TitleAll { get; set; } public string ShowEarlier { get; set; } public string ShowLater { get; set; } public string TotalAdjustmentX { get; set; } diff --git a/src/Logic/VideoFormats/Matroska.cs b/src/Logic/VideoFormats/Matroska.cs index 519e0a14a..bbfa69617 100644 --- a/src/Logic/VideoFormats/Matroska.cs +++ b/src/Logic/VideoFormats/Matroska.cs @@ -4,6 +4,30 @@ using System.IO; namespace Nikse.SubtitleEdit.Logic { + public class SubtitleSequence + { + public long StartMilliseconds { get; set; } + public long EndMilliseconds { get; set; } + public byte[] BinaryData { get; set; } + + public SubtitleSequence(byte[] data, long startMilliseconds, long endMilliseconds) + { + BinaryData = data; + StartMilliseconds = startMilliseconds; + EndMilliseconds = endMilliseconds; + } + + public string Text + { + get + { + if (BinaryData != null) + return System.Text.Encoding.UTF8.GetString(BinaryData).Replace("\\N", Environment.NewLine); + return string.Empty; + } + } + } + public class MatroskaSubtitleInfo { public long TrackNumber { get; set; } @@ -92,7 +116,8 @@ namespace Nikse.SubtitleEdit.Logic List _subtitleList; int _subtitleRipTrackNumber = 0; - Subtitle _subtitleRip = new Subtitle(); + List _subtitleRip = new List(); + //Subtitle _subtitleRip = new Subtitle(); private static int GetMatroskaVariableIntLength(byte b) @@ -953,16 +978,17 @@ namespace Nikse.SubtitleEdit.Logic break; } - - // save subtitle data if (trackNo == _subtitleRipTrackNumber) { long sublength = afterPosition - f.Position; if (sublength > 0) { - string s = GetMatroskaString(sublength); - s = s.Replace("\\N", Environment.NewLine); + byte[] buffer = new byte[sublength]; + f.Read(buffer, 0, (int)sublength); + + //string s = GetMatroskaString(sublength); + //s = s.Replace("\\N", Environment.NewLine); f.Seek(afterPosition, SeekOrigin.Begin); b = (byte)f.ReadByte(); @@ -974,7 +1000,7 @@ namespace Nikse.SubtitleEdit.Logic duration = GetMatroskaVariableSizeUnsignedInt(dataSize); } - _subtitleRip.Paragraphs.Add(new Paragraph(s, timeCode + clusterTimeCode, timeCode + clusterTimeCode + duration)); + _subtitleRip.Add(new SubtitleSequence(buffer, timeCode + clusterTimeCode, timeCode + clusterTimeCode + duration)); } } @@ -1061,7 +1087,7 @@ namespace Nikse.SubtitleEdit.Logic return _subtitleList; } - public Subtitle GetMatroskaSubtitle(string fileName, int trackNumber, out bool isValid) + public List GetMatroskaSubtitle(string fileName, int trackNumber, out bool isValid) { byte b; bool done; diff --git a/src/SubtitleEdit.csproj b/src/SubtitleEdit.csproj index 038f987a0..4a25601cf 100644 --- a/src/SubtitleEdit.csproj +++ b/src/SubtitleEdit.csproj @@ -35,6 +35,7 @@ 3 2.0.1.%2a false + true true @@ -76,7 +77,10 @@ True DLLs\Interop.QuartzTypeLib.dll - + + False + DLLs\NHunspell.dll + @@ -393,6 +397,12 @@ VobSubOcrNewFolder.cs + + Form + + + Watermark.cs + @@ -688,6 +698,9 @@ VobSubOcrNewFolder.cs Designer + + Watermark.cs + PublicResXFileCodeGenerator Resources.Designer.cs