Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions AudioCuesheetEditor.Tests/Model/AudioCuesheet/CuesheetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -555,22 +555,6 @@ public void IsRecordingPossible_WhenCuesheetContainsTracks_ReturnsError()
Assert.Contains("Cuesheet already contains tracks!", errors);
}

[TestMethod()]
public void IsRecordingPossible_WhenRecordingIsAlreadyAvailable_ReturnsError()
{
// Arrange
var cuesheet = new Cuesheet
{
Audiofile = new Audiofile("test", isRecorded: true)
};

// Act
var errors = cuesheet.IsRecordingPossible.ToList();

// Assert
Assert.Contains("A recording is already available!", errors);
}

[TestMethod()]
public void IsRecordingPossible_WhenNoErrors_ReturnsEmpty()
{
Expand Down Expand Up @@ -915,19 +899,19 @@ public void StartRecording_WithTrackAlreadyAdded_ShouldNotStartRecording()
}

[TestMethod]
public void StartRecording_WithAudiofile_ShouldNotStartRecording()
public void StartRecording_WithAudiofile_ShouldStartRecording()
{
// Arrange
var cuesheet = new Cuesheet
{
Audiofile = new Audiofile("test", isRecorded: true)
Audiofile = new Audiofile("test")
};

// Act
cuesheet.StartRecording();

// Assert
Assert.IsFalse(cuesheet.IsRecording);
Assert.IsTrue(cuesheet.IsRecording);
}

[TestMethod]
Expand Down
2 changes: 0 additions & 2 deletions AudioCuesheetEditor.Tests/Model/IO/ProjectfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public void ImportFile_ValidProjectfile_ShouldImportFile()
Assert.AreEqual("CuesheetArtist", cuesheet.Artist);
Assert.AreEqual("CuesheetTitle", cuesheet.Title);
Assert.AreEqual("AudioFile.mp3", cuesheet.Audiofile?.Name);
Assert.IsFalse(cuesheet.Audiofile?.IsRecorded);
Assert.AreEqual("A123", cuesheet.Cataloguenumber);
Assert.AreEqual(2, cuesheet.Validate(nameof(Cuesheet.Cataloguenumber)).ValidationMessages?.Count);
Assert.AreEqual(10, cuesheet.Tracks.Count);
Expand All @@ -166,7 +165,6 @@ public void ImportFile_ValidProjectfileWithSections_ShouldImportFile()
Assert.AreEqual("CuesheetArtist", cuesheet.Artist);
Assert.AreEqual("CuesheetTitle", cuesheet.Title);
Assert.AreEqual("AudioFile.mp3", cuesheet.Audiofile?.Name);
Assert.IsFalse(cuesheet.Audiofile?.IsRecorded);
Assert.AreEqual("A123", cuesheet.Cataloguenumber);
Assert.AreEqual(2, cuesheet.Validate(nameof(Cuesheet.Cataloguenumber)).ValidationMessages?.Count);
Assert.AreEqual(10, cuesheet.Tracks.Count);
Expand Down
4 changes: 0 additions & 4 deletions AudioCuesheetEditor/Model/AudioCuesheet/Cuesheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ public IEnumerable<String> IsRecordingPossible
{
errors.Add("Cuesheet already contains tracks!");
}
if (Audiofile?.IsRecorded == true)
{
errors.Add("A recording is already available!");
}
return errors;
}
}
Expand Down
9 changes: 3 additions & 6 deletions AudioCuesheetEditor/Model/IO/Audio/Audiofile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
namespace AudioCuesheetEditor.Model.IO.Audio
{
[method: JsonConstructor]
public class Audiofile(String name, Boolean isRecorded = false) : IDisposable, IAudiofile
public class Audiofile(String name) : IDisposable, IAudiofile
{
public static readonly String RecordingFileName = $"Recording-{Guid.NewGuid()}.webm";
public static readonly AudioCodec AudioCodecWEBM = new("audio/webm", ".webm", "AudioCodec WEBM");

public static readonly List<AudioCodec> AudioCodecs =
Expand All @@ -42,7 +41,7 @@ public class Audiofile(String name, Boolean isRecorded = false) : IDisposable, I

public event EventHandler? ContentStreamLoaded;

public Audiofile(String name, String objectURL, AudioCodec? audioCodec, Boolean isRecorded = false) : this(name, isRecorded)
public Audiofile(String name, String objectURL, AudioCodec? audioCodec) : this(name)
{
if (String.IsNullOrEmpty(objectURL))
{
Expand Down Expand Up @@ -80,7 +79,7 @@ public Boolean IsContentStreamLoaded
get { return ContentStream != null; }
}
/// <summary>
/// File content stream. Be carefull, this stream is loaded asynchronously. Connect to the StreamLoaded for checking if loading has already been done!
/// File content stream. Be carefully, this stream is loaded asynchronously. Connect to the StreamLoaded for checking if loading has already been done!
/// </summary>
[JsonIgnore]
public Stream? ContentStream
Expand All @@ -97,8 +96,6 @@ public Stream? ContentStream
}
}
}
[JsonIgnore]
public Boolean IsRecorded { get; private set; } = isRecorded;
/// <summary>
/// Duration of the audio file
/// </summary>
Expand Down
1 change: 0 additions & 1 deletion AudioCuesheetEditor/Model/IO/Audio/IAudiofile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public interface IAudiofile
Stream? ContentStream { get; set; }
TimeSpan? Duration { get; }
bool IsContentStreamLoaded { get; }
bool IsRecorded { get; }
string Name { get; set; }
string? ObjectURL { get; }
bool PlaybackPossible { get; }
Expand Down
17 changes: 0 additions & 17 deletions AudioCuesheetEditor/Services/IO/FileInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,6 @@ public Boolean CheckFileMimeType(IBrowserFile file, String mimeType, String file
return audiofile;
}

