From ac628a5a4b097a5de76881935c7b20f594289376 Mon Sep 17 00:00:00 2001 From: NeoCoderMatrix86 <40752681+NeoCoderMatrix86@users.noreply.github.com> Date: Wed, 3 Apr 2024 08:40:45 +0200 Subject: [PATCH] Generate export files with begin and end --- .../Model/IO/Export/ExportfileGenerator.cs | 15 +++++++++++---- .../Model/IO/Export/ExportfileGeneratorTests.cs | 8 ++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs index f4c2833b..50f4d964 100644 --- a/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs +++ b/AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs @@ -47,13 +47,13 @@ public ExportfileGenerator(ExportType exportType, Cuesheet cuesheet, Exportprofi public IReadOnlyCollection GenerateExportfiles() { - //TODO: Generate export files with start 00:00:00 and each end set correctly! List exportfiles = new(); if (Validate().Status != ValidationStatus.Error) { if (Cuesheet.SplitPoints.Count != 0) { TimeSpan? previousSplitPointMoment = null; + var begin = Cuesheet.Tracks.Min(x => x.Begin); var counter = 1; String? content = null; String filename = String.Empty; @@ -79,7 +79,11 @@ public IReadOnlyCollection GenerateExportfiles() } if (content != null) { - exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = previousSplitPointMoment, End = splitPoint.Moment }); + if (previousSplitPointMoment != null) + { + begin = previousSplitPointMoment; + } + exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = begin, End = splitPoint.Moment }); } previousSplitPointMoment = splitPoint.Moment; counter++; @@ -103,7 +107,8 @@ public IReadOnlyCollection GenerateExportfiles() } if (content != null) { - exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = previousSplitPointMoment }); + var end = Cuesheet.Tracks.Max(x => x.End); + exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = previousSplitPointMoment, End = end }); } } else @@ -140,7 +145,9 @@ public IReadOnlyCollection GenerateExportfiles() } if (content != null) { - exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content) }); + var begin = Cuesheet.Tracks.Min(x => x.Begin); + var end = Cuesheet.Tracks.Max(x => x.End); + exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = begin, End = end }); } } } diff --git a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs index 79bcb516..d1bf57d4 100644 --- a/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs +++ b/AudioCuesheetEditorTests/Model/IO/Export/ExportfileGeneratorTests.cs @@ -322,7 +322,7 @@ public void GenerateCuesheetFilesWithSplitPointsTest() var position = 1; var counter = 1; //Check split according to split points - Assert.IsNull(generatedFiles.First().Begin); + Assert.AreEqual(cuesheet.Tracks.Min(x => x.Begin), generatedFiles.First().Begin); Assert.AreEqual(new TimeSpan(0, 30, 0), generatedFiles.First().End); Assert.AreEqual(new TimeSpan(0, 30, 0), generatedFiles.ElementAt(1).Begin); Assert.AreEqual(new TimeSpan(1, 0, 0), generatedFiles.ElementAt(1).End); @@ -331,7 +331,7 @@ public void GenerateCuesheetFilesWithSplitPointsTest() Assert.AreEqual(new TimeSpan(1, 30, 0), generatedFiles.ElementAt(3).Begin); Assert.AreEqual(new TimeSpan(2, 0, 0), generatedFiles.ElementAt(3).End); Assert.AreEqual(new TimeSpan(2, 0, 0), generatedFiles.ElementAt(4).Begin); - Assert.IsNull(generatedFiles.Last().End); + Assert.AreEqual(cuesheet.Tracks.Max(x => x.End), generatedFiles.Last().End); foreach (var generatedFile in generatedFiles) { Assert.AreEqual(String.Format("Unit test({0}).cue", counter), generatedFile.Name); @@ -647,7 +647,7 @@ public void GenerateExportfilesWithSplitPointsTest() Assert.AreEqual(5, generatedFiles.Count); //Check split according to split points - Assert.IsNull(generatedFiles.First().Begin); + Assert.AreEqual(cuesheet.Tracks.Min(x => x.Begin), generatedFiles.First().Begin); Assert.AreEqual(new TimeSpan(0, 30, 0), generatedFiles.First().End); Assert.AreEqual(new TimeSpan(0, 30, 0), generatedFiles.ElementAt(1).Begin); Assert.AreEqual(new TimeSpan(1, 0, 0), generatedFiles.ElementAt(1).End); @@ -656,7 +656,7 @@ public void GenerateExportfilesWithSplitPointsTest() Assert.AreEqual(new TimeSpan(1, 30, 0), generatedFiles.ElementAt(3).Begin); Assert.AreEqual(new TimeSpan(2, 0, 0), generatedFiles.ElementAt(3).End); Assert.AreEqual(new TimeSpan(2, 0, 0), generatedFiles.ElementAt(4).Begin); - Assert.IsNull(generatedFiles.Last().End); + Assert.AreEqual(cuesheet.Tracks.Max(x => x.End), generatedFiles.Last().End); var counter = 1; var position = 1; foreach (var generatedFile in generatedFiles)