Skip to content

Commit

Permalink
Fixed renamed entities
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Apr 15, 2024
1 parent 3078237 commit 0590288
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 102 deletions.
21 changes: 11 additions & 10 deletions AudioCuesheetEditor/Model/IO/Export/ExportfileGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ public IReadOnlyCollection<Exportfile> GenerateExportfiles()
List<Exportfile> exportfiles = [];
if (Validate().Status != ValidationStatus.Error)
{
if (Cuesheet.SplitPoints.Count != 0)
if (Cuesheet.Sections.Count != 0)
{
//TODO: Generate only splitpoint content (starting from begin to end)
TimeSpan? previousSplitPointMoment = null;
var begin = Cuesheet.Tracks.Min(x => x.Begin);
var counter = 1;
String? content = null;
String filename = String.Empty;
String? audioFileName = null;
foreach (var splitPoint in Cuesheet.SplitPoints.OrderBy(x => x.Moment))
foreach (var splitPoint in Cuesheet.Sections.OrderBy(x => x.Begin))
{
audioFileName = splitPoint.AudiofileName;
if (splitPoint.Validate().Status == ValidationStatus.Success)
Expand All @@ -75,9 +76,9 @@ public IReadOnlyCollection<Exportfile> GenerateExportfiles()
{
begin = previousSplitPointMoment;
}
exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = begin, End = splitPoint.Moment });
exportfiles.Add(new Exportfile() { Name = filename, Content = Encoding.UTF8.GetBytes(content), Begin = begin, End = splitPoint.Begin });
}
previousSplitPointMoment = splitPoint.Moment;
previousSplitPointMoment = splitPoint.Begin;
counter++;
}
}
Expand Down Expand Up @@ -146,7 +147,7 @@ public IReadOnlyCollection<Exportfile> GenerateExportfiles()
return exportfiles;
}

private string WriteCuesheet(String? audiofileName, TimeSpan? from = null, SplitPoint? splitPoint = null)
private string WriteCuesheet(String? audiofileName, TimeSpan? from = null, CuesheetSection? splitPoint = null)
{
var builder = new StringBuilder();
if (Cuesheet.Cataloguenumber != null && string.IsNullOrEmpty(Cuesheet.Cataloguenumber.Value) == false && Cuesheet.Cataloguenumber.Validate().Status != ValidationStatus.Error)
Expand All @@ -163,7 +164,7 @@ private string WriteCuesheet(String? audiofileName, TimeSpan? from = null, Split
IEnumerable<Track> tracks = Cuesheet.Tracks.OrderBy(x => x.Position);
if (from != null && splitPoint != null)
{
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Moment && x.End >= from).OrderBy(x => x.Position);
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Begin && x.End >= from).OrderBy(x => x.Position);
}
else
{
Expand All @@ -173,7 +174,7 @@ private string WriteCuesheet(String? audiofileName, TimeSpan? from = null, Split
}
if (splitPoint != null)
{
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Moment).OrderBy(x => x.Position);
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Begin).OrderBy(x => x.Position);
}
}
if (tracks.Any())
Expand Down Expand Up @@ -222,7 +223,7 @@ private string WriteCuesheet(String? audiofileName, TimeSpan? from = null, Split
return builder.ToString();
}

private String WriteExport(String? audiofileName, TimeSpan? from = null, SplitPoint? splitPoint = null)
private String WriteExport(String? audiofileName, TimeSpan? from = null, CuesheetSection? splitPoint = null)
{
var builder = new StringBuilder();
if (Exportprofile != null)
Expand All @@ -240,7 +241,7 @@ private String WriteExport(String? audiofileName, TimeSpan? from = null, SplitPo
IEnumerable<Track> tracks = Cuesheet.Tracks.OrderBy(x => x.Position);
if (from != null && splitPoint != null)
{
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Moment && x.End >= from).OrderBy(x => x.Position);
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Begin && x.End >= from).OrderBy(x => x.Position);
}
else
{
Expand All @@ -250,7 +251,7 @@ private String WriteExport(String? audiofileName, TimeSpan? from = null, SplitPo
}
if (splitPoint != null)
{
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Moment).OrderBy(x => x.Position);
tracks = Cuesheet.Tracks.Where(x => x.Begin <= splitPoint.Begin).OrderBy(x => x.Position);
}
}
if (tracks.Any())
Expand Down
29 changes: 15 additions & 14 deletions AudioCuesheetEditor/Pages/EditSplitpoints.razor
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ along with Foobar. If not, see
@inject TraceChangeManager _traceChangeManager
@inject IJSRuntime _jsRuntime

