AudioNode.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibJS/Forward.h>
  9. #include <LibWeb/Bindings/AudioNodePrototype.h>
  10. #include <LibWeb/Bindings/PlatformObject.h>
  11. #include <LibWeb/DOM/EventTarget.h>
  12. #include <LibWeb/WebIDL/Types.h>
  13. namespace Web::WebAudio {
  14. // https://webaudio.github.io/web-audio-api/#AudioNodeOptions
  15. struct AudioNodeOptions {
  16. Optional<WebIDL::UnsignedLong> channel_count;
  17. Bindings::ChannelCountMode channel_count_mode;
  18. Bindings::ChannelInterpretation channel_interpretation;
  19. };
  20. // https://webaudio.github.io/web-audio-api/#AudioNode
  21. class AudioNode : public DOM::EventTarget {
  22. WEB_PLATFORM_OBJECT(AudioNode, DOM::EventTarget);
  23. JS_DECLARE_ALLOCATOR(AudioNode);
  24. public:
  25. virtual ~AudioNode() override;
  26. WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output = 0, WebIDL::UnsignedLong input = 0);
  27. WebIDL::ExceptionOr<JS::NonnullGCPtr<AudioNode>> connect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output = 0);
  28. void disconnect();
  29. void disconnect(WebIDL::UnsignedLong output);
  30. void disconnect(JS::NonnullGCPtr<AudioNode> destination_node);
  31. void disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output);
  32. void disconnect(JS::NonnullGCPtr<AudioNode> destination_node, WebIDL::UnsignedLong output, WebIDL::UnsignedLong input);
  33. void disconnect(JS::NonnullGCPtr<AudioParam> destination_param);
  34. void disconnect(JS::NonnullGCPtr<AudioParam> destination_param, WebIDL::UnsignedLong output);
  35. // https://webaudio.github.io/web-audio-api/#dom-audionode-context
  36. JS::NonnullGCPtr<BaseAudioContext const> context() const
  37. {
  38. // The BaseAudioContext which owns this AudioNode.
  39. return m_context;
  40. }
  41. protected:
  42. AudioNode(JS::Realm&, JS::NonnullGCPtr<BaseAudioContext>);
  43. virtual void initialize(JS::Realm&) override;
  44. virtual void visit_edges(Cell::Visitor&) override;
  45. private:
  46. JS::NonnullGCPtr<BaseAudioContext> m_context;
  47. };
  48. }