BaseAudioContext.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <LibWeb/Bindings/BaseAudioContextPrototype.h>
  8. #include <LibWeb/DOM/EventTarget.h>
  9. namespace Web::WebAudio {
  10. // https://webaudio.github.io/web-audio-api/#BaseAudioContext
  11. class BaseAudioContext : public DOM::EventTarget {
  12. WEB_PLATFORM_OBJECT(BaseAudioContext, DOM::EventTarget);
  13. public:
  14. virtual ~BaseAudioContext() override;
  15. float sample_rate() const { return m_sample_rate; }
  16. double current_time() const { return m_current_time; }
  17. Bindings::AudioContextState state() const { return m_control_thread_state; }
  18. void set_onstatechange(WebIDL::CallbackType*);
  19. WebIDL::CallbackType* onstatechange();
  20. void set_sample_rate(float sample_rate) { m_sample_rate = sample_rate; }
  21. void set_control_state(Bindings::AudioContextState state) { m_control_thread_state = state; }
  22. void set_rendering_state(Bindings::AudioContextState state) { m_rendering_thread_state = state; }
  23. protected:
  24. explicit BaseAudioContext(JS::Realm&);
  25. virtual void initialize(JS::Realm&) override;
  26. private:
  27. float m_sample_rate { 0 };
  28. double m_current_time { 0 };
  29. Bindings::AudioContextState m_control_thread_state = Bindings::AudioContextState::Suspended;
  30. Bindings::AudioContextState m_rendering_thread_state = Bindings::AudioContextState::Suspended;
  31. };
  32. }