Skip to content

Commit

Permalink
Deploy Version 2.2 (#135)
Browse files Browse the repository at this point in the history
* Capture AudioFile changed in AudioPlayer

* Automatically calculate begin and end when using record mode

* Added Unit test for recalculation during record mode

* Handle media recorder state when stopping

* First version with ffmpeg for conversion

* Corrected handling for codec in AudioFile

* Record audio on all browsers in WebM format

* Set Version 2.2.0

* Added documentation for options

* Added ATL library for getting audio file duration

* Added AudioFile Duration Property

* Added linking Track with previous Track

* Corrected bug during textimport and activated link tracks

* First model changes for TextImport with Cuesheet

* Added saving of textimport format in ApplicationOptions

* Made TextImportScheme Validateable

* Set all properties of Cuesheet on Import

* Added Cuesheet properties during textimport

* Corrected unit tests and import of ImportCuesheet

* First step displaying import file content

* Display recognized file content during text import

* Update TextImportFile.cs

* Documented new text import

* Catch JSONException during Deserialize of ApplicationOptions

* Made images scale to 100% on any display

* Made ErrorReport with margin

* Display timespan without milliseconds

* Correctly open and close import files tab

* Fix text edit fields for time inputs

* Bugfixes for text import
  • Loading branch information
NeoCoderMatrix86 authored Feb 25, 2021
1 parent 8f8f958 commit 6ac7bb3
Show file tree
Hide file tree
Showing 49 changed files with 2,384 additions and 879 deletions.
4 changes: 3 additions & 1 deletion AudioCuesheetEditor/AudioCuesheetEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<BlazorWebAssemblyLoadAllGlobalizationData>true</BlazorWebAssemblyLoadAllGlobalizationData>
<RazorLangVersion>3.0</RazorLangVersion>
<Version>2.1.0</Version>
<Version>2.2.0</Version>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>

Expand All @@ -17,6 +17,7 @@
<PackageReference Include="BlazorDownloadFile" Version="2.1.6" />
<PackageReference Include="Blazorise.Bootstrap" Version="0.9.2.5" />
<PackageReference Include="Blazorise.Components" Version="0.9.2.5" />
<PackageReference Include="FFmpegBlazor" Version="1.0.0.2" />
<PackageReference Include="Howler.Blazor" Version="0.9.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.3" PrivateAssets="all" />
Expand All @@ -25,6 +26,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="5.0.0" />
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
<PackageReference Include="Toolbelt.Blazor.HotKeys" Version="10.0.0" />
<PackageReference Include="z440.atl.core" Version="3.18.0" />
</ItemGroup>

<ItemGroup>
Expand Down
15 changes: 6 additions & 9 deletions AudioCuesheetEditor/Controller/CuesheetController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using AudioCuesheetEditor.Model.AudioCuesheet;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Export;
using AudioCuesheetEditor.Model.Reflection;
using AudioCuesheetEditor.Shared.ResourceFiles;
Expand Down Expand Up @@ -82,18 +83,14 @@ public static Boolean CheckFileMimeType(IBrowserFile file, String mimeType, Stri
return fileMimeTypeMatches;
}

public static Boolean CheckFileMimeType(IBrowserFile file, Dictionary<String, String> mimeTypes)
public static Boolean CheckFileMimeType(IBrowserFile file, IReadOnlyCollection<AudioCodec> audioCodecs)
{
Boolean fileMimeTypeMatches = false;
if ((file != null) && (mimeTypes != null))
if ((file != null) && (audioCodecs != null))
{
fileMimeTypeMatches = mimeTypes.ContainsValue(file.ContentType);
if (fileMimeTypeMatches == false)
{
//Try to find by file extension
var extension = Path.GetExtension(file.Name).ToLower();
fileMimeTypeMatches = mimeTypes.ContainsKey(extension);
}
var extension = Path.GetExtension(file.Name).ToLower();
var audioCodecsFound = audioCodecs.Where(x => x.MimeType.Equals(file.ContentType, StringComparison.OrdinalIgnoreCase) || x.FileExtension.Equals(extension, StringComparison.OrdinalIgnoreCase));
fileMimeTypeMatches = (audioCodecsFound != null) && (audioCodecsFound.Any());
}
return fileMimeTypeMatches;
}
Expand Down
20 changes: 17 additions & 3 deletions AudioCuesheetEditor/Controller/OptionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
//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.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Shared.ResourceFiles;
using Microsoft.Extensions.Localization;
Expand Down Expand Up @@ -45,8 +47,16 @@ public async Task LoadOptions()
String optionsJson = await jsRuntime.InvokeAsync<String>("ApplicationOptions.get");
if (String.IsNullOrEmpty(optionsJson) == false)
{
Options = JsonSerializer.Deserialize<ApplicationOptions>(optionsJson);
Options.SetDefaultValues();
try
{
Options = JsonSerializer.Deserialize<ApplicationOptions>(optionsJson);
Options.SetDefaultValues();
}
catch(JsonException)
{
//Nothing to do, we can not deserialize
Options = new ApplicationOptions();
}
}
}

