-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added demo of using Custom Waveform.
- Loading branch information
1 parent
ad98af2
commit b91979d
Showing
11 changed files
with
353 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...s/KristofferStrube.Blazor.WebAudio.WasmExample/CustomPeriodicWaves/ExpressionTemplates.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
using KristofferStrube.Blazor.FormulaEditor; | ||
using KristofferStrube.Blazor.FormulaEditor.BooleanExpressions; | ||
using KristofferStrube.Blazor.FormulaEditor.Expressions; | ||
|
||
namespace KristofferStrube.Blazor.WebAudio.WasmExample.CustomPeriodicWaves; | ||
|
||
public static class ExpressionTemplates | ||
{ | ||
public static NumberReturningExpression SineWave(Identifier nIdentifier) => new CasesExpression() | ||
{ | ||
Cases = [new() { | ||
Value = new NumericExpression() { Value = 1 }, | ||
Condition = new EqualsOperator() { First = new IdentifierExpression() { Value = nIdentifier }, Second = new NumericExpression() { Value = 1 } } | ||
}], | ||
Otherwise = new NumericExpression() { Value = 0 }, | ||
}; | ||
|
||
public static NumberReturningExpression SquareWave(Identifier nIdentifier) => new MultiplicationOperator() | ||
{ | ||
First = new FractionOperator() | ||
{ | ||
Numerator = new NumericExpression() { Value = 2 }, | ||
Denominator = new MultiplicationOperator() | ||
{ | ||
First = new IdentifierExpression() { Value = nIdentifier }, | ||
Second = new ConstantExpression() { Value = new Constant("π", Math.PI) }, | ||
ExplicitOperator = false | ||
} | ||
}, | ||
Second = new SubtractionOperator() | ||
{ | ||
First = new NumericExpression() { Value = 1 }, | ||
Second = new PowerOperator() | ||
{ | ||
Value = new NumericExpression() { Value = -1, Parenthesis = true }, | ||
Power = new IdentifierExpression() { Value = nIdentifier } | ||
}, | ||
Parenthesis = true | ||
}, | ||
ExplicitOperator = false | ||
}; | ||
|
||
public static NumberReturningExpression SawtoothWave(Identifier nIdentifier) => new MultiplicationOperator() | ||
{ | ||
First = new PowerOperator() | ||
{ | ||
Value = new NumericExpression() { Value = -1, Parenthesis = true }, | ||
Power = new AdditionOperator() | ||
{ | ||
First = new IdentifierExpression() { Value = nIdentifier }, | ||
Second = new NumericExpression() { Value = 1 }, | ||
Parenthesis = true | ||
} | ||
}, | ||
Second = new FractionOperator() | ||
{ | ||
Numerator = new NumericExpression() { Value = 2 }, | ||
Denominator = new MultiplicationOperator() | ||
{ | ||
First = new IdentifierExpression() { Value = nIdentifier }, | ||
Second = new ConstantExpression() { Value = new Constant("π", Math.PI) }, | ||
ExplicitOperator = false | ||
} | ||
}, | ||
ExplicitOperator = false | ||
}; | ||
|
||
public static NumberReturningExpression TriangleWave(Identifier nIdentifier) => new FractionOperator() | ||
{ | ||
Numerator = new MultiplicationOperator() | ||
{ | ||
First = new NumericExpression() { Value = 8 }, | ||
Second = new FunctionExpression() | ||
{ | ||
Function = new Function("sin", v => Math.Sin(v)), | ||
Input = new FractionOperator() | ||
{ | ||
Numerator = new MultiplicationOperator() | ||
{ | ||
First = new IdentifierExpression() { Value = nIdentifier }, | ||
Second = new ConstantExpression() { Value = new Constant("π", Math.PI) }, | ||
ExplicitOperator = false | ||
}, | ||
Denominator = new NumericExpression() { Value = 2 } | ||
}, | ||
Parenthesis = false | ||
}, | ||
ExplicitOperator = false | ||
}, | ||
Denominator = new PowerOperator() | ||
{ | ||
Value = new MultiplicationOperator() | ||
{ | ||
First = new ConstantExpression() { Value = new Constant("π", Math.PI) }, | ||
Second = new IdentifierExpression() { Value = nIdentifier }, | ||
ExplicitOperator = false, | ||
Parenthesis = true | ||
}, | ||
Power = new NumericExpression() { Value = 2 } | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
samples/KristofferStrube.Blazor.WebAudio.WasmExample/Shared/EnumSelector.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@typeparam TEnum where TEnum : Enum | ||
|
||
<select @bind=Value @bind:after=OnValueChanged disabled=@Disabled> | ||
@foreach (TEnum option in Enum.GetValues(typeof(TEnum))) | ||
{ | ||
<option value="@option">@option</option> | ||
} | ||
</select> | ||
|
||
@code { | ||
[Parameter] | ||
public bool Disabled { get; set; } = false; | ||
|
||
[Parameter, EditorRequired] | ||
public required TEnum Value { get; set; } | ||
|
||
[Parameter, EditorRequired] | ||
public EventCallback<TEnum> ValueChanged { get; set; } | ||
|
||
private async Task OnValueChanged() | ||
{ | ||
await ValueChanged.InvokeAsync(Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,7 @@ | |
|
||
[Parameter] | ||
public int Height { get; set; } = 200; | ||
|
||
[Parameter] | ||
public string Color { get; set; } = "red"; | ||
} |
3 changes: 3 additions & 0 deletions
3
samples/KristofferStrube.Blazor.WebAudio.WasmExample/Shared/TimeDomainPlot.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@using Excubo.Blazor.Canvas | ||
|
||
<Plot Data=@timeDomainMeasurements Height=@Height Color=@Color /> |
Oops, something went wrong.