Skip to content

Commit

Permalink
switched import to use services
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoCoderMatrix86 committed Aug 26, 2024
1 parent 1b3ff1f commit 31cf057
Show file tree
Hide file tree
Showing 14 changed files with 178 additions and 274 deletions.
47 changes: 10 additions & 37 deletions AudioCuesheetEditor/Extensions/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Model.Options;
Expand All @@ -31,7 +32,6 @@ public class SessionStateContainer
private ViewMode currentViewMode;
private Cuesheet cuesheet;
private Cuesheet? importCuesheet;
private TextImportfile? textImportFile;
private CuesheetImportfile? cuesheetImportFile;
private Audiofile? importAudiofile;

Expand Down Expand Up @@ -65,28 +65,8 @@ public Cuesheet? ImportCuesheet
}
}

public TextImportfile? TextImportFile
{
get { return textImportFile; }
set
{
if (textImportFile != null)
{
textImportFile.AnalysisFinished -= TextImportScheme_AnalysisFinished;
}
textImportFile = value;
if (textImportFile != null)
{
textImportFile.AnalysisFinished += TextImportScheme_AnalysisFinished;
ImportCuesheet = textImportFile.Cuesheet;
}
else
{
ImportCuesheet = null;
}
}
}

public TextImportfile? TextImportFile { get; set; }

