2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* KX_SoundActuator.cpp
|
|
|
|
*
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_SoundActuator.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_SoundActuator.h"
|
2011-06-23 09:27:56 +00:00
|
|
|
|
|
|
|
#ifdef WITH_AUDASPACE
|
|
|
|
# include "AUD_C-API.h"
|
2011-08-07 11:54:58 +00:00
|
|
|
# include "AUD_PingPongFactory.h"
|
|
|
|
# include "AUD_IDevice.h"
|
|
|
|
# include "AUD_I3DHandle.h"
|
2011-06-23 09:27:56 +00:00
|
|
|
#endif
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_GameObject.h"
|
2009-04-09 20:40:12 +00:00
|
|
|
#include "KX_PyMath.h" // needed for PyObjectFrom()
|
2011-08-22 18:59:56 +00:00
|
|
|
#include "KX_PythonInit.h"
|
|
|
|
#include "KX_Camera.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_IFactory> sound,
|
2009-08-09 21:16:39 +00:00
|
|
|
float volume,
|
|
|
|
float pitch,
|
|
|
|
bool is3d,
|
|
|
|
KX_3DSoundSettings settings,
|
|
|
|
KX_SOUNDACT_TYPE type)//,
|
2009-09-24 21:22:24 +00:00
|
|
|
: SCA_IActuator(gameobj, KX_ACT_SOUND)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-08-07 11:54:58 +00:00
|
|
|
m_sound = sound;
|
2009-08-09 21:16:39 +00:00
|
|
|
m_volume = volume;
|
|
|
|
m_pitch = pitch;
|
|
|
|
m_is3d = is3d;
|
|
|
|
m_3d = settings;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_type = type;
|
|
|
|
m_isplaying = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_SoundActuator::~KX_SoundActuator()
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->stop();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
void KX_SoundActuator::play()
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->stop();
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_sound.isNull())
|
2009-08-09 21:16:39 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// this is the sound that will be played and not deleted afterwards
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_IFactory> sound = m_sound;
|
2010-07-31 10:03:08 +00:00
|
|
|
|
|
|
|
bool loop = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
switch (m_type)
|
|
|
|
{
|
|
|
|
case KX_SOUNDACT_LOOPBIDIRECTIONAL:
|
|
|
|
case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
|
2011-08-07 11:54:58 +00:00
|
|
|
sound = new AUD_PingPongFactory(sound);
|
2010-07-31 10:03:08 +00:00
|
|
|
// fall through
|
2009-08-09 21:16:39 +00:00
|
|
|
case KX_SOUNDACT_LOOPEND:
|
|
|
|
case KX_SOUNDACT_LOOPSTOP:
|
2010-07-31 10:03:08 +00:00
|
|
|
loop = true;
|
2009-08-09 21:16:39 +00:00
|
|
|
break;
|
|
|
|
case KX_SOUNDACT_PLAYSTOP:
|
|
|
|
case KX_SOUNDACT_PLAYEND:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-06 21:02:26 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
m_handle = AUD_getDevice()->play(sound, 0);
|
|
|
|
}
|
|
|
|
catch(AUD_Exception&)
|
|
|
|
{
|
|
|
|
// cannot play back, ignore
|
|
|
|
return;
|
|
|
|
}
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(m_handle);
|
2011-06-21 20:21:43 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_is3d && !handle3d.isNull())
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-08-22 18:59:56 +00:00
|
|
|
handle3d->setRelative(true);
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setVolumeMaximum(m_3d.max_gain);
|
|
|
|
handle3d->setVolumeMinimum(m_3d.min_gain);
|
|
|
|
handle3d->setDistanceReference(m_3d.reference_distance);
|
|
|
|
handle3d->setDistanceMaximum(m_3d.max_distance);
|
|
|
|
handle3d->setAttenuation(m_3d.rolloff_factor);
|
|
|
|
handle3d->setConeAngleInner(m_3d.cone_inner_angle);
|
|
|
|
handle3d->setConeAngleOuter(m_3d.cone_outer_angle);
|
|
|
|
handle3d->setConeVolumeOuter(m_3d.cone_outer_gain);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (loop)
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->setLoopCount(-1);
|
|
|
|
m_handle->setPitch(m_pitch);
|
|
|
|
m_handle->setVolume(m_volume);
|
2009-08-09 21:16:39 +00:00
|
|
|
m_isplaying = true;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
CValue* KX_SoundActuator::GetReplica()
|
|
|
|
{
|
|
|
|
KX_SoundActuator* replica = new KX_SoundActuator(*this);
|
|
|
|
replica->ProcessReplica();
|
2009-05-10 20:53:58 +00:00
|
|
|
return replica;
|
|
|
|
};
|
|
|
|
|
|
|
|
void KX_SoundActuator::ProcessReplica()
|
|
|
|
{
|
|
|
|
SCA_IActuator::ProcessReplica();
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle = AUD_Reference<AUD_IHandle>();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
bool KX_SoundActuator::Update(double curtime, bool frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
if (!frame)
|
|
|
|
return true;
|
2002-10-12 11:37:38 +00:00
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
// do nothing on negative events, otherwise sounds are played twice!
|
|
|
|
bool bNegativeEvent = IsNegativeEvent();
|
2009-06-17 12:32:28 +00:00
|
|
|
bool bPositiveEvent = m_posevent;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
RemoveAllEvents();
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_sound.isNull())
|
2008-08-28 08:13:58 +00:00
|
|
|
return false;
|
|
|
|
|
2008-10-09 06:06:11 +00:00
|
|
|
// actual audio device playing state
|
2011-08-07 11:54:58 +00:00
|
|
|
bool isplaying = m_handle.isNull() ? false : (m_handle->getStatus() == AUD_STATUS_PLAYING);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
if (bNegativeEvent)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
// here must be a check if it is still playing
|
2009-08-09 21:16:39 +00:00
|
|
|
if (m_isplaying && isplaying)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-10-09 06:06:11 +00:00
|
|
|
switch (m_type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2008-10-09 06:06:11 +00:00
|
|
|
case KX_SOUNDACT_PLAYSTOP:
|
|
|
|
case KX_SOUNDACT_LOOPSTOP:
|
|
|
|
case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
|
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
// stop immediately
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->stop();
|
|
|
|
m_handle = AUD_Reference<AUD_IHandle>();
|
2008-10-09 06:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SOUNDACT_PLAYEND:
|
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
// do nothing, sound will stop anyway when it's finished
|
2008-10-09 06:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_SOUNDACT_LOOPEND:
|
|
|
|
case KX_SOUNDACT_LOOPBIDIRECTIONAL:
|
|
|
|
{
|
2009-08-09 21:16:39 +00:00
|
|
|
// stop the looping so that the sound stops when it finished
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->setLoopCount(0);
|
2008-10-09 06:06:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
// implement me !!
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-10-09 06:06:11 +00:00
|
|
|
// remember that we tried to stop the actuator
|
|
|
|
m_isplaying = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2009-06-17 12:32:28 +00:00
|
|
|
|
|
|
|
#if 1
|
|
|
|
// Warning: when de-activating the actuator, after a single negative event this runs again with...
|
|
|
|
// m_posevent==false && m_posevent==false, in this case IsNegativeEvent() returns false
|
|
|
|
// and assumes this is a positive event.
|
|
|
|
// check that we actually have a positive event so as not to play sounds when being disabled.
|
2012-03-24 07:52:14 +00:00
|
|
|
else if (bPositiveEvent) { // <- added since 2.49
|
2009-06-17 12:32:28 +00:00
|
|
|
#else
|
|
|
|
else { // <- works in most cases except a loop-end sound will never stop unless
|
|
|
|
// the negative pulse is done continuesly
|
|
|
|
#endif
|
2008-10-09 06:06:11 +00:00
|
|
|
if (!m_isplaying)
|
2009-08-09 21:16:39 +00:00
|
|
|
play();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-09 06:06:11 +00:00
|
|
|
// verify that the sound is still playing
|
2011-08-07 11:54:58 +00:00
|
|
|
isplaying = m_handle.isNull() ? false : (m_handle->getStatus() == AUD_STATUS_PLAYING);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-10-09 06:06:11 +00:00
|
|
|
if (isplaying)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(m_handle);
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (m_is3d && !handle3d.isNull())
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-08-22 18:59:56 +00:00
|
|
|
KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera();
|
|
|
|
if (cam)
|
|
|
|
{
|
|
|
|
KX_GameObject* obj = (KX_GameObject*)this->GetParent();
|
|
|
|
MT_Point3 p;
|
|
|
|
MT_Matrix3x3 Mo;
|
|
|
|
AUD_Vector3 v;
|
|
|
|
float q[4];
|
|
|
|
|
|
|
|
Mo = cam->NodeGetWorldOrientation().inverse();
|
|
|
|
p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition());
|
|
|
|
p = Mo * p;
|
|
|
|
p.getValue(v.get());
|
|
|
|
handle3d->setSourceLocation(v);
|
|
|
|
p = (obj->GetLinearVelocity() - cam->GetLinearVelocity());
|
|
|
|
p = Mo * p;
|
|
|
|
p.getValue(v.get());
|
|
|
|
handle3d->setSourceVelocity(v);
|
|
|
|
(Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(q);
|
|
|
|
handle3d->setSourceOrientation(AUD_Quaternion(q[3], q[0], q[1], q[2]));
|
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-09 06:06:11 +00:00
|
|
|
m_isplaying = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
result = false;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_SoundActuator::Type = {
|
2009-04-29 16:54:45 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2009-08-10 00:07:34 +00:00
|
|
|
"KX_SoundActuator",
|
|
|
|
sizeof(PyObjectPlus_Proxy),
|
|
|
|
0,
|
|
|
|
py_base_dealloc,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
py_base_repr,
|
|
|
|
0,0,0,0,0,0,0,0,0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&SCA_IActuator::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_SoundActuator::Methods[] = {
|
2009-04-09 20:40:12 +00:00
|
|
|
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound),
|
|
|
|
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound),
|
|
|
|
KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound),
|
2010-04-17 15:47:00 +00:00
|
|
|
{NULL, NULL} //Sentinel
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_SoundActuator::Attributes[] = {
|
2010-02-05 00:51:32 +00:00
|
|
|
KX_PYATTRIBUTE_BOOL_RO("is3D", KX_SoundActuator, m_is3d),
|
2010-07-30 22:20:08 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("volume_maximum", KX_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("distance_reference", KX_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("attenuation", 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_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
|
2011-06-16 09:13:29 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("sound", KX_SoundActuator, pyattr_get_sound, pyattr_set_sound),
|
2010-07-30 22:20:08 +00:00
|
|
|
|
2010-02-05 00:51:32 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition),
|
2009-04-09 20:40:12 +00:00
|
|
|
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),
|
2009-05-15 03:26:53 +00:00
|
|
|
KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type),
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
/* Methods ----------------------------------------------------------------- */
|
2009-08-09 21:16:39 +00:00
|
|
|
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound,
|
2009-04-09 20:40:12 +00:00
|
|
|
"startSound()\n"
|
|
|
|
"\tStarts the sound.\n")
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-02-24 19:34:29 +00:00
|
|
|
switch(m_handle.isNull() ? AUD_STATUS_INVALID : m_handle->getStatus())
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2012-02-24 19:34:29 +00:00
|
|
|
case AUD_STATUS_PLAYING:
|
|
|
|
break;
|
|
|
|
case AUD_STATUS_PAUSED:
|
|
|
|
m_handle->resume();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
play();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2009-04-09 20:40:12 +00:00
|
|
|
Py_RETURN_NONE;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound,
|
|
|
|
"pauseSound()\n"
|
|
|
|
"\tPauses the sound.\n")
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->pause();
|
2009-04-09 20:40:12 +00:00
|
|
|
Py_RETURN_NONE;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound,
|
|
|
|
"stopSound()\n"
|
|
|
|
"\tStops the sound.\n")
|
|
|
|
{
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
m_handle->stop();
|
|
|
|
m_handle = AUD_Reference<AUD_IHandle>();
|
2009-02-21 12:43:24 +00:00
|
|
|
Py_RETURN_NONE;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
/* Atribute setting and getting -------------------------------------------- */
|
2010-02-05 00:51:32 +00:00
|
|
|
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;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!strcmp(prop, "volume_maximum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.max_gain;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "volume_minimum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.min_gain;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "distance_reference")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.reference_distance;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "distance_maximum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.max_distance;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "attenuation")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.rolloff_factor;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "cone_angle_inner")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.cone_inner_angle;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "cone_angle_outer")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
result_value = actuator->m_3d.cone_outer_angle;
|
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "cone_volume_outer")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
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;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
position = actuator->m_handle->getPosition();
|
2010-02-05 00:51:32 +00:00
|
|
|
|
|
|
|
PyObject* result = PyFloat_FromDouble(position);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
PyObject* KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
2009-08-09 21:16:39 +00:00
|
|
|
float gain = actuator->m_volume;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
PyObject* result = PyFloat_FromDouble(gain);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
PyObject* KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-04-09 20:40:12 +00:00
|
|
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
2009-08-09 21:16:39 +00:00
|
|
|
float pitch = actuator->m_pitch;
|
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
PyObject* result = PyFloat_FromDouble(pitch);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-06-16 09:13:29 +00:00
|
|
|
PyObject* KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_sound.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
return AUD_getPythonFactory(&actuator->m_sound);
|
2011-07-23 15:59:10 +00:00
|
|
|
else
|
|
|
|
Py_RETURN_NONE;
|
2011-06-16 09:13:29 +00:00
|
|
|
}
|
|
|
|
|
2010-02-05 00:51:32 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
if (!PyArg_Parse(value, "f", &prop_value))
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_I3DHandle> handle3d = AUD_Reference<AUD_I3DHandle>(actuator->m_handle);
|
2010-07-30 22:20:08 +00:00
|
|
|
// if sound is working and 3D, set the new setting
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_is3d)
|
2010-07-30 22:20:08 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!strcmp(prop, "volume_maximum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.max_gain = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setVolumeMaximum(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "volume_minimum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.min_gain = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setVolumeMinimum(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "distance_reference")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.reference_distance = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setDistanceReference(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "distance_maximum")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.max_distance = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setDistanceMaximum(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "attenuation")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.rolloff_factor = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setAttenuation(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!!strcmp(prop, "cone_angle_inner")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.cone_inner_angle = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setConeAngleInner(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "cone_angle_outer")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.cone_outer_angle = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setConeAngleOuter(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
2010-07-30 22:20:08 +00:00
|
|
|
} else if (!strcmp(prop, "cone_volume_outer")) {
|
2010-02-05 00:51:32 +00:00
|
|
|
actuator->m_3d.cone_outer_gain = prop_value;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!handle3d.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
handle3d->setConeVolumeOuter(prop_value);
|
2010-02-05 00:51:32 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
return PY_SET_ATTR_FAIL;
|
2010-07-30 22:20:08 +00:00
|
|
|
}
|
2010-02-05 00:51:32 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
actuator->m_handle->seek(position);
|
2010-02-05 00:51:32 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
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))
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
actuator->m_volume = gain;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
actuator->m_handle->setVolume(gain);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-09 20:40:12 +00:00
|
|
|
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))
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
2009-08-09 21:16:39 +00:00
|
|
|
|
|
|
|
actuator->m_pitch = pitch;
|
2012-03-24 07:52:14 +00:00
|
|
|
if (!actuator->m_handle.isNull())
|
2011-08-07 11:54:58 +00:00
|
|
|
actuator->m_handle->setPitch(pitch);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2009-05-19 07:16:40 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
2009-04-09 20:40:12 +00:00
|
|
|
|
2011-06-16 09:13:29 +00:00
|
|
|
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;
|
|
|
|
|
2011-08-07 11:54:58 +00:00
|
|
|
AUD_Reference<AUD_IFactory>* snd = reinterpret_cast<AUD_Reference<AUD_IFactory>*>(AUD_getPythonSound(sound));
|
2012-03-24 07:52:14 +00:00
|
|
|
if (snd)
|
2011-06-16 09:13:29 +00:00
|
|
|
{
|
2011-08-07 11:54:58 +00:00
|
|
|
actuator->m_sound = *snd;
|
|
|
|
delete snd;
|
2011-06-16 09:13:29 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|