Skip to content

Commit 1241701

Browse files
Updated demos some more to not have gain sliders jump.
1 parent c7c47e1 commit 1241701

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Status:
7878
</table>
7979
</div>
8080
}
81-
<GainSlider GainNode=gainNode />
81+
<GainSlider GainNode=gainNode InteractiveBeforeGainNodeIsPresent="true" />
8282
<TimeDomainPlot Analyser=analyser />
8383

8484
@code {

samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Keyboard.razor

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@
1313
@foreach (var i in whiteKeyIndices)
1414
{
1515
var k = i;
16-
<rect @onmousedown="e => Start(keys[k].Octave, keys[k].Pitch, e)"
17-
@onmouseenter="e => Start(keys[k].Octave, keys[k].Pitch, e)"
18-
@onmouseup="End"
19-
@onmouseout="End"
20-
@ontouchstart="e => Start(keys[k].Octave, keys[k].Pitch, e)"
21-
@ontouchend="End"
16+
<rect @onpointerdown="e => Start(keys[k].Octave, keys[k].Pitch, e)"
17+
@onpointerenter="e => Start(keys[k].Octave, keys[k].Pitch, e)"
18+
@onpointerup="End"
19+
@onpointerout="End"
2220
x="@(keys.GetRange(0, i).Count(k => k.Color == "white") * 100)"
2321
y="0"
2422
width="100"
@@ -42,12 +40,10 @@
4240
@foreach (var i in blackKeyIndices)
4341
{
4442
var k = i;
45-
<rect @onmousedown="e => Start(keys[k].Octave, keys[k].Pitch, e)"
46-
@onmouseenter="e => Start(keys[k].Octave, keys[k].Pitch, e)"
47-
@onmouseup="End"
48-
@onmouseout="End"
49-
@ontouchstart="e => Start(keys[k].Octave, keys[k].Pitch, e)"
50-
@ontouchend="End"
43+
<rect @onpointerdown="e => Start(keys[k].Octave, keys[k].Pitch, e)"
44+
@onpointerenter="e => Start(keys[k].Octave, keys[k].Pitch, e)"
45+
@onpointerup="End"
46+
@onpointerout="End"
5147
x="@(keys.GetRange(0, i).Count(k => k.Color == "white") * 100 - 30 - (keys[k].Pitch is 2 or 7 ? 10 : 0) + (keys[k].Pitch is 4 or 11 ? 10 : 0))"
5248
y="0"
5349
width="60"
@@ -57,7 +53,7 @@
5753
stroke-width="1"></rect>
5854
}
5955
</svg>
60-
<GainSlider GainNode="mainNode" />
56+
<GainSlider GainNode="mainNode" InteractiveBeforeGainNodeIsPresent="true" />
6157

6258
<div style="height:30vh;width:100%;">
6359
<ADSREditor @ref=ADSREditor />

samples/KristofferStrube.Blazor.WebAudio.WasmExample/Shared/GainSlider.razor

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,31 @@
88
max="1"
99
step="0.01"
1010
style="width:min(200px, 100%);"/>
11-
<span class="badge bg-primary">@Math.Round(Gain*100, 0)%</span>
11+
<span class="badge bg-primary">@Math.Round(Gain * 100, 0)%</span>
1212

1313
@code {
1414
private string inputId = $"gain_{Guid.NewGuid()}"[..9];
1515

1616
[Parameter, EditorRequired]
1717
public GainNode? GainNode { get; set; }
1818

19-
public float Gain { get; private set; } = 0.05f;
19+
[Parameter]
20+
public bool InteractiveBeforeGainNodeIsPresent { get; set; } = false;
21+
22+
public float Gain { get; private set; } = 0.1f;
2023

2124
protected override async Task OnParametersSetAsync()
2225
{
2326
if (GainNode is null) return;
2427
await using AudioParam audioParam = await GainNode.GetGainAsync();
25-
Gain = await audioParam.GetValueAsync();
28+
if (InteractiveBeforeGainNodeIsPresent)
29+
{
30+
await audioParam.SetValueAsync(Gain);
31+
}
32+
else
33+
{
34+
Gain = await audioParam.GetValueAsync();
35+
}
2636
}
2737

2838
public async Task GainUpdatedAsync()

0 commit comments

Comments
 (0)