diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 426ef8cac83..c9f8a03cc13 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -664,6 +664,7 @@ set(SOURCES WebAudio/AudioScheduledSourceNode.cpp WebAudio/BaseAudioContext.cpp WebAudio/OfflineAudioContext.cpp + WebAudio/OscillatorNode.cpp WebAudio/PeriodicWave.cpp WebDriver/Capabilities.cpp WebDriver/Client.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index f4f68b74309..6d88ee1b15a 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -686,6 +686,7 @@ class AudioParam; class AudioScheduledSourceNode; class BaseAudioContext; class OfflineAudioContext; +class OscillatorNode; class PeriodicWave; enum class AudioContextState; diff --git a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp new file mode 100644 index 00000000000..bff58dbcacd --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::WebAudio { + +JS_DEFINE_ALLOCATOR(OscillatorNode); + +OscillatorNode::~OscillatorNode() = default; + +WebIDL::ExceptionOr> OscillatorNode::create(JS::Realm& realm, JS::NonnullGCPtr context, OscillatorOptions const& options) +{ + return construct_impl(realm, context, options); +} + +// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-oscillatornode +WebIDL::ExceptionOr> OscillatorNode::construct_impl(JS::Realm& realm, JS::NonnullGCPtr, OscillatorOptions const&) +{ + return WebIDL::NotSupportedError::create(realm, "FIXME: Implement OscillatorNode::construct_impl"_fly_string); +} + +void OscillatorNode::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + WEB_SET_PROTOTYPE_FOR_INTERFACE(OscillatorNode); +} + +void OscillatorNode::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); +} + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h new file mode 100644 index 00000000000..9bfedcfd9fd --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::WebAudio { + +// https://webaudio.github.io/web-audio-api/#OscillatorOptions +struct OscillatorOptions : AudioNodeOptions { + Bindings::OscillatorType type { Bindings::OscillatorType::Sine }; + float frequency { 440 }; + float detune { 0 }; + JS::GCPtr periodic_wave; +}; + +// https://webaudio.github.io/web-audio-api/#OscillatorNode +class OscillatorNode : public AudioScheduledSourceNode { + WEB_PLATFORM_OBJECT(OscillatorNode, AudioScheduledSourceNode); + JS_DECLARE_ALLOCATOR(OscillatorNode); + +public: + virtual ~OscillatorNode() override; + + static WebIDL::ExceptionOr> create(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, JS::NonnullGCPtr, OscillatorOptions const& = {}); + +protected: + virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.idl b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.idl new file mode 100644 index 00000000000..e17f9bd670e --- /dev/null +++ b/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.idl @@ -0,0 +1,29 @@ +#import +#import + +// https://webaudio.github.io/web-audio-api/#enumdef-oscillatortype +enum OscillatorType { + "sine", + "square", + "sawtooth", + "triangle", + "custom" +}; + +// https://webaudio.github.io/web-audio-api/#OscillatorOptions +dictionary OscillatorOptions : AudioNodeOptions { + OscillatorType type = "sine"; + float frequency = 440; + float detune = 0; + PeriodicWave periodicWave; +}; + +// https://webaudio.github.io/web-audio-api/#OscillatorNode +[Exposed=Window] +interface OscillatorNode : AudioScheduledSourceNode { + constructor(BaseAudioContext context, optional OscillatorOptions options = {}); + // FIXME: attribute OscillatorType type; + // FIXME: readonly attribute AudioParam frequency; + // FIXME: readonly attribute AudioParam detune; + // FIXME: undefined setPeriodicWave(PeriodicWave periodicWave); +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index e5487c84f0f..b2be76c6aff 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -300,6 +300,7 @@ libweb_js_bindings(WebAudio/AudioParam) libweb_js_bindings(WebAudio/AudioScheduledSourceNode) libweb_js_bindings(WebAudio/BaseAudioContext) libweb_js_bindings(WebAudio/OfflineAudioContext) +libweb_js_bindings(WebAudio/OscillatorNode) libweb_js_bindings(WebAudio/PeriodicWave) libweb_js_bindings(WebGL/WebGLContextEvent) libweb_js_bindings(WebGL/WebGLRenderingContext)