From ff629f512e6a3fc3ef439b65b40cc4d3ca3b1f7b Mon Sep 17 00:00:00 2001 From: niksedk Date: Fri, 29 Oct 2021 20:56:25 +0200 Subject: [PATCH] Testing waveform move perf --- src/ui/Controls/SubtitleListView.cs | 62 +++++++++++++++++++++++++++-- src/ui/Forms/Main.cs | 10 ++--- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/ui/Controls/SubtitleListView.cs b/src/ui/Controls/SubtitleListView.cs index d9f3280c0..edc46f419 100644 --- a/src/ui/Controls/SubtitleListView.cs +++ b/src/ui/Controls/SubtitleListView.cs @@ -94,16 +94,27 @@ namespace Nikse.SubtitleEdit.Controls private bool _saveColumnWidthChanges; private Timer _setLastColumnWidthTimer; - public class SyntaxColorLineParamter + public class SyntaxColorLineParameter { public List Paragraphs { get; set; } public int Index { get; set; } public Paragraph Paragraph { get; set; } } - private readonly List _syntaxColorList = new List(); + public class SetStartAndDurationParameter + { + public int Index { get; set; } + public Paragraph Paragraph { get; set; } + public Paragraph Next { get; set; } + public Paragraph Prev { get; set; } + } + + private readonly List _syntaxColorList = new List(); + private readonly List _setStartAndDurationList = new List(); private static readonly object SyntaxColorListLock = new object(); + private static readonly object SetStartTimeAndDurationLock = new object(); private readonly Timer _syntaxColorLineTimer; + private readonly Timer _setStartAndDurationTimer; public int FirstVisibleIndex { get; set; } = -1; @@ -386,9 +397,12 @@ namespace Nikse.SubtitleEdit.Controls ShowGapColumn(LanguageSettings.Current.General.Gap); } - _syntaxColorLineTimer = new Timer { Interval = 50 }; + _syntaxColorLineTimer = new Timer { Interval = 43 }; _syntaxColorLineTimer.Tick += SyntaxColorLineTimerTick; + _setStartAndDurationTimer = new Timer { Interval = 49 }; + _setStartAndDurationTimer.Tick += SetStartAndDurationTimerTick; + SubtitleListViewLastColumnFill(this, null); FullRowSelect = true; @@ -1351,6 +1365,28 @@ namespace Nikse.SubtitleEdit.Controls } } + private void SetStartAndDurationTimerTick(object sender, EventArgs e) + { + var hashSet = new HashSet(); + lock (SetStartTimeAndDurationLock) + { + _setStartAndDurationTimer.Stop(); + for (int i = _setStartAndDurationList.Count - 1; i >= 0; i--) + { + var item = _setStartAndDurationList[i]; + if (!hashSet.Contains(item.Index)) + { + if (IsValidIndex(item.Index)) + { + SetStartTimeAndDuration(item.Index, item.Paragraph, item.Next, item.Prev); + } + hashSet.Add(item.Index); + } + } + _setStartAndDurationList.Clear(); + } + } + /// /// Can handle multiple events to same line - but not line adding/splitting. /// @@ -1364,11 +1400,29 @@ namespace Nikse.SubtitleEdit.Controls lock (SyntaxColorListLock) { _syntaxColorLineTimer.Stop(); - _syntaxColorList.Add(new SyntaxColorLineParamter { Index = i, Paragraphs = paragraphs, Paragraph = paragraph }); + _syntaxColorList.Add(new SyntaxColorLineParameter { Index = i, Paragraphs = paragraphs, Paragraph = paragraph }); _syntaxColorLineTimer.Start(); } } + /// + /// Can handle multiple events to same line - but not line adding/splitting. + /// + public void SetStartTimeAndDurationBackground(int index, Paragraph paragraph, Paragraph next, Paragraph prev) + { + if (_settings == null) + { + return; + } + + lock (SetStartTimeAndDurationLock) + { + _setStartAndDurationTimer.Stop(); + _setStartAndDurationList.Add(new SetStartAndDurationParameter { Index = index, Paragraph = paragraph, Next = next, Prev = prev }); + _setStartAndDurationTimer.Start(); + } + } + public void SyntaxColorLine(List paragraphs, int i, Paragraph paragraph) { if (UseSyntaxColoring && _settings != null && IsValidIndex(i)) diff --git a/src/ui/Forms/Main.cs b/src/ui/Forms/Main.cs index 1313a2295..603e74b3a 100644 --- a/src/ui/Forms/Main.cs +++ b/src/ui/Forms/Main.cs @@ -1163,7 +1163,7 @@ namespace Nikse.SubtitleEdit.Forms } InitializeListViewEditBoxTimeOnly(p); - SubtitleListview1.SetStartTimeAndDuration(index, p, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); + SubtitleListview1.SetStartTimeAndDurationBackground(index, p, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); UpdateSourceView(); } @@ -1238,7 +1238,7 @@ namespace Nikse.SubtitleEdit.Forms timeUpDownStartTime.MaskedTextBox.TextChanged -= MaskedTextBoxTextChanged; timeUpDownStartTime.TimeCode = paragraph.StartTime; timeUpDownStartTime.MaskedTextBox.TextChanged += MaskedTextBoxTextChanged; - SubtitleListview1.SetStartTimeAndDuration(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); + SubtitleListview1.SetStartTimeAndDurationBackground(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); var durationInSeconds = (decimal)paragraph.Duration.TotalSeconds; if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum) @@ -1277,7 +1277,7 @@ namespace Nikse.SubtitleEdit.Forms index = _subtitle.GetIndex(current); - SubtitleListview1.SetStartTimeAndDuration(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); + SubtitleListview1.SetStartTimeAndDurationBackground(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); if (index == selectedIndex) { @@ -1313,7 +1313,7 @@ namespace Nikse.SubtitleEdit.Forms original.EndTime.TotalMilliseconds = paragraph.EndTime.TotalMilliseconds; } - SubtitleListview1.SetStartTimeAndDuration(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); + SubtitleListview1.SetStartTimeAndDurationBackground(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); } } else @@ -1357,7 +1357,7 @@ namespace Nikse.SubtitleEdit.Forms } } - SubtitleListview1.SetStartTimeAndDuration(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); + SubtitleListview1.SetStartTimeAndDurationBackground(index, paragraph, _subtitle.GetParagraphOrDefault(index + 1), _subtitle.GetParagraphOrDefault(index - 1)); } beforeParagraph.StartTime.TotalMilliseconds = paragraph.StartTime.TotalMilliseconds;