| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Optional.h>
 | 
					
						
							|  |  |  | #include <LibJS/Forward.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/AudioNodePrototype.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/EventTarget.h>
 | 
					
						
							|  |  |  | #include <LibWeb/WebIDL/Types.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::WebAudio { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://webaudio.github.io/web-audio-api/#AudioNodeOptions
 | 
					
						
							|  |  |  | struct AudioNodeOptions { | 
					
						
							|  |  |  |     Optional<WebIDL::UnsignedLong> channel_count; | 
					
						
							| 
									
										
										
										
											2024-10-20 02:49:55 +04:00
										 |  |  |     Optional<Bindings::ChannelCountMode> channel_count_mode; | 
					
						
							|  |  |  |     Optional<Bindings::ChannelInterpretation> channel_interpretation; | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 03:28:48 +04:00
										 |  |  | struct AudioNodeDefaultOptions { | 
					
						
							|  |  |  |     WebIDL::UnsignedLong channel_count; | 
					
						
							|  |  |  |     Bindings::ChannelCountMode channel_count_mode; | 
					
						
							|  |  |  |     Bindings::ChannelInterpretation channel_interpretation; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | // https://webaudio.github.io/web-audio-api/#AudioNode
 | 
					
						
							|  |  |  | class AudioNode : public DOM::EventTarget { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(AudioNode, DOM::EventTarget); | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC_DECLARE_ALLOCATOR(AudioNode); | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~AudioNode() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     WebIDL::ExceptionOr<GC::Ref<AudioNode>> connect(GC::Ref<AudioNode> destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0); | 
					
						
							| 
									
										
										
										
											2025-01-04 02:21:16 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> connect(GC::Ref<AudioParam> destination_param, WebIDL::UnsignedLong output = 0); | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void disconnect(); | 
					
						
							| 
									
										
										
										
											2025-01-08 23:09:17 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> disconnect(WebIDL::UnsignedLong output); | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     void disconnect(GC::Ref<AudioNode> destination_node); | 
					
						
							| 
									
										
										
										
											2025-01-08 23:09:17 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> disconnect(GC::Ref<AudioNode> destination_node, WebIDL::UnsignedLong output); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> disconnect(GC::Ref<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input); | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     void disconnect(GC::Ref<AudioParam> destination_param); | 
					
						
							| 
									
										
										
										
											2025-01-08 23:09:17 +00:00
										 |  |  |     WebIDL::ExceptionOr<void> disconnect(GC::Ref<AudioParam> destination_param, WebIDL::UnsignedLong output); | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-30 21:38:35 +12:00
										 |  |  |     // https://webaudio.github.io/web-audio-api/#dom-audionode-context
 | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<BaseAudioContext const> context() const | 
					
						
							| 
									
										
										
										
											2024-04-30 21:38:35 +12:00
										 |  |  |     { | 
					
						
							|  |  |  |         // The BaseAudioContext which owns this AudioNode.
 | 
					
						
							|  |  |  |         return m_context; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-08 12:03:50 +02:00
										 |  |  |     // https://webaudio.github.io/web-audio-api/#dom-audionode-numberofinputs
 | 
					
						
							|  |  |  |     virtual WebIDL::UnsignedLong number_of_inputs() = 0; | 
					
						
							|  |  |  |     // https://webaudio.github.io/web-audio-api/#dom-audionode-numberofoutputs
 | 
					
						
							|  |  |  |     virtual WebIDL::UnsignedLong number_of_outputs() = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-08 13:51:27 +02:00
										 |  |  |     // https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
 | 
					
						
							|  |  |  |     virtual WebIDL::ExceptionOr<void> set_channel_count(WebIDL::UnsignedLong); | 
					
						
							|  |  |  |     virtual WebIDL::UnsignedLong channel_count() const { return m_channel_count; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 02:49:55 +04:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_channel_count_mode(Bindings::ChannelCountMode); | 
					
						
							| 
									
										
										
										
											2024-07-27 12:36:14 +03:00
										 |  |  |     Bindings::ChannelCountMode channel_count_mode(); | 
					
						
							| 
									
										
										
										
											2025-01-01 22:00:52 +00:00
										 |  |  |     virtual WebIDL::ExceptionOr<void> set_channel_interpretation(Bindings::ChannelInterpretation); | 
					
						
							| 
									
										
										
										
											2024-07-27 12:36:14 +03:00
										 |  |  |     Bindings::ChannelInterpretation channel_interpretation(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-10-20 03:28:48 +04:00
										 |  |  |     WebIDL::ExceptionOr<void> initialize_audio_node_options(AudioNodeOptions const& given_options, AudioNodeDefaultOptions const& default_options); | 
					
						
							| 
									
										
										
										
											2024-10-20 02:49:55 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2025-01-07 23:24:10 +00:00
										 |  |  |     AudioNode(JS::Realm&, GC::Ref<BaseAudioContext>, WebIDL::UnsignedLong channel_count = 2); | 
					
						
							| 
									
										
										
										
											2024-04-29 20:03:15 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							|  |  |  |     virtual void visit_edges(Cell::Visitor&) override; | 
					
						
							| 
									
										
										
										
											2024-04-29 20:03:15 +12:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2024-11-15 04:01:23 +13:00
										 |  |  |     GC::Ref<BaseAudioContext> m_context; | 
					
						
							| 
									
										
										
										
											2024-10-08 13:51:27 +02:00
										 |  |  |     WebIDL::UnsignedLong m_channel_count { 2 }; | 
					
						
							| 
									
										
										
										
											2024-07-27 12:36:14 +03:00
										 |  |  |     Bindings::ChannelCountMode m_channel_count_mode { Bindings::ChannelCountMode::Max }; | 
					
						
							|  |  |  |     Bindings::ChannelInterpretation m_channel_interpretation { Bindings::ChannelInterpretation::Speakers }; | 
					
						
							| 
									
										
										
										
											2024-04-28 12:46:07 +12:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |