[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [26616] trunk/blender/source/gameengine/ Ketsji: BGE: Sound Actuator API

Dalai Felinto dfelinto at gmail.com
Fri Feb 5 01:51:32 CET 2010


Revision: 26616
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=26616
Author:   dfelinto
Date:     2010-02-05 01:51:32 +0100 (Fri, 05 Feb 2010)

Log Message:
-----------
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?\195?\182rg M?\195?\188ller (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)

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.h

Modified: trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2010-02-04 23:51:41 UTC (rev 26615)
+++ trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp	2010-02-05 00:51:32 UTC (rev 26616)
@@ -2102,7 +2102,8 @@
 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),

Modified: trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp	2010-02-04 23:51:41 UTC (rev 26615)
+++ trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp	2010-02-05 00:51:32 UTC (rev 26616)
@@ -303,6 +303,17 @@
 };
 
 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,7 +356,57 @@
 }
 
 /* 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)
 {
 	KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
@@ -375,6 +436,73 @@
 	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;

Modified: trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.h	2010-02-04 23:51:41 UTC (rev 26615)
+++ trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.h	2010-02-05 00:51:32 UTC (rev 26616)
@@ -103,11 +103,15 @@
 	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);





More information about the Bf-blender-cvs mailing list