diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2010-02-05 03:51:32 +0300 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2010-02-05 03:51:32 +0300 |
commit | f7a24a25bac02f7e74bd01451046a2ed0f89bb20 (patch) | |
tree | 1526535a56b46e5b114daeb0f4005ae3d26518e3 /source | |
parent | f32df64d2bbd151b770aa36e74137145a2817813 (diff) |
BGE: Sound Actuator API
act.time can set the sound position (float in seconds)
act.is3D RO gives you the dimension of the audio
act.minGain3D, maxGain3D ... set the 3D parameters of the sound
** PyDoc to be done. Jörg Müller (NeXyon) do you want to document them? The file is here:
//source/gameengine/PyDoc/GameTypes.py
+ adding a missing \n to KX_Scene.cpp. (kind of typo)
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/Ketsji/KX_Scene.cpp | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.cpp | 128 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_SoundActuator.h | 4 |
3 files changed, 134 insertions, 1 deletions
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 4d25b2742d7..291003594ae 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -2102,7 +2102,8 @@ int KX_Scene::pyattr_set_drawing_callback_post(void *self_v, const KX_PYATTRIBUT PyAttributeDef KX_Scene::Attributes[] = { KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name), KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects), - KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive), KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights), + KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive), + KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights), KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras), KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights), KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera), diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp index c97b4618f28..40d2339b816 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.cpp +++ b/source/gameengine/Ketsji/KX_SoundActuator.cpp @@ -303,6 +303,17 @@ PyMethodDef KX_SoundActuator::Methods[] = { }; PyAttributeDef KX_SoundActuator::Attributes[] = { + KX_PYATTRIBUTE_BOOL_RO("is3D", KX_SoundActuator, m_is3d), + KX_PYATTRIBUTE_RW_FUNCTION("maxGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("minGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("referenceDistance3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("maxDistance3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("rolloffFactor3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("coneInnerAngle3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("coneOuterAngle3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + KX_PYATTRIBUTE_RW_FUNCTION("coneOuterGain3D", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), + + 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("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), KX_PYATTRIBUTE_RW_FUNCTION("rollOffFactor", KX_SoundActuator, pyattr_get_rollOffFactor, pyattr_set_rollOffFactor), @@ -345,6 +356,56 @@ KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, } /* Atribute setting and getting -------------------------------------------- */ +PyObject* KX_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + const char* prop = attrdef->m_name; + float result_value = 0.0; + + if(!strcmp(prop, "maxGain3D")) { + result_value = actuator->m_3d.max_gain; + + } else if (!strcmp(prop, "minGain3D")) { + result_value = actuator->m_3d.min_gain; + + } else if (!strcmp(prop, "referenceDistance3D")) { + result_value = actuator->m_3d.reference_distance; + + } else if (!strcmp(prop, "maxDistance3D")) { + result_value = actuator->m_3d.max_distance; + + } else if (!strcmp(prop, "rolloffFactor3D")) { + result_value = actuator->m_3d.rolloff_factor; + + } else if (!strcmp(prop, "coneInnerAngle3D")) { + result_value = actuator->m_3d.cone_inner_angle; + + } else if (!strcmp(prop, "coneOuterAngle3D")) { + result_value = actuator->m_3d.cone_outer_angle; + + } else if (!strcmp(prop, "coneOuterGain3D")) { + result_value = actuator->m_3d.cone_outer_gain; + + } else { + Py_RETURN_NONE; + } + + PyObject* result = PyFloat_FromDouble(result_value); + return result; +} + +PyObject* KX_SoundActuator::pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) +{ + KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + float position = 0.0; + + if(actuator->m_handle) + position = AUD_getPosition(actuator->m_handle); + + PyObject* result = PyFloat_FromDouble(position); + + return result; +} PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) { @@ -375,6 +436,73 @@ PyObject* KX_SoundActuator::pyattr_get_rollOffFactor(void *self, const struct KX return result; } +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); + const char* prop = attrdef->m_name; + float prop_value = 0.0; + AUD_3DSourceSetting setting = AUD_3DSS_NONE; + + if (!PyArg_Parse(value, "f", &prop_value)) + return PY_SET_ATTR_FAIL; + + // update the internal value + if(!strcmp(prop, "maxGain3D")) { + actuator->m_3d.max_gain = prop_value; + setting = AUD_3DSS_MAX_GAIN; + + } else if (!strcmp(prop, "minGain3D")) { + actuator->m_3d.min_gain = prop_value; + setting = AUD_3DSS_MIN_GAIN; + + } else if (!strcmp(prop, "referenceDistance3D")) { + actuator->m_3d.reference_distance = prop_value; + setting = AUD_3DSS_REFERENCE_DISTANCE; + + } else if (!strcmp(prop, "maxDistance3D")) { + actuator->m_3d.max_distance = prop_value; + setting = AUD_3DSS_MAX_DISTANCE; + + } else if (!strcmp(prop, "rolloffFactor3D")) { + actuator->m_3d.rolloff_factor = prop_value; + setting = AUD_3DSS_ROLLOFF_FACTOR; + + } else if (!!strcmp(prop, "coneInnerAngle3D")) { + actuator->m_3d.cone_inner_angle = prop_value; + setting = AUD_3DSS_CONE_INNER_ANGLE; + + } else if (!strcmp(prop, "coneOuterAngle3D")) { + actuator->m_3d.cone_outer_angle = prop_value; + setting = AUD_3DSS_CONE_OUTER_ANGLE; + + } else if (!strcmp(prop, "coneOuterGain3D")) { + actuator->m_3d.cone_outer_gain = prop_value; + setting = AUD_3DSS_CONE_OUTER_GAIN; + + } else { + return PY_SET_ATTR_FAIL; + } + + // if sound is working and 3D, set the new setting + if(actuator->m_handle && actuator->m_is3d && setting != AUD_3DSS_NONE) + AUD_set3DSourceSetting(actuator->m_handle, setting, prop_value); + + return PY_SET_ATTR_SUCCESS; +} + +int KX_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) +{ + KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); + + float position = 1.0; + if (!PyArg_Parse(value, "f", &position)) + return PY_SET_ATTR_FAIL; + + if(actuator->m_handle) + AUD_seek(actuator->m_handle, position); + return PY_SET_ATTR_SUCCESS; +} + int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) { float gain = 1.0; diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h index de862473aac..520b9cc052d 100644 --- a/source/gameengine/Ketsji/KX_SoundActuator.h +++ b/source/gameengine/Ketsji/KX_SoundActuator.h @@ -103,11 +103,15 @@ public: KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound); KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound); + static int pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value); + static int pyattr_set_audposition(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_type(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_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_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); static PyObject* pyattr_get_rollOffFactor(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef); |