public Audiofile? CreateRecordedAudiofile(String objectUrl, Action<Task<Stream>>? afterContentStreamLoaded = null)
{
Audiofile? audiofile = null;
if (String.IsNullOrEmpty(objectUrl) == false)
{
audiofile = new Audiofile(Audiofile.RecordingFileName, objectUrl, Audiofile.AudioCodecWEBM, true);
var loadContentStreamTask = _httpClient.GetStreamAsync(objectUrl)
.ContinueWith(x => audiofile.ContentStream = x.Result);
if (afterContentStreamLoaded != null)
{
_ = loadContentStreamTask
.ContinueWith(afterContentStreamLoaded);
}
}
return audiofile;
}

public CDTextfile? CreateCDTextfile(IBrowserFile? browserFile)
{
CDTextfile? cdTextfile = null;
Expand Down
1 change: 0 additions & 1 deletion AudioCuesheetEditor/Services/IO/IFileInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ public interface IFileInputManager
bool CheckFileMimeType(IBrowserFile file, string mimeType, string fileExtension);
Task<Audiofile?> CreateAudiofileAsync(string? fileInputId, IBrowserFile? browserFile, Action<Task<Stream>>? afterContentStreamLoaded = null);
CDTextfile? CreateCDTextfile(IBrowserFile? browserFile);
Audiofile? CreateRecordedAudiofile(string objectUrl, Action<Task<Stream>>? afterContentStreamLoaded = null);
}
}
3 changes: 0 additions & 3 deletions AudioCuesheetEditor/Shared/Record/ControlRecording.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="A recording is already available!" xml:space="preserve">
<value>Eine Aufnahme ist bereits verfügbar!</value>
</data>
<data name="Cuesheet already contains tracks!" xml:space="preserve">
<value>Das Cuesheet enthält bereits Titel!</value>
</data>
Expand Down
26 changes: 8 additions & 18 deletions AudioCuesheetEditor/Shared/Record/ControlRecording.razor
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ along with Foobar. If not, see
@inherits BaseLocalizedComponent

@inject IStringLocalizer<ControlRecording> _localizer
@inject IJSRuntime _jsRuntime
@inject IDialogService _dialogService
@inject IBlazorDownloadFileService _blazorDownloadFileService

