ladybird/Userland/Libraries/LibWeb/WebAudio/OscillatorNode.h
Shannon Booth 099c9e4a7e LibWeb: Implement OscillatorNode.type
This is a simple getter and setter of the OscillatorType enum, with
error checking to not allow 'custom', as that should only be changed
through 'setPeriodicWave()'.
2024-05-04 14:01:38 +02:00

49 lines
1.7 KiB
C++

/*
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Bindings/OscillatorNodePrototype.h>
#include <LibWeb/WebAudio/AudioScheduledSourceNode.h>
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<PeriodicWave> 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<JS::NonnullGCPtr<OscillatorNode>> create(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
static WebIDL::ExceptionOr<JS::NonnullGCPtr<OscillatorNode>> construct_impl(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
Bindings::OscillatorType type() const;
WebIDL::ExceptionOr<void> set_type(Bindings::OscillatorType);
protected:
OscillatorNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>, OscillatorOptions const& = {});
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
private:
static WebIDL::ExceptionOr<void> verify_valid_type(JS::Realm&, Bindings::OscillatorType);
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
Bindings::OscillatorType m_type { Bindings::OscillatorType::Sine };
};
}