Expand All @@ -55,7 +65,11 @@ public async Task SaveOptions()
String optionsJson = null;
if (Options != null)
{
optionsJson = JsonSerializer.Serialize(Options);
var serializerOptions = new JsonSerializerOptions
{
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
};
optionsJson = JsonSerializer.Serialize(Options, serializerOptions);
}
await jsRuntime.InvokeVoidAsync("ApplicationOptions.set", optionsJson);
}
Expand Down
169 changes: 122 additions & 47 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
using AudioCuesheetEditor.Controller;
using AudioCuesheetEditor.Model.Entity;
using AudioCuesheetEditor.Model.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using AudioCuesheetEditor.Model.IO.Import;
using AudioCuesheetEditor.Model.Options;
using AudioCuesheetEditor.Model.Reflection;
using System;
using System.Collections.Generic;
Expand All @@ -41,6 +44,8 @@ public class Cuesheet : Validateable, ICuesheet<Track>
private CDTextfile cDTextfile;
private DateTime? recordingStart;
private Boolean currentlyHandlingRankPropertyValueChanged;

public event EventHandler AudioFileChanged;
public Cuesheet()
{
tracks = new List<Track>();
Expand All @@ -64,7 +69,7 @@ public String Title
public AudioFile AudioFile
{
get { return audioFile; }
set { audioFile = value; OnValidateablePropertyChanged(); }
set { audioFile = value; OnValidateablePropertyChanged(); AudioFileChanged?.Invoke(this, EventArgs.Empty); }
}

public CDTextfile CDTextfile
Expand Down Expand Up @@ -104,12 +109,16 @@ public TimeSpan? RecordingTime
}
}

public void AddTrack(Track track)
public void AddTrack(Track track, ApplicationOptions applicationOptions)
{
if (track == null)
{
throw new ArgumentNullException(nameof(track));
}
if (applicationOptions == null)
{
throw new ArgumentNullException(nameof(applicationOptions));
}
if (track.IsCloned)
{
throw new ArgumentException("Cloned tracks may not be added!");
Expand All @@ -121,42 +130,16 @@ public void AddTrack(Track track)
track.Cuesheet = this;
tracks.Add(track);
ReCalculateTrackProperties(track);
track.RankPropertyValueChanged += Track_RankPropertyValueChanged;
OnValidateablePropertyChanged();
}

private void Track_RankPropertyValueChanged(object sender, string e)
{
if (currentlyHandlingRankPropertyValueChanged == false)
if ((applicationOptions.LinkTracksWithPreviousOne.HasValue) && (applicationOptions.LinkTracksWithPreviousOne.Value == true))
{
currentlyHandlingRankPropertyValueChanged = true;
Track trackRaisedEvent = (Track)sender;
var index = tracks.IndexOf(trackRaisedEvent);
switch (e)
if (tracks.Count > 1)
{
case nameof(Track.Begin):
if (index > 0)
{
var previousTrack = tracks.ElementAt(index - 1);
if ((previousTrack != trackRaisedEvent) && (previousTrack.End.HasValue == false))
{
previousTrack.End = trackRaisedEvent.Begin;
}
}
break;
case nameof(Track.End):
if ((index + 1) < Tracks.Count)
{
var nextTrack = tracks.ElementAt(index + 1);
if ((nextTrack != trackRaisedEvent) && (nextTrack.Begin.HasValue == false))
{
nextTrack.Begin = trackRaisedEvent.End;
}
}
break;
var previousTrack = tracks.ElementAt(tracks.IndexOf(track) - 1);
track.LinkedPreviousTrack = previousTrack;
}
currentlyHandlingRankPropertyValueChanged = false;
}
track.RankPropertyValueChanged += Track_RankPropertyValueChanged;
OnValidateablePropertyChanged();
}

public void RemoveTrack(Track track)
Expand Down Expand Up @@ -232,21 +215,37 @@ public void MoveTrack(Track track, MoveDirection moveDirection)
}
}

public void Import(TextImportFile textImportFile)
public void Import(TextImportFile textImportFile, ApplicationOptions applicationOptions)
{
if (textImportFile == null)
{
throw new ArgumentNullException(nameof(textImportFile));
}
if (applicationOptions == null)
{
throw new ArgumentNullException(nameof(applicationOptions));
}
if (textImportFile.IsValid == false)
{
throw new InvalidOperationException(String.Format("{0} was not valid!", nameof(textImportFile)));
}
foreach (var importTrack in textImportFile.Tracks)
CopyValues(textImportFile.ImportCuesheet, applicationOptions);
}

