From 6a0cb5bdf42dc61d4e75ac471edd6f7f8d5eec94 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 4 Aug 2016 22:41:37 +0200 Subject: [PATCH] Remember scene changes --- libse/LibSE.csproj | 1 + libse/SceneChangeHelper.cs | 52 ++++++++++++++++++++++++++++++++++++++ src/Forms/Main.cs | 5 ++++ 3 files changed, 58 insertions(+) create mode 100644 libse/SceneChangeHelper.cs diff --git a/libse/LibSE.csproj b/libse/LibSE.csproj index d19fe2633..54bb831af 100644 --- a/libse/LibSE.csproj +++ b/libse/LibSE.csproj @@ -180,6 +180,7 @@ + diff --git a/libse/SceneChangeHelper.cs b/libse/SceneChangeHelper.cs new file mode 100644 index 000000000..f84e6d49a --- /dev/null +++ b/libse/SceneChangeHelper.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Text; + +namespace Nikse.SubtitleEdit.Core +{ + public static class SceneChangeHelper + { + + public static string GetSceneChangesFileName(string videoFileName) + { + var fileName = WavePeakGenerator.GetPeakWaveFileName(videoFileName); + return Path.GetFileNameWithoutExtension(fileName) + ".scenechanges"; + } + + public static List FromDisk(string videoFileName) + { + var list = new List(); + var sceneChangesFileName = GetSceneChangesFileName(videoFileName); + if (!File.Exists(sceneChangesFileName)) + return list; + + foreach (var line in File.ReadLines(sceneChangesFileName)) + { + if (!string.IsNullOrWhiteSpace(line)) + { + list.Add(double.Parse(line, CultureInfo.InvariantCulture)); + } + } + return list; + } + + public static void SaveSceneChangesInSeconds(string videoFileName, List list) + { + var sb = new StringBuilder(); + foreach (var d in list) + { + sb.AppendLine(d.ToString(CultureInfo.InvariantCulture)); + } + File.WriteAllText(GetSceneChangesFileName(videoFileName), sb.ToString().Trim()); + } + + public static void DeleteSceneChangesInSeconds(string videoFileName) + { + var sceneChangesFileName = GetSceneChangesFileName(videoFileName); + if (File.Exists(sceneChangesFileName)) + File.Delete(sceneChangesFileName); + } + + } +} diff --git a/src/Forms/Main.cs b/src/Forms/Main.cs index dfb79e4cb..768d36a6e 100644 --- a/src/Forms/Main.cs +++ b/src/Forms/Main.cs @@ -13183,6 +13183,7 @@ namespace Nikse.SubtitleEdit.Forms { audioVisualizer.WavePeaks = WavePeakData.FromDisk(peakWaveFileName); audioVisualizer.Spectrogram = SpectrogramData.FromDisk(spectrogramFolder); + audioVisualizer.SceneChanges = SceneChangeHelper.FromDisk(_videoFileName); toolStripComboBoxWaveform_SelectedIndexChanged(null, null); SetWaveformPosition(0, 0, 0); timerWaveform.Start(); @@ -19668,6 +19669,7 @@ namespace Nikse.SubtitleEdit.Forms if (form.ShowDialog(this) == DialogResult.OK) { audioVisualizer.SceneChanges = form.SceneChangesInSeconds; + SceneChangeHelper.SaveSceneChangesInSeconds(_videoFileName, audioVisualizer.SceneChanges); ShowStatus(string.Format(_language.XSceneChangesImported, form.SceneChangesInSeconds.Count)); } } @@ -19676,7 +19678,10 @@ namespace Nikse.SubtitleEdit.Forms private void toolStripMenuItemRemoveSceneChanges_Click(object sender, EventArgs e) { if (audioVisualizer != null && audioVisualizer.SceneChanges != null) + { audioVisualizer.SceneChanges = new List(); + SceneChangeHelper.DeleteSceneChangesInSeconds(_videoFileName); + } } private void toolStripMenuItemDurationBridgeGaps_Click(object sender, EventArgs e)