/src/serenity/Userland/Libraries/LibWeb/WebAudio/AudioNode.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Optional.h> |
10 | | #include <LibJS/Forward.h> |
11 | | #include <LibWeb/Bindings/AudioNodePrototype.h> |
12 | | #include <LibWeb/Bindings/PlatformObject.h> |
13 | | #include <LibWeb/DOM/EventTarget.h> |
14 | | #include <LibWeb/WebIDL/Types.h> |
15 | | |
16 | | namespace Web::WebAudio { |
17 | | |
18 | | // https://webaudio.github.io/web-audio-api/#AudioNodeOptions |
19 | | struct AudioNodeOptions { |
20 | | Optional<WebIDL::UnsignedLong> channel_count; |
21 | | Optional<Bindings::ChannelCountMode> channel_count_mode; |
22 | | Optional<Bindings::ChannelInterpretation> channel_interpretation; |
23 | | }; |
24 | | |
25 | | struct AudioNodeDefaultOptions { |
26 | | WebIDL::UnsignedLong channel_count; |
27 | | Bindings::ChannelCountMode channel_count_mode; |
28 | | Bindings::ChannelInterpretation channel_interpretation; |
29 | | }; |
30 | | |
31 | | // https://webaudio.github.io/web-audio-api/#AudioNode |
32 | | class AudioNode : public DOM::EventTarget { |
33 | | WEB_PLATFORM_OBJECT(AudioNode, DOM::EventTarget); |
34 | | JS_DECLARE_ALLOCATOR(AudioNode); |
35 | | |
36 | | public: |
37 | | virtual ~AudioNode() override; |
38 | | |
39 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0); |
40 | | void connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output = 0); |
41 | | |
42 | | void disconnect(); |
43 | | void disconnect(WebIDL::UnsignedLong output); |
44 | | void disconnect(JS::NonnullGCPtr<AudioNode> destination_node); |
45 | | void disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output); |
46 | | void disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input); |
47 | | void disconnect(JS::NonnullGCPtr<AudioParam> destination_param); |
48 | | void disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output); |
49 | | |
50 | | // https://webaudio.github.io/web-audio-api/#dom-audionode-context |
51 | | JS::NonnullGCPtr<BaseAudioContext const> context() const |
52 | 0 | { |
53 | | // The BaseAudioContext which owns this AudioNode. |
54 | 0 | return m_context; |
55 | 0 | } |
56 | | |
57 | | // https://webaudio.github.io/web-audio-api/#dom-audionode-numberofinputs |
58 | | virtual WebIDL::UnsignedLong number_of_inputs() = 0; |
59 | | // https://webaudio.github.io/web-audio-api/#dom-audionode-numberofoutputs |
60 | | virtual WebIDL::UnsignedLong number_of_outputs() = 0; |
61 | | |
62 | | // https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount |
63 | | virtual WebIDL::ExceptionOr<void> set_channel_count(WebIDL::UnsignedLong); |
64 | 0 | virtual WebIDL::UnsignedLong channel_count() const { return m_channel_count; } |
65 | | |
66 | | virtual WebIDL::ExceptionOr<void> set_channel_count_mode(Bindings::ChannelCountMode); |
67 | | Bindings::ChannelCountMode channel_count_mode(); |
68 | | WebIDL::ExceptionOr<void> set_channel_interpretation(Bindings::ChannelInterpretation); |
69 | | Bindings::ChannelInterpretation channel_interpretation(); |
70 | | |
71 | | WebIDL::ExceptionOr<void> initialize_audio_node_options(AudioNodeOptions const& given_options, AudioNodeDefaultOptions const& default_options); |
72 | | |
73 | | protected: |
74 | | AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>); |
75 | | |
76 | | virtual void initialize(JS::Realm&) override; |
77 | | virtual void visit_edges(Cell::Visitor&) override; |
78 | | |
79 | | private: |
80 | | JS::NonnullGCPtr<BaseAudioContext> m_context; |
81 | | WebIDL::UnsignedLong m_channel_count { 2 }; |
82 | | Bindings::ChannelCountMode m_channel_count_mode { Bindings::ChannelCountMode::Max }; |
83 | | Bindings::ChannelInterpretation m_channel_interpretation { Bindings::ChannelInterpretation::Speakers }; |
84 | | }; |
85 | | |
86 | | } |