Skip to content

Commit

Permalink
Fixed bug with hydrating elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Jun 5, 2024
1 parent 783a6e1 commit f1e205e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
InputUpdated="async (string s) => { Input = s; await InputChanged.InvokeAsync(s); StateHasChanged(); }"
SupportedElements=SupportedElements
AddNewSVGElementMenuItems=AddNewMenuItems
ActionMenuItems=ActionMenuItems />
ActionMenuItems=ActionMenuItems/>
</CascadingValue>

@code {
Expand All @@ -29,15 +29,23 @@
{
AudioContext = await AudioContext.CreateAsync(JSRuntime);

await ProcessQueue();
StateHasChanged();

while (running)
{
await Task.Delay(50);
foreach (ITaskQueueable taskQueueable in SVGEditor.Elements.Where(e => e is ITaskQueueable))
await ProcessQueue();
}
}

private async Task ProcessQueue()
{
foreach (ITaskQueueable taskQueueable in SVGEditor.Elements.Where(e => e is ITaskQueueable))
{
while (taskQueueable.QueuedTasks.TryDequeue(out var task))
{
while (taskQueueable.QueuedTasks.TryDequeue(out var task))
{
await task(AudioContext);
}
await task(AudioContext);
}
}
}
Expand All @@ -49,14 +57,14 @@

protected List<SupportedElement> SupportedElements { get; set; } = new()
{
new(typeof(G), element => element.TagName == "G"),
new(typeof(Oscillator), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "oscillator"),
new(typeof(AudioDestination), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "audio-destination"),
new(typeof(Gain), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "gain"),
new(typeof(Analyser), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "analyser"),
new(typeof(BiquadFilter), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "biquad-filter"),
new(typeof(MediaStreamAudioSource), element => element.TagName is "RECT" && element.GetAttribute("data-elementtype") == "media-stream-audio-source"),
new(typeof(Connector), element => element.TagName is "LINE" && element.GetAttribute("data-elementtype") == "connector"),
new(typeof(G), element => element.TagName == "g"),
new(typeof(Oscillator), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "oscillator"),
new(typeof(AudioDestination), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "audio-destination"),
new(typeof(Gain), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "gain"),
new(typeof(Analyser), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "analyser"),
new(typeof(BiquadFilter), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "biquad-filter"),
new(typeof(MediaStreamAudioSource), element => element.TagName is "rect" && element.GetAttribute("data-elementtype") == "media-stream-audio-source"),
new(typeof(Connector), element => element.TagName is "line" && element.GetAttribute("data-elementtype") == "connector"),
};

protected List<SupportedAddNewSVGElementMenuItem> AddNewMenuItems { get; set; } = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@
[CascadingParameter]
public required AudioContext AudioContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnParametersSetAsync()
{
await base.OnAfterRenderAsync(firstRender);

if (analyser is null && AudioContext is not null)
{
analyser = (AnalyserNode)await SVGElement.AudioNode(AudioContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@

[CascadingParameter]
public required AudioContext AudioContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnParametersSetAsync()
{
await base.OnAfterRenderAsync(firstRender);

if (AudioContext is not null)
{
if (QAudioParam is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@
[CascadingParameter]
public required AudioContext AudioContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnParametersSetAsync()
{
await base.OnAfterRenderAsync(firstRender);

if (GainAudioParam is null && AudioContext is not null)
{
GainAudioParam = await SVGElement.AudioParams["gain"](AudioContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@
[CascadingParameter]
public required AudioContext AudioContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnParametersSetAsync()
{
await base.OnAfterRenderAsync(firstRender);

if (mediaStreamAudioSourceNode is null && AudioContext is not null)
{
mediaStreamAudioSourceNode = (MediaStreamAudioSourceNode)await SVGElement.AudioNode(AudioContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@
[CascadingParameter]
public required AudioContext AudioContext { get; set; }

protected override async Task OnAfterRenderAsync(bool firstRender)
protected override async Task OnParametersSetAsync()
{
await base.OnAfterRenderAsync(firstRender);

if (FrequencyAudioParam is null && AudioContext is not null)
{
FrequencyAudioParam = await SVGElement.AudioParams["frequency"](AudioContext);
Expand Down

0 comments on commit f1e205e

Please sign in to comment.