Skip to content

Commit

Permalink
Updated OscillatorTypeConverter to support reading.
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferStrube committed Jan 31, 2024
1 parent 0f4afe1 commit c3970bd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ internal class OscillatorTypeConverter : JsonConverter<OscillatorType>
{
public override OscillatorType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
throw new NotImplementedException();
return reader.GetString() switch
{
"sine" => OscillatorType.Sine,
"square" => OscillatorType.Square,
"sawtooth" => OscillatorType.Sawtooth,
"triangle" => OscillatorType.Triangle,
"custom" => OscillatorType.Custom,
var value => throw new ArgumentException($"Value '{value}' was not a valid {nameof(OscillatorType)}."),
};
}

public override void Write(Utf8JsonWriter writer, OscillatorType value, JsonSerializerOptions options)
Expand Down
10 changes: 5 additions & 5 deletions src/KristofferStrube.Blazor.WebAudio/Options/OscillatorType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ namespace KristofferStrube.Blazor.WebAudio;
public enum OscillatorType
{
/// <summary>
/// A sine wave
/// A sine wave.
/// </summary>
Sine,
/// <summary>
/// A square wave of duty period 0.5
/// A square wave of duty period <c>0.5</c>.
/// </summary>
Square,
/// <summary>
/// A sawtooth wave
/// A sawtooth wave.
/// </summary>
Sawtooth,
/// <summary>
/// A triangle wave
/// A triangle wave.
/// </summary>
Triangle,
/// <summary>
/// A custom periodic wave
/// A custom periodic wave.
/// </summary>
Custom
}

0 comments on commit c3970bd

Please sign in to comment.