Skip to content

Commit

Permalink
Merge pull request #351 from NeoCoderMatrix86/328-make-split-points-w…
Browse files Browse the repository at this point in the history
…ork-with-begin-and-end

Make split points work with begin and end
  • Loading branch information
NeoCoderMatrix86 authored Apr 19, 2024
2 parents fdc3e23 + 7525103 commit 0a4eb17
Show file tree
Hide file tree
Showing 23 changed files with 365 additions and 392 deletions.
8 changes: 4 additions & 4 deletions AudioCuesheetEditor/AudioCuesheetEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
<Content Remove="Resources\Localization\CatalogueNumber\en.json" />
<Content Remove="Resources\Localization\CuesheetData\de.json" />
<Content Remove="Resources\Localization\CuesheetData\en.json" />
<Content Remove="Resources\Localization\EditSplitpoints\de.json" />
<Content Remove="Resources\Localization\EditSplitpoints\en.json" />
<Content Remove="Resources\Localization\EditSections\de.json" />
<Content Remove="Resources\Localization\EditSections\en.json" />
<Content Remove="Resources\Localization\EditTrackModal\de.json" />
<Content Remove="Resources\Localization\EditTrackModal\en.json" />
<Content Remove="Resources\Localization\MainLayout\de.json" />
Expand Down Expand Up @@ -61,8 +61,8 @@
<EmbeddedResource Include="Resources\Localization\CatalogueNumber\de.json" />
<EmbeddedResource Include="Resources\Localization\CuesheetData\de.json" />
<EmbeddedResource Include="Resources\Localization\CuesheetData\en.json" />
<EmbeddedResource Include="Resources\Localization\EditSplitpoints\de.json" />
<EmbeddedResource Include="Resources\Localization\EditSplitpoints\en.json" />
<EmbeddedResource Include="Resources\Localization\EditSections\de.json" />
<EmbeddedResource Include="Resources\Localization\EditSections\en.json" />
<EmbeddedResource Include="Resources\Localization\EditTrackModal\de.json" />
<EmbeddedResource Include="Resources\Localization\EditTrackModal\en.json" />
<EmbeddedResource Include="Resources\Localization\MainLayout\en.json" />
Expand Down
119 changes: 44 additions & 75 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,72 +29,54 @@ public enum MoveDirection
Down
}

public class TrackAddRemoveEventArgs : EventArgs
public class TrackAddRemoveEventArgs(Track track) : EventArgs
{
public TrackAddRemoveEventArgs(Track track)
{
Track = track;
}

public Track Track { get; }
public Track Track { get; } = track;
}

public class SplitPointAddRemoveEventArgs : EventArgs
public class CuesheetSectionAddRemoveEventArgs(CuesheetSection section) : EventArgs
{
public SplitPointAddRemoveEventArgs(SplitPoint splitPoint)
{
SplitPoint = splitPoint;
}

public SplitPoint SplitPoint { get; }
public CuesheetSection Section { get; } = section;
}

