/* * Copyright (c) 2024, Bar Yemini * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::WebAudio { // https://webaudio.github.io/web-audio-api/#AudioBufferSourceOptions struct AudioBufferSourceOptions { JS::GCPtr buffer; float detune { 0 }; bool loop { false }; double loop_end { 0 }; double loop_start { 0 }; float playback_rate { 1 }; }; // https://webaudio.github.io/web-audio-api/#AudioBufferSourceNode class AudioBufferSourceNode : public AudioScheduledSourceNode { WEB_PLATFORM_OBJECT(AudioBufferSourceNode, AudioScheduledSourceNode); JS_DECLARE_ALLOCATOR(AudioBufferSourceNode); 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& = {}); protected: AudioBufferSourceNode(JS::Realm&, JS::NonnullGCPtr, AudioBufferSourceOptions const& = {}); 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 }; }; }