audio_stream_player.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**************************************************************************/
  2. /* audio_stream_player.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef AUDIO_STREAM_PLAYER_H
  31. #define AUDIO_STREAM_PLAYER_H
  32. #include "scene/main/node.h"
  33. #include "servers/audio_server.h"
  34. struct AudioFrame;
  35. class AudioStream;
  36. class AudioStreamPlayback;
  37. class AudioStreamPlayerInternal;
  38. class AudioStreamPlayer : public Node {
  39. GDCLASS(AudioStreamPlayer, Node);
  40. public:
  41. enum MixTarget {
  42. MIX_TARGET_STEREO,
  43. MIX_TARGET_SURROUND,
  44. MIX_TARGET_CENTER
  45. };
  46. private:
  47. AudioStreamPlayerInternal *internal = nullptr;
  48. MixTarget mix_target = MIX_TARGET_STEREO;
  49. void _set_playing(bool p_enable);
  50. bool _is_active() const;
  51. Vector<AudioFrame> _get_volume_vector();
  52. protected:
  53. void _validate_property(PropertyInfo &p_property) const;
  54. void _notification(int p_what);
  55. static void _bind_methods();
  56. bool _set(const StringName &p_name, const Variant &p_value);
  57. bool _get(const StringName &p_name, Variant &r_ret) const;
  58. void _get_property_list(List<PropertyInfo> *p_list) const;
  59. #ifndef DISABLE_DEPRECATED
  60. bool _is_autoplay_enabled_bind_compat_86907();
  61. static void _bind_compatibility_methods();
  62. #endif // DISABLE_DEPRECATED
  63. public:
  64. void set_stream(Ref<AudioStream> p_stream);
  65. Ref<AudioStream> get_stream() const;
  66. void set_volume_db(float p_volume);
  67. float get_volume_db() const;
  68. void set_pitch_scale(float p_pitch_scale);
  69. float get_pitch_scale() const;
  70. void set_max_polyphony(int p_max_polyphony);
  71. int get_max_polyphony() const;
  72. void play(float p_from_pos = 0.0);
  73. void seek(float p_seconds);
  74. void stop();
  75. bool is_playing() const;
  76. float get_playback_position();
  77. void set_bus(const StringName &p_bus);
  78. StringName get_bus() const;
  79. void set_autoplay(bool p_enable);
  80. bool is_autoplay_enabled() const;
  81. void set_mix_target(MixTarget p_target);
  82. MixTarget get_mix_target() const;
  83. void set_stream_paused(bool p_pause);
  84. bool get_stream_paused() const;
  85. bool has_stream_playback();
  86. Ref<AudioStreamPlayback> get_stream_playback();
  87. AudioServer::PlaybackType get_playback_type() const;
  88. void set_playback_type(AudioServer::PlaybackType p_playback_type);
  89. AudioStreamPlayer();
  90. ~AudioStreamPlayer();
  91. };
  92. VARIANT_ENUM_CAST(AudioStreamPlayer::MixTarget)
  93. #endif // AUDIO_STREAM_PLAYER_H