public void StartRecording()
{
recordingStart = DateTime.UtcNow;
}

public void StopRecording()
{
//Set end of last track
var lastTrack = Tracks.LastOrDefault();
if (lastTrack != null)
{
var track = new Track(importTrack);
AddTrack(track);
lastTrack.End = DateTime.UtcNow - recordingStart.Value;
}
recordingStart = null;
}

protected override void Validate()
Expand Down Expand Up @@ -282,19 +281,60 @@ protected override void Validate()
}
}

private void Track_RankPropertyValueChanged(object sender, string e)
{
if (currentlyHandlingRankPropertyValueChanged == false)
{
currentlyHandlingRankPropertyValueChanged = true;
Track trackRaisedEvent = (Track)sender;
var index = tracks.IndexOf(trackRaisedEvent);
switch (e)
{
case nameof(Track.Begin):
if (index > 0)
{
var previousTrack = tracks.ElementAt(index - 1);
if ((previousTrack != trackRaisedEvent) && (previousTrack.End.HasValue == false))
{
previousTrack.End = trackRaisedEvent.Begin;
}
}
break;
case nameof(Track.End):
if ((index + 1) < Tracks.Count)
{
var nextTrack = tracks.ElementAt(index + 1);
if ((nextTrack != trackRaisedEvent) && (nextTrack.Begin.HasValue == false))
{
nextTrack.Begin = trackRaisedEvent.End;
}
}
break;
}
currentlyHandlingRankPropertyValueChanged = false;
}
}

private void CatalogueNumber_ValidateablePropertyChanged(object sender, EventArgs e)
{
OnValidateablePropertyChanged();
}

private void ReCalculateTrackProperties(Track trackToCalculate)
{
//TODO: Get last end from audio file end
if ((AudioFile != null) && (AudioFile.Duration.HasValue) && (trackToCalculate.End.HasValue == false))
{
trackToCalculate.End = AudioFile.Duration;
}
if (Tracks.Count > 1)
{
var lastTrack = tracks.ElementAt(tracks.IndexOf(trackToCalculate) - 1);
if (lastTrack != trackToCalculate)
{
if ((AudioFile != null) && (AudioFile.Duration.HasValue) && (lastTrack.End.HasValue) && (lastTrack.End.Value == AudioFile.Duration.Value))
{
lastTrack.End = null;
}
if (trackToCalculate.Position.HasValue == false)
{
trackToCalculate.Position = lastTrack.Position + 1;
Expand All @@ -303,6 +343,17 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
{
trackToCalculate.Begin = lastTrack.End;
}
else
{
if (lastTrack.End.HasValue == false)
{
lastTrack.End = trackToCalculate.Begin;
}
}
if (IsRecording)
{
lastTrack.End = trackToCalculate.Begin;
}
}
}
else
Expand All @@ -311,21 +362,45 @@ private void ReCalculateTrackProperties(Track trackToCalculate)
{
trackToCalculate.Position = 1;
}
if (trackToCalculate.Begin.HasValue == false)
if ((trackToCalculate.Begin.HasValue == false) || (IsRecording))
{
trackToCalculate.Begin = TimeSpan.Zero;
}
}
}

public void StartRecording()
{
recordingStart = DateTime.UtcNow;
}

public void StopRecording()
/// <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(ICuesheet<ImportTrack> cuesheet, ApplicationOptions applicationOptions)
{
recordingStart = null;
if (String.IsNullOrEmpty(cuesheet.Artist) == false)
{
Artist = cuesheet.Artist;
}
if (String.IsNullOrEmpty(cuesheet.Title) == false)
{
Title = cuesheet.Title;
}
if (cuesheet.AudioFile != null)
{
AudioFile = cuesheet.AudioFile;
}
if (cuesheet.CDTextfile != null)
{
CDTextfile = cuesheet.CDTextfile;
}
if (cuesheet.CatalogueNumber != null)
{
CatalogueNumber = cuesheet.CatalogueNumber;
}
foreach (var importTrack in cuesheet.Tracks)
{
var track = new Track(importTrack);
AddTrack(track, applicationOptions);
}
}
}
}
6 changes: 1 addition & 5 deletions AudioCuesheetEditor/Model/AudioCuesheet/ICuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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.IO;
using AudioCuesheetEditor.Model.IO.Audio;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -29,9 +29,5 @@ public interface ICuesheet<ITrack> : ICuesheetEntity
public AudioFile AudioFile { get; set; }
public CDTextfile CDTextfile { get; set; }
public CatalogueNumber CatalogueNumber { get; }
public void StartRecording();
public void StopRecording();
public Boolean IsRecording { get; }
public TimeSpan? RecordingTime { get; }
}
}
Loading

0 comments on commit 6ac7bb3

Please sign in to comment.