public class Cuesheet : Validateable<Cuesheet>, ICuesheetEntity, ITraceable
public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable<Cuesheet>, ICuesheetEntity, ITraceable
{
public const String MimeType = "text/*";
public const String FileExtension = ".cue";

private readonly object syncLock = new();

private List<Track> tracks;
private List<Track> tracks = [];
private String? artist;
private String? title;
private Audiofile? audiofile;
private CDTextfile? cDTextfile;
private Cataloguenumber catalogueNumber;
private Cataloguenumber catalogueNumber = new();
private DateTime? recordingStart;
private readonly List<KeyValuePair<String, Track>> currentlyHandlingLinkedTrackPropertyChange = new();
private List<SplitPoint> splitPoints;
private readonly List<KeyValuePair<String, Track>> currentlyHandlingLinkedTrackPropertyChange = [];
private List<CuesheetSection> sections = [];

public event EventHandler? AudioFileChanged;
public event EventHandler<TraceablePropertiesChangedEventArgs>? TraceablePropertyChanged;
public event EventHandler<TrackAddRemoveEventArgs>? TrackAdded;
public event EventHandler<TrackAddRemoveEventArgs>? TrackRemoved;
public event EventHandler<SplitPointAddRemoveEventArgs>? SplitPointAdded;
public event EventHandler<SplitPointAddRemoveEventArgs>? SplitPointRemoved;
public event EventHandler<CuesheetSectionAddRemoveEventArgs>? SectionAdded;
public event EventHandler<CuesheetSectionAddRemoveEventArgs>? SectionRemoved;
public event EventHandler? CuesheetImported;

public Cuesheet(TraceChangeManager? traceChangeManager = null)
{
tracks = new();
catalogueNumber = new();
splitPoints = new();
TraceChangeManager = traceChangeManager;
}

[JsonInclude]
public IReadOnlyCollection<Track> Tracks
{
get { return tracks.AsReadOnly(); }
private set
get => tracks.AsReadOnly();
private set
{
foreach (var track in tracks)
{
track.RankPropertyValueChanged -= Track_RankPropertyValueChanged;
track.IsLinkedToPreviousTrackChanged -= Track_IsLinkedToPreviousTrackChanged;
track.Cuesheet = null;
}
tracks = value.ToList();
tracks = [.. value];
foreach (var track in tracks)
{
track.Cuesheet = this;
Expand All @@ -103,7 +85,7 @@ private set
}
}
}

public String? Artist
{
get => artist;
Expand Down Expand Up @@ -197,46 +179,45 @@ public TimeSpan? RecordingTime
public Boolean IsImporting { get; private set; }

[JsonInclude]
public IReadOnlyCollection<SplitPoint> SplitPoints
public IReadOnlyCollection<CuesheetSection> Sections
{
get => splitPoints;
get => sections;
private set
{
foreach(var splitpoint in value.Where(x => x.Cuesheet != this))
foreach(var section in value.Where(x => x.Cuesheet != this))
{
splitpoint.Cuesheet = this;
section.Cuesheet = this;
}
splitPoints = value.ToList();
sections = [.. value];
}
}

[JsonIgnore]
public TraceChangeManager? TraceChangeManager { get; }
public TraceChangeManager? TraceChangeManager { get; } = traceChangeManager;

public SplitPoint AddSplitPoint()
public CuesheetSection AddSection()
{
var previousValue = new List<SplitPoint>(splitPoints);
var splitPoint = new SplitPoint(this);
splitPoints.Add(splitPoint);
SplitPointAdded?.Invoke(this, new SplitPointAddRemoveEventArgs(splitPoint));
OnTraceablePropertyChanged(previousValue, nameof(SplitPoints));
return splitPoint;
var previousValue = new List<CuesheetSection>(sections);
var section = new CuesheetSection(this);
sections.Add(section);
SectionAdded?.Invoke(this, new CuesheetSectionAddRemoveEventArgs(section));
OnTraceablePropertyChanged(previousValue, nameof(Sections));
return section;
}

public void RemoveSplitPoint(SplitPoint splitPoint)
public void RemoveSection(CuesheetSection section)
{
var previousValue = new List<SplitPoint>(splitPoints);
if (splitPoints.Remove(splitPoint))
var previousValue = new List<CuesheetSection>(sections);
if (sections.Remove(section))
{
OnTraceablePropertyChanged(previousValue, nameof(SplitPoints));
SplitPointRemoved?.Invoke(this, new SplitPointAddRemoveEventArgs(splitPoint));
OnTraceablePropertyChanged(previousValue, nameof(Sections));
SectionRemoved?.Invoke(this, new CuesheetSectionAddRemoveEventArgs(section));
}
}

public SplitPoint? GetSplitPointAtTrack(Track track)
public CuesheetSection? GetSectionAtTrack(Track track)
{
SplitPoint? splitPointAtTrack = SplitPoints?.FirstOrDefault(x => track.Begin < x.Moment && track.End >= x.Moment);
return splitPointAtTrack;
return Sections?.FirstOrDefault(x => track.Begin < x.Begin && track.End >= x.Begin);
}

/// <summary>
Expand All @@ -247,10 +228,6 @@ public void RemoveSplitPoint(SplitPoint splitPoint)
public Track? GetPreviousLinkedTrack(Track track)
{
Track? previousLinkedTrack = null;
if (track == null)
{
throw new ArgumentNullException(nameof(track));
}
if (track.IsLinkedToPreviousTrack)
{
var index = tracks.IndexOf(track);
Expand Down Expand Up @@ -462,7 +439,7 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Tracks.Count <= 0)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has invalid Count ({1})!", nameof(Tracks), 0));
}
else
Expand All @@ -473,7 +450,7 @@ protected override ValidationResult Validate(string property)
.Where(grp => grp.Count() > 1);
if (tracksWithSamePosition.Any())
{
validationMessages ??= new();
validationMessages ??= [];
foreach (var track in tracksWithSamePosition)
{
foreach (var trackWithSamePosition in track)
Expand All @@ -489,7 +466,7 @@ protected override ValidationResult Validate(string property)
&& (x.Equals(track) == false));
if (tracksBetween.Any())
{
validationMessages ??= new();
validationMessages ??= [];
foreach (var trackBetween in tracksBetween)
{
validationMessages.Add(new ValidationMessage("{0}({1},{2},{3},{4},{5}) is overlapping with {0}({6},{7},{8},{9},{10}). Please make shure the timeinterval is only used once!", nameof(Track), track.Position != null ? track.Position : String.Empty, track.Artist ?? String.Empty, track.Title ?? String.Empty, track.Begin != null ? track.Begin : String.Empty, track.End != null ? track.End : String.Empty, trackBetween.Position != null ? trackBetween.Position : String.Empty, trackBetween.Artist ?? String.Empty, trackBetween.Title ?? String.Empty, trackBetween.Begin != null ? trackBetween.Begin : String.Empty, trackBetween.End != null ? trackBetween.End : String.Empty));
Expand All @@ -502,23 +479,23 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Audiofile == null)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Audiofile)));
}
break;
case nameof(Artist):
validationStatus = ValidationStatus.Success;
if (String.IsNullOrEmpty(Artist))
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Artist)));
}
break;
case nameof(Title):
validationStatus = ValidationStatus.Success;
if (String.IsNullOrEmpty(Title))
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Title)));
}
break;
Expand Down Expand Up @@ -594,10 +571,10 @@ private void CopyValues(Cuesheet cuesheet, ApplicationOptions applicationOptions
var track = new Track(importTrack, false);
AddTrack(track, applicationOptions);
}
// Copy splitpoints
foreach (var splitPoint in cuesheet.SplitPoints)
// Copy sections
foreach (var splitPoint in cuesheet.Sections)
{
var newSplitPoint = AddSplitPoint();
var newSplitPoint = AddSection();
newSplitPoint.CopyValues(splitPoint);
}
}
Expand Down Expand Up @@ -701,14 +678,6 @@ private void Audiofile_ContentStreamLoaded(object? sender, EventArgs e)

