Skip to content

Commit

Permalink
Merge pull request #385 from NeoCoderMatrix86/373-enhance-text-import…
Browse files Browse the repository at this point in the history
…-to-use-fixed-timestamps2

Enhance text import to use fixed timestamps
  • Loading branch information
NeoCoderMatrix86 authored Sep 2, 2024
2 parents 0563982 + ded97b5 commit 4c9624c
Show file tree
Hide file tree
Showing 59 changed files with 2,256 additions and 1,643 deletions.
4 changes: 4 additions & 0 deletions AudioCuesheetEditor/AudioCuesheetEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
<Content Remove="Resources\Localization\Index\en.json" />
<Content Remove="Resources\Localization\ValidationMessage\de.json" />
<Content Remove="Resources\Localization\ValidationMessage\en.json" />
<Content Remove="Resources\Localization\EditImportOptions\de.json" />
<Content Remove="Resources\Localization\EditImportOptions\en.json" />
<Content Remove="Resources\Localization\ViewModeImport\de.json" />
<Content Remove="Resources\Localization\ViewModeImport\en.json" />
<Content Remove="Resources\Localization\ViewModeRecord\de.json" />
Expand Down Expand Up @@ -98,6 +100,8 @@
<EmbeddedResource Include="Resources\Localization\Index\de.json" />
<EmbeddedResource Include="Resources\Localization\ValidationMessage\de.json" />
<EmbeddedResource Include="Resources\Localization\ValidationMessage\en.json" />
<EmbeddedResource Include="Resources\Localization\EditImportOptions\de.json" />
<EmbeddedResource Include="Resources\Localization\EditImportOptions\en.json" />
<EmbeddedResource Include="Resources\Localization\ViewModeImport\de.json" />
<EmbeddedResource Include="Resources\Localization\ViewModeImport\en.json" />
<EmbeddedResource Include="Resources\Localization\ViewModeRecord\de.json" />
Expand Down
28 changes: 28 additions & 0 deletions AudioCuesheetEditor/Data/Options/ILocalStorageOptionsProvider.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 />.
using AudioCuesheetEditor.Model.Options;
using System.Linq.Expressions;

namespace AudioCuesheetEditor.Data.Options
{
public interface ILocalStorageOptionsProvider
{
event EventHandler<IOptions>? OptionSaved;
Task<T> GetOptions<T>() where T : IOptions;
Task SaveOptions(IOptions options);
Task SaveOptionsValue<T>(Expression<Func<T, object>> propertyExpression, object value) where T : class, IOptions, new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

namespace AudioCuesheetEditor.Data.Options
{
public class LocalStorageOptionsProvider(IJSRuntime jsRuntime)
public class LocalStorageOptionsProvider(IJSRuntime jsRuntime): ILocalStorageOptionsProvider
{
public event EventHandler<IOptions>? OptionSaved;

Expand Down
104 changes: 5 additions & 99 deletions AudioCuesheetEditor/Extensions/SessionStateContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ public class SessionStateContainer
private ViewMode currentViewMode;
private Cuesheet cuesheet;
private Cuesheet? importCuesheet;
private TextImportfile? textImportFile;
private CuesheetImportfile? cuesheetImportFile;
private Audiofile? importAudiofile;

public SessionStateContainer(TraceChangeManager traceChangeManager)
Expand Down Expand Up @@ -65,50 +63,6 @@ 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 CuesheetImportfile? CuesheetImportFile
{
get { return cuesheetImportFile; }
set
{
if (cuesheetImportFile != null)
{
cuesheetImportFile.AnalysisFinished -= CuesheetImportFile_AnalysisFinished;
}
cuesheetImportFile = value;
if ((CuesheetImportFile != null) && (CuesheetImportFile.Cuesheet != null))
{
CuesheetImportFile.AnalysisFinished += CuesheetImportFile_AnalysisFinished;
ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
ImportCuesheet = null;
}
}
}

public Audiofile? ImportAudiofile
{
get => importAudiofile;
Expand All @@ -133,74 +87,26 @@ public ViewMode CurrentViewMode
}
}

public IImportfile? Importfile
{
get
{
if (TextImportFile != null)
{
return TextImportFile;
}
if (CuesheetImportFile != null)
{
return CuesheetImportFile;
}
return null;
}
}
public IImportfile? Importfile{ get; set; }

public void ResetImport()
{
TextImportFile = null;
CuesheetImportFile = null;
Importfile = null;
ImportAudiofile = null;
}

public void StartImportCuesheet(ApplicationOptions applicationOptions)
{
if (ImportCuesheet != null)
{
Cuesheet.Import(ImportCuesheet, applicationOptions, _traceChangeManager);
ImportCuesheet = null;
}
ResetImport();
ImportCuesheet = null;
}

private void SetCuesheetReference(Cuesheet value)
{
cuesheet.CuesheetImported -= Cuesheet_CuesheetImported;
cuesheet = value;
cuesheet.CuesheetImported += Cuesheet_CuesheetImported;
_traceChangeManager.Reset();
_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)

public void FireCuesheetImported()
{
CuesheetChanged?.Invoke(this, EventArgs.Empty);
}

void CuesheetImportFile_AnalysisFinished(object? sender, EventArgs e)
{
if (CuesheetImportFile != null)
{
ImportCuesheet = CuesheetImportFile.Cuesheet;
}
else
{
ImportCuesheet = null;
}
}
}
}
2 changes: 1 addition & 1 deletion AudioCuesheetEditor/Extensions/WebAssemblyHostExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static class WebAssemblyHostExtension
{
public async static Task SetDefaultCulture(this WebAssemblyHost host)
{
var localStorageOptionsProvider = host.Services.GetRequiredService<LocalStorageOptionsProvider>();
var localStorageOptionsProvider = host.Services.GetRequiredService<ILocalStorageOptionsProvider>();
var options = await localStorageOptionsProvider.GetOptions<ApplicationOptions>();

CultureInfo.DefaultThreadCurrentCulture = options.Culture;
Expand Down
4 changes: 2 additions & 2 deletions AudioCuesheetEditor/Model/AudioCuesheet/CatalogueNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ protected override ValidationResult Validate(string property)
validationStatus = ValidationStatus.Success;
if (Value.All(Char.IsDigit) == false)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} must only contain numbers!", nameof(Value)));
}
if (Value.Length != 13)
{
validationMessages ??= new();
validationMessages ??= [];
validationMessages.Add(new ValidationMessage("{0} has an invalid length. Allowed length is {1}!", nameof(Value), 13));
}
}
Expand Down
56 changes: 2 additions & 54 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Export;
using AudioCuesheetEditor.Model.Options;
Expand All @@ -39,11 +38,8 @@ 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>, ITraceable, ICuesheet
{
public const String MimeType = "text/*";
public const String FileExtension = ".cue";

private readonly object syncLock = new();

private List<Track> tracks = [];
Expand All @@ -62,7 +58,6 @@ public class Cuesheet(TraceChangeManager? traceChangeManager = null) : Validatea
public event EventHandler<TrackAddRemoveEventArgs>? TrackRemoved;
public event EventHandler<CuesheetSectionAddRemoveEventArgs>? SectionAdded;
public event EventHandler<CuesheetSectionAddRemoveEventArgs>? SectionRemoved;
public event EventHandler? CuesheetImported;

[JsonInclude]
public IReadOnlyCollection<Track> Tracks
Expand Down Expand Up @@ -176,7 +171,7 @@ public TimeSpan? RecordingTime
}

