diff --git a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor index 7853fa4..71c2201 100644 --- a/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor +++ b/samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/Status.razor @@ -43,7 +43,7 @@ private (int start, int end)[] supportedRows = new (int start, int end)[] { (0, 16), (19, 41), - (46, 142), + (46, 154), (157, 200), (202, 266), (269, 269), diff --git a/src/KristofferStrube.Blazor.WebAudio/AudioNodes/AudioNode.cs b/src/KristofferStrube.Blazor.WebAudio/AudioNodes/AudioNode.cs index 36e99be..03a0764 100644 --- a/src/KristofferStrube.Blazor.WebAudio/AudioNodes/AudioNode.cs +++ b/src/KristofferStrube.Blazor.WebAudio/AudioNodes/AudioNode.cs @@ -49,15 +49,15 @@ protected AudioNode(IJSRuntime jSRuntime, IJSObjectReference jSReference) : base /// /// It is possible to connect an output to more than one with multiple calls to . Thus, "fan-out" is supported.
/// It is possible to connect more than one output to a single with multiple calls to . Thus, "fan-in" is supported.
- /// If the parameter is an that has been created using another , an will be thrown. That is, s cannot be shared between s.
- /// If the parameter is out-of-bounds, an exception will be thrown.
- /// If the parameter is out-of-bounds, an exception will be thrown.
+ /// It throws an if is an that has been created using another .
+ /// It throws an if the is out of bounds.
+ /// It throws an if the is out of bounds. ///
/// The destination parameter is the to connect to. /// The output parameter is an index describing which output of the from which to connect. /// The input parameter is an index describing which input of the destination to connect to. - /// - /// + /// + /// /// This method returns destination AudioNode object. public async Task ConnectAsync(AudioNode destinationNode, ulong output = 0, ulong input = 0) { @@ -71,30 +71,18 @@ public async Task ConnectAsync(AudioNode destinationNode, ulong outpu /// /// It is possible to connect an output to more than one with multiple calls to . Thus, "fan-out" is supported.
/// It is possible to connect more than one output to a single with multiple calls to . Thus, "fan-in" is supported.
- /// If the parameter is out-of-bounds, an exception will be thrown.
+ /// It throws an if belongs to an that belongs to a that is different from the that has created the on which this method was called.
+ /// It throws an if the is out of bounds. ///
/// The destination parameter is the to connect to. /// The output parameter is an index describing which output of the from which to connect. - /// - /// - /// This method returns destination AudioNode object. + /// + /// public async Task ConnectAsync(AudioParam destinationParam, ulong output = 0) { await JSReference.InvokeVoidAsync("connect", destinationParam.JSReference, output); } - /// - /// channelCount is the number of channels used when up-mixing and down-mixing connections to any inputs to the node. - /// The default value is 2 except for specific nodes where its value is specially determined. - /// This attribute has no effect for nodes with no inputs. - /// - /// - public async Task GetChannelCountAsync() - { - IJSObjectReference helper = await webAudioHelperTask.Value; - return await helper.InvokeAsync("getAttribute", JSReference, "channelCount"); - } - /// /// Disconnects all outgoing connections from the . /// @@ -104,15 +92,156 @@ public async Task DisconnectAsync() } /// - /// Disconnects all outgoing connections from the . + /// Disconnects a single output of the from any other or objects to which it is connected. /// /// - /// It throws an is the is out of bounds. + /// It throws an if the is out of bounds. /// - /// This parameter is an index describing which output of the AudioNode to disconnect. It disconnects all outgoing connections from the given output. + /// This parameter is an index describing which output of the to disconnect. It disconnects all outgoing connections from the given output. /// public async Task DisconnectAsync(ulong output) { await JSReference.InvokeVoidAsync("disconnect", output); } + + /// + /// Disconnects all outputs of the that go to a specific destination . + /// + /// + /// It throws an if there is connection to the . + /// + /// This parameter is the to disconnect. It disconnects all outgoing connections to the given destinationNode. + /// + public async Task DisconnectAsync(AudioNode destinationNode) + { + await JSReference.InvokeVoidAsync("disconnect", destinationNode.JSReference); + } + + /// + /// Disconnects a specific output of the from any and all inputs of some destination . + /// + /// + /// It throws an if there is connection from the given to the .
+ /// It throws an if the is out of bounds. + ///
+ /// This parameter is the to disconnect. + /// This parameter is an index describing which output of the from which to disconnect. + /// + /// + public async Task DisconnectAsync(AudioNode destinationNode, ulong output) + { + await JSReference.InvokeVoidAsync("disconnect", destinationNode.JSReference, output); + } + + /// + /// Disconnects a specific output of the from a specific input of some destination . + /// + /// + /// It throws an if there is no connection to the from the given to the given .
+ /// It throws an if the is out of bounds.
+ /// It throws an if the is out of bounds. + ///
+ /// This parameter is the to disconnect. + /// This parameter is an index describing which output of the from which to disconnect. + /// This parameter is an index describing which input of the destination to disconnect. + /// + /// + public async Task DisconnectAsync(AudioNode destinationNode, ulong output, ulong input) + { + await JSReference.InvokeVoidAsync("disconnect", destinationNode.JSReference, output, input); + } + + /// + /// Disconnects all outputs of the that go to a specific destination . + /// The contribution of this to the computed parameter value goes to 0 when this operation takes effect. + /// The intrinsic parameter value is not affected by this operation. + /// + /// + /// It throws an if there is no connection to the . + /// + /// This parameter is the to disconnect. + /// + public async Task DisconnectAsync(AudioParam destinationParam) + { + await JSReference.InvokeVoidAsync("disconnect", destinationParam.JSReference); + } + + /// + /// Disconnects a specific output of the from a specific destination . + /// The contribution of this to the computed parameter value goes to 0 when this operation takes effect. + /// The intrinsic parameter value is not affected by this operation. + /// + /// + /// It throws an if there is no connection to the .
+ /// It throws an if the is out of bounds. + ///
+ /// This parameter is the to disconnect. + /// This parameter is an index describing which output of the from which to disconnect. + /// + /// + public async Task DisconnectAsync(AudioParam destinationParam, ulong output) + { + await JSReference.InvokeVoidAsync("disconnect", destinationParam.JSReference, output); + } + + /// + /// Returns the which owns this . + /// + public async Task GetContextAsync() + { + IJSObjectReference helper = await webAudioHelperTask.Value; + IJSObjectReference jSInstance = await helper.InvokeAsync("getAttribute", JSReference, "context"); + return await BaseAudioContext.CreateAsync(JSRuntime, jSInstance); + } + + /// + /// Returns the number of inputs feeding into the . + /// For source nodes, this will be 0. + /// + /// + /// This attribute is predetermined for many types, but some s, like the and the , have variable number of inputs. + /// + public async Task GetNumberOfInputsAsync() + { + IJSObjectReference helper = await webAudioHelperTask.Value; + return await helper.InvokeAsync("getAttribute", JSReference, "numberOfInputs"); + } + + /// + /// Returns the number of outputs coming out of the . + /// + /// + /// This attribute is predetermined for some types, but can be variable, like for the and the . + /// + public async Task GetNumberOfOutputsAsync() + { + IJSObjectReference helper = await webAudioHelperTask.Value; + return await helper.InvokeAsync("getAttribute", JSReference, "numberOfOutputs"); + } + + /// + /// Returns the number of channels used when up-mixing and down-mixing connections to any inputs to the node. + /// The default value is 2 except for specific nodes where its value is specially determined. + /// This attribute has no effect for nodes with no inputs. + /// + public async Task GetChannelCountAsync() + { + IJSObjectReference helper = await webAudioHelperTask.Value; + return await helper.InvokeAsync("getAttribute", JSReference, "channelCount"); + } + + /// + /// Sets the number of channels used when up-mixing and down-mixing connections to any inputs to the node. + /// The default value is 2 except for specific nodes where its value is specially determined. + /// This attribute has no effect for nodes with no inputs. + /// + /// + /// It throws a if this is set to zero or to a value greater than the implementation’s maximum number of channels. + /// + /// + public async Task SetChannelCountAsync(ulong value) + { + IJSObjectReference helper = await webAudioHelperTask.Value; + await helper.InvokeVoidAsync("setAttribute", JSReference, "channelCount", value); + } } diff --git a/src/KristofferStrube.Blazor.WebAudio/BaseAudioContext.cs b/src/KristofferStrube.Blazor.WebAudio/BaseAudioContext.cs index bdf924c..a5546ea 100644 --- a/src/KristofferStrube.Blazor.WebAudio/BaseAudioContext.cs +++ b/src/KristofferStrube.Blazor.WebAudio/BaseAudioContext.cs @@ -21,6 +21,17 @@ public class BaseAudioContext : EventTarget /// protected readonly Lazy> webAudioHelperTask; + /// + /// Constructs a wrapper instance for a given JS Instance of an . + /// + /// An instance. + /// A JS reference to an existing . + /// A wrapper instance for an . + public static new Task CreateAsync(IJSRuntime jSRuntime, IJSObjectReference jSReference) + { + return Task.FromResult(new BaseAudioContext(jSRuntime, jSReference)); + } + /// /// Constructs a wrapper instance for a given JS Instance of a . ///