1 /*************************************************************************/
2 /*  sound_player_2d.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 SOUND_PLAYER_2D_H
31 #define SOUND_PLAYER_2D_H
32 
33 #include "scene/2d/node_2d.h"
34 #include "scene/main/viewport.h"
35 #include "scene/resources/sample_library.h"
36 #include "servers/spatial_sound_2d_server.h"
37 
38 class SoundPlayer2D : public Node2D {
39 
40 	OBJ_TYPE(SoundPlayer2D, Node2D);
41 
42 public:
43 	enum Param {
44 
45 		PARAM_VOLUME_DB = SpatialSound2DServer::SOURCE_PARAM_VOLUME_DB,
46 		PARAM_PITCH_SCALE = SpatialSound2DServer::SOURCE_PARAM_PITCH_SCALE,
47 		PARAM_ATTENUATION_MIN_DISTANCE = SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MIN_DISTANCE,
48 		PARAM_ATTENUATION_MAX_DISTANCE = SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_MAX_DISTANCE,
49 		PARAM_ATTENUATION_DISTANCE_EXP = SpatialSound2DServer::SOURCE_PARAM_ATTENUATION_DISTANCE_EXP,
50 		PARAM_MAX = SpatialSound2DServer::SOURCE_PARAM_MAX
51 	};
52 
53 private:
54 	float params[PARAM_MAX];
55 	RID source_rid;
56 
57 protected:
get_source_rid()58 	_FORCE_INLINE_ RID get_source_rid() const { return source_rid; }
59 
60 	void _notification(int p_what);
61 
62 	static void _bind_methods();
63 
64 public:
65 	void set_param(Param p_param, float p_value);
66 	float get_param(Param p_param) const;
67 
68 	SoundPlayer2D();
69 	~SoundPlayer2D();
70 };
71 
72 VARIANT_ENUM_CAST(SoundPlayer2D::Param);
73 
74 #endif // SOUND_PLAYER_2D_H
75