svn merge -r39781:39792 https://svn.blender.org/svnroot/bf-blender/trunk/blender...
[blender-staging.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 #  include "AUD_Reference.h"
42 #  include "AUD_IFactory.h"
43 #  include "AUD_IHandle.h"
44 #endif
45
46 #include "BKE_sound.h"
47
48 typedef struct KX_3DSoundSettings
49 {
50         float min_gain;
51         float max_gain;
52         float reference_distance;
53         float max_distance;
54         float rolloff_factor;
55         float cone_inner_angle;
56         float cone_outer_angle;
57         float cone_outer_gain;
58 } KX_3DSoundSettings;
59
60 class KX_SoundActuator : public SCA_IActuator
61 {
62         Py_Header;
63         bool                                    m_isplaying;
64         AUD_Reference<AUD_IFactory>                             m_sound;
65         float                                   m_volume;
66         float                                   m_pitch;
67         bool                                    m_is3d;
68         KX_3DSoundSettings              m_3d;
69         AUD_Reference<AUD_IHandle>                              m_handle;
70
71         void play();
72
73 public:
74
75         enum KX_SOUNDACT_TYPE
76         {
77                         KX_SOUNDACT_NODEF = 0,
78                         KX_SOUNDACT_PLAYSTOP,
79                         KX_SOUNDACT_PLAYEND,
80                         KX_SOUNDACT_LOOPSTOP,
81                         KX_SOUNDACT_LOOPEND,
82                         KX_SOUNDACT_LOOPBIDIRECTIONAL,
83                         KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,
84                         KX_SOUNDACT_MAX
85         };
86
87         KX_SOUNDACT_TYPE                m_type;
88
89         KX_SoundActuator(SCA_IObject* gameobj,
90                                          AUD_Reference<AUD_IFactory> sound,
91                                          float volume,
92                                          float pitch,
93                                          bool is3d,
94                                          KX_3DSoundSettings settings,
95                                          KX_SOUNDACT_TYPE type);
96
97         ~KX_SoundActuator();
98
99         virtual bool Update(double curtime, bool frame);
100
101         CValue* GetReplica();
102         void ProcessReplica();
103
104 #ifdef WITH_PYTHON
105
106         /* -------------------------------------------------------------------- */
107         /* Python interface --------------------------------------------------- */
108         /* -------------------------------------------------------------------- */
109
110         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, startSound);
111         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound);
112         KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound);
113
114         static int pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
115         static int pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
116         static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
117         static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
118         static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
119         static int pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
120
121         static PyObject* pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
122         static PyObject* pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
123         static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
124         static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
125         static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
126         static PyObject* pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
127
128 #endif // WITH_PYTHON
129
130 };
131
132 #endif //__KX_SOUNDACTUATOR
133