From 6d33cc2b3a3e8b2c570c80866c5aa666927d0ad5 Mon Sep 17 00:00:00 2001 From: bbb651 Date: Sat, 27 Jul 2024 12:36:14 +0300 Subject: [PATCH] WebAudio: Stub/implement more of `AudioNode` --- .../Libraries/LibWeb/WebAudio/AudioNode.cpp | 68 ++++++++++++++++++- .../Libraries/LibWeb/WebAudio/AudioNode.h | 13 +++- .../Libraries/LibWeb/WebAudio/AudioNode.idl | 10 +-- 3 files changed, 82 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp index df8eedd2751..67af990712a 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp @@ -24,18 +24,26 @@ AudioNode::~AudioNode() = default; // https://webaudio.github.io/web-audio-api/#dom-audionode-connect WebIDL::ExceptionOr> AudioNode::connect(JS::NonnullGCPtr destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input) { + // There can only be one connection between a given output of one specific node and a given input of another specific node. + // Multiple connections with the same termini are ignored. + + // If the destination parameter is an AudioNode that has been created using another AudioContext, an InvalidAccessError MUST be thrown. + if (m_context != destination_node->m_context) { + return WebIDL::InvalidAccessError::create(realm(), "Cannot connect to an AudioNode in a different AudioContext"_fly_string); + } + (void)output; (void)input; - dbgln("FIXME: Implement AudioNode::connect (AudioNode)"); + dbgln("FIXME: Implement Audio::connect(AudioNode)"); return destination_node; } // https://webaudio.github.io/web-audio-api/#dom-audionode-connect-destinationparam-output -WebIDL::ExceptionOr> AudioNode::connect(JS::NonnullGCPtr destination_param, WebIDL::UnsignedLong output) +void AudioNode::connect(JS::NonnullGCPtr destination_param, WebIDL::UnsignedLong output) { (void)destination_param; (void)output; - return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioNode::connect (AudioParam)"_fly_string); + dbgln("FIXME: Implement AudioNode::connect(AudioParam)"); } // https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect @@ -90,6 +98,60 @@ void AudioNode::disconnect(JS::NonnullGCPtr destination_param, WebID dbgln("FIXME: Implement AudioNode::disconnect(destination_param, output)"); } +// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofinputs +WebIDL::UnsignedLong AudioNode::number_of_inputs() +{ + dbgln("FIXME: Implement AudioNode::number_of_inputs()"); + return 0; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-numberofoutputs +WebIDL::UnsignedLong AudioNode::number_of_outputs() +{ + dbgln("FIXME: Implement AudioNode::number_of_outputs()"); + return 0; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount +WebIDL::ExceptionOr AudioNode::set_channel_count(WebIDL::UnsignedLong channel_count) +{ + (void)channel_count; + return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioNode::set_channel_count(channel_count)"_fly_string); +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount +WebIDL::UnsignedLong AudioNode::channel_count() +{ + dbgln("FIXME: Implement AudioNode::channel_count()"); + return 2; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode +WebIDL::ExceptionOr AudioNode::set_channel_count_mode(Bindings::ChannelCountMode channel_count_mode) +{ + m_channel_count_mode = channel_count_mode; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode +Bindings::ChannelCountMode AudioNode::channel_count_mode() +{ + return m_channel_count_mode; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation +WebIDL::ExceptionOr AudioNode::set_channel_interpretation(Bindings::ChannelInterpretation channel_interpretation) +{ + m_channel_interpretation = channel_interpretation; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation +Bindings::ChannelInterpretation AudioNode::channel_interpretation() +{ + return m_channel_interpretation; +} + void AudioNode::initialize(JS::Realm& realm) { Base::initialize(realm); diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h index c0b526297be..0c9e39830d9 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.h @@ -31,7 +31,7 @@ public: virtual ~AudioNode() override; WebIDL::ExceptionOr> connect(JS::NonnullGCPtr destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0); - WebIDL::ExceptionOr> connect(JS::NonnullGCPtr destination_param, WebIDL::UnsignedLong output = 0); + void connect(JS::NonnullGCPtr destination_param, WebIDL::UnsignedLong output = 0); void disconnect(); void disconnect(WebIDL::UnsignedLong output); @@ -48,6 +48,15 @@ public: return m_context; } + WebIDL::UnsignedLong number_of_inputs(); + WebIDL::UnsignedLong number_of_outputs(); + WebIDL::ExceptionOr set_channel_count(WebIDL::UnsignedLong); + WebIDL::UnsignedLong channel_count(); + WebIDL::ExceptionOr set_channel_count_mode(Bindings::ChannelCountMode); + Bindings::ChannelCountMode channel_count_mode(); + WebIDL::ExceptionOr set_channel_interpretation(Bindings::ChannelInterpretation); + Bindings::ChannelInterpretation channel_interpretation(); + protected: AudioNode(JS::Realm&, JS::NonnullGCPtr); @@ -56,6 +65,8 @@ protected: private: JS::NonnullGCPtr m_context; + Bindings::ChannelCountMode m_channel_count_mode { Bindings::ChannelCountMode::Max }; + Bindings::ChannelInterpretation m_channel_interpretation { Bindings::ChannelInterpretation::Speakers }; }; } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioNode.idl b/Userland/Libraries/LibWeb/WebAudio/AudioNode.idl index 7237dd11f5d..356d774aa8f 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioNode.idl +++ b/Userland/Libraries/LibWeb/WebAudio/AudioNode.idl @@ -38,9 +38,9 @@ interface AudioNode : EventTarget { undefined disconnect(AudioParam destinationParam); undefined disconnect(AudioParam destinationParam, unsigned long output); readonly attribute BaseAudioContext context; - [FIXME] readonly attribute unsigned long numberOfInputs; - [FIXME] readonly attribute unsigned long numberOfOutputs; - [FIXME] attribute unsigned long channelCount; - [FIXME] attribute ChannelCountMode channelCountMode; - [FIXME] attribute ChannelInterpretation channelInterpretation; + readonly attribute unsigned long numberOfInputs; + readonly attribute unsigned long numberOfOutputs; + attribute unsigned long channelCount; + attribute ChannelCountMode channelCountMode; + attribute ChannelInterpretation channelInterpretation; };