Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_SoundActuator.cpp
- This file was moved from source/gameengine/Ketsji/KX_SoundActuator.cpp.
| /* | /* | ||||
| * KX_SoundActuator.cpp | |||||
| * | |||||
| * | |||||
| * ***** BEGIN GPL LICENSE BLOCK ***** | * ***** BEGIN GPL LICENSE BLOCK ***** | ||||
| * | * | ||||
| * This program is free software; you can redistribute it and/or | * This program is free software; you can redistribute it and/or | ||||
| * modify it under the terms of the GNU General Public License | * modify it under the terms of the GNU General Public License | ||||
| * as published by the Free Software Foundation; either version 2 | * as published by the Free Software Foundation; either version 2 | ||||
| * of the License, or (at your option) any later version. | * of the License, or (at your option) any later version. | ||||
| * | * | ||||
| * This program is distributed in the hope that it will be useful, | * This program is distributed in the hope that it will be useful, | ||||
| Show All 11 Lines | |||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| * | * | ||||
| */ | */ | ||||
| /** \file gameengine/Ketsji/KX_SoundActuator.cpp | /** \file gameengine/GameLogic/SCA_SoundActuator.cpp | ||||
| * \ingroup ketsji | * \ingroup gamelogic | ||||
| */ | */ | ||||
| #include "KX_SoundActuator.h" | #include "SCA_SoundActuator.h" | ||||
| #ifdef WITH_AUDASPACE | #ifdef WITH_AUDASPACE | ||||
| # include "AUD_C-API.h" | # include "AUD_C-API.h" | ||||
| # include "AUD_PingPongFactory.h" | # include "AUD_PingPongFactory.h" | ||||
| # include "AUD_IDevice.h" | # include "AUD_IDevice.h" | ||||
| # include "AUD_I3DHandle.h" | # include "AUD_I3DHandle.h" | ||||
| #endif | #endif | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "KX_PyMath.h" // needed for PyObjectFrom() | #include "KX_PyMath.h" // needed for PyObjectFrom() | ||||
| #include "KX_PythonInit.h" | #include "KX_PythonInit.h" | ||||
| #include "KX_Camera.h" | #include "KX_Camera.h" | ||||
| #include <iostream> | #include <iostream> | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj, | SCA_SoundActuator::SCA_SoundActuator(SCA_IObject* gameobj, | ||||
| boost::shared_ptr<AUD_IFactory> sound, | boost::shared_ptr<AUD_IFactory> sound, | ||||
| float volume, | float volume, | ||||
| float pitch, | float pitch, | ||||
| bool is3d, | bool is3d, | ||||
| KX_3DSoundSettings settings, | KX_3DSoundSettings settings, | ||||
| KX_SOUNDACT_TYPE type)//, | KX_SOUNDACT_TYPE type)//, | ||||
| : SCA_IActuator(gameobj, KX_ACT_SOUND) | : SCA_IActuator(gameobj, SCA_ACT_SOUND) | ||||
| { | { | ||||
| m_sound = sound; | m_sound = sound; | ||||
| m_volume = volume; | m_volume = volume; | ||||
| m_pitch = pitch; | m_pitch = pitch; | ||||
| m_is3d = is3d; | m_is3d = is3d; | ||||
| m_3d = settings; | m_3d = settings; | ||||
| m_type = type; | m_type = type; | ||||
| m_isplaying = false; | m_isplaying = false; | ||||
| } | } | ||||
| KX_SoundActuator::~KX_SoundActuator() | SCA_SoundActuator::~SCA_SoundActuator() | ||||
| { | { | ||||
| if (m_handle.get()) | if (m_handle.get()) | ||||
| m_handle->stop(); | m_handle->stop(); | ||||
| } | } | ||||
| void KX_SoundActuator::play() | void SCA_SoundActuator::play() | ||||
| { | { | ||||
| if (m_handle.get()) | if (m_handle.get()) | ||||
| m_handle->stop(); | m_handle->stop(); | ||||
| if (!m_sound.get()) | if (!m_sound.get()) | ||||
| return; | return; | ||||
| // this is the sound that will be played and not deleted afterwards | // this is the sound that will be played and not deleted afterwards | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if (loop) | ||||
| m_handle->setLoopCount(-1); | m_handle->setLoopCount(-1); | ||||
| m_handle->setPitch(m_pitch); | m_handle->setPitch(m_pitch); | ||||
| m_handle->setVolume(m_volume); | m_handle->setVolume(m_volume); | ||||
| } | } | ||||
| m_isplaying = true; | m_isplaying = true; | ||||
| } | } | ||||
| CValue* KX_SoundActuator::GetReplica() | CValue* SCA_SoundActuator::GetReplica() | ||||
| { | { | ||||
| KX_SoundActuator* replica = new KX_SoundActuator(*this); | SCA_SoundActuator* replica = new SCA_SoundActuator(*this); | ||||
| replica->ProcessReplica(); | replica->ProcessReplica(); | ||||
| return replica; | return replica; | ||||
| } | } | ||||
| void KX_SoundActuator::ProcessReplica() | void SCA_SoundActuator::ProcessReplica() | ||||
| { | { | ||||
| SCA_IActuator::ProcessReplica(); | SCA_IActuator::ProcessReplica(); | ||||
| m_handle = boost::shared_ptr<AUD_IHandle>(); | m_handle = boost::shared_ptr<AUD_IHandle>(); | ||||
| } | } | ||||
| bool KX_SoundActuator::Update(double curtime, bool frame) | bool SCA_SoundActuator::Update(double curtime, bool frame) | ||||
| { | { | ||||
| if (!frame) | if (!frame) | ||||
| return true; | return true; | ||||
| bool result = false; | bool result = false; | ||||
| // do nothing on negative events, otherwise sounds are played twice! | // do nothing on negative events, otherwise sounds are played twice! | ||||
| bool bNegativeEvent = IsNegativeEvent(); | bool bNegativeEvent = IsNegativeEvent(); | ||||
| bool bPositiveEvent = m_posevent; | bool bPositiveEvent = m_posevent; | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | |||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_SoundActuator::Type = { | PyTypeObject SCA_SoundActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_SoundActuator", | "SCA_SoundActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_SoundActuator::Methods[] = { | PyMethodDef SCA_SoundActuator::Methods[] = { | ||||
| KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound), | KX_PYMETHODTABLE_NOARGS(SCA_SoundActuator, startSound), | ||||
| KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound), | KX_PYMETHODTABLE_NOARGS(SCA_SoundActuator, pauseSound), | ||||
| KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound), | KX_PYMETHODTABLE_NOARGS(SCA_SoundActuator, stopSound), | ||||
| {NULL, NULL} //Sentinel | {NULL, NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_SoundActuator::Attributes[] = { | PyAttributeDef SCA_SoundActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_BOOL_RO("is3D", KX_SoundActuator, m_is3d), | KX_PYATTRIBUTE_BOOL_RO("is3D", SCA_SoundActuator, m_is3d), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("volume_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | KX_PYATTRIBUTE_RW_FUNCTION("volume_maximum", SCA_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("volume_minimum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | KX_PYATTRIBUTE_RW_FUNCTION("volume_minimum", SCA_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("distance_reference", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | KX_PYATTRIBUTE_RW_FUNCTION("distance_reference", SCA_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("distance_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | KX_PYATTRIBUTE_RW_FUNCTION("distance_maximum", SCA_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("attenuation", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property), | KX_PYATTRIBUTE_RW_FUNCTION("attenuation", SCA_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_inner", SCA_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", SCA_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", SCA_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("sound", SCA_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", SCA_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", SCA_SoundActuator, pyattr_get_gain, pyattr_set_gain), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), | KX_PYATTRIBUTE_RW_FUNCTION("pitch", SCA_SoundActuator, pyattr_get_pitch, pyattr_set_pitch), | ||||
| KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type), | KX_PYATTRIBUTE_ENUM_RW("mode",SCA_SoundActuator::KX_SOUNDACT_NODEF+1,SCA_SoundActuator::KX_SOUNDACT_MAX-1,false,SCA_SoundActuator,m_type), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| /* Methods ----------------------------------------------------------------- */ | /* Methods ----------------------------------------------------------------- */ | ||||
| KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound, | KX_PYMETHODDEF_DOC_NOARGS(SCA_SoundActuator, startSound, | ||||
| "startSound()\n" | "startSound()\n" | ||||
| "\tStarts the sound.\n") | "\tStarts the sound.\n") | ||||
| { | { | ||||
| switch (m_handle.get() ? m_handle->getStatus() : AUD_STATUS_INVALID) { | switch (m_handle.get() ? m_handle->getStatus() : AUD_STATUS_INVALID) { | ||||
| case AUD_STATUS_PLAYING: | case AUD_STATUS_PLAYING: | ||||
| break; | break; | ||||
| case AUD_STATUS_PAUSED: | case AUD_STATUS_PAUSED: | ||||
| m_handle->resume(); | m_handle->resume(); | ||||
| break; | break; | ||||
| default: | default: | ||||
| play(); | play(); | ||||
| } | } | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound, | KX_PYMETHODDEF_DOC_NOARGS(SCA_SoundActuator, pauseSound, | ||||
| "pauseSound()\n" | "pauseSound()\n" | ||||
| "\tPauses the sound.\n") | "\tPauses the sound.\n") | ||||
| { | { | ||||
| if (m_handle.get()) | if (m_handle.get()) | ||||
| m_handle->pause(); | m_handle->pause(); | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound, | KX_PYMETHODDEF_DOC_NOARGS(SCA_SoundActuator, stopSound, | ||||
| "stopSound()\n" | "stopSound()\n" | ||||
| "\tStops the sound.\n") | "\tStops the sound.\n") | ||||
| { | { | ||||
| if (m_handle.get()) | if (m_handle.get()) | ||||
| m_handle->stop(); | m_handle->stop(); | ||||
| m_handle = boost::shared_ptr<AUD_IHandle>(); | m_handle = boost::shared_ptr<AUD_IHandle>(); | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| /* Atribute setting and getting -------------------------------------------- */ | /* Atribute setting and getting -------------------------------------------- */ | ||||
| PyObject *KX_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| const char* prop = attrdef->m_name; | const char* prop = attrdef->m_name; | ||||
| float result_value = 0.0; | float result_value = 0.0; | ||||
| if (!strcmp(prop, "volume_maximum")) { | if (!strcmp(prop, "volume_maximum")) { | ||||
| result_value = actuator->m_3d.max_gain; | result_value = actuator->m_3d.max_gain; | ||||
| } else if (!strcmp(prop, "volume_minimum")) { | } else if (!strcmp(prop, "volume_minimum")) { | ||||
| result_value = actuator->m_3d.min_gain; | result_value = actuator->m_3d.min_gain; | ||||
| Show All 19 Lines | PyObject *SCA_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| } else { | } else { | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| PyObject *result = PyFloat_FromDouble(result_value); | PyObject *result = PyFloat_FromDouble(result_value); | ||||
| return result; | return result; | ||||
| } | } | ||||
| PyObject *KX_SoundActuator::pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_SoundActuator::pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| float position = 0.0; | float position = 0.0; | ||||
| if (actuator->m_handle.get()) | if (actuator->m_handle.get()) | ||||
| position = actuator->m_handle->getPosition(); | position = actuator->m_handle->getPosition(); | ||||
| PyObject *result = PyFloat_FromDouble(position); | PyObject *result = PyFloat_FromDouble(position); | ||||
| return result; | return result; | ||||
| } | } | ||||
| PyObject *KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| float gain = actuator->m_volume; | float gain = actuator->m_volume; | ||||
| PyObject *result = PyFloat_FromDouble(gain); | PyObject *result = PyFloat_FromDouble(gain); | ||||
| return result; | return result; | ||||
| } | } | ||||
| PyObject *KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| float pitch = actuator->m_pitch; | float pitch = actuator->m_pitch; | ||||
| PyObject *result = PyFloat_FromDouble(pitch); | PyObject *result = PyFloat_FromDouble(pitch); | ||||
| return result; | return result; | ||||
| } | } | ||||
| PyObject *KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| if (actuator->m_sound.get()) | if (actuator->m_sound.get()) | ||||
| return (PyObject *)AUD_getPythonFactory(&actuator->m_sound); | return (PyObject *)AUD_getPythonFactory(&actuator->m_sound); | ||||
| else | else | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| } | } | ||||
| int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| const char* prop = attrdef->m_name; | const char* prop = attrdef->m_name; | ||||
| float prop_value = 0.0; | float prop_value = 0.0; | ||||
| if (!PyArg_Parse(value, "f", &prop_value)) | if (!PyArg_Parse(value, "f", &prop_value)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| boost::shared_ptr<AUD_I3DHandle> handle3d = boost::dynamic_pointer_cast<AUD_I3DHandle>(actuator->m_handle); | boost::shared_ptr<AUD_I3DHandle> handle3d = boost::dynamic_pointer_cast<AUD_I3DHandle>(actuator->m_handle); | ||||
| // if sound is working and 3D, set the new setting | // if sound is working and 3D, set the new setting | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | int SCA_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| } else { | } else { | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| int KX_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| float position = 1.0; | float position = 1.0; | ||||
| if (!PyArg_Parse(value, "f", &position)) | if (!PyArg_Parse(value, "f", &position)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| if (actuator->m_handle.get()) | if (actuator->m_handle.get()) | ||||
| actuator->m_handle->seek(position); | actuator->m_handle->seek(position); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| float gain = 1.0; | float gain = 1.0; | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| if (!PyArg_Parse(value, "f", &gain)) | if (!PyArg_Parse(value, "f", &gain)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| actuator->m_volume = gain; | actuator->m_volume = gain; | ||||
| if (actuator->m_handle.get()) | if (actuator->m_handle.get()) | ||||
| actuator->m_handle->setVolume(gain); | actuator->m_handle->setVolume(gain); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| float pitch = 1.0; | float pitch = 1.0; | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| if (!PyArg_Parse(value, "f", &pitch)) | if (!PyArg_Parse(value, "f", &pitch)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| actuator->m_pitch = pitch; | actuator->m_pitch = pitch; | ||||
| if (actuator->m_handle.get()) | if (actuator->m_handle.get()) | ||||
| actuator->m_handle->setPitch(pitch); | actuator->m_handle->setPitch(pitch); | ||||
| 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) | int SCA_SoundActuator::pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| PyObject *sound = NULL; | PyObject *sound = NULL; | ||||
| KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self); | SCA_SoundActuator * actuator = static_cast<SCA_SoundActuator *> (self); | ||||
| if (!PyArg_Parse(value, "O", &sound)) | if (!PyArg_Parse(value, "O", &sound)) | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| boost::shared_ptr<AUD_IFactory>* snd = reinterpret_cast<boost::shared_ptr<AUD_IFactory>*>(AUD_getPythonSound((void *)sound)); | boost::shared_ptr<AUD_IFactory>* snd = reinterpret_cast<boost::shared_ptr<AUD_IFactory>*>(AUD_getPythonSound((void *)sound)); | ||||
| if (snd) | if (snd) | ||||
| { | { | ||||
| actuator->m_sound = *snd; | actuator->m_sound = *snd; | ||||
| delete snd; | delete snd; | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| return PY_SET_ATTR_FAIL; | return PY_SET_ATTR_FAIL; | ||||
| } | } | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||