Coverage Report

Created: 2025-11-16 07:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/serenity/Userland/Libraries/LibWeb/WebAudio/AudioNode.cpp
Line
Count
Source
1
/*
2
 * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
3
 *
4
 * SPDX-License-Identifier: BSD-2-Clause
5
 */
6
7
#include <LibWeb/Bindings/Intrinsics.h>
8
#include <LibWeb/WebAudio/AudioNode.h>
9
#include <LibWeb/WebAudio/BaseAudioContext.h>
10
11
namespace Web::WebAudio {
12
13
JS_DEFINE_ALLOCATOR(AudioNode);
14
15
AudioNode::AudioNode(JS::Realm& realm, JS::NonnullGCPtr<BaseAudioContext> context)
16
0
    : DOM::EventTarget(realm)
17
0
    , m_context(context)
18
19
0
{
20
0
}
21
22
0
AudioNode::~AudioNode() = default;
23
24
WebIDL::ExceptionOr<void> AudioNode::initialize_audio_node_options(AudioNodeOptions const& given_options, AudioNodeDefaultOptions const& default_options)
25
0
{
26
    // Set channel count, fallback to default if not provided
27
0
    if (given_options.channel_count.has_value()) {
28
0
        TRY(set_channel_count(given_options.channel_count.value()));
29
0
    } else {
30
0
        TRY(set_channel_count(default_options.channel_count));
31
0
    }
32
33
    // Set channel count mode, fallback to default if not provided
34
0
    if (given_options.channel_count_mode.has_value()) {
35
0
        TRY(set_channel_count_mode(given_options.channel_count_mode.value()));
36
0
    } else {
37
0
        TRY(set_channel_count_mode(default_options.channel_count_mode));
38
0
    }
39
40
    // Set channel interpretation, fallback to default if not provided
41
0
    if (given_options.channel_interpretation.has_value()) {
42
0
        TRY(set_channel_interpretation(given_options.channel_interpretation.value()));
43
0
    } else {
44
0
        TRY(set_channel_interpretation(default_options.channel_interpretation));
45
0
    }
46
47
0
    return {};
48
0
}
49
50
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect
51
WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> AudioNode::connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input)
52
0
{
53
    // There can only be one connection between a given output of one specific node and a given input of another specific node.
54
    // Multiple connections with the same termini are ignored.
55
56
    // If the destination parameter is an AudioNode that has been created using another AudioContext, an InvalidAccessError MUST be thrown.
57
0
    if (m_context != destination_node->m_context) {
58
0
        return WebIDL::InvalidAccessError::create(realm(), "Cannot connect to an AudioNode in a different AudioContext"_string);
59
0
    }
60
61
0
    (void)output;
62
0
    (void)input;
63
0
    dbgln("FIXME: Implement Audio::connect(AudioNode)");
64
0
    return destination_node;
65
0
}
66
67
// https://webaudio.github.io/web-audio-api/#dom-audionode-connect-destinationparam-output
68
void AudioNode::connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output)
69
0
{
70
0
    (void)destination_param;
71
0
    (void)output;
72
0
    dbgln("FIXME: Implement AudioNode::connect(AudioParam)");
73
0
}
74
75
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect
76
void AudioNode::disconnect()
77
0
{
78
0
    dbgln("FIXME: Implement AudioNode::disconnect()");
79
0
}
80
81
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-output
82
void AudioNode::disconnect(WebIDL::UnsignedLong output)
83
0
{
84
0
    (void)output;
85
0
    dbgln("FIXME: Implement AudioNode::disconnect(output)");
86
0
}
87
88
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode
89
void AudioNode::disconnect(JS::NonnullGCPtr<AudioNode> destination_node)
90
0
{
91
0
    (void)destination_node;
92
0
    dbgln("FIXME: Implement AudioNode::disconnect(destination_node)");
93
0
}
94
95
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output
96
void AudioNode::disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output)
97
0
{
98
0
    (void)destination_node;
99
0
    (void)output;
100
0
    dbgln("FIXME: Implement AudioNode::disconnect(destination_node, output)");
101
0
}
102
103
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output-input
104
void AudioNode::disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input)
105
0
{
106
0
    (void)destination_node;
107
0
    (void)output;
108
0
    (void)input;
109
0
    dbgln("FIXME: Implement AudioNode::disconnect(destination_node, output, input)");
110
0
}
111
112
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationparam
113
void AudioNode::disconnect(JS::NonnullGCPtr<AudioParam> destination_param)
114
0
{
115
0
    (void)destination_param;
116
0
    dbgln("FIXME: Implement AudioNode::disconnect(destination_param)");
117
0
}
118
119
// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationparam-output
120
void AudioNode::disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output)
121
0
{
122
0
    (void)destination_param;
123
0
    (void)output;
124
0
    dbgln("FIXME: Implement AudioNode::disconnect(destination_param, output)");
125
0
}
126
127
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcount
128
WebIDL::ExceptionOr<void> AudioNode::set_channel_count(WebIDL::UnsignedLong channel_count)
129
0
{
130
    // If this value is set to zero or to a value greater than the implementation’s maximum number
131
    // of channels the implementation MUST throw a NotSupportedError exception.
132
0
    if (channel_count == 0 || channel_count > BaseAudioContext::MAX_NUMBER_OF_CHANNELS)
133
0
        return WebIDL::NotSupportedError::create(realm(), "Invalid channel count"_string);
134
135
0
    m_channel_count = channel_count;
136
0
    return {};
137
0
}
138
139
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode
140
WebIDL::ExceptionOr<void> AudioNode::set_channel_count_mode(Bindings::ChannelCountMode channel_count_mode)
141
0
{
142
0
    m_channel_count_mode = channel_count_mode;
143
0
    return {};
144
0
}
145
146
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelcountmode
147
Bindings::ChannelCountMode AudioNode::channel_count_mode()
148
0
{
149
0
    return m_channel_count_mode;
150
0
}
151
152
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation
153
WebIDL::ExceptionOr<void> AudioNode::set_channel_interpretation(Bindings::ChannelInterpretation channel_interpretation)
154
0
{
155
0
    m_channel_interpretation = channel_interpretation;
156
0
    return {};
157
0
}
158
159
// https://webaudio.github.io/web-audio-api/#dom-audionode-channelinterpretation
160
Bindings::ChannelInterpretation AudioNode::channel_interpretation()
161
0
{
162
0
    return m_channel_interpretation;
163
0
}
164
165
void AudioNode::initialize(JS::Realm& realm)
166
0
{
167
0
    Base::initialize(realm);
168
0
    WEB_SET_PROTOTYPE_FOR_INTERFACE(AudioNode);
169
0
}
170
171
void AudioNode::visit_edges(Cell::Visitor& visitor)
172
0
{
173
0
    Base::visit_edges(visitor);
174
0
    visitor.visit(m_context);
175
0
}
176
177
}