audio_stream_player_internal.h 4.5 KB

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