private void SwitchTracks(Track track1, Track track2)
{
if (track1 == null)
{
throw new ArgumentNullException(nameof(track1));
}
if (track2 == null)
{
throw new ArgumentNullException(nameof(track2));
}
var indexTrack1 = tracks.IndexOf(track1);
var indexTrack2 = tracks.IndexOf(track2);
//Switch track positions in array
Expand Down
32 changes: 12 additions & 20 deletions AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ public enum SetFlagMode

public class Track : Validateable<Track>, ICuesheetEntity, ITraceable
{
public static readonly List<String> AllPropertyNames = new() { nameof(IsLinkedToPreviousTrack), nameof(Position), nameof(Artist), nameof(Title), nameof(Begin), nameof(End), nameof(Flags), nameof(PreGap), nameof(PostGap), nameof(Length) };
public static readonly List<String> AllPropertyNames = [nameof(IsLinkedToPreviousTrack), nameof(Position), nameof(Artist), nameof(Title), nameof(Begin), nameof(End), nameof(Flags), nameof(PreGap), nameof(PostGap), nameof(Length)];

private uint? position;
private String? artist;
private String? title;
private TimeSpan? begin;
private TimeSpan? end;
private TimeSpan? _length;
private List<Flag> flags = new();
private List<Flag> flags = [];
private Boolean isLinkedToPreviousTrack;
private Cuesheet? cuesheet;
private TimeSpan? preGap;
Expand Down Expand Up @@ -161,11 +161,7 @@ public IReadOnlyCollection<Flag> Flags
get { return flags.AsReadOnly(); }
private set
{
if (value == null)
{
throw new ArgumentNullException(nameof(Flags));
}
flags = value.ToList();
flags = [.. value];
}
}
[JsonIgnore]
Expand Down Expand Up @@ -368,16 +364,12 @@ public void CopyValues(Track track, Boolean setCuesheet = true, Boolean setIsLin
///<inheritdoc/>
public void SetFlag(Flag flag, SetFlagMode flagMode)
{
if (flag == null)
{
throw new ArgumentNullException(nameof(flag));
}
var previousValue = flags;
if ((flagMode == SetFlagMode.Add) && (Flags.Contains(flag) == false))
{
flags.Add(flag);
}
if ((flagMode == SetFlagMode.Remove) && (Flags.Contains(flag)))
if ((flagMode == SetFlagMode.Remove) && Flags.Contains(flag))
{
flags.Remove(flag);
}
Expand All @@ -401,14 +393,14 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Position == null)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Position)));
}
else
{
if (Position == 0)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} may not be 0!", nameof(Position)));
}
else
Expand All @@ -419,7 +411,7 @@ protected override ValidationResult Validate(string property)
var positionTrackShouldHave = Cuesheet.Tracks.OrderBy(x => x.Begin ?? TimeSpan.MaxValue).ThenBy(x => x.Position).ToList().IndexOf(this) + 1;
if (positionTrackShouldHave != Position)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("Track({0},{1},{2},{3},{4}) does not have the correct position '{5}'!", Position, Artist ?? String.Empty, Title ?? String.Empty, Begin != null ? Begin : String.Empty, End != null ? End : String.Empty, positionTrackShouldHave));
}
}
Expand All @@ -430,14 +422,14 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Begin == null)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Begin)));
}
else
{
if (Begin < TimeSpan.Zero)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must be equal or greater zero!", nameof(Begin)));
}
}
Expand All @@ -446,14 +438,14 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (End == null)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(End)));
}
else
{
if (End < TimeSpan.Zero)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must be equal or greater zero!", nameof(End)));
}
}
Expand All @@ -462,7 +454,7 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Length == null)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has no value!", nameof(Length)));
}
break;
Expand Down
Loading

0 comments on commit 0a4eb17

Please sign in to comment.