Skip to content

Commit

Permalink
Generate export files with begin and end
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Apr 3, 2024
1 parent 33c1bfb commit ac628a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
15 changes: 11 additions & 4 deletions AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public ExportfileGenerator(ExportType exportType, Cuesheet cuesheet, Exportprofi

public IReadOnlyCollection<Exportfile> GenerateExportfiles()
{
//TODO: Generate export files with start 00:00:00 and each end set correctly!
List<Exportfile> 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;
Expand All @@ -79,7 +79,11 @@ public IReadOnlyCollection<Exportfile> 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++;
Expand All @@ -103,7 +107,8 @@ public IReadOnlyCollection<Exportfile> 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
Expand Down Expand Up @@ -140,7 +145,9 @@ public IReadOnlyCollection<Exportfile> 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 });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit ac628a5

Please sign in to comment.