2.50:
[blender.git] / source / gameengine / Ketsji / KX_SoundActuator.cpp
1 /**
2  * KX_SoundActuator.cpp
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
33 #include "KX_SoundActuator.h"
34 #include "SND_SoundObject.h"
35 #include "KX_GameObject.h"
36 #include "SND_SoundObject.h"
37 #include "SND_Scene.h" // needed for replication
38 #include "KX_PyMath.h" // needed for PyObjectFrom()
39 #include <iostream>
40
41 #ifdef HAVE_CONFIG_H
42 #include <config.h>
43 #endif
44
45 /* ------------------------------------------------------------------------- */
46 /* Native functions                                                          */
47 /* ------------------------------------------------------------------------- */
48 KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
49                                                                    SND_SoundObject* sndobj,
50                                                                    SND_Scene*   sndscene,
51                                                                    KX_SOUNDACT_TYPE type,
52                                                                    short start,
53                                                                    short end,
54                                                                    PyTypeObject* T)
55                                                                    : SCA_IActuator(gameobj,T)
56 {
57         m_soundObject = sndobj;
58         m_soundScene = sndscene;
59         m_type = type;
60         m_lastEvent = true;
61         m_isplaying = false;
62         m_startFrame = start;
63         m_endFrame = end;
64         m_pino = false;
65         
66
67 }
68
69
70
71 KX_SoundActuator::~KX_SoundActuator()
72 {
73         if (m_soundObject)
74         {
75                 m_soundScene->RemoveActiveObject(m_soundObject);
76                 m_soundScene->DeleteObject(m_soundObject);
77         }
78 }
79
80
81
82 CValue* KX_SoundActuator::GetReplica()
83 {
84         KX_SoundActuator* replica = new KX_SoundActuator(*this);
85         replica->ProcessReplica();
86         return replica;
87 };
88
89 void KX_SoundActuator::ProcessReplica()
90 {
91         SCA_IActuator::ProcessReplica();
92         if (m_soundObject)
93         {
94             SND_SoundObject* soundobj = new SND_SoundObject(*m_soundObject);
95                 setSoundObject(soundobj);
96                 m_soundScene->AddObject(soundobj);
97         }
98 }       
99
100 bool KX_SoundActuator::Update(double curtime, bool frame)
101 {
102         if (!frame)
103                 return true;
104         bool result = false;
105
106         // do nothing on negative events, otherwise sounds are played twice!
107         bool bNegativeEvent = IsNegativeEvent();
108
109         RemoveAllEvents();
110
111         if (!m_soundObject)
112                 return false;
113
114         // actual audio device playing state
115         bool isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED) ? true : false;
116
117         if (m_pino)
118         {
119                 bNegativeEvent = true;
120                 m_pino = false;
121         }
122
123         if (bNegativeEvent)
124         {       
125                 // here must be a check if it is still playing
126                 if (m_isplaying && isplaying) 
127                 {
128                         switch (m_type)
129                         {
130                         case KX_SOUNDACT_PLAYSTOP:
131                         case KX_SOUNDACT_LOOPSTOP:
132                         case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
133                                 {
134                                         m_soundScene->RemoveActiveObject(m_soundObject);
135                                         break;
136                                 }
137                         case KX_SOUNDACT_PLAYEND:
138                                 {
139                                         m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED);
140                                         break;
141                                 }
142                         case KX_SOUNDACT_LOOPEND:
143                         case KX_SOUNDACT_LOOPBIDIRECTIONAL:
144                                 {
145                                         m_soundObject->SetLoopMode(SND_LOOP_OFF);
146                                         m_soundObject->SetPlaystate(SND_MUST_STOP_WHEN_FINISHED);
147                                         break;
148                                 }
149                         default:
150                                 // implement me !!
151                                 break;
152                         }
153                 }
154                 // remember that we tried to stop the actuator
155                 m_isplaying = false;
156         }
157         else
158         {
159                 if (!m_isplaying)
160                 {
161                         switch (m_type)
162                         {
163                         case KX_SOUNDACT_LOOPBIDIRECTIONAL:
164                         case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
165                                 {
166                                         m_soundObject->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
167                                         m_soundScene->AddActiveObject(m_soundObject, curtime);
168                                         m_isplaying = true;
169                                         result = true;
170                                         break;
171                                 }
172                         case KX_SOUNDACT_LOOPEND:
173                         case KX_SOUNDACT_LOOPSTOP:
174                                 {
175                                         m_soundObject->SetLoopMode(SND_LOOP_NORMAL);
176                                         m_soundScene->AddActiveObject(m_soundObject, curtime);
177                                         m_isplaying = true;
178                                         result = true;
179                                         break;
180                                 }
181                         case KX_SOUNDACT_PLAYSTOP:
182                         case KX_SOUNDACT_PLAYEND:
183                                 {
184                                         m_soundObject->SetLoopMode(SND_LOOP_OFF);
185                                         m_soundScene->AddActiveObject(m_soundObject, curtime);
186                                         m_isplaying = true;
187                                         result = true;
188                                         break;
189                                 }
190                         default:
191                                 // implement me !!
192                                 break;
193                         }
194                 }
195         }
196         // verify that the sound is still playing
197         isplaying = (m_soundObject->GetPlaystate() != SND_STOPPED) ? true : false;
198
199         if (isplaying)
200         {
201                 m_soundObject->SetPosition(((KX_GameObject*)this->GetParent())->NodeGetWorldPosition());
202                 m_soundObject->SetVelocity(((KX_GameObject*)this->GetParent())->GetLinearVelocity());
203                 m_soundObject->SetOrientation(((KX_GameObject*)this->GetParent())->NodeGetWorldOrientation());
204                 result = true;
205         }
206         else
207         {
208                 m_isplaying = false;
209                 result = false;
210         }
211         /*
212         if (result && (m_soundObject->IsLifeSpanOver(curtime)) && ((m_type == KX_SOUNDACT_PLAYEND) || (m_type == KX_SOUNDACT_PLAYSTOP)))
213         {
214                 m_pino = true;
215         }
216         */
217         return result;
218 }
219
220
221
222 void KX_SoundActuator::setSoundObject(class SND_SoundObject* soundobject)
223 {
224         m_soundObject = soundobject;
225 }
226
227
228
229 /* ------------------------------------------------------------------------- */
230 /* Python functions                                                          */
231 /* ------------------------------------------------------------------------- */
232
233
234
235 /* Integration hooks ------------------------------------------------------- */
236 PyTypeObject KX_SoundActuator::Type = {
237 #if (PY_VERSION_HEX >= 0x02060000)
238         PyVarObject_HEAD_INIT(NULL, 0)
239 #else
240         /* python 2.5 and below */
241         PyObject_HEAD_INIT( NULL )  /* required py macro */
242         0,                          /* ob_size */
243 #endif
244                 "KX_SoundActuator",
245                 sizeof(PyObjectPlus_Proxy),
246                 0,
247                 py_base_dealloc,
248                 0,
249                 0,
250                 0,
251                 0,
252                 py_base_repr,
253                 0,0,0,0,0,0,
254                 py_base_getattro,
255                 py_base_setattro,
256                 0,0,0,0,0,0,0,0,0,
257                 Methods
258 };
259
260
261
262 PyParentObject KX_SoundActuator::Parents[] = {
263         &KX_SoundActuator::Type,
264                 &SCA_IActuator::Type,
265                 &SCA_ILogicBrick::Type,
266                 &CValue::Type,
267                 NULL
268 };
269
270
271
272 PyMethodDef KX_SoundActuator::Methods[] = {
273         // Deprecated ----->
274         {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL},
275         {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_NOARGS,NULL},
276         {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL},
277         {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_NOARGS,NULL},
278         {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL},
279         {"getPitch",(PyCFunction) KX_SoundActuator::sPyGetPitch,METH_NOARGS,NULL},
280         {"setRollOffFactor",(PyCFunction) KX_SoundActuator::sPySetRollOffFactor,METH_VARARGS,NULL},
281         {"getRollOffFactor",(PyCFunction) KX_SoundActuator::sPyGetRollOffFactor,METH_NOARGS,NULL},
282         {"setLooping",(PyCFunction) KX_SoundActuator::sPySetLooping,METH_VARARGS,NULL},
283         {"getLooping",(PyCFunction) KX_SoundActuator::sPyGetLooping,METH_NOARGS,NULL},
284         {"setPosition",(PyCFunction) KX_SoundActuator::sPySetPosition,METH_VARARGS,NULL},
285         {"setVelocity",(PyCFunction) KX_SoundActuator::sPySetVelocity,METH_VARARGS,NULL},
286         {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL},
287         {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL},
288         {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_NOARGS,NULL},
289         // <-----
290
291         KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound),
292         KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound),
293         KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound),
294         {NULL,NULL,NULL,NULL} //Sentinel
295 };
296
297 PyAttributeDef KX_SoundActuator::Attributes[] = {
298         KX_PYATTRIBUTE_RW_FUNCTION("fileName", KX_SoundActuator, pyattr_get_filename, pyattr_set_filename),
299         KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
300         KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch),
301         KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor),
302         KX_PYATTRIBUTE_RW_FUNCTION("looping", KX_SoundActuator, pyattr_get_looping, pyattr_set_looping),
303         KX_PYATTRIBUTE_RW_FUNCTION("position", KX_SoundActuator, pyattr_get_position, pyattr_set_position),
304         KX_PYATTRIBUTE_RW_FUNCTION("velocity", KX_SoundActuator, pyattr_get_velocity, pyattr_set_velocity),
305         KX_PYATTRIBUTE_RW_FUNCTION("orientation", KX_SoundActuator, pyattr_get_orientation, pyattr_set_orientation),
306         KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type),
307         { NULL }        //Sentinel
308 };
309
310 /* Methods ----------------------------------------------------------------- */
311 KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, 
312 "startSound()\n"
313 "\tStarts the sound.\n")
314 {
315         if (m_soundObject)
316                 // This has no effect if the actuator is not active.
317                 // To start the sound you must activate the actuator. 
318                 // This function is to restart the sound.
319                 m_soundObject->StartSound();    
320         Py_RETURN_NONE;
321 }         
322
323 KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound,
324 "pauseSound()\n"
325 "\tPauses the sound.\n")
326 {
327         if (m_soundObject)
328                 // unfortunately, openal does not implement pause correctly, it is equivalent to a stop
329                 m_soundObject->PauseSound();    
330         Py_RETURN_NONE;
331
332
333 KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound,
334 "stopSound()\n"
335 "\tStops the sound.\n")
336 {
337         if (m_soundObject)
338                 m_soundObject->StopSound();     
339         Py_RETURN_NONE;
340 }
341
342 /* Atribute setting and getting -------------------------------------------- */
343 PyObject* KX_SoundActuator::py_getattro(PyObject *attr)
344 {
345         py_getattro_up(SCA_IActuator);
346 }
347
348 PyObject* KX_SoundActuator::py_getattro_dict() {
349         py_getattro_dict_up(SCA_IActuator);
350 }
351
352 int KX_SoundActuator::py_setattro(PyObject *attr, PyObject* value) {
353         py_setattro_up(SCA_IActuator);
354 }
355
356 PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
357 {
358         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
359         if (!actuator->m_soundObject)
360         {
361                 return PyString_FromString("");
362         }
363         STR_String objectname = actuator->m_soundObject->GetObjectName();
364         char* name = objectname.Ptr();
365         
366         if (!name) {
367                 PyErr_SetString(PyExc_RuntimeError, "value = actuator.fileName: KX_SoundActuator, unable to get sound fileName");
368                 return NULL;
369         } else
370                 return PyString_FromString(name);
371 }
372
373 PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
374 {
375         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
376         float gain = (actuator->m_soundObject) ? actuator->m_soundObject->GetGain() : 1.0f;
377
378         PyObject* result = PyFloat_FromDouble(gain);
379         
380         return result;
381 }
382
383 PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
384 {
385         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
386         float pitch = (actuator->m_soundObject) ? actuator->m_soundObject->GetPitch() : 1.0;
387         PyObject* result = PyFloat_FromDouble(pitch);
388         
389         return result;
390 }
391
392 PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
393 {
394         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
395         float rollofffactor = (actuator->m_soundObject) ? actuator->m_soundObject->GetRollOffFactor() : 1.0;
396         PyObject* result = PyFloat_FromDouble(rollofffactor);
397         
398         return result;
399 }
400
401 PyObject* KX_SoundActuator::pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
402 {
403         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
404         int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF;
405         PyObject* result = PyInt_FromLong(looping);
406         
407         return result;
408 }
409
410 PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef) 
411 {
412         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
413         MT_Vector3 pos(0.0, 0.0, 0.0);
414
415         if (actuator->m_soundObject)
416                 pos = actuator->m_soundObject->GetPosition();
417
418         PyObject * result = PyObjectFrom(pos);
419         return result;
420 }
421
422 PyObject* KX_SoundActuator::pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
423 {
424         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
425         MT_Vector3 vel;
426
427         if (actuator->m_soundObject)
428                 vel = actuator->m_soundObject->GetVelocity();
429
430         PyObject * result = PyObjectFrom(vel);
431         return result;
432 }
433
434 PyObject* KX_SoundActuator::pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) 
435 {
436         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
437         MT_Matrix3x3 ori;
438
439         if (actuator->m_soundObject)
440                 ori = actuator->m_soundObject->GetOrientation();
441
442         PyObject * result = PyObjectFrom(ori);
443         return result;
444 }
445
446 int KX_SoundActuator::pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
447 {
448         char *soundName = NULL;
449         KX_SoundActuator * actuator = static_cast<KX_SoundActuator*> (self);
450         // void *soundPointer = NULL; /*unused*/
451         
452         if (!PyArg_Parse(value, "s", &soundName))
453                 return PY_SET_ATTR_FAIL;
454
455         if (actuator->m_soundObject) {
456                 actuator->m_soundObject->SetObjectName(soundName);
457         }
458         
459         return PY_SET_ATTR_SUCCESS;
460 }
461
462
463 int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
464 {
465         float gain = 1.0;
466         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
467         if (!PyArg_Parse(value, "f", &gain))
468                 return PY_SET_ATTR_FAIL;
469         
470         if (actuator->m_soundObject)
471                 actuator->m_soundObject->SetGain(gain);
472         
473         return PY_SET_ATTR_SUCCESS;
474 }         
475
476 int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
477 {
478         float pitch = 1.0;
479         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
480         if (!PyArg_Parse(value, "f", &pitch))
481                 return PY_SET_ATTR_FAIL;
482         
483         if (actuator->m_soundObject)
484                 actuator->m_soundObject->SetPitch(pitch);
485         
486         return PY_SET_ATTR_SUCCESS;
487 }         
488
489 int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
490 {
491         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
492         float rollofffactor = 1.0;
493         if (!PyArg_Parse(value, "f", &rollofffactor))
494                 return PY_SET_ATTR_FAIL;
495         
496         if (actuator->m_soundObject)
497                 actuator->m_soundObject->SetRollOffFactor(rollofffactor);
498
499         return PY_SET_ATTR_SUCCESS;
500 }         
501
502 int KX_SoundActuator::pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
503 {
504         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
505         int looping = 1;
506         if (!PyArg_Parse(value, "i", &looping))
507                 return PY_SET_ATTR_FAIL;
508         
509         if (actuator->m_soundObject)
510                 actuator->m_soundObject->SetLoopMode(looping);
511         
512         return PY_SET_ATTR_SUCCESS;
513 }         
514
515 int KX_SoundActuator::pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
516 {
517         float pos[3];
518
519         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
520
521         if (!PyArg_ParseTuple(value, "fff", &pos[0], &pos[1], &pos[2]))
522                 return PY_SET_ATTR_FAIL;
523         
524         if (actuator->m_soundObject)
525                 actuator->m_soundObject->SetPosition(MT_Vector3(pos));
526         
527         return PY_SET_ATTR_SUCCESS;
528 }         
529
530 int KX_SoundActuator::pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
531 {
532         float vel[3];
533         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
534
535
536         if (!PyArg_ParseTuple(value, "fff", &vel[0], &vel[1], &vel[2]))
537                 return PY_SET_ATTR_FAIL;
538         
539         if (actuator->m_soundObject)
540                 actuator->m_soundObject->SetVelocity(MT_Vector3(vel));
541         
542         return PY_SET_ATTR_SUCCESS;
543
544 }         
545
546 int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
547 {
548
549         MT_Matrix3x3 rot;
550         KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
551
552         /* if value is not a sequence PyOrientationTo makes an error */
553         if (!PyOrientationTo(value, rot, "actuator.orientation = value: KX_SoundActuator"))
554                 return PY_SET_ATTR_FAIL;
555         
556         /* Since not having m_soundObject didn't do anything in the old version,
557          * it probably should be kept that way  */
558         if (!actuator->m_soundObject)
559                 return PY_SET_ATTR_SUCCESS;
560         
561         actuator->m_soundObject->SetOrientation(rot);
562         return PY_SET_ATTR_SUCCESS;
563 }
564
565 // Deprecated ----->
566 PyObject* KX_SoundActuator::PySetFilename(PyObject* args)
567 {
568         char *soundName = NULL;
569         ShowDeprecationWarning("setFilename()", "the fileName property");
570         // void *soundPointer = NULL; /*unused*/
571         
572         if (!PyArg_ParseTuple(args, "s", &soundName))
573                 return NULL;
574
575         Py_RETURN_NONE;
576 }
577
578 PyObject* KX_SoundActuator::PyGetFilename()
579 {
580         ShowDeprecationWarning("getFilename()", "the fileName property");
581         if (!m_soundObject)
582         {
583                 return PyString_FromString("");
584         }
585         STR_String objectname = m_soundObject->GetObjectName();
586         char* name = objectname.Ptr();
587         
588         if (!name) {
589                 PyErr_SetString(PyExc_RuntimeError, "Unable to get sound fileName");
590                 return NULL;
591         } else
592                 return PyString_FromString(name);
593 }
594
595 PyObject* KX_SoundActuator::PySetGain(PyObject* args)
596 {
597         ShowDeprecationWarning("setGain()", "the volume property");
598         float gain = 1.0;
599         if (!PyArg_ParseTuple(args, "f:setGain", &gain))
600                 return NULL;
601         
602         if (m_soundObject)
603                 m_soundObject->SetGain(gain);
604         
605         Py_RETURN_NONE;
606 }         
607
608
609
610 PyObject* KX_SoundActuator::PyGetGain()
611 {
612         ShowDeprecationWarning("getGain()", "the volume property");
613         float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f;
614         PyObject* result = PyFloat_FromDouble(gain);
615         
616         return result;
617 }
618
619
620
621 PyObject* KX_SoundActuator::PySetPitch(PyObject* args)
622 {
623         ShowDeprecationWarning("setPitch()", "the pitch property");
624         float pitch = 1.0;
625         if (!PyArg_ParseTuple(args, "f:setPitch", &pitch))
626                 return NULL;
627         
628         if (m_soundObject)
629                 m_soundObject->SetPitch(pitch);
630         
631         Py_RETURN_NONE;
632 }         
633
634
635
636 PyObject* KX_SoundActuator::PyGetPitch()
637 {
638         ShowDeprecationWarning("getPitch()", "the pitch property");
639         float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0;
640         PyObject* result = PyFloat_FromDouble(pitch);
641         
642         return result;
643 }
644
645
646
647 PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* args)
648 {
649         ShowDeprecationWarning("setRollOffFactor()", "the rollOffFactor property");
650         float rollofffactor = 1.0;
651         if (!PyArg_ParseTuple(args, "f:setRollOffFactor", &rollofffactor))
652                 return NULL;
653         
654         if (m_soundObject)
655                 m_soundObject->SetRollOffFactor(rollofffactor);
656
657         Py_RETURN_NONE;
658 }         
659
660
661
662 PyObject* KX_SoundActuator::PyGetRollOffFactor()
663 {
664         ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property");
665         float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0;
666         PyObject* result = PyFloat_FromDouble(rollofffactor);
667         
668         return result;
669 }
670
671
672
673 PyObject* KX_SoundActuator::PySetLooping(PyObject* args)
674 {
675         ShowDeprecationWarning("setLooping()", "the looping property");
676         bool looping = 1;
677         if (!PyArg_ParseTuple(args, "i:setLooping", &looping))
678                 return NULL;
679         
680         if (m_soundObject)
681                 m_soundObject->SetLoopMode(looping);
682         
683         Py_RETURN_NONE;
684 }         
685
686
687
688 PyObject* KX_SoundActuator::PyGetLooping()
689 {
690         ShowDeprecationWarning("getLooping()", "the looping property");
691         int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF;
692         PyObject* result = PyInt_FromLong(looping);
693         
694         return result;
695 }
696
697
698
699 PyObject* KX_SoundActuator::PySetPosition(PyObject* args)
700 {
701         MT_Point3 pos;
702         ShowDeprecationWarning("setPosition()", "the position property");
703         pos[0] = 0.0;
704         pos[1] = 0.0;
705         pos[2] = 0.0;
706
707         if (!PyArg_ParseTuple(args, "fff:setPosition", &pos[0], &pos[1], &pos[2]))
708                 return NULL;
709         
710         if (m_soundObject)
711                 m_soundObject->SetPosition(pos);
712         
713         Py_RETURN_NONE;
714 }         
715
716
717
718 PyObject* KX_SoundActuator::PySetVelocity(PyObject* args)
719 {
720         MT_Vector3 vel;
721         ShowDeprecationWarning("setVelocity()", "the velocity property");
722         vel[0] = 0.0;
723         vel[1] = 0.0;
724         vel[2] = 0.0;
725
726         if (!PyArg_ParseTuple(args, "fff:setVelocity", &vel[0], &vel[1], &vel[2]))
727                 return NULL;
728         
729         if (m_soundObject)
730                 m_soundObject->SetVelocity(vel);
731         
732         Py_RETURN_NONE;
733 }         
734
735
736
737 PyObject* KX_SoundActuator::PySetOrientation(PyObject* args)
738 {
739         MT_Matrix3x3 ori;
740         ShowDeprecationWarning("setOrientation()", "the orientation property");
741         ori[0][0] = 1.0;
742         ori[0][1] = 0.0;
743         ori[0][2] = 0.0;
744         ori[1][0] = 0.0;
745         ori[1][1] = 1.0;
746         ori[1][2] = 0.0;
747         ori[2][0] = 0.0;
748         ori[2][1] = 0.0;
749         ori[2][2] = 1.0;
750
751         if (!PyArg_ParseTuple(args, "fffffffff:setOrientation", &ori[0][0], &ori[0][1], &ori[0][2], &ori[1][0], &ori[1][1], &ori[1][2], &ori[2][0], &ori[2][1], &ori[2][2]))
752                 return NULL;
753         
754         if (m_soundObject)
755                 m_soundObject->SetOrientation(ori);
756         
757         Py_RETURN_NONE;
758 }
759
760 PyObject* KX_SoundActuator::PySetType(PyObject* args)
761 {
762         int typeArg;
763         ShowDeprecationWarning("setType()", "the mode property");
764
765         if (!PyArg_ParseTuple(args, "i:setType", &typeArg)) {
766                 return NULL;
767         }
768
769         if ( (typeArg > KX_SOUNDACT_NODEF)
770           && (typeArg < KX_SOUNDACT_MAX) ) {
771                 m_type = (KX_SOUNDACT_TYPE) typeArg;
772         }
773
774         Py_RETURN_NONE;
775 }
776
777 PyObject* KX_SoundActuator::PyGetType()
778 {
779         ShowDeprecationWarning("getType()", "the mode property");
780         return PyInt_FromLong(m_type);
781 }
782 // <-----
783