3D Audio GSoC:
GameEngine Python access sound actuator's sound (with setting! :-D).
This commit is contained in:
@@ -2881,6 +2881,19 @@ Factory_empty()
|
|||||||
return FactoryType.tp_alloc(&FactoryType, 0);
|
return FactoryType.tp_alloc(&FactoryType, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Factory*
|
||||||
|
checkFactory(PyObject* factory)
|
||||||
|
{
|
||||||
|
if(!PyObject_TypeCheck(factory, &FactoryType))
|
||||||
|
{
|
||||||
|
PyErr_SetString(PyExc_TypeError, "Object is not of type Factory!");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Factory*)factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ====================================================================
|
// ====================================================================
|
||||||
|
|
||||||
PyDoc_STRVAR(M_aud_doc,
|
PyDoc_STRVAR(M_aud_doc,
|
||||||
|
@@ -68,6 +68,7 @@ PyInit_aud(void);
|
|||||||
|
|
||||||
extern PyObject* Device_empty();
|
extern PyObject* Device_empty();
|
||||||
extern PyObject* Factory_empty();
|
extern PyObject* Factory_empty();
|
||||||
|
extern Factory* checkFactory(PyObject* factory);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@@ -227,6 +227,32 @@ PyObject* AUD_initPython()
|
|||||||
|
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* AUD_getPythonFactory(AUD_Sound* sound)
|
||||||
|
{
|
||||||
|
if(sound)
|
||||||
|
{
|
||||||
|
Factory* obj = (Factory*) Factory_empty();
|
||||||
|
if(obj)
|
||||||
|
{
|
||||||
|
obj->factory = new AUD_Reference<AUD_IFactory>(*sound);
|
||||||
|
return (PyObject*) obj;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
AUD_Sound* AUD_getPythonSound(PyObject* sound)
|
||||||
|
{
|
||||||
|
Factory* factory = checkFactory(sound);
|
||||||
|
|
||||||
|
if(!factory)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return new AUD_Reference<AUD_IFactory>(*reinterpret_cast<AUD_Reference<AUD_IFactory>*>(factory->factory));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void AUD_lock()
|
void AUD_lock()
|
||||||
@@ -973,3 +999,8 @@ int AUD_doesPlayback()
|
|||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AUD_Sound* AUD_copy(AUD_Sound* sound)
|
||||||
|
{
|
||||||
|
return new AUD_Reference<AUD_IFactory>(*sound);
|
||||||
|
}
|
||||||
|
@@ -31,6 +31,10 @@
|
|||||||
#ifndef AUD_CAPI
|
#ifndef AUD_CAPI
|
||||||
#define AUD_CAPI
|
#define AUD_CAPI
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
#include "Python.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -492,6 +496,14 @@ extern void AUD_setSyncCallback(AUD_syncFunction function, void* data);
|
|||||||
|
|
||||||
extern int AUD_doesPlayback(void);
|
extern int AUD_doesPlayback(void);
|
||||||
|
|
||||||
|
extern AUD_Sound* AUD_copy(AUD_Sound* sound);
|
||||||
|
|
||||||
|
#ifdef WITH_PYTHON
|
||||||
|
extern PyObject* AUD_getPythonFactory(AUD_Sound* sound);
|
||||||
|
|
||||||
|
extern AUD_Sound* AUD_getPythonSound(PyObject* sound);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -53,7 +53,7 @@ KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
|
|||||||
KX_SOUNDACT_TYPE type)//,
|
KX_SOUNDACT_TYPE type)//,
|
||||||
: SCA_IActuator(gameobj, KX_ACT_SOUND)
|
: SCA_IActuator(gameobj, KX_ACT_SOUND)
|
||||||
{
|
{
|
||||||
m_sound = sound;
|
m_sound = AUD_copy(sound);
|
||||||
m_volume = volume;
|
m_volume = volume;
|
||||||
m_pitch = pitch;
|
m_pitch = pitch;
|
||||||
m_is3d = is3d;
|
m_is3d = is3d;
|
||||||
@@ -69,6 +69,7 @@ KX_SoundActuator::~KX_SoundActuator()
|
|||||||
{
|
{
|
||||||
if(m_handle)
|
if(m_handle)
|
||||||
AUD_stop(m_handle);
|
AUD_stop(m_handle);
|
||||||
|
AUD_unload(m_sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KX_SoundActuator::play()
|
void KX_SoundActuator::play()
|
||||||
@@ -286,6 +287,7 @@ PyAttributeDef KX_SoundActuator::Attributes[] = {
|
|||||||
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_inner", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_inner", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("cone_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
KX_PYATTRIBUTE_RW_FUNCTION("cone_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
||||||
|
KX_PYATTRIBUTE_RW_FUNCTION("sound", KX_SoundActuator, pyattr_get_sound, pyattr_set_sound),
|
||||||
|
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition),
|
KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition),
|
||||||
KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
|
KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
|
||||||
@@ -400,6 +402,12 @@ PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRI
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PyObject* KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
||||||
|
{
|
||||||
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
||||||
|
return AUD_getPythonFactory(actuator->m_sound);
|
||||||
|
}
|
||||||
|
|
||||||
int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||||
{
|
{
|
||||||
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
||||||
@@ -501,4 +509,22 @@ int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_D
|
|||||||
return PY_SET_ATTR_SUCCESS;
|
return PY_SET_ATTR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int KX_SoundActuator::pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
||||||
|
{
|
||||||
|
PyObject* sound = NULL;
|
||||||
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
||||||
|
if (!PyArg_Parse(value, "O", &sound))
|
||||||
|
return PY_SET_ATTR_FAIL;
|
||||||
|
|
||||||
|
AUD_Sound* snd = AUD_getPythonSound(sound);
|
||||||
|
if(snd)
|
||||||
|
{
|
||||||
|
AUD_unload(actuator->m_sound);
|
||||||
|
actuator->m_sound = snd;
|
||||||
|
return PY_SET_ATTR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
return PY_SET_ATTR_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // WITH_PYTHON
|
#endif // WITH_PYTHON
|
||||||
|
@@ -110,12 +110,14 @@ public:
|
|||||||
static int pyattr_set_gain(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_pitch(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 int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||||
|
static int pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
|
||||||
|
|
||||||
static PyObject* pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
static PyObject* pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
static PyObject* pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
static PyObject* pyattr_get_audposition(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_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_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
static PyObject* pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
|
static PyObject* pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
|
||||||
|
|
||||||
#endif // WITH_PYTHON
|
#endif // WITH_PYTHON
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user