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