Expand Down Expand Up @@ -53,10 +52,10 @@ along with Foobar. If not, see
<MudStack Row AlignItems="AlignItems.Baseline" Justify="Justify.SpaceBetween">
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert>
<MudButton StartIcon="@Icons.Material.Outlined.Mic" Disabled="StartRecordingDisabled" OnClick="StartRecordingAsync">@_localizer["Start recording"]</MudButton>
<MudButton StartIcon="@Icons.Material.Outlined.Mic" Disabled="StartRecordingDisabled" OnClick="StartRecording">@_localizer["Start recording"]</MudButton>
</MudHidden>
<MudHidden Breakpoint="Breakpoint.SmAndUp">
<MudIconButton Icon="@Icons.Material.Outlined.Mic" Disabled="StartRecordingDisabled" OnClick="StartRecordingAsync" />
<MudIconButton Icon="@Icons.Material.Outlined.Mic" Disabled="StartRecordingDisabled" OnClick="StartRecording" />
</MudHidden>
<MudMenu Icon="@Icons.Material.Outlined.ArrowRight" Disabled="StartRecordingDisabled" AnchorOrigin="Origin.TopRight">
<MudMenuItem Disabled="StartRecordingDisabled" OnClick="DisplayStartCountdownDialog">@_localizer["Enter countdown timer"]</MudMenuItem>
Expand All @@ -73,19 +72,12 @@ along with Foobar. If not, see
<MudText Typo="Typo.h5">@String.Format("--{0}--{1}--", CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator, CultureInfo.CurrentCulture.DateTimeFormat.TimeSeparator)</MudText>
}
<MudHidden Breakpoint="Breakpoint.SmAndUp" Invert>
<MudButton Color="Color.Warning" Variant="Variant.Filled" StartIcon="@Icons.Material.Outlined.Stop" Disabled="Cuesheet?.IsRecording == false" OnClick="StopRecordingAsync">@_localizer["Stop recording"]</MudButton>
<MudButton Color="Color.Warning" Variant="Variant.Filled" StartIcon="@Icons.Material.Outlined.Stop" Disabled="Cuesheet?.IsRecording == false" OnClick="StopRecording">@_localizer["Stop recording"]</MudButton>
</MudHidden>
<MudHidden Breakpoint="Breakpoint.SmAndUp">
<MudIconButton Color="Color.Warning" Variant="Variant.Filled" Icon="@Icons.Material.Outlined.Stop" Disabled="Cuesheet?.IsRecording == false" OnClick="StopRecordingAsync" />
<MudIconButton Color="Color.Warning" Variant="Variant.Filled" Icon="@Icons.Material.Outlined.Stop" Disabled="Cuesheet?.IsRecording == false" OnClick="StopRecording" />
</MudHidden>
</MudStack>
@if (Cuesheet?.Audiofile?.IsRecorded == true)
{
<br />
<MudStack Row Justify="Justify.FlexEnd">
<MudButton Color="Color.Success" Variant="Variant.Filled" StartIcon="@Icons.Material.Outlined.AudioFile" OnClick="DownloadAudio">@_localizer["Download recorded audio file"]</MudButton>
</MudStack>
}
</MudCardContent>
</MudCard>

Expand Down Expand Up @@ -118,18 +110,16 @@ along with Foobar. If not, see
};
}

async Task StartRecordingAsync()
void StartRecording()
{
Cuesheet?.StartRecording();
updateGUITimer.Start();
await _jsRuntime.InvokeVoidAsync("startAudioRecording");
Cuesheet!.Audiofile = null;
}

async Task StopRecordingAsync()
void StopRecording()
{
Cuesheet?.StopRecording();
await _jsRuntime.InvokeVoidAsync("stopAudioRecording");
}

async Task DisplayStartCountdownDialog()
Expand All @@ -140,9 +130,9 @@ along with Foobar. If not, see
if (result?.Canceled == false)
{
startRecordTimer = new Timer(ApplicationOptions!.RecordCountdownTimer * 1000);
startRecordTimer.Elapsed += async delegate
startRecordTimer.Elapsed += delegate
{
await StartRecordingAsync();
StartRecording();
startRecordTimer.Stop();
startRecordTimer.Dispose();
};
Expand Down
3 changes: 0 additions & 3 deletions AudioCuesheetEditor/Shared/Record/ControlRecording.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="A recording is already available!" xml:space="preserve">
<value>A recording is already available!</value>
</data>
<data name="Cuesheet already contains tracks!" xml:space="preserve">
<value>Cuesheet already contains tracks!</value>
</data>
Expand Down
26 changes: 0 additions & 26 deletions AudioCuesheetEditor/Shared/ViewModes/ViewModeRecord.razor
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,4 @@ along with Foobar. If not, see

[CascadingParameter]
public Cuesheet? Cuesheet { get; set; }

[JSInvokable()]
public Task AudioRecordingFinished(String objectUrl)
{
_sessionStateContainer.Cuesheet.Audiofile = _fileInputManager.CreateRecordedAudiofile(objectUrl, x =>
{
Cuesheet?.RecalculateLastTrackEnd();
TraceChangeManager.MergeLastEditWithEdit(x => x.Changes.All(y => y.TraceableObject == Cuesheet && y.TraceableChange.PropertyName == nameof(Audiofile)));
});
StateHasChanged();
return Task.CompletedTask;
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_jsRuntime.InvokeVoidAsync("closeAudioRecording");
}

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
var dotNetReference = DotNetObjectReference.Create(this);
await _jsRuntime.InvokeVoidAsync("GLOBAL.SetViewModeRecordReference", dotNetReference);
await _jsRuntime.InvokeVoidAsync("setupAudioRecording");
}
}
Loading