1 /*************************************************************************/
2 /*  event_player.h                                                       */
3 /*************************************************************************/
4 /*                       This file is part of:                           */
5 /*                           GODOT ENGINE                                */
6 /*                      https://godotengine.org                          */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */
9 /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */
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 EVENT_PLAYER_H
31 #define EVENT_PLAYER_H
32 
33 #include "scene/main/node.h"
34 #include "scene/resources/event_stream.h"
35 class EventPlayer : public Node {
36 
37 	OBJ_TYPE(EventPlayer, Node);
38 
39 	enum {
40 		MAX_CHANNELS = 256
41 	};
42 
43 	Ref<EventStreamPlayback> playback;
44 	Ref<EventStream> stream;
45 	bool paused;
46 	bool autoplay;
47 	bool loops;
48 	float volume;
49 
50 	float tempo_scale;
51 	float pitch_scale;
52 
53 	float channel_volume[MAX_CHANNELS];
54 	bool _play;
55 	void _set_play(bool p_play);
56 	bool _get_play() const;
57 
58 protected:
59 	void _notification(int p_what);
60 
61 	static void _bind_methods();
62 
63 public:
64 	void set_stream(const Ref<EventStream> &p_stream);
65 	Ref<EventStream> get_stream() const;
66 
67 	void play();
68 	void stop();
69 	bool is_playing() const;
70 
71 	void set_paused(bool p_paused);
72 	bool is_paused() const;
73 
74 	void set_loop(bool p_enable);
75 	bool has_loop() const;
76 
77 	void set_volume(float p_vol);
78 	float get_volume() const;
79 
80 	void set_volume_db(float p_db);
81 	float get_volume_db() const;
82 
83 	void set_pitch_scale(float p_scale);
84 	float get_pitch_scale() const;
85 
86 	void set_tempo_scale(float p_scale);
87 	float get_tempo_scale() const;
88 
89 	String get_stream_name() const;
90 
91 	int get_loop_count() const;
92 
93 	float get_pos() const;
94 	void seek_pos(float p_time);
95 	float get_length() const;
96 	void set_autoplay(bool p_vol);
97 	bool has_autoplay() const;
98 
99 	void set_channel_volume(int p_channel, float p_volume);
100 	float get_channel_volume(int p_channel) const;
101 
102 	float get_channel_last_note_time(int p_channel) const;
103 
104 	EventPlayer();
105 	~EventPlayer();
106 };
107 
108 #endif // EVENT_PLAYER_H
109