public CuesheetImportfile? CuesheetImportFile
{
get { return cuesheetImportFile; }
Expand All @@ -100,7 +80,8 @@ public CuesheetImportfile? CuesheetImportFile
if ((CuesheetImportFile != null) && (CuesheetImportFile.Cuesheet != null))
{
CuesheetImportFile.AnalysisFinished += CuesheetImportFile_AnalysisFinished;
ImportCuesheet = CuesheetImportFile.Cuesheet;
//TODO
//ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
Expand Down Expand Up @@ -160,7 +141,8 @@ public void StartImportCuesheet(ApplicationOptions applicationOptions)
{
if (ImportCuesheet != null)
{
Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
//TODO
//Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
ImportCuesheet = null;
}
ResetImport();
Expand All @@ -175,17 +157,7 @@ private void SetCuesheetReference(Cuesheet value)
_traceChangeManager.TraceChanges(Cuesheet);
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}
private void TextImportScheme_AnalysisFinished(object? sender, EventArgs eventArgs)
{
if (textImportFile != null)
{
ImportCuesheet = textImportFile.Cuesheet;
}
else
{
ImportCuesheet = null;
}
}

private void Cuesheet_CuesheetImported(object? sender, EventArgs e)
{
CuesheetChanged?.Invoke(this, EventArgs.Empty);
Expand All @@ -195,7 +167,8 @@ void CuesheetImportFile_AnalysisFinished(object? sender, EventArgs e)
{
if (CuesheetImportFile != null)
{
ImportCuesheet = CuesheetImportFile.Cuesheet;
//TODO
//ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
Expand Down
27 changes: 15 additions & 12 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
Expand All @@ -39,7 +40,7 @@ public class CuesheetSectionAddRemoveEventArgs(CuesheetSection section) : EventA
public CuesheetSection Section { get; } = section;
}

public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable<Cuesheet>, ICuesheetEntity, ITraceable
public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validateable<Cuesheet>, ICuesheetEntity, ITraceable, ICuesheet
{
public const String MimeType = "text/*";
public const String FileExtension = ".cue";
Expand Down Expand Up @@ -393,7 +394,7 @@ public void MoveTrack(Track track, MoveDirection moveDirection)
}
}

public void Import(Cuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
public void Import(ImportCuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
{
//Since we use a stack for several changes we need to lock execution for everything else
lock (syncLock)
Expand Down Expand Up @@ -559,25 +560,27 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
/// </summary>
/// <param name="cuesheet">Reference to import cuesheet</param>
/// <param name="applicationOptions">Reference to application options</param>
private void CopyValues(Cuesheet cuesheet, ApplicationOptions applicationOptions)
private void CopyValues(ImportCuesheet cuesheet, ApplicationOptions applicationOptions)
{
Artist = cuesheet.Artist;
Title = cuesheet.Title;
Audiofile = cuesheet.Audiofile;
CDTextfile = cuesheet.CDTextfile;
Cataloguenumber = cuesheet.Cataloguenumber;
//TODO
//Audiofile = cuesheet.Audiofile;
//CDTextfile = cuesheet.CDTextfile;
//Cataloguenumber = cuesheet.Cataloguenumber;
foreach (var importTrack in cuesheet.Tracks)
{
//We don't want to copy the cuesheet reference since we are doing a copy and want to assign the track to this object
var track = new Track(importTrack, false);
AddTrack(track, applicationOptions);
}
// Copy sections
foreach (var splitPoint in cuesheet.Sections)
{
var newSplitPoint = AddSection();
newSplitPoint.CopyValues(splitPoint);
}
//TODO
//// Copy sections
//foreach (var splitPoint in cuesheet.Sections)
//{
// var newSplitPoint = AddSection();
// newSplitPoint.CopyValues(splitPoint);
//}
}

private void Track_RankPropertyValueChanged(object? sender, string e)
Expand Down
26 changes: 26 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.

using AudioCuesheetEditor.Model.AudioCuesheet.Import;

namespace AudioCuesheetEditor.Model.AudioCuesheet
{
public interface ICuesheet
{
public String? Artist { get; set; }
public String? Title { get; set; }
}
}
1 change: 1 addition & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/ICuesheetEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace AudioCuesheetEditor.Model.AudioCuesheet
{
//TODO: Check if this can be removed
/// <summary>
/// Interface for cuesheet entities (Cuesheet, track, etc.)
/// </summary>
Expand Down
30 changes: 30 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/ITrack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
namespace AudioCuesheetEditor.Model.AudioCuesheet
{
public interface ITrack
{
public string? Artist { get; set; }
public string? Title { get; set; }
public uint? Position { get; set; }
public TimeSpan? Begin { get; set; }
public TimeSpan? End { get; set; }
public TimeSpan? Length { get; set; }
//TODO: Flags
public TimeSpan? PreGap { get; set; }
public TimeSpan? PostGap { get; set; }
}
}
28 changes: 28 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportCuesheet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.

namespace AudioCuesheetEditor.Model.AudioCuesheet.Import
{
public class ImportCuesheet : ICuesheet
{
public string? Artist { get; set; }
public string? Title { get; set; }
//TODO Audiofile
//TODO CDTextfile
public string? Cataloguenumber { get; set; }
public ICollection<ImportTrack> Tracks { get; set; } = [];
}
}
31 changes: 31 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/Import/ImportTrack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//This file is part of AudioCuesheetEditor.

//AudioCuesheetEditor is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//AudioCuesheetEditor is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.

namespace AudioCuesheetEditor.Model.AudioCuesheet.Import
{
public class ImportTrack : ITrack
{
public string? Artist { get; set; }
public string? Title { get; set; }
public uint? Position { get; set; }
public TimeSpan? Begin { get; set; }
public TimeSpan? End { get; set; }
public TimeSpan? Length { get; set; }
//TODO: Flags
public TimeSpan? PreGap { get; set; }
public TimeSpan? PostGap { get; set; }
}
}
38 changes: 20 additions & 18 deletions AudioCuesheetEditor/Model/AudioCuesheet/Track.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.AudioCuesheet.Import;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.UI;
using System.Text.Json.Serialization;
Expand All @@ -25,7 +26,7 @@ public enum SetFlagMode
Remove
}

public class Track : Validateable<Track>, ICuesheetEntity, ITraceable
public class Track : Validateable<Track>, ICuesheetEntity, ITraceable, ITrack
{
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)];

Expand Down Expand Up @@ -59,7 +60,7 @@ public class Track : Validateable<Track>, ICuesheetEntity, ITraceable
/// </summary>
/// <param name="track">Object to copy values from</param>
/// /// <param name="copyCuesheetReference">Copy cuesheet reference from track also?</param>
public Track(Track track, Boolean copyCuesheetReference = true)
public Track(ITrack track, Boolean copyCuesheetReference = true)
{
CopyValues(track, copyCuesheetReference);
}
Expand Down Expand Up @@ -242,17 +243,17 @@ public Track Clone()
/// <param name="setPreGap">Copy PreGap from track also?</param>
/// <param name="setPostGap">Copy PostGap from track also?</param>
/// <param name="useInternalSetters">A list of properties, for whom the internal set construct should be used, in order to avoid automatic calculation.</param>
public void CopyValues(Track track, Boolean setCuesheet = true, Boolean setIsLinkedToPreviousTrack = true, Boolean setPosition = true, Boolean setArtist = true, Boolean setTitle = true, Boolean setBegin = true, Boolean setEnd = true, Boolean setLength = false, Boolean setFlags = true, Boolean setPreGap = true, Boolean setPostGap = true, IEnumerable<String>? useInternalSetters = null)
public void CopyValues(ITrack track, Boolean setCuesheet = true, Boolean setIsLinkedToPreviousTrack = true, Boolean setPosition = true, Boolean setArtist = true, Boolean setTitle = true, Boolean setBegin = true, Boolean setEnd = true, Boolean setLength = false, Boolean setFlags = true, Boolean setPreGap = true, Boolean setPostGap = true, IEnumerable<String>? useInternalSetters = null)
{
if (setCuesheet)
if (setCuesheet && (track is Track cuesheetTrack))
{
if ((useInternalSetters != null) && (useInternalSetters.Contains(nameof(Cuesheet))))
{
cuesheet = track.Cuesheet;
cuesheet = cuesheetTrack.Cuesheet;
}
else
{
Cuesheet = track.Cuesheet;
Cuesheet = cuesheetTrack.Cuesheet;
}
}
if (setPosition)
Expand Down Expand Up @@ -316,15 +317,16 @@ public void CopyValues(Track track, Boolean setCuesheet = true, Boolean setIsLin
}
if (setFlags)
{
if ((useInternalSetters != null) && (useInternalSetters.Contains(nameof(Flags))))
{
flags.Clear();
flags.AddRange(track.Flags);
}
else
{
SetFlags(track.Flags);
}
//TODO
//if ((useInternalSetters != null) && (useInternalSetters.Contains(nameof(Flags))))
//{
// flags.Clear();
// flags.AddRange(track.Flags);
//}
//else
//{
// SetFlags(track.Flags);
//}
}
if (setPreGap)
{
Expand All @@ -348,15 +350,15 @@ public void CopyValues(Track track, Boolean setCuesheet = true, Boolean setIsLin
PostGap = track.PostGap;
}
}
if (setIsLinkedToPreviousTrack)
if (setIsLinkedToPreviousTrack && (track is Track cuesheetTrack2))
{
if ((useInternalSetters != null) && (useInternalSetters.Contains(nameof(IsLinkedToPreviousTrack))))
{
isLinkedToPreviousTrack = track.IsLinkedToPreviousTrack;
isLinkedToPreviousTrack = cuesheetTrack2.IsLinkedToPreviousTrack;
}
else
{
IsLinkedToPreviousTrack = track.IsLinkedToPreviousTrack;
IsLinkedToPreviousTrack = cuesheetTrack2.IsLinkedToPreviousTrack;
}
}
}
Expand Down
6 changes: 0 additions & 6 deletions AudioCuesheetEditor/Model/Options/ImportOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,5 @@ public class ImportOptions : IOptions
{
public TextImportScheme TextImportScheme { get; set; } = TextImportScheme.DefaultTextImportScheme;
public TimeSpanFormat TimeSpanFormat { get; set; } = new();
//TODO
//public ImportOptions(TextImportfile textImportfile)
//{
// TextImportScheme = textImportfile.TextImportScheme;
// TimeSpanFormat = textImportfile.TimeSpanFormat;
//}
}
}
Loading

0 comments on commit 31cf057

Please sign in to comment.