svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r22717:22875
[blender.git] / source / gameengine / Ketsji / KX_SoundActuator.h
1 /**
2  * KX_SoundActuator.h
3  *
4  * $Id$
5  *
6  * ***** BEGIN GPL LICENSE BLOCK *****
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  *
22  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23  * All rights reserved.
24  *
25  * The Original Code is: all of this file.
26  *
27  * Contributor(s): none yet.
28  *
29  * ***** END GPL LICENSE BLOCK *****
30  */
31
32 #ifndef __KX_SOUNDACTUATOR
33 #define __KX_SOUNDACTUATOR
34
35 #include "SCA_IActuator.h"
36
37 #include "AUD_C-API.h"
38 #include "BKE_sound.h"
39
40 typedef struct KX_3DSoundSettings
41 {
42         float min_gain;
43         float max_gain;
44         float reference_distance;
45         float max_distance;
46         float rolloff_factor;
47         float cone_inner_angle;
48         float cone_outer_angle;
49         float cone_outer_gain;
50 } KX_3DSoundSettings;
51
52 class KX_SoundActuator : public SCA_IActuator
53 {
54         Py_Header;
55         bool                                    m_isplaying;
56         AUD_Sound*                              m_sound;
57         float                                   m_volume;
58         float                                   m_pitch;
59         bool                                    m_is3d;
60         KX_3DSoundSettings              m_3d;
61         AUD_Handle*                             m_handle;
62
63         void play();
64
65 public:
66
67         enum KX_SOUNDACT_TYPE
68         {
69                         KX_SOUNDACT_NODEF = 0,
70                         KX_SOUNDACT_PLAYSTOP,
71                         KX_SOUNDACT_PLAYEND,
72                         KX_SOUNDACT_LOOPSTOP,
73                         KX_SOUNDACT_LOOPEND,
74                         KX_SOUNDACT_LOOPBIDIRECTIONAL,
75                         KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,
76                         KX_SOUNDACT_MAX
77         };
78
79         KX_SOUNDACT_TYPE                m_type;
80
81         KX_SoundActuator(SCA_IObject* gameobj,
82                                          AUD_Sound* sound,
83                                          float volume,
84                                          float pitch,
85                                          bool is3d,
86                                          KX_3DSoundSettings settings,
87                                          KX_SOUNDACT_TYPE type);
88
89         ~KX_SoundActuator();
90
91         virtual bool Update(double curtime, bool frame);
92
93         CValue* GetReplica();
94         void ProcessReplica();
95
96         /* -------------------------------------------------------------------- */
97         /* Python interface --------------------------------------------------- */
98         /* -------------------------------------------------------------------- */
99
100         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, startSound);
101         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound);
102         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound);
103
104         static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
105         static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
106         static int pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
107         static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
108
109         static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
110         static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
111         static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
112         static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
113 };
114
115 #endif //__KX_SOUNDACTUATOR
116