audio_stream_player_internal.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**************************************************************************/
  2. /* audio_stream_player_internal.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_INTERNAL_H
  31. #define AUDIO_STREAM_PLAYER_INTERNAL_H
  32. #include "core/object/ref_counted.h"
  33. #include "core/templates/safe_refcount.h"
  34. #include "servers/audio_server.h"
  35. class AudioStream;
  36. class AudioStreamPlayback;
  37. class AudioSamplePlayback;
  38. class Node;
  39. class AudioStreamPlayerInternal : public Object {
  40. GDCLASS(AudioStreamPlayerInternal, Object);
  41. private:
  42. struct ParameterData {
  43. StringName path;
  44. Variant value;
  45. };
  46. static inline const String PARAM_PREFIX = "parameters/";
  47. Node *node = nullptr;
  48. Callable play_callable;
  49. Callable stop_callable;
  50. bool physical = false;
  51. AudioServer::PlaybackType playback_type = AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT;
  52. HashMap<StringName, ParameterData> playback_parameters;
  53. void _set_process(bool p_enabled);
  54. void _update_stream_parameters();
  55. _FORCE_INLINE_ bool _is_sample() {
  56. return (AudioServer::get_singleton()->get_default_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE && get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_DEFAULT) || get_playback_type() == AudioServer::PlaybackType::PLAYBACK_TYPE_SAMPLE;
  57. }
  58. public:
  59. Vector<Ref<AudioStreamPlayback>> stream_playbacks;
  60. Ref<AudioStream> stream;
  61. SafeFlag active;
  62. float pitch_scale = 1.0;
  63. float volume_db = 0.0;
  64. bool autoplay = false;
  65. StringName bus;
  66. int max_polyphony = 1;
  67. void process();
  68. void ensure_playback_limit();
  69. void notification(int p_what);
  70. void validate_property(PropertyInfo &p_property) const;
  71. bool set(const StringName &p_name, const Variant &p_value);
  72. bool get(const StringName &p_name, Variant &r_ret) const;
  73. void get_property_list(List<PropertyInfo> *p_list) const;
  74. void set_stream(Ref<AudioStream> p_stream);
  75. void set_pitch_scale(float p_pitch_scale);
  76. void set_max_polyphony(int p_max_polyphony);
  77. StringName get_bus() const;
  78. Ref<AudioStreamPlayback> play_basic();
  79. void seek(float p_seconds);
  80. void stop_basic();
  81. bool is_playing() const;
  82. float get_playback_position();
  83. void set_playing(bool p_enable);
  84. bool is_active() const;
  85. void set_stream_paused(bool p_pause);
  86. bool get_stream_paused() const;
  87. bool has_stream_playback();
  88. Ref<AudioStreamPlayback> get_stream_playback();
  89. void set_playback_type(AudioServer::PlaybackType p_playback_type);
  90. AudioServer::PlaybackType get_playback_type() const;
  91. AudioStreamPlayerInternal(Node *p_node, const Callable &p_play_callable, const Callable &p_stop_callable, bool p_physical);
  92. };
  93. #endif // AUDIO_STREAM_PLAYER_INTERNAL_H