BGE API cleanup: sound actuator.

This commit is contained in:
2009-04-09 20:40:12 +00:00
parent 4669fa48a8
commit 09a5ffdf07
4 changed files with 397 additions and 46 deletions

View File

@@ -1147,6 +1147,13 @@ PyObject* initGameLogic(KX_KetsjiEngine *engine, KX_Scene* scene) // quick hack
KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT); KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT);
KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER); KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND, KX_SoundActuator:: KX_SOUNDACT_LOOPEND);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
// Check for errors // Check for errors
if (PyErr_Occurred()) if (PyErr_Occurred())

View File

@@ -35,6 +35,7 @@
#include "KX_GameObject.h" #include "KX_GameObject.h"
#include "SND_SoundObject.h" #include "SND_SoundObject.h"
#include "SND_Scene.h" // needed for replication #include "SND_Scene.h" // needed for replication
#include "KX_PyMath.h" // needed for PyObjectFrom()
#include <iostream> #include <iostream>
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
@@ -264,11 +265,9 @@ PyParentObject KX_SoundActuator::Parents[] = {
PyMethodDef KX_SoundActuator::Methods[] = { PyMethodDef KX_SoundActuator::Methods[] = {
// Deprecated ----->
{"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL}, {"setFilename", (PyCFunction) KX_SoundActuator::sPySetFilename, METH_VARARGS,NULL},
{"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_VARARGS,NULL}, {"getFilename", (PyCFunction) KX_SoundActuator::sPyGetFilename, METH_VARARGS,NULL},
{"startSound",(PyCFunction) KX_SoundActuator::sPyStartSound,METH_VARARGS,NULL},
{"pauseSound",(PyCFunction) KX_SoundActuator::sPyPauseSound,METH_VARARGS,NULL},
{"stopSound",(PyCFunction) KX_SoundActuator::sPyStopSound,METH_VARARGS,NULL},
{"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL}, {"setGain",(PyCFunction) KX_SoundActuator::sPySetGain,METH_VARARGS,NULL},
{"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_VARARGS,NULL}, {"getGain",(PyCFunction) KX_SoundActuator::sPyGetGain,METH_VARARGS,NULL},
{"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL}, {"setPitch",(PyCFunction) KX_SoundActuator::sPySetPitch,METH_VARARGS,NULL},
@@ -282,23 +281,316 @@ PyMethodDef KX_SoundActuator::Methods[] = {
{"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL}, {"setOrientation",(PyCFunction) KX_SoundActuator::sPySetOrientation,METH_VARARGS,NULL},
{"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL}, {"setType",(PyCFunction) KX_SoundActuator::sPySetType,METH_VARARGS,NULL},
{"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_VARARGS,NULL}, {"getType",(PyCFunction) KX_SoundActuator::sPyGetType,METH_VARARGS,NULL},
// <-----
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound),
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound),
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound),
{NULL,NULL,NULL,NULL} //Sentinel {NULL,NULL,NULL,NULL} //Sentinel
}; };
PyAttributeDef KX_SoundActuator::Attributes[] = { PyAttributeDef KX_SoundActuator::Attributes[] = {
KX_PYATTRIBUTE_RW_FUNCTION("filename", KX_SoundActuator, pyattr_get_filename, pyattr_set_filename),
KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch),
KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor),
KX_PYATTRIBUTE_RW_FUNCTION("looping", KX_SoundActuator, pyattr_get_looping, pyattr_set_looping),
KX_PYATTRIBUTE_RW_FUNCTION("position", KX_SoundActuator, pyattr_get_position, pyattr_set_position),
KX_PYATTRIBUTE_RW_FUNCTION("velocity", KX_SoundActuator, pyattr_get_velocity, pyattr_set_velocity),
KX_PYATTRIBUTE_RW_FUNCTION("orientation", KX_SoundActuator, pyattr_get_orientation, pyattr_set_orientation),
KX_PYATTRIBUTE_ENUM_RW("type",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type),
{ NULL } //Sentinel { NULL } //Sentinel
}; };
/* Methods ----------------------------------------------------------------- */
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound,
"startSound()\n"
"\tStarts the sound.\n")
{
if (m_soundObject)
// This has no effect if the actuator is not active.
// To start the sound you must activate the actuator.
// This function is to restart the sound.
m_soundObject->StartSound();
Py_RETURN_NONE;
}
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound,
"pauseSound()\n"
"\tPauses the sound.\n")
{
if (m_soundObject)
// unfortunately, openal does not implement pause correctly, it is equivalent to a stop
m_soundObject->PauseSound();
Py_RETURN_NONE;
}
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound,
"stopSound()\n"
"\tStops the sound.\n")
{
if (m_soundObject)
m_soundObject->StopSound();
Py_RETURN_NONE;
}
/* Atribute setting and getting -------------------------------------------- */
PyObject* KX_SoundActuator::py_getattro(PyObject *attr) PyObject* KX_SoundActuator::py_getattro(PyObject *attr)
{ {
py_getattro_up(SCA_IActuator); py_getattro_up(SCA_IActuator);
} }
int KX_SoundActuator::py_setattro(PyObject *attr, PyObject* value) {
py_setattro_up(SCA_IActuator);
}
PyObject* KX_SoundActuator::pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!actuator->m_soundObject)
{
return PyString_FromString("");
}
STR_String objectname = actuator->m_soundObject->GetObjectName();
char* name = objectname.Ptr();
if (!name) {
PyErr_SetString(PyExc_RuntimeError, "Unable to get sound filename");
return NULL;
} else
return PyString_FromString(name);
}
PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float gain = (actuator->m_soundObject) ? actuator->m_soundObject->GetGain() : 1.0f;
PyObject* result = PyFloat_FromDouble(gain);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float pitch = (actuator->m_soundObject) ? actuator->m_soundObject->GetPitch() : 1.0;
PyObject* result = PyFloat_FromDouble(pitch);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float rollofffactor = (actuator->m_soundObject) ? actuator->m_soundObject->GetRollOffFactor() : 1.0;
PyObject* result = PyFloat_FromDouble(rollofffactor);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
int looping = (actuator->m_soundObject) ? actuator->m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF;
PyObject* result = PyInt_FromLong(looping);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_position(void * self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
MT_Vector3 pos(0.0, 0.0, 0.0);
if (actuator->m_soundObject)
pos = actuator->m_soundObject->GetPosition();
PyObject * result = PyObjectFrom(pos);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
MT_Vector3 vel;
if (actuator->m_soundObject)
vel = actuator->m_soundObject->GetVelocity();
PyObject * result = PyObjectFrom(vel);
return result;
}
PyObject* KX_SoundActuator::pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
MT_Matrix3x3 ori;
if (actuator->m_soundObject)
ori = actuator->m_soundObject->GetOrientation();
PyObject * result = PyObjectFrom(ori);
return result;
}
int KX_SoundActuator::pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
char *soundName = NULL;
KX_SoundActuator * actuator = static_cast<KX_SoundActuator*> (self);
// void *soundPointer = NULL; /*unused*/
if (!PyArg_Parse(value, "s", &soundName))
return 1;
if (actuator->m_soundObject) {
actuator->m_soundObject->SetObjectName(soundName);
}
return 0;
}
int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
float gain = 1.0;
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!PyArg_Parse(value, "f", &gain))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetGain(gain);
return 0;
}
int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
float pitch = 1.0;
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!PyArg_Parse(value, "f", &pitch))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetPitch(pitch);
return 0;
}
int KX_SoundActuator::pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
float rollofffactor = 1.0;
if (!PyArg_Parse(value, "f", &rollofffactor))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetRollOffFactor(rollofffactor);
return 0;
}
int KX_SoundActuator::pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
int looping = 1;
if (!PyArg_Parse(value, "i", &looping))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetLoopMode(looping);
return 0;
}
int KX_SoundActuator::pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
float pos[3];
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!PyArg_ParseTuple(value, "fff", &pos[0], &pos[1], &pos[2]))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetPosition(MT_Vector3(pos));
return 0;
}
int KX_SoundActuator::pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
float vel[3];
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!PyArg_ParseTuple(value, "fff", &vel[0], &vel[1], &vel[2]))
return 1;
if (actuator->m_soundObject)
actuator->m_soundObject->SetVelocity(MT_Vector3(vel));
return 0;
}
int KX_SoundActuator::pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
{
MT_Matrix3x3 rot;
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
if (!PySequence_Check(value)) {
PyErr_SetString(PyExc_AttributeError, "'orientation' attribute needs to be a sequence");
return 1;
}
if (!actuator->m_soundObject)
return 0; /* Since not having m_soundObject didn't do anything in the old version,
* it probably should be kept that way */
if (PyMatTo(value, rot))
{
actuator->m_soundObject->SetOrientation(rot);
return 0;
}
PyErr_Clear();
if (PySequence_Size(value) == 4)
{
MT_Quaternion qrot;
if (PyVecTo(value, qrot))
{
rot.setRotation(qrot);
actuator->m_soundObject->SetOrientation(rot);
return 0;
}
return 1;
}
if (PySequence_Size(value) == 3)
{
MT_Vector3 erot;
if (PyVecTo(value, erot))
{
rot.setEuler(erot);
actuator->m_soundObject->SetOrientation(rot);
return 0;
}
return 1;
}
PyErr_SetString(PyExc_AttributeError, "could not set the orientation from a 3x3 matrix, quaternion or euler sequence");
return 1;
}
// Deprecated ----->
PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObject* kwds)
{ {
char *soundName = NULL; char *soundName = NULL;
ShowDeprecationWarning("setFilename()", "the filename property");
// void *soundPointer = NULL; /*unused*/ // void *soundPointer = NULL; /*unused*/
if (!PyArg_ParseTuple(args, "s", &soundName)) if (!PyArg_ParseTuple(args, "s", &soundName))
@@ -307,10 +599,9 @@ PyObject* KX_SoundActuator::PySetFilename(PyObject* self, PyObject* args, PyObje
Py_RETURN_NONE; Py_RETURN_NONE;
} }
PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getFilename()", "the filename property");
if (!m_soundObject) if (!m_soundObject)
{ {
return PyString_FromString(""); return PyString_FromString("");
@@ -325,41 +616,9 @@ PyObject* KX_SoundActuator::PyGetFilename(PyObject* self, PyObject* args, PyObje
return PyString_FromString(name); return PyString_FromString(name);
} }
PyObject* KX_SoundActuator::PyStartSound(PyObject* self, PyObject* args, PyObject* kwds)
{
if (m_soundObject)
// This has no effect if the actuator is not active.
// To start the sound you must activate the actuator.
// This function is to restart the sound.
m_soundObject->StartSound();
Py_RETURN_NONE;
}
PyObject* KX_SoundActuator::PyPauseSound(PyObject* self, PyObject* args, PyObject* kwds)
{
if (m_soundObject)
// unfortunately, openal does not implement pause correctly, it is equivalent to a stop
m_soundObject->PauseSound();
Py_RETURN_NONE;
}
PyObject* KX_SoundActuator::PyStopSound(PyObject* self, PyObject* args, PyObject* kwds)
{
if (m_soundObject)
m_soundObject->StopSound();
Py_RETURN_NONE;
}
PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("setGain()", "the volume property");
float gain = 1.0; float gain = 1.0;
if (!PyArg_ParseTuple(args, "f", &gain)) if (!PyArg_ParseTuple(args, "f", &gain))
return NULL; return NULL;
@@ -374,6 +633,7 @@ PyObject* KX_SoundActuator::PySetGain(PyObject* self, PyObject* args, PyObject*
PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getGain()", "the volume property");
float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f; float gain = (m_soundObject) ? m_soundObject->GetGain() : 1.0f;
PyObject* result = PyFloat_FromDouble(gain); PyObject* result = PyFloat_FromDouble(gain);
@@ -384,6 +644,7 @@ PyObject* KX_SoundActuator::PyGetGain(PyObject* self, PyObject* args, PyObject*
PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("setPitch()", "the pitch property");
float pitch = 1.0; float pitch = 1.0;
if (!PyArg_ParseTuple(args, "f", &pitch)) if (!PyArg_ParseTuple(args, "f", &pitch))
return NULL; return NULL;
@@ -398,6 +659,7 @@ PyObject* KX_SoundActuator::PySetPitch(PyObject* self, PyObject* args, PyObject*
PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getPitch()", "the pitch property");
float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0; float pitch = (m_soundObject) ? m_soundObject->GetPitch() : 1.0;
PyObject* result = PyFloat_FromDouble(pitch); PyObject* result = PyFloat_FromDouble(pitch);
@@ -408,6 +670,7 @@ PyObject* KX_SoundActuator::PyGetPitch(PyObject* self, PyObject* args, PyObject*
PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("setRollOffFactor()", "the rollOffFactor property");
float rollofffactor = 1.0; float rollofffactor = 1.0;
if (!PyArg_ParseTuple(args, "f", &rollofffactor)) if (!PyArg_ParseTuple(args, "f", &rollofffactor))
return NULL; return NULL;
@@ -422,6 +685,7 @@ PyObject* KX_SoundActuator::PySetRollOffFactor(PyObject* self, PyObject* args, P
PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getRollOffFactor()", "the rollOffFactor property");
float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0; float rollofffactor = (m_soundObject) ? m_soundObject->GetRollOffFactor() : 1.0;
PyObject* result = PyFloat_FromDouble(rollofffactor); PyObject* result = PyFloat_FromDouble(rollofffactor);
@@ -432,6 +696,7 @@ PyObject* KX_SoundActuator::PyGetRollOffFactor(PyObject* self, PyObject* args, P
PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("setLooping()", "the looping property");
bool looping = 1; bool looping = 1;
if (!PyArg_ParseTuple(args, "i", &looping)) if (!PyArg_ParseTuple(args, "i", &looping))
return NULL; return NULL;
@@ -446,6 +711,7 @@ PyObject* KX_SoundActuator::PySetLooping(PyObject* self, PyObject* args, PyObjec
PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getLooping()", "the looping property");
int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF; int looping = (m_soundObject) ? m_soundObject->GetLoopMode() : (int)SND_LOOP_OFF;
PyObject* result = PyInt_FromLong(looping); PyObject* result = PyInt_FromLong(looping);
@@ -457,6 +723,7 @@ PyObject* KX_SoundActuator::PyGetLooping(PyObject* self, PyObject* args, PyObjec
PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObject* kwds)
{ {
MT_Point3 pos; MT_Point3 pos;
ShowDeprecationWarning("setPosition()", "the position property");
pos[0] = 0.0; pos[0] = 0.0;
pos[1] = 0.0; pos[1] = 0.0;
pos[2] = 0.0; pos[2] = 0.0;
@@ -475,6 +742,7 @@ PyObject* KX_SoundActuator::PySetPosition(PyObject* self, PyObject* args, PyObje
PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObject* kwds)
{ {
MT_Vector3 vel; MT_Vector3 vel;
ShowDeprecationWarning("setVelocity()", "the velocity property");
vel[0] = 0.0; vel[0] = 0.0;
vel[1] = 0.0; vel[1] = 0.0;
vel[2] = 0.0; vel[2] = 0.0;
@@ -493,6 +761,7 @@ PyObject* KX_SoundActuator::PySetVelocity(PyObject* self, PyObject* args, PyObje
PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyObject* kwds)
{ {
MT_Matrix3x3 ori; MT_Matrix3x3 ori;
ShowDeprecationWarning("setOrientation()", "the orientation property");
ori[0][0] = 1.0; ori[0][0] = 1.0;
ori[0][1] = 0.0; ori[0][1] = 0.0;
ori[0][2] = 0.0; ori[0][2] = 0.0;
@@ -515,6 +784,7 @@ PyObject* KX_SoundActuator::PySetOrientation(PyObject* self, PyObject* args, PyO
PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject* kwds)
{ {
int typeArg; int typeArg;
ShowDeprecationWarning("setType()", "the type property");
if (!PyArg_ParseTuple(args, "i", &typeArg)) { if (!PyArg_ParseTuple(args, "i", &typeArg)) {
return NULL; return NULL;
@@ -530,8 +800,8 @@ PyObject* KX_SoundActuator::PySetType(PyObject* self, PyObject* args, PyObject*
PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds) PyObject* KX_SoundActuator::PyGetType(PyObject* self, PyObject* args, PyObject* kwds)
{ {
ShowDeprecationWarning("getType()", "the type property");
return PyInt_FromLong(m_type); return PyInt_FromLong(m_type);
} }
// <-----

View File

@@ -80,13 +80,36 @@ public:
/* Python interface --------------------------------------------------- */ /* Python interface --------------------------------------------------- */
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
virtual PyObject* py_getattro(PyObject *attr); virtual PyObject* py_getattro(PyObject *attr);
virtual int py_setattro(PyObject *attr, PyObject* value);
KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, startSound);
KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound);
KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound);
static int pyattr_set_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
static PyObject* pyattr_get_filename(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_looping(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_position(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_velocity(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_orientation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
// Deprecated ----->
KX_PYMETHOD(KX_SoundActuator,SetFilename); KX_PYMETHOD(KX_SoundActuator,SetFilename);
KX_PYMETHOD(KX_SoundActuator,GetFilename); KX_PYMETHOD(KX_SoundActuator,GetFilename);
KX_PYMETHOD(KX_SoundActuator,StartSound);
KX_PYMETHOD(KX_SoundActuator,PauseSound);
KX_PYMETHOD(KX_SoundActuator,StopSound);
KX_PYMETHOD(KX_SoundActuator,SetGain); KX_PYMETHOD(KX_SoundActuator,SetGain);
KX_PYMETHOD(KX_SoundActuator,GetGain); KX_PYMETHOD(KX_SoundActuator,GetGain);
KX_PYMETHOD(KX_SoundActuator,SetPitch); KX_PYMETHOD(KX_SoundActuator,SetPitch);
@@ -100,6 +123,8 @@ public:
KX_PYMETHOD(KX_SoundActuator,SetOrientation); KX_PYMETHOD(KX_SoundActuator,SetOrientation);
KX_PYMETHOD(KX_SoundActuator,SetType); KX_PYMETHOD(KX_SoundActuator,SetType);
KX_PYMETHOD(KX_SoundActuator,GetType); KX_PYMETHOD(KX_SoundActuator,GetType);
// <-----
}; };
#endif //__KX_SOUNDACTUATOR #endif //__KX_SOUNDACTUATOR

View File

@@ -8,17 +8,53 @@ class KX_SoundActuator(SCA_IActuator):
The L{startSound()}, L{pauseSound()} and L{stopSound()} do not require The L{startSound()}, L{pauseSound()} and L{stopSound()} do not require
the actuator to be activated - they act instantly. the actuator to be activated - they act instantly.
@ivar filename: Sets the filename of the sound this actuator plays.
@type filename: string
@ivar volume: Sets the volume (gain) of the sound.
@type volume: float
@ivar pitch: Sets the pitch of the sound.
@type pitch: float
@group Play Methods: startSound, pauseSound, stopSound @ivar rollOffFactor: Sets the roll off factor. Rolloff defines the rate of attenuation as the sound gets further away.
@type rollOffFactor: float
@ivar looping: Sets the loop mode of the actuator.
@type looping: integer
@ivar position: Sets the position of the sound.
@type position: float array
@ivar velocity: Sets the speed of the sound; The speed of the sound alter the pitch.
@type velocity: float array
@ivar orientation: Sets the orientation of the sound. When setting the orientation you can
also use quaternion [float,float,float,float] or euler angles [float,float,float]
@type orientation: 3x3 matrix [[float]]
@ivar type: Sets the operation mode of the actuator. You can use one of the following constant:
KX_SOUNDACT_PLAYSTOP (1)
KX_SOUNDACT_PLAYEND (2)
KX_SOUNDACT_LOOPSTOP (3)
KX_SOUNDACT_LOOPEND (4)
KX_SOUNDACT_LOOPBIDIRECTIONAL (5)
KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP (6)
@type type: integer
@group Play Methods: startSound, pauseSound, stopSound.
""" """
def setFilename(filename): def setFilename(filename):
""" """
Sets the filename of the sound this actuator plays. DEPRECATED: Use the filename property instead.
Sets the filename of the sound this actuator plays.
@type filename: string @type filename: string
""" """
def getFilename(): def getFilename():
""" """
DEPRECATED: Use the filename property instead.
Returns the filename of the sound this actuator plays. Returns the filename of the sound this actuator plays.
@rtype: string @rtype: string
@@ -37,6 +73,7 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def setGain(gain): def setGain(gain):
""" """
DEPRECATED: Use the volume property instead
Sets the gain (volume) of the sound Sets the gain (volume) of the sound
@type gain: float @type gain: float
@@ -44,24 +81,28 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def getGain(): def getGain():
""" """
DEPRECATED: Use the volume property instead.
Gets the gain (volume) of the sound. Gets the gain (volume) of the sound.
@rtype: float @rtype: float
""" """
def setPitch(pitch): def setPitch(pitch):
""" """
DEPRECATED: Use the pitch property instead.
Sets the pitch of the sound. Sets the pitch of the sound.
@type pitch: float @type pitch: float
""" """
def getPitch(): def getPitch():
""" """
DEPRECATED: Use the pitch property instead.
Returns the pitch of the sound. Returns the pitch of the sound.
@rtype: float @rtype: float
""" """
def setRollOffFactor(rolloff): def setRollOffFactor(rolloff):
""" """
DEPRECATED: Use the rollOffFactor property instead.
Sets the rolloff factor for the sounds. Sets the rolloff factor for the sounds.
Rolloff defines the rate of attenuation as the sound gets further away. Rolloff defines the rate of attenuation as the sound gets further away.
@@ -71,12 +112,14 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def getRollOffFactor(): def getRollOffFactor():
""" """
DEPRECATED: Use the rollOffFactor property instead.
Returns the rolloff factor for the sound. Returns the rolloff factor for the sound.
@rtype: float @rtype: float
""" """
def setLooping(loop): def setLooping(loop):
""" """
DEPRECATED: Use the looping property instead.
Sets the loop mode of the actuator. Sets the loop mode of the actuator.
@bug: There are no constants defined for this method! @bug: There are no constants defined for this method!
@@ -90,12 +133,14 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def getLooping(): def getLooping():
""" """
DEPRECATED: Use the looping property instead.
Returns the current loop mode of the actuator. Returns the current loop mode of the actuator.
@rtype: integer @rtype: integer
""" """
def setPosition(x, y, z): def setPosition(x, y, z):
""" """
DEPRECATED: Use the position property instead.
Sets the position this sound will come from. Sets the position this sound will come from.
@type x: float @type x: float
@@ -107,6 +152,7 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def setVelocity(vx, vy, vz): def setVelocity(vx, vy, vz):
""" """
DEPRECATED: Use the velocity property instead.
Sets the velocity this sound is moving at. Sets the velocity this sound is moving at.
The sound's pitch is determined from the velocity. The sound's pitch is determined from the velocity.
@@ -120,6 +166,7 @@ class KX_SoundActuator(SCA_IActuator):
""" """
def setOrientation(o11, o12, o13, o21, o22, o23, o31, o32, o33): def setOrientation(o11, o12, o13, o21, o22, o23, o31, o32, o33):
""" """
DEPRECATED: Use the orientation property instead.
Sets the orientation of the sound. Sets the orientation of the sound.
The nine parameters specify a rotation matrix:: The nine parameters specify a rotation matrix::
@@ -130,6 +177,7 @@ class KX_SoundActuator(SCA_IActuator):
def setType(mode): def setType(mode):
""" """
DEPRECATED: Use the type property instead.
Sets the operation mode of the actuator. Sets the operation mode of the actuator.
@param mode: KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP @param mode: KX_SOUNDACT_PLAYSTOP, KX_SOUNDACT_PLAYEND, KX_SOUNDACT_LOOPSTOP, KX_SOUNDACT_LOOPEND, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP
@@ -138,6 +186,7 @@ class KX_SoundActuator(SCA_IActuator):
def getType(): def getType():
""" """
DEPRECATED: Use the type property instead.
Returns the operation mode of the actuator. Returns the operation mode of the actuator.
@rtype: integer @rtype: integer