/src/serenity/Userland/Libraries/LibWeb/WebAudio/AudioParam.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include <LibWeb/Bindings/AudioParamPrototype.h> |
8 | | #include <LibWeb/Bindings/Intrinsics.h> |
9 | | #include <LibWeb/WebAudio/AudioParam.h> |
10 | | #include <LibWeb/WebIDL/ExceptionOr.h> |
11 | | |
12 | | namespace Web::WebAudio { |
13 | | |
14 | | JS_DEFINE_ALLOCATOR(AudioParam); |
15 | | |
16 | | AudioParam::AudioParam(JS::Realm& realm, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate) |
17 | 0 | : Bindings::PlatformObject(realm) |
18 | 0 | , m_current_value(default_value) |
19 | 0 | , m_default_value(default_value) |
20 | 0 | , m_min_value(min_value) |
21 | 0 | , m_max_value(max_value) |
22 | 0 | , m_automation_rate(automation_rate) |
23 | 0 | { |
24 | 0 | } |
25 | | |
26 | | JS::NonnullGCPtr<AudioParam> AudioParam::create(JS::Realm& realm, float default_value, float min_value, float max_value, Bindings::AutomationRate automation_rate) |
27 | 0 | { |
28 | 0 | return realm.vm().heap().allocate<AudioParam>(realm, realm, default_value, min_value, max_value, automation_rate); |
29 | 0 | } |
30 | | |
31 | 0 | AudioParam::~AudioParam() = default; |
32 | | |
33 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-value |
34 | | // https://webaudio.github.io/web-audio-api/#simple-nominal-range |
35 | | float AudioParam::value() const |
36 | 0 | { |
37 | | // Each AudioParam includes minValue and maxValue attributes that together form the simple nominal range |
38 | | // for the parameter. In effect, value of the parameter is clamped to the range [minValue, maxValue]. |
39 | 0 | return clamp(m_current_value, min_value(), max_value()); |
40 | 0 | } |
41 | | |
42 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-value |
43 | | void AudioParam::set_value(float value) |
44 | 0 | { |
45 | 0 | m_current_value = value; |
46 | 0 | } |
47 | | |
48 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate |
49 | | Bindings::AutomationRate AudioParam::automation_rate() const |
50 | 0 | { |
51 | 0 | return m_automation_rate; |
52 | 0 | } |
53 | | |
54 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-automationrate |
55 | | WebIDL::ExceptionOr<void> AudioParam::set_automation_rate(Bindings::AutomationRate automation_rate) |
56 | 0 | { |
57 | 0 | dbgln("FIXME: Fully implement AudioParam::set_automation_rate"); |
58 | 0 | m_automation_rate = automation_rate; |
59 | 0 | return {}; |
60 | 0 | } |
61 | | |
62 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-defaultvalue |
63 | | float AudioParam::default_value() const |
64 | 0 | { |
65 | 0 | return m_default_value; |
66 | 0 | } |
67 | | |
68 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-minvalue |
69 | | float AudioParam::min_value() const |
70 | 0 | { |
71 | 0 | return m_min_value; |
72 | 0 | } |
73 | | |
74 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-maxvalue |
75 | | float AudioParam::max_value() const |
76 | 0 | { |
77 | 0 | return m_max_value; |
78 | 0 | } |
79 | | |
80 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-setvalueattime |
81 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::set_value_at_time(float value, double start_time) |
82 | 0 | { |
83 | 0 | (void)value; |
84 | 0 | (void)start_time; |
85 | 0 | dbgln("FIXME: Implement AudioParam::set_value_at_time"); |
86 | 0 | return JS::NonnullGCPtr<AudioParam> { *this }; |
87 | 0 | } |
88 | | |
89 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-linearramptovalueattime |
90 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::linear_ramp_to_value_at_time(float value, double end_time) |
91 | 0 | { |
92 | 0 | (void)value; |
93 | 0 | (void)end_time; |
94 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::linear_ramp_to_value_at_time"_string); |
95 | 0 | } |
96 | | |
97 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-exponentialramptovalueattime |
98 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::exponential_ramp_to_value_at_time(float value, double end_time) |
99 | 0 | { |
100 | 0 | (void)value; |
101 | 0 | (void)end_time; |
102 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::exponential_ramp_to_value_at_time"_string); |
103 | 0 | } |
104 | | |
105 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-settargetattime |
106 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::set_target_at_time(float target, double start_time, float time_constant) |
107 | 0 | { |
108 | 0 | (void)target; |
109 | 0 | (void)start_time; |
110 | 0 | (void)time_constant; |
111 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::set_target_at_time"_string); |
112 | 0 | } |
113 | | |
114 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-setvaluecurveattime |
115 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::set_value_curve_at_time(Span<float> values, double start_time, double duration) |
116 | 0 | { |
117 | 0 | (void)values; |
118 | 0 | (void)start_time; |
119 | 0 | (void)duration; |
120 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::set_value_curve_at_time"_string); |
121 | 0 | } |
122 | | |
123 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelscheduledvalues |
124 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::cancel_scheduled_values(double cancel_time) |
125 | 0 | { |
126 | 0 | (void)cancel_time; |
127 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::cancel_scheduled_values"_string); |
128 | 0 | } |
129 | | |
130 | | // https://webaudio.github.io/web-audio-api/#dom-audioparam-cancelandholdattime |
131 | | WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioParam>> AudioParam::cancel_and_hold_at_time(double cancel_time) |
132 | 0 | { |
133 | 0 | (void)cancel_time; |
134 | 0 | return WebIDL::NotSupportedError::create(realm(), "FIXME: Implement AudioParam::cancel_and_hold_at_time"_string); |
135 | 0 | } |
136 | | |
137 | | void AudioParam::initialize(JS::Realm& realm) |
138 | 0 | { |
139 | 0 | Base::initialize(realm); |
140 | 0 | WEB_SET_PROTOTYPE_FOR_INTERFACE(AudioParam); |
141 | 0 | } |
142 | | |
143 | | void AudioParam::visit_edges(Cell::Visitor& visitor) |
144 | 0 | { |
145 | 0 | Base::visit_edges(visitor); |
146 | 0 | } |
147 | | |
148 | | } |