event_stream.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*************************************************************************/
  2. /* event_stream.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef EVENT_STREAM_H
  30. #define EVENT_STREAM_H
  31. #include "resource.h"
  32. #include "servers/audio_server.h"
  33. class EventStreamPlayback : public Reference {
  34. OBJ_TYPE(EventStreamPlayback,Reference);
  35. class InternalEventStream : public AudioServer::EventStream {
  36. public:
  37. AudioMixer *_get_mixer(){ return get_mixer(); }
  38. EventStreamPlayback *playback;
  39. virtual void update(uint64_t p_usec) {
  40. playback->_update(get_mixer(),p_usec);
  41. }
  42. virtual ~InternalEventStream() {}
  43. };
  44. InternalEventStream estream;
  45. RID stream;
  46. bool playing;
  47. protected:
  48. virtual AudioMixer* _get_mixer() { return estream._get_mixer(); }
  49. virtual Error _play()=0;
  50. virtual bool _update(AudioMixer* p_mixer, uint64_t p_usec)=0;
  51. virtual void _stop()=0;
  52. public:
  53. virtual Error play();
  54. virtual void stop();
  55. virtual bool is_playing() const;
  56. virtual void set_paused(bool p_paused)=0;
  57. virtual bool is_paused() const=0;
  58. virtual void set_loop(bool p_loop)=0;
  59. virtual bool is_loop_enabled() const=0;
  60. virtual int get_loop_count() const=0;
  61. virtual float get_pos() const=0;
  62. virtual void seek_pos(float p_time)=0;
  63. virtual void set_volume(float p_vol)=0;
  64. virtual float get_volume() const=0;
  65. virtual void set_pitch_scale(float p_pitch_scale)=0;
  66. virtual float get_pitch_scale() const=0;
  67. virtual void set_tempo_scale(float p_tempo_scale)=0;
  68. virtual float get_tempo_scale() const=0;
  69. virtual void set_channel_volume(int p_channel,float p_volume)=0;
  70. virtual float get_channel_volume(int p_channel) const=0;
  71. virtual float get_last_note_time(int p_channel) const=0;
  72. EventStreamPlayback();
  73. ~EventStreamPlayback();
  74. };
  75. class EventStream : public Resource {
  76. OBJ_TYPE(EventStream,Resource);
  77. OBJ_SAVE_TYPE( EventStream ); //children are all saved as EventStream, so they can be exchanged
  78. public:
  79. virtual Ref<EventStreamPlayback> instance_playback()=0;
  80. virtual String get_stream_name() const=0;
  81. virtual float get_length() const=0;
  82. virtual int get_channel_count() const=0;
  83. EventStream();
  84. };
  85. #endif // EVENT_STREAM_H