Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Aug 26, 2024
1 parent 7419873 commit 049d443
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Node? From
{
Element.SetAttribute("data-from-node", value.Id);
from = value;
if (value is { } newNode )
if (value is { } newNode)
{
_ = value.OutgoingConnectors.Add(this);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace KristofferStrube.Blazor.WebAudio.WasmExample.AudioEditor;

public class Gain : Node
{
public Gain(IElement element, SVGEditor.SVGEditor svg) : base(element, svg) {
public Gain(IElement element, SVGEditor.SVGEditor svg) : base(element, svg)
{
AudioParams = new()
{
["gain"] = async (audioContext) => await ((GainNode)await AudioNode(audioContext)).GetGainAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task SetMediaStreamAudioSourceNode(AudioContext context)
}

public string? SelectedAudioSource { get; set; }
public List<(string label, string id)> AudioOptions { get; set; } = new();
public List<(string label, string id)> AudioOptions { get; set; } = [];

public override Type Presenter => typeof(MediaStreamAudioSourceEditor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ public abstract class Node : Rect, ITaskQueueable
{
protected readonly SemaphoreSlim audioNodeSlim = new(1, 1);

public Dictionary<string, Func<AudioContext, Task<AudioParam>>> AudioParams { get; set; } = new();
public virtual Dictionary<string, int> AudioParamPositions { get; set; } = new();
public Dictionary<string, Func<AudioContext, Task<AudioParam>>> AudioParams { get; set; } = [];
public virtual Dictionary<string, int> AudioParamPositions { get; set; } = [];

public int Offset(string? identifier = null) => identifier is not null && AudioParamPositions.TryGetValue(identifier, out int offset) ? offset : 20;
public int Offset(string? identifier = null)
{
return identifier is not null && AudioParamPositions.TryGetValue(identifier, out int offset) ? offset : 20;
}

public Node(IElement element, SVGEditor.SVGEditor svg) : base(element, svg)
{
Expand Down Expand Up @@ -47,8 +50,8 @@ public override string Fill

public abstract Func<AudioContext, Task<AudioNode>> AudioNode { get; }

public HashSet<Connector> IngoingConnectors { get; } = new();
public HashSet<Connector> OutgoingConnectors { get; } = new();
public HashSet<Connector> IngoingConnectors { get; } = [];
public HashSet<Connector> OutgoingConnectors { get; } = [];

public string? CurrentActiveAudioParamIdentifier { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ namespace KristofferStrube.Blazor.WebAudio.WasmExample;

public static class DoubleExtensions
{
public static string AsString(this double value) => value.ToString(CultureInfo.InvariantCulture);
public static string AsString(this double value)
{
return value.ToString(CultureInfo.InvariantCulture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public partial class AmplitudePlot : ComponentBase, IDisposable

protected override async Task OnAfterRenderAsync(bool _)
{
if (running || Analyser is null) return;
if (running || Analyser is null)
{
return;
}

running = true;

int bufferLength = (int)await Analyser.GetFftSizeAsync();
Expand All @@ -37,7 +41,10 @@ protected override async Task OnAfterRenderAsync(bool _)
{
for (int i = 0; i < Width; i++)
{
if (!running) break;
if (!running)
{
break;
}

await Analyser.GetByteTimeDomainDataAsync(timeDomainData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public partial class SpectrogramPlot : ComponentBase, IDisposable

protected override async Task OnAfterRenderAsync(bool _)
{
if (running || Analyser is null) return;
if (running || Analyser is null)
{
return;
}

running = true;

int bufferLength = (int)await Analyser.GetFrequencyBinCountAsync();
Expand All @@ -37,7 +41,10 @@ protected override async Task OnAfterRenderAsync(bool _)
{
for (int i = 0; i < Width; i++)
{
if (!running) break;
if (!running)
{
break;
}

await Analyser.GetByteFrequencyDataAsync(frequencyDataArray);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MediaStreamAudioSourceNode : AudioNode, IJSCreatable<MediaStreamAud
public static async Task<MediaStreamAudioSourceNode> CreateAsync(IJSRuntime jSRuntime, AudioContext context, MediaStreamAudioSourceOptions options)
{
IJSObjectReference helper = await jSRuntime.GetHelperAsync();
IJSObjectReference jSInstance = await helper.InvokeAsync<IJSObjectReference>("constructMediaStreamAudioSourceNode", context, new {});
IJSObjectReference jSInstance = await helper.InvokeAsync<IJSObjectReference>("constructMediaStreamAudioSourceNode", context, new { });
return new MediaStreamAudioSourceNode(jSRuntime, jSInstance, new() { DisposesJSReference = true });
}

Expand Down

0 comments on commit 049d443

Please sign in to comment.