diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp index 4304b2b701c..277935e718d 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.cpp @@ -6,20 +6,102 @@ #include #include +#include #include +#include #include namespace Web::WebAudio { JS_DEFINE_ALLOCATOR(AudioBufferSourceNode); -AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, JS::NonnullGCPtr context, AudioBufferSourceOptions const&) +AudioBufferSourceNode::AudioBufferSourceNode(JS::Realm& realm, JS::NonnullGCPtr context, AudioBufferSourceOptions const& options) : AudioScheduledSourceNode(realm, context) + , m_buffer(options.buffer) + , m_playback_rate(AudioParam::create(realm, options.playback_rate, NumericLimits::lowest(), NumericLimits::max(), Bindings::AutomationRate::ARate)) + , m_detune(AudioParam::create(realm, options.detune, NumericLimits::lowest(), NumericLimits::max(), Bindings::AutomationRate::ARate)) + , m_loop(options.loop) + , m_loop_start(options.loop_start) + , m_loop_end(options.loop_end) { } AudioBufferSourceNode::~AudioBufferSourceNode() = default; +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer +WebIDL::ExceptionOr AudioBufferSourceNode::set_buffer(JS::GCPtr buffer) +{ + m_buffer = buffer; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-buffer +JS::GCPtr AudioBufferSourceNode::buffer() const +{ + return m_buffer; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-playbackrate +JS::NonnullGCPtr AudioBufferSourceNode::playback_rate() const +{ + return m_playback_rate; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-detune +JS::NonnullGCPtr AudioBufferSourceNode::detune() const +{ + return m_detune; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loop +WebIDL::ExceptionOr AudioBufferSourceNode::set_loop(bool loop) +{ + m_loop = loop; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loop +bool AudioBufferSourceNode::loop() const +{ + return m_loop; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart +WebIDL::ExceptionOr AudioBufferSourceNode::set_loop_start(double loop_start) +{ + m_loop_start = loop_start; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopstart +double AudioBufferSourceNode::loop_start() const +{ + return m_loop_start; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend +WebIDL::ExceptionOr AudioBufferSourceNode::set_loop_end(double loop_end) +{ + m_loop_end = loop_end; + return {}; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-loopend +double AudioBufferSourceNode::loop_end() const +{ + return m_loop_end; +} + +// https://webaudio.github.io/web-audio-api/#dom-audiobuffersourcenode-start` +WebIDL::ExceptionOr AudioBufferSourceNode::start(Optional when, Optional offset, Optional duration) +{ + (void)when; + (void)offset; + (void)duration; + dbgln("FIXME: Implement AudioBufferSourceNode::start(when, offset, duration)"); + return {}; +} + WebIDL::ExceptionOr> AudioBufferSourceNode::create(JS::Realm& realm, JS::NonnullGCPtr context, AudioBufferSourceOptions const& options) { return construct_impl(realm, context, options); @@ -44,6 +126,9 @@ void AudioBufferSourceNode::initialize(JS::Realm& realm) void AudioBufferSourceNode::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); + visitor.visit(m_buffer); + visitor.visit(m_playback_rate); + visitor.visit(m_detune); } } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h index e87070f67b8..52dac427362 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h +++ b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.h @@ -7,6 +7,8 @@ #pragma once #include +#include +#include #include namespace Web::WebAudio { @@ -29,6 +31,19 @@ class AudioBufferSourceNode : public AudioScheduledSourceNode { public: virtual ~AudioBufferSourceNode() override; + WebIDL::ExceptionOr set_buffer(JS::GCPtr); + JS::GCPtr buffer() const; + JS::NonnullGCPtr playback_rate() const; + JS::NonnullGCPtr detune() const; + WebIDL::ExceptionOr set_loop(bool); + bool loop() const; + WebIDL::ExceptionOr set_loop_start(double); + double loop_start() const; + WebIDL::ExceptionOr set_loop_end(double); + double loop_end() const; + + WebIDL::ExceptionOr start(Optional, Optional, Optional); + static WebIDL::ExceptionOr> create(JS::Realm&, JS::NonnullGCPtr, AudioBufferSourceOptions const& = {}); static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::NonnullGCPtr, AudioBufferSourceOptions const& = {}); @@ -37,6 +52,14 @@ protected: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; + +private: + JS::GCPtr m_buffer; + JS::NonnullGCPtr m_playback_rate; + JS::NonnullGCPtr m_detune; + bool m_loop { false }; + double m_loop_start { 0.0 }; + double m_loop_end { 0.0 }; }; } diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.idl b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.idl index 0ee9b113510..067723df32f 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.idl +++ b/Userland/Libraries/LibWeb/WebAudio/AudioBufferSourceNode.idl @@ -16,11 +16,11 @@ dictionary AudioBufferSourceOptions { [Exposed=Window] interface AudioBufferSourceNode : AudioScheduledSourceNode { constructor(BaseAudioContext context, optional AudioBufferSourceOptions options = {}); - [FIXME] attribute AudioBuffer? buffer; - [FIXME] readonly attribute AudioParam playbackRate; - [FIXME] readonly attribute AudioParam detune; - [FIXME] attribute boolean loop; - [FIXME] attribute double loopStart; - [FIXME] attribute double loopEnd; - [FIXME] undefined start(optional double when = 0, optional double offset, optional double duration); + attribute AudioBuffer? buffer; + readonly attribute AudioParam playbackRate; + readonly attribute AudioParam detune; + attribute boolean loop; + attribute double loopStart; + attribute double loopEnd; + undefined start(optional double when = 0, optional double offset, optional double duration); };