<Validations @ref="validations">
@* <Validations @ref="validations">
@if (Cuesheet != null)
{
@if (_sessionStateContainer.CurrentViewMode == ViewMode.ViewModeFull)
Expand Down Expand Up @@ -56,7 +56,7 @@ along with Foobar. If not, see
</TableRow>
</TableHeader>
<TableBody>
@foreach (var splitPoint in Cuesheet.SplitPoints)
@foreach (var splitPoint in Cuesheet.Sections)
{
<TableRow>
<TableRowCell>
Expand All @@ -75,16 +75,16 @@ along with Foobar. If not, see
</Buttons>
</TableRowCell>
<TableRowCell>
<Validation AsyncValidator="(args, token) => ValidatorUtility<SplitPoint>.Validate(args, splitPoint, x => x.Moment, _validationMessageLocalizer, token)">
<TextEdit Text="@splitPoint.Moment?.ToString()" TextChanged="(value) => _dateTimeUtility.TimespanTextChanged<SplitPoint, TimeSpan?>(splitPoint, x => x.Moment, value)" Immediate="false">
<Validation AsyncValidator="(args, token) => ValidatorUtility<CuesheetSection>.Validate(args, splitPoint, x => x.Begin, _validationMessageLocalizer, token)">
<TextEdit Text="@splitPoint.Begin?.ToString()" TextChanged="(value) => _dateTimeUtility.TimespanTextChanged<CuesheetSection, TimeSpan?>(splitPoint, x => x.Begin, value)" Immediate="false">
<Feedback>
<ValidationError />
</Feedback>
</TextEdit>
</Validation>
</TableRowCell>
<TableRowCell>
<Validation AsyncValidator="(args, token) => ValidatorUtility<SplitPoint>.Validate(args, splitPoint, x => x.Artist, _validationMessageLocalizer, token)">
<Validation AsyncValidator="(args, token) => ValidatorUtility<CuesheetSection>.Validate(args, splitPoint, x => x.Artist, _validationMessageLocalizer, token)">
<TextEdit @bind-Text="splitPoint.Artist" Immediate="false">
<Feedback>
<ValidationError />
Expand All @@ -93,7 +93,7 @@ along with Foobar. If not, see
</Validation>
</TableRowCell>
<TableRowCell>
<Validation AsyncValidator="(args, token) => ValidatorUtility<SplitPoint>.Validate(args, splitPoint, x => x.Title, _validationMessageLocalizer, token)">
<Validation AsyncValidator="(args, token) => ValidatorUtility<CuesheetSection>.Validate(args, splitPoint, x => x.Title, _validationMessageLocalizer, token)">
<TextEdit @bind-Text="splitPoint.Title" Immediate="false">
<Feedback>
<ValidationError />
Expand All @@ -102,7 +102,7 @@ along with Foobar. If not, see
</Validation>
</TableRowCell>
<TableRowCell>
<Validation @ref="audiofileValidation" AsyncValidator="(args, token) => ValidatorUtility<SplitPoint>.Validate(args, splitPoint, x => x.AudiofileName, _validationMessageLocalizer, token)">
<Validation @ref="audiofileValidation" AsyncValidator="(args, token) => ValidatorUtility<CuesheetSection>.Validate(args, splitPoint, x => x.AudiofileName, _validationMessageLocalizer, token)">
@if (String.IsNullOrEmpty(splitPoint.AudiofileName))
{
<FileEdit id="@fileEditAudiofileIds[splitPoint]" Filter="@String.Join(",", Audiofile.AudioCodecs.Select(x => x.MimeType))" Changed="(args) => OnSplitpointAudiofileChanged(args, splitPoint)" AutoReset="false">
Expand Down Expand Up @@ -133,15 +133,16 @@ along with Foobar. If not, see
</TableBody>
</Table>
}
</Validations>
</Validations> *@

<ModalDialog @ref="modalDialog" />

@code {
//TODO: Rename component!
Validations? validations;

Check warning on line 142 in AudioCuesheetEditor/Pages/EditSplitpoints.razor

View workflow job for this annotation

GitHub Actions / run-unit-tests

Field 'EditSplitpoints.validations' is never assigned to, and will always have its default value null
ModalDialog? modalDialog;
Validation? audiofileValidation;

Check warning on line 144 in AudioCuesheetEditor/Pages/EditSplitpoints.razor

View workflow job for this annotation

GitHub Actions / run-unit-tests

Field 'EditSplitpoints.audiofileValidation' is never assigned to, and will always have its default value null
Dictionary<SplitPoint, Guid> fileEditAudiofileIds = new();
Dictionary<CuesheetSection, Guid> fileEditAudiofileIds = new();

public Cuesheet? Cuesheet
{
Expand Down Expand Up @@ -204,18 +205,18 @@ along with Foobar. If not, see
{
if (Cuesheet != null)
{
var splitPoint = Cuesheet.AddSplitPoint();
var splitPoint = Cuesheet.AddSection();
_traceChangeManager.TraceChanges(splitPoint);
fileEditAudiofileIds.Add(splitPoint, Guid.NewGuid());
}
return Task.CompletedTask;
}

Task DeleteSplitPointClicked(SplitPoint splitPoint)
Task DeleteSplitPointClicked(CuesheetSection splitPoint)
{
if (Cuesheet != null)
{
Cuesheet.RemoveSplitPoint(splitPoint);
Cuesheet.RemoveSection(splitPoint);
}
return Task.CompletedTask;
}
Expand Down Expand Up @@ -265,15 +266,15 @@ along with Foobar. If not, see
StateHasChanged();
}

async Task OnSplitpointAudiofileChangedCliccked(SplitPoint splitPoint)
async Task OnSplitpointAudiofileChangedCliccked(CuesheetSection splitPoint)
{
splitPoint.AudiofileName = null;
StateHasChanged();
await Task.Delay(1);
await _jsRuntime.InvokeVoidAsync("triggerClick", fileEditAudiofileIds[splitPoint]);
}

async Task OnSplitpointAudiofileChanged(FileChangedEventArgs e, SplitPoint splitPoint)
async Task OnSplitpointAudiofileChanged(FileChangedEventArgs e, CuesheetSection splitPoint)
{
if (e.Files.FirstOrDefault() != null)
{
Expand Down
23 changes: 12 additions & 11 deletions AudioCuesheetEditor/Shared/TracksTable.razor
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ along with Foobar. If not, see
case ViewMode.ViewModeImport:
<TableRowCell>
<Div Flex="Flex.JustifyContent.Start.AlignItems.Center">
@if (Cuesheet?.GetSplitPointAtTrack(track) != null)
@if (Cuesheet?.GetSectionAtTrack(track) != null)
{
<Tooltip Text="@_localizer["A split point is currently set at the time of this track"]">
<Badge Color="Color.Info" Pill>
Expand Down Expand Up @@ -768,35 +768,36 @@ along with Foobar. If not, see
{
if (Cuesheet != null)
{
Cuesheet.SplitPointAdded += Cuesheet_SplitPointAdded;
Cuesheet.SplitPointRemoved += Cuesheet_SplitPointRemoved;
Cuesheet.SectionAdded += Cuesheet_SectionAdded;
Cuesheet.SectionRemoved += Cuesheet_SectionRemoved;
}
}

void DetachCuesheetFromSplitPointsAddedRemoved()
{
if (Cuesheet != null)
{
Cuesheet.SplitPointAdded -= Cuesheet_SplitPointAdded;
Cuesheet.SplitPointRemoved -= Cuesheet_SplitPointRemoved;
Cuesheet.SectionAdded -= Cuesheet_SectionAdded;
Cuesheet.SectionRemoved -= Cuesheet_SectionRemoved;
}
}

void Cuesheet_SplitPointAdded(object? sender, SplitPointAddRemoveEventArgs args)
void Cuesheet_SectionAdded(object? sender, CuesheetSectionAddRemoveEventArgs args)
{
args.SplitPoint.ValidateablePropertyChanged += SplitPoint_ValidateablePropertyChanged;
args.Section.ValidateablePropertyChanged += Section_ValidateablePropertyChanged;
}

void Cuesheet_SplitPointRemoved(object? sender, SplitPointAddRemoveEventArgs args)
void Cuesheet_SectionRemoved(object? sender, CuesheetSectionAddRemoveEventArgs args)
{
args.SplitPoint.ValidateablePropertyChanged -= SplitPoint_ValidateablePropertyChanged;
args.Section.ValidateablePropertyChanged -= Section_ValidateablePropertyChanged;
}

void SplitPoint_ValidateablePropertyChanged(object? sender, string property)
void Section_ValidateablePropertyChanged(object? sender, string property)
{
switch (property)
{
case nameof(SplitPoint.Moment):
case nameof(CuesheetSection.Begin):
case nameof(CuesheetSection.End):
StateHasChanged();
break;
}
Expand Down
6 changes: 3 additions & 3 deletions AudioCuesheetEditorTests/Model/AudioCuesheet/CuesheetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,12 @@ public void ImportProjectfileTest()
var fileContent = Encoding.UTF8.GetBytes("{\"Tracks\":[{\"Position\":1,\"Artist\":\"Artist 1\",\"Title\":\"Title 1\",\"Begin\":\"00:00:00\",\"End\":\"00:01:01\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":2,\"Artist\":\"Artist 2\",\"Title\":\"Title 2\",\"Begin\":\"00:01:01\",\"End\":\"00:03:03\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":3,\"Artist\":\"Artist 3\",\"Title\":\"Title 3\",\"Begin\":\"00:03:03\",\"End\":\"00:06:06\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":4,\"Artist\":\"Artist 4\",\"Title\":\"Title 4\",\"Begin\":\"00:06:06\",\"End\":\"00:10:10\",\"Flags\":[\"4CH\",\"DCP\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":5,\"Artist\":\"Artist 5\",\"Title\":\"Title 5\",\"Begin\":\"00:10:10\",\"End\":\"00:15:15\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":6,\"Artist\":\"Artist 6\",\"Title\":\"Title 6\",\"Begin\":\"00:15:15\",\"End\":\"00:21:21\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":7,\"Artist\":\"Artist 7\",\"Title\":\"Title 7\",\"Begin\":\"00:21:21\",\"End\":\"00:28:28\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":8,\"Artist\":\"Artist 8\",\"Title\":\"Title 8\",\"Begin\":\"00:28:28\",\"End\":\"00:36:36\",\"Flags\":[\"4CH\",\"DCP\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":9,\"Artist\":\"Artist 9\",\"Title\":\"Title 9\",\"Begin\":\"00:36:36\",\"End\":\"00:45:45\",\"Flags\":[\"4CH\"],\"IsLinkedToPreviousTrack\":true},{\"Position\":10,\"Artist\":\"Artist 10\",\"Title\":\"Title 10\",\"Begin\":\"00:45:45\",\"End\":\"00:55:55\",\"Flags\":[\"4CH\",\"DCP\"],\"IsLinkedToPreviousTrack\":true}],\"Artist\":\"CuesheetArtist\",\"Title\":\"CuesheetTitle\",\"Audiofile\":{\"Name\":\"AudioFile.mp3\"},\"CDTextfile\":{\"Name\":\"CDTextfile.cdt\"},\"Cataloguenumber\":{\"Value\":\"A123\"},\"SplitPoints\":[{\"Artist\":\"CuesheetArtist\",\"Title\":\"CuesheetTitle\",\"Moment\":\"00:30:00\"},{\"Artist\":\"CuesheetArtist\",\"Title\":\"CuesheetTitle\",\"Moment\":\"01:00:00\"}]}");
var projectFileCuesheet = Projectfile.ImportFile(fileContent);
Assert.IsNotNull(projectFileCuesheet);
Assert.AreEqual(2, projectFileCuesheet.SplitPoints.Count);
Assert.AreEqual(2, projectFileCuesheet.Sections.Count);
var cuesheet = new Cuesheet();
var testHelper = new TestHelper();
cuesheet.Import(projectFileCuesheet, testHelper.ApplicationOptions);
Assert.AreEqual(2, cuesheet.SplitPoints.Count);
Assert.IsTrue(cuesheet.SplitPoints.All(x => x.Cuesheet == cuesheet));
Assert.AreEqual(2, cuesheet.Sections.Count);
Assert.IsTrue(cuesheet.Sections.All(x => x.Cuesheet == cuesheet));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@
namespace AudioCuesheetEditor.Model.IO.Export.Tests
{
[TestClass()]
public class SplitPointTests
public class CuesheetSectionTests
{
[TestMethod()]
public void ValidationTest()
{
var cuesheet = new Cuesheet();
var splitPoint = new SplitPoint(cuesheet);
Assert.IsNull(splitPoint.Moment);
var validationResult = splitPoint.Validate(x => x.Moment);
var section = new CuesheetSection(cuesheet);
Assert.IsNull(section.Begin);
var validationResult = section.Validate(x => x.Begin);
Assert.AreEqual(ValidationStatus.Error, validationResult.Status);
splitPoint.Moment = new TimeSpan(0, 30, 0);
validationResult = splitPoint.Validate(x => x.Moment);
section.Begin = new TimeSpan(0, 30, 0);
validationResult = section.Validate(x => x.Begin);
Assert.AreEqual(ValidationStatus.Success, validationResult.Status);
cuesheet.AddTrack(new Track() { Position = 1});
cuesheet.AddTrack(new Track() { Position = 2, Begin = new TimeSpan(0, 8, 43), End = new TimeSpan(0, 15, 43) });
validationResult = splitPoint.Validate(x => x.Moment);
validationResult = section.Validate(x => x.Begin);
Assert.AreEqual(ValidationStatus.Error, validationResult.Status);
splitPoint.Moment = new TimeSpan(0, 15, 43);
validationResult = splitPoint.Validate(x => x.Moment);
section.Begin = new TimeSpan(0, 15, 43);
validationResult = section.Validate(x => x.Begin);
Assert.AreEqual(ValidationStatus.Success, validationResult.Status);
}
}
Expand Down
Loading

0 comments on commit 0590288

Please sign in to comment.