[JsonIgnore]
public Boolean IsImporting { get; private set; }
public Boolean IsImporting { get; set; }

[JsonInclude]
public IReadOnlyCollection<CuesheetSection> Sections
Expand Down Expand Up @@ -393,27 +388,6 @@ public void MoveTrack(Track track, MoveDirection moveDirection)
}
}

public void Import(Cuesheet cuesheet, ApplicationOptions applicationOptions, TraceChangeManager? traceChangeManager = null)
{
//Since we use a stack for several changes we need to lock execution for everything else
lock (syncLock)
{
IsImporting = true;
//We are doing a bulk edit, so inform the TraceChangeManager
if (traceChangeManager != null)
{
traceChangeManager.BulkEdit = true;
}
CopyValues(cuesheet, applicationOptions);
if (traceChangeManager != null)
{
traceChangeManager.BulkEdit = false;
}
IsImporting = false;
}
CuesheetImported?.Invoke(this, EventArgs.Empty);
}

public void StartRecording()
{
recordingStart = DateTime.UtcNow;
Expand Down Expand Up @@ -554,32 +528,6 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
}
}

/// <summary>
/// Copy values from import cuesheet to this cuesheet
/// </summary>
/// <param name="cuesheet">Reference to import cuesheet</param>
/// <param name="applicationOptions">Reference to application options</param>
private void CopyValues(Cuesheet cuesheet, ApplicationOptions applicationOptions)
{
Artist = cuesheet.Artist;
Title = cuesheet.Title;
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);
}
}

private void Track_RankPropertyValueChanged(object? sender, string e)
{
if (sender is Track trackRaisedEvent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,12 @@
//You should have received a copy of the GNU General Public License
//along with Foobar. If not, see
//<http: //www.gnu.org/licenses />.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AudioCuesheetEditor.Model.AudioCuesheet
{
/// <summary>
/// Interface for cuesheet entities (Cuesheet, track, etc.)
/// </summary>
public interface ICuesheetEntity
public interface ICuesheet
{
public String? Artist { get; set; }
public String? Title { get; set; }
string? Artist { get; set; }
string? Title { get; set; }
}
}
31 changes: 31 additions & 0 deletions AudioCuesheetEditor/Model/AudioCuesheet/ITrack.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
{
public interface ITrack
{
string? Artist { get; set; }
string? Title { get; set; }
uint? Position { get; set; }
TimeSpan? Begin { get; set; }
TimeSpan? End { get; set; }
TimeSpan? Length { get; set; }
IReadOnlyCollection<Flag> Flags { get; }
TimeSpan? PreGap { get; set; }
TimeSpan? PostGap { get; set; }
void SetFlags(IEnumerable<Flag> flags);
}
}
Loading

0 comments on commit 4c9624c

Please sign in to comment.